@autofleet/sadot 0.7.4-beta-5d31a6b9.0 → 0.7.4
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/events/index.js +21 -20
- package/dist/utils/helpers/index.d.ts +0 -1
- package/dist/utils/helpers/index.js +1 -27
- package/package.json +1 -1
- package/src/events/index.ts +25 -24
- package/src/scopes/filter.ts +0 -1
- package/src/utils/helpers/index.ts +1 -34
- package/.env +0 -3
- package/dist/utils/helpers/excludeCustomFieldFilterScope.d.ts +0 -0
- package/dist/utils/helpers/excludeCustomFieldFilterScope.js +0 -0
- package/src/utils/helpers/excludeCustomFieldFilterScope.ts +0 -0
package/dist/events/index.js
CHANGED
|
@@ -7,18 +7,18 @@ exports.sendDimEvent = void 0;
|
|
|
7
7
|
const events_1 = __importDefault(require("@autofleet/events"));
|
|
8
8
|
const logger_1 = __importDefault(require("../utils/logger"));
|
|
9
9
|
const events = new events_1.default({ logger: logger_1.default });
|
|
10
|
-
const KEYS_TO_CONVERT = ['value'];
|
|
11
|
-
const
|
|
12
|
-
if (Object.keys(savedObject).some((key) => keysToConvert.includes(key))) {
|
|
13
|
-
|
|
14
|
-
keysToConvert.forEach((key) => {
|
|
15
|
-
if (typeof savedObject[key] === 'boolean') {
|
|
16
|
-
objectToReturn[key] = savedObject[key].toString();
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return objectToReturn;
|
|
10
|
+
const KEYS_TO_CONVERT = ['value', 'defaultValue'];
|
|
11
|
+
const stringifyBooleans = (savedObject, keysToConvert) => {
|
|
12
|
+
if (!Object.keys(savedObject).some((key) => keysToConvert.includes(key))) {
|
|
13
|
+
return savedObject;
|
|
20
14
|
}
|
|
21
|
-
|
|
15
|
+
const objectToReturn = { ...savedObject };
|
|
16
|
+
keysToConvert.forEach((key) => {
|
|
17
|
+
if (typeof savedObject[key] === 'boolean') {
|
|
18
|
+
objectToReturn[key] = savedObject[key].toString();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return objectToReturn;
|
|
22
22
|
};
|
|
23
23
|
const modelTableMapping = {
|
|
24
24
|
CustomFieldDefinition: {
|
|
@@ -32,16 +32,17 @@ const modelTableMapping = {
|
|
|
32
32
|
};
|
|
33
33
|
const sendDimEvent = (instance) => {
|
|
34
34
|
const mapping = modelTableMapping[instance.constructor.name];
|
|
35
|
-
if (mapping) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
if (!mapping) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let objectToSend = instance.get();
|
|
39
|
+
try {
|
|
40
|
+
objectToSend = stringifyBooleans(instance.get(), KEYS_TO_CONVERT);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
logger_1.default.error('Failed to convert booleans in dim event payload', err);
|
|
44
44
|
}
|
|
45
|
+
events.sendObject(mapping.tableName, mapping.eventVersion, objectToSend);
|
|
45
46
|
};
|
|
46
47
|
exports.sendDimEvent = sendDimEvent;
|
|
47
48
|
exports.default = events;
|
|
@@ -23,5 +23,4 @@ interface CustomFieldsSearchPayload {
|
|
|
23
23
|
}
|
|
24
24
|
export declare const generateRandomString: (length?: number) => string;
|
|
25
25
|
export declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
26
|
-
export declare const excludeCustomFieldFilterScope: (modelType: string, keyToExclude: string, valuesToExclude: string | string[]) => Omit<CustomFieldsSearchPayload, 'replacements'>;
|
|
27
26
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateCustomFieldSearchQueryPayload = exports.generateRandomString = void 0;
|
|
4
4
|
/* eslint-disable import/prefer-default-export */
|
|
5
5
|
const sequelize_1 = require("sequelize");
|
|
6
6
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
@@ -38,29 +38,3 @@ const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, cust
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
exports.generateCustomFieldSearchQueryPayload = generateCustomFieldSearchQueryPayload;
|
|
41
|
-
const excludeCustomFieldFilterScope = (modelType, keyToExclude, valuesToExclude) => {
|
|
42
|
-
const keyToIgnore = keyToExclude.split('.')[1];
|
|
43
|
-
const valsToIgnore = Array.isArray(valuesToExclude) ? valuesToExclude.map((v) => `'"${v}"'`).join(', ') : null;
|
|
44
|
-
const customFieldsQuery = valsToIgnore ? `AND cv.value IN (${valsToIgnore})` : '';
|
|
45
|
-
const existsCondition = `
|
|
46
|
-
EXISTS (
|
|
47
|
-
SELECT 1
|
|
48
|
-
FROM custom_field_values cv
|
|
49
|
-
INNER JOIN custom_field_definitions cd
|
|
50
|
-
ON cv.custom_field_definition_id = cd.id
|
|
51
|
-
WHERE
|
|
52
|
-
cv.model_id = "${modelType}"."id"
|
|
53
|
-
AND cd.model_type = '${modelType}'
|
|
54
|
-
AND cd.name = '${keyToIgnore}'
|
|
55
|
-
${customFieldsQuery}
|
|
56
|
-
)
|
|
57
|
-
`;
|
|
58
|
-
return {
|
|
59
|
-
where: {
|
|
60
|
-
[sequelize_1.Op.and]: [
|
|
61
|
-
sequelize_typescript_1.Sequelize.literal(existsCondition),
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
exports.excludeCustomFieldFilterScope = excludeCustomFieldFilterScope;
|
package/package.json
CHANGED
package/src/events/index.ts
CHANGED
|
@@ -3,19 +3,19 @@ import logger from '../utils/logger';
|
|
|
3
3
|
|
|
4
4
|
const events = new Events({ logger });
|
|
5
5
|
|
|
6
|
-
const KEYS_TO_CONVERT = ['value'];
|
|
6
|
+
const KEYS_TO_CONVERT = ['value', 'defaultValue'];
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
if (Object.keys(savedObject).some((key) => keysToConvert.includes(key))) {
|
|
10
|
-
|
|
11
|
-
keysToConvert.forEach((key) => {
|
|
12
|
-
if (typeof savedObject[key] === 'boolean') {
|
|
13
|
-
objectToReturn[key] = savedObject[key].toString();
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return objectToReturn;
|
|
8
|
+
const stringifyBooleans = (savedObject: any, keysToConvert: Array<string>) => {
|
|
9
|
+
if (!Object.keys(savedObject).some((key) => keysToConvert.includes(key))) {
|
|
10
|
+
return savedObject;
|
|
17
11
|
}
|
|
18
|
-
|
|
12
|
+
const objectToReturn = { ...savedObject };
|
|
13
|
+
keysToConvert.forEach((key) => {
|
|
14
|
+
if (typeof savedObject[key] === 'boolean') {
|
|
15
|
+
objectToReturn[key] = savedObject[key].toString();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return objectToReturn;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const modelTableMapping = {
|
|
@@ -31,20 +31,21 @@ const modelTableMapping = {
|
|
|
31
31
|
|
|
32
32
|
export const sendDimEvent = (instance): void => {
|
|
33
33
|
const mapping = modelTableMapping[instance.constructor.name];
|
|
34
|
-
if (mapping) {
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
objectToSend = stringifyBools(instance.get(), KEYS_TO_CONVERT);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
logger.error('Failed to convert booleans in dim event payload', err);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
events.sendObject(
|
|
43
|
-
mapping.tableName,
|
|
44
|
-
mapping.eventVersion,
|
|
45
|
-
objectToSend,
|
|
46
|
-
);
|
|
34
|
+
if (!mapping) {
|
|
35
|
+
return;
|
|
47
36
|
}
|
|
37
|
+
let objectToSend = instance.get();
|
|
38
|
+
try {
|
|
39
|
+
objectToSend = stringifyBooleans(instance.get(), KEYS_TO_CONVERT);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
logger.error('Failed to convert booleans in dim event payload', err);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
events.sendObject(
|
|
45
|
+
mapping.tableName,
|
|
46
|
+
mapping.eventVersion,
|
|
47
|
+
objectToSend,
|
|
48
|
+
);
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
export default events;
|
package/src/scopes/filter.ts
CHANGED
|
@@ -112,7 +112,6 @@ export const customFieldsFilterScope = (
|
|
|
112
112
|
if (conditionsStrings.length === 0) {
|
|
113
113
|
return {};
|
|
114
114
|
}
|
|
115
|
-
|
|
116
115
|
const customFieldConditions = conditionsStrings.join(AND_DELIMETER);
|
|
117
116
|
const subQuery = `${'SELECT model_id FROM ('
|
|
118
117
|
+ 'SELECT cv.model_id, jsonb_object_agg(cd.name, cv.value) AS custom_fields '
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import {
|
|
3
|
-
type WhereOptions, Op, type BindOrReplacements,
|
|
4
|
-
} from 'sequelize';
|
|
2
|
+
import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';
|
|
5
3
|
import { type ModelStatic, Sequelize } from 'sequelize-typescript';
|
|
6
4
|
import { randomInt } from 'node:crypto';
|
|
7
5
|
import { CustomFieldDefinitionType } from '../constants';
|
|
@@ -66,34 +64,3 @@ export const generateCustomFieldSearchQueryPayload = (
|
|
|
66
64
|
replacements: { searchTerm: `%${searchTerm}%` },
|
|
67
65
|
};
|
|
68
66
|
};
|
|
69
|
-
|
|
70
|
-
export const excludeCustomFieldFilterScope = (
|
|
71
|
-
modelType: string,
|
|
72
|
-
keyToExclude: string,
|
|
73
|
-
valuesToExclude: string | string[],
|
|
74
|
-
): Omit<CustomFieldsSearchPayload, 'replacements'> => {
|
|
75
|
-
const keyToIgnore = keyToExclude.split('.')[1];
|
|
76
|
-
const valsToIgnore = Array.isArray(valuesToExclude) ? valuesToExclude.map((v) => `'"${v}"'`).join(', ') : null;
|
|
77
|
-
const customFieldsQuery = valsToIgnore ? `AND cv.value IN (${valsToIgnore})` : '';
|
|
78
|
-
const existsCondition = `
|
|
79
|
-
EXISTS (
|
|
80
|
-
SELECT 1
|
|
81
|
-
FROM custom_field_values cv
|
|
82
|
-
INNER JOIN custom_field_definitions cd
|
|
83
|
-
ON cv.custom_field_definition_id = cd.id
|
|
84
|
-
WHERE
|
|
85
|
-
cv.model_id = "${modelType}"."id"
|
|
86
|
-
AND cd.model_type = '${modelType}'
|
|
87
|
-
AND cd.name = '${keyToIgnore}'
|
|
88
|
-
${customFieldsQuery}
|
|
89
|
-
)
|
|
90
|
-
`;
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
where: {
|
|
94
|
-
[Op.and]: [
|
|
95
|
-
Sequelize.literal(existsCondition),
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
};
|
package/.env
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|