@arkyn/server 2.0.1-beta.0 → 2.0.1-beta.10
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/http/badResponses/badGateway.d.ts +11 -0
- package/dist/http/badResponses/badGateway.d.ts.map +1 -0
- package/dist/http/badResponses/badGateway.js +29 -0
- package/dist/http/badResponses/badRequest.d.ts +11 -0
- package/dist/http/badResponses/badRequest.d.ts.map +1 -0
- package/dist/http/badResponses/badRequest.js +29 -0
- package/dist/http/badResponses/conflict.d.ts +11 -0
- package/dist/http/badResponses/conflict.d.ts.map +1 -0
- package/dist/http/badResponses/conflict.js +29 -0
- package/dist/http/badResponses/forbidden.d.ts +11 -0
- package/dist/http/badResponses/forbidden.d.ts.map +1 -0
- package/dist/http/badResponses/forbidden.js +29 -0
- package/dist/http/badResponses/notFound.d.ts +11 -0
- package/dist/http/badResponses/notFound.d.ts.map +1 -0
- package/dist/http/badResponses/notFound.js +29 -0
- package/dist/http/badResponses/notImplemented.d.ts +11 -0
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -0
- package/dist/http/badResponses/notImplemented.js +29 -0
- package/dist/http/badResponses/serverError.d.ts +11 -0
- package/dist/http/badResponses/serverError.d.ts.map +1 -0
- package/dist/http/badResponses/serverError.js +29 -0
- package/dist/http/badResponses/unauthorized.d.ts +11 -0
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -0
- package/dist/http/badResponses/unauthorized.js +29 -0
- package/dist/http/badResponses/unprocessableEntity.d.ts +16 -0
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -0
- package/dist/http/badResponses/unprocessableEntity.js +33 -0
- package/dist/http/successResponses/created.d.ts +11 -0
- package/dist/http/successResponses/created.d.ts.map +1 -0
- package/dist/http/successResponses/created.js +29 -0
- package/dist/http/successResponses/found.d.ts +11 -0
- package/dist/http/successResponses/found.d.ts.map +1 -0
- package/dist/http/successResponses/found.js +29 -0
- package/dist/http/successResponses/noContent.d.ts +10 -0
- package/dist/http/successResponses/noContent.d.ts.map +1 -0
- package/dist/http/successResponses/noContent.js +27 -0
- package/dist/http/successResponses/success.d.ts +11 -0
- package/dist/http/successResponses/success.d.ts.map +1 -0
- package/dist/http/successResponses/success.js +29 -0
- package/dist/http/successResponses/updated.d.ts +11 -0
- package/dist/http/successResponses/updated.d.ts.map +1 -0
- package/dist/http/successResponses/updated.js +29 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/services/decodeRequestBody.d.ts +17 -0
- package/dist/services/decodeRequestBody.d.ts.map +1 -0
- package/dist/services/decodeRequestBody.js +42 -0
- package/dist/services/errorHandler.d.ts +3 -0
- package/dist/services/errorHandler.d.ts.map +1 -0
- package/dist/services/errorHandler.js +51 -0
- package/dist/services/formParse.d.ts +42 -0
- package/dist/services/formParse.d.ts.map +1 -0
- package/dist/services/formParse.js +54 -0
- package/dist/services/getCaller.d.ts +6 -0
- package/dist/services/getCaller.d.ts.map +1 -0
- package/dist/services/getCaller.js +29 -0
- package/dist/services/getScopedParams.d.ts +28 -0
- package/dist/services/getScopedParams.d.ts.map +1 -0
- package/dist/services/getScopedParams.js +34 -0
- package/dist/services/httpDebug.d.ts +3 -0
- package/dist/services/httpDebug.d.ts.map +1 -0
- package/dist/services/httpDebug.js +18 -0
- package/dist/services/schemaValidator.d.ts +13 -0
- package/dist/services/schemaValidator.d.ts.map +1 -0
- package/dist/services/schemaValidator.js +51 -0
- package/dist/services/sendFileToS3.d.ts +52 -0
- package/dist/services/sendFileToS3.d.ts.map +1 -0
- package/dist/services/sendFileToS3.js +143 -0
- package/package.json +4 -2
- package/src/http/badResponses/badGateway.ts +36 -0
- package/src/http/badResponses/badRequest.ts +36 -0
- package/src/http/badResponses/conflict.ts +36 -0
- package/src/http/badResponses/forbidden.ts +36 -0
- package/src/http/badResponses/notFound.ts +36 -0
- package/src/http/badResponses/notImplemented.ts +36 -0
- package/src/http/badResponses/serverError.ts +36 -0
- package/src/http/badResponses/unauthorized.ts +36 -0
- package/src/http/badResponses/unprocessableEntity.ts +48 -0
- package/src/http/successResponses/created.ts +35 -0
- package/src/http/successResponses/found.ts +35 -0
- package/src/http/successResponses/noContent.ts +33 -0
- package/src/http/successResponses/success.ts +35 -0
- package/src/http/successResponses/updated.ts +35 -0
- package/src/index.ts +19 -18
- package/src/services/decodeRequestBody.ts +46 -0
- package/src/services/errorHandler.ts +55 -0
- package/src/services/formParse.ts +42 -1
- package/src/services/getCaller.ts +37 -0
- package/src/services/getScopedParams.ts +29 -2
- package/src/services/httpDebug.ts +23 -0
- package/src/services/schemaValidator.ts +66 -0
- package/src/services/sendFileToS3.ts +81 -56
- package/src/helpers/globalErrorHandler.ts +0 -64
- package/src/httpBadResponses/badRequest.ts +0 -29
- package/src/httpBadResponses/conflict.ts +0 -29
- package/src/httpBadResponses/forbidden.ts +0 -29
- package/src/httpBadResponses/notFound.ts +0 -29
- package/src/httpBadResponses/serverError.ts +0 -29
- package/src/httpBadResponses/unauthorized.ts +0 -29
- package/src/httpBadResponses/unprocessableEntity.ts +0 -43
- package/src/httpResponses/created.ts +0 -35
- package/src/httpResponses/noContent.ts +0 -33
- package/src/httpResponses/success.ts +0 -35
- package/src/httpResponses/updated.ts +0 -35
- package/src/services/extractJsonFromRequest.ts +0 -30
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function conflict(error: ConflictError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 409,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 409,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ConflictError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ConflictError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { conflict, ConflictError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function forbidden(error: ForbiddenError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 403,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 403,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ForbiddenError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ForbiddenError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { forbidden, ForbiddenError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function notFound(error: NotFoundError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 404,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 404,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class NotFoundError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "NotFoundError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { notFound, NotFoundError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function serverError(error: ServerError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 500,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 500,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ServerError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ServerError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { serverError, ServerError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function unauthorized(error: UnauthorizedError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 401,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 401,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class UnauthorizedError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "UnauthorizedError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { unauthorized, UnauthorizedError };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
type UnprocessableEntityErrorProps = {
|
|
2
|
-
data?: any;
|
|
3
|
-
fieldErrors?: Record<string, string>;
|
|
4
|
-
fields?: Record<string, string>;
|
|
5
|
-
message?: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
function unprocessableEntity(error: UnprocessableEntityError) {
|
|
9
|
-
return new Response(
|
|
10
|
-
JSON.stringify({
|
|
11
|
-
status: 433,
|
|
12
|
-
success: false,
|
|
13
|
-
name: error.name,
|
|
14
|
-
message: error.message,
|
|
15
|
-
data: error.data || null,
|
|
16
|
-
fieldErrors: error.fieldErrors || null,
|
|
17
|
-
fields: error.fields || null,
|
|
18
|
-
}),
|
|
19
|
-
{
|
|
20
|
-
status: 433,
|
|
21
|
-
statusText: "Bad Request",
|
|
22
|
-
headers: { "Content-Type": "application/json" },
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
class UnprocessableEntityError {
|
|
28
|
-
name: string;
|
|
29
|
-
message?: string;
|
|
30
|
-
fieldErrors: any;
|
|
31
|
-
fields: any;
|
|
32
|
-
data: any;
|
|
33
|
-
|
|
34
|
-
constructor(data: UnprocessableEntityErrorProps) {
|
|
35
|
-
this.data = data?.data || null;
|
|
36
|
-
this.fieldErrors = data?.fieldErrors || null;
|
|
37
|
-
this.fields = data?.fields || null;
|
|
38
|
-
this.name = "UnprocessableEntity";
|
|
39
|
-
this.message = data?.message;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { unprocessableEntity, UnprocessableEntityError };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function created(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 201,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Created<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
response() {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 201,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
json() {
|
|
27
|
-
return new Response(JSON.stringify(this.body), {
|
|
28
|
-
...this.init,
|
|
29
|
-
status: 201,
|
|
30
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
31
|
-
}).json();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { created, Created };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function noContent(init?: ResponseInit): Response {
|
|
2
|
-
return new Response(null, {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class NoContent {
|
|
10
|
-
init: ResponseInit;
|
|
11
|
-
|
|
12
|
-
constructor(init?: ResponseInit) {
|
|
13
|
-
this.init = init || {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
response() {
|
|
17
|
-
return new Response(null, {
|
|
18
|
-
...this.init,
|
|
19
|
-
status: 200,
|
|
20
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
json() {
|
|
25
|
-
return new Response(null, {
|
|
26
|
-
...this.init,
|
|
27
|
-
status: 200,
|
|
28
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
29
|
-
}).json();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { noContent, NoContent };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function success(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Success<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
response() {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
json() {
|
|
27
|
-
return new Response(JSON.stringify(this.body), {
|
|
28
|
-
...this.init,
|
|
29
|
-
status: 200,
|
|
30
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
31
|
-
}).json();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { success, Success };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function updated(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Updated<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
response() {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
json() {
|
|
27
|
-
return new Response(JSON.stringify(this.body), {
|
|
28
|
-
...this.init,
|
|
29
|
-
status: 200,
|
|
30
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
31
|
-
}).json();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { updated, Updated };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
async function extractJsonFromRequest(req: Request): Promise<any> {
|
|
2
|
-
let data: any;
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
const arrayBuffer = await req.arrayBuffer();
|
|
6
|
-
const text = new TextDecoder().decode(arrayBuffer);
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
data = JSON.parse(text);
|
|
10
|
-
} catch (jsonError) {
|
|
11
|
-
try {
|
|
12
|
-
const formData = new URLSearchParams(text);
|
|
13
|
-
data = Object.fromEntries(formData.entries());
|
|
14
|
-
} catch (formDataError) {
|
|
15
|
-
console.error("Failed to extract data from request:", {
|
|
16
|
-
jsonError,
|
|
17
|
-
formDataError,
|
|
18
|
-
});
|
|
19
|
-
data = {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error("Failed to read request body:", error);
|
|
24
|
-
data = {};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { extractJsonFromRequest };
|