@vonq/hapi-elements-types 1.5.0 → 1.6.0
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 +15 -4
- package/src/_window/api.types.ts +9 -7
- package/src/_window/auth.types.ts +6 -4
- package/src/_window/config.types.ts +0 -25
- package/src/_window/events.types.ts +15 -14
- package/src/_window/instances.types.ts +19 -10
- package/src/_window/qa.types.ts +7 -5
- package/src/_window/routing.types.ts +6 -4
- package/src/_window/sdk.types.ts +29 -27
- package/src/_window/service.types.ts +9 -7
- package/src/_window/state.types.ts +55 -53
- package/src/_window/ui.types.ts +6 -4
- package/src/_window/utils.types.ts +7 -5
- package/src/_window/validation.types.ts +7 -5
- package/src/_window/window.ts +126 -42
- package/src/alert/index.ts +4 -7
- package/src/alert/service.types.ts +2 -2
- package/src/alert/state.types.ts +1 -19
- package/src/ats/api.types.ts +2 -2
- package/src/ats/index.ts +4 -7
- package/src/ats/service.types.ts +2 -2
- package/src/ats/state.types.ts +1 -1
- package/src/basket/index.ts +5 -10
- package/src/basket/service.types.ts +2 -2
- package/src/basket/state.types.ts +1 -1
- package/src/basket/utils.types.ts +2 -2
- package/src/campaign/api.types.ts +2 -2
- package/src/campaign/index.ts +8 -13
- package/src/campaign/qa.types.ts +4 -4
- package/src/campaign/service.types.ts +2 -2
- package/src/campaign/state.types.ts +1 -1
- package/src/campaign/utils.types.ts +2 -2
- package/{enums.ts → src/common/enums.ts} +2 -1
- package/src/common/events/types.ts +6 -6
- package/src/common/index.ts +5 -20
- package/src/common/logger/types.ts +11 -0
- package/src/common/qa.types.ts +2 -2
- package/src/common/types.ts +5 -6
- package/src/common/validator/types.ts +4 -0
- package/src/contract/api.types.ts +2 -2
- package/src/contract/index.ts +7 -12
- package/src/contract/qa.types.ts +2 -2
- package/src/contract/service.types.ts +2 -2
- package/src/contract/state.types.ts +1 -1
- package/src/contract/utils.types.ts +2 -2
- package/src/debugging/index.ts +1 -4
- package/src/debugging/state.types.ts +1 -1
- package/src/index.ts +16 -20
- package/src/language/index.ts +3 -9
- package/src/language/qa.types.ts +2 -2
- package/src/language/state.types.ts +1 -1
- package/src/modal/index.ts +4 -9
- package/src/modal/service.types.ts +2 -2
- package/src/modal/state.types.ts +1 -1
- package/src/orderJourney/index.ts +6 -11
- package/src/orderJourney/qa.types.ts +2 -2
- package/src/orderJourney/state.types.ts +1 -1
- package/src/orderJourney/utils.types.ts +2 -2
- package/src/product/api.types.ts +2 -2
- package/src/product/index.ts +8 -12
- package/src/product/qa.types.ts +2 -2
- package/src/product/service.types.ts +2 -2
- package/src/product/state.types.ts +1 -1
- package/src/product/utils.types.ts +2 -2
- package/src/routing/index.ts +1 -3
- package/src/theming/index.ts +4 -9
- package/src/theming/qa.types.ts +2 -2
- package/src/theming/state.types.ts +1 -1
- package/src/ui/service.types.ts +2 -2
- package/src/wallet/api.types.ts +2 -2
- package/src/wallet/index.ts +5 -9
- package/src/wallet/service.types.ts +2 -2
- package/src/wallet/state.types.ts +1 -1
- package/tsconfig.json +6 -11
- package/src/alert/functions.types.ts +0 -13
- package/src/alert/state.initial.ts +0 -16
- package/src/alert/state.validations.ts +0 -11
- package/src/ats/functions.types.ts +0 -7
- package/src/ats/state.initial.ts +0 -5
- package/src/ats/state.validations.ts +0 -6
- package/src/basket/consts.ts +0 -1
- package/src/basket/functions.types.ts +0 -40
- package/src/basket/state.initial.ts +0 -11
- package/src/basket/state.validations.ts +0 -12
- package/src/basket/utils.ts +0 -79
- package/src/campaign/consts.ts +0 -1
- package/src/campaign/functions.types.ts +0 -90
- package/src/campaign/state.initial.ts +0 -84
- package/src/campaign/state.validations.ts +0 -16
- package/src/campaign/utils.ts +0 -53
- package/src/common/LocalStorage.ts +0 -123
- package/src/common/browser.ts +0 -2
- package/src/common/color.ts +0 -9
- package/src/common/immutable.ts +0 -28
- package/src/common/instances/Instance.ts +0 -13
- package/src/common/instances/consts.ts +0 -1
- package/src/common/instances/index.ts +0 -4
- package/src/common/json.ts +0 -25
- package/src/common/logger/Logger.ts +0 -70
- package/src/common/logger/index.ts +0 -5
- package/src/common/logger-datadog/LoggerDatadog.ts +0 -42
- package/src/common/logger-datadog/index.ts +0 -3
- package/src/common/misc.ts +0 -114
- package/src/common/promise.ts +0 -161
- package/src/common/proxy.ts +0 -77
- package/src/common/regExTest.ts +0 -12
- package/src/common/tree.ts +0 -148
- package/src/common/utm.ts +0 -19
- package/src/common/validators.ts +0 -21
- package/src/common/webComponents.ts +0 -26
- package/src/config/functions.types.ts +0 -23
- package/src/config/index.ts +0 -5
- package/src/config/state.initial.ts +0 -11
- package/src/config/state.types.ts +0 -15
- package/src/consts.ts +0 -980
- package/src/contract/consts.ts +0 -1
- package/src/contract/functions.types.ts +0 -112
- package/src/contract/state.initial.ts +0 -39
- package/src/contract/state.validations.ts +0 -21
- package/src/contract/utils.ts +0 -36
- package/src/debugging/functions.types.ts +0 -34
- package/src/debugging/state.initial.ts +0 -10
- package/src/debugging/state.validations.ts +0 -10
- package/src/language/consts.ts +0 -6
- package/src/language/en.ts +0 -530
- package/src/language/functions.types.ts +0 -29
- package/src/language/state.initial.ts +0 -13
- package/src/language/state.validations.ts +0 -10
- package/src/language/utils.ts +0 -17
- package/src/modal/consts.ts +0 -6
- package/src/modal/functions.types.ts +0 -22
- package/src/modal/state.initial.ts +0 -9
- package/src/modal/state.validations.ts +0 -6
- package/src/modal/store.types.ts +0 -5
- package/src/orderJourney/consts.ts +0 -289
- package/src/orderJourney/functions.types.ts +0 -140
- package/src/orderJourney/state.initial.ts +0 -401
- package/src/orderJourney/state.validations.ts +0 -78
- package/src/orderJourney/utils.ts +0 -7
- package/src/product/consts.ts +0 -1
- package/src/product/functions.types.ts +0 -156
- package/src/product/state.initial.ts +0 -28
- package/src/product/state.validations.ts +0 -25
- package/src/routing/functions.types.ts +0 -48
- package/src/routing/state.initial.ts +0 -10
- package/src/theming/consts.ts +0 -7727
- package/src/theming/functions.types.ts +0 -13
- package/src/theming/state.initial.ts +0 -16
- package/src/theming/state.validations.ts +0 -8
- package/src/theming/utils.ts +0 -581
- package/src/types.ts +0 -229
- package/src/utils.ts +0 -3
- package/src/wallet/consts.ts +0 -3
- package/src/wallet/functions.types.ts +0 -58
- package/src/wallet/state.initial.ts +0 -18
- package/src/wallet/state.validations.ts +0 -18
@@ -1,70 +0,0 @@
|
|
1
|
-
import { LogLevel } from "./enums"
|
2
|
-
import { LogOutput } from "./types"
|
3
|
-
|
4
|
-
export class Logger {
|
5
|
-
static level = LogLevel.Debug
|
6
|
-
static outputs: LogOutput[] = []
|
7
|
-
public id = `logger-${this.source}`
|
8
|
-
|
9
|
-
constructor(
|
10
|
-
public source?: string,
|
11
|
-
public isEnabled: boolean = true, // // by default all logs should be disabled, ATS should enable it if they want
|
12
|
-
) {
|
13
|
-
/*const areAllLogsEnabled =
|
14
|
-
cookie.get(DEBUG_COOKIE_ARE_LOGS_ENABLED) === "true"
|
15
|
-
|
16
|
-
if (areAllLogsEnabled) {
|
17
|
-
this.isEnabled = areAllLogsEnabled
|
18
|
-
}*/
|
19
|
-
}
|
20
|
-
|
21
|
-
setIsEnabled = (isEnabled: boolean) => {
|
22
|
-
//this.isEnabled = isEnabled
|
23
|
-
}
|
24
|
-
|
25
|
-
static enableProductionMode() {
|
26
|
-
Logger.level = LogLevel.Warning
|
27
|
-
}
|
28
|
-
|
29
|
-
debug(...objects: any[]) {
|
30
|
-
this.log(console.log, LogLevel.Debug, objects)
|
31
|
-
}
|
32
|
-
|
33
|
-
info(...objects: any[]) {
|
34
|
-
this.log(console.info, LogLevel.Info, objects)
|
35
|
-
}
|
36
|
-
|
37
|
-
warn(...objects: any[]) {
|
38
|
-
this.log(console.warn, LogLevel.Warning, objects)
|
39
|
-
}
|
40
|
-
|
41
|
-
error(...objects: any[]) {
|
42
|
-
this.log(console.error, LogLevel.Error, objects)
|
43
|
-
}
|
44
|
-
|
45
|
-
timeStart(message: string) {
|
46
|
-
this.log(console.time, LogLevel.Info, [message])
|
47
|
-
}
|
48
|
-
|
49
|
-
timeEnd(message: string) {
|
50
|
-
this.log(console.log, LogLevel.Info, [message, "timer finished"])
|
51
|
-
this.log(console.timeEnd, LogLevel.Info, [message])
|
52
|
-
}
|
53
|
-
|
54
|
-
private log(func: Function, level: LogLevel, objects: any[]) {
|
55
|
-
if (level <= Logger.level && this.isEnabled) {
|
56
|
-
let sourceString = "[HAPI]"
|
57
|
-
|
58
|
-
sourceString += `[${this.source}]`
|
59
|
-
|
60
|
-
const log = this.source ? [sourceString].concat(objects) : objects
|
61
|
-
func.apply(console, log)
|
62
|
-
Logger.outputs.forEach((output) =>
|
63
|
-
output.apply(
|
64
|
-
output,
|
65
|
-
[this.source, level].concat(objects) as any,
|
66
|
-
),
|
67
|
-
)
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { datadogLogs, Logger } from "@datadog/browser-logs"
|
2
|
-
import { HandlerType } from "@datadog/browser-logs/cjs/domain/logger"
|
3
|
-
|
4
|
-
export default class LoggerDatadog {
|
5
|
-
prefix: string
|
6
|
-
logger: Logger
|
7
|
-
commonContext: Record<string, any> = {}
|
8
|
-
handler: HandlerType = "http"
|
9
|
-
constructor(
|
10
|
-
prefix: string,
|
11
|
-
commonContext?: Record<string, any>,
|
12
|
-
handler?: HandlerType,
|
13
|
-
) {
|
14
|
-
this.prefix = `[${prefix}]`
|
15
|
-
this.logger = datadogLogs.createLogger(this.prefix)
|
16
|
-
this.commonContext = commonContext || {}
|
17
|
-
this.handler = handler || "http"
|
18
|
-
}
|
19
|
-
|
20
|
-
info = (message: string, messageContext?: Record<string, any>) => {
|
21
|
-
this.logger.info(message, this.getMergedContext(messageContext))
|
22
|
-
}
|
23
|
-
|
24
|
-
debug = (message: string, messageContext?: Record<string, any>) => {
|
25
|
-
this.logger.debug(message, this.getMergedContext(messageContext))
|
26
|
-
}
|
27
|
-
|
28
|
-
error = (message: string, messageContext?: Record<string, any>) => {
|
29
|
-
this.logger.error(message, this.getMergedContext(messageContext))
|
30
|
-
}
|
31
|
-
|
32
|
-
warn = (message: string, messageContext?: Record<string, any>) => {
|
33
|
-
this.logger.warn(message, this.getMergedContext(messageContext))
|
34
|
-
}
|
35
|
-
|
36
|
-
private getMergedContext = (messageContext?: Record<string, any>) => {
|
37
|
-
return {
|
38
|
-
...this.commonContext,
|
39
|
-
...messageContext,
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
package/src/common/misc.ts
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
export const convertNumberToTime = (num: number) => {
|
2
|
-
const hours = Math.floor(num / 60)
|
3
|
-
const minutes = num % 60
|
4
|
-
return `${hours}:${minutes.toString().padStart(2, "0")}`
|
5
|
-
}
|
6
|
-
|
7
|
-
export const getDomainWithSubdomains = (url: any) => {
|
8
|
-
let domainParts = 2
|
9
|
-
url = url.replace(/(https?:\/\/)?(www.)?/i, "")
|
10
|
-
url = url.split(".")
|
11
|
-
if (url.length > 2) {
|
12
|
-
domainParts = 3
|
13
|
-
}
|
14
|
-
url = url.slice(url.length - domainParts).join(".")
|
15
|
-
if (url.indexOf("/") !== -1) {
|
16
|
-
return url.split("/")[0]
|
17
|
-
}
|
18
|
-
return url
|
19
|
-
}
|
20
|
-
|
21
|
-
export const abbreviateNumber = (value: number) => {
|
22
|
-
// from https://stackoverflow.com/a/10601315/2302269
|
23
|
-
let newValue: any = value
|
24
|
-
if (value >= 1000) {
|
25
|
-
const suffixes = ["", "K", "M", "B", "T"]
|
26
|
-
const suffixNum = Math.floor(("" + value).length / 3)
|
27
|
-
let shortValue: any = ""
|
28
|
-
for (let precision = 2; precision >= 1; precision--) {
|
29
|
-
shortValue = parseFloat(
|
30
|
-
(suffixNum != 0
|
31
|
-
? value / Math.pow(1000, suffixNum)
|
32
|
-
: value
|
33
|
-
).toPrecision(precision),
|
34
|
-
)
|
35
|
-
const dotLessShortValue = (shortValue + "").replace(
|
36
|
-
/[^a-zA-Z 0-9]+/g,
|
37
|
-
"",
|
38
|
-
)
|
39
|
-
if (dotLessShortValue.length <= 2) {
|
40
|
-
break
|
41
|
-
}
|
42
|
-
}
|
43
|
-
if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1)
|
44
|
-
newValue = shortValue + suffixes[suffixNum]
|
45
|
-
}
|
46
|
-
return newValue
|
47
|
-
}
|
48
|
-
|
49
|
-
export const replaceBrTagsWithNewLines = (str: string) => {
|
50
|
-
return str.replace(/<br\s*\/?>/gi, "\n")
|
51
|
-
}
|
52
|
-
|
53
|
-
export const capitalizeText = (s: string | null) => {
|
54
|
-
if (typeof s !== "string") return ""
|
55
|
-
return s.charAt(0).toUpperCase() + s.slice(1)
|
56
|
-
}
|
57
|
-
|
58
|
-
export const optionalKeyValue = (key: string, value: any) => {
|
59
|
-
return !!value ? { [key]: value } : {}
|
60
|
-
}
|
61
|
-
|
62
|
-
export const getDomainWithDotPrefix = (domain: string) => {
|
63
|
-
return `.${domain}`
|
64
|
-
}
|
65
|
-
export const getDomainWithoutDotPrefix = (
|
66
|
-
cookieDomainWithDotPrefix?: string,
|
67
|
-
) => {
|
68
|
-
return cookieDomainWithDotPrefix
|
69
|
-
? cookieDomainWithDotPrefix.substring(1)
|
70
|
-
: ""
|
71
|
-
}
|
72
|
-
|
73
|
-
export const isObject = (item: any) => {
|
74
|
-
return item && typeof item === "object" && !Array.isArray(item)
|
75
|
-
}
|
76
|
-
|
77
|
-
export const padZero = (str: string | number, len?: number) => {
|
78
|
-
len = len || 2
|
79
|
-
let zeros = new Array(len).join("0")
|
80
|
-
return (zeros + str).slice(-len)
|
81
|
-
}
|
82
|
-
|
83
|
-
export const getFunctionArgumentNames = (func: Function) => {
|
84
|
-
const STRIP_COMMENTS =
|
85
|
-
/(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/gm
|
86
|
-
const ARGUMENT_NAMES = /([^\s,]+)/g
|
87
|
-
const fnStr = func.toString().replace(STRIP_COMMENTS, "")
|
88
|
-
let result: any = fnStr
|
89
|
-
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
|
90
|
-
.match(ARGUMENT_NAMES)
|
91
|
-
if (result === null) result = []
|
92
|
-
return result
|
93
|
-
}
|
94
|
-
|
95
|
-
export const removeByIndex = (array: any[], index: number | number[]) => {
|
96
|
-
return array.filter((el, i) => {
|
97
|
-
return Array.isArray(index) ? !index.includes(i) : index !== i
|
98
|
-
})
|
99
|
-
}
|
100
|
-
|
101
|
-
export const getRandomIdOfNCharacters = (length: number) => {
|
102
|
-
let result = ""
|
103
|
-
const characters =
|
104
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
105
|
-
const charactersLength = characters.length
|
106
|
-
let counter = 0
|
107
|
-
while (counter < length) {
|
108
|
-
result += characters.charAt(
|
109
|
-
Math.floor(Math.random() * charactersLength),
|
110
|
-
)
|
111
|
-
counter += 1
|
112
|
-
}
|
113
|
-
return result
|
114
|
-
}
|
package/src/common/promise.ts
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
import isPromise from "is-promise"
|
2
|
-
|
3
|
-
function hasSymbols() {
|
4
|
-
if (
|
5
|
-
typeof Symbol !== "function" ||
|
6
|
-
typeof Object.getOwnPropertySymbols !== "function"
|
7
|
-
) {
|
8
|
-
return false
|
9
|
-
}
|
10
|
-
if (typeof Symbol.iterator === "symbol") {
|
11
|
-
return true
|
12
|
-
}
|
13
|
-
|
14
|
-
var obj: any = {}
|
15
|
-
var sym = Symbol("test")
|
16
|
-
var symObj = Object(sym)
|
17
|
-
if (typeof sym === "string") {
|
18
|
-
return false
|
19
|
-
}
|
20
|
-
|
21
|
-
if (Object.prototype.toString.call(sym) !== "[object Symbol]") {
|
22
|
-
return false
|
23
|
-
}
|
24
|
-
if (Object.prototype.toString.call(symObj) !== "[object Symbol]") {
|
25
|
-
return false
|
26
|
-
}
|
27
|
-
|
28
|
-
// temp disabled per https://github.com/ljharb/object.assign/issues/17
|
29
|
-
// if (sym instanceof Symbol) { return false; }
|
30
|
-
// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
31
|
-
// if (!(symObj instanceof Symbol)) { return false; }
|
32
|
-
|
33
|
-
// if (typeof Symbol.prototype.toString !== 'function') { return false; }
|
34
|
-
// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
|
35
|
-
|
36
|
-
var symVal = 42
|
37
|
-
obj[sym] = symVal
|
38
|
-
for (const sym in obj) {
|
39
|
-
return false
|
40
|
-
} // eslint-disable-line no-restricted-syntax, no-unreachable-loop
|
41
|
-
if (typeof Object.keys === "function" && Object.keys(obj).length !== 0) {
|
42
|
-
return false
|
43
|
-
}
|
44
|
-
|
45
|
-
if (
|
46
|
-
typeof Object.getOwnPropertyNames === "function" &&
|
47
|
-
Object.getOwnPropertyNames(obj).length !== 0
|
48
|
-
) {
|
49
|
-
return false
|
50
|
-
}
|
51
|
-
|
52
|
-
var syms = Object.getOwnPropertySymbols(obj)
|
53
|
-
if (syms.length !== 1 || syms[0] !== sym) {
|
54
|
-
return false
|
55
|
-
}
|
56
|
-
|
57
|
-
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) {
|
58
|
-
return false
|
59
|
-
}
|
60
|
-
|
61
|
-
if (typeof Object.getOwnPropertyDescriptor === "function") {
|
62
|
-
var descriptor: any = Object.getOwnPropertyDescriptor(obj, sym)
|
63
|
-
if (descriptor.value !== symVal || descriptor.enumerable !== true) {
|
64
|
-
return false
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
return true
|
69
|
-
}
|
70
|
-
|
71
|
-
function hasToStringTagShams() {
|
72
|
-
return hasSymbols() && !!Symbol.toStringTag
|
73
|
-
}
|
74
|
-
|
75
|
-
const toStr = Object.prototype.toString
|
76
|
-
const fnToStr = Function.prototype.toString
|
77
|
-
const isFnRegex = /^\s*async(?:\s+function(?:\s+|\()|\s*\()/
|
78
|
-
const hasToStringTag = hasToStringTagShams()
|
79
|
-
const getProto = Object.getPrototypeOf
|
80
|
-
const getAsyncFunc = function () {
|
81
|
-
// eslint-disable-line consistent-return
|
82
|
-
if (!hasToStringTag) {
|
83
|
-
return false
|
84
|
-
}
|
85
|
-
try {
|
86
|
-
return Function("return async function () {}")()
|
87
|
-
} catch (e) {}
|
88
|
-
}
|
89
|
-
|
90
|
-
export const isAsyncFunction = (fn: Function) => {
|
91
|
-
let AsyncFunction: any
|
92
|
-
if (typeof fn !== "function") {
|
93
|
-
return false
|
94
|
-
}
|
95
|
-
if (isFnRegex.test(fnToStr.call(fn))) {
|
96
|
-
return true
|
97
|
-
}
|
98
|
-
if (!hasToStringTag) {
|
99
|
-
const str = toStr.call(fn)
|
100
|
-
return str === "[object AsyncFunction]"
|
101
|
-
}
|
102
|
-
if (!getProto) {
|
103
|
-
return false
|
104
|
-
}
|
105
|
-
if (typeof AsyncFunction === "undefined") {
|
106
|
-
const asyncFunc = getAsyncFunc()
|
107
|
-
AsyncFunction = asyncFunc ? getProto(asyncFunc) : false
|
108
|
-
}
|
109
|
-
return getProto(fn) === AsyncFunction
|
110
|
-
}
|
111
|
-
|
112
|
-
const isFnRegexNormal = /^\s*(?:function)?\*/
|
113
|
-
const getGeneratorFunc = function () {
|
114
|
-
// eslint-disable-line consistent-return
|
115
|
-
if (!hasToStringTag) {
|
116
|
-
return false
|
117
|
-
}
|
118
|
-
try {
|
119
|
-
return Function("return function*() {}")()
|
120
|
-
} catch (e) {}
|
121
|
-
}
|
122
|
-
|
123
|
-
const isGeneratorFunction = (fn: any) => {
|
124
|
-
let GeneratorFunction: any
|
125
|
-
if (typeof fn !== "function") {
|
126
|
-
return false
|
127
|
-
}
|
128
|
-
if (isFnRegexNormal.test(fnToStr.call(fn))) {
|
129
|
-
return true
|
130
|
-
}
|
131
|
-
if (!hasToStringTag) {
|
132
|
-
var str = toStr.call(fn)
|
133
|
-
return str === "[object GeneratorFunction]"
|
134
|
-
}
|
135
|
-
if (!getProto) {
|
136
|
-
return false
|
137
|
-
}
|
138
|
-
if (typeof GeneratorFunction === "undefined") {
|
139
|
-
var generatorFunc = getGeneratorFunc()
|
140
|
-
GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false
|
141
|
-
}
|
142
|
-
return getProto(fn) === GeneratorFunction
|
143
|
-
}
|
144
|
-
|
145
|
-
export const isPromiseOrAsyncFunction = (fn: Function) => {
|
146
|
-
const stringFn = fn.toString()
|
147
|
-
|
148
|
-
const isJestFn = (fn as any)._isMockFunction === true
|
149
|
-
const isJestFnAsync = isJestFn && (fn as any).getMockName() === "async"
|
150
|
-
// it is required while defining jest.fn that .mockName("async") is specified
|
151
|
-
// so this FN can recognize that it's async
|
152
|
-
|
153
|
-
return (
|
154
|
-
isPromise(fn) ||
|
155
|
-
isAsyncFunction(fn) ||
|
156
|
-
isGeneratorFunction(fn) ||
|
157
|
-
stringFn.includes("this,null,function*") ||
|
158
|
-
(stringFn.includes("__async") && stringFn.includes("function* ()")) ||
|
159
|
-
(isJestFn && isJestFnAsync)
|
160
|
-
)
|
161
|
-
}
|
package/src/common/proxy.ts
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
export type ProxyChangeHandler = (target: any, key: string, value: any) => void
|
2
|
-
|
3
|
-
export type DeepProxyChangeHandler = (
|
4
|
-
target: any,
|
5
|
-
key: string,
|
6
|
-
value: any,
|
7
|
-
parentKey?: string,
|
8
|
-
) => void
|
9
|
-
|
10
|
-
const validatorWithLevelGet = (
|
11
|
-
target: any,
|
12
|
-
key: string,
|
13
|
-
level: number,
|
14
|
-
maxLevel: number,
|
15
|
-
changeFn: DeepProxyChangeHandler,
|
16
|
-
parentKey?: string,
|
17
|
-
) => {
|
18
|
-
if (
|
19
|
-
typeof target[key] === "object" &&
|
20
|
-
target[key] !== null &&
|
21
|
-
level < maxLevel
|
22
|
-
) {
|
23
|
-
return new Proxy(
|
24
|
-
target[key],
|
25
|
-
getValidatorWithLevel(level + 1, maxLevel, changeFn, parentKey),
|
26
|
-
)
|
27
|
-
} else {
|
28
|
-
return target[key]
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
const getValidatorWithLevel = (
|
33
|
-
level: number,
|
34
|
-
maxLevel: number,
|
35
|
-
changeFn: DeepProxyChangeHandler,
|
36
|
-
parentKey?: string,
|
37
|
-
) => {
|
38
|
-
return {
|
39
|
-
get(target: any, key: string): any {
|
40
|
-
return validatorWithLevelGet(
|
41
|
-
target,
|
42
|
-
key,
|
43
|
-
level,
|
44
|
-
maxLevel,
|
45
|
-
changeFn,
|
46
|
-
parentKey,
|
47
|
-
)
|
48
|
-
},
|
49
|
-
set(target: any, key: string, value: any) {
|
50
|
-
target[key] = value
|
51
|
-
changeFn(target, key, value, parentKey)
|
52
|
-
return true
|
53
|
-
},
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
export const deepProxyByLevel = (
|
58
|
-
object: Record<string, any>,
|
59
|
-
maxLevel: number,
|
60
|
-
changeFn: DeepProxyChangeHandler,
|
61
|
-
parentKey?: string,
|
62
|
-
): ProxyConstructor =>
|
63
|
-
new Proxy(object, getValidatorWithLevel(0, maxLevel, changeFn, parentKey))
|
64
|
-
|
65
|
-
export const decorateVariableWithOnListener = (
|
66
|
-
variable: any,
|
67
|
-
callbackFn: (value: any) => void,
|
68
|
-
) => {
|
69
|
-
return new Proxy(variable, {
|
70
|
-
get(target: any, key: string): any {
|
71
|
-
return {
|
72
|
-
value: target[key],
|
73
|
-
on: callbackFn,
|
74
|
-
}
|
75
|
-
},
|
76
|
-
})
|
77
|
-
}
|
package/src/common/regExTest.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
export const regexRulesMap: Record<"id" | "number" | "utm", RegExp> = {
|
2
|
-
id: /^([a-zA-Z0-9_-]){36}$/,
|
3
|
-
number: /e|[-=+,.]/,
|
4
|
-
utm: /^([%.\-_!*a-zA-Z0-9]{1,}=[%.\-_!*+,;$()a-zA-Z0-9]{1,}[&]{0,}){1,}$/,
|
5
|
-
}
|
6
|
-
|
7
|
-
export function testRegexFromRegexRulesMap(
|
8
|
-
type: "id" | "number" | "utm",
|
9
|
-
str: string,
|
10
|
-
) {
|
11
|
-
return regexRulesMap[type].test(str)
|
12
|
-
}
|
package/src/common/tree.ts
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
import { flatten, partition, without } from "lodash"
|
2
|
-
|
3
|
-
export type TreeItem<FileData, FolderData> =
|
4
|
-
| FolderItem<FileData, FolderData>
|
5
|
-
| FileItem<FileData>
|
6
|
-
|
7
|
-
export interface FolderItem<FileData, FolderData> {
|
8
|
-
children: Array<TreeItem<FileData, FolderData>>
|
9
|
-
data: FolderData
|
10
|
-
isLeaf: false
|
11
|
-
}
|
12
|
-
|
13
|
-
export interface FileItem<FileData> {
|
14
|
-
data: FileData
|
15
|
-
isLeaf: true
|
16
|
-
}
|
17
|
-
|
18
|
-
function folderItemFactory<FileData, FolderData>(
|
19
|
-
data: FolderData,
|
20
|
-
children: Array<TreeItem<FileData, FolderData>> = [],
|
21
|
-
): FolderItem<FileData, FolderData> {
|
22
|
-
return {
|
23
|
-
children,
|
24
|
-
data,
|
25
|
-
isLeaf: false,
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
function fileItemFactory<FileData>(data: FileData): FileItem<FileData> {
|
30
|
-
return {
|
31
|
-
data,
|
32
|
-
isLeaf: true,
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
function checkRecursive<T>(
|
37
|
-
list: Array<T>,
|
38
|
-
isParentOf: (parent: T, children: T) => boolean,
|
39
|
-
) {
|
40
|
-
const isParentOfItself = list.some((item) => isParentOf(item, item))
|
41
|
-
if (isParentOfItself) {
|
42
|
-
throw new Error("An item cannot be a parent of itself")
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Create a tree hierarchy from an array of items both files and folders mixed. Using treeItemFromFolderAndFileList is preferred
|
48
|
-
**/
|
49
|
-
export function treeItemFromList<FileData, FolderData>(
|
50
|
-
list: Array<FileData | FolderData>,
|
51
|
-
isFolder: (data: FileData | FolderData) => boolean,
|
52
|
-
isParentOfFile: (parent: FolderData, children: FileData) => boolean,
|
53
|
-
isParentOfFolder?: (parent: FolderData, children: FolderData) => boolean,
|
54
|
-
): Array<TreeItem<FileData, FolderData>> {
|
55
|
-
const [folderData, fileData] = partition(list, isFolder) as [
|
56
|
-
Array<FolderData>,
|
57
|
-
Array<FileData>,
|
58
|
-
]
|
59
|
-
return treeItemFromFolderAndFileList<FileData, FolderData>(
|
60
|
-
fileData,
|
61
|
-
folderData,
|
62
|
-
isParentOfFile,
|
63
|
-
isParentOfFolder,
|
64
|
-
)
|
65
|
-
}
|
66
|
-
|
67
|
-
/**
|
68
|
-
* Create a tree hierarchy from 2 array of items, one representing files (or leaves) and the second folders (or directories)
|
69
|
-
**/
|
70
|
-
export function treeItemFromFolderAndFileList<FileData, FolderData>(
|
71
|
-
fileData: Array<FileData>,
|
72
|
-
folderData: Array<FolderData>,
|
73
|
-
isParentOfFile: (parent: FolderData, children: FileData) => boolean,
|
74
|
-
// only if this is a multi level tree hierarchy (folder containing folders)
|
75
|
-
isParentOfFolder: (
|
76
|
-
parent: FolderData,
|
77
|
-
children: FolderData,
|
78
|
-
) => boolean = () => false,
|
79
|
-
): Array<TreeItem<FileData, FolderData>> {
|
80
|
-
checkRecursive(folderData, isParentOfFolder)
|
81
|
-
|
82
|
-
const folderTreeItems: Array<FolderItem<FileData, FolderData>> =
|
83
|
-
folderData.map((data) => folderItemFactory(data))
|
84
|
-
const fileTreeItems: Array<FileItem<FileData>> = fileData.map((data) =>
|
85
|
-
fileItemFactory(data),
|
86
|
-
) as Array<FileItem<FileData>>
|
87
|
-
const allTreeItems = [...folderTreeItems, ...fileTreeItems]
|
88
|
-
|
89
|
-
folderTreeItems.forEach((folderTreeItem) => {
|
90
|
-
const fileChildren = fileTreeItems.filter((childTreeItem) =>
|
91
|
-
isParentOfFile(folderTreeItem.data, childTreeItem.data),
|
92
|
-
)
|
93
|
-
const folderChildren = folderTreeItems.filter((childTreeItem) =>
|
94
|
-
isParentOfFolder(folderTreeItem.data, childTreeItem.data),
|
95
|
-
)
|
96
|
-
folderTreeItem.children.push(...fileChildren, ...folderChildren)
|
97
|
-
})
|
98
|
-
|
99
|
-
return filterOrphans(allTreeItems)
|
100
|
-
}
|
101
|
-
|
102
|
-
function filterOrphans<T, V>(
|
103
|
-
treeItems: Array<TreeItem<T, V>>,
|
104
|
-
): Array<TreeItem<T, V>> {
|
105
|
-
const flatItems: Array<TreeItem<T, V>> = flattenTreeItemDeep(treeItems)
|
106
|
-
const folderItems: Array<FolderItem<T, V>> = flatItems.filter((item) =>
|
107
|
-
isFolderTreeItem(item),
|
108
|
-
) as Array<FolderItem<T, V>>
|
109
|
-
const allChildren: Array<TreeItem<T, V>> = flatten(
|
110
|
-
folderItems.map(({ children }) => children),
|
111
|
-
)
|
112
|
-
return without(flatItems, ...allChildren)
|
113
|
-
}
|
114
|
-
|
115
|
-
export function flattenTreeItemDeep<T, V>(
|
116
|
-
treeItems: Array<TreeItem<T, V>>,
|
117
|
-
): Array<TreeItem<T, V>> {
|
118
|
-
return Array.from(walkTreeItem(...treeItems))
|
119
|
-
}
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Visitor going through all the nodes of the tree
|
123
|
-
*/
|
124
|
-
function* walkTreeItem<FileData, FolderData>(
|
125
|
-
...treeItems: TreeItem<FileData, FolderData>[]
|
126
|
-
): Generator<TreeItem<FileData, FolderData>> {
|
127
|
-
for (const treeItem of treeItems) {
|
128
|
-
yield treeItem
|
129
|
-
if (isFolderTreeItem(treeItem)) {
|
130
|
-
const children = treeItem.children
|
131
|
-
yield* walkTreeItem(...children)
|
132
|
-
}
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
function isFolderTreeItem<FileData, FolderData>(
|
137
|
-
treeItem: TreeItem<FileData, FolderData>,
|
138
|
-
): treeItem is FolderItem<FileData, FolderData> {
|
139
|
-
return !treeItem.isLeaf
|
140
|
-
}
|
141
|
-
|
142
|
-
export function flattenTreeItem<T, V>(
|
143
|
-
treeItem: TreeItem<T, V>,
|
144
|
-
): Array<TreeItem<T, V>> {
|
145
|
-
return isFolderTreeItem(treeItem)
|
146
|
-
? [treeItem, ...treeItem.children]
|
147
|
-
: [treeItem]
|
148
|
-
}
|
package/src/common/utm.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Product } from "../product/types"
|
2
|
-
import { Contract } from "../contract/types"
|
3
|
-
import { getBasketProductTitle } from "../basket/utils"
|
4
|
-
import { testRegexFromRegexRulesMap } from "./regExTest"
|
5
|
-
|
6
|
-
export const getUtmCodeForProductOrContract = (
|
7
|
-
productOrContract: Product | Contract,
|
8
|
-
utmMedium: string = "jobposting",
|
9
|
-
utmCampaign: string = "jobmarketing",
|
10
|
-
): [string, boolean] => {
|
11
|
-
const cName = getBasketProductTitle(productOrContract)
|
12
|
-
.replace(/ /g, "_")
|
13
|
-
.replace(/[^a-z0-9]_+/gi, "")
|
14
|
-
.toLowerCase()
|
15
|
-
const autoUtm = `utm_source=${cName}&utm_medium=${utmMedium}&utm_campaign=${utmCampaign}`
|
16
|
-
const isValid = testRegexFromRegexRulesMap("utm", autoUtm) || !autoUtm
|
17
|
-
|
18
|
-
return [autoUtm, isValid]
|
19
|
-
}
|
package/src/common/validators.ts
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
import validator from "validator"
|
2
|
-
|
3
|
-
export const isNotEmpty = (value: string | Record<string, any> | any[]) => {
|
4
|
-
return Array.isArray(value)
|
5
|
-
? value?.length > 0
|
6
|
-
: typeof value === "object"
|
7
|
-
? validator.isLength(value?.["value"], { min: 1 })
|
8
|
-
: validator.isLength(value, { min: 1 })
|
9
|
-
}
|
10
|
-
|
11
|
-
export const isNotZero = (value: number) => value !== 0
|
12
|
-
|
13
|
-
// it is important that the functions are not exported individually
|
14
|
-
// the store data needs to be serializable so we need to assign the names of these functions to variables
|
15
|
-
// rather than the function itself
|
16
|
-
const validators = {
|
17
|
-
isNotEmpty,
|
18
|
-
isNotZero,
|
19
|
-
}
|
20
|
-
|
21
|
-
export default validators
|