@socotra/ec-react-utils 2.19.3-next.6 → 2.19.3-next.7
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 +112 -27
- package/dist/index.es.js +11572 -11860
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,48 +1,133 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
title: Utils
|
|
3
|
+
description: Utils for the @socotra/ec-react-utils package.
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# EC React Utils
|
|
7
|
+
### Utils for the Socotra Insurance Suite
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
- **Repo Path**: `packages/utils`
|
|
7
|
-
- **Install**:
|
|
8
|
-
```sh
|
|
9
|
-
npm i @socotra/ec-react-utils
|
|
10
|
-
```
|
|
11
|
-
- **Usage**:
|
|
9
|
+
This package provides a collection of shared helper functions used throughout the Socotra EC ecosystem. These utilities handle common tasks such as data extraction, transformation, default value generation, and building API requests, serving as a foundational layer for the component and application logic.
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
import { myUtilityFunction } from '@socotra/ec-react-utils';
|
|
15
|
-
```
|
|
11
|
+
The library is organized by function, including:
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
- **Data Extraction:** Functions for safely extracting nested data from large, complex objects.
|
|
14
|
+
- **Default Value Getters:** Functions for generating default values for forms.
|
|
15
|
+
- **API Request Builders:** Functions for mapping form data to API request payloads.
|
|
16
|
+
- **Miscellaneous Helpers:** A variety of other useful functions for data manipulation and comparison.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
20
21
|
|
|
21
22
|
```sh
|
|
22
|
-
|
|
23
|
+
npm i @socotra/ec-react-utils
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
This package has peer dependencies on `@socotra/ec-react-schemas` and `zod`, which you likely have installed already.
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
pnpm run test
|
|
29
|
-
```
|
|
28
|
+
---
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
## Usage
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
Import any utility directly from the package:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { extractElementByType } from '@socotra/ec-react-utils';
|
|
36
|
+
|
|
37
|
+
const element = extractElementByType(quote, 'my_element_type');
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
### Documentation
|
|
41
|
+
|
|
42
|
+
The documentation for this package is generated from a script that must be run after the package is built.
|
|
43
|
+
|
|
44
|
+
To contribute to the documentation, clone the repo and run the following command:
|
|
38
45
|
|
|
39
46
|
```sh
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
git clone https://github.com/socotra/ec-react.git
|
|
48
|
+
cd ec-react/packages/docs/src/utils
|
|
42
49
|
```
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
Edit files under the `utils` directory.
|
|
52
|
+
|
|
53
|
+
Run `pnpm run sync` to update the documentation in the `README.md` files of the other packages.
|
|
54
|
+
|
|
55
|
+
Follow instructions in the `ec-react/packages/docs/README.md` file to build the documentation and update the `Socotra Documentation` repo.
|
|
56
|
+
|
|
57
|
+
## Available Utilities
|
|
58
|
+
|
|
59
|
+
<!-- UTILS-START -->
|
|
60
|
+
|
|
61
|
+
### Data Extraction
|
|
62
|
+
|
|
63
|
+
| Function | Description | Returns |
|
|
64
|
+
|----------|-------------|---------|
|
|
65
|
+
| `extractElementByLocator` | Extracts the first element from a policy, quote, or transaction segment that matches the specified locator. | `Element` or `undefined` |
|
|
66
|
+
| `extractElementByType` | Extracts the first element from a policy, quote, or transaction segment that matches the specified type. | `Element` or `undefined` |
|
|
67
|
+
| `extractElementsByType` | Extracts all elements from a policy, quote, or transaction segment that match the specified type. | `Element[]` |
|
|
68
|
+
| `extractElementDataModelFromQuote` | Extracts the data model for a specific element type from a quote response. | `object` or `undefined` |
|
|
69
|
+
| `extractElementDataModelFromSegment` | Extracts the data model for a specific element type from a transaction segment. | `object` or `undefined` |
|
|
70
|
+
| `extractElementDataModelFromType` | Extracts the data model for a specific element type from a policy response. | `object` or `undefined` |
|
|
71
|
+
| `extractElementsFromQuote` | Extracts all elements from a quote's exposures. | `Element[]` |
|
|
72
|
+
| `extractElementsFromTransactionSegment` | Extracts all elements from a transaction segment's exposures. | `Element[]` |
|
|
73
|
+
| `extractProductDataModel` | Extracts the data model for a specific product from a policy or quote. | `object` or `undefined` |
|
|
74
|
+
| `extractProductElements` | Extracts all elements associated with a product from a policy or quote. | `Element[]` |
|
|
75
|
+
|
|
76
|
+
### Default Value Getters
|
|
77
|
+
|
|
78
|
+
| Function | Description | Returns |
|
|
79
|
+
|----------|-------------|---------|
|
|
80
|
+
| `getCoverageTermsDefaultValues` | Generates default values for coverage terms based on the product configuration. | `object` |
|
|
81
|
+
| `getDefaultAccountFormValues` | Generates default values for the account form. | `object` |
|
|
82
|
+
| `getDefaultDraftTransactionValues` | Generates default values for a new draft transaction form. | `object` |
|
|
83
|
+
| `getDefaultElementValues` | Generates default values for an element based on its data model. | `object` |
|
|
84
|
+
| `getDefaultInitializedTransactionValues` | Generates default values for an initialized transaction form. | `object` |
|
|
85
|
+
| `getDefaultPolicyValues` | Generates default values for a new policy. | `object` |
|
|
86
|
+
| `getDefaultQuoteValues` | Generates default values for a new quote. | `object` |
|
|
87
|
+
|
|
88
|
+
### API Request Builders
|
|
89
|
+
|
|
90
|
+
| Function | Description | Returns |
|
|
91
|
+
|----------|-------------|---------|
|
|
92
|
+
| `getAccountRequest` | Transforms form data into a request payload for creating or updating an account. | `AccountCreateRequest` or `AccountUpdateRequest` |
|
|
93
|
+
| `getElementRequest` | Transforms form data into a request payload for creating or updating an element. | `ElementCreateRequest` or `ElementUpdateRequest` |
|
|
94
|
+
| `getEvaluatedConstraintsRequest` | Creates a request payload to evaluate constraints for a specific element. | `EvaluateConstraintsRequest` |
|
|
95
|
+
| `getModifyChangeInstructionCreateRequestFromFormData` | Transforms form data into a request to modify a transaction's change instructions. | `ModifyChangeInstructionCreateRequest` |
|
|
96
|
+
| `getParamsChangeInstructionCreateRequestFromFormData` | Transforms form data into a request to update the parameters of a transaction. | `ParamsChangeInstructionCreateRequest` |
|
|
97
|
+
| `getElementTransactionUpdateRequestFromFormData` | Transforms form data into a request to update an element within a transaction. | `ElementTransactionUpdateRequest` |
|
|
98
|
+
| `getPolicyRequest` | Transforms form data into a request payload for creating a new policy. | `PolicyCreateRequest` |
|
|
99
|
+
| `getQuoteRequest` | Transforms form data into a request payload for creating or updating a quote. | `QuoteRequest` |
|
|
100
|
+
|
|
101
|
+
### Miscellaneous
|
|
102
|
+
|
|
103
|
+
| Function | Description | Returns |
|
|
104
|
+
|----------|-------------|---------|
|
|
105
|
+
| `compareData` | Compares two data objects and returns a list of differences. | `Diff[]` |
|
|
106
|
+
| `dataModelToJSONSchema` | Converts a Socotra data model into a JSON schema for form generation. | `JSONSchema7` |
|
|
107
|
+
| `getElementNameByType` | Retrieves the display name of an element based on its type from the product configuration. | `string` |
|
|
108
|
+
| `getRemoveDataFieldValues` | Identifies fields that should be removed from a data object based on a comparison. | `object` |
|
|
109
|
+
| `getUpdatedDataFromConstraints` | Applies the results of a constraint evaluation to a data object. | `object` |
|
|
110
|
+
| `parseToPrimitive` | Safely parses a string into a boolean, number, or returns the original string. | `string | number | boolean` |
|
|
111
|
+
| `splitInputAndQuantifier` | Splits a string into its core name and a quantifier suffix (e.g., `?`, `*`). | `{ name: string; quantifier: string }` |
|
|
112
|
+
| `translateError` | Translates a validation error object into a human-readable string. | `string` |
|
|
113
|
+
|
|
114
|
+
<!-- UTILS-END -->
|
|
115
|
+
|
|
116
|
+
### Documentation
|
|
117
|
+
|
|
118
|
+
The documentation for this package is generated from a script that must be run after the package is built.
|
|
119
|
+
|
|
120
|
+
To contribute to the documentation, clone the repo and run the following command:
|
|
45
121
|
|
|
46
122
|
```sh
|
|
47
|
-
|
|
123
|
+
git clone https://github.com/socotra/ec-react.git
|
|
124
|
+
cd ec-react/packages/docs/src/utils
|
|
48
125
|
```
|
|
126
|
+
|
|
127
|
+
Edit files under the `utils` directory.
|
|
128
|
+
|
|
129
|
+
Run `pnpm run sync` to update the documentation in the `README.md` files of this package.
|
|
130
|
+
|
|
131
|
+
Run `pnpm run build` to build the documentation for the `Socotra Documentation` repo.
|
|
132
|
+
|
|
133
|
+
Follow instructions in the `ec-react/packages/docs/README.md` file to build the documentation and update the `Socotra Documentation` repo.
|