@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
package/src/types.ts ADDED
@@ -0,0 +1,229 @@
1
+ import React from "react"
2
+ import { WindowHapiState } from "./_window/state.types"
3
+ import { WindowHapiAuth } from "./_window/auth.types"
4
+ import { WindowHapiUI } from "./_window/ui.types"
5
+ import HapiInstance from "./common/instances/Instance"
6
+ import { WindowHapiQA } from "./_window/qa.types"
7
+ import { ProductStoreState } from "./product/state.types"
8
+ import { ProductStoreFunctions } from "./product/functions.types"
9
+ import { BasketStoreState } from "./basket/state.types"
10
+ import { BasketStoreFunctions } from "./basket/functions.types"
11
+ import { ModalStore } from "./modal/store.types"
12
+ import { ModalStoreState } from "./modal/state.types"
13
+ import { ModalStoreFunctions } from "./modal/functions.types"
14
+ import { ContractStoreState } from "./contract/state.types"
15
+ import { ContractStoreFunctions } from "./contract/functions.types"
16
+ import { AlertStoreState } from "./alert/state.types"
17
+ import { AlertStoreFunctions } from "./alert/functions.types"
18
+ import { OrderJourneyStoreState } from "./orderJourney/state.types"
19
+ import { OrderJourneyStoreFunctions } from "./orderJourney/functions.types"
20
+ import { CampaignStoreState } from "./campaign/state.types"
21
+ import { CampaignStoreFunctions } from "./campaign/functions.types"
22
+ import { WalletStoreState } from "./wallet/state.types"
23
+ import { WalletStoreFunctions } from "./wallet/functions.types"
24
+ import { ThemeStoreState } from "./theming/state.types"
25
+ import { ThemeStoreFunctions } from "./theming/functions.types"
26
+ import { RouterStoreState } from "./routing/state.types"
27
+ import { RouterStoreFunctions } from "./routing/functions.types"
28
+ import { ConfigStoreState } from "./config/state.types"
29
+ import { ConfigStoreFunctions } from "./config/functions.types"
30
+ import { LanguageStoreState } from "./language/state.types"
31
+ import { LanguageStoreFunctions } from "./language/functions.types"
32
+ import { DebuggingStoreState } from "./debugging/state.types"
33
+ import { DebuggingStoreFunctions } from "./debugging/functions.types"
34
+ import { IntlShape } from "react-intl"
35
+ import { Logger } from "./common/logger/Logger"
36
+ import { IReactionDisposer } from "mobx"
37
+ import { ATSStoreState } from "./ats/state.types"
38
+ import { ATSStoreFunctions } from "./ats/functions.types"
39
+ import { WindowHapiValidations } from "./_window/validation.types"
40
+ import { WindowHapiUtils } from "./_window/utils.types"
41
+ import { WindowHapiRouting } from "./_window/routing.types"
42
+ import { WindowHapiInstances } from "./_window/instances.types"
43
+ import { WindowHapiSDK } from "./_window/sdk.types"
44
+ import { WindowHapiService } from "./_window/service.types"
45
+ import { WindowHapiEvents } from "./_window/events.types"
46
+ import { WindowHapiAPI } from "./_window/api.types"
47
+ import { WindowHapiConfig } from "./_window/config.types"
48
+ import { RecursivePartial } from "./common/types"
49
+
50
+ export type ComponentWithChildren = {
51
+ children?: React.ReactNode
52
+ }
53
+
54
+ export type WindowHAPIInterface = {
55
+ hapiState: WindowHapiState
56
+ hapiAuth: WindowHapiAuth
57
+ hapiConfig: WindowHapiConfig
58
+ hapiEvents: WindowHapiEvents
59
+ hapiInstances: WindowHapiInstances
60
+ hapiRouting: WindowHapiRouting
61
+ hapiUI: WindowHapiUI
62
+ hapiUtils: WindowHapiUtils
63
+ hapiInstance: HapiInstance
64
+ hapiValidation: WindowHapiValidations
65
+ hapi: WindowHapiSDK
66
+ hapiApi: WindowHapiAPI
67
+ hapiService: WindowHapiService
68
+ hapiQA: WindowHapiQA
69
+ __hapi: IRootStore
70
+ __mobxToJS: <T>(source: T, options?: any) => T
71
+ }
72
+ export type BaseStoreFunctions = {
73
+ init: () => void
74
+ }
75
+ export type CreateLoggerHandler = (
76
+ source?: string,
77
+ isEnabled?: boolean,
78
+ ) => Logger
79
+ export type IRootStore = {
80
+ store: Stores
81
+ rehydrateStore: (
82
+ storeName: keyof Stores,
83
+ storeData: RecursivePartial<Stores[keyof Stores]>,
84
+ ) => void
85
+ intl: IntlShape
86
+ createLogger: CreateLoggerHandler
87
+
88
+ sourceInstance: HapiInstance
89
+ targetInstances: HapiInstance[]
90
+ }
91
+ export type BaseStoreVariables = {
92
+ rootStore: IRootStore
93
+ }
94
+ export type BaseStoreVariablesAndFunctions = BaseStoreVariables &
95
+ BaseStoreFunctions
96
+ export type BaseStore<State, Functions> = BaseStoreVariablesAndFunctions &
97
+ State &
98
+ Functions
99
+ export type ConfigStore = BaseStore<ConfigStoreState, ConfigStoreFunctions>
100
+ export type ConfigStoreType = StoryFactoryType<
101
+ ConfigStore,
102
+ ConfigStoreState,
103
+ ConfigStoreFunctions
104
+ >
105
+ export type ATSStore = BaseStore<ATSStoreState, ATSStoreFunctions>
106
+ export type ATSStoreType = StoryFactoryType<
107
+ ATSStore,
108
+ ATSStoreState,
109
+ ATSStoreFunctions
110
+ >
111
+ export type LanguageStore = BaseStore<
112
+ LanguageStoreState,
113
+ LanguageStoreFunctions
114
+ >
115
+ export type LanguageStoreType = StoryFactoryType<
116
+ LanguageStore,
117
+ LanguageStoreState,
118
+ LanguageStoreFunctions
119
+ >
120
+ export type AlertStore = BaseStore<AlertStoreState, AlertStoreFunctions>
121
+ export type AlertStoreType = StoryFactoryType<
122
+ AlertStore,
123
+ AlertStoreState,
124
+ AlertStoreFunctions
125
+ >
126
+ export type ThemeStore = BaseStore<ThemeStoreState, ThemeStoreFunctions>
127
+ export type ThemeStoreType = StoryFactoryType<
128
+ ThemeStore,
129
+ ThemeStoreState,
130
+ ThemeStoreFunctions
131
+ >
132
+ export type RouterStore = BaseStore<RouterStoreState, RouterStoreFunctions>
133
+ export type RouterStoreType = StoryFactoryType<
134
+ RouterStore,
135
+ RouterStoreState,
136
+ RouterStoreFunctions
137
+ >
138
+ export type ContractStore = BaseStore<
139
+ ContractStoreState,
140
+ ContractStoreFunctions
141
+ >
142
+ export type ContractStoreType = StoryFactoryType<
143
+ ContractStore,
144
+ ContractStoreState,
145
+ ContractStoreFunctions
146
+ >
147
+ export type ProductStore = BaseStore<ProductStoreState, ProductStoreFunctions>
148
+ export type ProductStoreType = StoryFactoryType<
149
+ ProductStore,
150
+ ProductStoreState,
151
+ ProductStoreFunctions
152
+ >
153
+ export type CampaignStore = BaseStore<
154
+ CampaignStoreState,
155
+ CampaignStoreFunctions
156
+ >
157
+ export type CampaignStoreType = StoryFactoryType<
158
+ CampaignStore,
159
+ CampaignStoreState,
160
+ CampaignStoreFunctions
161
+ >
162
+ export type WalletStore = BaseStore<WalletStoreState, WalletStoreFunctions>
163
+ export type WalletStoreType = StoryFactoryType<
164
+ WalletStore,
165
+ WalletStoreState,
166
+ WalletStoreFunctions
167
+ >
168
+ export type BasketStore = BaseStore<BasketStoreState, BasketStoreFunctions>
169
+ export type BasketStoreType = StoryFactoryType<
170
+ BasketStore,
171
+ BasketStoreState,
172
+ BasketStoreFunctions
173
+ >
174
+ export type ModalStoreType = StoryFactoryType<
175
+ ModalStore,
176
+ ModalStoreState,
177
+ ModalStoreFunctions
178
+ >
179
+ export type OrderJourneyStore = BaseStore<
180
+ OrderJourneyStoreState,
181
+ OrderJourneyStoreFunctions
182
+ >
183
+ export type OrderJourneyStoreType = StoryFactoryType<
184
+ OrderJourneyStore,
185
+ OrderJourneyStoreState,
186
+ OrderJourneyStoreFunctions
187
+ >
188
+ export type DebuggingStore = BaseStore<
189
+ DebuggingStoreState,
190
+ DebuggingStoreFunctions
191
+ >
192
+ export type DebuggingStoreType = StoryFactoryType<
193
+ DebuggingStore,
194
+ DebuggingStoreState,
195
+ DebuggingStoreFunctions
196
+ >
197
+ export type Stores = {
198
+ atsStore: ATSStoreType
199
+ configStore: ConfigStoreType
200
+ languageStore: LanguageStoreType
201
+ alertStore: AlertStoreType
202
+ themeStore: ThemeStoreType
203
+ contractStore: ContractStoreType
204
+ productStore: ProductStoreType
205
+ routerStore: RouterStoreType
206
+ campaignStore: CampaignStoreType
207
+ modalStore: ModalStoreType
208
+ walletStore: WalletStoreType
209
+ basketStore: BasketStoreType
210
+ orderJourneyStore: OrderJourneyStoreType
211
+ debuggingStore: DebuggingStoreType
212
+ }
213
+ export type CommonStoreVariablesAndFunctions = {
214
+ init: (...args: any[]) => void | Promise<void>
215
+ logger: Logger
216
+ classObserver: StoreClassObserver | undefined
217
+ toJSON: JSON
218
+ }
219
+ export type StoreClassObserver = IReactionDisposer
220
+ export type StoreFactory<Store, _StoreState, _StoreFunctions> =
221
+ CommonStoreVariablesAndFunctions
222
+ export type StoryFactoryType<Store, _StoreState, _StoreFunctions> =
223
+ StoreFactory<Store, _StoreState, _StoreFunctions> &
224
+ _StoreState &
225
+ _StoreFunctions
226
+ export type DemoATSLayoutType = "technical" | "product-oriented"
227
+
228
+ export type ModuleWithConstructorArgs<Module, ConstructorArgs> = Module &
229
+ ConstructorArgs
@@ -0,0 +1,3 @@
1
+ // created from 'create-ts-index'
2
+
3
+ export * from './service.types';
@@ -0,0 +1,26 @@
1
+ import { ModuleWithConstructorArgs } from "../types"
2
+ import { WindowHapiService } from "../_window/service.types"
3
+
4
+ export type WindowHapiServiceUI = ModuleWithConstructorArgs<
5
+ {
6
+ setStyleAttribute: (
7
+ selector: string,
8
+ attributeName: string,
9
+ attributeValue: any,
10
+ ) => Promise<void>
11
+ setStyle: (selector: string, style: any) => Promise<void>
12
+ addClass: (selector: string, className: string) => Promise<void>
13
+ removeClass: (selector: string, className: string) => Promise<void>
14
+ appendChild: (
15
+ containerSelector: string,
16
+ element: HTMLElement,
17
+ ) => Promise<void>
18
+ removeChild: (
19
+ containerSelector: string,
20
+ elementSelector: string,
21
+ ) => Promise<void>
22
+ hideElement: (elementSelector: string) => Promise<void>
23
+ showElement: (elementSelector: string) => Promise<void>
24
+ },
25
+ { readonly service: WindowHapiService }
26
+ >
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const isZodInstance = (object: Record<any, any>) => {
2
+ return object?._def && object?.parse
3
+ }
@@ -0,0 +1,33 @@
1
+ import { RawAxiosRequestConfig } from "axios"
2
+ import {
3
+ Wallet,
4
+ WalletBillingPortalLinkResponse,
5
+ WalletCreateForm,
6
+ WalletPaymentIntentRequest,
7
+ } from "./types"
8
+ import { WindowHapiAPI, WindowHapiAPIModule } from "../_window/api.types"
9
+ import { ModuleWithConstructorArgs } from "../types"
10
+
11
+ export type WindowHapiAPIWalletConfigs = {
12
+ getWallet: RawAxiosRequestConfig
13
+ createWallet: RawAxiosRequestConfig
14
+ getBillingPortalLink: RawAxiosRequestConfig
15
+ createPaymentIntent: RawAxiosRequestConfig
16
+ }
17
+ export type WindowHapiAPIWalletRequests = {
18
+ getWallet: () => Promise<Wallet>
19
+ createWallet: (wallet: WalletCreateForm) => Promise<Wallet>
20
+ getBillingPortalLink: (
21
+ returnUrl: string,
22
+ ) => Promise<WalletBillingPortalLinkResponse>
23
+ createPaymentIntent: (
24
+ paymentParams: WalletPaymentIntentRequest,
25
+ ) => Promise<any>
26
+ }
27
+ export type WindowHapiAPIWallet = ModuleWithConstructorArgs<
28
+ WindowHapiAPIModule<
29
+ WindowHapiAPIWalletRequests,
30
+ WindowHapiAPIWalletConfigs
31
+ >,
32
+ { readonly api: WindowHapiAPI }
33
+ >
@@ -0,0 +1,3 @@
1
+ export const WALLET_BILLING_PORTAL_LINK_EXPIRY_IN_MINUTES = 4.5 //normally its 5 but lets make it 4.5
2
+ export const WALLET_BILLING_PORTAL_LINK_EXPIRY_IN_SECONDS =
3
+ WALLET_BILLING_PORTAL_LINK_EXPIRY_IN_MINUTES * 60
@@ -0,0 +1,58 @@
1
+ import { ProductPriceCurrency } from "../product/enums"
2
+ import { Wallet, WalletPaymentIntentPaymentMethod } from "./types"
3
+
4
+ export type WalletStoreSetWalletHandler = (wallet: Wallet) => void
5
+ export type WalletStoreSetIsWalletLoadingHandler = (isLoading: boolean) => void
6
+ export type WalletStoreSetTopUpIsLoadingHandler = (isLoading: boolean) => void
7
+ export type WalletStoreSetTopUpAmountHandler = (amount: number) => void
8
+ export type WalletStoreSetTopUpMinAmountHandler = (amount: number) => void
9
+ export type WalletStoreSetTopUpMinAmountCurrencyHandler = (
10
+ currency: ProductPriceCurrency,
11
+ ) => void
12
+ export type WalletStoreSetTopUpTermsOfServiceIsAgreedHandler = (
13
+ isAgreed: boolean,
14
+ ) => void
15
+ export type WalletStoreSetStripeClientSecretHandler = (client: string) => void
16
+ export type WalletStoreSetTopUpCurrentStepIndexHandler = (step: number) => void
17
+ export type WalletStoreSetTopUpPaymentMethodTypesHandler = (
18
+ type: WalletPaymentIntentPaymentMethod[],
19
+ ) => void
20
+
21
+ export type WalletStoreFunctions = {
22
+ /**
23
+ * The function that sets the value of `wallet`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
24
+ */
25
+ setWallet: WalletStoreSetWalletHandler
26
+ /**
27
+ * The function that sets the value of `walletIsLoading`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
28
+ */
29
+ setWalletIsLoading: WalletStoreSetIsWalletLoadingHandler
30
+ /**
31
+ * The function that sets the value of `topUpIsLoading`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
32
+ */
33
+ setTopUpIsLoading: WalletStoreSetTopUpIsLoadingHandler
34
+ /**
35
+ * The function that sets the value of `topUpAmount`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
36
+ */
37
+ setTopUpAmount: WalletStoreSetTopUpAmountHandler
38
+ /**
39
+ * The function that sets the value of `topUpMinAmount`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
40
+ */
41
+ setTopUpMinAmount: WalletStoreSetTopUpMinAmountHandler
42
+ /**
43
+ * The function that sets the value of `topUpMinAmountCurrency`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
44
+ */
45
+ setTopUpMinAmountCurrency: WalletStoreSetTopUpMinAmountCurrencyHandler
46
+ /**
47
+ * The function that sets the value of `topUpTermsOfServiceIsAgreed`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
48
+ */
49
+ setTopUpTermsOfServiceIsAgreed: WalletStoreSetTopUpTermsOfServiceIsAgreedHandler
50
+ /**
51
+ * The function that sets the value of `topUpCurrentStepIndex`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
52
+ */
53
+ setTopUpCurrentStepIndex: WalletStoreSetTopUpCurrentStepIndexHandler
54
+ /**
55
+ * The function that sets the value of `topUpPaymentMethodTypes`. Refer to [WalletStoreState](/docs/sdk/wallet/#walletstorestate) for more details.
56
+ */
57
+ setTopUpPaymentMethodTypes: WalletStoreSetTopUpPaymentMethodTypesHandler
58
+ }
@@ -0,0 +1,11 @@
1
+ // created from 'create-ts-index'
2
+
3
+ export * from './api.types';
4
+ export * from './consts';
5
+ export * from './functions.types';
6
+ export * from './service.types';
7
+ export * from './state.initial';
8
+ export * from './state.types';
9
+ export * from './state.validations';
10
+ export * from './types';
11
+ export * from './validations.types';
@@ -0,0 +1,26 @@
1
+ import { Wallet, WalletATSSettings, WalletPaymentIntentRequest } from "./types"
2
+ import {
3
+ HapiServiceFunctionWithLifecycleHooks,
4
+ WindowHapiService,
5
+ } from "../_window/service.types"
6
+ import { ModuleWithConstructorArgs } from "../types"
7
+
8
+ export type WalletServiceGetATSSettingsHandler =
9
+ () => Promise<WalletATSSettings>
10
+ export type WalletServiceGetWalletHandler = (
11
+ preventSettingIsLoading?: boolean,
12
+ ) => Promise<Wallet>
13
+ export type WalletServiceCreateWalletHandler = () => Promise<Wallet>
14
+
15
+ export type WindowHapiServiceWallet = ModuleWithConstructorArgs<
16
+ {
17
+ getATSSettings: HapiServiceFunctionWithLifecycleHooks<WalletServiceGetATSSettingsHandler>
18
+ getWallet: HapiServiceFunctionWithLifecycleHooks<WalletServiceGetWalletHandler>
19
+ createWallet: HapiServiceFunctionWithLifecycleHooks<WalletServiceCreateWalletHandler>
20
+ createPaymentIntent: (
21
+ paymentParams: WalletPaymentIntentRequest,
22
+ ) => Promise<void>
23
+ resetTopUpState: () => void
24
+ },
25
+ { readonly service: WindowHapiService }
26
+ >
@@ -0,0 +1,18 @@
1
+ import { ProductPriceCurrency } from "../product/enums"
2
+ import { WalletStoreState } from "./state.types"
3
+
4
+ export const initialWalletStoreState: WalletStoreState = {
5
+ balanceIsEnoughToOrderCampaign: false,
6
+ balanceInUSD: null,
7
+ paymentIntentRequestBody: null,
8
+ paymentIntentClientSecret: null,
9
+ topUpPaymentMethodTypes: ["card"],
10
+ wallet: null,
11
+ walletIsLoading: false,
12
+ topUpIsLoading: false,
13
+ topUpAmount: 0,
14
+ topUpMinAmount: 0,
15
+ topUpMinAmountCurrency: ProductPriceCurrency.USD,
16
+ topUpTermsOfServiceIsAgreed: false,
17
+ topUpCurrentStepIndex: 0,
18
+ }
@@ -0,0 +1,58 @@
1
+ import { ProductPriceCurrency } from "../product/enums"
2
+ import {
3
+ Wallet,
4
+ WalletPaymentIntentPaymentMethod,
5
+ WalletPaymentIntentRequest,
6
+ } from "./types"
7
+
8
+ export type WalletStoreState = {
9
+ /**
10
+ * User's Wallet that can hold credits to be used on Creating/Ordering a Campaign
11
+ */
12
+ wallet: Wallet | null
13
+ /**
14
+ * User's balance in dollars converted from cents through `wallet.balance`. **This value is a computed getter meaning that it cannot be set from outside**
15
+ */
16
+ balanceInUSD: number | null
17
+ /**
18
+ * Indicates whether or not user has enough credits/balance to Order a Campaign
19
+ */
20
+ balanceIsEnoughToOrderCampaign: boolean
21
+ /**
22
+ * Shows a loading spinner while wallet is loading
23
+ */
24
+ walletIsLoading: boolean
25
+ /**
26
+ * The request body to be sent to HAPI Backend Service to create a payment intent. **This value is a computed getter meaning that it cannot be set from outside**
27
+ */
28
+ paymentIntentRequestBody: WalletPaymentIntentRequest | null
29
+ paymentIntentClientSecret: string | null
30
+ /**
31
+ * Shows a loading spinner while PaymentIntent is creating
32
+ */
33
+ topUpIsLoading: boolean
34
+ /**
35
+ * A custom amount to specify for the top up of balance
36
+ */
37
+ topUpAmount: number
38
+ /**
39
+ * A minimum amount enforced by an ATS for the top up of balance
40
+ */
41
+ topUpMinAmount: number
42
+ /**
43
+ * A minimum amount's currency enforced by an ATS for the top up of balance
44
+ */
45
+ topUpMinAmountCurrency: ProductPriceCurrency
46
+ /**
47
+ * Indicates if user has agreed to terms of service
48
+ */
49
+ topUpTermsOfServiceIsAgreed: boolean
50
+ /**
51
+ * Step of the popup. **Should not be edited from outside**
52
+ */
53
+ topUpCurrentStepIndex: number
54
+ /**
55
+ * An array of payment method types that Stripe accepts https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types to specify which types of payment methods the end user can use
56
+ */
57
+ topUpPaymentMethodTypes: WalletPaymentIntentPaymentMethod[]
58
+ }
@@ -0,0 +1,18 @@
1
+ import { WalletStoreState } from "./state.types"
2
+ import { StateValidations } from "../_window/state.types"
3
+
4
+ export const walletStoreStateValidations: StateValidations<WalletStoreState> = {
5
+ wallet: "wallet.wallet",
6
+ walletIsLoading: "common.genericBoolean",
7
+ balanceInUSD: "throwHasNoSetterError",
8
+ balanceIsEnoughToOrderCampaign: "throwHasNoSetterError",
9
+ topUpPaymentMethodTypes: "common.genericStringArray",
10
+ paymentIntentRequestBody: "throwHasNoSetterError",
11
+ paymentIntentClientSecret: "common.genericNullableString",
12
+ topUpIsLoading: "common.genericBoolean",
13
+ topUpAmount: "common.genericNumber",
14
+ topUpMinAmount: "common.genericNumber",
15
+ topUpMinAmountCurrency: "product.currency",
16
+ topUpTermsOfServiceIsAgreed: "common.genericBoolean",
17
+ topUpCurrentStepIndex: "common.genericNumber",
18
+ }
@@ -0,0 +1,65 @@
1
+ import { ProductPriceCurrency } from "../product/enums"
2
+
3
+ export type WalletBalanceInCents = {
4
+ USD: number
5
+ }
6
+
7
+ export type Wallet = {
8
+ balance: WalletBalanceInCents
9
+ created_date: string
10
+ has_billing_details: boolean
11
+ id: string
12
+ }
13
+
14
+ export type WalletATSSettings = {
15
+ topUpAmount: number
16
+ topUpMinAmount: number
17
+ topUpPaymentMethodTypes: WalletPaymentIntentPaymentMethod[]
18
+ topUpMinAmountCurrency: ProductPriceCurrency
19
+ }
20
+
21
+ export type WalletCreateForm = {
22
+ customerName: string
23
+ }
24
+
25
+ export type WalletBillingPortalLinkResponse = {
26
+ billingPortalLink: string
27
+ }
28
+
29
+ export type WalletPaymentIntentPaymentMethod =
30
+ | "card"
31
+ | "acss_debit"
32
+ | "affirm"
33
+ | "afterpay_clearpay"
34
+ | "alipay"
35
+ | "au_becs_debit"
36
+ | "bacs_debit"
37
+ | "bancontact"
38
+ | "blik"
39
+ | "boleto"
40
+ | "card_present"
41
+ | "eps"
42
+ | "fpx"
43
+ | "giropay"
44
+ | "grabpay"
45
+ | "ideal"
46
+ | "klarna"
47
+ | "konbini"
48
+ | "link"
49
+ | "oxxo"
50
+ | "p24"
51
+ | "paynow"
52
+ | "pix"
53
+ | "promptpay"
54
+ | "sepa_debit"
55
+ | "sofort"
56
+ | "us_bank_account"
57
+ | "wechat_pay"
58
+
59
+ export type WalletPaymentIntentRequest = {
60
+ walletId: string
61
+ partnerId: string
62
+ amount: number
63
+ agreeTerms: boolean
64
+ paymentMethodTypes?: WalletPaymentIntentPaymentMethod[]
65
+ }
@@ -0,0 +1,18 @@
1
+ import { ZodBoolean, ZodNullable, ZodNumber, ZodObject, ZodString } from "zod"
2
+
3
+ export type ZodWalletBalance = ZodObject<{
4
+ USD: ZodNumber
5
+ }>
6
+ export type ZodWallet = ZodObject<{
7
+ balance: ZodWalletBalance
8
+ created_date: ZodString
9
+ has_billing_details: ZodBoolean
10
+ id: ZodString
11
+ }>
12
+ export type ZodWalletCreateForm = ZodObject<{
13
+ customerName: ZodString
14
+ }>
15
+ export type WindowHapiValidationsWallet = {
16
+ wallet: ZodNullable<ZodWallet>
17
+ walletForm: ZodWalletCreateForm
18
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2015",
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
9
+ "allowJs": true,
10
+ "skipLibCheck": true,
11
+ "strict": true,
12
+ "noEmit": false,
13
+ "esModuleInterop": true,
14
+ "moduleResolution": "node",
15
+ "module": "commonjs",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": false,
18
+ "jsx": "preserve",
19
+ "incremental": false,
20
+ "experimentalDecorators": true,
21
+ "baseUrl": "./src",
22
+ "forceConsistentCasingInFileNames": true,
23
+ "paths": {
24
+ "axios": ["../../node_modules/axios"],
25
+ "zod": ["../../node_modules/zod"],
26
+ "theming": ["../../node_modules/theming"],
27
+ "react-intl": ["../../node_modules/react-intl"],
28
+ "react": ["../../node_modules/react"],
29
+ "lodash": ["../../node_modules/lodash"]
30
+ }
31
+ },
32
+ "include": [
33
+ "./src/**/*",
34
+ ],
35
+ "exclude": [
36
+ "node_modules",
37
+ "../ats/**/*",
38
+ "../common/**/*",
39
+ "./dist/**/*"
40
+ ]
41
+ }