oc 0.50.63 → 0.50.64
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/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-lint.log +2 -2
- package/.turbo/turbo-test-silent.log +12 -12
- package/.turbo/turbo-test.log +313 -145
- package/CHANGELOG.md +11 -0
- package/dist/components/oc-client/_package/package.json +4 -4
- package/dist/components/oc-client/_package/server.js +1 -1
- package/dist/components/oc-client/package-lock.json +5 -5
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/domain/repository.js +3 -3
- package/dist/registry/domain/storage-adapter.d.ts +1 -0
- package/dist/registry/domain/storage-adapter.js +9 -1
- package/dist/registry/router.js +3 -0
- package/dist/registry/routes/component-static.d.ts +3 -0
- package/dist/registry/routes/component-static.js +79 -0
- package/dist/registry/routes/helpers/component-parameter-processor.d.ts +22 -0
- package/dist/registry/routes/helpers/component-parameter-processor.js +228 -0
- package/dist/registry/routes/helpers/get-component.d.ts +1 -0
- package/dist/registry/routes/helpers/get-component.js +100 -47
- package/package.json +4 -4
- package/dist/registry/routes/helpers/get-component-retrieving-info.d.ts +0 -19
- package/dist/registry/routes/helpers/get-component-retrieving-info.js +0 -24
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-client",
|
|
3
3
|
"description": "The OpenComponents client-side javascript client",
|
|
4
|
-
"version": "0.50.
|
|
4
|
+
"version": "0.50.64",
|
|
5
5
|
"repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
|
|
6
6
|
"author": "Matteo Figus <matteofigus@gmail.com>",
|
|
7
7
|
"oc": {
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dataProvider": {
|
|
25
25
|
"type": "node.js",
|
|
26
|
-
"hashKey": "
|
|
26
|
+
"hashKey": "28a1d089593e21c02409631c4224cea4f72a23f2",
|
|
27
27
|
"src": "server.js",
|
|
28
28
|
"size": 644
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
"version": "0.50.
|
|
31
|
+
"version": "0.50.64",
|
|
32
32
|
"packaged": true,
|
|
33
|
-
"date":
|
|
33
|
+
"date": 1789052430262
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"oc-template-es6-compiler": "^8.0.0"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},r=(t,s)=>{o(t,(e,a,i={})=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},r=(t,s)=>{o(t,(e,a,i={})=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.64"}),c=t.staticPath.indexOf("http")===0?t.staticPath:"https:"+t.staticPath;return s(null,Object.assign({},{component:{key:"c4abb6bf4dc6657fb718a45b64bd6b2cb92e874a",src:c+"template.js",props:n,esm:!1,development:void 0}}))})};exports.data=r;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-client",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.63",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "oc-client",
|
|
9
|
-
"version": "0.50.
|
|
9
|
+
"version": "0.50.63",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"oc-template-es6-compiler": "^8.0.0"
|
|
12
12
|
}
|
|
@@ -2501,9 +2501,9 @@
|
|
|
2501
2501
|
}
|
|
2502
2502
|
},
|
|
2503
2503
|
"node_modules/brace-expansion": {
|
|
2504
|
-
"version": "1.1.
|
|
2505
|
-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.
|
|
2506
|
-
"integrity": "sha512-
|
|
2504
|
+
"version": "1.1.18",
|
|
2505
|
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz",
|
|
2506
|
+
"integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==",
|
|
2507
2507
|
"dev": true,
|
|
2508
2508
|
"license": "MIT",
|
|
2509
2509
|
"dependencies": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-client",
|
|
3
3
|
"description": "The OpenComponents client-side javascript client",
|
|
4
|
-
"version": "0.50.
|
|
4
|
+
"version": "0.50.64",
|
|
5
5
|
"repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
|
|
6
6
|
"author": "Matteo Figus <matteofigus@gmail.com>",
|
|
7
7
|
"oc": {
|
|
@@ -53,7 +53,7 @@ const metadata_adapter_options_1 = __importDefault(require("./metadata-adapter-o
|
|
|
53
53
|
const metadata_index_1 = require("./metadata-index");
|
|
54
54
|
const metadata_migration_1 = require("./metadata-migration");
|
|
55
55
|
const register_templates_1 = __importDefault(require("./register-templates"));
|
|
56
|
-
const storage_adapter_1 =
|
|
56
|
+
const storage_adapter_1 = __importStar(require("./storage-adapter"));
|
|
57
57
|
const validator = __importStar(require("./validators"));
|
|
58
58
|
const versionHandler = __importStar(require("./version-handler"));
|
|
59
59
|
const packageInfo = fs_extra_1.default.readJsonSync(node_path_1.default.join(__dirname, '..', '..', '..', 'package.json'));
|
|
@@ -421,7 +421,7 @@ function repository(conf) {
|
|
|
421
421
|
throw err;
|
|
422
422
|
});
|
|
423
423
|
try {
|
|
424
|
-
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}
|
|
424
|
+
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`, storage_adapter_1.isPrivateComponentFile);
|
|
425
425
|
await metadataStore.commitVersion(componentName, componentVersion, token);
|
|
426
426
|
invalidateComponentInfo(componentName, componentVersion);
|
|
427
427
|
metadataIndex.add(componentRow);
|
|
@@ -434,7 +434,7 @@ function repository(conf) {
|
|
|
434
434
|
}
|
|
435
435
|
return;
|
|
436
436
|
}
|
|
437
|
-
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}
|
|
437
|
+
await cdn.putDir(pkgDetails.outputFolder, `${options.componentsDir}/${componentName}/${componentVersion}`, storage_adapter_1.isPrivateComponentFile);
|
|
438
438
|
invalidateComponentInfo(componentName, componentVersion);
|
|
439
439
|
void componentsCache
|
|
440
440
|
.refresh()
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPrivateComponentFile = isPrivateComponentFile;
|
|
3
4
|
exports.default = getPromiseBasedAdapter;
|
|
4
5
|
const universalify_1 = require("universalify");
|
|
6
|
+
const privateComponentFilePatterns = [/(\\|\/)server\.js/, /(\\|\/)\..+/];
|
|
7
|
+
function isPrivateComponentFile(filePath) {
|
|
8
|
+
return privateComponentFilePatterns.some((pattern) => pattern.test(filePath));
|
|
9
|
+
}
|
|
5
10
|
const officialAdapters = {
|
|
6
11
|
s3: { name: 'oc-s3-storage-adapter', firstPromiseBasedVersion: '1.2.0' },
|
|
7
12
|
gs: { name: 'oc-gs-storage-adapter', firstPromiseBasedVersion: '1.1.0' },
|
|
@@ -28,11 +33,14 @@ function isLegacyAdapter(adapter) {
|
|
|
28
33
|
return !isPromiseBased(() => adapter.getFile(''));
|
|
29
34
|
}
|
|
30
35
|
function convertLegacyAdapter(adapter) {
|
|
36
|
+
const putDir = (0, universalify_1.fromCallback)(adapter.putDir);
|
|
31
37
|
return {
|
|
32
38
|
getFile: (0, universalify_1.fromCallback)(adapter.getFile),
|
|
33
39
|
getJson: (0, universalify_1.fromCallback)(adapter.getJson),
|
|
34
40
|
listSubDirectories: (0, universalify_1.fromCallback)(adapter.listSubDirectories),
|
|
35
|
-
|
|
41
|
+
// Legacy callback adapters use their third argument for the callback and
|
|
42
|
+
// already own their directory privacy behaviour.
|
|
43
|
+
putDir: (folderPath, filePath) => putDir(folderPath, filePath),
|
|
36
44
|
putFile: (0, universalify_1.fromCallback)(adapter.putFile),
|
|
37
45
|
putFileContent: (0, universalify_1.fromCallback)(adapter.putFileContent),
|
|
38
46
|
getUrl: adapter.getUrl,
|
package/dist/registry/router.js
CHANGED
|
@@ -9,6 +9,7 @@ const routes_1 = __importDefault(require("./routes"));
|
|
|
9
9
|
const component_1 = __importDefault(require("./routes/component"));
|
|
10
10
|
const component_info_1 = __importDefault(require("./routes/component-info"));
|
|
11
11
|
const component_preview_1 = __importDefault(require("./routes/component-preview"));
|
|
12
|
+
const component_static_1 = __importDefault(require("./routes/component-static"));
|
|
12
13
|
const components_1 = __importDefault(require("./routes/components"));
|
|
13
14
|
const dependencies_1 = __importDefault(require("./routes/dependencies"));
|
|
14
15
|
const get_component_1 = __importDefault(require("./routes/helpers/get-component"));
|
|
@@ -25,6 +26,7 @@ function create(adapter, conf, repository) {
|
|
|
25
26
|
components: (0, components_1.default)(conf, repository, renderComponent),
|
|
26
27
|
componentInfo: (0, component_info_1.default)(conf, repository),
|
|
27
28
|
componentPreview: (0, component_preview_1.default)(conf, repository),
|
|
29
|
+
componentStatic: (0, component_static_1.default)(repository),
|
|
28
30
|
index: (0, routes_1.default)(repository),
|
|
29
31
|
publish: (0, publish_1.default)(repository),
|
|
30
32
|
staticRedirector: {
|
|
@@ -57,6 +59,7 @@ function create(adapter, conf, repository) {
|
|
|
57
59
|
route('get', `${prefix}:componentName/:componentVersion/${settings_1.default.registry.localStaticRedirectorPath}*splat`, 'local-static', routes.staticRedirector.localStatic);
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
62
|
+
route('get', `${prefix}:componentName/:componentVersion/${settings_1.default.registry.localStaticRedirectorPath}*splat`, 'component-static', routes.componentStatic);
|
|
60
63
|
route('put', `${prefix}:componentName/:componentVersion`, 'publish', adapter.fromConnect(conf.beforePublish), routes.publish);
|
|
61
64
|
}
|
|
62
65
|
route('get', prefix, 'index', routes.index);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.default = componentStatic;
|
|
37
|
+
const storage_adapter_1 = require("../domain/storage-adapter");
|
|
38
|
+
const versionHandler = __importStar(require("../domain/version-handler"));
|
|
39
|
+
function componentStatic(repository) {
|
|
40
|
+
return async (req, res) => {
|
|
41
|
+
const componentName = req.params['componentName'];
|
|
42
|
+
const requestedVersion = req.params['componentVersion'];
|
|
43
|
+
const filePath = req.params['splat'] ?? '';
|
|
44
|
+
if (!filePath ||
|
|
45
|
+
filePath.includes('\\') ||
|
|
46
|
+
filePath.split('/').includes('..')) {
|
|
47
|
+
res.status(404).json({ err: 'File not found' });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if ((0, storage_adapter_1.isPrivateComponentFile)(`/${filePath}`)) {
|
|
51
|
+
res.status(404).json({ err: 'File not found' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let versions;
|
|
55
|
+
try {
|
|
56
|
+
versions = await repository.getComponentVersions(componentName);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
res.status(404).json({
|
|
60
|
+
err: `Component "${componentName}" not found`
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!versions || versions.length === 0) {
|
|
65
|
+
res.status(404).json({
|
|
66
|
+
err: `Component "${componentName}" not found`
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const resolvedVersion = versionHandler.getAvailableVersion(requestedVersion, versions);
|
|
71
|
+
if (!resolvedVersion) {
|
|
72
|
+
res.status(404).json({
|
|
73
|
+
err: `Component "${componentName}" with version "${requestedVersion}" not found`
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
res.redirect(repository.getStaticFilePath(componentName, resolvedVersion, filePath));
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OcParameter } from '../../../types';
|
|
2
|
+
export interface ValidationResult {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
errors: {
|
|
5
|
+
mandatory: Record<string, string>;
|
|
6
|
+
types: Record<string, string>;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface CompiledParameterSchema {
|
|
11
|
+
isEmpty: boolean;
|
|
12
|
+
defaults: Array<[string, string | number | boolean]>;
|
|
13
|
+
mandatory: string[];
|
|
14
|
+
types: Record<string, string>;
|
|
15
|
+
coercions: Record<string, 'boolean' | 'number' | 'string'>;
|
|
16
|
+
enums: Record<string, ReadonlyArray<string | number | boolean>>;
|
|
17
|
+
}
|
|
18
|
+
export declare function compileParameterSchema(expectedParameters?: Record<string, OcParameter> | null): CompiledParameterSchema;
|
|
19
|
+
export declare function processParameters(requestParameters: Record<string, string | number | boolean> | null | undefined, compiled: CompiledParameterSchema): {
|
|
20
|
+
params: Record<string, string | number | boolean>;
|
|
21
|
+
validation: ValidationResult;
|
|
22
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compileParameterSchema = compileParameterSchema;
|
|
7
|
+
exports.processParameters = processParameters;
|
|
8
|
+
const resources_1 = __importDefault(require("../../../resources"));
|
|
9
|
+
const emptyCompiledSchema = {
|
|
10
|
+
isEmpty: true,
|
|
11
|
+
defaults: [],
|
|
12
|
+
mandatory: [],
|
|
13
|
+
types: Object.create(null),
|
|
14
|
+
coercions: Object.create(null),
|
|
15
|
+
enums: Object.create(null)
|
|
16
|
+
};
|
|
17
|
+
function compileParameterSchema(expectedParameters) {
|
|
18
|
+
if (!expectedParameters ||
|
|
19
|
+
typeof expectedParameters !== 'object' ||
|
|
20
|
+
Array.isArray(expectedParameters)) {
|
|
21
|
+
return emptyCompiledSchema;
|
|
22
|
+
}
|
|
23
|
+
const keys = Object.keys(expectedParameters);
|
|
24
|
+
if (keys.length === 0) {
|
|
25
|
+
return emptyCompiledSchema;
|
|
26
|
+
}
|
|
27
|
+
const defaults = [];
|
|
28
|
+
const mandatory = [];
|
|
29
|
+
const types = Object.create(null);
|
|
30
|
+
const coercions = Object.create(null);
|
|
31
|
+
const enums = Object.create(null);
|
|
32
|
+
for (const name in expectedParameters) {
|
|
33
|
+
if (!Object.hasOwn(expectedParameters, name)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const param = expectedParameters[name];
|
|
37
|
+
if (!param || typeof param !== 'object') {
|
|
38
|
+
throw new TypeError(`Invalid parameter schema for "${name}"`);
|
|
39
|
+
}
|
|
40
|
+
const rawType = param.type;
|
|
41
|
+
const normalizedType = typeof rawType === 'string' ? rawType.toLowerCase() : '';
|
|
42
|
+
types[name] = normalizedType;
|
|
43
|
+
if (rawType === 'boolean' || rawType === 'number' || rawType === 'string') {
|
|
44
|
+
coercions[name] = rawType;
|
|
45
|
+
}
|
|
46
|
+
const enumValues = param.enum;
|
|
47
|
+
if (typeof enumValues !== 'undefined') {
|
|
48
|
+
enums[name] = enumValues;
|
|
49
|
+
}
|
|
50
|
+
if (param.mandatory) {
|
|
51
|
+
mandatory.push(name);
|
|
52
|
+
}
|
|
53
|
+
else if (typeof param.default !== 'undefined') {
|
|
54
|
+
defaults.push([name, param.default]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
isEmpty: false,
|
|
59
|
+
defaults,
|
|
60
|
+
mandatory,
|
|
61
|
+
types,
|
|
62
|
+
coercions,
|
|
63
|
+
enums
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function processParameters(requestParameters, compiled) {
|
|
67
|
+
if (compiled.isEmpty) {
|
|
68
|
+
const source = requestParameters;
|
|
69
|
+
if (!source || typeof source !== 'object') {
|
|
70
|
+
return {
|
|
71
|
+
params: {},
|
|
72
|
+
validation: {
|
|
73
|
+
isValid: true,
|
|
74
|
+
errors: { mandatory: {}, types: {}, message: '' }
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const params = {};
|
|
79
|
+
for (const key in source) {
|
|
80
|
+
if (!Object.hasOwn(source, key)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (key === '__ocAcceptLanguage') {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
params[key] = source[key];
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
params,
|
|
90
|
+
validation: {
|
|
91
|
+
isValid: true,
|
|
92
|
+
errors: { mandatory: {}, types: {}, message: '' }
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
let source;
|
|
97
|
+
if (requestParameters == null || typeof requestParameters !== 'object') {
|
|
98
|
+
source = {};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
source = requestParameters;
|
|
102
|
+
}
|
|
103
|
+
const defaults = compiled.defaults;
|
|
104
|
+
for (let i = 0; i < defaults.length; i++) {
|
|
105
|
+
const entry = defaults[i];
|
|
106
|
+
const key = entry[0];
|
|
107
|
+
const defVal = entry[1];
|
|
108
|
+
const cur = source[key];
|
|
109
|
+
if (cur === null || cur === undefined) {
|
|
110
|
+
source[key] = defVal;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const params = {};
|
|
114
|
+
let mandatoryErrors = null;
|
|
115
|
+
let typeErrors = null;
|
|
116
|
+
let isValid = true;
|
|
117
|
+
const types = compiled.types;
|
|
118
|
+
const coercions = compiled.coercions;
|
|
119
|
+
const enums = compiled.enums;
|
|
120
|
+
for (const key in source) {
|
|
121
|
+
if (!Object.hasOwn(source, key)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const isDeclared = Object.hasOwn(types, key);
|
|
125
|
+
if (isDeclared) {
|
|
126
|
+
const rawVal = source[key];
|
|
127
|
+
const type = types[key];
|
|
128
|
+
const coercion = coercions[key];
|
|
129
|
+
let sanitised;
|
|
130
|
+
if (coercion === 'boolean') {
|
|
131
|
+
if (typeof rawVal === 'string') {
|
|
132
|
+
if (rawVal === 'true') {
|
|
133
|
+
sanitised = true;
|
|
134
|
+
}
|
|
135
|
+
else if (rawVal === 'false') {
|
|
136
|
+
sanitised = false;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
sanitised = rawVal;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
sanitised = rawVal;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (coercion === 'number') {
|
|
147
|
+
sanitised = Number(rawVal);
|
|
148
|
+
}
|
|
149
|
+
else if (coercion === 'string') {
|
|
150
|
+
sanitised = rawVal == null ? '' : rawVal;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
sanitised = rawVal;
|
|
154
|
+
}
|
|
155
|
+
params[key] = sanitised;
|
|
156
|
+
let typeValid;
|
|
157
|
+
if (type === 'boolean') {
|
|
158
|
+
typeValid = typeof sanitised === 'boolean';
|
|
159
|
+
}
|
|
160
|
+
else if (type === 'number') {
|
|
161
|
+
typeValid = typeof sanitised === 'number';
|
|
162
|
+
}
|
|
163
|
+
else if (type === 'string') {
|
|
164
|
+
typeValid = typeof sanitised === 'string';
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
typeValid = false;
|
|
168
|
+
}
|
|
169
|
+
if (!typeValid) {
|
|
170
|
+
isValid = false;
|
|
171
|
+
if (!typeErrors) {
|
|
172
|
+
typeErrors = {};
|
|
173
|
+
}
|
|
174
|
+
typeErrors[key] = resources_1.default.errors.registry.PARAMETER_WRONG_FORMAT_CODE;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const enumVals = enums[key];
|
|
178
|
+
if (enumVals && !enumVals.includes(sanitised)) {
|
|
179
|
+
isValid = false;
|
|
180
|
+
if (!typeErrors) {
|
|
181
|
+
typeErrors = {};
|
|
182
|
+
}
|
|
183
|
+
typeErrors[key] = resources_1.default.errors.registry.PARAMETER_WRONG_VALUE(key, enumVals);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if (key === '__ocAcceptLanguage') {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
params[key] = source[key];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const mandatory = compiled.mandatory;
|
|
194
|
+
for (let i = 0; i < mandatory.length; i++) {
|
|
195
|
+
const name = mandatory[i];
|
|
196
|
+
if (!(name in params)) {
|
|
197
|
+
isValid = false;
|
|
198
|
+
if (!mandatoryErrors) {
|
|
199
|
+
mandatoryErrors = {};
|
|
200
|
+
}
|
|
201
|
+
mandatoryErrors[name] =
|
|
202
|
+
resources_1.default.errors.registry.MANDATORY_PARAMETER_MISSING_CODE;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let message = '';
|
|
206
|
+
if (mandatoryErrors) {
|
|
207
|
+
const keys = Object.keys(mandatoryErrors);
|
|
208
|
+
const joined = keys.join(', ');
|
|
209
|
+
message += resources_1.default.errors.registry.MANDATORY_PARAMETER_MISSING(joined);
|
|
210
|
+
}
|
|
211
|
+
if (typeErrors) {
|
|
212
|
+
if (message.length > 0) {
|
|
213
|
+
message += '; ';
|
|
214
|
+
}
|
|
215
|
+
const keys = Object.keys(typeErrors);
|
|
216
|
+
const joined = keys.join(', ');
|
|
217
|
+
message += resources_1.default.errors.registry.PARAMETER_WRONG_FORMAT(joined);
|
|
218
|
+
}
|
|
219
|
+
const validation = {
|
|
220
|
+
isValid,
|
|
221
|
+
errors: {
|
|
222
|
+
mandatory: mandatoryErrors || {},
|
|
223
|
+
types: typeErrors || {},
|
|
224
|
+
message
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
return { params, validation };
|
|
228
|
+
}
|