@goodgamestudios/cxf-webshop 6.27.3 → 7.0.0-qa.2
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/REFACTORING_README.md +265 -0
- package/TEST_MIGRATION.md +441 -0
- package/TYPES_REFACTORING.md +308 -0
- package/dist/webshop-cxf.js +1 -1
- package/dist/webshop-cxf.js.map +4 -4
- package/package.json +2 -3
- package/src_old/@types/global.d.ts +2 -0
- package/src_old/ArgumentNullError.ts +6 -0
- package/src_old/app.ts +30 -0
- package/src_old/combineReaders.ts +8 -0
- package/src_old/common.ts +35 -0
- package/src_old/config.ts +42 -0
- package/src_old/cxf.ts +32 -0
- package/src_old/dialog.ts +25 -0
- package/src_old/env.ts +127 -0
- package/src_old/fetch.ts +46 -0
- package/src_old/handlers/eventHandlers.ts +43 -0
- package/src_old/handlers/postMessageHandlers.ts +43 -0
- package/src_old/handlers/pushHandlers.ts +95 -0
- package/src_old/handlers/reducers.ts +207 -0
- package/src_old/helpers.ts +143 -0
- package/src_old/index.ts +35 -0
- package/src_old/messages/IShopMessageBus.ts +3 -0
- package/src_old/messages/ShopMessageBus.ts +10 -0
- package/src_old/messages/TestShopMessageBus.ts +8 -0
- package/src_old/ping.ts +15 -0
- package/src_old/preFetch.ts +43 -0
- package/src_old/storage.ts +32 -0
- package/src_old/store.ts +82 -0
- package/src_old/track.ts +59 -0
- package/src_old/url.ts +95 -0
- package/src_old/utils.ts +64 -0
package/src_old/url.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { inject } from 'readuz'
|
|
2
|
+
import { DIReader } from './common'
|
|
3
|
+
import { getCxf, createSessionId, formatQueryString, getTokenAndLanguage } from './helpers'
|
|
4
|
+
import { validateForNull } from './utils'
|
|
5
|
+
import { criteriaSelector } from './store'
|
|
6
|
+
import { acronym } from '@goodgamestudios/game-alias'
|
|
7
|
+
|
|
8
|
+
export interface ICreateCatalogUrlProperties {
|
|
9
|
+
sid?: string
|
|
10
|
+
page?: string
|
|
11
|
+
route?: string
|
|
12
|
+
config?: Record<string, any>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type CreateIframeUrl = (properties: ICreateCatalogUrlProperties) => string
|
|
16
|
+
export const createIframeUrl: DIReader<CreateIframeUrl> = inject(
|
|
17
|
+
(environment) => environment.config,
|
|
18
|
+
(environment) => environment.log,
|
|
19
|
+
(environment) => environment.getStore,
|
|
20
|
+
(environment) => environment.getDomain,
|
|
21
|
+
(environment) => environment.ggsGetQueryParams,
|
|
22
|
+
(environment) => environment.ggsGetReferrerValue,
|
|
23
|
+
(environment) => environment.createCustomizationUrl,
|
|
24
|
+
(config, log, getStore, getDomain, ggsGetQueryParameters, ggsGetReferrerValue, getCustomizationUrl) =>
|
|
25
|
+
({ page, route, sid, config: igsConfig = {} }: ICreateCatalogUrlProperties) => {
|
|
26
|
+
const store = getStore()
|
|
27
|
+
|
|
28
|
+
const { token, zoneId, locale } = getTokenAndLanguage(store)
|
|
29
|
+
const parameters = {
|
|
30
|
+
token,
|
|
31
|
+
zoneId,
|
|
32
|
+
locale,
|
|
33
|
+
sid: sid || createSessionId(),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (Object.keys(igsConfig).length > 0) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
parameters.config = JSON.stringify(igsConfig)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
validateForNull(parameters)
|
|
42
|
+
|
|
43
|
+
const urlParameters = new URLSearchParams(ggsGetQueryParameters())
|
|
44
|
+
const queryParameters = {
|
|
45
|
+
...parameters,
|
|
46
|
+
'lemonstand.customization.url': store.resolvedCustomizationUrl || getCustomizationUrl(),
|
|
47
|
+
domain: getDomain(ggsGetReferrerValue()),
|
|
48
|
+
websiteId: urlParameters.get('w'),
|
|
49
|
+
criteria: JSON.stringify(criteriaSelector(store)),
|
|
50
|
+
level: store.level,
|
|
51
|
+
}
|
|
52
|
+
// <editor-fold desc="SPIL integration">
|
|
53
|
+
/* In case of SPIL integration the game can be launched
|
|
54
|
+
with additional params 'network=xx&usekeybaselogin=false'
|
|
55
|
+
in this case it needs to pass the network parameter to iframe url */
|
|
56
|
+
const network = urlParameters.get('network')
|
|
57
|
+
if (urlParameters.get('usekeybaselogin') === 'false' && Number(network) > 0) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
queryParameters.network = network
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (store.adStatus?.areBannersAvailable) {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
queryParameters.ads = true
|
|
65
|
+
}
|
|
66
|
+
// </editor-fold>
|
|
67
|
+
|
|
68
|
+
log('createIframeUrl params', queryParameters)
|
|
69
|
+
return `${config.BASE_URL}/?${formatQueryString(queryParameters)}${page ? `#${page}` : ''}${
|
|
70
|
+
route ? `--${route}--${Date.now()}` : ''
|
|
71
|
+
}`
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
export type CreateCustomizationUrl = () => string
|
|
76
|
+
export const createCustomizationUrl: DIReader<CreateCustomizationUrl> = inject(
|
|
77
|
+
(environment) => environment.config,
|
|
78
|
+
(environment) => environment.getStore,
|
|
79
|
+
(environment) => environment.cxfProvider,
|
|
80
|
+
(config, getStore, cxfProvider) => () => {
|
|
81
|
+
const store = getStore()
|
|
82
|
+
const configBase = acronym(store.gameId)
|
|
83
|
+
const configVariance = store.customizationSuffix ? `-${store.customizationSuffix}` : ''
|
|
84
|
+
const configBranch = `${configBase}${configVariance}`
|
|
85
|
+
const cxf = getCxf(cxfProvider)
|
|
86
|
+
|
|
87
|
+
if (cxf.env === 'test') {
|
|
88
|
+
const configVersion = new URLSearchParams(window.location.search).get('configGGS')
|
|
89
|
+
if (configVersion !== null) {
|
|
90
|
+
return config.CUSTOMIZATION_URL_TEMPLATE.replace('{0}', configBranch).replace('{1}', configVersion)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return config.CUSTOMIZATION_URL.replace('{0}', configBranch)
|
|
94
|
+
}
|
|
95
|
+
)
|
package/src_old/utils.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AnyVoidFn as AnyVoidFunction, IDictionary, PromiseFn as PromiseFunction } from './common'
|
|
2
|
+
import { ArgumentNullError } from './ArgumentNullError'
|
|
3
|
+
|
|
4
|
+
const startTimer = (function_: AnyVoidFunction, time: number) => {
|
|
5
|
+
const id = setTimeout(function_, time)
|
|
6
|
+
return () => clearTimeout(id)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const timeout =
|
|
10
|
+
<A, B>(function_: PromiseFunction<A, B>, time: number): PromiseFunction<A, B> =>
|
|
11
|
+
(a) => {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const stopTimer = startTimer(() => {
|
|
14
|
+
reject(new Error(`Timeout has exceeded ${time}`))
|
|
15
|
+
}, time)
|
|
16
|
+
|
|
17
|
+
function_(a)
|
|
18
|
+
.then((value) => {
|
|
19
|
+
resolve(value)
|
|
20
|
+
stopTimer()
|
|
21
|
+
})
|
|
22
|
+
.catch(reject)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const validateForNull = (properties: IDictionary<any>) => {
|
|
27
|
+
for (const key of Object.keys(properties)) {
|
|
28
|
+
const value = properties[key]
|
|
29
|
+
if (value === undefined || value === null || Number.isNaN(value)) {
|
|
30
|
+
throw new ArgumentNullError(key, value)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function msToSec(value: number): number {
|
|
36
|
+
return Math.floor(value / 1000)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function decodePayload<T>(data: string): T {
|
|
40
|
+
return JSON.parse(atob(data))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function diffHours(d1: Date, d2: Date): number {
|
|
44
|
+
const diff = (d1.getTime() - d2.getTime()) / 1000
|
|
45
|
+
return Math.abs(Math.round(diff / (60 * 60)))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function timestampToHours(value: number): number {
|
|
49
|
+
return Math.abs(Math.round(value / 1000 / (60 * 60)))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const parentDomain = (referrer: string) => {
|
|
53
|
+
const matches = referrer.match(/^https?:\/\/([^#/?]+)(?:[#/?]|$)/i)
|
|
54
|
+
if (!matches || !matches[1]) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const result = matches[1].match(/[^.]+\.[^.]+$/)
|
|
59
|
+
if (!result) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return result[0]
|
|
64
|
+
}
|