@sap-ux/project-input-validator 0.5.0 → 0.5.2

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.
@@ -23,4 +23,46 @@ export declare function hasCustomerPrefix(value: string): boolean;
23
23
  * @returns {boolean} True if the URI is valid, false if it is not.
24
24
  */
25
25
  export declare function isDataSourceURI(uri: string): boolean;
26
+ /**
27
+ * Validates that the project name is not empty and it is correct for VENDOR and CUSTOMER_BASE layer.
28
+ *
29
+ * @param {string} value - The project name.
30
+ * @param {string} destinationPath - The project directory.
31
+ * @param {boolean} isCustomerBase - Whether the layer is customer base.
32
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
33
+ */
34
+ export declare function validateProjectName(value: string, destinationPath: string, isCustomerBase: boolean): boolean | string;
35
+ /**
36
+ * Validates that project name is valid for CUSTOMER_BASE layer.
37
+ *
38
+ * @param {string} value - The project name.
39
+ * @param {string} destinationPath - The project directory.
40
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
41
+ */
42
+ export declare function validateProjectNameExternal(value: string, destinationPath: string): boolean | string;
43
+ /**
44
+ * Validates that project name is valid for VENDOR layer.
45
+ *
46
+ * @param {string} value - The project name.
47
+ * @param {string} destinationPath - The project directory.
48
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
49
+ */
50
+ export declare function validateProjectNameInternal(value: string, destinationPath: string): boolean | string;
51
+ /**
52
+ * Validates that project name is unique in directory.
53
+ *
54
+ * @param {string} value - The project name.
55
+ * @param {string} destinationPath - The project directory.
56
+ * @returns {string | boolean} If project with same name already exists return error message otherwise true.
57
+ */
58
+ export declare function validateDuplicateProjectName(value: string, destinationPath: string): boolean | string;
59
+ /**
60
+ * Validates that the project name is valid. Checks that it is not empty string and it is valid for CUSTOMER_BASE and VENDOR layers.
61
+ *
62
+ * @param {string} namespace - The project namespace.
63
+ * @param {string} projectName - The project name.
64
+ * @param {boolean} isCustomerBase - Whether the layer is customer base.
65
+ * @returns {string | boolean} If project namespace is valid returns true otherwise error message.
66
+ */
67
+ export declare function validateNamespaceAdp(namespace: string, projectName: string, isCustomerBase: boolean): string | boolean;
26
68
  //# sourceMappingURL=validators.d.ts.map
@@ -3,6 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasContentDuplication = hasContentDuplication;
4
4
  exports.hasCustomerPrefix = hasCustomerPrefix;
5
5
  exports.isDataSourceURI = isDataSourceURI;
6
+ exports.validateProjectName = validateProjectName;
7
+ exports.validateProjectNameExternal = validateProjectNameExternal;
8
+ exports.validateProjectNameInternal = validateProjectNameInternal;
9
+ exports.validateDuplicateProjectName = validateDuplicateProjectName;
10
+ exports.validateNamespaceAdp = validateNamespaceAdp;
11
+ const path_1 = require("path");
12
+ const fs_1 = require("fs");
13
+ const i18n_1 = require("../i18n");
14
+ const validators_1 = require("../general/validators");
6
15
  /**
7
16
  * Validates a value for duplication in existing change files.
8
17
  *
@@ -35,4 +44,108 @@ function hasCustomerPrefix(value) {
35
44
  function isDataSourceURI(uri) {
36
45
  return /^(?!.*\/\/)\/([^\s]*)\/$/.test(uri);
37
46
  }
47
+ const projectNamePattern = /^(\w\.\w|[a-zA-Z0-9]){1,61}$/;
48
+ /**
49
+ * Validates that the project name is not empty and it is correct for VENDOR and CUSTOMER_BASE layer.
50
+ *
51
+ * @param {string} value - The project name.
52
+ * @param {string} destinationPath - The project directory.
53
+ * @param {boolean} isCustomerBase - Whether the layer is customer base.
54
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
55
+ */
56
+ function validateProjectName(value, destinationPath, isCustomerBase) {
57
+ const validationResult = (0, validators_1.validateEmptyString)(value);
58
+ if (typeof validationResult === 'string') {
59
+ return validationResult;
60
+ }
61
+ if (/[A-Z]/.test(value)) {
62
+ return (0, i18n_1.t)('adp.projectNameUppercaseError');
63
+ }
64
+ if (!isCustomerBase) {
65
+ return validateProjectNameInternal(value, destinationPath);
66
+ }
67
+ else {
68
+ return validateProjectNameExternal(value, destinationPath);
69
+ }
70
+ }
71
+ /**
72
+ * Validates that project name is valid for CUSTOMER_BASE layer.
73
+ *
74
+ * @param {string} value - The project name.
75
+ * @param {string} destinationPath - The project directory.
76
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
77
+ */
78
+ function validateProjectNameExternal(value, destinationPath) {
79
+ if (value.length > 61 || value.toLocaleLowerCase().endsWith('component')) {
80
+ return (0, i18n_1.t)('adp.projectNameLengthErrorExt');
81
+ }
82
+ const projectNamePattern = /^(\w\.\w|[a-zA-Z0-9]){1,61}$/;
83
+ if (!projectNamePattern.test(value)) {
84
+ return (0, i18n_1.t)('adp.projectNameValidationErrorExt');
85
+ }
86
+ return validateDuplicateProjectName(value, destinationPath);
87
+ }
88
+ /**
89
+ * Validates that project name is valid for VENDOR layer.
90
+ *
91
+ * @param {string} value - The project name.
92
+ * @param {string} destinationPath - The project directory.
93
+ * @returns {string | boolean} If value is valid returns true otherwise error message.
94
+ */
95
+ function validateProjectNameInternal(value, destinationPath) {
96
+ if (value.toLowerCase().startsWith('customer') ||
97
+ value.length > 61 ||
98
+ value.toLocaleLowerCase().endsWith('component')) {
99
+ return (0, i18n_1.t)('adp.projectNameLengthErrorInt');
100
+ }
101
+ if (!projectNamePattern.test(value)) {
102
+ return (0, i18n_1.t)('adp.projectNameValidationErrorInt');
103
+ }
104
+ return validateDuplicateProjectName(value, destinationPath);
105
+ }
106
+ /**
107
+ * Validates that project name is unique in directory.
108
+ *
109
+ * @param {string} value - The project name.
110
+ * @param {string} destinationPath - The project directory.
111
+ * @returns {string | boolean} If project with same name already exists return error message otherwise true.
112
+ */
113
+ function validateDuplicateProjectName(value, destinationPath) {
114
+ if ((0, fs_1.existsSync)((0, path_1.join)(destinationPath, value))) {
115
+ return (0, i18n_1.t)('adp.duplicatedProjectName');
116
+ }
117
+ return true;
118
+ }
119
+ /**
120
+ * Validates that the project name is valid. Checks that it is not empty string and it is valid for CUSTOMER_BASE and VENDOR layers.
121
+ *
122
+ * @param {string} namespace - The project namespace.
123
+ * @param {string} projectName - The project name.
124
+ * @param {boolean} isCustomerBase - Whether the layer is customer base.
125
+ * @returns {string | boolean} If project namespace is valid returns true otherwise error message.
126
+ */
127
+ function validateNamespaceAdp(namespace, projectName, isCustomerBase) {
128
+ const validationResult = (0, validators_1.validateEmptyString)(namespace);
129
+ if (typeof validationResult === 'string') {
130
+ return validationResult;
131
+ }
132
+ if (!isCustomerBase) {
133
+ if (namespace !== projectName) {
134
+ return (0, i18n_1.t)('adp.differentNamespaceThanProjectName');
135
+ }
136
+ }
137
+ else if (namespace.toLowerCase().startsWith('customer.') !== true) {
138
+ return (0, i18n_1.t)('adp.namespaceSameAsProjectNameError');
139
+ }
140
+ else {
141
+ namespace = namespace.slice('customer.'.length, namespace.length);
142
+ }
143
+ if (namespace.length > 61 || namespace.toLowerCase().endsWith('component') === true) {
144
+ return (0, i18n_1.t)('adp.namespaceLengthError');
145
+ }
146
+ else if (namespace !== '' && projectNamePattern.test(namespace) === false) {
147
+ return (0, i18n_1.t)('adp.namespaceValidationError');
148
+ }
149
+ return true;
150
+ }
38
151
  //# sourceMappingURL=validators.js.map
@@ -54,5 +54,17 @@
54
54
  "invalidValueForSpecialChars": "Input must contain only Latin alphanumeric characters or the following symbols: '-','_','$' and '.'",
55
55
  "maxLength": "Maximum length: {{maxLength}} characters",
56
56
  "supportedFormats": "Only alphanumeric and '{{allowedCharacters}}' characters are allowed"
57
+ },
58
+ "adp": {
59
+ "projectNameUppercaseError": "The name cannot contain uppercase letters.",
60
+ "projectNameLengthErrorExt": "The name cannot contain more than 61 characters or end with the word 'component'.",
61
+ "projectNameValidationErrorExt": "The name must contain only latin alphanumeric characters. Different parts can be separated by a period and every part must start with a letter.",
62
+ "projectNameLengthErrorInt": "The name cannot start with the word 'customer', or contain more than 61 characters, or end with the word 'component'.",
63
+ "projectNameValidationErrorInt": "The name must contain only latin alphanumeric characters and it must have at least two parts. The different parts must be separated by a period and every part must start with a letter.",
64
+ "duplicatedProjectName": "A project with this name already exists in your workspace. Please choose another name.",
65
+ "differentNamespaceThanProjectName": "The namespace must be the same as the project name.",
66
+ "namespaceSameAsProjectNameError": "The namespace must be the same as the project name.",
67
+ "namespaceLengthError": "The namespace cannot contain more than 61 characters or end with the word 'component'.",
68
+ "namespaceValidationError": "The namespace must contain only latin alphanumeric characters. Different parts can be separated by a period and every part must start with a letter."
57
69
  }
58
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-input-validator",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Library to validate Fiori project input formats",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "i18next": "23.5.1",
18
18
  "validate-npm-package-name": "5.0.0",
19
- "@sap-ux/project-access": "1.29.18"
19
+ "@sap-ux/project-access": "1.29.19"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/validate-npm-package-name": "4.0.1",