@arkyn/server 3.0.1-beta.3 → 3.0.1-beta.30

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 (59) hide show
  1. package/README.md +368 -65
  2. package/dist/api/arkynLogRequest.d.ts.map +1 -1
  3. package/dist/api/arkynLogRequest.js +3 -4
  4. package/dist/api/makeRequest.d.ts +1 -1
  5. package/dist/api/makeRequest.d.ts.map +1 -1
  6. package/dist/api/makeRequest.js +3 -5
  7. package/dist/config/apiInstance.d.ts +17 -17
  8. package/dist/config/apiInstance.d.ts.map +1 -1
  9. package/dist/config/apiInstance.js +15 -15
  10. package/dist/config/arkynLogInstance.d.ts +2 -2
  11. package/dist/config/arkynLogInstance.d.ts.map +1 -1
  12. package/dist/config/arkynLogInstance.js +6 -5
  13. package/dist/mapper/arkynLogRequestMapper.js +2 -2
  14. package/dist/services/formParse.d.ts +3 -3
  15. package/dist/services/formParse.d.ts.map +1 -1
  16. package/dist/services/formParse.js +8 -5
  17. package/dist/services/measureRouteExecution.d.ts +3 -0
  18. package/dist/services/measureRouteExecution.d.ts.map +1 -0
  19. package/dist/services/measureRouteExecution.js +24 -0
  20. package/dist/services/schemaValidator.d.ts +3 -3
  21. package/dist/services/schemaValidator.d.ts.map +1 -1
  22. package/dist/services/schemaValidator.js +1 -1
  23. package/package.json +32 -21
  24. package/src/api/arkynLogRequest.ts +0 -112
  25. package/src/api/deleteRequest.ts +0 -22
  26. package/src/api/getRequest.ts +0 -20
  27. package/src/api/makeRequest.ts +0 -120
  28. package/src/api/patchRequest.ts +0 -22
  29. package/src/api/postRequest.ts +0 -22
  30. package/src/api/putRequest.ts +0 -22
  31. package/src/config/apiInstance.ts +0 -148
  32. package/src/config/arkynLogInstance.ts +0 -68
  33. package/src/http/badResponses/badGateway.ts +0 -63
  34. package/src/http/badResponses/badRequest.ts +0 -63
  35. package/src/http/badResponses/conflict.ts +0 -63
  36. package/src/http/badResponses/forbidden.ts +0 -63
  37. package/src/http/badResponses/notFound.ts +0 -63
  38. package/src/http/badResponses/notImplemented.ts +0 -63
  39. package/src/http/badResponses/serverError.ts +0 -63
  40. package/src/http/badResponses/unauthorized.ts +0 -63
  41. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  42. package/src/http/successResponses/created.ts +0 -64
  43. package/src/http/successResponses/found.ts +0 -67
  44. package/src/http/successResponses/noContent.ts +0 -42
  45. package/src/http/successResponses/success.ts +0 -64
  46. package/src/http/successResponses/updated.ts +0 -64
  47. package/src/index.ts +0 -31
  48. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  49. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  50. package/src/services/decodeRequestBody.ts +0 -43
  51. package/src/services/errorHandler.ts +0 -99
  52. package/src/services/formParse.ts +0 -83
  53. package/src/services/getCaller.ts +0 -82
  54. package/src/services/getScopedParams.ts +0 -43
  55. package/src/services/httpDebug.ts +0 -61
  56. package/src/services/schemaValidator.ts +0 -66
  57. package/src/types/ApiResponseDTO.ts +0 -19
  58. package/tsconfig.json +0 -21
  59. package/vitest.config.ts +0 -5
@@ -49,59 +49,59 @@ class ApiInstance {
49
49
  return headers;
50
50
  }
51
51
  /**
52
- * Sends a GET request to the specified route.
53
- * @param route - The API route to send the GET request to.
52
+ * Sends a get request to the specified route.
53
+ * @param route - The API route to send the get request to.
54
54
  * @param data - The request data, including optional headers and token.
55
55
  * @returns The API response data.
56
56
  */
57
- async GET(route, data) {
57
+ async get(route, data) {
58
58
  const url = this.generateURL(route);
59
59
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
60
60
  return await getRequest(url, headers);
61
61
  }
62
62
  /**
63
- * Sends a POST request to the specified route.
64
- * @param route - The API route to send the POST request to.
63
+ * Sends a post request to the specified route.
64
+ * @param route - The API route to send the post request to.
65
65
  * @param data - The request data, including body, optional headers, and token.
66
66
  * @returns The API response data.
67
67
  */
68
- async POST(route, data) {
68
+ async post(route, data) {
69
69
  const url = this.generateURL(route);
70
70
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
71
71
  const body = data?.body;
72
72
  return await postRequest(url, headers, body);
73
73
  }
74
74
  /**
75
- * Sends a PUT request to the specified route.
76
- * @param route - The API route to send the PUT request to.
75
+ * Sends a put request to the specified route.
76
+ * @param route - The API route to send the put request to.
77
77
  * @param data - The request data, including body, optional headers, and token.
78
78
  * @returns The API response data.
79
79
  */
80
- async PUT(route, data) {
80
+ async put(route, data) {
81
81
  const url = this.generateURL(route);
82
82
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
83
83
  const body = data?.body;
84
84
  return await putRequest(url, headers, body);
85
85
  }
86
86
  /**
87
- * Sends a PATCH request to the specified route.
88
- * @param route - The API route to send the PATCH request to.
87
+ * Sends a patch request to the specified route.
88
+ * @param route - The API route to send the patch request to.
89
89
  * @param data - The request data, including body, optional headers, and token.
90
90
  * @returns The API response data.
91
91
  */
92
- async PATCH(route, data) {
92
+ async patch(route, data) {
93
93
  const url = this.generateURL(route);
94
94
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
95
95
  const body = data?.body;
96
96
  return await patchRequest(url, headers, body);
97
97
  }
98
98
  /**
99
- * Sends a DELETE request to the specified route.
100
- * @param route - The API route to send the DELETE request to.
99
+ * Sends a delete request to the specified route.
100
+ * @param route - The API route to send the delete request to.
101
101
  * @param data - The request data, including body, optional headers, and token.
102
102
  * @returns The API response data.
103
103
  */
104
- async DELETE(route, data) {
104
+ async delete(route, data) {
105
105
  const url = this.generateURL(route);
106
106
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
107
107
  const body = data?.body;
@@ -6,7 +6,7 @@ type ArkynConfigProps = {
6
6
  type SetArkynConfigProps = {
7
7
  arkynTrafficSourceId: string;
8
8
  arkynUserToken: string;
9
- arkynApiUrl?: string;
9
+ arkynLogBaseApiUrl?: string;
10
10
  };
11
11
  /**
12
12
  * The `ArkynLogInstance` class manages the configuration for the arkyn flow.
@@ -23,7 +23,7 @@ declare class ArkynLogInstance {
23
23
  * @param arkynConfig - An object containing the arkyn configuration properties.
24
24
  * @param arkynConfig.arkynTrafficSourceId - The key used to identify the arkyn.
25
25
  * @param arkynConfig.arkynUserToken - The user token for authenticating with the arkyn.
26
- * @param arkynConfig.arkynApiUrl - (Optional) The API URL for the arkyn. If not provided,
26
+ * @param arkynConfig.arkynLogBaseApiUrl - (Optional) The API URL for the arkyn. If not provided,
27
27
  * a default URL will be used.
28
28
  */
29
29
  static setArkynConfig(arkynConfig: SetArkynConfigProps): void;
@@ -1 +1 @@
1
- {"version":3,"file":"arkynLogInstance.d.ts","sourceRoot":"","sources":["../../src/config/arkynLogInstance.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,gBAAgB;IACpB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IActD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"arkynLogInstance.d.ts","sourceRoot":"","sources":["../../src/config/arkynLogInstance.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AAEH,cAAM,gBAAgB;IACpB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAgBtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -13,19 +13,20 @@ class ArkynLogInstance {
13
13
  * @param arkynConfig - An object containing the arkyn configuration properties.
14
14
  * @param arkynConfig.arkynTrafficSourceId - The key used to identify the arkyn.
15
15
  * @param arkynConfig.arkynUserToken - The user token for authenticating with the arkyn.
16
- * @param arkynConfig.arkynApiUrl - (Optional) The API URL for the arkyn. If not provided,
16
+ * @param arkynConfig.arkynLogBaseApiUrl - (Optional) The API URL for the arkyn. If not provided,
17
17
  * a default URL will be used.
18
18
  */
19
19
  static setArkynConfig(arkynConfig) {
20
20
  if (!!this.arkynConfig)
21
21
  return;
22
- let defaultArkynURL = `https://logs-arkyn-flow-logs.vw6wo7.easypanel.host/http-traffic-records/:trafficSourceId`;
23
- let arkynApiUrl = arkynConfig.arkynApiUrl || defaultArkynURL;
24
- arkynApiUrl.replace(":trafficSourceId", arkynConfig.arkynTrafficSourceId);
22
+ let defaultArkynURL = `https://logs-arkyn-flow-logs.vw6wo7.easypanel.host`;
23
+ let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
24
+ arkynLogBaseApiUrl =
25
+ arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
25
26
  this.arkynConfig = {
26
27
  arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
27
28
  arkynUserToken: arkynConfig.arkynUserToken,
28
- arkynApiUrl: arkynConfig.arkynApiUrl || defaultArkynURL,
29
+ arkynApiUrl: arkynLogBaseApiUrl,
29
30
  };
30
31
  }
31
32
  /**
@@ -34,10 +34,10 @@ class ArkynLogRequestMapper {
34
34
  token: null,
35
35
  elapsedTime: props.elapsedTime,
36
36
  requestHeaders: this.mapHeaders(props.requestHeaders),
37
- requestBody: props.requestBody,
37
+ requestBody: props.requestBody || null,
38
38
  queryParams: this.mapQueryParams(props.queryParams),
39
39
  responseHeaders: this.mapHeaders(props.responseHeaders),
40
- responseBody: props.responseBody,
40
+ responseBody: props.responseBody || null,
41
41
  };
42
42
  }
43
43
  }
@@ -1,7 +1,7 @@
1
- import type { Schema } from "zod";
1
+ import type { ZodType } from "zod";
2
2
  type SuccessResponse<T extends FormParseProps> = {
3
3
  success: true;
4
- data: T[1] extends Schema<infer U> ? U : never;
4
+ data: T[1] extends ZodType<infer U> ? U : never;
5
5
  };
6
6
  type ErrorResponse = {
7
7
  success: false;
@@ -14,7 +14,7 @@ type ErrorResponse = {
14
14
  };
15
15
  type FormParseProps = [formData: {
16
16
  [k: string]: any;
17
- }, schema: Schema];
17
+ }, schema: ZodType];
18
18
  type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
19
  /**
20
20
  * Parses form data using a Zod schema and returns the result.
@@ -1 +1 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CAChD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAmB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -39,10 +39,10 @@
39
39
  function formParse([formData, schema,]) {
40
40
  const zodResponse = schema.safeParse(formData);
41
41
  if (zodResponse.success === false) {
42
- const errorsObject = Object.fromEntries(zodResponse.error.errors.map((item) => [
43
- item.path.join("."),
44
- item.message,
45
- ]));
42
+ const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
43
+ console.log(item);
44
+ return [item.path.join("."), item.message];
45
+ }));
46
46
  return {
47
47
  success: zodResponse.success,
48
48
  fieldErrors: errorsObject,
@@ -50,7 +50,10 @@ function formParse([formData, schema,]) {
50
50
  };
51
51
  }
52
52
  else {
53
- return { success: zodResponse.success, data: zodResponse.data };
53
+ return {
54
+ success: zodResponse.success,
55
+ data: zodResponse.data,
56
+ };
54
57
  }
55
58
  }
56
59
  export { formParse };
@@ -0,0 +1,3 @@
1
+ declare function measureRouteExecution<T = unknown>(handler: (props: any) => Promise<T>): (props: any) => Promise<T>;
2
+ export { measureRouteExecution };
3
+ //# sourceMappingURL=measureRouteExecution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureRouteExecution.d.ts","sourceRoot":"","sources":["../../src/services/measureRouteExecution.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,CAAC,GAAG,OAAO,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,IAEG,OAAO,GAAG,KAAG,OAAO,CAAC,CAAC,CAAC,CAyB9D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ function measureRouteExecution(handler) {
2
+ return async function measuredHandler(props) {
3
+ const startTime = performance.now();
4
+ try {
5
+ const result = await handler(props);
6
+ const url = new URL(props.request.url);
7
+ const endTime = performance.now();
8
+ const duration = (endTime - startTime).toFixed(2);
9
+ console.log({
10
+ domain: url.hostname,
11
+ pathname: url.pathname,
12
+ method: props.request.method,
13
+ duration,
14
+ });
15
+ return result;
16
+ }
17
+ catch (error) {
18
+ const endTime = performance.now();
19
+ console.error("");
20
+ throw error;
21
+ }
22
+ };
23
+ }
24
+ export { measureRouteExecution };
@@ -1,11 +1,11 @@
1
- import { Schema, z } from "zod";
2
- declare class SchemaValidator<T extends Schema> {
1
+ import { ZodType, z } from "zod";
2
+ declare class SchemaValidator<T extends ZodType> {
3
3
  readonly schema: T;
4
4
  functionName: string;
5
5
  callerInfo: string;
6
6
  constructor(schema: T);
7
7
  isValid(data: any): boolean;
8
- safeValidate(data: any): z.SafeParseReturnType<z.infer<T>, z.infer<T>>;
8
+ safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>>;
9
9
  validate(data: any): z.infer<T>;
10
10
  formValidate(data: any, message?: string): z.infer<T>;
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBhC,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM;IAIxB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;gBAEE,MAAM,EAAE,CAAC;IAM9B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAItE,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAoBtD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBjC,cAAM,eAAe,CAAC,CAAC,SAAS,OAAO;IAIzB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;gBAEE,MAAM,EAAE,CAAC;IAM9B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAIzD,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAoBtD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Schema, z } from "zod";
1
+ import { ZodType, z } from "zod";
2
2
  import { ServerError } from "../http/badResponses/serverError";
3
3
  import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
4
4
  import { formParse } from "./formParse";
package/package.json CHANGED
@@ -1,32 +1,43 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.3",
3
+ "version": "3.0.1-beta.30",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
- "main": "./dist/bundle.js",
6
- "module": "./src/index.ts",
7
- "dependencies": {
8
- "@arkyn/shared": "*",
9
- "@aws-sdk/client-s3": "^3.782.0",
10
- "@mjackson/multipart-parser": "^0.8.2",
11
- "sharp": "^0.33.5",
12
- "zod": "^3.24.2"
13
- },
14
- "devDependencies": {
15
- "bun-types": "latest",
16
- "vitest": "^3.1.1",
17
- "typescript": "^5.8.3"
18
- },
19
- "peerDependencies": {
20
- "@react-router/node": ">=7.6.0"
21
- },
22
- "description": "Server-side utilities for projects.",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "type": "module",
8
+ "types": "./dist/index.d.ts",
23
9
  "license": "Apache-2.0",
10
+ "description": "Comprehensive server-side utilities for building robust backend applications, featuring HTTP response helpers, error handlers, request utilities, and API configurations.",
11
+ "keywords": [
12
+ "server",
13
+ "http",
14
+ "api",
15
+ "utilities",
16
+ "error-handling",
17
+ "validation",
18
+ "remix",
19
+ "typescript",
20
+ "zod"
21
+ ],
22
+ "homepage": "https://docs.arkyn.dev/en/server/introduction",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/Lucas-Eduardo-Goncalves/arkyn.git",
26
+ "directory": "packages/server"
27
+ },
24
28
  "scripts": {
25
29
  "clean": "rm -rf dist",
26
30
  "build": "bun run clean && bunx tsc --project tsconfig.json",
27
31
  "test": "vitest --config vitest.config.ts",
28
32
  "typecheck": "bunx tsc --project tsconfig.json --noEmit"
29
33
  },
30
- "type": "module",
31
- "types": "./dist/index.d.ts"
34
+ "dependencies": {
35
+ "@arkyn/shared": "*",
36
+ "zod": "^4.0.17"
37
+ },
38
+ "devDependencies": {
39
+ "bun-types": "latest",
40
+ "vitest": "^3.2.4",
41
+ "typescript": "^5.9.2"
42
+ }
32
43
  }
@@ -1,112 +0,0 @@
1
- import { ArkynLogInstance } from "../config/arkynLogInstance";
2
- import { httpDebug } from "../services/httpDebug";
3
-
4
- type ConfigProps = {
5
- rawUrl: string;
6
- status: number;
7
- method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
8
- token: string | null;
9
- elapsedTime: number;
10
- requestHeaders: Record<string, string>;
11
- requestBody: Record<string, string>;
12
- queryParams: Record<string, string>;
13
- responseHeaders: Record<string, string>;
14
- responseBody: Record<string, string>;
15
- };
16
-
17
- /**
18
- * Sends a request to the inbox flow API with the provided configuration.
19
- *
20
- * @param config - The configuration object for the request.
21
- * @param config.rawUrl - The raw URL of the request.
22
- * @param config.status - The HTTP status code associated with the request.
23
- * @param config.method - The HTTP method used for the request. Can be "POST", "GET", "PUT", "DELETE", or "PATCH".
24
- * @param config.token - The authentication token for the request.
25
- * @param config.elapsedTime - The elapsed time for the request in milliseconds.
26
- * @param config.requestHeaders - The headers sent with the request.
27
- * @param config.requestBody - The body of the request, if applicable.
28
- * @param config.queryParams - The query parameters for the request.
29
- * @param config.responseHeaders - The headers received in the response.
30
- * @param config.responseBody - The body of the response received.
31
- *
32
- * @remarks
33
- * - This function retrieves the inbox flow configuration using `InboxFlowInstance.getInboxConfig()`.
34
- * - If the configuration is not available, the function will return early without performing any action.
35
- * - In a development environment (`NODE_ENV === "development"`), the function will also return early.
36
- * - The request is sent as a POST request to the inbox API URL with the provided configuration details.
37
- * - If an error occurs during the request, it will be logged using the `httpDebug` service.
38
- *
39
- * @example
40
- * ```typescript
41
- * const config = {
42
- * rawUrl: "https://example.com/api/data",
43
- * status: 200,
44
- * method: "GET",
45
- * token: "auth-token-123",
46
- * elapsedTime: "150ms",
47
- * requestHeaders: { "Accept": "application/json", "Authorization": "Bearer token123" },
48
- * requestBody: {},
49
- * queryParams: { "page": "1", "limit": "10" },
50
- * responseHeaders: { "Content-Type": "application/json" },
51
- * responseBody: { "data": "example response" }
52
- * };
53
- *
54
- * await arkynLogRequest(config);
55
- * ```
56
- */
57
-
58
- async function arkynLogRequest(config: ConfigProps) {
59
- const arkynInstance = ArkynLogInstance.getArkynConfig();
60
- if (!arkynInstance) return;
61
-
62
- const { arkynApiUrl, arkynUserToken } = arkynInstance;
63
-
64
- const {
65
- elapsedTime,
66
- method,
67
- queryParams,
68
- requestBody,
69
- requestHeaders,
70
- responseBody,
71
- responseHeaders,
72
- status,
73
- token,
74
- rawUrl,
75
- } = config;
76
-
77
- if (process.env.NODE_ENV === "development") return;
78
-
79
- try {
80
- const url = new URL(rawUrl);
81
- let protocol: "HTTPS" | "HTTP" = "HTTPS";
82
- if (url.protocol === "http:") protocol = "HTTP";
83
-
84
- const body = JSON.stringify({
85
- domainUrl: url.protocol + "//" + url.host,
86
- pathnameUrl: url.pathname,
87
- status,
88
- protocol,
89
- method,
90
- trafficUserId: null,
91
- elapsedTime,
92
- requestHeaders,
93
- requestBody,
94
- queryParams,
95
- responseHeaders,
96
- responseBody,
97
- });
98
-
99
- await fetch(arkynApiUrl, {
100
- method: "POST",
101
- body,
102
- headers: {
103
- "Content-Type": "application/json",
104
- Authorization: `Bearer ${arkynUserToken}`,
105
- },
106
- });
107
- } catch (err) {
108
- httpDebug("arkyn log error", "Error sending request", err);
109
- }
110
- }
111
-
112
- export { arkynLogRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a DELETE request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the DELETE request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} [body] - Optional body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function deleteRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body?: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("DELETE", url, headers, body);
20
- }
21
-
22
- export { deleteRequest };
@@ -1,20 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a GET request to the specified URL with optional headers.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the GET request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
11
- */
12
-
13
- async function getRequest<T = any>(
14
- url: string,
15
- headers: HeadersInit = {}
16
- ): Promise<ApiResponseDTO<T>> {
17
- return makeRequest("GET", url, headers);
18
- }
19
-
20
- export { getRequest };
@@ -1,120 +0,0 @@
1
- import { ArkynLogRequestMapper } from "../mapper/arkynLogRequestMapper";
2
- import { httpDebug } from "../services/httpDebug";
3
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
4
- import { arkynLogRequest } from "./arkynLogRequest";
5
-
6
- /**
7
- * Makes an HTTP request using the Fetch API and returns a standardized response.
8
- *
9
- * @template T - The expected type of the response data.
10
- * @param method - The HTTP method to use for the request. Supported methods are:
11
- * - "POST": Create a new resource.
12
- * - "PUT": Update an existing resource.
13
- * - "DELETE": Remove a resource.
14
- * - "PATCH": Partially update a resource.
15
- * - "GET": Retrieve a resource.
16
- * @param url - The URL to which the request is sent.
17
- * @param headers - Optional headers to include in the request. Defaults to an empty object.
18
- * @param body - Optional body to include in the request. Should be serializable to JSON.
19
- * @returns A promise that resolves to an `ApiResponseDTO<T>` object containing:
20
- * - `success`: A boolean indicating whether the request was successful.
21
- * - `status`: The HTTP status code of the response.
22
- * - `message`: A message describing the result of the request.
23
- * - `response`: The parsed JSON response data, or `null` if parsing fails.
24
- * - `cause`: Additional error information, if applicable.
25
- *
26
- * @example
27
- * ```typescript
28
- * import { makeRequest } from "./makeRequest";
29
- *
30
- * async function fetchData() {
31
- * const response = await makeRequest("GET", "https://api.example.com/data");
32
- * if (response.success) {
33
- * console.log("Data:", response.response);
34
- * } else {
35
- * console.error("Error:", response.message);
36
- * }
37
- * }
38
- * ```
39
- */
40
-
41
- async function makeRequest<T = any>(
42
- method: "POST" | "PUT" | "DELETE" | "PATCH" | "GET",
43
- url: string,
44
- headers: HeadersInit = {},
45
- body?: any
46
- ): Promise<ApiResponseDTO<T>> {
47
- const successMessage = {
48
- POST: "Resource created successfully",
49
- PUT: "Resource updated successfully",
50
- DELETE: "Resource deleted successfully",
51
- PATCH: "Resource patched successfully",
52
- GET: "Request successful",
53
- };
54
-
55
- try {
56
- const startTime = performance.now();
57
-
58
- const response = await fetch(url, {
59
- method,
60
- headers: {
61
- ...headers,
62
- "Content-Type": "application/json",
63
- },
64
- body: body ? JSON.stringify(body) : undefined,
65
- });
66
-
67
- const elapsedTime = performance.now() - startTime;
68
- const status = response.status;
69
-
70
- let data: any = null;
71
- try {
72
- data = await response.json();
73
- } catch {
74
- data = null;
75
- }
76
-
77
- const logData = ArkynLogRequestMapper.handle({
78
- elapsedTime,
79
- method,
80
- queryParams: new URL(url).searchParams,
81
- requestHeaders: headers,
82
- requestBody: body,
83
- responseBody: data,
84
- responseHeaders: response.headers,
85
- status,
86
- url,
87
- });
88
-
89
- arkynLogRequest(logData);
90
-
91
- if (!response.ok) {
92
- return {
93
- success: false,
94
- status,
95
- message: data?.message || response.statusText || "Request failed",
96
- response: data,
97
- cause: null,
98
- };
99
- }
100
-
101
- return {
102
- success: true,
103
- status,
104
- message: data?.message || successMessage[method],
105
- response: data,
106
- cause: null,
107
- };
108
- } catch (err) {
109
- httpDebug("Network error or request failed", null, err);
110
- return {
111
- success: false,
112
- status: 0,
113
- message: "Network error or request failed",
114
- response: null,
115
- cause: err instanceof Error ? err.message : String(err),
116
- };
117
- }
118
- }
119
-
120
- export { makeRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a PATCH request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the PATCH request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} body - The body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function patchRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("PATCH", url, headers, body);
20
- }
21
-
22
- export { patchRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a PATCH request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the PATCH request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} body - The body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function postRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("POST", url, headers, body);
20
- }
21
-
22
- export { postRequest };