@raketa-cloud/admin 1.5.0 → 1.5.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/HonoAdapter.js +26 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "main": "src/index.js",
5
5
  "files": [
6
6
  "src/",
@@ -22,7 +22,7 @@ function escapeHtml(string) {
22
22
  '<': '&lt;',
23
23
  '>': '&gt;'
24
24
  };
25
-
25
+
26
26
  return String(string).replace(/["&'<>]/g, char => escape[char]);
27
27
  }
28
28
 
@@ -47,11 +47,11 @@ function putIn(result, key, value) {
47
47
 
48
48
  segments.forEach((segment, idx) => {
49
49
  const isLastSegment = idx === segments.length - 1;
50
-
50
+
51
51
  if (isLastSegment) {
52
52
  // Set value at final segment
53
- current[segment] = key.endsWith("[]") || Array.isArray(value)
54
- ? toArray(value)
53
+ current[segment] = key.endsWith("[]") || Array.isArray(value)
54
+ ? toArray(value)
55
55
  : value;
56
56
  } else {
57
57
  // Create path to next segment
@@ -71,22 +71,22 @@ function getPartialPath(partialPath, views, viewsFallback) {
71
71
  sanitizePath(`${currentPath}/views/${views}/${partialPath}`),
72
72
  viewsFallback && sanitizePath(`${currentPath}/views/${viewsFallback}/${partialPath}`)
73
73
  ].filter(Boolean);
74
-
74
+
75
75
  // Return first existing path
76
76
  const existingPath = paths.find(path => existsSync(path));
77
-
77
+
78
78
  if (existingPath) return existingPath;
79
-
79
+
80
80
  throw new Error(`Template not found: "${partialPath}"\nSearched in:\n${paths.join('\n')}`);
81
81
  }
82
82
 
83
83
  // Parse request body based on content type
84
84
  async function parseBody(req) {
85
85
  const contentType = req.header("Content-type") || "";
86
-
86
+
87
87
  if (contentType.includes("json")) return req.json();
88
88
  if (contentType === "text/plain") return req.text();
89
-
89
+
90
90
  // Default for form data and other content types
91
91
  return req.parseBody();
92
92
  }
@@ -94,11 +94,11 @@ async function parseBody(req) {
94
94
  // Convert body to request parameters
95
95
  function bodyToParams(req, parsedBody, adapter) {
96
96
  const contentType = req.header("Content-type") || "";
97
-
97
+
98
98
  if (contentType.includes("form-data") || contentType.includes("urlencoded")) {
99
99
  return adapter.parseFormBody(parsedBody);
100
100
  }
101
-
101
+
102
102
  return parsedBody;
103
103
  }
104
104
 
@@ -113,7 +113,7 @@ export default class HonoAdapter {
113
113
  // TODO: Pass in a path to redirect to after login?
114
114
  if (config) {
115
115
  setupAuthentication(router, config);
116
-
116
+
117
117
  router.get("/", (c) => {
118
118
  return c.redirect("/en");
119
119
  });
@@ -123,11 +123,11 @@ export default class HonoAdapter {
123
123
  setGlobalContext(globalCtx) {
124
124
  this.globalCtx = globalCtx;
125
125
  }
126
-
126
+
127
127
  setBeforeFilter(pattern, filter) {
128
128
  this.globalBeforeFilters.push({ pattern, filter });
129
129
  }
130
-
130
+
131
131
  setAfterFilter(pattern, filter) {
132
132
  this.globalAfterFilters.push({ pattern, filter });
133
133
  }
@@ -264,19 +264,19 @@ export default class HonoAdapter {
264
264
  async createAction([verb, path, resource, views, action, handler], resourceConfig) {
265
265
  const method = this.getMethod(verb);
266
266
  const { i18n } = this.globalConfig;
267
-
267
+
268
268
  Object.keys(i18n.locales).forEach((currentLocale) => {
269
269
  const completePath = `/${currentLocale}${path}`;
270
-
270
+
271
271
  // Clean up existing routes with same path/verb
272
- this.router.router.routes = this.router.router.routes.filter(route =>
272
+ this.router.routes = this.router.routes.filter(route =>
273
273
  route[0] !== verb || route[1] !== completePath
274
274
  );
275
275
 
276
276
  method(completePath, async (routerCtx, next) => {
277
277
  // Create context with request data
278
278
  const ctx = await this.createContext(routerCtx, next, verb, resource, action);
279
-
279
+
280
280
  // Set context properties
281
281
  Object.assign(ctx, {
282
282
  resourceConfig,
@@ -293,7 +293,7 @@ export default class HonoAdapter {
293
293
  timezones: i18n.timezones,
294
294
  locales: ctx.locales,
295
295
  locale: ctx.locale,
296
- defaultLocale: ctx.defaultLocale,
296
+ defaultLocale: ctx.defaultLocale,
297
297
  maxOpenRevisions: ctx.maxOpenRevisions,
298
298
  path: ctx.req.path,
299
299
  query: ctx.query || {},
@@ -305,7 +305,7 @@ export default class HonoAdapter {
305
305
  };
306
306
 
307
307
  ctx.logger.info(`${ctx.method} "${ctx.rawPath}" -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`);
308
-
308
+
309
309
  const assigns = {
310
310
  beforeFilterAssigns: {},
311
311
  actionAssigns: {},
@@ -319,10 +319,10 @@ export default class HonoAdapter {
319
319
  for (const { pattern, filter } of this.globalBeforeFilters) {
320
320
  if (pattern.test(ctx.path)) {
321
321
  const result = filter(ctx) || {};
322
-
322
+
323
323
  if (result.redirect) return routerCtx.redirect(result.redirect);
324
324
  if (result.json) return routerCtx.json(result.json);
325
-
325
+
326
326
  Object.assign(assigns.beforeFilterAssigns, result.assigns || {});
327
327
  }
328
328
  }
@@ -330,7 +330,7 @@ export default class HonoAdapter {
330
330
  // Process action handler
331
331
  const result = await handler(ctx, resourceConfig) || {};
332
332
  assigns.actionAssigns = result.assigns || {};
333
-
333
+
334
334
  if (result.headers) this.applyHeaders(result.headers, routerCtx);
335
335
  if (result.redirect) return routerCtx.redirect(result.redirect);
336
336
  if (result.json) return routerCtx.json(result.json);
@@ -339,10 +339,10 @@ export default class HonoAdapter {
339
339
  for (const { pattern, filter } of this.globalAfterFilters) {
340
340
  if (pattern.test(ctx.path)) {
341
341
  const afterResult = filter(ctx) || {};
342
-
342
+
343
343
  if (afterResult.redirect) return routerCtx.redirect(afterResult.redirect);
344
344
  if (afterResult.json) return routerCtx.json(afterResult.json);
345
-
345
+
346
346
  Object.assign(assigns.afterFilterAssigns, afterResult.assigns || {});
347
347
  }
348
348
  }
@@ -401,4 +401,4 @@ export default class HonoAdapter {
401
401
  });
402
402
  return result;
403
403
  }
404
- }
404
+ }