Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (config, extendConfigSchema) => {
// TODO: improve prompts and actions validation
const schema = {
description: struct.optional('string'),
prepare: struct.optional('function'),
prompts: struct.optional(struct.union(['array', 'function'])),
actions: struct.optional(struct.union(['array', 'function'])),
completed: struct.optional('function')
}
if (typeof extendConfigSchema === 'function') {
extendConfigSchema(schema, struct, superstruct)
}
const res = struct(schema)
const [error, result] = res.validate(config)
if (error) {
throw new KopyError(`Invalid Kopy config: ${error.message}`)
}
return result
}
slugify: 'string?',
options: 'object?',
headings: 'object?',
highlighter: 'string?',
lineNumbers: 'boolean?',
// Same as the type of Saber plugins
plugins
},
{
plugins: []
}
)
const themeConfig = struct.interface({}, {})
const permalinks = struct.union(['object', 'function'], {})
const server = struct(
{
host: 'string?',
port: 'number?'
},
{
host: '0.0.0.0',
port: 3000
}
)
const build = struct(
{
publicUrl: 'string?',
extractCSS: 'boolean?',
export function validateConfig(
config: SaberConfig,
{ dev }: { dev: boolean }
): ValidatedSaberConfig {
const siteConfig = struct.interface(
{
title: 'string?',
description: 'string?'
},
{}
)
// Type of Saber plugins
const plugins = struct.union(
[
['string'],
[
{
resolve: 'string',
options: 'object?'
}
]
],
[]
)
const markdown = struct(
{
slugify: 'string?',
options: 'object?',
import {sealed} from "./decorators";
import {struct} from "superstruct";
import {IGatewayBFFConfiguration, IStorefrontConfig} from "./types";
import {ERROR_CODES, PuzzleError} from "./errors";
import {HTTP_METHODS, INJECTABLE, RESOURCE_INJECT_TYPE} from "./enums";
import {RESOURCE_LOADING_TYPE, RESOURCE_TYPE} from "@puzzle-js/client-lib/dist/enums";
const httpsStructure = struct({
allowHTTP1: struct.optional('boolean'),
key: struct.optional(struct.union(['string', 'buffer'])),
cert: struct.optional(struct.union(['string', 'buffer']))
});
const serverOptionsStructure = struct({
port: struct.optional('number'),
hostname: struct.optional('string'),
http2: struct.optional('boolean'),
https: struct.optional(httpsStructure)
});
const apiEndpointsStructure = struct({
path: 'string',
middlewares: struct.optional(['string']),
method: struct.enum(Object.values(HTTP_METHODS)),
controller: 'string',
routeCache: 'number?',
cacheControl: 'string?'
url: 'string',
serverOptions: serverOptionsStructure,
fragments: [gatewayFragmentStructure],
api: [apiStructure],
isMobile: 'boolean?',
authToken: 'string?',
fragmentsFolder: 'string',
corsDomains: struct.optional(['string']),
corsMaxAge: 'number?',
customHeaders: struct.optional([customHeaderStructure])
});
const storefrontPageStructure = struct({
page: 'string?',
html: 'string',
url: struct.union(['string', ['string']]),
condition: 'function?'
});
const storefrontGatewaysStructure = struct({
name: 'string',
url: 'string',
assetUrl: 'string?'
});
const storefrontDependencyStructure = struct({
content: 'string?',
link: 'string?'
});
const storefrontStructure = struct({
gateways: [storefrontGatewaysStructure],
http2: struct.optional('boolean'),
https: struct.optional(httpsStructure)
});
const apiEndpointsStructure = struct({
path: 'string',
middlewares: struct.optional(['string']),
method: struct.enum(Object.values(HTTP_METHODS)),
controller: 'string',
routeCache: 'number?',
cacheControl: 'string?'
});
const customHeaderStructure = struct({
key: 'string',
value: struct.union(['string', 'number']),
isEnv: 'boolean?'
});
const apiVersionStructure = struct({
handler: 'string?',
endpoints: [apiEndpointsStructure]
});
const apiStructure = struct({
name: 'string',
testCookie: 'string',
liveVersion: 'string',
versions: struct.dict(['string', apiVersionStructure])
});
const gatewayRenderStructure = struct({
const Source = struct({
script: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
render: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
styles: struct.list([
{
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
modules: 'object?',
descriptor: struct.union(['object', 'null'])
}
]),
customBlocks: struct.list([
{
id: 'string?',
code: 'string?',
map: 'object?',
descriptor: struct.union(['object', 'null'])
}
])
})
return output
}
const Source = struct({
script: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
render: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
styles: struct.list([
{
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
modules: 'object?',
descriptor: struct.union(['object', 'null'])
}
]),
customBlocks: struct.list([
{
id: 'string?',
code: 'string?',
map: 'object?',
descriptor: struct.union(['object', 'null'])
output +=
`${name}.__inject__ = function (context) {\n` +
` ${STYLE_INJECTOR_IDENTIFIER}(${_s(config.shortFilePath)}, [[${_s(
config.shortFilePath
)}, ${_s(style.code)}, ${_s(style.descriptor.attrs.media)}, ${_s(
style.map
)}]], ${config.isProduction}, context)\n` +
`}\n`
return output
}
const Source = struct({
script: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
render: {
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
descriptor: struct.union(['object', 'null'])
},
styles: struct.list([
{
id: struct.union(['string?', 'null']),
code: struct.union(['string?', 'null']),
map: 'object?',
modules: 'object?',
descriptor: struct.union(['object', 'null'])