@forwardslashns/taskit-validation-messages 1.3.0 → 1.3.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.
package/README.md CHANGED
@@ -6,9 +6,51 @@ This package provides a centralized list of validation messages used across both
6
6
 
7
7
  - **Centralized validation messages** across all features
8
8
  - **Type-safe** message retrieval with TypeScript
9
+ - **Feature name constants** to eliminate magic strings (v1.3.0+)
10
+ - **Message key constants** to eliminate magic strings for error aliases (v1.3.1+)
9
11
  - **Dynamic parameter substitution** for contextual messages
10
12
  - **Affected fields tracking** for better frontend UX (v1.1.0+)
11
13
 
14
+ # VALIDATION_FEATURES (v1.3.0+)
15
+
16
+ To avoid using magic strings and improve type safety, the package now exports `VALIDATION_FEATURES` constants:
17
+
18
+ ```typescript
19
+ import { getValidationMessage, VALIDATION_FEATURES } from '@forwardslashns/taskit-validation-messages';
20
+
21
+ // ✅ Recommended: Use constants
22
+ const result = getValidationMessage(VALIDATION_FEATURES.CLIENT_CURRENT_ENTITY_STATUS, 'NAME_ALREADY_EXISTS', {
23
+ name: 'Client Name',
24
+ });
25
+
26
+ // ❌ Not recommended: Using string literals
27
+ const result = getValidationMessage('CLIENT_CURRENT_ENTITY_STATUS', 'NAME_ALREADY_EXISTS', { name: 'Client Name' });
28
+ ```
29
+
30
+ ### Available Feature Constants
31
+
32
+ ```typescript
33
+ VALIDATION_FEATURES.ACCOUNT_CATEGORY;
34
+ VALIDATION_FEATURES.ACCOUNT_ID;
35
+ VALIDATION_FEATURES.CLIENT_RECORD_ADDRESS;
36
+ VALIDATION_FEATURES.BUSINESS_ACTIVITY;
37
+ VALIDATION_FEATURES.CLIENT_RECORD_BANK_AND_CREDIT_CARD;
38
+ VALIDATION_FEATURES.CLIENT_RECORD_CONTACT;
39
+ VALIDATION_FEATURES.CLIENT_RECORD_COMISSION_DETAIL;
40
+ VALIDATION_FEATURES.CLIENT_CURRENT_ENTITY_STATUS;
41
+ VALIDATION_FEATURES.CLIENT_RECORD_ENTITY_TYPE_HISTORY;
42
+ VALIDATION_FEATURES.CLIENT_RECORD_FILING_TYPE_HISTORY;
43
+ VALIDATION_FEATURES.CLIENT_RECORD_ENTITY_STATE_HISTORY;
44
+ VALIDATION_FEATURES.CLIENT_RELATIONSHIP;
45
+ VALIDATION_FEATURES.FILING_CATEGORY;
46
+ VALIDATION_FEATURES.STATE;
47
+ VALIDATION_FEATURES.USER;
48
+ VALIDATION_FEATURES.ROLE_AND_PERMISSION;
49
+ VALIDATION_FEATURES.DATA_FILTER;
50
+ VALIDATION_FEATURES.USER_PREFERENCE;
51
+ VALIDATION_FEATURES.CLIENT_RECORD_OUTSIDE_PROVIDER;
52
+ ```
53
+
12
54
  # VALIDATION_MESSAGES
13
55
 
14
56
  The package exposes validation messages that can be retrieved using specific aliases. These messages are organized by the features they belong to, making it easier to manage and update them.
@@ -31,10 +73,13 @@ This mechanism allows for the retrieval and dynamic creation of validation messa
31
73
  ## Usage
32
74
 
33
75
  ```typescript
34
- import { getValidationMessage } from '@forwardslashns/taskit-validation-messages';
76
+ import { getValidationMessage, VALIDATION_FEATURES } from '@forwardslashns/taskit-validation-messages';
77
+
78
+ // ✅ Best practice: Use feature constants (v1.3.0+)
79
+ const result = getValidationMessage(VALIDATION_FEATURES.ACCOUNT_CATEGORY, 'NAME_ALREADY_EXISTS', { name: 'Marketing' });
35
80
 
36
- // Simple usage
37
- const result = getValidationMessage('ACCOUNT_CATEGORY', 'NAME_ALREADY_EXISTS', {
81
+ // Also works: String literals (backward compatible)
82
+ const result2 = getValidationMessage('ACCOUNT_CATEGORY', 'NAME_ALREADY_EXISTS', {
38
83
  name: 'Marketing',
39
84
  });
40
85
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { getValidationMessage, ValidationMessageResult } from './validation/validation-message.formatter';
2
- import { VALIDATION_MESSAGES } from './validation/validation-messages';
3
- export { VALIDATION_MESSAGES, getValidationMessage, ValidationMessageResult };
2
+ import { VALIDATION } from './validation/validation-constants';
3
+ export { VALIDATION, getValidationMessage, ValidationMessageResult };
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValidationMessage = exports.VALIDATION_MESSAGES = void 0;
3
+ exports.getValidationMessage = exports.VALIDATION = void 0;
4
4
  const validation_message_formatter_1 = require("./validation/validation-message.formatter");
5
5
  Object.defineProperty(exports, "getValidationMessage", { enumerable: true, get: function () { return validation_message_formatter_1.getValidationMessage; } });
6
- const validation_messages_1 = require("./validation/validation-messages");
7
- Object.defineProperty(exports, "VALIDATION_MESSAGES", { enumerable: true, get: function () { return validation_messages_1.VALIDATION_MESSAGES; } });
6
+ const validation_constants_1 = require("./validation/validation-constants");
7
+ Object.defineProperty(exports, "VALIDATION", { enumerable: true, get: function () { return validation_constants_1.VALIDATION; } });
@@ -0,0 +1,5 @@
1
+ import { VALIDATION_MESSAGES } from './validation-messages';
2
+ export declare const VALIDATION: { [F in keyof typeof VALIDATION_MESSAGES]: {
3
+ readonly FEATURE: F;
4
+ } & { [K in keyof (typeof VALIDATION_MESSAGES)[F]]: `${F}.${K & string}`; }; };
5
+ //# sourceMappingURL=validation-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-constants.d.ts","sourceRoot":"","sources":["../../src/validation/validation-constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAmB5D,eAAO,MAAM,UAAU,EAAkC,GACtD,CAAC,IAAI,MAAM,OAAO,mBAAmB,GAAG;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB,GAAG,GACD,CAAC,IAAI,MAAM,CAAC,OAAO,mBAAmB,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,GACnE,GACF,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALIDATION = void 0;
4
+ const validation_messages_1 = require("./validation-messages");
5
+ const createValidationConstants = () => {
6
+ const result = {};
7
+ for (const feature in validation_messages_1.VALIDATION_MESSAGES) {
8
+ result[feature] = {
9
+ FEATURE: feature,
10
+ };
11
+ const messages = validation_messages_1.VALIDATION_MESSAGES[feature];
12
+ for (const messageKey in messages) {
13
+ result[feature][messageKey] = `${feature}.${messageKey}`;
14
+ }
15
+ }
16
+ return result;
17
+ };
18
+ exports.VALIDATION = createValidationConstants();
@@ -10,7 +10,8 @@ type MessageParams<T extends readonly string[]> = {
10
10
  export type ValidationMessageResult = {
11
11
  content: string;
12
12
  affectedFields: string[];
13
+ feature: string;
13
14
  };
14
- export declare const getValidationMessage: <FeatureType extends Features, FeatureErrorType extends ErrorType<FeatureType>>(feature: FeatureType, featureError: FeatureErrorType, params?: MessageParams<ErrorMessageParams<FeatureType, FeatureErrorType>>) => ValidationMessageResult;
15
+ export declare const getValidationMessage: <FeatureType extends Features, FeatureErrorType extends ErrorType<FeatureType>>(combinedKey: `${FeatureType}.${FeatureErrorType & string}`, params?: MessageParams<ErrorMessageParams<FeatureType, FeatureErrorType>>) => ValidationMessageResult;
15
16
  export {};
16
17
  //# sourceMappingURL=validation-message.formatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation-message.formatter.d.ts","sourceRoot":"","sources":["../../src/validation/validation-message.formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,KAAK,QAAQ,GAAG,MAAM,OAAO,mBAAmB,CAAC;AACjD,KAAK,SAAS,CAAC,CAAC,SAAS,QAAQ,IAAI,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,KAAK,kBAAkB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAC/G,MAAM,EAAE,MAAM,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC;CAC3C,GACG,CAAC,GACD,EAAE,CAAC;AACP,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM;CAAE,CAAC;AAO/E,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,WAAW,SAAS,QAAQ,EAAE,gBAAgB,SAAS,SAAS,CAAC,WAAW,CAAC,EAChH,SAAS,WAAW,EACpB,cAAc,gBAAgB,EAC9B,SAAS,aAAa,CAAC,kBAAkB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,KACxE,uBA+CF,CAAC"}
1
+ {"version":3,"file":"validation-message.formatter.d.ts","sourceRoot":"","sources":["../../src/validation/validation-message.formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,KAAK,QAAQ,GAAG,MAAM,OAAO,mBAAmB,CAAC;AACjD,KAAK,SAAS,CAAC,CAAC,SAAS,QAAQ,IAAI,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,KAAK,kBAAkB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAC/G,MAAM,EAAE,MAAM,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC;CAC3C,GACG,CAAC,GACD,EAAE,CAAC;AACP,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM;CAAE,CAAC;AAO/E,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,WAAW,SAAS,QAAQ,EAAE,gBAAgB,SAAS,SAAS,CAAC,WAAW,CAAC,EAChH,aAAa,GAAG,WAAW,IAAI,gBAAgB,GAAG,MAAM,EAAE,EAC1D,SAAS,aAAa,CAAC,kBAAkB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,KACxE,uBAoDF,CAAC"}
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValidationMessage = void 0;
4
4
  const validation_messages_1 = require("./validation-messages");
5
- const getValidationMessage = (feature, featureError, params) => {
5
+ const getValidationMessage = (combinedKey, params) => {
6
+ const parts = combinedKey.split('.');
7
+ const feature = parts[0];
8
+ const featureError = parts[1];
6
9
  const messageConfig = validation_messages_1.VALIDATION_MESSAGES[feature][featureError];
7
10
  if (!messageConfig) {
8
11
  throw new Error(`Validation error message is not defined properly in configuration for feature: '${String(feature)}', error: '${String(featureError)}')`);
@@ -38,6 +41,7 @@ const getValidationMessage = (feature, featureError, params) => {
38
41
  return {
39
42
  content: message,
40
43
  affectedFields: messageConfig.affectedFields ? [...messageConfig.affectedFields] : [],
44
+ feature: feature,
41
45
  };
42
46
  };
43
47
  exports.getValidationMessage = getValidationMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forwardslashns/taskit-validation-messages",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "commonjs",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { getValidationMessage, ValidationMessageResult } from './validation/validation-message.formatter';
2
- import { VALIDATION_MESSAGES } from './validation/validation-messages';
2
+ import { VALIDATION } from './validation/validation-constants';
3
3
 
4
- export { VALIDATION_MESSAGES, getValidationMessage, ValidationMessageResult };
4
+ export { VALIDATION, getValidationMessage, ValidationMessageResult };
@@ -0,0 +1,26 @@
1
+ import { VALIDATION_MESSAGES } from './validation-messages';
2
+
3
+ const createValidationConstants = () => {
4
+ const result: any = {};
5
+
6
+ for (const feature in VALIDATION_MESSAGES) {
7
+ result[feature] = {
8
+ FEATURE: feature,
9
+ };
10
+
11
+ const messages = VALIDATION_MESSAGES[feature as keyof typeof VALIDATION_MESSAGES];
12
+ for (const messageKey in messages) {
13
+ result[feature][messageKey] = `${feature}.${messageKey}`;
14
+ }
15
+ }
16
+
17
+ return result;
18
+ };
19
+
20
+ export const VALIDATION = createValidationConstants() as {
21
+ [F in keyof typeof VALIDATION_MESSAGES]: {
22
+ readonly FEATURE: F;
23
+ } & {
24
+ [K in keyof (typeof VALIDATION_MESSAGES)[F]]: `${F}.${K & string}`;
25
+ };
26
+ };
@@ -17,13 +17,17 @@ type MessageConfig = {
17
17
  export type ValidationMessageResult = {
18
18
  content: string;
19
19
  affectedFields: string[];
20
+ feature: string;
20
21
  };
21
22
 
22
23
  export const getValidationMessage = <FeatureType extends Features, FeatureErrorType extends ErrorType<FeatureType>>(
23
- feature: FeatureType,
24
- featureError: FeatureErrorType,
24
+ combinedKey: `${FeatureType}.${FeatureErrorType & string}`,
25
25
  params?: MessageParams<ErrorMessageParams<FeatureType, FeatureErrorType>>
26
26
  ): ValidationMessageResult => {
27
+ const parts = combinedKey.split('.');
28
+ const feature = parts[0] as FeatureType;
29
+ const featureError = parts[1] as FeatureErrorType;
30
+
27
31
  const messageConfig = VALIDATION_MESSAGES[feature][featureError] as MessageConfig;
28
32
 
29
33
  if (!messageConfig) {
@@ -69,5 +73,6 @@ export const getValidationMessage = <FeatureType extends Features, FeatureErrorT
69
73
  return {
70
74
  content: message,
71
75
  affectedFields: messageConfig.affectedFields ? [...messageConfig.affectedFields] : [],
76
+ feature: feature,
72
77
  };
73
78
  };