@teamkeel/functions-runtime 0.365.14 → 0.365.15-prerelease18
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 +1 -1
- package/src/ModelAPI.js +1 -7
- package/src/ModelAPI.test.js +180 -71
- package/src/QueryBuilder.js +120 -1
- package/src/consts.js +9 -8
- package/src/database.js +6 -2
- package/src/errors.js +11 -1
- package/src/handleJob.js +2 -7
- package/src/handleJob.test.js +0 -1
- package/src/handleSubscriber.js +88 -0
- package/src/index.js +2 -0
- package/src/permissions.js +1 -2
- package/src/permissions.test.js +1 -3
- package/src/tracing.js +1 -1
- package/src/tryExecuteFunction.js +2 -2
- package/src/tryExecuteJob.js +6 -7
- package/src/tryExecuteSubscriber.js +10 -0
- package/pnpm-lock.yaml +0 -1524
|
@@ -2,9 +2,9 @@ const { withDatabase } = require("./database");
|
|
|
2
2
|
const {
|
|
3
3
|
withPermissions,
|
|
4
4
|
PERMISSION_STATE,
|
|
5
|
-
PermissionError,
|
|
6
5
|
checkBuiltInPermissions,
|
|
7
6
|
} = require("./permissions");
|
|
7
|
+
const { PermissionError } = require("./errors");
|
|
8
8
|
const { PROTO_ACTION_TYPES } = require("./consts");
|
|
9
9
|
|
|
10
10
|
// tryExecuteFunction will create a new database transaction around a function call
|
|
@@ -16,7 +16,7 @@ function tryExecuteFunction(
|
|
|
16
16
|
return withPermissions(permitted, async ({ getPermissionState }) => {
|
|
17
17
|
return withDatabase(db, actionType, async ({ transaction }) => {
|
|
18
18
|
const fnResult = await cb();
|
|
19
|
-
// api.permissions maintains an internal state of whether the current
|
|
19
|
+
// api.permissions maintains an internal state of whether the current function 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
22
|
switch (getPermissionState()) {
|
package/src/tryExecuteJob.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const { withDatabase } = require("./database");
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
PermissionError,
|
|
6
|
-
} = require("./permissions");
|
|
2
|
+
const { withPermissions, PERMISSION_STATE } = require("./permissions");
|
|
3
|
+
|
|
4
|
+
const { PermissionError } = require("./errors");
|
|
7
5
|
|
|
8
6
|
// tryExecuteJob will create a new database transaction around a function call
|
|
9
7
|
// and handle any permissions checks. If a permission check fails, then an Error will be thrown and the catch block will be hit.
|
|
@@ -11,8 +9,9 @@ function tryExecuteJob({ db, permitted, actionType, request }, cb) {
|
|
|
11
9
|
return withPermissions(permitted, async ({ getPermissionState }) => {
|
|
12
10
|
return withDatabase(db, actionType, async ({ transaction }) => {
|
|
13
11
|
await cb();
|
|
14
|
-
|
|
15
|
-
// we need to check that the final state is unpermitted. if it's not, then it means that the user has taken no explicit action to permit/deny
|
|
12
|
+
// 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).
|
|
13
|
+
// 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
|
|
14
|
+
// and therefore we default to checking the permissions defined in the schema automatically.
|
|
16
15
|
if (getPermissionState() === PERMISSION_STATE.UNPERMITTED) {
|
|
17
16
|
throw new PermissionError(`Not permitted to access ${request.method}`);
|
|
18
17
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { withDatabase } = require("./database");
|
|
2
|
+
|
|
3
|
+
// tryExecuteSubscriber will create a new database connection and execute the function call.
|
|
4
|
+
function tryExecuteSubscriber({ db, actionType }, cb) {
|
|
5
|
+
return withDatabase(db, actionType, async () => {
|
|
6
|
+
await cb();
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports.tryExecuteSubscriber = tryExecuteSubscriber;
|