@opengis/fastify-table 1.1.62 → 1.1.64

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.62",
3
+ "version": "1.1.64",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -18,7 +18,7 @@ export default async function deleteCrud(req) {
18
18
  const { table: del, id } = hookData || tokenData || (config.auth?.disable ? req.params : {});
19
19
  const { actions = [] } = await getAccess({ table: del, id, user }) || {};
20
20
 
21
- if (!actions.includes('del') && !config?.local) {
21
+ if (!actions.includes('del') && !config?.local && !tokenData) {
22
22
  return { message: 'access restricted', status: 403 };
23
23
  }
24
24
  const loadTemplate = await getTemplate('table', del);
@@ -6,6 +6,7 @@ export default async function insert(req) {
6
6
  const {
7
7
  user, params = {}, body = {},
8
8
  } = req || {};
9
+ if (!user) return { message: 'access restricted', status: 403 };
9
10
  const hookData = await applyHook('preInsert', { table: params?.table, user });
10
11
  if (hookData?.message && hookData?.status) {
11
12
  return { message: hookData?.message, status: hookData?.status };
@@ -18,7 +19,7 @@ export default async function insert(req) {
18
19
 
19
20
  const { actions = [] } = await getAccess({ table: add, user }) || {};
20
21
 
21
- if (!actions.includes('add') && !config?.local) {
22
+ if (!actions.includes('add') && !config?.local && !tokenData) {
22
23
  return { message: 'access restricted', status: 403 };
23
24
  }
24
25
 
@@ -38,7 +38,7 @@ export default async function tableAPI(req) {
38
38
  user,
39
39
  }) || {};
40
40
 
41
- if (!actions.includes('edit') && !config?.local) {
41
+ if (!actions.includes('edit') && !config?.local && !tokenData) {
42
42
  return { message: 'access restricted', status: 403 };
43
43
  }
44
44
 
@@ -73,12 +73,11 @@ export default async function tableAPI(req) {
73
73
  }));
74
74
  }
75
75
  if (user.uid) {
76
- const [token] = setToken({
77
- ids: [JSON.stringify({ id, table, form: loadTable.form })],
76
+ data.token = tokenData?.table ? params.table : setToken({
77
+ ids: [JSON.stringify({ id, table: tableName, form: loadTable.form })],
78
78
  uid: user.uid,
79
79
  array: 1,
80
- });
81
- data.token = token;
80
+ })[0];
82
81
  }
83
82
  const res = await applyHook('afterTable', {
84
83
  table: tableName, payload: [data], user,
@@ -5,6 +5,7 @@ import config from '../../../../config.js';
5
5
 
6
6
  export default async function update(req) {
7
7
  const { user, params = {}, body = {} } = req;
8
+ if (!user) return { message: 'access restricted', status: 403 };
8
9
  const hookData = await applyHook('preUpdate', {
9
10
  table: params?.table, id: params?.id, user,
10
11
  });
@@ -20,7 +21,7 @@ export default async function update(req) {
20
21
 
21
22
  const { actions = [] } = await getAccess({ table: edit, id, user }) || {};
22
23
 
23
- if (!actions.includes('edit') && !config?.local) {
24
+ if (!actions.includes('edit') && !config?.local && !tokenData) {
24
25
  return { message: 'access restricted', status: 403 };
25
26
  }
26
27
 
@@ -33,7 +34,7 @@ export default async function update(req) {
33
34
  }
34
35
 
35
36
  const loadTemplate = await getTemplate('table', edit);
36
- const { table } = loadTemplate || hookData || params || {};
37
+ const { table } = loadTemplate || hookData || tokenData || params || {};
37
38
 
38
39
  const uid = user?.uid;
39
40
 
@@ -56,7 +57,7 @@ export default async function update(req) {
56
57
  });
57
58
 
58
59
  // form DataTable
59
- const extraKeys = Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && body[key].length);
60
+ const extraKeys = formData ? Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && body[key].length) : [];
60
61
  if (extraKeys?.length) {
61
62
  res.extra = {};
62
63
  await Promise.all(extraKeys?.map(async (key) => {