@getstrata/core 0.5.40 → 0.5.42
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/dist/core/cache/simpleCache.d.ts +1 -0
- package/dist/core/cache/simpleCacheStore.d.ts +1 -0
- package/dist/core/database/baseRepository.d.ts +1 -0
- package/dist/core/queue/failedJobRepository.d.ts +1 -0
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/entries/audit/exportAuditLogs.js +18 -0
- package/dist/entries/auth/sessionGuard.js +443 -0
- package/dist/entries/cache/simpleCache.js +178 -0
- package/dist/entries/cache/simpleCacheStore.js +42 -0
- package/dist/entries/database/baseRepository.js +1388 -0
- package/dist/entries/database/bindConnection.js +22 -0
- package/dist/entries/database/boundConnection.js +19 -0
- package/dist/entries/database/connection.js +12 -0
- package/dist/entries/database/errors.js +128 -0
- package/dist/entries/database/model.js +948 -0
- package/dist/entries/database/query.js +436 -0
- package/dist/entries/database/relationships.js +162 -0
- package/dist/entries/database/table.js +8 -0
- package/dist/entries/database/transaction.js +129 -0
- package/dist/entries/http/authMiddleware.js +47 -0
- package/dist/entries/http/authorizeMiddleware.js +104 -0
- package/dist/entries/http/metricsMiddleware.js +91 -0
- package/dist/entries/http/parseMultipartUpload.js +144 -0
- package/dist/entries/http/securedRouteModelBinding.js +6 -0
- package/dist/entries/http/webErrorResponse.js +443 -0
- package/dist/entries/http/webFormRequest.js +6 -0
- package/dist/entries/jobs/dispatchWebhookJob.js +18 -0
- package/dist/entries/queue/createAppQueue.js +449 -0
- package/dist/entries/queue/failedJobRepository.js +2306 -0
- package/dist/entries/queue/failedJobService.js +3 -0
- package/dist/entries/queue/publicQueue.js +449 -0
- package/dist/entries/queue/queueMetrics.js +449 -0
- package/dist/entries/queue/redisQueue.js +232 -0
- package/dist/entries/security/scimTenantTokens.js +51 -0
- package/dist/entries/tenant/tenantDatabaseScope.js +113 -0
- package/dist/entries/view.js +443 -0
- package/package.json +102 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/database/boundConnection.ts
|
|
3
|
+
var boundConnectionHolder = {
|
|
4
|
+
connection: null
|
|
5
|
+
};
|
|
6
|
+
function bindDatabaseConnection(connection) {
|
|
7
|
+
boundConnectionHolder.connection = connection;
|
|
8
|
+
}
|
|
9
|
+
function getBoundDatabaseConnection() {
|
|
10
|
+
return boundConnectionHolder.connection;
|
|
11
|
+
}
|
|
12
|
+
function resetBoundDatabaseConnection() {
|
|
13
|
+
boundConnectionHolder.connection = null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ../../src/core/database/bindConnection.ts
|
|
17
|
+
function bindDatabaseConnection2(connection) {
|
|
18
|
+
bindDatabaseConnection(connection);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
bindDatabaseConnection2 as bindDatabaseConnection
|
|
22
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/database/boundConnection.ts
|
|
3
|
+
var boundConnectionHolder = {
|
|
4
|
+
connection: null
|
|
5
|
+
};
|
|
6
|
+
function bindDatabaseConnection(connection) {
|
|
7
|
+
boundConnectionHolder.connection = connection;
|
|
8
|
+
}
|
|
9
|
+
function getBoundDatabaseConnection() {
|
|
10
|
+
return boundConnectionHolder.connection;
|
|
11
|
+
}
|
|
12
|
+
function resetBoundDatabaseConnection() {
|
|
13
|
+
boundConnectionHolder.connection = null;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
resetBoundDatabaseConnection,
|
|
17
|
+
getBoundDatabaseConnection,
|
|
18
|
+
bindDatabaseConnection
|
|
19
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/errors/http.ts
|
|
3
|
+
class HttpError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
details;
|
|
6
|
+
constructor(status, message, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = new.target.name;
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.details = details;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class BadRequestError extends HttpError {
|
|
15
|
+
constructor(message = "Bad Request", details) {
|
|
16
|
+
super(400, message, details);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class NotFoundError extends HttpError {
|
|
21
|
+
constructor(message = "Not Found", details) {
|
|
22
|
+
super(404, message, details);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class ConflictError extends HttpError {
|
|
27
|
+
constructor(message = "Conflict", details) {
|
|
28
|
+
super(409, message, details);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class UnprocessableEntityError extends HttpError {
|
|
33
|
+
constructor(message = "Unprocessable Entity", details) {
|
|
34
|
+
super(422, message, details);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class ValidationError extends HttpError {
|
|
39
|
+
constructor(message = "Validation failed", details) {
|
|
40
|
+
super(422, message, details);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class ForbiddenError extends HttpError {
|
|
45
|
+
constructor(message = "Forbidden", details) {
|
|
46
|
+
super(403, message, details);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class UnauthorizedError extends HttpError {
|
|
51
|
+
constructor(message = "Unauthorized", details) {
|
|
52
|
+
super(401, message, details);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class PayloadTooLargeError extends HttpError {
|
|
57
|
+
constructor(message = "Payload Too Large", details) {
|
|
58
|
+
super(413, message, details);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class PreconditionFailedError extends HttpError {
|
|
63
|
+
constructor(message = "Precondition Failed", details) {
|
|
64
|
+
super(412, message, details);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ../../src/core/database/errors.ts
|
|
69
|
+
function isPostgresError(error) {
|
|
70
|
+
return typeof error === "object" && error !== null && (("errno" in error) || ("code" in error));
|
|
71
|
+
}
|
|
72
|
+
function getPostgresSqlState(error) {
|
|
73
|
+
if (typeof error.errno === "string" && /^\d{5}$/.test(error.errno)) {
|
|
74
|
+
return error.errno;
|
|
75
|
+
}
|
|
76
|
+
if (typeof error.errno === "number") {
|
|
77
|
+
return String(error.errno).padStart(5, "0");
|
|
78
|
+
}
|
|
79
|
+
if (typeof error.code === "string" && /^\d{5}$/.test(error.code)) {
|
|
80
|
+
return error.code;
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
function mapDatabaseError(error) {
|
|
85
|
+
if (error instanceof HttpError) {
|
|
86
|
+
return error;
|
|
87
|
+
}
|
|
88
|
+
if (!isPostgresError(error)) {
|
|
89
|
+
const message = error instanceof Error ? error.message : "Database operation failed.";
|
|
90
|
+
return new BadRequestError(message);
|
|
91
|
+
}
|
|
92
|
+
const sqlState = getPostgresSqlState(error);
|
|
93
|
+
switch (sqlState) {
|
|
94
|
+
case "23505":
|
|
95
|
+
return new ConflictError(error.detail ?? "A record with these values already exists.", {
|
|
96
|
+
constraint: error.constraint
|
|
97
|
+
});
|
|
98
|
+
case "23503":
|
|
99
|
+
return new UnprocessableEntityError(error.detail ?? "Referenced record does not exist.", {
|
|
100
|
+
constraint: error.constraint
|
|
101
|
+
});
|
|
102
|
+
case "23502":
|
|
103
|
+
return new BadRequestError(error.detail ?? "Required field is missing.", {
|
|
104
|
+
constraint: error.constraint
|
|
105
|
+
});
|
|
106
|
+
case "23514":
|
|
107
|
+
return new BadRequestError(error.detail ?? "Value violates a database constraint.", {
|
|
108
|
+
constraint: error.constraint
|
|
109
|
+
});
|
|
110
|
+
default:
|
|
111
|
+
return new BadRequestError(error.message ?? "Database operation failed.", {
|
|
112
|
+
code: error.code,
|
|
113
|
+
sqlState
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function withDatabaseErrorHandling(operation) {
|
|
118
|
+
try {
|
|
119
|
+
return await operation();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw mapDatabaseError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
withDatabaseErrorHandling,
|
|
126
|
+
mapDatabaseError,
|
|
127
|
+
isPostgresError
|
|
128
|
+
};
|