@teamkeel/functions-runtime 0.357.1 → 0.358.0

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": "@teamkeel/functions-runtime",
3
- "version": "0.357.1",
3
+ "version": "0.358.0",
4
4
  "description": "Internal package used by @teamkeel/sdk",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/database.js CHANGED
@@ -15,7 +15,6 @@ async function withDatabase(db, actionType, cb) {
15
15
  let requiresTransaction = true;
16
16
 
17
17
  switch (actionType) {
18
- case PROTO_ACTION_TYPES.JOB:
19
18
  case PROTO_ACTION_TYPES.GET:
20
19
  case PROTO_ACTION_TYPES.LIST:
21
20
  requiresTransaction = false;
package/src/handleJob.js CHANGED
@@ -53,9 +53,13 @@ async function handleJob(request, config) {
53
53
  const db = getDatabaseClient();
54
54
  const jobFunction = jobs[request.method];
55
55
  const actionType = PROTO_ACTION_TYPES.JOB;
56
+ const permissionFns = new Object();
57
+
58
+ // Jobs will have no permission functions yet.
59
+ permissionFns[request.method] = [];
56
60
 
57
61
  const result = await tryExecuteFunction(
58
- { request, ctx, permitted, db, actionType },
62
+ { request, ctx, permissionFns, permitted, db, actionType },
59
63
  async () => {
60
64
  // Return the job function to the containing tryExecuteFunction block
61
65
  return jobFunction(ctx, request.params);
@@ -60,7 +60,6 @@ const checkBuiltInPermissions = async ({
60
60
  }) => {
61
61
  for (const permissionFn of permissionFns) {
62
62
  const result = await permissionFn(rows, ctx, db);
63
-
64
63
  // if any of the permission functions return true,
65
64
  // then we return early
66
65
  if (result) {
@@ -19,7 +19,6 @@ function tryExecuteFunction(
19
19
  // api.permissions maintains an internal state of whether the current operation has been *explicitly* permitted/denied by the user in the course of their custom function, or if execution has already been permitted by a role based permission (evaluated in the main runtime).
20
20
  // we need to check that the final state is permitted or unpermitted. if it's not, then it means that the user has taken no explicit action to permit/deny
21
21
  // and therefore we default to checking the permissions defined in the schema automatically.
22
-
23
22
  switch (getPermissionState()) {
24
23
  case PERMISSION_STATE.PERMITTED:
25
24
  return fnResult;
@@ -35,16 +34,21 @@ function tryExecuteFunction(
35
34
  actionType === PROTO_ACTION_TYPES.CREATE;
36
35
 
37
36
  let rowsForPermissions = [];
38
- switch (actionType) {
39
- case PROTO_ACTION_TYPES.LIST:
40
- rowsForPermissions = fnResult;
41
- break;
42
- case PROTO_ACTION_TYPES.DELETE:
43
- rowsForPermissions = [{ id: fnResult }];
44
- break;
45
- default:
46
- rowsForPermissions = [fnResult];
47
- break;
37
+ if (fnResult != null) {
38
+ switch (actionType) {
39
+ case PROTO_ACTION_TYPES.LIST:
40
+ rowsForPermissions = fnResult;
41
+ break;
42
+ case PROTO_ACTION_TYPES.DELETE:
43
+ rowsForPermissions = [{ id: fnResult }];
44
+ break;
45
+ case (PROTO_ACTION_TYPES.GET, PROTO_ACTION_TYPES.CREATE):
46
+ rowsForPermissions = [fnResult];
47
+ break;
48
+ default:
49
+ rowsForPermissions = [fnResult];
50
+ break;
51
+ }
48
52
  }
49
53
 
50
54
  // check will throw a PermissionError if a permission rule is invalid