@autofleet/sadot 1.6.18-beta.12 → 1.6.18-beta.15
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/dist/api/v1/field-policies/index.cjs +33 -0
- package/dist/api/v1/field-policies/index.js +34 -1
- package/dist/api/v1/index.cjs +1 -1
- package/dist/api/v1/index.js +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.js +2 -1
- package/dist/types/index.d.cts +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/utils/db/index.js +1 -1
- package/package.json +23 -23
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_index = require('../../../utils/logger/index.cjs');
|
|
3
3
|
const require_errors = require('../errors.cjs');
|
|
4
|
+
const require_mat_path_state = require('../../../mat-path-state.cjs');
|
|
5
|
+
const require_FieldPolicy = require('../../../models/FieldPolicy.cjs');
|
|
4
6
|
const require_field_policy = require('../../../repository/field-policy.cjs');
|
|
5
7
|
let sequelize = require("sequelize");
|
|
6
8
|
let _autofleet_node_common = require("@autofleet/node-common");
|
|
7
9
|
|
|
8
10
|
//#region src/api/v1/field-policies/index.ts
|
|
9
11
|
const router = (0, _autofleet_node_common.Router)({ logger: require_index.default });
|
|
12
|
+
const tableName = require_FieldPolicy.default.getTableName();
|
|
13
|
+
router.get("/:entityType/effective", async (req, res) => {
|
|
14
|
+
const EFFECTIVE_POLICY_QUERY = `
|
|
15
|
+
SELECT fp.*
|
|
16
|
+
FROM "${tableName}" fp
|
|
17
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
18
|
+
AND cep.entity_id = fp.context_id
|
|
19
|
+
AND cep.entity_type = 'context'
|
|
20
|
+
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
21
|
+
WHERE fp.entity_type = $1
|
|
22
|
+
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
23
|
+
LIMIT 1
|
|
24
|
+
`;
|
|
25
|
+
const { withMatPath } = require_mat_path_state.matPathState;
|
|
26
|
+
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
27
|
+
if (!req.headers["x-request-paths"]) return res.status(400).json({ error: "x-request-paths header is required" });
|
|
28
|
+
const { entityType } = req.params;
|
|
29
|
+
try {
|
|
30
|
+
const [policy] = await withMatPath(tableName, (transaction) => require_FieldPolicy.default.sequelize.query(EFFECTIVE_POLICY_QUERY, {
|
|
31
|
+
bind: [entityType],
|
|
32
|
+
type: sequelize.QueryTypes.SELECT,
|
|
33
|
+
transaction
|
|
34
|
+
}));
|
|
35
|
+
return res.status(200).json(policy ?? null);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return require_errors.default(err, res, {
|
|
38
|
+
logger: require_index.default,
|
|
39
|
+
message: "Error resolving effective field policy"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
10
43
|
router.get("/", async (_req, res) => {
|
|
11
44
|
try {
|
|
12
45
|
const policies = await require_field_policy.findAll();
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import logger_default from "../../../utils/logger/index.js";
|
|
2
2
|
import errors_default from "../errors.js";
|
|
3
|
+
import { matPathState } from "../../../mat-path-state.js";
|
|
4
|
+
import FieldPolicy_default from "../../../models/FieldPolicy.js";
|
|
3
5
|
import { create, findAll, remove, update } from "../../../repository/field-policy.js";
|
|
4
|
-
import { UniqueConstraintError } from "sequelize";
|
|
6
|
+
import { QueryTypes, UniqueConstraintError } from "sequelize";
|
|
5
7
|
import { Router } from "@autofleet/node-common";
|
|
6
8
|
|
|
7
9
|
//#region src/api/v1/field-policies/index.ts
|
|
8
10
|
const router = Router({ logger: logger_default });
|
|
11
|
+
const tableName = FieldPolicy_default.getTableName();
|
|
12
|
+
router.get("/:entityType/effective", async (req, res) => {
|
|
13
|
+
const EFFECTIVE_POLICY_QUERY = `
|
|
14
|
+
SELECT fp.*
|
|
15
|
+
FROM "${tableName}" fp
|
|
16
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
17
|
+
AND cep.entity_id = fp.context_id
|
|
18
|
+
AND cep.entity_type = 'context'
|
|
19
|
+
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
20
|
+
WHERE fp.entity_type = $1
|
|
21
|
+
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
22
|
+
LIMIT 1
|
|
23
|
+
`;
|
|
24
|
+
const { withMatPath } = matPathState;
|
|
25
|
+
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
26
|
+
if (!req.headers["x-request-paths"]) return res.status(400).json({ error: "x-request-paths header is required" });
|
|
27
|
+
const { entityType } = req.params;
|
|
28
|
+
try {
|
|
29
|
+
const [policy] = await withMatPath(tableName, (transaction) => FieldPolicy_default.sequelize.query(EFFECTIVE_POLICY_QUERY, {
|
|
30
|
+
bind: [entityType],
|
|
31
|
+
type: QueryTypes.SELECT,
|
|
32
|
+
transaction
|
|
33
|
+
}));
|
|
34
|
+
return res.status(200).json(policy ?? null);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return errors_default(err, res, {
|
|
37
|
+
logger: logger_default,
|
|
38
|
+
message: "Error resolving effective field policy"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
9
42
|
router.get("/", async (_req, res) => {
|
|
10
43
|
try {
|
|
11
44
|
const policies = await findAll();
|
package/dist/api/v1/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ let _autofleet_node_common = require("@autofleet/node-common");
|
|
|
9
9
|
const router = (0, _autofleet_node_common.Router)({ logger: require_index.default });
|
|
10
10
|
router.use("/custom-field-definitions/:modelName", require_index$1.default);
|
|
11
11
|
router.use("/custom-validators/:modelName", require_index$2.default);
|
|
12
|
-
router.use("/field-policies
|
|
12
|
+
router.use("/field-policies", require_index$3.default);
|
|
13
13
|
var v1_default = router;
|
|
14
14
|
|
|
15
15
|
//#endregion
|
package/dist/api/v1/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Router } from "@autofleet/node-common";
|
|
|
8
8
|
const router = Router({ logger: logger_default });
|
|
9
9
|
router.use("/custom-field-definitions/:modelName", definition_default);
|
|
10
10
|
router.use("/custom-validators/:modelName", validator_default);
|
|
11
|
-
router.use("/field-policies
|
|
11
|
+
router.use("/field-policies", field_policies_default);
|
|
12
12
|
var v1_default = router;
|
|
13
13
|
|
|
14
14
|
//#endregion
|
package/dist/index.cjs
CHANGED
|
@@ -26,8 +26,9 @@ const sadotInitState = new require_init_state.SadotInitializationState();
|
|
|
26
26
|
*/
|
|
27
27
|
const internalUseCustomFields = async (app, getModel, options) => {
|
|
28
28
|
require_index.tryAddingTraceIdMiddleware();
|
|
29
|
-
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;
|
|
29
|
+
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations, withMatPath } = options;
|
|
30
30
|
require_mat_path_state.matPathState.isMatPathEnabled = isMatPathEnabled;
|
|
31
|
+
require_mat_path_state.matPathState.withMatPath = withMatPath;
|
|
31
32
|
if (app) app.use("/api", require_index$4.default);
|
|
32
33
|
const sequelize = options.sequelize ?? require_index$5.default(options.databaseConfig);
|
|
33
34
|
if (process.env.NODE_ENV === "test") await require_index$3.initTestModels(sequelize);
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,9 @@ const sadotInitState = new SadotInitializationState();
|
|
|
25
25
|
*/
|
|
26
26
|
const internalUseCustomFields = async (app, getModel, options) => {
|
|
27
27
|
tryAddingTraceIdMiddleware();
|
|
28
|
-
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;
|
|
28
|
+
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations, withMatPath } = options;
|
|
29
29
|
matPathState.isMatPathEnabled = isMatPathEnabled;
|
|
30
|
+
matPathState.withMatPath = withMatPath;
|
|
30
31
|
if (app) app.use("/api", api_default);
|
|
31
32
|
const sequelize = options.sequelize ?? db_default(options.databaseConfig);
|
|
32
33
|
if (process.env.NODE_ENV === "test") await initTestModels(sequelize);
|
package/dist/types/index.d.cts
CHANGED
|
@@ -64,6 +64,12 @@ interface CustomFieldOptions {
|
|
|
64
64
|
* Pass `matPathManager.isScopingRequest` if using `@autofleet/mat-path-mvp`.
|
|
65
65
|
*/
|
|
66
66
|
isMatPathEnabled?: () => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Optional hook for the effective field-policy route. When provided, sadot mounts
|
|
69
|
+
* GET /field-policies/:entityType/effective and delegates scoped queries through this callback.
|
|
70
|
+
* Typically: (table, cb) => { matPathManager.setScopingMode({ [table]: SCOPING_MODE.ANCESTORS }); return matPathManager.withPaths(cb); }
|
|
71
|
+
*/
|
|
72
|
+
withMatPath?: (tableName: string, callback: (transaction: any) => Promise<any>) => Promise<any>;
|
|
67
73
|
}
|
|
68
74
|
//#endregion
|
|
69
75
|
export { CustomFieldOptions, ModelFetcher, Models };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -65,6 +65,12 @@ interface CustomFieldOptions {
|
|
|
65
65
|
* Pass `matPathManager.isScopingRequest` if using `@autofleet/mat-path-mvp`.
|
|
66
66
|
*/
|
|
67
67
|
isMatPathEnabled?: () => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Optional hook for the effective field-policy route. When provided, sadot mounts
|
|
70
|
+
* GET /field-policies/:entityType/effective and delegates scoped queries through this callback.
|
|
71
|
+
* Typically: (table, cb) => { matPathManager.setScopingMode({ [table]: SCOPING_MODE.ANCESTORS }); return matPathManager.withPaths(cb); }
|
|
72
|
+
*/
|
|
73
|
+
withMatPath?: (tableName: string, callback: (transaction: any) => Promise<any>) => Promise<any>;
|
|
68
74
|
}
|
|
69
75
|
//#endregion
|
|
70
76
|
export { CustomFieldOptions, ModelFetcher, Models };
|
package/dist/utils/db/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sadot",
|
|
3
|
-
"version": "1.6.18-beta.
|
|
3
|
+
"version": "1.6.18-beta.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,15 +22,6 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "pnpm -w tsdown -W ./packages/sadot",
|
|
27
|
-
"linter": "eslint .",
|
|
28
|
-
"test": "vitest",
|
|
29
|
-
"test-debug": "node --inspect-brk node_modules/.bin/vitest --testTimeout=10000000",
|
|
30
|
-
"coverage": "vitest --coverage",
|
|
31
|
-
"build-to-local-repo": "node --run build && cp -r dist/* ../$REPO/node_modules/$npm_package_name/dist",
|
|
32
|
-
"watch": "npm-watch build-to-local-repo"
|
|
33
|
-
},
|
|
34
25
|
"watch": {
|
|
35
26
|
"build-to-local-repo": {
|
|
36
27
|
"extensions": [
|
|
@@ -44,28 +35,28 @@
|
|
|
44
35
|
}
|
|
45
36
|
},
|
|
46
37
|
"dependencies": {
|
|
47
|
-
"@autofleet/common-types": "
|
|
48
|
-
"@autofleet/events": "workspace:^",
|
|
38
|
+
"@autofleet/common-types": "5.42.0",
|
|
49
39
|
"ajv": "^8.12.0",
|
|
50
40
|
"ajv-errors": "^3.0.0",
|
|
51
41
|
"ajv-formats": "^3.0.1",
|
|
52
42
|
"http-status-codes": "^2.3.0",
|
|
53
43
|
"joi": "^17.7.0",
|
|
54
|
-
"pg": "
|
|
44
|
+
"pg": "^8.16.3",
|
|
55
45
|
"reflect-metadata": "^0.1.13",
|
|
56
|
-
"sequelize": "
|
|
57
|
-
"sequelize-typescript": "
|
|
58
|
-
"umzug": "^3.8.3"
|
|
46
|
+
"sequelize": "^6.37.7",
|
|
47
|
+
"sequelize-typescript": "^2.1.6",
|
|
48
|
+
"umzug": "^3.8.3",
|
|
49
|
+
"@autofleet/events": "^5.3.22"
|
|
59
50
|
},
|
|
60
51
|
"devDependencies": {
|
|
61
|
-
"@autofleet/errors": "workspace:^",
|
|
62
|
-
"@autofleet/logger": "workspace:^",
|
|
63
|
-
"@autofleet/node-common": "workspace:^",
|
|
64
|
-
"@autofleet/zehut": "workspace:^",
|
|
65
52
|
"@types/express": "^4.17.17",
|
|
66
53
|
"express": "^4.21.2",
|
|
67
54
|
"npm-watch": "^0.11.0",
|
|
68
|
-
"supertest": "^7.0.0"
|
|
55
|
+
"supertest": "^7.0.0",
|
|
56
|
+
"@autofleet/errors": "^3.3.7",
|
|
57
|
+
"@autofleet/logger": "^4.7.0",
|
|
58
|
+
"@autofleet/zehut": "^4.13.4",
|
|
59
|
+
"@autofleet/node-common": "^4.3.22"
|
|
69
60
|
},
|
|
70
61
|
"peerDependencies": {
|
|
71
62
|
"@autofleet/errors": "^3",
|
|
@@ -78,5 +69,14 @@
|
|
|
78
69
|
"node": ">=18.0.0"
|
|
79
70
|
},
|
|
80
71
|
"author": "Autofleet",
|
|
81
|
-
"license": "ISC"
|
|
82
|
-
|
|
72
|
+
"license": "ISC",
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "pnpm -w tsdown -W ./packages/sadot",
|
|
75
|
+
"linter": "eslint .",
|
|
76
|
+
"test": "vitest",
|
|
77
|
+
"test-debug": "node --inspect-brk node_modules/.bin/vitest --testTimeout=10000000",
|
|
78
|
+
"coverage": "vitest --coverage",
|
|
79
|
+
"build-to-local-repo": "node --run build && cp -r dist/* ../$REPO/node_modules/$npm_package_name/dist",
|
|
80
|
+
"watch": "npm-watch build-to-local-repo"
|
|
81
|
+
}
|
|
82
|
+
}
|