@wandzai/utils 1.0.58-interactions-close-btn-2 → 1.0.58-interactions-close-btn-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/package.json +1 -1
- package/src/cache.d.ts +1 -0
- package/src/cache.js +6 -0
- package/src/cache.js.map +1 -0
- package/src/common.d.ts +16 -0
- package/src/common.js +93 -0
- package/src/common.js.map +1 -0
- package/src/date.d.ts +7 -0
- package/src/date.js +34 -0
- package/src/date.js.map +1 -0
- package/src/encrypt-decrypt.d.ts +2 -0
- package/src/encrypt-decrypt.js +17 -0
- package/src/encrypt-decrypt.js.map +1 -0
- package/src/gzip.d.ts +1 -0
- package/src/gzip.js +22 -0
- package/src/gzip.js.map +1 -0
- package/src/hash.d.ts +1 -0
- package/src/hash.js +17 -0
- package/src/hash.js.map +1 -0
- package/src/http.d.ts +5 -0
- package/src/http.js +47 -0
- package/src/http.js.map +1 -0
- package/src/index.js +30 -0
- package/src/index.js.map +1 -0
- package/src/interactions.d.ts +5 -0
- package/src/{interactions.ts → interactions.js} +31 -35
- package/src/interactions.js.map +1 -0
- package/src/mysql.d.ts +1 -0
- package/src/mysql.js +19 -0
- package/src/mysql.js.map +1 -0
- package/src/numeric.d.ts +2 -0
- package/src/numeric.js +14 -0
- package/src/numeric.js.map +1 -0
- package/src/schedule.d.ts +8 -0
- package/src/schedule.js +31 -0
- package/src/schedule.js.map +1 -0
- package/src/snowflake.d.ts +3 -0
- package/src/snowflake.js +31 -0
- package/src/snowflake.js.map +1 -0
- package/src/wandz.d.ts +17 -0
- package/src/wandz.js +118 -0
- package/src/wandz.js.map +1 -0
- package/src/cache.ts +0 -1
- package/src/common.ts +0 -104
- package/src/date.ts +0 -37
- package/src/encrypt-decrypt.ts +0 -14
- package/src/gzip.ts +0 -30
- package/src/hash.ts +0 -12
- package/src/http.ts +0 -64
- package/src/mysql.ts +0 -14
- package/src/numeric.ts +0 -9
- package/src/schedule.ts +0 -35
- package/src/snowflake.ts +0 -23
- package/src/wandz.ts +0 -132
- package/tsconfig.lib.json +0 -9
- /package/src/{index.ts → index.d.ts} +0 -0
package/src/wandz.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AdaptiveSearchReplaceLabels, AiFeatureDistributionType, IAdaptiveSearch, IAffinityBasedCustomAiFeatureConfig, IAiFeaturesBasicConfig, IAudience, ICustomAiFeature, ICustomAudience, IEntity, IEventBasedCustomAiFeatureConfig, IPredictionModel, IStorageBasedCustomAiFeatureConfig, IWandzAiFeaturesConfig, WandzEntities } from '@wandzai/wandz-interfaces';
|
|
2
|
+
export declare const entityTechNameBuilder: (entityName: string) => string;
|
|
3
|
+
export declare function isAffinityBasedCustomAiFeature(feature: ICustomAiFeature): feature is IAffinityBasedCustomAiFeatureConfig;
|
|
4
|
+
export declare function isStorageBasedCustomAiFeature(feature: ICustomAiFeature): feature is IStorageBasedCustomAiFeatureConfig;
|
|
5
|
+
export declare function isEventBasedCustomAiFeature(feature: ICustomAiFeature): feature is IEventBasedCustomAiFeatureConfig;
|
|
6
|
+
export declare const getCustomAiFeatureType: (feature: ICustomAiFeature) => AiFeatureDistributionType;
|
|
7
|
+
export declare const isAiFeature: (entity: IEntity) => entity is IAiFeaturesBasicConfig;
|
|
8
|
+
export declare const isAudience: (entity: IEntity) => entity is IAudience;
|
|
9
|
+
export declare const isCustomEntity: (entity: IEntity) => boolean;
|
|
10
|
+
export declare const isCustomAudience: (audience: IAudience) => audience is ICustomAudience;
|
|
11
|
+
export declare const isCustomAiFeature: (feature: IAiFeaturesBasicConfig) => feature is ICustomAiFeature;
|
|
12
|
+
export declare const isInHouseAiFeature: (entity: IEntity) => entity is IWandzAiFeaturesConfig;
|
|
13
|
+
export declare const isModel: (entity: IEntity) => entity is IPredictionModel;
|
|
14
|
+
export declare const getEntityID: (entity: IEntity) => string;
|
|
15
|
+
export declare const getEntityType: (entity: IEntity) => WandzEntities;
|
|
16
|
+
export declare const getEntityDisplayName: (entity: IEntity) => string;
|
|
17
|
+
export declare const getAdaptiveSearchDataByField: (search: IAdaptiveSearch, label: AdaptiveSearchReplaceLabels) => any;
|
package/src/wandz.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAdaptiveSearchDataByField = exports.getEntityDisplayName = exports.getEntityType = exports.getEntityID = exports.isModel = exports.isInHouseAiFeature = exports.isCustomAiFeature = exports.isCustomAudience = exports.isCustomEntity = exports.isAudience = exports.isAiFeature = exports.getCustomAiFeatureType = exports.entityTechNameBuilder = void 0;
|
|
4
|
+
exports.isAffinityBasedCustomAiFeature = isAffinityBasedCustomAiFeature;
|
|
5
|
+
exports.isStorageBasedCustomAiFeature = isStorageBasedCustomAiFeature;
|
|
6
|
+
exports.isEventBasedCustomAiFeature = isEventBasedCustomAiFeature;
|
|
7
|
+
const wandz_interfaces_1 = require("@wandzai/wandz-interfaces");
|
|
8
|
+
const entityTechNameBuilder = (entityName) => {
|
|
9
|
+
return entityName
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.replace(/ /g, '_')
|
|
12
|
+
.replace(/[^\w_.]+/g, '');
|
|
13
|
+
};
|
|
14
|
+
exports.entityTechNameBuilder = entityTechNameBuilder;
|
|
15
|
+
function isAffinityBasedCustomAiFeature(feature) {
|
|
16
|
+
return feature.affinityType != null;
|
|
17
|
+
}
|
|
18
|
+
function isStorageBasedCustomAiFeature(feature) {
|
|
19
|
+
return feature.storageLogic != null;
|
|
20
|
+
}
|
|
21
|
+
function isEventBasedCustomAiFeature(feature) {
|
|
22
|
+
return feature.eventLogic != null;
|
|
23
|
+
}
|
|
24
|
+
const getCustomAiFeatureType = (feature) => {
|
|
25
|
+
if (isEventBasedCustomAiFeature(feature)) {
|
|
26
|
+
return 'event';
|
|
27
|
+
}
|
|
28
|
+
else if (isAffinityBasedCustomAiFeature(feature)) {
|
|
29
|
+
return feature.affinityType;
|
|
30
|
+
}
|
|
31
|
+
return 'storage';
|
|
32
|
+
};
|
|
33
|
+
exports.getCustomAiFeatureType = getCustomAiFeatureType;
|
|
34
|
+
const isAiFeature = (entity) => {
|
|
35
|
+
return entity.aiFeature != null;
|
|
36
|
+
};
|
|
37
|
+
exports.isAiFeature = isAiFeature;
|
|
38
|
+
const isAudience = (entity) => {
|
|
39
|
+
return entity.operator != null && entity.rules != null;
|
|
40
|
+
};
|
|
41
|
+
exports.isAudience = isAudience;
|
|
42
|
+
const isCustomEntity = (entity) => {
|
|
43
|
+
return (entity.hasOwnProperty('createdBy'));
|
|
44
|
+
};
|
|
45
|
+
exports.isCustomEntity = isCustomEntity;
|
|
46
|
+
const isCustomAudience = (audience) => {
|
|
47
|
+
return (0, exports.isCustomEntity)(audience);
|
|
48
|
+
};
|
|
49
|
+
exports.isCustomAudience = isCustomAudience;
|
|
50
|
+
const isCustomAiFeature = (feature) => {
|
|
51
|
+
return (0, exports.isCustomEntity)(feature);
|
|
52
|
+
};
|
|
53
|
+
exports.isCustomAiFeature = isCustomAiFeature;
|
|
54
|
+
const isInHouseAiFeature = (entity) => {
|
|
55
|
+
return (0, exports.isAiFeature)(entity) && !(0, exports.isCustomEntity)(entity);
|
|
56
|
+
};
|
|
57
|
+
exports.isInHouseAiFeature = isInHouseAiFeature;
|
|
58
|
+
const isModel = (entity) => {
|
|
59
|
+
return entity.targetRules != null;
|
|
60
|
+
};
|
|
61
|
+
exports.isModel = isModel;
|
|
62
|
+
const getEntityID = (entity) => {
|
|
63
|
+
if ((0, exports.isAiFeature)(entity)) {
|
|
64
|
+
return entity.id?.toString();
|
|
65
|
+
}
|
|
66
|
+
else if ((0, exports.isAudience)(entity)) {
|
|
67
|
+
return entity.guid;
|
|
68
|
+
}
|
|
69
|
+
else if ((0, exports.isModel)(entity)) {
|
|
70
|
+
return entity.guid;
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
};
|
|
74
|
+
exports.getEntityID = getEntityID;
|
|
75
|
+
const getEntityType = (entity) => {
|
|
76
|
+
if ((0, exports.isAiFeature)(entity)) {
|
|
77
|
+
return wandz_interfaces_1.WandzEntities.AI_FEATURE;
|
|
78
|
+
}
|
|
79
|
+
else if ((0, exports.isAudience)(entity)) {
|
|
80
|
+
return wandz_interfaces_1.WandzEntities.AUDIENCE;
|
|
81
|
+
}
|
|
82
|
+
else if ((0, exports.isModel)(entity)) {
|
|
83
|
+
return wandz_interfaces_1.WandzEntities.MODEL;
|
|
84
|
+
}
|
|
85
|
+
return wandz_interfaces_1.WandzEntities.AI_FEATURE;
|
|
86
|
+
};
|
|
87
|
+
exports.getEntityType = getEntityType;
|
|
88
|
+
const getEntityDisplayName = (entity) => {
|
|
89
|
+
if ((0, exports.isAiFeature)(entity)) {
|
|
90
|
+
return entity.displayName;
|
|
91
|
+
}
|
|
92
|
+
else if ((0, exports.isAudience)(entity)) {
|
|
93
|
+
return entity.displayName;
|
|
94
|
+
}
|
|
95
|
+
else if ((0, exports.isModel)(entity)) {
|
|
96
|
+
return entity.name;
|
|
97
|
+
}
|
|
98
|
+
return '';
|
|
99
|
+
};
|
|
100
|
+
exports.getEntityDisplayName = getEntityDisplayName;
|
|
101
|
+
const getAdaptiveSearchDataByField = (search, label) => {
|
|
102
|
+
switch (label) {
|
|
103
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.CONTENTS:
|
|
104
|
+
return search.whatToShow.contents;
|
|
105
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.PRIORITIZE_BY:
|
|
106
|
+
return search.whatToShow.priority;
|
|
107
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.SUGGESTIONS_MAX_QUANTITY:
|
|
108
|
+
return search.whatToShow.suggestionsAmount;
|
|
109
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.TEST_GROUP_SIZE:
|
|
110
|
+
return search.testGroupSize;
|
|
111
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.NUM_CHARACTERS_STOP_SHOWING:
|
|
112
|
+
return search.typedCharactersToStopShowing;
|
|
113
|
+
case wandz_interfaces_1.AdaptiveSearchReplaceLabels.ADD_ADAPTIVE_URL_PARAM:
|
|
114
|
+
return search.addUrlParam;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.getAdaptiveSearchDataByField = getAdaptiveSearchDataByField;
|
|
118
|
+
//# sourceMappingURL=wandz.js.map
|
package/src/wandz.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wandz.js","sourceRoot":"","sources":["../../../../libs/utils/src/wandz.ts"],"names":[],"mappings":";;;AA6BA,wEAIC;AAED,sEAIC;AAED,kEAEC;AA3CD,gEAemC;AAG5B,MAAM,qBAAqB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAK1D,OAAO,UAAU;SACd,WAAW,EAAE;SACb,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC;AAEF,SAAgB,8BAA8B,CAC5C,OAAyB;IAEzB,OAAQ,OAA+C,CAAC,YAAY,IAAI,IAAI,CAAC;AAC/E,CAAC;AAED,SAAgB,6BAA6B,CAC3C,OAAyB;IAEzB,OAAQ,OAA8C,CAAC,YAAY,IAAI,IAAI,CAAC;AAC9E,CAAC;AAED,SAAgB,2BAA2B,CAAC,OAAyB;IACnE,OAAQ,OAA4C,CAAC,UAAU,IAAI,IAAI,CAAC;AAC1E,CAAC;AAEM,MAAM,sBAAsB,GAAG,CAAC,OAAyB,EAA6B,EAAE;IAC7F,IAAI,2BAA2B,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,IAAI,8BAA8B,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,OAAO,OAAO,CAAC,YAAY,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,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oBAAoB,wBAS/B;AAGK,MAAM,4BAA4B,GAAG,CAAC,MAAuB,EAAE,KAAkC,EAAO,EAAE;IAC7G,QAAQ,KAAK,EAAE,CAAC;QACZ,KAAK,8CAA2B,CAAC,QAAQ;YACrC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;QACtC,KAAK,8CAA2B,CAAC,aAAa;YAC1C,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;QACtC,KAAK,8CAA2B,CAAC,wBAAwB;YACrD,OAAO,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC;QAC/C,KAAK,8CAA2B,CAAC,eAAe;YAC5C,OAAO,MAAM,CAAC,aAAa,CAAC;QAChC,KAAK,8CAA2B,CAAC,2BAA2B;YACxD,OAAO,MAAM,CAAC,4BAA4B,CAAC;QAC/C,KAAK,8CAA2B,CAAC,sBAAsB;YACnD,OAAO,MAAM,CAAC,WAAW,CAAC;IAClC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,4BAA4B,gCAevC"}
|
package/src/cache.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const cacheKeyBuilder = (cacheKey: string, identifiers: any): string => `${cacheKey}${JSON.stringify(identifiers)}`;
|
package/src/common.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
export const fakeDelay = (milliSec: number) =>
|
|
2
|
-
new Promise((resolve) => {
|
|
3
|
-
setTimeout(resolve, milliSec);
|
|
4
|
-
});
|
|
5
|
-
|
|
6
|
-
export const convertCamelCaseToUnderscore = (term: string):
|
|
7
|
-
string =>
|
|
8
|
-
term
|
|
9
|
-
.split(/\.?(?=[A-Z])/)
|
|
10
|
-
.join('_')
|
|
11
|
-
.toLowerCase();
|
|
12
|
-
export const convertUnderscoreToCamelCase = (underscoreString: string): string => {
|
|
13
|
-
return underscoreString.replace(/_([a-z])/g, (_match: string, group) => {
|
|
14
|
-
return group.toUpperCase();
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const convertUnderscoreToCamelCaseObj = (obj: Record<string, any>): Record<string, any> => {
|
|
19
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
20
|
-
acc[convertUnderscoreToCamelCase(key)] = obj[key];
|
|
21
|
-
return acc;
|
|
22
|
-
}, {});
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export const convertCamelCaseToUnderscoreObj = (obj: Record<string, any>): Record<string, any> => {
|
|
27
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
28
|
-
acc[convertCamelCaseToUnderscore(key)] = obj[key];
|
|
29
|
-
return acc;
|
|
30
|
-
}, {});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const kebabToDisplayName = (kebabCase: string) => kebabCase
|
|
35
|
-
.split('-')
|
|
36
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
37
|
-
.join(' ');
|
|
38
|
-
|
|
39
|
-
export const stringifyWithSingleQuotes = (arr: any[]) => {
|
|
40
|
-
return JSON.stringify(arr, (key, value) => {
|
|
41
|
-
if (typeof value === 'string') {
|
|
42
|
-
return `'${value}'`; /** Wrap string values with single quotes */
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
})
|
|
46
|
-
.replace(/"([^"]+)":/g, "'$1':") /** Wrap keys with single quotes */
|
|
47
|
-
.replace(/"/g, ''); /** Remove any remaining double quotes */
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const upperCaseFirstChar = (word: string) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
51
|
-
|
|
52
|
-
export const upperCaseFirstCharOfEachWord = (str: string) => {
|
|
53
|
-
return (str || '').replace(/\b\w/g, function (match) {
|
|
54
|
-
return match.toUpperCase();
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const upperCaseFirstCharOfEachWordSplitBySpace = (str: string) => {
|
|
59
|
-
return (str || '').split(' ').map(upperCaseFirstChar).join(' ');
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const jsonToConsistentString = (jsonObj) => {
|
|
63
|
-
// Helper function to sort an object recursively
|
|
64
|
-
function sortObject(obj) {
|
|
65
|
-
if (obj === null || typeof obj !== 'object') {
|
|
66
|
-
return obj;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (Array.isArray(obj)) {
|
|
70
|
-
return obj.map(sortObject);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const sortedKeys = Object.keys(obj).sort();
|
|
74
|
-
const sortedObj = {};
|
|
75
|
-
|
|
76
|
-
for (const key of sortedKeys) {
|
|
77
|
-
sortedObj[key] = sortObject(obj[key]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return sortedObj;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Sort the JSON object */
|
|
84
|
-
const sortedJsonObj = sortObject(jsonObj);
|
|
85
|
-
|
|
86
|
-
/** Convert the sorted JSON object to a string */
|
|
87
|
-
return JSON.stringify(sortedJsonObj);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const booleanStringToBoolean = (value: string) => value === 'true';
|
|
91
|
-
export const booleanStringToNumber = (value: string) =>
|
|
92
|
-
booleanStringToBoolean(value) ? 1 : 0;
|
|
93
|
-
|
|
94
|
-
/**Convert snowflake response keys CAPITAL_CHAR into capitalChar **/
|
|
95
|
-
export const normalizeSfResponseObjKeys = (obj: Record<string, any>) => {
|
|
96
|
-
return Object.fromEntries(
|
|
97
|
-
Object.entries(obj).map(([key, value]) => [
|
|
98
|
-
key
|
|
99
|
-
.toLowerCase()
|
|
100
|
-
.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), // Convert _X to X
|
|
101
|
-
value
|
|
102
|
-
])
|
|
103
|
-
);
|
|
104
|
-
}
|
package/src/date.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {TimeUnits} from '@wandzai/wandz-interfaces';
|
|
2
|
-
|
|
3
|
-
export const formatDateYearMonthDay = (date: string | Date) =>
|
|
4
|
-
new Date(date).toLocaleDateString('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit' });
|
|
5
|
-
|
|
6
|
-
export const calcDatesRange = (range: number) => {
|
|
7
|
-
const today = new Date();
|
|
8
|
-
const startDate = new Date(today);
|
|
9
|
-
startDate.setDate(today.getDate() - range);
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
startDate: formatDateYearMonthDay(startDate),
|
|
13
|
-
endDate: formatDateYearMonthDay(today),
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const getTimeDifference = (date: Date, timeUnit: TimeUnits): number => {
|
|
18
|
-
/** Get the current date and time */
|
|
19
|
-
const now = new Date();
|
|
20
|
-
|
|
21
|
-
/** Calculate the time difference in milliseconds */
|
|
22
|
-
const timeDifference = now.getTime() - date.getTime();
|
|
23
|
-
|
|
24
|
-
/** Convert the time difference to the specified time unit */
|
|
25
|
-
switch (timeUnit) {
|
|
26
|
-
case TimeUnits.Hours:
|
|
27
|
-
return timeDifference / (1000 * 60 * 60);
|
|
28
|
-
case TimeUnits.Minutes:
|
|
29
|
-
return timeDifference / (1000 * 60);
|
|
30
|
-
case TimeUnits.Seconds:
|
|
31
|
-
return timeDifference / 1000;
|
|
32
|
-
case TimeUnits.Days:
|
|
33
|
-
return timeDifference / (1000 * 60 * 60 * 24);
|
|
34
|
-
default:
|
|
35
|
-
return timeDifference; /** Return milliseconds by default */
|
|
36
|
-
}
|
|
37
|
-
};
|
package/src/encrypt-decrypt.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const CryptoJS = require('crypto-js');
|
|
2
|
-
const key = '66807eb6-f5c0-4245-8e4c-0c5d3f80f203';
|
|
3
|
-
|
|
4
|
-
export const encryptData = (data: any): string => {
|
|
5
|
-
const encryptedData = CryptoJS.RC4.encrypt(JSON.stringify(data), key).toString();
|
|
6
|
-
|
|
7
|
-
return encodeURIComponent(encryptedData);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const decryptData = (data: string): any => {
|
|
11
|
-
const decodedEncrypted = decodeURIComponent(data);
|
|
12
|
-
const bytes = CryptoJS.RC4.decrypt(decodedEncrypted, key);
|
|
13
|
-
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
|
|
14
|
-
};
|
package/src/gzip.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gzip single file or every file in given folder
|
|
3
|
-
* @file gzip.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {createGzip} from 'zlib';
|
|
7
|
-
import {createReadStream, createWriteStream} from 'fs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @method gzipFile
|
|
11
|
-
* @param {String} fileIn
|
|
12
|
-
* @param {String} fileOut
|
|
13
|
-
*/
|
|
14
|
-
export function gzipFile(fileIn: string, fileOut: string) {
|
|
15
|
-
return new Promise<void>((resolve, reject) => {
|
|
16
|
-
const inp = createReadStream(fileIn);
|
|
17
|
-
const out = createWriteStream(fileOut);
|
|
18
|
-
const gzip = createGzip();
|
|
19
|
-
|
|
20
|
-
inp
|
|
21
|
-
.pipe(gzip)
|
|
22
|
-
.pipe(out)
|
|
23
|
-
.on('finish', function () {
|
|
24
|
-
resolve();
|
|
25
|
-
})
|
|
26
|
-
.on('error', function (err) {
|
|
27
|
-
reject(err);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
package/src/hash.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const hmacSHA512 = require('crypto-js/hmac-sha512');
|
|
2
|
-
const Base64 = require('crypto-js/enc-base64');
|
|
3
|
-
|
|
4
|
-
export const hashData = (strToHash: string, specificSalt: string): string => {
|
|
5
|
-
try {
|
|
6
|
-
const saltPrefix: string = 'YvSmHe0x5FC90fmk';
|
|
7
|
-
const salt: string = `${saltPrefix}-${specificSalt.toLowerCase()}`;
|
|
8
|
-
return Base64.stringify(hmacSHA512(strToHash, salt)).replaceAll('+', '');
|
|
9
|
-
} catch (error) {
|
|
10
|
-
console.error('Error:', error.message);
|
|
11
|
-
}
|
|
12
|
-
};
|
package/src/http.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {Request} from 'express';
|
|
2
|
-
import * as querystring from 'querystring';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Extracts ip address from http request
|
|
6
|
-
* @param {Request} req - http request
|
|
7
|
-
*/
|
|
8
|
-
export function getIpFromHttpRequest(req: Request): string {
|
|
9
|
-
return req.headers['x-forwarded-for']
|
|
10
|
-
? String(req.headers['x-forwarded-for']).split(',')[0].trim()
|
|
11
|
-
: req.socket.remoteAddress;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function buildUriBodyString(queryParams: Record<string, any>): string {
|
|
15
|
-
return Object.keys(queryParams)
|
|
16
|
-
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(queryParams[key]))}`)
|
|
17
|
-
.join('&');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* On platform side we're stringifies all entries (also strings) as you can see buildUriBodyString above
|
|
22
|
-
* On the other hand, while using <getEncodedQueryParams> to verify network calls on Automation,
|
|
23
|
-
* the string values are not sent wrapped with double quotes,
|
|
24
|
-
* therefore we'll add a safety mechanism
|
|
25
|
-
* */
|
|
26
|
-
export function getEncodedQueryParams(fullUrl: string): object {
|
|
27
|
-
const queryStringStartIndex = fullUrl.indexOf('?');
|
|
28
|
-
if (queryStringStartIndex === -1) {
|
|
29
|
-
return {}; // No query string found
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const queryString = fullUrl.substring(queryStringStartIndex + 1);
|
|
33
|
-
const data = querystring.parse(queryString);
|
|
34
|
-
|
|
35
|
-
return Object.keys(data).reduce((acc, key) => {
|
|
36
|
-
try {
|
|
37
|
-
/** safety mechanism */
|
|
38
|
-
acc[key] = JSON.parse(data[key] as string);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
acc[key] = data[key]; /** for non-object values*/
|
|
41
|
-
}
|
|
42
|
-
return acc;
|
|
43
|
-
}, {});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Builds a query string from an object of parameters.
|
|
48
|
-
*
|
|
49
|
-
* @param {Record<string, any>} params - The parameters to be converted into a query string.
|
|
50
|
-
* @returns {string} The constructed query string.
|
|
51
|
-
*/
|
|
52
|
-
export function buildQueryString(params: Record<string, any>): string {
|
|
53
|
-
const queryParams = new URLSearchParams();
|
|
54
|
-
|
|
55
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
56
|
-
if (typeof value === 'object') {
|
|
57
|
-
queryParams.append(key, JSON.stringify(value));
|
|
58
|
-
} else {
|
|
59
|
-
queryParams.append(key, String(value));
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return queryParams.toString();
|
|
64
|
-
}
|
package/src/mysql.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const formatParamValue = (value: any): string => {
|
|
2
|
-
if (typeof value === 'object') {
|
|
3
|
-
/** Currently used for arrays (typeof [] is 'object') */
|
|
4
|
-
return `'${JSON.stringify(value)}'`;
|
|
5
|
-
} else if (typeof value === 'string') {
|
|
6
|
-
return `'${value}'`;
|
|
7
|
-
} else {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const buildMysqlProcedureString = (procedure: string, params: any[]): string => {
|
|
13
|
-
return `CALL ${procedure}(${params.map((v) => formatParamValue(v)).join(',')});`;
|
|
14
|
-
};
|
package/src/numeric.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const getRandomIntInclusive = (minVal: number, maxVal: number) => {
|
|
2
|
-
const min = Math.ceil(minVal);
|
|
3
|
-
const max = Math.floor(maxVal);
|
|
4
|
-
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const getRandomFloatInclusive = (minVal: number, maxVal: number) => {
|
|
8
|
-
return Number((Math.random() * (minVal - maxVal + 1) + minVal).toFixed(2));
|
|
9
|
-
};
|
package/src/schedule.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as dayjs from 'dayjs';
|
|
2
|
-
import * as utc from 'dayjs/plugin/utc';
|
|
3
|
-
import * as timezone from 'dayjs/plugin/timezone';
|
|
4
|
-
|
|
5
|
-
dayjs.extend(utc);
|
|
6
|
-
dayjs.extend(timezone);
|
|
7
|
-
export { dayjs };
|
|
8
|
-
|
|
9
|
-
export const nowInUTC = (asDate: boolean = true): Date | dayjs.Dayjs =>
|
|
10
|
-
asDate ? dayjs().utc().toDate() : dayjs().utc();
|
|
11
|
-
|
|
12
|
-
export const isInPast = (date: Date | string): boolean => dayjs.utc(date).isBefore(nowInUTC());
|
|
13
|
-
|
|
14
|
-
export const isSameDate = (date1: Date | string, date2: Date | string): boolean =>
|
|
15
|
-
dayjs(date1).isSame(dayjs(date2), 'day');
|
|
16
|
-
|
|
17
|
-
export const getHourOfUTCDate = (date: Date | string): number => dayjs.utc(date).hour();
|
|
18
|
-
|
|
19
|
-
export const formatUTCDateWithTimezone = (date: Date | string, timezone: string, format: string): string => {
|
|
20
|
-
return dayjs
|
|
21
|
-
.utc(date) // Explicitly treat the input as UTC
|
|
22
|
-
.tz(timezone) // Convert to user's timezone
|
|
23
|
-
.format(format);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const getTimezoneOffsetInHours = (region: string): number => {
|
|
27
|
-
// Get the current time in the given timezone
|
|
28
|
-
const nowInTimezone = dayjs().tz(region);
|
|
29
|
-
|
|
30
|
-
// Get the offset in minutes and convert to hours
|
|
31
|
-
const offsetInHours = nowInTimezone.utcOffset() / 60;
|
|
32
|
-
|
|
33
|
-
// Return the offset in hours
|
|
34
|
-
return parseFloat(offsetInHours.toFixed(1));
|
|
35
|
-
};
|
package/src/snowflake.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const formatParamValue = (value: any): string => {
|
|
2
|
-
if (Array.isArray(value)) {
|
|
3
|
-
return `[${value.map(formatParamValue).join(',')}]`;
|
|
4
|
-
} else if (typeof value === 'boolean') {
|
|
5
|
-
return value ? 'TRUE' : 'FALSE';
|
|
6
|
-
} else if (typeof value === 'number') {
|
|
7
|
-
return value.toString();
|
|
8
|
-
} else if (value === null) {
|
|
9
|
-
return 'NULL';
|
|
10
|
-
} else if (typeof value === 'object') {
|
|
11
|
-
const content = Object.entries(value).map(([key, value]) => {
|
|
12
|
-
return `'${key}', ${formatParamValue(value)}`;
|
|
13
|
-
}).join(',');
|
|
14
|
-
return `object_construct(${content})`;
|
|
15
|
-
} else {
|
|
16
|
-
return `'${value}'`;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const buildComplexTypedProcedure = (procedure: string, params: { [paramName: string]: any }): string =>
|
|
21
|
-
`CALL ${procedure}(${Object.entries(params)
|
|
22
|
-
.map(([paramName, paramValue]) => `${paramName} => ${formatParamValue(paramValue)}`)
|
|
23
|
-
.join(', ')})`;
|
package/src/wandz.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AdaptiveSearchReplaceLabels,
|
|
3
|
-
AffinityTypes,
|
|
4
|
-
AiFeatureDistributionType,
|
|
5
|
-
IAdaptiveSearch,
|
|
6
|
-
IAffinityBasedCustomAiFeatureConfig,
|
|
7
|
-
IAiFeaturesBasicConfig,
|
|
8
|
-
IAudience,
|
|
9
|
-
ICustomAiFeature,
|
|
10
|
-
ICustomAudience,
|
|
11
|
-
IEntity,
|
|
12
|
-
IEventBasedCustomAiFeatureConfig,
|
|
13
|
-
IPredictionModel,
|
|
14
|
-
IStorageBasedCustomAiFeatureConfig, IWandzAiFeaturesConfig,
|
|
15
|
-
WandzEntities,
|
|
16
|
-
} from '@wandzai/wandz-interfaces';
|
|
17
|
-
|
|
18
|
-
/** ai-features */
|
|
19
|
-
export const entityTechNameBuilder = (entityName: string) => {
|
|
20
|
-
/** Convert display name to slug:
|
|
21
|
-
transform to lowercase, replace spaces with underscores
|
|
22
|
-
remove anything not alphanumeric, or underscore, or dot
|
|
23
|
-
*/
|
|
24
|
-
return entityName
|
|
25
|
-
.toLowerCase()
|
|
26
|
-
.replace(/ /g, '_')
|
|
27
|
-
.replace(/[^\w_.]+/g, '');
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function isAffinityBasedCustomAiFeature(
|
|
31
|
-
feature: ICustomAiFeature,
|
|
32
|
-
): feature is IAffinityBasedCustomAiFeatureConfig {
|
|
33
|
-
return (feature as IAffinityBasedCustomAiFeatureConfig).affinityType != null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function isStorageBasedCustomAiFeature(
|
|
37
|
-
feature: ICustomAiFeature,
|
|
38
|
-
): feature is IStorageBasedCustomAiFeatureConfig {
|
|
39
|
-
return (feature as IStorageBasedCustomAiFeatureConfig).storageLogic != null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isEventBasedCustomAiFeature(feature: ICustomAiFeature): feature is IEventBasedCustomAiFeatureConfig {
|
|
43
|
-
return (feature as IEventBasedCustomAiFeatureConfig).eventLogic != null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const getCustomAiFeatureType = (feature: ICustomAiFeature): AiFeatureDistributionType => {
|
|
47
|
-
if (isEventBasedCustomAiFeature(feature)) {
|
|
48
|
-
return 'event';
|
|
49
|
-
} else if (isAffinityBasedCustomAiFeature(feature)) {
|
|
50
|
-
return feature.affinityType;
|
|
51
|
-
}
|
|
52
|
-
return 'storage';
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const isAiFeature = (entity: IEntity): entity is IAiFeaturesBasicConfig => {
|
|
56
|
-
return (entity as IAiFeaturesBasicConfig).aiFeature != null;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const isAudience = (entity: IEntity): entity is IAudience => {
|
|
60
|
-
return (entity as IAudience).operator != null && (entity as IAudience).rules != null;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const isCustomEntity = (entity: IEntity) => {
|
|
64
|
-
return (
|
|
65
|
-
/** checking if entity matches <ICreationMeta> interfaces */
|
|
66
|
-
entity.hasOwnProperty('createdBy')
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const isCustomAudience = (audience: IAudience): audience is ICustomAudience => {
|
|
71
|
-
return isCustomEntity(audience);
|
|
72
|
-
};
|
|
73
|
-
export const isCustomAiFeature = (feature: IAiFeaturesBasicConfig): feature is ICustomAiFeature => {
|
|
74
|
-
return isCustomEntity(feature);
|
|
75
|
-
};
|
|
76
|
-
export const isInHouseAiFeature = (entity: IEntity): entity is IWandzAiFeaturesConfig => {
|
|
77
|
-
return isAiFeature(entity) && !isCustomEntity(entity);
|
|
78
|
-
};
|
|
79
|
-
export const isModel = (entity: IEntity): entity is IPredictionModel => {
|
|
80
|
-
return (entity as IPredictionModel).targetRules != null;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const getEntityID = (entity: IEntity): string => {
|
|
84
|
-
if (isAiFeature(entity)) {
|
|
85
|
-
return entity.id?.toString();
|
|
86
|
-
} else if (isAudience(entity)) {
|
|
87
|
-
return entity.guid;
|
|
88
|
-
} else if (isModel(entity)) {
|
|
89
|
-
return entity.guid;
|
|
90
|
-
}
|
|
91
|
-
return '';
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const getEntityType = (entity: IEntity): WandzEntities => {
|
|
95
|
-
if (isAiFeature(entity)) {
|
|
96
|
-
return WandzEntities.AI_FEATURE;
|
|
97
|
-
} else if (isAudience(entity)) {
|
|
98
|
-
return WandzEntities.AUDIENCE;
|
|
99
|
-
} else if (isModel(entity)) {
|
|
100
|
-
return WandzEntities.MODEL;
|
|
101
|
-
}
|
|
102
|
-
return WandzEntities.AI_FEATURE;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const getEntityDisplayName = (entity: IEntity): string => {
|
|
106
|
-
if (isAiFeature(entity)) {
|
|
107
|
-
return entity.displayName;
|
|
108
|
-
} else if (isAudience(entity)) {
|
|
109
|
-
return entity.displayName;
|
|
110
|
-
} else if (isModel(entity)) {
|
|
111
|
-
return entity.name;
|
|
112
|
-
}
|
|
113
|
-
return '';
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/** Adaptive search */
|
|
117
|
-
export const getAdaptiveSearchDataByField = (search: IAdaptiveSearch, label: AdaptiveSearchReplaceLabels): any => {
|
|
118
|
-
switch (label) {
|
|
119
|
-
case AdaptiveSearchReplaceLabels.CONTENTS:
|
|
120
|
-
return search.whatToShow.contents;
|
|
121
|
-
case AdaptiveSearchReplaceLabels.PRIORITIZE_BY:
|
|
122
|
-
return search.whatToShow.priority;
|
|
123
|
-
case AdaptiveSearchReplaceLabels.SUGGESTIONS_MAX_QUANTITY:
|
|
124
|
-
return search.whatToShow.suggestionsAmount;
|
|
125
|
-
case AdaptiveSearchReplaceLabels.TEST_GROUP_SIZE:
|
|
126
|
-
return search.testGroupSize;
|
|
127
|
-
case AdaptiveSearchReplaceLabels.NUM_CHARACTERS_STOP_SHOWING:
|
|
128
|
-
return search.typedCharactersToStopShowing;
|
|
129
|
-
case AdaptiveSearchReplaceLabels.ADD_ADAPTIVE_URL_PARAM:
|
|
130
|
-
return search.addUrlParam;
|
|
131
|
-
}
|
|
132
|
-
};
|
package/tsconfig.lib.json
DELETED
|
File without changes
|