@forwardslashns/taskit-validation-messages 1.0.64 → 1.1.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/.env.example ADDED
@@ -0,0 +1 @@
1
+ NPM_TOKEN=your_npm_token_here
package/PUBLISHING.md ADDED
@@ -0,0 +1,78 @@
1
+ # Publishing Guide
2
+
3
+ ## Prerequisites
4
+
5
+ You need a valid NPM access token with publish permissions for the `@forwardslashns` scope.
6
+
7
+ ### Generate a New Token (if needed)
8
+
9
+ 1. Go to https://www.npmjs.com/settings/YOUR_USERNAME/tokens
10
+ 2. Click "Generate New Token"
11
+ 3. Choose "Classic Token"
12
+ 4. Select "Automation" or "Publish" type
13
+ 5. Copy the token (starts with `npm_`)
14
+
15
+ **Important:** The token must be associated with the `forwardslashns` npm account that has publish permissions for `@forwardslashns/taskit-validation-messages`.
16
+
17
+ ## Setup
18
+
19
+ 1. **Create `.env` file** (first time only):
20
+ ```bash
21
+ cp .env.example .env
22
+ ```
23
+
24
+ 2. **Add your NPM token** to `.env`:
25
+ ```
26
+ NPM_TOKEN=npm_your_actual_token_here
27
+ ```
28
+
29
+ Make sure to use the **full token** (should be 40+ characters starting with `npm_`)
30
+
31
+ ## Publishing
32
+
33
+ Run the publish script:
34
+
35
+ ```powershell
36
+ pnpm run publish:token
37
+ ```
38
+
39
+ Or directly:
40
+
41
+ ```powershell
42
+ .\publish.ps1
43
+ ```
44
+
45
+ ## Troubleshooting
46
+
47
+ ### "Access token expired or revoked"
48
+
49
+ This means your token is either:
50
+ - **Expired** - Generate a new token from npm
51
+ - **Invalid** - Check you copied the complete token
52
+ - **No permissions** - Token must belong to `forwardslashns` npm account with publish rights
53
+
54
+ **Solution:** Generate a fresh token from the npm account that owns the package.
55
+
56
+ ### "Not in this registry"
57
+
58
+ - Verify the package exists: `npm view @forwardslashns/taskit-validation-messages`
59
+ - Ensure you have publish permissions for the `@forwardslashns` scope
60
+
61
+ ### Token not loading
62
+
63
+ - Verify `.env` exists and contains `NPM_TOKEN=...`
64
+ - Check token has no extra spaces or quotes
65
+ - Run `Get-Content .env` to verify the file
66
+
67
+ ## How It Works
68
+
69
+ 1. Script loads `NPM_TOKEN` from `.env` file
70
+ 2. Temporarily replaces `${NPM_TOKEN}` in `.npmrc` with actual token
71
+ 3. Runs `pnpm publish`
72
+ 4. Restores original `.npmrc` (keeps token out of git)
73
+
74
+ ## Security
75
+
76
+ - `.env` is in `.gitignore` - never commit it
77
+ - `.npmrc` uses `${NPM_TOKEN}` placeholder - safe to commit
78
+ - Token is only in memory during publish
package/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This package provides a centralized list of validation messages used across both frontend and backend of the project. It ensures consistent error display and simplifies maintenance by keeping all validation messages in one place, without altering code in development repositories.
4
4
 
5
+ ## ✨ Features
6
+
7
+ - **Centralized validation messages** across all features
8
+ - **Type-safe** message retrieval with TypeScript
9
+ - **Dynamic parameter substitution** for contextual messages
10
+ - **Affected fields tracking** for better frontend UX (v1.1.0+)
11
+
5
12
  # VALIDATION_MESSAGES
6
13
 
7
14
  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.
@@ -9,3 +16,55 @@ The package exposes validation messages that can be retrieved using specific ali
9
16
  # getValidationMessage
10
17
 
11
18
  This mechanism allows for the retrieval and dynamic creation of validation messages by passing their aliases and any required parameters. Parameters are optional and passed as objects, following the structure defined within each validation message itself.
19
+
20
+ ## Return Value (v1.1.0+)
21
+
22
+ `getValidationMessage` now returns a `ValidationMessageResult` object:
23
+
24
+ ```typescript
25
+ {
26
+ content: string; // The formatted validation message
27
+ affectedFields: string[]; // Array of field identifiers affected by this validation error
28
+ }
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import { getValidationMessage } from '@forwardslashns/taskit-validation-messages';
35
+
36
+ // Simple usage
37
+ const result = getValidationMessage('ACCOUNT_CATEGORY', 'NAME_ALREADY_EXISTS', {
38
+ name: 'Marketing',
39
+ });
40
+
41
+ console.log(result.content); // "Account category with the same name 'Marketing' already exists"
42
+ console.log(result.affectedFields); // ['name']
43
+
44
+ // In API responses
45
+ return reply.status(400).send({
46
+ message: result.content,
47
+ affectedFields: result.affectedFields,
48
+ });
49
+ ```
50
+
51
+ ## Migration from v1.0.x
52
+
53
+ See [MIGRATION_GUIDE.md](./MIGRATION_GUIDE.md) for detailed migration instructions.
54
+
55
+ **Quick update:**
56
+
57
+ ```typescript
58
+ // Old (v1.0.x)
59
+ const message = getValidationMessage('FEATURE', 'ERROR');
60
+
61
+ // New (v1.1.0+)
62
+ const { content, affectedFields } = getValidationMessage('FEATURE', 'ERROR');
63
+ ```
64
+
65
+ ## Documentation
66
+
67
+ - [Migration Guide](./MIGRATION_GUIDE.md) - Upgrading from v1.0.x
68
+ - [Implementation Summary](./IMPLEMENTATION_SUMMARY.md) - Technical details
69
+ - [Backend Update Checklist](./BACKEND_UPDATE_CHECKLIST.md) - Step-by-step backend migration
70
+ - [Example Usage](./example-usage.ts) - Code examples
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getValidationMessage } from './validation/validation-message.formatter';
1
+ import { getValidationMessage, ValidationMessageResult } from './validation/validation-message.formatter';
2
2
  import { VALIDATION_MESSAGES } from './validation/validation-messages';
3
- export { VALIDATION_MESSAGES, getValidationMessage };
3
+ export { VALIDATION_MESSAGES, 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,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,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,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,CAAC"}
@@ -7,6 +7,10 @@ type ErrorMessageParams<F extends Features, E extends ErrorType<F>> = (typeof VA
7
7
  type MessageParams<T extends readonly string[]> = {
8
8
  [K in T[number]]: string;
9
9
  };
10
- export declare const getValidationMessage: <FeatureType extends Features, FeatureErrorType extends ErrorType<FeatureType>>(feature: FeatureType, featureError: FeatureErrorType, params?: MessageParams<ErrorMessageParams<FeatureType, FeatureErrorType>>) => string;
10
+ export type ValidationMessageResult = {
11
+ content: string;
12
+ affectedFields: string[];
13
+ };
14
+ export declare const getValidationMessage: <FeatureType extends Features, FeatureErrorType extends ErrorType<FeatureType>>(feature: FeatureType, featureError: FeatureErrorType, params?: MessageParams<ErrorMessageParams<FeatureType, FeatureErrorType>>) => ValidationMessageResult;
11
15
  export {};
12
16
  //# 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;CAC3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,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"}
@@ -35,6 +35,9 @@ const getValidationMessage = (feature, featureError, params) => {
35
35
  expectedParams.forEach((param) => {
36
36
  message = message.replaceAll(`{${param}}`, inputParams[param]);
37
37
  });
38
- return message;
38
+ return {
39
+ content: message,
40
+ affectedFields: messageConfig.affectedFields ? [...messageConfig.affectedFields] : [],
41
+ };
39
42
  };
40
43
  exports.getValidationMessage = getValidationMessage;