adminforth 1.3.25 → 1.3.27

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/auth.ts CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
2
  import jwt from 'jsonwebtoken';
3
-
4
3
  import crypto from 'crypto';
5
4
  import AdminForth from './index.js';
6
5
 
@@ -19,6 +18,23 @@ function generateSalt(length = 16) {
19
18
  return crypto.randomBytes(length).toString('hex');
20
19
  }
21
20
 
21
+ function parseTimeToSeconds(time: string): number {
22
+ const unit = time.slice(-1);
23
+ const value = parseInt(time.slice(0, -1), 10);
24
+ switch (unit) {
25
+ case 's':
26
+ return value;
27
+ case 'm':
28
+ return value * 60;
29
+ case 'h':
30
+ return value * 60 * 60;
31
+ case 'd':
32
+ return value * 60 * 60 * 24;
33
+ default:
34
+ throw new Error(`Invalid time unit: ${unit}`);
35
+ }
36
+ }
37
+
22
38
  class AdminForthAuth {
23
39
  adminforth: AdminForth;
24
40
 
@@ -37,13 +53,17 @@ class AdminForthAuth {
37
53
  pk: string | null
38
54
  }) {
39
55
  const expiresIn: string = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
56
+ // might be h,m,d in string
57
+ const expiresInSec = parseTimeToSeconds(expiresIn);
40
58
 
41
59
  const token = this.issueJWT({ username, pk}, 'auth', expiresIn);
42
- response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
60
+ const expiresCookieFormat = new Date(Date.now() + expiresInSec * 1000).toUTCString();
61
+
62
+ response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${expiresCookieFormat}`);
43
63
  }
44
64
 
45
65
  removeCustomCookie({response, name}) {
46
- response.setHeader('Set-Cookie', `adminforth_test'='2'; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
66
+ response.setHeader('Set-Cookie', `adminforth_${name}=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
47
67
  }
48
68
 
49
69
  setCustomCookie({ response, payload }: {
package/dist/auth.js CHANGED
@@ -23,6 +23,22 @@ function calcPasswordHash(password, salt, iterations = 100000, keyLength = 64, d
23
23
  function generateSalt(length = 16) {
24
24
  return crypto.randomBytes(length).toString('hex');
25
25
  }
26
+ function parseTimeToSeconds(time) {
27
+ const unit = time.slice(-1);
28
+ const value = parseInt(time.slice(0, -1), 10);
29
+ switch (unit) {
30
+ case 's':
31
+ return value;
32
+ case 'm':
33
+ return value * 60;
34
+ case 'h':
35
+ return value * 60 * 60;
36
+ case 'd':
37
+ return value * 60 * 60 * 24;
38
+ default:
39
+ throw new Error(`Invalid time unit: ${unit}`);
40
+ }
41
+ }
26
42
  class AdminForthAuth {
27
43
  constructor(adminforth) {
28
44
  this.adminforth = adminforth;
@@ -32,11 +48,14 @@ class AdminForthAuth {
32
48
  }
33
49
  setAuthCookie({ expireInDays, response, username, pk }) {
34
50
  const expiresIn = expireInDays ? `${expireInDays}d` : (process.env.ADMINFORTH_AUTH_EXPIRESIN || '24h');
51
+ // might be h,m,d in string
52
+ const expiresInSec = parseTimeToSeconds(expiresIn);
35
53
  const token = this.issueJWT({ username, pk }, 'auth', expiresIn);
36
- response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
54
+ const expiresCookieFormat = new Date(Date.now() + expiresInSec * 1000).toUTCString();
55
+ response.setHeader('Set-Cookie', `adminforth_jwt=${token}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${expiresCookieFormat}`);
37
56
  }
38
57
  removeCustomCookie({ response, name }) {
39
- response.setHeader('Set-Cookie', `adminforth_test'='2'; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict`);
58
+ response.setHeader('Set-Cookie', `adminforth_${name}=; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:00 GMT`);
40
59
  }
41
60
  setCustomCookie({ response, payload }) {
42
61
  const { name, value, expiry, httpOnly } = payload;
@@ -1,5 +1,4 @@
1
- import { error } from 'console';
2
- import { IAdminForthFilter, IAdminForthSort, IOperationalResource, IAdminForthDataSourceConnectorBase, AdminForthResource, IAdminForth } from '../types/AdminForthConfig.js';
1
+ import { IAdminForthFilter, IAdminForthSort, IOperationalResource, IAdminForthDataSourceConnectorBase, AdminForthResource } from '../types/AdminForthConfig.js';
3
2
 
4
3
 
5
4
  function filtersIfFilter(filter: IAdminForthFilter | IAdminForthFilter[] | undefined): IAdminForthFilter[] {
@@ -362,8 +362,6 @@ export default class AdminForthRestAPI {
362
362
  }
363
363
  const { limit, offset, filters, sort } = body;
364
364
 
365
-
366
-
367
365
  for (const filter of (filters || [])) {
368
366
  if (!Object.values(AdminForthFilterOperators).includes(filter.operator)) {
369
367
  throw new Error(`Operator '${filter.operator}' is not allowed`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.3.25",
3
+ "version": "1.3.27",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
 
3
3
 
4
- <div id="toast-default" class="flex items-center w-full p-4 text-gray-500 rounded-lg shadow dark:text-gray-400 dark:bg-gray-800"
4
+ <div class="flex items-center w-full p-4 text-gray-500 rounded-lg shadow-lg dark:text-gray-400 dark:bg-gray-800 bg-white"
5
5
  role="alert"
6
6
  :class="
7
7
  {
@@ -156,6 +156,13 @@ async function saveRecord() {
156
156
  });
157
157
  if (resp.error) {
158
158
  showErrorTost(resp.error);
159
+ } else {
160
+ window.adminforth.alert({
161
+ message: 'Record updated successfully',
162
+ variant: 'success',
163
+ timeout: 400000
164
+
165
+ });
159
166
  }
160
167
  saving.value = false;
161
168
  router.push({ name: 'resource-show', params: { resourceId: route.params.resourceId, primaryKey: coreStore.record[coreStore.primaryKey] } });
@@ -78,7 +78,7 @@
78
78
  <td class="px-6 py-4 whitespace-nowrap "> <!--align-top-->
79
79
  {{ column.label }}
80
80
  </td>
81
- <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap">
81
+ <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap" :data-af-column="column.name">
82
82
  <component
83
83
  v-if="column?.components?.show"
84
84
  :is="getCustomComponent(column?.components?.show)"
@@ -1,5 +1,4 @@
1
1
  import type { Express } from 'express';
2
- import OperationalResource from '../modules/operationalResource.js';
3
2
 
4
3
  export interface ICodeInjector {
5
4
  srcFoldersToSync: Object;