@arkyn/server 1.4.52 → 2.0.1-beta.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.
Files changed (52) hide show
  1. package/package.json +1 -1
  2. package/dist/helpers/globalErrorHandler.d.ts +0 -3
  3. package/dist/helpers/globalErrorHandler.d.ts.map +0 -1
  4. package/dist/helpers/globalErrorHandler.js +0 -53
  5. package/dist/httpBadResponses/badRequest.d.ts +0 -9
  6. package/dist/httpBadResponses/badRequest.d.ts.map +0 -1
  7. package/dist/httpBadResponses/badRequest.js +0 -23
  8. package/dist/httpBadResponses/conflict.d.ts +0 -9
  9. package/dist/httpBadResponses/conflict.d.ts.map +0 -1
  10. package/dist/httpBadResponses/conflict.js +0 -23
  11. package/dist/httpBadResponses/forbidden.d.ts +0 -9
  12. package/dist/httpBadResponses/forbidden.d.ts.map +0 -1
  13. package/dist/httpBadResponses/forbidden.js +0 -23
  14. package/dist/httpBadResponses/notFound.d.ts +0 -9
  15. package/dist/httpBadResponses/notFound.d.ts.map +0 -1
  16. package/dist/httpBadResponses/notFound.js +0 -23
  17. package/dist/httpBadResponses/serverError.d.ts +0 -9
  18. package/dist/httpBadResponses/serverError.d.ts.map +0 -1
  19. package/dist/httpBadResponses/serverError.js +0 -23
  20. package/dist/httpBadResponses/unauthorized.d.ts +0 -9
  21. package/dist/httpBadResponses/unauthorized.d.ts.map +0 -1
  22. package/dist/httpBadResponses/unauthorized.js +0 -23
  23. package/dist/httpBadResponses/unprocessableEntity.d.ts +0 -17
  24. package/dist/httpBadResponses/unprocessableEntity.d.ts.map +0 -1
  25. package/dist/httpBadResponses/unprocessableEntity.js +0 -30
  26. package/dist/httpResponses/created.d.ts +0 -10
  27. package/dist/httpResponses/created.d.ts.map +0 -1
  28. package/dist/httpResponses/created.js +0 -30
  29. package/dist/httpResponses/noContent.d.ts +0 -9
  30. package/dist/httpResponses/noContent.d.ts.map +0 -1
  31. package/dist/httpResponses/noContent.js +0 -28
  32. package/dist/httpResponses/success.d.ts +0 -10
  33. package/dist/httpResponses/success.d.ts.map +0 -1
  34. package/dist/httpResponses/success.js +0 -30
  35. package/dist/httpResponses/updated.d.ts +0 -10
  36. package/dist/httpResponses/updated.d.ts.map +0 -1
  37. package/dist/httpResponses/updated.js +0 -30
  38. package/dist/index.d.ts +0 -17
  39. package/dist/index.d.ts.map +0 -1
  40. package/dist/index.js +0 -20
  41. package/dist/services/extractJsonFromRequest.d.ts +0 -3
  42. package/dist/services/extractJsonFromRequest.d.ts.map +0 -1
  43. package/dist/services/extractJsonFromRequest.js +0 -29
  44. package/dist/services/formParse.d.ts +0 -3
  45. package/dist/services/formParse.d.ts.map +0 -1
  46. package/dist/services/formParse.js +0 -15
  47. package/dist/services/getScopedParams.d.ts +0 -3
  48. package/dist/services/getScopedParams.d.ts.map +0 -1
  49. package/dist/services/getScopedParams.js +0 -10
  50. package/dist/services/sendFileToS3.d.ts +0 -20
  51. package/dist/services/sendFileToS3.d.ts.map +0 -1
  52. package/dist/services/sendFileToS3.js +0 -101
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "1.4.52",
3
+ "version": "2.0.1-beta.0",
4
4
  "main": "./dist/bundle.js",
5
5
  "module": "./src/index.ts",
6
6
  "type": "module",
@@ -1,3 +0,0 @@
1
- declare const globalErrorHandler: (error: any) => Response;
2
- export { globalErrorHandler };
3
- //# sourceMappingURL=globalErrorHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"globalErrorHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/globalErrorHandler.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,kBAAkB,GAAI,OAAO,GAAG,aA2CrC,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,53 +0,0 @@
1
- import { badRequest, BadRequestError } from "../httpBadResponses/badRequest";
2
- import { conflict, ConflictError } from "../httpBadResponses/conflict";
3
- import { forbidden, ForbiddenError } from "../httpBadResponses/forbidden";
4
- import { notFound, NotFoundError } from "../httpBadResponses/notFound";
5
- import { serverError } from "../httpBadResponses/serverError";
6
- import { unauthorized, UnauthorizedError, } from "../httpBadResponses/unauthorized";
7
- import { unprocessableEntity, UnprocessableEntityError, } from "../httpBadResponses/unprocessableEntity";
8
- import { created, Created } from "../httpResponses/created";
9
- import { noContent, NoContent } from "../httpResponses/noContent";
10
- import { success, Success } from "../httpResponses/success";
11
- import { updated, Updated } from "../httpResponses/updated";
12
- const globalErrorHandler = (error) => {
13
- // If the error is not an instance of Error, return the response
14
- switch (true) {
15
- case error instanceof Response:
16
- return error;
17
- case error instanceof Created:
18
- return created(error.body, error.init);
19
- case error instanceof Updated:
20
- return updated(error.body, error.init);
21
- case error instanceof Success:
22
- return success(error.body, error.init);
23
- case error instanceof NoContent:
24
- return noContent(error.init);
25
- }
26
- const showConsoleError = process.env.NODE_ENV === "development" ||
27
- process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
28
- // If showConsoleError is true, log the error to the console
29
- if (showConsoleError)
30
- console.error(error);
31
- // If the error is an instance of BadRequestError, ForbiddenError, ConflictError, UnauthorizedError, NotFoundError, or UnprocessableEntityError, return the error
32
- switch (true) {
33
- case error instanceof BadRequestError:
34
- return badRequest(error);
35
- case error instanceof ForbiddenError:
36
- return forbidden(error);
37
- case error instanceof ConflictError:
38
- return conflict(error);
39
- case error instanceof UnauthorizedError:
40
- return unauthorized(error);
41
- case error instanceof NotFoundError:
42
- return notFound(error);
43
- case error instanceof UnprocessableEntityError:
44
- return unprocessableEntity(error);
45
- default:
46
- return serverError({
47
- message: error?.message || "Server error | Message not found",
48
- name: "Server Error",
49
- cause: error.cause || "Unknown",
50
- });
51
- }
52
- };
53
- export { globalErrorHandler };
@@ -1,9 +0,0 @@
1
- declare function badRequest(error: BadRequestError): Response;
2
- declare class BadRequestError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { badRequest, BadRequestError };
9
- //# sourceMappingURL=badRequest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/badRequest.ts"],"names":[],"mappings":"AAAA,iBAAS,UAAU,CAAC,KAAK,EAAE,eAAe,YAczC;AAED,cAAM,eAAe;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function badRequest(error) {
2
- return new Response(JSON.stringify({
3
- status: 400,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 400,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class BadRequestError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "BadRequestError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { badRequest, BadRequestError };
@@ -1,9 +0,0 @@
1
- declare function conflict(error: ConflictError): Response;
2
- declare class ConflictError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { conflict, ConflictError };
9
- //# sourceMappingURL=conflict.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/conflict.ts"],"names":[],"mappings":"AAAA,iBAAS,QAAQ,CAAC,KAAK,EAAE,aAAa,YAcrC;AAED,cAAM,aAAa;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function conflict(error) {
2
- return new Response(JSON.stringify({
3
- status: 409,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 409,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class ConflictError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "ConflictError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { conflict, ConflictError };
@@ -1,9 +0,0 @@
1
- declare function forbidden(error: ForbiddenError): Response;
2
- declare class ForbiddenError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { forbidden, ForbiddenError };
9
- //# sourceMappingURL=forbidden.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/forbidden.ts"],"names":[],"mappings":"AAAA,iBAAS,SAAS,CAAC,KAAK,EAAE,cAAc,YAcvC;AAED,cAAM,cAAc;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function forbidden(error) {
2
- return new Response(JSON.stringify({
3
- status: 403,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 403,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class ForbiddenError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "ForbiddenError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { forbidden, ForbiddenError };
@@ -1,9 +0,0 @@
1
- declare function notFound(error: NotFoundError): Response;
2
- declare class NotFoundError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { notFound, NotFoundError };
9
- //# sourceMappingURL=notFound.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/notFound.ts"],"names":[],"mappings":"AAAA,iBAAS,QAAQ,CAAC,KAAK,EAAE,aAAa,YAcrC;AAED,cAAM,aAAa;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function notFound(error) {
2
- return new Response(JSON.stringify({
3
- status: 404,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 404,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class NotFoundError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "NotFoundError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { notFound, NotFoundError };
@@ -1,9 +0,0 @@
1
- declare function serverError(error: ServerError): Response;
2
- declare class ServerError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { serverError, ServerError };
9
- //# sourceMappingURL=serverError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/serverError.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,KAAK,EAAE,WAAW,YActC;AAED,cAAM,WAAW;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function serverError(error) {
2
- return new Response(JSON.stringify({
3
- status: 500,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 500,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class ServerError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "ServerError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { serverError, ServerError };
@@ -1,9 +0,0 @@
1
- declare function unauthorized(error: UnauthorizedError): Response;
2
- declare class UnauthorizedError {
3
- name: string;
4
- message: string;
5
- cause?: any;
6
- constructor(message: string, cause?: any);
7
- }
8
- export { unauthorized, UnauthorizedError };
9
- //# sourceMappingURL=unauthorized.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/unauthorized.ts"],"names":[],"mappings":"AAAA,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,YAc7C;AAED,cAAM,iBAAiB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAEA,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;CAKzC;AAED,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,23 +0,0 @@
1
- function unauthorized(error) {
2
- return new Response(JSON.stringify({
3
- status: 401,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- }), {
8
- status: 401,
9
- statusText: "Bad Request",
10
- headers: { "Content-Type": "application/json" },
11
- });
12
- }
13
- class UnauthorizedError {
14
- name;
15
- message;
16
- cause;
17
- constructor(message, cause) {
18
- this.name = "UnauthorizedError";
19
- this.message = message;
20
- this.cause = cause ? JSON.stringify(cause) : undefined;
21
- }
22
- }
23
- export { unauthorized, UnauthorizedError };
@@ -1,17 +0,0 @@
1
- type UnprocessableEntityErrorProps = {
2
- data?: any;
3
- fieldErrors?: Record<string, string>;
4
- fields?: Record<string, string>;
5
- message?: string;
6
- };
7
- declare function unprocessableEntity(error: UnprocessableEntityError): Response;
8
- declare class UnprocessableEntityError {
9
- name: string;
10
- message?: string;
11
- fieldErrors: any;
12
- fields: any;
13
- data: any;
14
- constructor(data: UnprocessableEntityErrorProps);
15
- }
16
- export { unprocessableEntity, UnprocessableEntityError };
17
- //# sourceMappingURL=unprocessableEntity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,KAAK,6BAA6B,GAAG;IACnC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,iBAAS,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAiB3D;AAED,cAAM,wBAAwB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;gBAEE,IAAI,EAAE,6BAA6B;CAOhD;AAED,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function unprocessableEntity(error) {
2
- return new Response(JSON.stringify({
3
- status: 433,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- data: error.data || null,
8
- fieldErrors: error.fieldErrors || null,
9
- fields: error.fields || null,
10
- }), {
11
- status: 433,
12
- statusText: "Bad Request",
13
- headers: { "Content-Type": "application/json" },
14
- });
15
- }
16
- class UnprocessableEntityError {
17
- name;
18
- message;
19
- fieldErrors;
20
- fields;
21
- data;
22
- constructor(data) {
23
- this.data = data?.data || null;
24
- this.fieldErrors = data?.fieldErrors || null;
25
- this.fields = data?.fields || null;
26
- this.name = "UnprocessableEntity";
27
- this.message = data?.message;
28
- }
29
- }
30
- export { unprocessableEntity, UnprocessableEntityError };
@@ -1,10 +0,0 @@
1
- declare function created(body: any, init?: ResponseInit): Response;
2
- declare class Created<T> {
3
- body: T;
4
- init: ResponseInit;
5
- constructor(body: T, init?: ResponseInit);
6
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { created, Created };
10
- //# sourceMappingURL=created.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../src/httpResponses/created.ts"],"names":[],"mappings":"AAAA,iBAAS,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMzD;AAED,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAKxC,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function created(body, init) {
2
- return new Response(JSON.stringify(body), {
3
- ...init,
4
- status: 201,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class Created {
9
- body;
10
- init;
11
- constructor(body, init) {
12
- this.body = body;
13
- this.init = init || {};
14
- }
15
- response() {
16
- return new Response(JSON.stringify(this.body), {
17
- ...this.init,
18
- status: 201,
19
- headers: { "Content-Type": "application/json", ...this.init.headers },
20
- });
21
- }
22
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 201,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { created, Created };
@@ -1,9 +0,0 @@
1
- declare function noContent(init?: ResponseInit): Response;
2
- declare class NoContent {
3
- init: ResponseInit;
4
- constructor(init?: ResponseInit);
5
- response(): Response;
6
- json(): Promise<any>;
7
- }
8
- export { noContent, NoContent };
9
- //# sourceMappingURL=noContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noContent.d.ts","sourceRoot":"","sources":["../../src/httpResponses/noContent.ts"],"names":[],"mappings":"AAAA,iBAAS,SAAS,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMhD;AAED,cAAM,SAAS;IACb,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,CAAC,EAAE,YAAY;IAI/B,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -1,28 +0,0 @@
1
- function noContent(init) {
2
- return new Response(null, {
3
- ...init,
4
- status: 200,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class NoContent {
9
- init;
10
- constructor(init) {
11
- this.init = init || {};
12
- }
13
- response() {
14
- return new Response(null, {
15
- ...this.init,
16
- status: 200,
17
- headers: { "Content-Type": "application/json", ...this.init.headers },
18
- });
19
- }
20
- json() {
21
- return new Response(null, {
22
- ...this.init,
23
- status: 200,
24
- headers: { "Content-Type": "application/json", ...this.init.headers },
25
- }).json();
26
- }
27
- }
28
- export { noContent, NoContent };
@@ -1,10 +0,0 @@
1
- declare function success(body: any, init?: ResponseInit): Response;
2
- declare class Success<T> {
3
- body: T;
4
- init: ResponseInit;
5
- constructor(body: T, init?: ResponseInit);
6
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { success, Success };
10
- //# sourceMappingURL=success.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../src/httpResponses/success.ts"],"names":[],"mappings":"AAAA,iBAAS,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMzD;AAED,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAKxC,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function success(body, init) {
2
- return new Response(JSON.stringify(body), {
3
- ...init,
4
- status: 200,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class Success {
9
- body;
10
- init;
11
- constructor(body, init) {
12
- this.body = body;
13
- this.init = init || {};
14
- }
15
- response() {
16
- return new Response(JSON.stringify(this.body), {
17
- ...this.init,
18
- status: 200,
19
- headers: { "Content-Type": "application/json", ...this.init.headers },
20
- });
21
- }
22
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 200,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { success, Success };
@@ -1,10 +0,0 @@
1
- declare function updated(body: any, init?: ResponseInit): Response;
2
- declare class Updated<T> {
3
- body: T;
4
- init: ResponseInit;
5
- constructor(body: T, init?: ResponseInit);
6
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { updated, Updated };
10
- //# sourceMappingURL=updated.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../src/httpResponses/updated.ts"],"names":[],"mappings":"AAAA,iBAAS,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMzD;AAED,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAKxC,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function updated(body, init) {
2
- return new Response(JSON.stringify(body), {
3
- ...init,
4
- status: 200,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class Updated {
9
- body;
10
- init;
11
- constructor(body, init) {
12
- this.body = body;
13
- this.init = init || {};
14
- }
15
- response() {
16
- return new Response(JSON.stringify(this.body), {
17
- ...this.init,
18
- status: 200,
19
- headers: { "Content-Type": "application/json", ...this.init.headers },
20
- });
21
- }
22
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 200,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { updated, Updated };
package/dist/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export { BadRequestError } from "./httpBadResponses/badRequest";
2
- export { ConflictError } from "./httpBadResponses/conflict";
3
- export { ForbiddenError } from "./httpBadResponses/forbidden";
4
- export { NotFoundError } from "./httpBadResponses/notFound";
5
- export { ServerError } from "./httpBadResponses/serverError";
6
- export { UnauthorizedError } from "./httpBadResponses/unauthorized";
7
- export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity";
8
- export { Created } from "./httpResponses/created";
9
- export { NoContent } from "./httpResponses/noContent";
10
- export { Success } from "./httpResponses/success";
11
- export { Updated } from "./httpResponses/updated";
12
- export { globalErrorHandler } from "./helpers/globalErrorHandler";
13
- export { extractJsonFromRequest } from "./services/extractJsonFromRequest";
14
- export { formParse } from "./services/formParse";
15
- export { getScopedParams } from "./services/getScopedParams";
16
- export { sendFileToS3 } from "./services/sendFileToS3";
17
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js DELETED
@@ -1,20 +0,0 @@
1
- // http bad responses
2
- export { BadRequestError } from "./httpBadResponses/badRequest";
3
- export { ConflictError } from "./httpBadResponses/conflict";
4
- export { ForbiddenError } from "./httpBadResponses/forbidden";
5
- export { NotFoundError } from "./httpBadResponses/notFound";
6
- export { ServerError } from "./httpBadResponses/serverError";
7
- export { UnauthorizedError } from "./httpBadResponses/unauthorized";
8
- export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity";
9
- // http responses
10
- export { Created } from "./httpResponses/created";
11
- export { NoContent } from "./httpResponses/noContent";
12
- export { Success } from "./httpResponses/success";
13
- export { Updated } from "./httpResponses/updated";
14
- // helpers
15
- export { globalErrorHandler } from "./helpers/globalErrorHandler";
16
- // services
17
- export { extractJsonFromRequest } from "./services/extractJsonFromRequest";
18
- export { formParse } from "./services/formParse";
19
- export { getScopedParams } from "./services/getScopedParams";
20
- export { sendFileToS3 } from "./services/sendFileToS3";
@@ -1,3 +0,0 @@
1
- declare function extractJsonFromRequest(req: Request): Promise<any>;
2
- export { extractJsonFromRequest };
3
- //# sourceMappingURL=extractJsonFromRequest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractJsonFromRequest.d.ts","sourceRoot":"","sources":["../../src/services/extractJsonFromRequest.ts"],"names":[],"mappings":"AAAA,iBAAe,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CA2BhE;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1,29 +0,0 @@
1
- async function extractJsonFromRequest(req) {
2
- let data;
3
- try {
4
- const arrayBuffer = await req.arrayBuffer();
5
- const text = new TextDecoder().decode(arrayBuffer);
6
- try {
7
- data = JSON.parse(text);
8
- }
9
- catch (jsonError) {
10
- try {
11
- const formData = new URLSearchParams(text);
12
- data = Object.fromEntries(formData.entries());
13
- }
14
- catch (formDataError) {
15
- console.error("Failed to extract data from request:", {
16
- jsonError,
17
- formDataError,
18
- });
19
- data = {};
20
- }
21
- }
22
- }
23
- catch (error) {
24
- console.error("Failed to read request body:", error);
25
- data = {};
26
- }
27
- return data;
28
- }
29
- export { extractJsonFromRequest };
@@ -1,3 +0,0 @@
1
- import type { FormParseProps, FormParseReturnType } from "@arkyn/types";
2
- export declare function formParse<T extends FormParseProps>([formData, schema,]: T): FormParseReturnType<T>;
3
- //# sourceMappingURL=formParse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExE,wBAAgB,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAClD,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAoB5B"}
@@ -1,15 +0,0 @@
1
- export function formParse([formData, schema,]) {
2
- const zodResponse = schema.safeParse(formData);
3
- if (zodResponse.success === false) {
4
- const errorsArray = Object.entries(zodResponse.error.formErrors.fieldErrors);
5
- const errorsObject = Object.fromEntries(errorsArray.map((item) => [item[0], item[1]?.[0] || "Error"]));
6
- return {
7
- success: zodResponse.success,
8
- fieldErrors: errorsObject,
9
- fields: formData,
10
- };
11
- }
12
- else {
13
- return { success: zodResponse.success, data: zodResponse.data };
14
- }
15
- }
@@ -1,3 +0,0 @@
1
- declare function getScopedParams(request: Request, scope?: string): URLSearchParams;
2
- export { getScopedParams };
3
- //# sourceMappingURL=getScopedParams.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getScopedParams.d.ts","sourceRoot":"","sources":["../../src/services/getScopedParams.ts"],"names":[],"mappings":"AAAA,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,MAAW,mBAW5D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,10 +0,0 @@
1
- function getScopedParams(request, scope = "") {
2
- const url = new URL(request.url);
3
- if (scope === "")
4
- return url.searchParams;
5
- const scopedSearchParams = Array.from(url.searchParams.entries())
6
- .filter(([key]) => key.startsWith(`${scope}:`))
7
- .map(([key, value]) => [key.replace(`${scope}:`, ""), value]);
8
- return new URLSearchParams(scopedSearchParams);
9
- }
10
- export { getScopedParams };
@@ -1,20 +0,0 @@
1
- import { type ActionFunctionArgs } from "@remix-run/node";
2
- type AWSConfig = {
3
- AWS_REGION: string;
4
- AWS_ACCESS_KEY_ID: string;
5
- AWS_SECRET_ACCESS_KEY: string;
6
- AWS_S3_BUCKET: string;
7
- };
8
- type Config = {
9
- maxPartSize?: number;
10
- fileName?: string;
11
- };
12
- declare function sendFileToS3(props: ActionFunctionArgs, awsS3Config: AWSConfig, config?: Config): Promise<{
13
- error: string;
14
- url?: undefined;
15
- } | {
16
- url: string;
17
- error?: undefined;
18
- }>;
19
- export { sendFileToS3 };
20
- //# sourceMappingURL=sendFileToS3.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sendFileToS3.d.ts","sourceRoot":"","sources":["../../src/services/sendFileToS3.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAOzB,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAmDF,iBAAe,YAAY,CACzB,KAAK,EAAE,kBAAkB,EACzB,WAAW,EAAE,SAAS,EACtB,MAAM,GAAE,MAGP;;;;;;GAwEF;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,101 +0,0 @@
1
- import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2
- import { unstable_composeUploadHandlers as composeUploadHandlers, unstable_createFileUploadHandler as createFileUploadHandler, unstable_parseMultipartFormData as parseMultipartFormData, } from "@remix-run/node";
3
- import { randomUUID } from "crypto";
4
- import fs from "fs";
5
- import sharp from "sharp";
6
- import { BadRequestError } from "../httpBadResponses/badRequest";
7
- import { getScopedParams } from "./getScopedParams";
8
- async function s3_upload(fileStream, contentType, awsS3Config) {
9
- const { AWS_ACCESS_KEY_ID, AWS_REGION, AWS_S3_BUCKET, AWS_SECRET_ACCESS_KEY, } = awsS3Config;
10
- const filePath = fileStream.path;
11
- let fileName = "";
12
- if (typeof filePath === "string") {
13
- fileName = filePath.split("/").pop() || "";
14
- }
15
- else {
16
- fileName = randomUUID();
17
- }
18
- const uploadParams = {
19
- Bucket: AWS_S3_BUCKET,
20
- Key: `uploads/${Date.now()}-${fileName.split(" ").join("-")}`,
21
- Body: fileStream,
22
- ContentType: contentType,
23
- };
24
- const s3Client = new S3Client({
25
- region: AWS_REGION,
26
- credentials: {
27
- accessKeyId: AWS_ACCESS_KEY_ID,
28
- secretAccessKey: AWS_SECRET_ACCESS_KEY,
29
- },
30
- });
31
- const command = new PutObjectCommand(uploadParams);
32
- try {
33
- await s3Client.send(command);
34
- }
35
- catch (error) {
36
- console.error(error);
37
- }
38
- return {
39
- location: `https://${AWS_S3_BUCKET}.s3.amazonaws.com/${uploadParams.Key}`,
40
- };
41
- }
42
- async function sendFileToS3(props, awsS3Config, config = {
43
- maxPartSize: 5_000_000,
44
- fileName: "file",
45
- }) {
46
- const { fileName = "file", maxPartSize = 5_000_000 } = config;
47
- const { request } = props;
48
- const uploadHandler = composeUploadHandlers(createFileUploadHandler({
49
- maxPartSize,
50
- file: ({ filename }) => filename,
51
- }));
52
- const formData = await parseMultipartFormData(request, uploadHandler);
53
- const file = formData.get(fileName);
54
- if (!file)
55
- throw new BadRequestError("No file uploaded");
56
- const filterParams = getScopedParams(request);
57
- const width = filterParams.get("w");
58
- const height = filterParams.get("h");
59
- const reduceQuality = filterParams.get("reduceQuality");
60
- const quality = reduceQuality ? +reduceQuality : 100;
61
- const isImage = file.type.startsWith("image");
62
- if (isImage && width && height) {
63
- const image = sharp(file.getFilePath());
64
- const metadata = await image.metadata();
65
- if (metadata.width && metadata.height) {
66
- const widthDiff = Math.abs(metadata.width - +width);
67
- const heightDiff = Math.abs(metadata.height - +height);
68
- if (widthDiff > 10 || heightDiff > 10) {
69
- return {
70
- error: `Formato inválido ${metadata.width}px x ${metadata.height}px`,
71
- };
72
- }
73
- }
74
- }
75
- if (isImage) {
76
- let image = sharp(file.getFilePath());
77
- if (file.type === "image/jpeg") {
78
- image = image.jpeg({ quality });
79
- }
80
- else if (file.type === "image/png") {
81
- image = image.png({ quality });
82
- }
83
- else if (file.type === "image/webp") {
84
- image = image.webp({ quality });
85
- }
86
- const compressedFilePath = file.getFilePath() + "_compressed";
87
- await image.toFile(compressedFilePath);
88
- file.getFilePath = () => compressedFilePath;
89
- const streamFile = fs.createReadStream(file.getFilePath());
90
- const apiResponse = await s3_upload(streamFile, file.type, awsS3Config);
91
- fs.unlink(compressedFilePath, (err) => {
92
- if (err)
93
- console.error(`Delete image error: ${err}`);
94
- });
95
- return { url: apiResponse.location };
96
- }
97
- const streamFile = fs.createReadStream(file.getFilePath());
98
- const apiResponse = await s3_upload(streamFile, file.type, awsS3Config);
99
- return { url: apiResponse.location };
100
- }
101
- export { sendFileToS3 };