@vonq/hapi-elements-types 1.4.0 → 1.5.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.
Files changed (188) hide show
  1. package/enums.ts +41 -0
  2. package/package.json +5 -7
  3. package/src/_window/api.types.ts +59 -0
  4. package/src/_window/auth.types.ts +11 -0
  5. package/src/_window/config.types.ts +30 -0
  6. package/src/_window/events.types.ts +157 -0
  7. package/src/_window/index.ts +16 -0
  8. package/src/_window/instances.types.ts +18 -0
  9. package/src/_window/qa.types.ts +28 -0
  10. package/src/_window/routing.types.ts +21 -0
  11. package/src/_window/sdk.types.ts +147 -0
  12. package/src/_window/service.types.ts +67 -0
  13. package/src/_window/state.types.ts +112 -0
  14. package/src/_window/ui.types.ts +13 -0
  15. package/src/_window/utils.types.ts +34 -0
  16. package/src/_window/validation.types.ts +43 -0
  17. package/src/_window/window.ts +56 -0
  18. package/src/alert/enums.ts +22 -0
  19. package/src/alert/functions.types.ts +13 -0
  20. package/src/alert/index.ts +9 -0
  21. package/src/alert/service.types.ts +15 -0
  22. package/src/alert/state.initial.ts +16 -0
  23. package/src/alert/state.types.ts +27 -0
  24. package/src/alert/state.validations.ts +11 -0
  25. package/src/alert/types.ts +63 -0
  26. package/src/ats/api.types.ts +16 -0
  27. package/src/ats/functions.types.ts +7 -0
  28. package/src/ats/index.ts +9 -0
  29. package/src/ats/service.types.ts +17 -0
  30. package/src/ats/state.initial.ts +5 -0
  31. package/src/ats/state.types.ts +5 -0
  32. package/src/ats/state.validations.ts +6 -0
  33. package/src/ats/types.ts +19 -0
  34. package/src/basket/consts.ts +1 -0
  35. package/src/basket/functions.types.ts +40 -0
  36. package/src/basket/index.ts +12 -0
  37. package/src/basket/service.types.ts +32 -0
  38. package/src/basket/state.initial.ts +11 -0
  39. package/src/basket/state.types.ts +34 -0
  40. package/src/basket/state.validations.ts +12 -0
  41. package/src/basket/types.ts +4 -0
  42. package/src/basket/utils.ts +79 -0
  43. package/src/basket/utils.types.ts +10 -0
  44. package/src/basket/validations.types.ts +25 -0
  45. package/src/campaign/api.types.ts +45 -0
  46. package/src/campaign/consts.ts +1 -0
  47. package/src/campaign/enums.ts +17 -0
  48. package/src/campaign/functions.types.ts +90 -0
  49. package/src/campaign/index.ts +15 -0
  50. package/src/campaign/qa.types.ts +12 -0
  51. package/src/campaign/service.types.ts +48 -0
  52. package/src/campaign/state.initial.ts +84 -0
  53. package/src/campaign/state.types.ts +55 -0
  54. package/src/campaign/state.validations.ts +16 -0
  55. package/src/campaign/types.ts +237 -0
  56. package/src/campaign/utils.ts +53 -0
  57. package/src/campaign/utils.types.ts +59 -0
  58. package/src/campaign/validations.types.ts +215 -0
  59. package/src/common/LocalStorage.ts +123 -0
  60. package/src/common/browser.ts +2 -0
  61. package/src/common/color.ts +9 -0
  62. package/src/common/events/EventCommand/enums.ts +49 -0
  63. package/src/common/events/EventCommand/index.ts +4 -0
  64. package/src/common/events/EventCommand/types.ts +18 -0
  65. package/src/common/events/index.ts +4 -0
  66. package/src/common/events/types.ts +52 -0
  67. package/src/common/immutable.ts +28 -0
  68. package/src/common/index.ts +22 -0
  69. package/src/common/instances/Instance.ts +13 -0
  70. package/src/common/instances/consts.ts +1 -0
  71. package/src/common/instances/index.ts +4 -0
  72. package/src/common/json.ts +25 -0
  73. package/src/common/logger/Logger.ts +70 -0
  74. package/src/common/logger/enums.ts +12 -0
  75. package/src/common/logger/index.ts +5 -0
  76. package/src/common/logger/types.ts +7 -0
  77. package/src/common/logger-datadog/LoggerDatadog.ts +42 -0
  78. package/src/common/logger-datadog/index.ts +3 -0
  79. package/src/common/misc.ts +114 -0
  80. package/src/common/promise.ts +161 -0
  81. package/src/common/proxy.ts +77 -0
  82. package/src/common/qa.types.ts +9 -0
  83. package/src/common/regExTest.ts +12 -0
  84. package/src/common/tree.ts +148 -0
  85. package/src/common/types.ts +110 -0
  86. package/src/common/utm.ts +19 -0
  87. package/src/common/validations.types.ts +89 -0
  88. package/src/common/validators.ts +21 -0
  89. package/src/common/webComponents.ts +26 -0
  90. package/src/config/functions.types.ts +23 -0
  91. package/src/config/index.ts +5 -0
  92. package/src/config/state.initial.ts +11 -0
  93. package/src/config/state.types.ts +15 -0
  94. package/src/consts.ts +980 -0
  95. package/src/contract/api.types.ts +47 -0
  96. package/src/contract/consts.ts +1 -0
  97. package/src/contract/functions.types.ts +112 -0
  98. package/src/contract/index.ts +14 -0
  99. package/src/contract/qa.types.ts +12 -0
  100. package/src/contract/service.types.ts +54 -0
  101. package/src/contract/state.initial.ts +39 -0
  102. package/src/contract/state.types.ts +74 -0
  103. package/src/contract/state.validations.ts +21 -0
  104. package/src/contract/types.ts +145 -0
  105. package/src/contract/utils.ts +36 -0
  106. package/src/contract/utils.types.ts +11 -0
  107. package/src/contract/validations.types.ts +104 -0
  108. package/src/debugging/functions.types.ts +34 -0
  109. package/src/debugging/index.ts +6 -0
  110. package/src/debugging/state.initial.ts +10 -0
  111. package/src/debugging/state.types.ts +18 -0
  112. package/src/debugging/state.validations.ts +10 -0
  113. package/src/index.ts +22 -0
  114. package/src/language/consts.ts +6 -0
  115. package/src/language/en.ts +530 -0
  116. package/src/language/functions.types.ts +29 -0
  117. package/src/language/index.ts +11 -0
  118. package/src/language/qa.types.ts +19 -0
  119. package/src/language/state.initial.ts +13 -0
  120. package/src/language/state.types.ts +25 -0
  121. package/src/language/state.validations.ts +10 -0
  122. package/src/language/utils.ts +17 -0
  123. package/src/language/validations.types.ts +13 -0
  124. package/src/modal/consts.ts +6 -0
  125. package/src/modal/enums.ts +14 -0
  126. package/src/modal/functions.types.ts +22 -0
  127. package/src/modal/index.ts +11 -0
  128. package/src/modal/service.types.ts +32 -0
  129. package/src/modal/state.initial.ts +9 -0
  130. package/src/modal/state.types.ts +8 -0
  131. package/src/modal/state.validations.ts +6 -0
  132. package/src/modal/store.types.ts +5 -0
  133. package/src/modal/types.ts +44 -0
  134. package/src/orderJourney/consts.ts +289 -0
  135. package/src/orderJourney/enums.ts +25 -0
  136. package/src/orderJourney/functions.types.ts +140 -0
  137. package/src/orderJourney/index.ts +13 -0
  138. package/src/orderJourney/qa.types.ts +16 -0
  139. package/src/orderJourney/state.initial.ts +401 -0
  140. package/src/orderJourney/state.types.ts +99 -0
  141. package/src/orderJourney/state.validations.ts +78 -0
  142. package/src/orderJourney/types.ts +31 -0
  143. package/src/orderJourney/utils.ts +7 -0
  144. package/src/orderJourney/utils.types.ts +11 -0
  145. package/src/orderJourney/validations.types.ts +34 -0
  146. package/src/product/api.types.ts +62 -0
  147. package/src/product/consts.ts +1 -0
  148. package/src/product/enums.ts +11 -0
  149. package/src/product/functions.types.ts +156 -0
  150. package/src/product/index.ts +14 -0
  151. package/src/product/qa.types.ts +11 -0
  152. package/src/product/service.types.ts +68 -0
  153. package/src/product/state.initial.ts +28 -0
  154. package/src/product/state.types.ts +93 -0
  155. package/src/product/state.validations.ts +25 -0
  156. package/src/product/types.ts +161 -0
  157. package/src/product/utils.types.ts +22 -0
  158. package/src/product/validations.types.ts +189 -0
  159. package/src/routing/functions.types.ts +48 -0
  160. package/src/routing/index.ts +5 -0
  161. package/src/routing/state.initial.ts +10 -0
  162. package/src/routing/state.types.ts +30 -0
  163. package/src/theming/consts.ts +7727 -0
  164. package/src/theming/functions.types.ts +13 -0
  165. package/src/theming/index.ts +11 -0
  166. package/src/theming/qa.types.ts +11 -0
  167. package/src/theming/state.initial.ts +16 -0
  168. package/src/theming/state.types.ts +6 -0
  169. package/src/theming/state.validations.ts +8 -0
  170. package/src/theming/types.ts +123 -0
  171. package/src/theming/utils.ts +581 -0
  172. package/src/theming/validations.types.ts +62 -0
  173. package/src/types.ts +229 -0
  174. package/src/ui/index.ts +3 -0
  175. package/src/ui/service.types.ts +26 -0
  176. package/src/utils.ts +3 -0
  177. package/src/wallet/api.types.ts +33 -0
  178. package/src/wallet/consts.ts +3 -0
  179. package/src/wallet/functions.types.ts +58 -0
  180. package/src/wallet/index.ts +11 -0
  181. package/src/wallet/service.types.ts +26 -0
  182. package/src/wallet/state.initial.ts +18 -0
  183. package/src/wallet/state.types.ts +58 -0
  184. package/src/wallet/state.validations.ts +18 -0
  185. package/src/wallet/types.ts +65 -0
  186. package/src/wallet/validations.types.ts +18 -0
  187. package/tsconfig.json +41 -0
  188. package/index.d.ts +0 -5207
@@ -0,0 +1,77 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleWithConstructorArgs } from "../types"
2
+ import { WindowHapiQA } from "../_window/qa.types"
3
+
4
+ export type WindowHapiQACommon = ModuleWithConstructorArgs<
5
+ {
6
+ setComponentDebuggingIsEnabled: (isEnabled: boolean) => boolean
7
+ },
8
+ { readonly qa: WindowHapiQA }
9
+ >
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,148 @@
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
+ }
@@ -0,0 +1,110 @@
1
+ import validator from "validator"
2
+ import validators from "./validators"
3
+ import { MessageDescriptor } from "react-intl"
4
+ import { Logger } from "./logger/Logger"
5
+ import { Stores } from "../types"
6
+
7
+ export type ValueOf<T> = T[keyof T]
8
+ export type AnyNonFunction<T> = Omit<T, "function">
9
+ export declare type PrimitiveType =
10
+ | string
11
+ | number
12
+ | boolean
13
+ | null
14
+ | undefined
15
+ | Date
16
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
17
+ export type RecursivePartial<T> = {
18
+ [P in keyof T]?: RecursivePartial<T[P]>
19
+ }
20
+ export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>
21
+ export type RemoveIndex<T> = {
22
+ [K in keyof T as string extends K
23
+ ? never
24
+ : number extends K
25
+ ? never
26
+ : K]: T[K]
27
+ }
28
+ export type PaginationLimitOffset = {
29
+ limit?: number
30
+ offset?: number
31
+ }
32
+ export type PaginationResponseV1 = {
33
+ count?: number
34
+ next?: string | null
35
+ previous?: string | null
36
+ } & PaginationLimitOffset
37
+ export type PaginationResponseV2 = {
38
+ total?: number
39
+ meta?: {
40
+ first: string
41
+ last: string
42
+ next: string
43
+ previous: string
44
+ }
45
+ } & PaginationLimitOffset
46
+ export type PaginatedAPIResponseV1<T> = {
47
+ results: T[]
48
+ } & PaginationResponseV1
49
+ export type PaginatedAPIResponseV2<T> = {
50
+ data: T[]
51
+ } & PaginationResponseV2
52
+ export type HapiInputErrorMessageOrValidity =
53
+ | MessageDescriptor
54
+ | boolean
55
+ | undefined
56
+ | null
57
+ export type UseValidatorResult = {
58
+ validityOrErrorMessages: Record<string, HapiInputErrorMessageOrValidity>
59
+ areAllValid: boolean
60
+ }
61
+ export type ValidatorKey =
62
+ | Exclude<
63
+ keyof typeof validator,
64
+ | "version"
65
+ | "AlphaLocale"
66
+ | "isAlphaLocales"
67
+ | "AlphanumericLocale"
68
+ | "isAlphanumericLocales"
69
+ | "ibanLocales"
70
+ | "FloatLocale"
71
+ | "isFloatLocales"
72
+ | "MobilePhoneLocale"
73
+ | "PhoneLocale"
74
+ | "PhoneLocaleAlias"
75
+ | "isMobilePhoneLocales"
76
+ | "PostalCodeLocale"
77
+ | "isPostalCodeLocales"
78
+ >
79
+ | keyof typeof validators
80
+ export type NestedValidatorKeys =
81
+ | ValidatorKey
82
+ | {
83
+ [k: string]: ValidatorKey | NestedValidatorKeys
84
+ }
85
+ export type BaseService = {
86
+ logger: Logger
87
+ }
88
+ // the reason there are no types like enums here is because
89
+ // the options should be a serializable JSON during generation of web component files
90
+ export type HapiWebComponent = {
91
+ title: string
92
+ description: string
93
+ moduleName: string //WindowHapiModuleName
94
+ secondaryModuleName?: string //WindowHapiModuleName
95
+ notes?: string //additional remarks like some best practices for this individual widget
96
+ path: string
97
+ key: string
98
+ id: string
99
+ injects?: string[]
100
+ initialState?: Partial<Record<keyof Stores, any>>
101
+ isUserJourney?: boolean
102
+ webComponentCSS?: Record<string, any> //React.CSSProperties
103
+ attributes?: Record<string, string>
104
+ qaFunctionToMockId?: Record<string, string> //some widgets have attributes like <widget campaign-id=IDHERE> and they show 404 inside demo pages and documentation so this will map to window.hapiQA function that will grab that id. example below
105
+ /* mock id example
106
+ {
107
+ "campaignId": "campaign.getRandomCampaignId" //campaignId being the path parameter like [campaignId].tsx
108
+ }
109
+ */
110
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,89 @@
1
+ import {
2
+ ZodAny,
3
+ ZodArray,
4
+ ZodBoolean,
5
+ ZodFunction,
6
+ ZodNullable,
7
+ ZodNumber,
8
+ ZodObject,
9
+ ZodOptional,
10
+ ZodRecord,
11
+ ZodString,
12
+ ZodTuple,
13
+ ZodUnion,
14
+ ZodUnknown,
15
+ } from "zod"
16
+
17
+ export type ZodIntlDescriptor = ZodObject<{
18
+ id: ZodString
19
+ defaultMessage: ZodString
20
+ }>
21
+ export type ZodPaginationLimit = ZodNumber
22
+ export type ZodPaginationOffset = ZodNumber
23
+ export type ZodPaginationLimitOffsetDefinition = {
24
+ limit: ZodOptional<ZodPaginationLimit>
25
+ offset: ZodOptional<ZodPaginationOffset>
26
+ }
27
+ export type ZodPaginationLimitOffset =
28
+ ZodObject<ZodPaginationLimitOffsetDefinition>
29
+ export type ZodPaginationNext = ZodString
30
+ export type ZodPaginationPrevious = ZodString
31
+ export type ZodPaginationFirst = ZodString
32
+ export type ZodPaginationLast = ZodString
33
+ export type ZodPaginationNextPreviousDefinition = {
34
+ next: ZodOptional<ZodNullable<ZodPaginationNext>>
35
+ previous: ZodOptional<ZodNullable<ZodPaginationPrevious>>
36
+ }
37
+ export type ZodPaginationFirstLastDefinition = {
38
+ first: ZodOptional<ZodNullable<ZodPaginationFirst>>
39
+ last: ZodOptional<ZodNullable<ZodPaginationLast>>
40
+ }
41
+ export type ZodPaginationTotal = ZodNumber
42
+ export type ZodPaginationResponseV1 = ZodObject<
43
+ {
44
+ count: ZodOptional<ZodNullable<ZodNumber>>
45
+ } & ZodPaginationLimitOffsetDefinition &
46
+ ZodPaginationNextPreviousDefinition
47
+ >
48
+ export type ZodPaginationMeta = ZodObject<
49
+ ZodPaginationFirstLastDefinition & ZodPaginationNextPreviousDefinition
50
+ >
51
+ export type ZodPaginationResponseV2 = ZodObject<
52
+ {
53
+ total: ZodOptional<ZodNullable<ZodPaginationTotal>>
54
+ meta: ZodOptional<ZodPaginationMeta>
55
+ } & ZodPaginationLimitOffsetDefinition
56
+ >
57
+ export type WindowHapiValidationsCommon = {
58
+ genericBoolean: ZodBoolean
59
+ genericNumber: ZodNumber
60
+ genericNumberArray: ZodArray<ZodNumber>
61
+ genericString: ZodString
62
+ genericStringArray: ZodArray<ZodString>
63
+ genericObject: ZodObject<any>
64
+ genericRecordFunction: ZodRecord<
65
+ ZodString,
66
+ ZodFunction<ZodTuple<[], ZodUnknown>, ZodUnknown>
67
+ >
68
+ genericRecordBoolean: ZodRecord<ZodString, ZodBoolean>
69
+ genericRecordString: ZodRecord<ZodString, ZodString>
70
+ genericStringOrNumber: ZodUnion<[ZodNumber, ZodString]>
71
+ genericNullableStringOrNumber: ZodNullable<ZodUnion<[ZodNumber, ZodString]>>
72
+ genericNullableString: ZodNullable<ZodString>
73
+ genericAny: ZodAny
74
+ genericAnyArray: ZodArray<ZodAny>
75
+ genericStringOrNumberArray: ZodArray<ZodUnion<[ZodNumber, ZodString]>>
76
+ recordString: ZodRecord<ZodString, ZodString>
77
+ intlDescriptor: ZodIntlDescriptor
78
+ limitOffsetPagination: ZodPaginationLimitOffsetDefinition
79
+ paginationMetaV1: ZodPaginationResponseV1
80
+ paginationMetaV2: ZodPaginationResponseV2
81
+ hexRegex: RegExp
82
+ hex: ZodString
83
+ camelCaseRegex: RegExp
84
+ camelCase: ZodString
85
+ urlRegex: RegExp
86
+ url: ZodString
87
+ apiResourceRegex: RegExp
88
+ apiResource: ZodString
89
+ }
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,26 @@
1
+ import { WindowHapiModuleName } from "../../enums"
2
+ import { _window } from "../consts"
3
+
4
+ export const getWebComponentElementCode = (key: string) => `<${key}></${key}>`
5
+
6
+ export const getWebComponentsFromHapiConfigByModuleName = (
7
+ activeModule: WindowHapiModuleName,
8
+ ) => {
9
+ return _window!.hapiConfig?.webComponents
10
+ .filter((component) => component.moduleName === activeModule)
11
+ .map((component) => {
12
+ return {
13
+ name: component.title,
14
+ id: component.key,
15
+ language: "component",
16
+ }
17
+ })
18
+ }
19
+
20
+ export const getWebComponentFromHapiConfigByWidgetName = (
21
+ widgetName: string,
22
+ ) => {
23
+ return _window!.hapiConfig?.webComponents.find(
24
+ (component) => component.key === widgetName,
25
+ )
26
+ }
@@ -0,0 +1,23 @@
1
+ import { ClientID, PartnerID } from "./state.types"
2
+ import { DemoATSLayoutType } from "../types"
3
+
4
+ export type ConfigStoreSetPartnerIdHandler = (partnerId: PartnerID) => void
5
+ export type ConfigStoreSetClientIdHandler = (clientId: ClientID) => void
6
+
7
+ export type ConfigStoreSetShouldCallInitOfServicesHandler = (
8
+ shouldCallInitOfServices: boolean,
9
+ ) => void
10
+
11
+ export type ConfigStoreSetDemoATSLayoutHandler = (
12
+ layout: DemoATSLayoutType,
13
+ ) => void
14
+
15
+ export type ConfigStoreFunctions = {
16
+ /* App Related */
17
+ setPartnerId: ConfigStoreSetPartnerIdHandler
18
+ setClientId: ConfigStoreSetClientIdHandler
19
+
20
+ /* Demo ATS Related */
21
+ setShouldCallInitOfServices: ConfigStoreSetShouldCallInitOfServicesHandler
22
+ setDemoATSLayout: ConfigStoreSetDemoATSLayoutHandler
23
+ }
@@ -0,0 +1,5 @@
1
+ // created from 'create-ts-index'
2
+
3
+ export * from './functions.types';
4
+ export * from './state.initial';
5
+ export * from './state.types';
@@ -0,0 +1,11 @@
1
+ import { ConfigStoreState } from "./state.types"
2
+
3
+ export const initialConfigStoreState: ConfigStoreState = {
4
+ /* App Related */
5
+ partnerId: undefined,
6
+ clientId: undefined,
7
+
8
+ /* Demo ATS Related */
9
+ shouldCallInitOfServices: false,
10
+ demoATSLayout: "technical",
11
+ }
@@ -0,0 +1,15 @@
1
+ import { DemoATSLayoutType } from "../types"
2
+
3
+ export type PartnerID = string | undefined
4
+ export type ClientID = string | undefined
5
+ export type ClientToken = string | undefined
6
+
7
+ export type ConfigStoreState = {
8
+ /* App Related */
9
+ partnerId: PartnerID
10
+ clientId: ClientID
11
+
12
+ /* Demo ATS Related */
13
+ shouldCallInitOfServices: boolean
14
+ demoATSLayout: DemoATSLayoutType
15
+ }