@adobe/alloy 2.17.0-beta.0 → 2.18.0-beta.0
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/libEs5/components/ActivityCollector/configValidators.js +9 -5
- package/libEs5/components/ActivityCollector/utils.js +22 -3
- package/libEs5/components/Audiences/index.js +0 -1
- package/libEs5/components/Context/index.js +2 -2
- package/libEs5/components/DataCollector/index.js +1 -2
- package/libEs5/components/EventMerge/index.js +0 -1
- package/libEs5/components/Identity/configValidators.js +2 -2
- package/libEs5/components/Identity/getIdentity/createGetIdentity.js +8 -5
- package/libEs5/components/Identity/getIdentity/createIdentityRequest.js +5 -2
- package/libEs5/components/MachineLearning/index.js +0 -1
- package/libEs5/components/Personalization/index.js +2 -2
- package/libEs5/components/Privacy/createConsentRequest.js +5 -2
- package/libEs5/components/Privacy/injectSendSetConsentRequest.js +10 -6
- package/libEs5/constants/libraryVersion.js +1 -1
- package/libEs5/core/buildAndValidateConfig.js +79 -26
- package/libEs5/core/config/createCoreConfigs.js +3 -3
- package/libEs5/core/createEventManager.js +15 -6
- package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +3 -2
- package/libEs5/utils/request/createDataCollectionRequest.js +10 -6
- package/libEs5/utils/request/createRequest.js +5 -1
- package/libEs5/utils/request/createRequestParams.js +53 -0
- package/libEs5/utils/request/index.js +8 -0
- package/libEs5/utils/validation/booleanValidator.js +2 -2
- package/libEs5/utils/validation/callbackValidator.js +2 -2
- package/libEs5/utils/validation/createAnyOfValidator.js +8 -5
- package/libEs5/utils/validation/createArrayOfValidator.js +6 -4
- package/libEs5/utils/validation/createDeprecatedValidator.js +53 -0
- package/libEs5/utils/validation/createLiteralValidator.js +2 -2
- package/libEs5/utils/validation/createMapOfValuesValidator.js +6 -4
- package/libEs5/utils/validation/createMinimumValidator.js +2 -2
- package/libEs5/utils/validation/createNonEmptyValidator.js +3 -3
- package/libEs5/utils/validation/createObjectOfValidator.js +6 -4
- package/libEs5/utils/validation/createUniqueItemsValidator.js +2 -2
- package/libEs5/utils/validation/createUniqueValidator.js +2 -2
- package/libEs5/utils/validation/domainValidator.js +2 -2
- package/libEs5/utils/validation/index.js +54 -45
- package/libEs5/utils/validation/integerValidator.js +2 -2
- package/libEs5/utils/validation/numberValidator.js +2 -2
- package/libEs5/utils/validation/regexpValidator.js +2 -2
- package/libEs5/utils/validation/stringValidator.js +2 -2
- package/libEs5/utils/validation/utils.js +155 -0
- package/libEs6/components/ActivityCollector/configValidators.js +6 -5
- package/libEs6/components/ActivityCollector/utils.js +20 -3
- package/libEs6/components/Audiences/index.js +0 -1
- package/libEs6/components/Context/index.js +3 -3
- package/libEs6/components/DataCollector/index.js +1 -2
- package/libEs6/components/EventMerge/index.js +0 -1
- package/libEs6/components/Identity/configValidators.js +3 -3
- package/libEs6/components/Identity/getIdentity/createGetIdentity.js +7 -5
- package/libEs6/components/Identity/getIdentity/createIdentityRequest.js +6 -2
- package/libEs6/components/MachineLearning/index.js +0 -1
- package/libEs6/components/Personalization/index.js +3 -3
- package/libEs6/components/Privacy/createConsentRequest.js +6 -2
- package/libEs6/components/Privacy/injectSendSetConsentRequest.js +9 -6
- package/libEs6/constants/libraryVersion.js +1 -1
- package/libEs6/core/buildAndValidateConfig.js +48 -19
- package/libEs6/core/config/createCoreConfigs.js +4 -4
- package/libEs6/core/createEventManager.js +14 -6
- package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +3 -2
- package/libEs6/utils/request/createDataCollectionRequest.js +6 -2
- package/libEs6/utils/request/createRequest.js +6 -1
- package/libEs6/utils/request/createRequestParams.js +43 -0
- package/libEs6/utils/request/index.js +1 -0
- package/libEs6/utils/validation/booleanValidator.js +1 -1
- package/libEs6/utils/validation/callbackValidator.js +1 -1
- package/libEs6/utils/validation/createAnyOfValidator.js +5 -4
- package/libEs6/utils/validation/createArrayOfValidator.js +3 -3
- package/libEs6/utils/validation/createDeprecatedValidator.js +41 -0
- package/libEs6/utils/validation/createLiteralValidator.js +1 -1
- package/libEs6/utils/validation/createMapOfValuesValidator.js +3 -3
- package/libEs6/utils/validation/createMinimumValidator.js +1 -1
- package/libEs6/utils/validation/createNonEmptyValidator.js +1 -1
- package/libEs6/utils/validation/createObjectOfValidator.js +3 -3
- package/libEs6/utils/validation/createUniqueItemsValidator.js +1 -1
- package/libEs6/utils/validation/createUniqueValidator.js +1 -1
- package/libEs6/utils/validation/domainValidator.js +1 -1
- package/libEs6/utils/validation/index.js +84 -13
- package/libEs6/utils/validation/integerValidator.js +1 -1
- package/libEs6/utils/validation/numberValidator.js +1 -1
- package/libEs6/utils/validation/regexpValidator.js +1 -1
- package/libEs6/utils/validation/stringValidator.js +1 -1
- package/libEs6/utils/validation/utils.js +131 -0
- package/package.json +6 -4
- package/libEs5/utils/validation/assertValid.js +0 -22
- package/libEs5/utils/validation/chain.js +0 -76
- package/libEs5/utils/validation/nullSafeChain.js +0 -41
- package/libEs6/utils/validation/assertValid.js +0 -16
- package/libEs6/utils/validation/chain.js +0 -67
- package/libEs6/utils/validation/nullSafeChain.js +0 -32
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {{ datastreamId: string, [k: string]: Object }} Override
|
|
15
|
+
* @typedef {Object} RequestPayload
|
|
16
|
+
* @property {function(Override): void} mergeConfigOverride
|
|
17
|
+
* @param {Object} params
|
|
18
|
+
* @param {Override} params.localConfigOverrides
|
|
19
|
+
* @param {Override} params.globalConfigOverrides
|
|
20
|
+
* @param {RequestPayload} params.payload
|
|
21
|
+
* @returns {{ payload: RequestPayload, datastreamIdOverride: string }}
|
|
22
|
+
*/
|
|
23
|
+
export default (({
|
|
24
|
+
localConfigOverrides,
|
|
25
|
+
globalConfigOverrides,
|
|
26
|
+
payload
|
|
27
|
+
}) => {
|
|
28
|
+
const requestParams = {
|
|
29
|
+
payload
|
|
30
|
+
};
|
|
31
|
+
const {
|
|
32
|
+
datastreamId,
|
|
33
|
+
...localConfigOverridesWithoutDatastreamId
|
|
34
|
+
} = localConfigOverrides || {};
|
|
35
|
+
|
|
36
|
+
if (datastreamId) {
|
|
37
|
+
requestParams.datastreamIdOverride = datastreamId;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
payload.mergeConfigOverride(globalConfigOverrides);
|
|
41
|
+
payload.mergeConfigOverride(localConfigOverridesWithoutDatastreamId);
|
|
42
|
+
return requestParams;
|
|
43
|
+
});
|
|
@@ -14,5 +14,6 @@ export { default as createDataCollectionRequest } from "./createDataCollectionRe
|
|
|
14
14
|
export { default as createDataCollectionRequestPayload } from "./createDataCollectionRequestPayload";
|
|
15
15
|
export { default as createHasIdentity } from "./createHasIdentity";
|
|
16
16
|
export { default as createRequest } from "./createRequest";
|
|
17
|
+
export { default as createRequestParams } from "./createRequestParams";
|
|
17
18
|
export { default as createRequestPayload } from "./createRequestPayload";
|
|
18
19
|
export { default as createGetAssuranceValidationTokenParams } from "./createGetAssuranceValidationTokenParams";
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isBoolean from "../isBoolean";
|
|
13
|
-
import assertValid from "./
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isBoolean(value), value, path, "true or false");
|
|
16
16
|
return value;
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isFunction from "../isFunction";
|
|
13
|
-
import assertValid from "./
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isFunction(value), value, path, "a function");
|
|
16
16
|
return value;
|
|
@@ -9,17 +9,18 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
import find from "../find";
|
|
14
|
-
export default ((validators, message) => (value, path)
|
|
14
|
+
export default ((validators, message) => function anyOf(value, path) {
|
|
15
|
+
let newValue;
|
|
15
16
|
const valid = find(validators, validator => {
|
|
16
17
|
try {
|
|
17
|
-
validator(value, path);
|
|
18
|
+
newValue = validator.call(this, value, path);
|
|
18
19
|
return true;
|
|
19
20
|
} catch (e) {
|
|
20
21
|
return false;
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
assertValid(valid, value, path, message);
|
|
24
|
-
return
|
|
25
|
+
return newValue;
|
|
25
26
|
});
|
|
@@ -9,13 +9,13 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
13
|
-
export default (elementValidator => (value, path)
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
|
+
export default (elementValidator => function arrayOf(value, path) {
|
|
14
14
|
assertValid(Array.isArray(value), value, path, "an array");
|
|
15
15
|
const errors = [];
|
|
16
16
|
const validatedArray = value.map((subValue, i) => {
|
|
17
17
|
try {
|
|
18
|
-
return elementValidator(subValue, `${path}[${i}]
|
|
18
|
+
return elementValidator.call(this, subValue, `${path}[${i}]`, value);
|
|
19
19
|
} catch (e) {
|
|
20
20
|
errors.push(e.message);
|
|
21
21
|
return undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import isObject from "../isObject";
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
|
+
export default ((oldField, oldSchema, newField) => function deprecated(value, path) {
|
|
15
|
+
assertValid(isObject(value), value, path, "an object");
|
|
16
|
+
const {
|
|
17
|
+
[oldField]: oldValue,
|
|
18
|
+
[newField]: newValue,
|
|
19
|
+
...otherValues
|
|
20
|
+
} = value;
|
|
21
|
+
const validatedOldValue = oldSchema(oldValue, path);
|
|
22
|
+
|
|
23
|
+
if (validatedOldValue !== undefined) {
|
|
24
|
+
let message = `The field '${oldField}' is deprecated. Use '${newField}' instead.`;
|
|
25
|
+
|
|
26
|
+
if (path) {
|
|
27
|
+
message = `'${path}': ${message}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (newValue !== undefined && newValue !== validatedOldValue) {
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
} else if (this && this.logger) {
|
|
33
|
+
this.logger.warn(message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
[newField]: newValue || validatedOldValue,
|
|
39
|
+
...otherValues
|
|
40
|
+
};
|
|
41
|
+
});
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
export default (literalValue => (value, path) => {
|
|
14
14
|
assertValid(value === literalValue, value, path, `${literalValue}`);
|
|
15
15
|
return value;
|
|
@@ -10,8 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isObject from "../isObject";
|
|
13
|
-
import assertValid from "./
|
|
14
|
-
export default (valueValidator => (value, path)
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
|
+
export default (valueValidator => function mapOfValues(value, path) {
|
|
15
15
|
assertValid(isObject(value), value, path, "an object");
|
|
16
16
|
const errors = [];
|
|
17
17
|
const validatedObject = {};
|
|
@@ -20,7 +20,7 @@ export default (valueValidator => (value, path) => {
|
|
|
20
20
|
const subPath = path ? `${path}.${subKey}` : subKey;
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
const validatedValue = valueValidator(subValue, subPath);
|
|
23
|
+
const validatedValue = valueValidator.call(this, subValue, subPath);
|
|
24
24
|
|
|
25
25
|
if (validatedValue !== undefined) {
|
|
26
26
|
validatedObject[subKey] = validatedValue;
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
export default ((typeName, minimum) => (value, path) => {
|
|
14
14
|
assertValid(value >= minimum, value, path, `${typeName} greater than or equal to ${minimum}`);
|
|
15
15
|
return value;
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
import isObject from "../isObject";
|
|
14
14
|
import isEmptyObject from "../isEmptyObject";
|
|
15
15
|
export default (message => (value, path) => {
|
|
@@ -10,8 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isObject from "../isObject";
|
|
13
|
-
import assertValid from "./
|
|
14
|
-
export default (schema => (value, path)
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
|
+
export default (schema => function objectOf(value, path) {
|
|
15
15
|
assertValid(isObject(value), value, path, "an object");
|
|
16
16
|
const errors = [];
|
|
17
17
|
const validatedObject = {};
|
|
@@ -21,7 +21,7 @@ export default (schema => (value, path) => {
|
|
|
21
21
|
const subPath = path ? `${path}.${subKey}` : subKey;
|
|
22
22
|
|
|
23
23
|
try {
|
|
24
|
-
const validatedValue = subSchema(subValue, subPath);
|
|
24
|
+
const validatedValue = subSchema.call(this, subValue, subPath);
|
|
25
25
|
|
|
26
26
|
if (validatedValue !== undefined) {
|
|
27
27
|
validatedObject[subKey] = validatedValue;
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
import isUnique from "../isUnique";
|
|
14
14
|
export default (() => {
|
|
15
15
|
return (value, path) => {
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
export default (() => {
|
|
14
14
|
const values = [];
|
|
15
15
|
return (value, path) => {
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
const DOMAIN_REGEX = /^[a-z0-9.-]{1,}$/i;
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(DOMAIN_REGEX.test(value), value, path, "a valid domain");
|
|
@@ -9,13 +9,70 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validators are functions of two parameters (value and path) that return the
|
|
15
|
+
* computed value if the input is valid, or throw an exception if the input is
|
|
16
|
+
* invalid. In most cases the returned value is the same as the input value;
|
|
17
|
+
* however, reference createDefaultValidator.js to see an example where the
|
|
18
|
+
* computed value is different from the input. Additionally, if we ever wanted
|
|
19
|
+
* to coerce types (i.e. parse string values into integers) as part of the
|
|
20
|
+
* validation process we could use the computed value to accomplish that.
|
|
21
|
+
*
|
|
22
|
+
* The path parameter is used to generate informative error messages. It is
|
|
23
|
+
* created by the objectOf, and arrayOf validators so that any error message can
|
|
24
|
+
* describe which key within the object or array is invalid.
|
|
25
|
+
*
|
|
26
|
+
* The validators also have methods to chain additional validation logic. For
|
|
27
|
+
* example, when you call `string()` to start a validator chain, it returns a
|
|
28
|
+
* validator function but it also has methods like `required` and `nonEmpty`.
|
|
29
|
+
* Here you can see that these methods are actually calling `chain`.
|
|
30
|
+
* Specifically in this function, the leftValidator is called first and then the
|
|
31
|
+
* return value of that is sent to the rightValidator. For example, when calling
|
|
32
|
+
* `string().nonEmpty().required()` the following chain is built up:
|
|
33
|
+
* ```
|
|
34
|
+
* *
|
|
35
|
+
* / \
|
|
36
|
+
* * required
|
|
37
|
+
* / \
|
|
38
|
+
* * nonEmpty
|
|
39
|
+
* / \
|
|
40
|
+
* base string
|
|
41
|
+
* ```
|
|
42
|
+
* Where every * is a call to chain where the two are combined. The individual
|
|
43
|
+
* validators are called from left to right in the above tree. The base
|
|
44
|
+
* validator is simply the identity function `value => value`, representing an
|
|
45
|
+
* optional value.
|
|
46
|
+
*
|
|
47
|
+
* After combining the validators, the new validator function is then augmented
|
|
48
|
+
* with the methods from the leftValidator and from the additionalMethods
|
|
49
|
+
* parameter. For example, when the string() function is called it chains to the
|
|
50
|
+
* base validator, but also adds additional methods like (`regexp`, `domain`,
|
|
51
|
+
* `nonEmpty`, and `unique`). When `nonEmpty` is called, which calls chain
|
|
52
|
+
* again, the additional methods are carried forward because they are already
|
|
53
|
+
* defined on the leftValidator.
|
|
54
|
+
*
|
|
55
|
+
* The base validator also contains the two methods `required` and `default`, so
|
|
56
|
+
* these can be used anywhere after any of the exposed validator functions are
|
|
57
|
+
* called.
|
|
58
|
+
*
|
|
59
|
+
* For most validators, we want the validation to be optional (i.e. allow null
|
|
60
|
+
* or undefined values). To accomplish this, the validator needs to have a check
|
|
61
|
+
* at the begining of the function, short circuiting the validation logic and
|
|
62
|
+
* returning value if value is null or undefined. `default` and `required` do
|
|
63
|
+
* not want this null check though. Indeed, `default` should return the default
|
|
64
|
+
* value if value is null, and `required` should throw an error if value is
|
|
65
|
+
* null.
|
|
66
|
+
*
|
|
67
|
+
* So to keep from having to have a null check in front of most validators,
|
|
68
|
+
* nullSafeChain allows you to chain a validator in a null-safe way.
|
|
69
|
+
*/
|
|
70
|
+
import { chain, nullSafeChain, reverseNullSafeChainJoinErrors } from "./utils";
|
|
15
71
|
import booleanValidator from "./booleanValidator";
|
|
16
72
|
import callbackValidator from "./callbackValidator";
|
|
17
73
|
import createArrayOfValidator from "./createArrayOfValidator";
|
|
18
74
|
import createDefaultValidator from "./createDefaultValidator";
|
|
75
|
+
import createDeprecatedValidator from "./createDeprecatedValidator";
|
|
19
76
|
import createLiteralValidator from "./createLiteralValidator";
|
|
20
77
|
import createMapOfValuesValidator from "./createMapOfValuesValidator";
|
|
21
78
|
import createMinimumValidator from "./createMinimumValidator";
|
|
@@ -32,8 +89,9 @@ import regexpValidator from "./regexpValidator";
|
|
|
32
89
|
import requiredValidator from "./requiredValidator";
|
|
33
90
|
import stringValidator from "./stringValidator"; // The base validator does no validation and just returns the value unchanged
|
|
34
91
|
|
|
35
|
-
const base = value => value; // The 'default' and '
|
|
36
|
-
// Don't use the nullSafeChain
|
|
92
|
+
const base = value => value; // The 'default', 'required', and 'deprecated' methods are available after any
|
|
93
|
+
// data-type method. Don't use the nullSafeChain on 'default' or 'required'
|
|
94
|
+
// because they need to handle the null or undefined case
|
|
37
95
|
|
|
38
96
|
|
|
39
97
|
base.default = function _default(defaultValue) {
|
|
@@ -95,7 +153,7 @@ const anyOf = function anyOf(validators, message) {
|
|
|
95
153
|
};
|
|
96
154
|
|
|
97
155
|
const anything = function anything() {
|
|
98
|
-
return
|
|
156
|
+
return this;
|
|
99
157
|
};
|
|
100
158
|
|
|
101
159
|
const arrayOf = function arrayOf(elementValidator) {
|
|
@@ -131,15 +189,28 @@ const mapOfValues = function mapOfValues(valuesValidator) {
|
|
|
131
189
|
});
|
|
132
190
|
};
|
|
133
191
|
|
|
134
|
-
const
|
|
135
|
-
|
|
192
|
+
const createObjectOfAdditionalProperties = schema => ({
|
|
193
|
+
noUnknownFields: function noUnknownFields() {
|
|
136
194
|
return nullSafeChain(this, createNoUnknownFieldsValidator(schema));
|
|
137
|
-
}
|
|
195
|
+
},
|
|
196
|
+
nonEmpty: nonEmptyObject,
|
|
197
|
+
concat: function concat(otherObjectOfValidator) {
|
|
198
|
+
// combine the schema so that noUnknownFields, and concat have the combined schema
|
|
199
|
+
const newSchema = { ...schema,
|
|
200
|
+
...otherObjectOfValidator.schema
|
|
201
|
+
};
|
|
202
|
+
return nullSafeChain(this, otherObjectOfValidator, createObjectOfAdditionalProperties(newSchema));
|
|
203
|
+
},
|
|
204
|
+
deprecated: function deprecated(oldField, oldSchema, newField) {
|
|
205
|
+
// Run the deprecated validator first so that the deprecated field is removed
|
|
206
|
+
// before the objectOf validator runs.
|
|
207
|
+
return reverseNullSafeChainJoinErrors(this, createDeprecatedValidator(oldField, oldSchema, newField));
|
|
208
|
+
},
|
|
209
|
+
schema
|
|
210
|
+
});
|
|
138
211
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
nonEmpty: nonEmptyObject
|
|
142
|
-
});
|
|
212
|
+
const objectOf = function objectOf(schema) {
|
|
213
|
+
return nullSafeChain(this, createObjectOfValidator(schema), createObjectOfAdditionalProperties(schema));
|
|
143
214
|
};
|
|
144
215
|
|
|
145
216
|
const string = function string() {
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isInteger from "../isInteger";
|
|
13
|
-
import assertValid from "./
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isInteger(value), value, path, "an integer");
|
|
16
16
|
return value;
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isNumber from "../isNumber";
|
|
13
|
-
import assertValid from "./
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isNumber(value), value, path, "a number");
|
|
16
16
|
return value;
|
|
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import assertValid from "./
|
|
12
|
+
import { assertValid } from "./utils";
|
|
13
13
|
import isValidRegExp from "../isValidRegExp";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isValidRegExp(value), value, path, "a regular expression");
|
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import isString from "../isString";
|
|
13
|
-
import assertValid from "./
|
|
13
|
+
import { assertValid } from "./utils";
|
|
14
14
|
export default ((value, path) => {
|
|
15
15
|
assertValid(isString(value), value, path, "a string");
|
|
16
16
|
return value;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
// This is used to add methods onto a function.
|
|
13
|
+
import assign from "../assign";
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a validator returning the value if it is null or undefined, otherwise
|
|
16
|
+
* it will call the original validator and return the result.
|
|
17
|
+
*
|
|
18
|
+
* @param {function} validator - the validator to call if the value is not null
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const skipIfNull = validator => function skipIfNullValidator(value, path) {
|
|
22
|
+
return value == null ? value : validator.call(this, value, path);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns a new validator that calls the first validator and then calls the second
|
|
26
|
+
* validator with the result of the first validator. The result of the second validator
|
|
27
|
+
* is returned.
|
|
28
|
+
*
|
|
29
|
+
* @param {function} firstValidator - validator to call first
|
|
30
|
+
* @param {function} secondValidator - validator to call second
|
|
31
|
+
* @returns {function} - a new validator that calls the first and second validators
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const callSequentially = (firstValidator, secondValidator) => function callSequentiallyValidator(value, path) {
|
|
36
|
+
return secondValidator.call(this, firstValidator.call(this, value, path), path);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Just like callSequentially, but if either validator throws an error, the errors
|
|
40
|
+
* are collected and thrown at the end.
|
|
41
|
+
*
|
|
42
|
+
* @param {function} firstValidator
|
|
43
|
+
* @param {function} secondValidator
|
|
44
|
+
* @returns {function}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const callSequentiallyJoinErrors = (firstValidator, secondValidator) => function callSequentiallyJoinErrorsValidator(value, path) {
|
|
49
|
+
const errors = [];
|
|
50
|
+
const newValue = [firstValidator, secondValidator].reduce((memo, validator) => {
|
|
51
|
+
try {
|
|
52
|
+
return validator.call(this, memo, path);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
errors.push(e);
|
|
55
|
+
return memo;
|
|
56
|
+
}
|
|
57
|
+
}, value);
|
|
58
|
+
|
|
59
|
+
if (errors.length) {
|
|
60
|
+
throw new Error(errors.join("\n"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return newValue;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Chains two validators together. In addition to calling the validators in
|
|
67
|
+
* sequence, this will also copy over methods from the base validator to the
|
|
68
|
+
* resulting validator and include any additional methods.
|
|
69
|
+
*
|
|
70
|
+
* @param {function} baseValidator - This validator will be called first, and its
|
|
71
|
+
* methods will be copied over to the returned validator.
|
|
72
|
+
* @param {function} newValidator - This validator will be called second.
|
|
73
|
+
* @param {object} additionalMethods - Additional methods to include on the returned
|
|
74
|
+
* validator.
|
|
75
|
+
* @returns {function}
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export const chain = (baseValidator, newValidator, additionalMethods) => {
|
|
80
|
+
return assign(callSequentially(baseValidator, newValidator), baseValidator, additionalMethods);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Chains two validators together, but skips the second validator if the value
|
|
84
|
+
* is null. In addition to calling the validators in sequence, this will also
|
|
85
|
+
* copy over methods from the base validator to the resulting validator and
|
|
86
|
+
* include any additional methods.
|
|
87
|
+
*
|
|
88
|
+
* @param {function} baseValidator - This validator will be called first, and its
|
|
89
|
+
* methods will be copied over to the returned validator.
|
|
90
|
+
* @param {function} newValidator - This validator will be called second. If the value
|
|
91
|
+
* is null after the first validator is called, this validator will not be
|
|
92
|
+
* called.
|
|
93
|
+
* @param {object} additionalMethods - Additional methods to include on the returned
|
|
94
|
+
* validator.
|
|
95
|
+
* @returns {function}
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
export const nullSafeChain = (baseValidator, newValidator, additionalMethods) => {
|
|
99
|
+
return assign(callSequentially(baseValidator, skipIfNull(newValidator)), baseValidator, additionalMethods);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Same as nullSafeChain, but calls the new validator first.
|
|
103
|
+
*
|
|
104
|
+
* @param {function} baseValidator - This validator will be called second, and its
|
|
105
|
+
* methods will be copied over to the returned validator.
|
|
106
|
+
* @param {function} newValidator - This validator will be called first. If the value
|
|
107
|
+
* is null, this validator will not be called.
|
|
108
|
+
* @param {function} additionalMethods - Additional methods to include on the returned
|
|
109
|
+
* validator.
|
|
110
|
+
* @returns {function}
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
export const reverseNullSafeChainJoinErrors = (baseValidator, newValidator, additionalMethods) => {
|
|
114
|
+
return assign(callSequentiallyJoinErrors(skipIfNull(newValidator), baseValidator), baseValidator, additionalMethods);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Throws an error if the value is not valid.
|
|
118
|
+
*
|
|
119
|
+
* @param {boolean} isValid - Whether or not the value is valid.
|
|
120
|
+
* @param {*} value - The value to validate.
|
|
121
|
+
* @param {string} path - The path to the value.
|
|
122
|
+
* @param {string} message - The expected part of the error message.
|
|
123
|
+
* @throws {Error} - Throws an error if the value is not valid.
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
export const assertValid = (isValid, value, path, message) => {
|
|
128
|
+
if (!isValid) {
|
|
129
|
+
throw new Error(`'${path}': Expected ${message}, but got ${JSON.stringify(value)}.`);
|
|
130
|
+
}
|
|
131
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/alloy",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0-beta.0",
|
|
4
4
|
"description": "Adobe Experience Platform Web SDK",
|
|
5
5
|
"main": "libEs5/index.js",
|
|
6
6
|
"module": "libEs6/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"test:unit:saucelabs:local": "karma start karma.saucelabs.conf.js --single-run",
|
|
19
19
|
"test:unit:coverage": "karma start --single-run --reporters spec,coverage",
|
|
20
20
|
"test:functional": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe chrome",
|
|
21
|
+
"test:functional:saucelabs:dev": "NPM_PACKAGE_VERSION=\"2.17.0\" EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" saucectl run --config ./.sauce/dev.yml",
|
|
21
22
|
"test:functional:watch": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" ./scripts/watchFunctionalTests.js --browsers chrome",
|
|
22
23
|
"test:functional:debug": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe --inspect-brk chrome",
|
|
23
24
|
"test:functional:build:int": "rollup -c --environment BASE_CODE_MIN,STANDALONE,NPM_PACKAGE_LOCAL",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"uuid": "^3.3.2"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"@adobe/alloy": "^2.
|
|
69
|
+
"@adobe/alloy": "^2.17.0",
|
|
69
70
|
"@babel/cli": "^7.12.8",
|
|
70
71
|
"@babel/core": "^7.2.2",
|
|
71
72
|
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
|
|
@@ -121,9 +122,10 @@
|
|
|
121
122
|
"semver": "^7.3.7",
|
|
122
123
|
"staged-git-files": "^1.3.0",
|
|
123
124
|
"start-server-and-test": "^1.10.6",
|
|
124
|
-
"testcafe": "^2.
|
|
125
|
-
"testcafe-browser-provider-saucelabs": "^
|
|
125
|
+
"testcafe": "^2.6.2",
|
|
126
|
+
"testcafe-browser-provider-saucelabs": "^2.0.0",
|
|
126
127
|
"testcafe-reporter-junit": "^3.0.2",
|
|
128
|
+
"testcafe-reporter-saucelabs": "^1.0.1",
|
|
127
129
|
"url-exists-nodejs": "^0.1.0",
|
|
128
130
|
"url-parse": "^1.4.7",
|
|
129
131
|
"yargs": "^16.2.0"
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.default = void 0;
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Copyright 2020 Adobe. All rights reserved.
|
|
7
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
-
governing permissions and limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
var _default = function _default(isValid, value, path, message) {
|
|
17
|
-
if (!isValid) {
|
|
18
|
-
throw new Error("'" + path + "': Expected " + message + ", but got " + JSON.stringify(value) + ".");
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.default = _default;
|