@etohq/framework 1.0.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/README.md +0 -0
- package/dist/build-tools/compiler.d.ts +49 -0
- package/dist/build-tools/compiler.d.ts.map +1 -0
- package/dist/build-tools/compiler.js +291 -0
- package/dist/build-tools/compiler.js.map +1 -0
- package/dist/build-tools/index.d.ts +2 -0
- package/dist/build-tools/index.d.ts.map +1 -0
- package/dist/build-tools/index.js +18 -0
- package/dist/build-tools/index.js.map +1 -0
- package/dist/config/config.d.ts +34 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +132 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +35 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +901 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +3 -0
- package/dist/config/types.js.map +1 -0
- package/dist/container.d.ts +3 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +21 -0
- package/dist/container.js.map +1 -0
- package/dist/database/index.d.ts +3 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +19 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/pg-connection-loader.d.ts +6 -0
- package/dist/database/pg-connection-loader.d.ts.map +1 -0
- package/dist/database/pg-connection-loader.js +37 -0
- package/dist/database/pg-connection-loader.js.map +1 -0
- package/dist/eto-app-loader.d.ts +51 -0
- package/dist/eto-app-loader.d.ts.map +1 -0
- package/dist/eto-app-loader.js +183 -0
- package/dist/eto-app-loader.js.map +1 -0
- package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
- package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
- package/dist/feature-flags/feature-flag-loader.js +81 -0
- package/dist/feature-flags/feature-flag-loader.js.map +1 -0
- package/dist/feature-flags/flag-router.d.ts +32 -0
- package/dist/feature-flags/flag-router.d.ts.map +1 -0
- package/dist/feature-flags/flag-router.js +67 -0
- package/dist/feature-flags/flag-router.js.map +1 -0
- package/dist/feature-flags/index.d.ts +5 -0
- package/dist/feature-flags/index.d.ts.map +1 -0
- package/dist/feature-flags/index.js +21 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/feature-flags/types.d.ts +31 -0
- package/dist/feature-flags/types.d.ts.map +1 -0
- package/dist/feature-flags/types.js +3 -0
- package/dist/feature-flags/types.js.map +1 -0
- package/dist/http/express-loader.d.ts +8 -0
- package/dist/http/express-loader.d.ts.map +1 -0
- package/dist/http/express-loader.js +85 -0
- package/dist/http/express-loader.js.map +1 -0
- package/dist/http/index.d.ts +15 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +31 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middlewares/apply-default-filters.d.ts +3 -0
- package/dist/http/middlewares/apply-default-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-default-filters.js +32 -0
- package/dist/http/middlewares/apply-default-filters.js.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts +5 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.js +14 -0
- package/dist/http/middlewares/apply-params-as-filters.js.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts +11 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.js +135 -0
- package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.js +12 -0
- package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js +49 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
- package/dist/http/middlewares/error-handler.d.ts +23 -0
- package/dist/http/middlewares/error-handler.d.ts.map +1 -0
- package/dist/http/middlewares/error-handler.js +85 -0
- package/dist/http/middlewares/error-handler.js.map +1 -0
- package/dist/http/middlewares/exception-formatter.d.ts +9 -0
- package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
- package/dist/http/middlewares/exception-formatter.js +36 -0
- package/dist/http/middlewares/exception-formatter.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +8 -0
- package/dist/http/middlewares/index.d.ts.map +1 -0
- package/dist/http/middlewares/index.js +24 -0
- package/dist/http/middlewares/index.js.map +1 -0
- package/dist/http/middlewares/set-context.d.ts +3 -0
- package/dist/http/middlewares/set-context.d.ts.map +1 -0
- package/dist/http/middlewares/set-context.js +18 -0
- package/dist/http/middlewares/set-context.js.map +1 -0
- package/dist/http/router.d.ts +100 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +764 -0
- package/dist/http/router.js.map +1 -0
- package/dist/http/types.d.ts +141 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +16 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/utils/define-middlewares.d.ts +18 -0
- package/dist/http/utils/define-middlewares.d.ts.map +1 -0
- package/dist/http/utils/define-middlewares.js +40 -0
- package/dist/http/utils/define-middlewares.js.map +1 -0
- package/dist/http/utils/get-query-config.d.ts +42 -0
- package/dist/http/utils/get-query-config.d.ts.map +1 -0
- package/dist/http/utils/get-query-config.js +183 -0
- package/dist/http/utils/get-query-config.js.map +1 -0
- package/dist/http/utils/http-compression.d.ts +5 -0
- package/dist/http/utils/http-compression.d.ts.map +1 -0
- package/dist/http/utils/http-compression.js +33 -0
- package/dist/http/utils/http-compression.js.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.js +71 -0
- package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
- package/dist/http/utils/refetch-entities.d.ts +5 -0
- package/dist/http/utils/refetch-entities.d.ts.map +1 -0
- package/dist/http/utils/refetch-entities.js +29 -0
- package/dist/http/utils/refetch-entities.js.map +1 -0
- package/dist/http/utils/restricted-fields.d.ts +6 -0
- package/dist/http/utils/restricted-fields.d.ts.map +1 -0
- package/dist/http/utils/restricted-fields.js +30 -0
- package/dist/http/utils/restricted-fields.js.map +1 -0
- package/dist/http/utils/unless-path.d.ts +9 -0
- package/dist/http/utils/unless-path.d.ts.map +1 -0
- package/dist/http/utils/unless-path.js +19 -0
- package/dist/http/utils/unless-path.js.map +1 -0
- package/dist/http/utils/validate-body.d.ts +5 -0
- package/dist/http/utils/validate-body.d.ts.map +1 -0
- package/dist/http/utils/validate-body.js +23 -0
- package/dist/http/utils/validate-body.js.map +1 -0
- package/dist/http/utils/validate-query.d.ts +6 -0
- package/dist/http/utils/validate-query.d.ts.map +1 -0
- package/dist/http/utils/validate-query.js +79 -0
- package/dist/http/utils/validate-query.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/index.d.ts +2 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +18 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/job-loader.d.ts +37 -0
- package/dist/jobs/job-loader.d.ts.map +1 -0
- package/dist/jobs/job-loader.js +130 -0
- package/dist/jobs/job-loader.js.map +1 -0
- package/dist/links/index.d.ts +2 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/index.js +18 -0
- package/dist/links/index.js.map +1 -0
- package/dist/links/link-loader.d.ts +10 -0
- package/dist/links/link-loader.d.ts.map +1 -0
- package/dist/links/link-loader.js +74 -0
- package/dist/links/link-loader.js.map +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +9 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/mikro-orm-cli/bin.d.ts +14 -0
- package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
- package/dist/mikro-orm-cli/bin.js +54 -0
- package/dist/mikro-orm-cli/bin.js.map +1 -0
- package/dist/modules-sdk/index.d.ts +2 -0
- package/dist/modules-sdk/index.d.ts.map +1 -0
- package/dist/modules-sdk/index.js +18 -0
- package/dist/modules-sdk/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +2 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +18 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/subscribers/index.d.ts +3 -0
- package/dist/subscribers/index.d.ts.map +1 -0
- package/dist/subscribers/index.js +19 -0
- package/dist/subscribers/index.js.map +1 -0
- package/dist/subscribers/subscriber-loader.d.ts +11 -0
- package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
- package/dist/subscribers/subscriber-loader.js +196 -0
- package/dist/subscribers/subscriber-loader.js.map +1 -0
- package/dist/subscribers/types.d.ts +15 -0
- package/dist/subscribers/types.d.ts.map +1 -0
- package/dist/subscribers/types.js +3 -0
- package/dist/subscribers/types.js.map +1 -0
- package/dist/telemetry/index.d.ts +50 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +81 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/types/container.d.ts +62 -0
- package/dist/types/container.d.ts.map +1 -0
- package/dist/types/container.js +3 -0
- package/dist/types/container.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/workflows/index.d.ts +3 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +19 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/workflow-loader.d.ts +10 -0
- package/dist/workflows/workflow-loader.d.ts.map +1 -0
- package/dist/workflows/workflow-loader.js +74 -0
- package/dist/workflows/workflow-loader.js.map +1 -0
- package/dist/workflows-sdk/composer.d.ts +2 -0
- package/dist/workflows-sdk/composer.d.ts.map +1 -0
- package/dist/workflows-sdk/composer.js +18 -0
- package/dist/workflows-sdk/composer.js.map +1 -0
- package/dist/workflows-sdk/index.d.ts +3 -0
- package/dist/workflows-sdk/index.d.ts.map +1 -0
- package/dist/workflows-sdk/index.js +19 -0
- package/dist/workflows-sdk/index.js.map +1 -0
- package/dist/zod/index.d.ts +2 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +18 -0
- package/dist/zod/index.js.map +1 -0
- package/dist/zod/zod-helpers.d.ts +3 -0
- package/dist/zod/zod-helpers.d.ts.map +1 -0
- package/dist/zod/zod-helpers.js +95 -0
- package/dist/zod/zod-helpers.js.map +1 -0
- package/package.json +120 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = errorHandler;
|
|
4
|
+
const utils_1 = require("@etohq/utils");
|
|
5
|
+
const exception_formatter_1 = require("./exception-formatter");
|
|
6
|
+
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError";
|
|
7
|
+
const TRANSACTION_STARTED = "TransactionAlreadyStartedError";
|
|
8
|
+
const TRANSACTION_NOT_STARTED = "TransactionNotStartedError";
|
|
9
|
+
const API_ERROR = "api_error";
|
|
10
|
+
const INVALID_REQUEST_ERROR = "invalid_request_error";
|
|
11
|
+
const INVALID_STATE_ERROR = "invalid_state_error";
|
|
12
|
+
function errorHandler() {
|
|
13
|
+
return (err, req, res, next) => {
|
|
14
|
+
const logger = req.scope.resolve(utils_1.ContainerRegistrationKeys.LOGGER);
|
|
15
|
+
err = (0, exception_formatter_1.formatException)(err);
|
|
16
|
+
logger.error(err);
|
|
17
|
+
const errorType = err.type || err.name;
|
|
18
|
+
const errObj = {
|
|
19
|
+
code: err.code,
|
|
20
|
+
type: err.type,
|
|
21
|
+
message: err.message,
|
|
22
|
+
};
|
|
23
|
+
let statusCode = 500;
|
|
24
|
+
switch (errorType) {
|
|
25
|
+
case QUERY_RUNNER_RELEASED:
|
|
26
|
+
case TRANSACTION_STARTED:
|
|
27
|
+
case TRANSACTION_NOT_STARTED:
|
|
28
|
+
case utils_1.EtoError.Types.CONFLICT:
|
|
29
|
+
statusCode = 409;
|
|
30
|
+
errObj.code = INVALID_STATE_ERROR;
|
|
31
|
+
errObj.message =
|
|
32
|
+
"The request conflicted with another request. You may retry the request with the provided Idempotency-Key.";
|
|
33
|
+
break;
|
|
34
|
+
case utils_1.EtoError.Types.UNAUTHORIZED:
|
|
35
|
+
statusCode = 401;
|
|
36
|
+
break;
|
|
37
|
+
case utils_1.EtoError.Types.PAYMENT_AUTHORIZATION_ERROR:
|
|
38
|
+
statusCode = 422;
|
|
39
|
+
break;
|
|
40
|
+
case utils_1.EtoError.Types.DUPLICATE_ERROR:
|
|
41
|
+
statusCode = 422;
|
|
42
|
+
errObj.code = INVALID_REQUEST_ERROR;
|
|
43
|
+
break;
|
|
44
|
+
case utils_1.EtoError.Types.NOT_ALLOWED:
|
|
45
|
+
case utils_1.EtoError.Types.INVALID_DATA:
|
|
46
|
+
statusCode = 400;
|
|
47
|
+
break;
|
|
48
|
+
case utils_1.EtoError.Types.NOT_FOUND:
|
|
49
|
+
statusCode = 404;
|
|
50
|
+
break;
|
|
51
|
+
case utils_1.EtoError.Types.DB_ERROR:
|
|
52
|
+
statusCode = 500;
|
|
53
|
+
errObj.code = API_ERROR;
|
|
54
|
+
break;
|
|
55
|
+
case utils_1.EtoError.Types.UNEXPECTED_STATE:
|
|
56
|
+
case utils_1.EtoError.Types.INVALID_ARGUMENT:
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
errObj.code = "unknown_error";
|
|
60
|
+
errObj.message = "An unknown error occurred.";
|
|
61
|
+
errObj.type = "unknown_error";
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
res.status(statusCode).json(errObj);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @schema Error
|
|
69
|
+
* title: "Response Error"
|
|
70
|
+
* type: object
|
|
71
|
+
* properties:
|
|
72
|
+
* code:
|
|
73
|
+
* type: string
|
|
74
|
+
* description: A slug code to indicate the type of the error.
|
|
75
|
+
* enum: [invalid_state_error, invalid_request_error, api_error, unknown_error]
|
|
76
|
+
* message:
|
|
77
|
+
* type: string
|
|
78
|
+
* description: Description of the error that occurred.
|
|
79
|
+
* example: "first_name must be a string"
|
|
80
|
+
* type:
|
|
81
|
+
* type: string
|
|
82
|
+
* description: A slug indicating the type of the error.
|
|
83
|
+
* enum: [QueryRunnerAlreadyReleasedError, TransactionAlreadyStartedError, TransactionNotStartedError, conflict, unauthorized, payment_authorization_error, duplicate_error, not_allowed, invalid_data, not_found, database_error, unexpected_state, invalid_argument, unknown_error]
|
|
84
|
+
*/
|
|
85
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/http/middlewares/error-handler.ts"],"names":[],"mappings":";;AAcA,oCAiEC;AA7ED,wCAAkE;AAClE,+DAAuD;AAGvD,MAAM,qBAAqB,GAAG,iCAAiC,CAAA;AAC/D,MAAM,mBAAmB,GAAG,gCAAgC,CAAA;AAC5D,MAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAE5D,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,qBAAqB,GAAG,u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K,CAAC,WAAW,CAAC;YAChC,KAAK,gBAAQ,CAAC,KAAK,CAAC,YAAY;gBAC9B,UAAU,GAAG,GAAG,CAAA;gBAChB,MAAK;YACP,KAAK,gBAAQ,CAAC,KAAK,CAAC,SAAS;gBAC3B,UAAU,GAAG,GAAG,CAAA;gBAChB,MAAK;YACP,KAAK,gBAAQ,CAAC,KAAK,CAAC,QAAQ;gBAC1B,UAAU,GAAG,GAAG,CAAA;gBAChB,MAAM,CAAC,IAAI,GAAG,SAAS,CAAA;gBACvB,MAAK;YACP,KAAK,gBAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC;YACrC,KAAK,gBAAQ,CAAC,KAAK,CAAC,gBAAgB;gBAClC,MAAK;YACP;gBACE,MAAM,CAAC,IAAI,GAAG,eAAe,CAAA;gBAC7B,MAAM,CAAC,OAAO,GAAG,4BAA4B,CAAA;gBAC7C,MAAM,CAAC,IAAI,GAAG,eAAe,CAAA;gBAC7B,MAAK;QACT,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EtoError } from "@etohq/utils";
|
|
2
|
+
export declare enum PostgresError {
|
|
3
|
+
DUPLICATE_ERROR = "23505",
|
|
4
|
+
FOREIGN_KEY_ERROR = "23503",
|
|
5
|
+
SERIALIZATION_FAILURE = "40001",
|
|
6
|
+
NULL_VIOLATION = "23502"
|
|
7
|
+
}
|
|
8
|
+
export declare const formatException: (err: any) => EtoError;
|
|
9
|
+
//# sourceMappingURL=exception-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-formatter.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/exception-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,oBAAY,aAAa;IACvB,eAAe,UAAU;IACzB,iBAAiB,UAAU;IAC3B,qBAAqB,UAAU;IAC/B,cAAc,UAAU;CACzB;AAED,eAAO,MAAM,eAAe,gBAAU,QA8CrC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatException = exports.PostgresError = void 0;
|
|
4
|
+
const utils_1 = require("@etohq/utils");
|
|
5
|
+
var PostgresError;
|
|
6
|
+
(function (PostgresError) {
|
|
7
|
+
PostgresError["DUPLICATE_ERROR"] = "23505";
|
|
8
|
+
PostgresError["FOREIGN_KEY_ERROR"] = "23503";
|
|
9
|
+
PostgresError["SERIALIZATION_FAILURE"] = "40001";
|
|
10
|
+
PostgresError["NULL_VIOLATION"] = "23502";
|
|
11
|
+
})(PostgresError || (exports.PostgresError = PostgresError = {}));
|
|
12
|
+
const formatException = (err) => {
|
|
13
|
+
switch (err.code) {
|
|
14
|
+
case PostgresError.DUPLICATE_ERROR:
|
|
15
|
+
return new utils_1.EtoError(utils_1.EtoError.Types.DUPLICATE_ERROR, `${err.table.charAt(0).toUpperCase()}${err.table.slice(1)} with ${err.detail.slice(4).replace(/[()=]/g, (s) => {
|
|
16
|
+
return s === "=" ? " " : "";
|
|
17
|
+
})}`);
|
|
18
|
+
case PostgresError.FOREIGN_KEY_ERROR: {
|
|
19
|
+
const matches = /Key \(([\w-\d]+)\)=\(([\w-\d]+)\) is not present in table "(\w+)"/g.exec(err.detail);
|
|
20
|
+
if (matches?.length !== 4) {
|
|
21
|
+
return new utils_1.EtoError(utils_1.EtoError.Types.NOT_FOUND, JSON.stringify(matches));
|
|
22
|
+
}
|
|
23
|
+
return new utils_1.EtoError(utils_1.EtoError.Types.NOT_FOUND, `${matches[3]?.charAt(0).toUpperCase()}${matches[3]?.slice(1)} with ${matches[1]} ${matches[2]} does not exist.`);
|
|
24
|
+
}
|
|
25
|
+
case PostgresError.SERIALIZATION_FAILURE: {
|
|
26
|
+
return new utils_1.EtoError(utils_1.EtoError.Types.CONFLICT, err?.detail ?? err?.message);
|
|
27
|
+
}
|
|
28
|
+
case PostgresError.NULL_VIOLATION: {
|
|
29
|
+
return new utils_1.EtoError(utils_1.EtoError.Types.INVALID_DATA, `Can't insert null value in field ${err?.column} on insert in table ${err?.table}`);
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.formatException = formatException;
|
|
36
|
+
//# sourceMappingURL=exception-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-formatter.js","sourceRoot":"","sources":["../../../src/http/middlewares/exception-formatter.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAEvC,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,0CAAyB,CAAA;IACzB,4CAA2B,CAAA;IAC3B,gDAA+B,CAAA;IAC/B,yCAAwB,CAAA;AAC1B,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB;AAEM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAY,EAAE;IAC/C,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,aAAa,CAAC,eAAe;YAChC,OAAO,IAAI,gBAAQ,CACjB,gBAAQ,CAAC,KAAK,CAAC,eAAe,EAC9B,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CACpD,CAAC,CACF,SAAS,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpD,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;YAC7B,CAAC,CAAC,EAAE,CACL,CAAA;QACH,KAAK,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC;YACrC,MAAM,OAAO,GACX,oEAAoE,CAAC,IAAI,CACvE,GAAG,CAAC,MAAM,CACX,CAAA;YAEH,IAAI,OAAO,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO,IAAI,gBAAQ,CACjB,gBAAQ,CAAC,KAAK,CAAC,SAAS,EACxB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CACxB,CAAA;YACH,CAAC;YAED,OAAO,IAAI,gBAAQ,CACjB,gBAAQ,CAAC,KAAK,CAAC,SAAS,EACxB,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,SAC3D,OAAO,CAAC,CAAC,CACX,IAAI,OAAO,CAAC,CAAC,CAAC,kBAAkB,CACjC,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACzC,OAAO,IAAI,gBAAQ,CACjB,gBAAQ,CAAC,KAAK,CAAC,QAAQ,EACvB,GAAG,EAAE,MAAM,IAAI,GAAG,EAAE,OAAO,CAC5B,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;YAClC,OAAO,IAAI,gBAAQ,CACjB,gBAAQ,CAAC,KAAK,CAAC,YAAY,EAC3B,oCAAoC,GAAG,EAAE,MAAM,uBAAuB,GAAG,EAAE,KAAK,EAAE,CACnF,CAAA;QACH,CAAC;QACD;YACE,OAAO,GAAG,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AA9CY,QAAA,eAAe,mBA8C3B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./authenticate-middleware";
|
|
2
|
+
export * from "./error-handler";
|
|
3
|
+
export * from "./exception-formatter";
|
|
4
|
+
export * from "./apply-default-filters";
|
|
5
|
+
export * from "./apply-params-as-filters";
|
|
6
|
+
export * from "./clear-filters-by-key";
|
|
7
|
+
export * from "./set-context";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./authenticate-middleware"), exports);
|
|
18
|
+
__exportStar(require("./error-handler"), exports);
|
|
19
|
+
__exportStar(require("./exception-formatter"), exports);
|
|
20
|
+
__exportStar(require("./apply-default-filters"), exports);
|
|
21
|
+
__exportStar(require("./apply-params-as-filters"), exports);
|
|
22
|
+
__exportStar(require("./clear-filters-by-key"), exports);
|
|
23
|
+
__exportStar(require("./set-context"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAyC;AACzC,kDAA+B;AAC/B,wDAAqC;AACrC,0DAAuC;AACvC,4DAAyC;AACzC,yDAAsC;AACtC,gDAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-context.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/set-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEtD,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAClC,UAAU,gBAAW,eAAe,mBAiBxD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setContext = setContext;
|
|
4
|
+
function setContext(context) {
|
|
5
|
+
return async (req, _, next) => {
|
|
6
|
+
const ctx = { ...(req.context || {}) };
|
|
7
|
+
for (const [contextKey, contextValue] of Object.entries(context || {})) {
|
|
8
|
+
let valueToApply = contextValue;
|
|
9
|
+
if (typeof contextValue === "function") {
|
|
10
|
+
valueToApply = await contextValue(req, ctx);
|
|
11
|
+
}
|
|
12
|
+
ctx[contextKey] = valueToApply;
|
|
13
|
+
}
|
|
14
|
+
req.context = ctx;
|
|
15
|
+
return next();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=set-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-context.js","sourceRoot":"","sources":["../../../src/http/middlewares/set-context.ts"],"names":[],"mappings":";;AAEA,gCAkBC;AAlBD,SAAgB,UAAU,CAAC,OAA4B;IACrD,OAAO,KAAK,EAAE,GAAe,EAAE,CAAC,EAAE,IAAqB,EAAE,EAAE;QACzD,MAAM,GAAG,GAAwB,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAA;QAE3D,KAAK,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;YACvE,IAAI,YAAY,GAAG,YAAY,CAAA;YAE/B,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE,CAAC;gBACvC,YAAY,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAC7C,CAAC;YAED,GAAG,CAAC,UAAU,CAAC,GAAG,YAAY,CAAA;QAChC,CAAC;QAED,GAAG,CAAC,OAAO,GAAG,GAAG,CAAA;QAEjB,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Express, RequestHandler } from "express";
|
|
2
|
+
import { AuthType } from "./middlewares";
|
|
3
|
+
import { MiddlewareFunction, MiddlewaresConfig, RouteHandler, RouteVerb } from "./types";
|
|
4
|
+
export declare class ApiRoutesLoader {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Wrap the original route handler implementation for
|
|
8
|
+
* instrumentation.
|
|
9
|
+
*/
|
|
10
|
+
static traceRoute?: (handler: RouteHandler, route: {
|
|
11
|
+
route: string;
|
|
12
|
+
method: string;
|
|
13
|
+
}) => RouteHandler;
|
|
14
|
+
/**
|
|
15
|
+
* Wrap the original middleware handler implementation for
|
|
16
|
+
* instrumentation.
|
|
17
|
+
*/
|
|
18
|
+
static traceMiddleware?: (handler: RequestHandler | MiddlewareFunction, route: {
|
|
19
|
+
route: string;
|
|
20
|
+
method?: string;
|
|
21
|
+
}) => RequestHandler | MiddlewareFunction;
|
|
22
|
+
constructor({ app, activityId, sourceDir, }: {
|
|
23
|
+
app: Express;
|
|
24
|
+
activityId?: string;
|
|
25
|
+
sourceDir: string;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Validate the route config and display a log info if
|
|
29
|
+
* it should be ignored or skipped.
|
|
30
|
+
*
|
|
31
|
+
* @param {GlobalMiddlewareDescriptor} descriptor
|
|
32
|
+
* @param {MiddlewaresConfig} config
|
|
33
|
+
*
|
|
34
|
+
* @return {void}
|
|
35
|
+
*/
|
|
36
|
+
protected validateMiddlewaresConfig({ config, }: {
|
|
37
|
+
config?: MiddlewaresConfig;
|
|
38
|
+
}): void;
|
|
39
|
+
/**
|
|
40
|
+
* Take care of replacing the special path segments
|
|
41
|
+
* to an express specific path segment
|
|
42
|
+
*
|
|
43
|
+
* @param route - The route to parse
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* "/admin/orders/[id]/route.ts => "/admin/orders/:id/route.ts"
|
|
47
|
+
*/
|
|
48
|
+
protected parseRoute(route: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Load the file content from a descriptor and retrieve the verbs and handlers
|
|
51
|
+
* to be assigned to the descriptor
|
|
52
|
+
*
|
|
53
|
+
* @return {Promise<void>}
|
|
54
|
+
*/
|
|
55
|
+
protected createRoutesConfig(): Promise<void>;
|
|
56
|
+
protected createRoutesDescriptor(path: string): void;
|
|
57
|
+
protected createMiddlewaresDescriptor(): Promise<void>;
|
|
58
|
+
protected createRoutesMap(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Apply the most specific body parser middleware to the router
|
|
61
|
+
*/
|
|
62
|
+
applyBodyParserMiddleware(path: string, method: RouteVerb): void;
|
|
63
|
+
/**
|
|
64
|
+
* Applies middleware that checks if a valid publishable key is set on store request
|
|
65
|
+
*/
|
|
66
|
+
applyStorePublishableKeyMiddleware(route: string | RegExp): void;
|
|
67
|
+
/**
|
|
68
|
+
* Applies the route middleware on a route. Encapsulates the logic
|
|
69
|
+
* needed to pass the middleware via the trace calls
|
|
70
|
+
*/
|
|
71
|
+
applyAuthMiddleware(route: string | RegExp, actorType: string | string[], authType: AuthType | AuthType[], options?: {
|
|
72
|
+
allowUnauthenticated?: boolean;
|
|
73
|
+
allowUnregistered?: boolean;
|
|
74
|
+
}): void;
|
|
75
|
+
/**
|
|
76
|
+
* Apply the route specific middlewares to the router,
|
|
77
|
+
* this includes the cors, authentication and
|
|
78
|
+
* body parsing. These are applied first to ensure
|
|
79
|
+
* that they are applied before any other middleware.
|
|
80
|
+
*/
|
|
81
|
+
applyRouteSpecificMiddlewares(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Apply the error handler middleware to the router
|
|
84
|
+
*/
|
|
85
|
+
applyErrorHandlerMiddleware(): void;
|
|
86
|
+
protected registerRoutes(): Promise<void>;
|
|
87
|
+
protected registerMiddlewares(): Promise<void>;
|
|
88
|
+
load(): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
export declare class RoutesLoader {
|
|
91
|
+
#private;
|
|
92
|
+
constructor({ app, activityId, sourceDir, baseRestrictedFields, }: {
|
|
93
|
+
app: Express;
|
|
94
|
+
activityId?: string;
|
|
95
|
+
sourceDir: string | string[];
|
|
96
|
+
baseRestrictedFields?: string[];
|
|
97
|
+
});
|
|
98
|
+
load(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/http/router.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,OAAO,EAEZ,cAAc,EAIf,MAAM,SAAS,CAAA;AAMhB,OAAO,EAAgB,QAAQ,EAAgB,MAAM,eAAe,CAAA;AAEpE,OAAO,EAML,kBAAkB,EAElB,iBAAiB,EAKjB,YAAY,EACZ,SAAS,EACV,MAAM,SAAS,CAAA;AA0LhB,qBAAa,eAAe;;IA+C1B;;;OAGG;IACH,MAAM,CAAC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