in src/ccf/ccf-provider-common/constitution/actions.js [672:762]
function (args) {
const bundle = args.bundle;
checkType(bundle, "object", "bundle");
let prefix = "bundle.modules";
checkType(bundle.modules, "array", prefix);
for (const [i, module] of bundle.modules.entries()) {
checkType(module, "object", `${prefix}[${i}]`);
checkType(module.name, "string", `${prefix}[${i}].name`);
checkType(module.module, "string", `${prefix}[${i}].module`);
}
prefix = "bundle.metadata";
checkType(bundle.metadata, "object", prefix);
checkType(bundle.metadata.endpoints, "object", `${prefix}.endpoints`);
for (const [url, endpoint] of Object.entries(
bundle.metadata.endpoints
)) {
checkType(endpoint, "object", `${prefix}.endpoints["${url}"]`);
for (const [method, info] of Object.entries(endpoint)) {
const prefix2 = `${prefix}.endpoints["${url}"]["${method}"]`;
checkType(info, "object", prefix2);
checkType(info.js_module, "string", `${prefix2}.js_module`);
checkType(info.js_function, "string", `${prefix2}.js_function`);
checkEnum(
info.mode,
["readwrite", "readonly", "historical"],
`${prefix2}.mode`
);
checkEnum(
info.forwarding_required,
["sometimes", "always", "never"],
`${prefix2}.forwarding_required`
);
const redirection_strategy = info.redirection_strategy;
if (redirection_strategy !== undefined) {
checkEnum(
info.redirection_strategy,
["none", "to_primary", "to_backup"],
`${prefix2}.redirection_strategy`
);
}
checkType(info.openapi, "object?", `${prefix2}.openapi`);
checkType(
info.openapi_hidden,
"boolean?",
`${prefix2}.openapi_hidden`
);
checkType(
info.authn_policies,
"array",
`${prefix2}.authn_policies`
);
for (const [i, policy] of info.authn_policies.entries()) {
if (typeof policy === "string") {
// May still be an unrecognised value. That will only throw later
continue;
} else if (typeof policy === "object") {
const constituents = policy["all_of"];
checkType(
constituents,
"array",
`${prefix2}.authn_policies[${i}].all_of`
);
for (const [j, sub_policy] of constituents.entries()) {
checkType(
sub_policy,
"string",
`${prefix2}.authn_policies[${i}].all_of[${j}]`
);
}
} else {
throw new Error(
`${prefix2}.authn_policies[${i}] must be of type string or object but is ${typeof policy}`
);
}
}
if (!bundle.modules.some((m) => m.name === info.js_module)) {
throw new Error(`module '${info.js_module}' not found in bundle`);
}
}
}
checkType(
args.disable_bytecode_cache,
"boolean?",
"disable_bytecode_cache"
);
},