@todesktop/shared 7.76.0 → 7.77.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.
@@ -1,5 +1,6 @@
1
1
  import * as yup from "yup";
2
2
  export declare const appTitleValidation: yup.StringSchema;
3
+ export declare const forceVersionValidation: yup.StringSchema;
3
4
  export declare const iconValidation: yup.StringSchema;
4
5
  export declare const urlValidation: yup.StringSchema;
5
6
  export declare const urlValidationForm: yup.ObjectSchema<yup.Shape<object, {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const yup = require("yup");
4
+ const semver = require("semver");
4
5
  const isRegex = require("is-regex");
5
6
  exports.appTitleValidation = yup
6
7
  .string()
@@ -9,6 +10,29 @@ exports.appTitleValidation = yup
9
10
  .matches(/^[\w\-\s]+$/, "App title may contain letters, numbers, spaces and dashes only")
10
11
  .matches(/^[^\s]+(\s+[^\s]+)*$/, "App title may not begin or end with space")
11
12
  .required();
13
+ function isNumeric(str) {
14
+ if (typeof str != "string")
15
+ return false;
16
+ return !isNaN(str) && !isNaN(parseFloat(str));
17
+ }
18
+ function isNumericSemver(value) {
19
+ // check if valid semver
20
+ if (!semver.valid(value))
21
+ return false;
22
+ // ensure that all values are numbers
23
+ if (!value.split(".").every((num) => isNumeric(num)))
24
+ return false;
25
+ return true;
26
+ }
27
+ exports.forceVersionValidation = yup
28
+ .string()
29
+ .label("App version")
30
+ .min(5)
31
+ .required()
32
+ .when("$currentVersion", (currentVersion, schema) => schema.test("semantic-version", "Specified app version must follow a numeric SemVer versioning scheme (e.g. 1.0.0)", (forceVersion) => {
33
+ return (isNumericSemver(forceVersion) &&
34
+ semver.gt(forceVersion, currentVersion));
35
+ }));
12
36
  exports.iconValidation = yup
13
37
  .string()
14
38
  .label("Icon")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todesktop/shared",
3
- "version": "7.76.0",
3
+ "version": "7.77.0",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,9 +19,11 @@
19
19
  "@types/node": "^16.4.12",
20
20
  "@types/yup": "^0.26.9",
21
21
  "is-regex": "^1.0.4",
22
+ "semver": "^7.3.5",
22
23
  "yup": "^0.26.10"
23
24
  },
24
25
  "devDependencies": {
26
+ "@types/semver": "^7.3.9",
25
27
  "app-builder-lib": "^22.10.4",
26
28
  "tslint": "^5.12.1",
27
29
  "tslint-config-prettier": "1.18.0",
@@ -1,4 +1,5 @@
1
1
  import * as yup from "yup";
2
+ import * as semver from "semver";
2
3
  import * as isRegex from "is-regex";
3
4
  export const appTitleValidation = yup
4
5
  .string()
@@ -11,6 +12,39 @@ export const appTitleValidation = yup
11
12
  .matches(/^[^\s]+(\s+[^\s]+)*$/, "App title may not begin or end with space")
12
13
  .required();
13
14
 
15
+ function isNumeric(str: string) {
16
+ if (typeof str != "string") return false;
17
+ return !isNaN(str as any) && !isNaN(parseFloat(str));
18
+ }
19
+
20
+ function isNumericSemver(value: string) {
21
+ // check if valid semver
22
+ if (!semver.valid(value)) return false;
23
+
24
+ // ensure that all values are numbers
25
+ if (!value.split(".").every((num) => isNumeric(num))) return false;
26
+
27
+ return true;
28
+ }
29
+
30
+ export const forceVersionValidation = yup
31
+ .string()
32
+ .label("App version")
33
+ .min(5)
34
+ .required()
35
+ .when("$currentVersion", (currentVersion, schema) =>
36
+ schema.test(
37
+ "semantic-version",
38
+ "Specified app version must follow a numeric SemVer versioning scheme (e.g. 1.0.0)",
39
+ (forceVersion: string) => {
40
+ return (
41
+ isNumericSemver(forceVersion) &&
42
+ semver.gt(forceVersion, currentVersion)
43
+ );
44
+ }
45
+ )
46
+ );
47
+
14
48
  export const iconValidation = yup
15
49
  .string()
16
50
  .label("Icon")