@xrystal/core 3.16.0 → 3.16.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.16.0",
4
+ "version": "3.16.2",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -22,30 +22,19 @@ class Controller {
22
22
  const identityT = (k) => k;
23
23
  if (!store)
24
24
  return { url: '', method: '', headers: {}, params: {}, query: {}, t: identityT };
25
- const ctx = store.ctx;
26
- if (ctx) {
27
- const request = ctx.request || ctx.data?.request;
28
- return {
29
- url: request?.url || '',
30
- method: request?.method || '',
31
- headers: ctx.headers || {},
32
- body: ctx.body,
33
- params: ctx.params || {},
34
- query: ctx.query || {},
35
- accounts: ctx.user || ctx.data?.user || ctx.accounts,
36
- t: ctx.t || ctx.data?.t || identityT
37
- };
38
- }
39
- const req = store.req;
25
+ const { ctx, req: nativeReq } = store;
26
+ const reqSource = nativeReq?.url ? nativeReq : (ctx?.request?.url ? ctx.request : nativeReq);
40
27
  return {
41
- url: req?.originalUrl || req?.url || '',
42
- method: req?.method || 'GET',
43
- headers: req?.headers || {},
44
- body: req?.body,
45
- params: req?.params || {},
46
- query: req?.query || {},
47
- accounts: req?.accounts,
48
- t: req?.t || identityT
28
+ url: reqSource?.url || '',
29
+ method: reqSource?.method || 'GET',
30
+ headers: reqSource?.headers && typeof reqSource.headers.entries === 'function'
31
+ ? Object.fromEntries(reqSource.headers.entries())
32
+ : (ctx?.headers || nativeReq?.headers || {}),
33
+ body: ctx?.body || nativeReq?.body,
34
+ params: ctx?.params || nativeReq?.params || {},
35
+ query: ctx?.query || nativeReq?.query || {},
36
+ accounts: ctx?.user || ctx?.data?.user || nativeReq?.accounts,
37
+ t: ctx?.t || nativeReq?.t || identityT
49
38
  };
50
39
  }
51
40
  get res() {
@@ -58,7 +47,7 @@ class Controller {
58
47
  locals: {}
59
48
  };
60
49
  const currentProtocol = this.protocol;
61
- if (store.ctx) {
50
+ if (store.ctx || store.req) {
62
51
  if (!store.metadata)
63
52
  store.metadata = { locals: {} };
64
53
  return {
@@ -88,8 +77,13 @@ class Controller {
88
77
  return res.status(resStatus).send(responseData);
89
78
  };
90
79
  parsedQuerys = (url) => {
91
- const queryString = url.includes('?') ? url.split('?')[1] : '';
92
- return queryString ? qs.parse(queryString, { decoder: decodeURIComponent }) : {};
80
+ try {
81
+ const queryString = url.includes('?') ? url.split('?')[1] : '';
82
+ return queryString ? qs.parse(queryString, { decoder: decodeURIComponent }) : {};
83
+ }
84
+ catch {
85
+ return {};
86
+ }
93
87
  };
94
88
  }
95
89
  export class ControllerService extends Controller {
@@ -101,6 +95,8 @@ export class ControllerService extends Controller {
101
95
  try {
102
96
  const currentReq = this.req;
103
97
  const currentRes = this.res;
98
+ if (!currentReq.url)
99
+ throw new Error("Request URL is missing from context");
104
100
  const payload = { req: currentReq, res: currentRes };
105
101
  const convertedPayload = { ...payload, parsedQuerys: this.parsedQuerys(currentReq.url) };
106
102
  if (checks) {