@autofleet/sadot 1.6.18-beta.21 → 1.6.18-beta.24
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/_virtual/rolldown_runtime.cjs +0 -14
- package/dist/_virtual/rolldown_runtime.js +1 -15
- package/dist/api/v1/definition/index.cjs +4 -4
- package/dist/api/v1/index.cjs +0 -2
- package/dist/api/v1/validator/index.cjs +4 -2
- package/dist/index.cjs +8 -19
- package/dist/index.d.cts +12 -13
- package/dist/index.d.ts +12 -14
- package/dist/index.js +16 -21
- package/dist/migrations/index.cjs +1 -13
- package/dist/repository/validator.cjs +22 -23
- package/dist/{api → sadot/src/api}/v1/definition/index.js +1 -1
- package/dist/{api → sadot/src/api}/v1/index.js +0 -2
- package/dist/{api → sadot/src/api}/v1/validator/index.js +4 -2
- package/dist/{migrations → sadot/src/migrations}/index.js +2 -14
- package/dist/{models → sadot/src/models}/CustomFieldDefinition.js +2 -2
- package/dist/{models → sadot/src/models}/CustomFieldEntries.js +2 -2
- package/dist/{models → sadot/src/models}/CustomFieldModelTypeMap.js +2 -2
- package/dist/{models → sadot/src/models}/CustomFieldValue.js +2 -2
- package/dist/{models → sadot/src/models}/CustomValidator.js +2 -2
- package/dist/sadot/src/models/index.d.cts +7 -0
- package/dist/{models → sadot/src/models}/index.d.ts +0 -4
- package/dist/{models → sadot/src/models}/tests/AssociatedTestModel.js +2 -2
- package/dist/{models → sadot/src/models}/tests/TestModel.js +2 -2
- package/dist/{models → sadot/src/models}/tests/contextAwareModels/ContextAwareTestModel.js +2 -2
- package/dist/{models → sadot/src/models}/tests/contextAwareModels/ContextTestModel.js +2 -2
- package/dist/{repository → sadot/src/repository}/validator.js +22 -22
- package/dist/{types → sadot/src/types}/index.d.cts +3 -1
- package/dist/{types → sadot/src/types}/index.d.ts +3 -1
- package/dist/{utils → sadot/src/utils}/helpers/index.d.cts +2 -1
- package/dist/{utils → sadot/src/utils}/helpers/index.d.ts +2 -1
- package/dist/{utils → sadot/src/utils}/helpers/index.js +2 -1
- package/dist/utils/helpers/index.cjs +3 -1
- package/dist/zehut/src/check-permission.d.cts +6 -0
- package/dist/zehut/src/check-permission.d.ts +6 -0
- package/dist/zehut/src/errors.d.cts +1 -0
- package/dist/zehut/src/errors.d.ts +1 -0
- package/dist/zehut/src/index.d.cts +6 -0
- package/dist/zehut/src/index.d.ts +6 -0
- package/dist/zehut/src/permissions/SDK/evaluatePermissions.d.cts +1 -0
- package/dist/zehut/src/permissions/SDK/evaluatePermissions.d.ts +1 -0
- package/dist/zehut/src/permissions/SDK/types.d.cts +1 -0
- package/dist/zehut/src/permissions/SDK/types.d.ts +1 -0
- package/dist/zehut/src/permissions/index.d.cts +2 -0
- package/dist/zehut/src/permissions/index.d.ts +2 -0
- package/dist/zehut/src/permissions/middleware/requirePermissions.d.cts +1 -0
- package/dist/zehut/src/permissions/middleware/requirePermissions.d.ts +1 -0
- package/dist/zehut/src/user/ApiUser.d.cts +59 -0
- package/dist/zehut/src/user/ApiUser.d.ts +59 -0
- package/dist/zehut/src/user/fastify.d.cts +8 -0
- package/dist/zehut/src/user/fastify.d.ts +8 -0
- package/dist/zehut/src/user/index.d.cts +9 -0
- package/dist/zehut/src/user/index.d.ts +9 -0
- package/package.json +14 -2
- package/dist/api/v1/field-policies/index.cjs +0 -104
- package/dist/api/v1/field-policies/index.js +0 -103
- package/dist/migrations/004-create-field-policy-tables.cjs +0 -29
- package/dist/migrations/004-create-field-policy-tables.js +0 -27
- package/dist/migrations/005-add-entity-type-to-field-policies.cjs +0 -20
- package/dist/migrations/005-add-entity-type-to-field-policies.js +0 -18
- package/dist/models/FieldPolicy.cjs +0 -54
- package/dist/models/FieldPolicy.d.cts +0 -25
- package/dist/models/FieldPolicy.d.ts +0 -25
- package/dist/models/FieldPolicy.js +0 -53
- package/dist/models/tests/AssociatedTestModel.d.ts +0 -2
- package/dist/models/tests/TestModel.d.ts +0 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -2
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -1
- package/dist/repository/field-policy.cjs +0 -69
- package/dist/repository/field-policy.d.cts +0 -35
- package/dist/repository/field-policy.d.ts +0 -35
- package/dist/repository/field-policy.js +0 -59
- /package/dist/{api → sadot/src/api}/index.js +0 -0
- /package/dist/{api → sadot/src/api}/v1/definition/validations.js +0 -0
- /package/dist/{api → sadot/src/api}/v1/errors.js +0 -0
- /package/dist/{api → sadot/src/api}/v1/validator/validations.d.cts +0 -0
- /package/dist/{api → sadot/src/api}/v1/validator/validations.d.ts +0 -0
- /package/dist/{api → sadot/src/api}/v1/validator/validations.js +0 -0
- /package/dist/{errors → sadot/src/errors}/index.js +0 -0
- /package/dist/{events → sadot/src/events}/index.js +0 -0
- /package/dist/{hooks → sadot/src/hooks}/enrich.js +0 -0
- /package/dist/{hooks → sadot/src/hooks}/find.js +0 -0
- /package/dist/{hooks → sadot/src/hooks}/hooks.js +0 -0
- /package/dist/{hooks → sadot/src/hooks}/index.js +0 -0
- /package/dist/{hooks → sadot/src/hooks}/utils/updateInstanceValues.js +0 -0
- /package/dist/{init-state.d.cts → sadot/src/init-state.d.cts} +0 -0
- /package/dist/{init-state.d.ts → sadot/src/init-state.d.ts} +0 -0
- /package/dist/{init-state.js → sadot/src/init-state.js} +0 -0
- /package/dist/{mat-path-state.js → sadot/src/mat-path-state.js} +0 -0
- /package/dist/{migrations → sadot/src/migrations}/001-create-core-tables.js +0 -0
- /package/dist/{migrations → sadot/src/migrations}/002-create-custom-field-entries.js +0 -0
- /package/dist/{migrations → sadot/src/migrations}/003-create-custom-field-model-type-map.js +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldDefinition.d.cts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldDefinition.d.ts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldEntries.d.cts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldEntries.d.ts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldModelTypeMap.d.cts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldModelTypeMap.d.ts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldValue.d.cts +0 -0
- /package/dist/{models → sadot/src/models}/CustomFieldValue.d.ts +0 -0
- /package/dist/{models → sadot/src/models}/CustomValidator.d.cts +0 -0
- /package/dist/{models → sadot/src/models}/CustomValidator.d.ts +0 -0
- /package/dist/{models → sadot/src/models}/index.js +0 -0
- /package/dist/{repository → sadot/src/repository}/definition.js +0 -0
- /package/dist/{repository → sadot/src/repository}/entries.js +0 -0
- /package/dist/{repository → sadot/src/repository}/utils/formatValues.js +0 -0
- /package/dist/{repository → sadot/src/repository}/value.js +0 -0
- /package/dist/{scopes → sadot/src/scopes}/filter.d.cts +0 -0
- /package/dist/{scopes → sadot/src/scopes}/filter.d.ts +0 -0
- /package/dist/{scopes → sadot/src/scopes}/filter.js +0 -0
- /package/dist/{scopes → sadot/src/scopes}/helpers/filter.helpers.d.cts +0 -0
- /package/dist/{scopes → sadot/src/scopes}/helpers/filter.helpers.d.ts +0 -0
- /package/dist/{scopes → sadot/src/scopes}/helpers/filter.helpers.js +0 -0
- /package/dist/{scopes → sadot/src/scopes}/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/constants/index.d.cts +0 -0
- /package/dist/{utils → sadot/src/utils}/constants/index.d.ts +0 -0
- /package/dist/{utils → sadot/src/utils}/constants/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/db/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/init.js +0 -0
- /package/dist/{utils → sadot/src/utils}/logger/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/scopeAttributes.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/schema/custom-fields.d.cts +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/schema/custom-fields.d.ts +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/schema/custom-fields.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/schema/validator-schema.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/index.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/multi-select-dropdown.validator.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/multi-select-status.validator.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/multi-select.helpers.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/select.validator.js +0 -0
- /package/dist/{utils → sadot/src/utils}/validations/validators/status.validator.js +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import logger_default from "../utils/logger/index.js";
|
|
2
2
|
import CustomValidator_default from "../models/CustomValidator.js";
|
|
3
3
|
import "../models/index.js";
|
|
4
|
-
import
|
|
4
|
+
import { matPathState } from "../mat-path-state.js";
|
|
5
|
+
import { QueryTypes } from "sequelize";
|
|
5
6
|
|
|
6
7
|
//#region src/repository/validator.ts
|
|
7
8
|
const create = async (validatorAttributes, options = {}) => {
|
|
@@ -50,28 +51,27 @@ const disable = async (id, options) => {
|
|
|
50
51
|
logger_default.debug("custom-validator - disable validator");
|
|
51
52
|
return update(id, { disabled: true }, options);
|
|
52
53
|
};
|
|
53
|
-
const findEffective = async (
|
|
54
|
+
const findEffective = async (modelType) => {
|
|
55
|
+
const { withMatPath } = matPathState;
|
|
56
|
+
if (!withMatPath) return null;
|
|
54
57
|
const QUERY = `
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} catch (err) {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
58
|
+
SELECT cv.*, cep.path
|
|
59
|
+
FROM custom_validators cv
|
|
60
|
+
INNER JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
61
|
+
AND cep.entity_id = cv.entity_id
|
|
62
|
+
AND cep.entity_type = cv.entity_type
|
|
63
|
+
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
64
|
+
WHERE cv.model_type = :modelType
|
|
65
|
+
AND cv.disabled = false
|
|
66
|
+
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
67
|
+
LIMIT 1;
|
|
68
|
+
`;
|
|
69
|
+
const [row] = await withMatPath("custom_validators", async (transaction) => CustomValidator_default.sequelize.query(QUERY, {
|
|
70
|
+
replacements: { modelType },
|
|
71
|
+
type: QueryTypes.SELECT,
|
|
72
|
+
transaction
|
|
73
|
+
}));
|
|
74
|
+
return row;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
//#endregion
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getUser } from "../../../zehut/src/check-permission.cjs";
|
|
2
|
+
import "../../../zehut/src/index.cjs";
|
|
1
3
|
import { CustomFieldDefinition } from "../models/CustomFieldDefinition.cjs";
|
|
2
4
|
import { ModelCtor, Sequelize } from "sequelize-typescript";
|
|
3
5
|
import { IncludeOptions } from "sequelize";
|
|
@@ -45,7 +47,7 @@ interface CustomFieldOptions {
|
|
|
45
47
|
models: Models[];
|
|
46
48
|
hasTypeId?: boolean;
|
|
47
49
|
databaseConfig: any;
|
|
48
|
-
getUser: typeof
|
|
50
|
+
getUser: typeof getUser;
|
|
49
51
|
sequelize?: Sequelize;
|
|
50
52
|
useCustomFieldsEntries?: boolean;
|
|
51
53
|
useValidators?: boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getUser } from "../../../zehut/src/check-permission.js";
|
|
2
|
+
import "../../../zehut/src/index.js";
|
|
1
3
|
import { CustomFieldDefinition } from "../models/CustomFieldDefinition.js";
|
|
2
4
|
import "../models/CustomValidator.js";
|
|
3
5
|
import { IncludeOptions } from "sequelize";
|
|
@@ -46,7 +48,7 @@ interface CustomFieldOptions {
|
|
|
46
48
|
models: Models[];
|
|
47
49
|
hasTypeId?: boolean;
|
|
48
50
|
databaseConfig: any;
|
|
49
|
-
getUser: typeof
|
|
51
|
+
getUser: typeof getUser;
|
|
50
52
|
sequelize?: Sequelize;
|
|
51
53
|
useCustomFieldsEntries?: boolean;
|
|
52
54
|
useValidators?: boolean;
|
|
@@ -25,6 +25,7 @@ interface CustomFieldsSearchPayload {
|
|
|
25
25
|
replacements: BindOrReplacements;
|
|
26
26
|
}
|
|
27
27
|
declare const generateRandomString: (length?: number) => string;
|
|
28
|
+
declare const toPascalCase: (str: string) => string;
|
|
28
29
|
declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
29
30
|
//#endregion
|
|
30
|
-
export { generateCustomFieldSearchQueryPayload, generateRandomString };
|
|
31
|
+
export { generateCustomFieldSearchQueryPayload, generateRandomString, toPascalCase };
|
|
@@ -25,6 +25,7 @@ interface CustomFieldsSearchPayload {
|
|
|
25
25
|
replacements: BindOrReplacements;
|
|
26
26
|
}
|
|
27
27
|
declare const generateRandomString: (length?: number) => string;
|
|
28
|
+
declare const toPascalCase: (str: string) => string;
|
|
28
29
|
declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
29
30
|
//#endregion
|
|
30
|
-
export { generateCustomFieldSearchQueryPayload, generateRandomString };
|
|
31
|
+
export { generateCustomFieldSearchQueryPayload, generateRandomString, toPascalCase };
|
|
@@ -8,6 +8,7 @@ const generateRandomString = (length = 5) => {
|
|
|
8
8
|
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
9
9
|
return Array.from({ length }, () => characters.charAt(randomInt(52))).join("");
|
|
10
10
|
};
|
|
11
|
+
const toPascalCase = (str) => str.replace(/(^\w|-\w)/g, (subStr) => subStr.replace(/-/, "").toUpperCase());
|
|
11
12
|
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [CustomFieldDefinitionType.DATETIME, CustomFieldDefinitionType.DATE]) => {
|
|
12
13
|
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(",");
|
|
13
14
|
const subQuery = `SELECT cv.model_id FROM "custom_field_values" AS cv INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id AND cd.entity_id = '${entityId}' AND cd.model_type = '${model.name}' AND cd.deleted_at IS NULL` + (excludedTypesString ? ` AND cd.field_type NOT IN (${excludedTypesString})` : "") + " WHERE cv.deleted_at IS NULL AND CAST(cv.value AS TEXT) ILIKE :searchTerm";
|
|
@@ -18,4 +19,4 @@ const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, cust
|
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
//#endregion
|
|
21
|
-
export { generateCustomFieldSearchQueryPayload, generateRandomString };
|
|
22
|
+
export { generateCustomFieldSearchQueryPayload, generateRandomString, toPascalCase };
|
|
@@ -9,6 +9,7 @@ const generateRandomString = (length = 5) => {
|
|
|
9
9
|
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
10
10
|
return Array.from({ length }, () => characters.charAt((0, node_crypto.randomInt)(52))).join("");
|
|
11
11
|
};
|
|
12
|
+
const toPascalCase = (str) => str.replace(/(^\w|-\w)/g, (subStr) => subStr.replace(/-/, "").toUpperCase());
|
|
12
13
|
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [require_index.CustomFieldDefinitionType.DATETIME, require_index.CustomFieldDefinitionType.DATE]) => {
|
|
13
14
|
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(",");
|
|
14
15
|
const subQuery = `SELECT cv.model_id FROM "custom_field_values" AS cv INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id AND cd.entity_id = '${entityId}' AND cd.model_type = '${model.name}' AND cd.deleted_at IS NULL` + (excludedTypesString ? ` AND cd.field_type NOT IN (${excludedTypesString})` : "") + " WHERE cv.deleted_at IS NULL AND CAST(cv.value AS TEXT) ILIKE :searchTerm";
|
|
@@ -20,4 +21,5 @@ const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, cust
|
|
|
20
21
|
|
|
21
22
|
//#endregion
|
|
22
23
|
exports.generateCustomFieldSearchQueryPayload = generateCustomFieldSearchQueryPayload;
|
|
23
|
-
exports.generateRandomString = generateRandomString;
|
|
24
|
+
exports.generateRandomString = generateRandomString;
|
|
25
|
+
exports.toPascalCase = toPascalCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./user/index.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./user/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../user/index.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../user/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../SDK/types.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../SDK/types.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region ../zehut/src/user/ApiUser.d.ts
|
|
2
|
+
type AccountType = "client" | "user" | "service" | "driver";
|
|
3
|
+
type EntityPermissions = Record<string, string[]>;
|
|
4
|
+
interface UserExternalData {
|
|
5
|
+
element?: {
|
|
6
|
+
internalUser: boolean;
|
|
7
|
+
};
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface UserPayload {
|
|
11
|
+
businessModels: EntityPermissions;
|
|
12
|
+
fleets: EntityPermissions;
|
|
13
|
+
demandSources: EntityPermissions;
|
|
14
|
+
businessAccounts?: EntityPermissions;
|
|
15
|
+
accountType?: AccountType;
|
|
16
|
+
contexts?: EntityPermissions;
|
|
17
|
+
createdAt?: string;
|
|
18
|
+
externalData?: UserExternalData | null;
|
|
19
|
+
authorizedContextPaths?: string[];
|
|
20
|
+
}
|
|
21
|
+
interface PartialUserPayload {
|
|
22
|
+
businessModels?: EntityPermissions;
|
|
23
|
+
fleets?: EntityPermissions;
|
|
24
|
+
demandSources?: EntityPermissions;
|
|
25
|
+
vehicles?: EntityPermissions;
|
|
26
|
+
drivers?: EntityPermissions;
|
|
27
|
+
businessAccounts?: EntityPermissions;
|
|
28
|
+
}
|
|
29
|
+
declare class ApiUser {
|
|
30
|
+
id?: string | undefined;
|
|
31
|
+
accountType?: AccountType | undefined;
|
|
32
|
+
contextIds?: string[] | undefined;
|
|
33
|
+
requestedContextPaths?: string[] | undefined;
|
|
34
|
+
private privatePermissions;
|
|
35
|
+
private readonly privateElevatedPermissionsHash;
|
|
36
|
+
private privatePermissionsLegacy;
|
|
37
|
+
private readonly appPermission;
|
|
38
|
+
readonly emptyUser: boolean;
|
|
39
|
+
private privateAuthorizedContextPaths;
|
|
40
|
+
constructor(id?: string | undefined, accountType?: AccountType | undefined, elevatedPermissions?: PartialUserPayload, contextIds?: string[] | undefined, requestedContextPaths?: string[] | undefined);
|
|
41
|
+
getUserPermissions(): Promise<UserPayload>;
|
|
42
|
+
useCustomPermissionLoader(customPermissionLoader: (userId: string) => UserPayload | PromiseLike<UserPayload>): Promise<UserPayload>;
|
|
43
|
+
get businessModels(): string[];
|
|
44
|
+
get fleets(): string[];
|
|
45
|
+
get demandSources(): string[];
|
|
46
|
+
private getUserProperty;
|
|
47
|
+
get elevatedPermissions(): UserPayload;
|
|
48
|
+
get permissions(): UserPayload | undefined;
|
|
49
|
+
get authorizedContextPaths(): string[];
|
|
50
|
+
elevatePermissions(addedPermissions: PartialUserPayload): (() => void) & {
|
|
51
|
+
[Symbol.dispose]: () => void;
|
|
52
|
+
};
|
|
53
|
+
getUserPermissionsLegacy(): Promise<unknown>;
|
|
54
|
+
get permissionsLegacy(): any;
|
|
55
|
+
getUserAppPermissions(appId: string, clientSecret: string): Promise<UserPayload | undefined>;
|
|
56
|
+
extendRequiredContexts(contextIdsToAdd?: string[]): void;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ApiUser, UserPayload };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region ../zehut/src/user/ApiUser.d.ts
|
|
2
|
+
type AccountType = "client" | "user" | "service" | "driver";
|
|
3
|
+
type EntityPermissions = Record<string, string[]>;
|
|
4
|
+
interface UserExternalData {
|
|
5
|
+
element?: {
|
|
6
|
+
internalUser: boolean;
|
|
7
|
+
};
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface UserPayload {
|
|
11
|
+
businessModels: EntityPermissions;
|
|
12
|
+
fleets: EntityPermissions;
|
|
13
|
+
demandSources: EntityPermissions;
|
|
14
|
+
businessAccounts?: EntityPermissions;
|
|
15
|
+
accountType?: AccountType;
|
|
16
|
+
contexts?: EntityPermissions;
|
|
17
|
+
createdAt?: string;
|
|
18
|
+
externalData?: UserExternalData | null;
|
|
19
|
+
authorizedContextPaths?: string[];
|
|
20
|
+
}
|
|
21
|
+
interface PartialUserPayload {
|
|
22
|
+
businessModels?: EntityPermissions;
|
|
23
|
+
fleets?: EntityPermissions;
|
|
24
|
+
demandSources?: EntityPermissions;
|
|
25
|
+
vehicles?: EntityPermissions;
|
|
26
|
+
drivers?: EntityPermissions;
|
|
27
|
+
businessAccounts?: EntityPermissions;
|
|
28
|
+
}
|
|
29
|
+
declare class ApiUser {
|
|
30
|
+
id?: string | undefined;
|
|
31
|
+
accountType?: AccountType | undefined;
|
|
32
|
+
contextIds?: string[] | undefined;
|
|
33
|
+
requestedContextPaths?: string[] | undefined;
|
|
34
|
+
private privatePermissions;
|
|
35
|
+
private readonly privateElevatedPermissionsHash;
|
|
36
|
+
private privatePermissionsLegacy;
|
|
37
|
+
private readonly appPermission;
|
|
38
|
+
readonly emptyUser: boolean;
|
|
39
|
+
private privateAuthorizedContextPaths;
|
|
40
|
+
constructor(id?: string | undefined, accountType?: AccountType | undefined, elevatedPermissions?: PartialUserPayload, contextIds?: string[] | undefined, requestedContextPaths?: string[] | undefined);
|
|
41
|
+
getUserPermissions(): Promise<UserPayload>;
|
|
42
|
+
useCustomPermissionLoader(customPermissionLoader: (userId: string) => UserPayload | PromiseLike<UserPayload>): Promise<UserPayload>;
|
|
43
|
+
get businessModels(): string[];
|
|
44
|
+
get fleets(): string[];
|
|
45
|
+
get demandSources(): string[];
|
|
46
|
+
private getUserProperty;
|
|
47
|
+
get elevatedPermissions(): UserPayload;
|
|
48
|
+
get permissions(): UserPayload | undefined;
|
|
49
|
+
get authorizedContextPaths(): string[];
|
|
50
|
+
elevatePermissions(addedPermissions: PartialUserPayload): (() => void) & {
|
|
51
|
+
[Symbol.dispose]: () => void;
|
|
52
|
+
};
|
|
53
|
+
getUserPermissionsLegacy(): Promise<unknown>;
|
|
54
|
+
get permissionsLegacy(): any;
|
|
55
|
+
getUserAppPermissions(appId: string, clientSecret: string): Promise<UserPayload | undefined>;
|
|
56
|
+
extendRequiredContexts(contextIdsToAdd?: string[]): void;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ApiUser, UserPayload };
|
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.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,6 +32,16 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"quiet": false
|
|
35
|
+
},
|
|
36
|
+
"build-to-vehicle-ms": {
|
|
37
|
+
"extensions": [
|
|
38
|
+
"js",
|
|
39
|
+
"ts"
|
|
40
|
+
],
|
|
41
|
+
"patterns": [
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
44
|
+
"quiet": false
|
|
35
45
|
}
|
|
36
46
|
},
|
|
37
47
|
"dependencies": {
|
|
@@ -77,6 +87,8 @@
|
|
|
77
87
|
"test-debug": "node --inspect-brk node_modules/.bin/vitest --testTimeout=10000000",
|
|
78
88
|
"coverage": "vitest --coverage",
|
|
79
89
|
"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"
|
|
90
|
+
"watch": "npm-watch build-to-local-repo",
|
|
91
|
+
"build-to-vehicle-ms": "node ../../node_modules/.bin/tsdown --config ./tsdown.config.ts && cp -r dist/* ../../../vehicle-ms/node_modules/@autofleet/sadot/dist",
|
|
92
|
+
"watch-vehicle-ms": "npm-watch build-to-vehicle-ms"
|
|
81
93
|
}
|
|
82
94
|
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_index = require('../../../utils/logger/index.cjs');
|
|
3
|
-
const require_errors = require('../errors.cjs');
|
|
4
|
-
const require_mat_path_state = require('../../../mat-path-state.cjs');
|
|
5
|
-
const require_field_policy = require('../../../repository/field-policy.cjs');
|
|
6
|
-
let sequelize = require("sequelize");
|
|
7
|
-
let _autofleet_node_common = require("@autofleet/node-common");
|
|
8
|
-
|
|
9
|
-
//#region src/api/v1/field-policies/index.ts
|
|
10
|
-
const router = (0, _autofleet_node_common.Router)({
|
|
11
|
-
logger: require_index.default,
|
|
12
|
-
mergeParams: true
|
|
13
|
-
});
|
|
14
|
-
router.get("/effective", async (req, res) => {
|
|
15
|
-
const { withMatPath } = require_mat_path_state.matPathState;
|
|
16
|
-
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
17
|
-
const entityType = req.params.entityType;
|
|
18
|
-
try {
|
|
19
|
-
const [policy] = await require_field_policy.findEffectivePolicy(entityType);
|
|
20
|
-
return res.status(200).json(policy ?? null);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
return require_errors.default(err, res, {
|
|
23
|
-
logger: require_index.default,
|
|
24
|
-
message: "Error resolving effective field policy"
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
router.get("/", async (_req, res) => {
|
|
29
|
-
try {
|
|
30
|
-
const policies = await require_field_policy.findAll();
|
|
31
|
-
res.status(200).json(policies);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
require_errors.default(err, res, {
|
|
34
|
-
logger: require_index.default,
|
|
35
|
-
message: "Error in get field policies request"
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
router.post("/", async (req, res) => {
|
|
40
|
-
const { contextId, name, entityType, fields, models } = req.body;
|
|
41
|
-
if (!contextId || !name) {
|
|
42
|
-
res.status(400).json({ error: "contextId and name are required" });
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const policy = await require_field_policy.create({
|
|
47
|
-
contextId,
|
|
48
|
-
name,
|
|
49
|
-
entityType,
|
|
50
|
-
fields,
|
|
51
|
-
models
|
|
52
|
-
});
|
|
53
|
-
res.status(201).json(policy);
|
|
54
|
-
} catch (err) {
|
|
55
|
-
if (err instanceof sequelize.UniqueConstraintError) {
|
|
56
|
-
res.status(409).json({ error: "A field policy for this contextId and name already exists" });
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
require_errors.default(err, res, {
|
|
60
|
-
logger: require_index.default,
|
|
61
|
-
message: "Error in create field policy request"
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
router.put("/:policyId", async (req, res) => {
|
|
66
|
-
const { policyId } = req.params;
|
|
67
|
-
const { entityType, fields, models } = req.body;
|
|
68
|
-
try {
|
|
69
|
-
const updated = await require_field_policy.update(policyId, {
|
|
70
|
-
entityType,
|
|
71
|
-
fields,
|
|
72
|
-
models
|
|
73
|
-
});
|
|
74
|
-
if (!updated) {
|
|
75
|
-
res.status(404).json({ error: "Field policy not found" });
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
res.status(200).json(updated);
|
|
79
|
-
} catch (err) {
|
|
80
|
-
require_errors.default(err, res, {
|
|
81
|
-
logger: require_index.default,
|
|
82
|
-
message: "Error in update field policy request"
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
router.delete("/:policyId", async (req, res) => {
|
|
87
|
-
const { policyId } = req.params;
|
|
88
|
-
try {
|
|
89
|
-
if (!await require_field_policy.remove(policyId)) {
|
|
90
|
-
res.status(404).json({ error: "Field policy not found" });
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
res.status(204).send();
|
|
94
|
-
} catch (err) {
|
|
95
|
-
require_errors.default(err, res, {
|
|
96
|
-
logger: require_index.default,
|
|
97
|
-
message: "Error in delete field policy request"
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
var field_policies_default = router;
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
exports.default = field_policies_default;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import logger_default from "../../../utils/logger/index.js";
|
|
2
|
-
import errors_default from "../errors.js";
|
|
3
|
-
import { matPathState } from "../../../mat-path-state.js";
|
|
4
|
-
import { create, findAll, findEffectivePolicy, remove, update } from "../../../repository/field-policy.js";
|
|
5
|
-
import { UniqueConstraintError } from "sequelize";
|
|
6
|
-
import { Router } from "@autofleet/node-common";
|
|
7
|
-
|
|
8
|
-
//#region src/api/v1/field-policies/index.ts
|
|
9
|
-
const router = Router({
|
|
10
|
-
logger: logger_default,
|
|
11
|
-
mergeParams: true
|
|
12
|
-
});
|
|
13
|
-
router.get("/effective", async (req, res) => {
|
|
14
|
-
const { withMatPath } = matPathState;
|
|
15
|
-
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
16
|
-
const entityType = req.params.entityType;
|
|
17
|
-
try {
|
|
18
|
-
const [policy] = await findEffectivePolicy(entityType);
|
|
19
|
-
return res.status(200).json(policy ?? null);
|
|
20
|
-
} catch (err) {
|
|
21
|
-
return errors_default(err, res, {
|
|
22
|
-
logger: logger_default,
|
|
23
|
-
message: "Error resolving effective field policy"
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
router.get("/", async (_req, res) => {
|
|
28
|
-
try {
|
|
29
|
-
const policies = await findAll();
|
|
30
|
-
res.status(200).json(policies);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
errors_default(err, res, {
|
|
33
|
-
logger: logger_default,
|
|
34
|
-
message: "Error in get field policies request"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
router.post("/", async (req, res) => {
|
|
39
|
-
const { contextId, name, entityType, fields, models } = req.body;
|
|
40
|
-
if (!contextId || !name) {
|
|
41
|
-
res.status(400).json({ error: "contextId and name are required" });
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const policy = await create({
|
|
46
|
-
contextId,
|
|
47
|
-
name,
|
|
48
|
-
entityType,
|
|
49
|
-
fields,
|
|
50
|
-
models
|
|
51
|
-
});
|
|
52
|
-
res.status(201).json(policy);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
if (err instanceof UniqueConstraintError) {
|
|
55
|
-
res.status(409).json({ error: "A field policy for this contextId and name already exists" });
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
errors_default(err, res, {
|
|
59
|
-
logger: logger_default,
|
|
60
|
-
message: "Error in create field policy request"
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
router.put("/:policyId", async (req, res) => {
|
|
65
|
-
const { policyId } = req.params;
|
|
66
|
-
const { entityType, fields, models } = req.body;
|
|
67
|
-
try {
|
|
68
|
-
const updated = await update(policyId, {
|
|
69
|
-
entityType,
|
|
70
|
-
fields,
|
|
71
|
-
models
|
|
72
|
-
});
|
|
73
|
-
if (!updated) {
|
|
74
|
-
res.status(404).json({ error: "Field policy not found" });
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
res.status(200).json(updated);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
errors_default(err, res, {
|
|
80
|
-
logger: logger_default,
|
|
81
|
-
message: "Error in update field policy request"
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
router.delete("/:policyId", async (req, res) => {
|
|
86
|
-
const { policyId } = req.params;
|
|
87
|
-
try {
|
|
88
|
-
if (!await remove(policyId)) {
|
|
89
|
-
res.status(404).json({ error: "Field policy not found" });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
res.status(204).send();
|
|
93
|
-
} catch (err) {
|
|
94
|
-
errors_default(err, res, {
|
|
95
|
-
logger: logger_default,
|
|
96
|
-
message: "Error in delete field policy request"
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
var field_policies_default = router;
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
export { field_policies_default as default };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/migrations/004-create-field-policy-tables.ts
|
|
3
|
-
const up = async ({ context: queryInterface }) => {
|
|
4
|
-
const { sequelize } = queryInterface;
|
|
5
|
-
await sequelize.query(`
|
|
6
|
-
CREATE TABLE IF NOT EXISTS "field_policies" (
|
|
7
|
-
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
|
|
8
|
-
"context_id" UUID NOT NULL,
|
|
9
|
-
"name" VARCHAR NOT NULL,
|
|
10
|
-
"fields" JSONB NOT NULL DEFAULT '[]',
|
|
11
|
-
"models" JSONB NOT NULL DEFAULT '[]',
|
|
12
|
-
"created_at" TIMESTAMPTZ NOT NULL,
|
|
13
|
-
"updated_at" TIMESTAMPTZ,
|
|
14
|
-
PRIMARY KEY ("id")
|
|
15
|
-
)
|
|
16
|
-
`);
|
|
17
|
-
await sequelize.query(`
|
|
18
|
-
CREATE UNIQUE INDEX IF NOT EXISTS "unique_context_policy"
|
|
19
|
-
ON "field_policies" ("context_id", "name")
|
|
20
|
-
`);
|
|
21
|
-
};
|
|
22
|
-
const down = async ({ context: queryInterface }) => {
|
|
23
|
-
const { sequelize } = queryInterface;
|
|
24
|
-
await sequelize.query("DROP TABLE IF EXISTS \"field_policies\"");
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
exports.down = down;
|
|
29
|
-
exports.up = up;
|