Add Spree as allowed Framework

This commit is contained in:
tniezg
2021-07-23 17:01:43 +02:00
parent a3ef27f5e7
commit c90fa7abf2
53 changed files with 912 additions and 166 deletions

View File

@@ -0,0 +1,43 @@
import type { NonUndefined, UnknownObjectValues } from '../types'
import MisconfigurationError from '../errors/MisconfigurationError'
import isServer from './isServer'
const generateMisconfigurationErrorMessage = (
keys: Array<string | number | symbol>
) => `${keys.join(', ')} must have values before running the Framework.`
const forceIsomorphicConfigValues = <
X extends keyof T,
T extends UnknownObjectValues,
H extends Record<X, NonUndefined<T[X]>>
>(
config: T,
requiredServerKeys: string[],
requiredPublicKeys: X[]
) => {
if (isServer) {
const missingServerConfigValues = requiredServerKeys.filter(
(requiredServerKey) => typeof config[requiredServerKey] === 'undefined'
)
if (missingServerConfigValues.length > 0) {
throw new MisconfigurationError(
generateMisconfigurationErrorMessage(missingServerConfigValues)
)
}
}
const missingPublicConfigValues = requiredPublicKeys.filter(
(requiredPublicKey) => typeof config[requiredPublicKey] === 'undefined'
)
if (missingPublicConfigValues.length > 0) {
throw new MisconfigurationError(
generateMisconfigurationErrorMessage(missingPublicConfigValues)
)
}
return config as T & H
}
export default forceIsomorphicConfigValues

View File

@@ -0,0 +1 @@
export default typeof window === 'undefined'

View File

@@ -0,0 +1,16 @@
import MissingConfigurationValueError from '../errors/MissingConfigurationValueError'
import type { NonUndefined, ValueOf } from '../types'
const requireConfig = <T>(isomorphicConfig: T, key: keyof T) => {
const valueUnderKey = isomorphicConfig[key]
if (typeof valueUnderKey === 'undefined') {
throw new MissingConfigurationValueError(
`Value for configuration key ${key} was undefined.`
)
}
return valueUnderKey as NonUndefined<ValueOf<T>>
}
export default requireConfig