
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@socotra/ec-react-utils
Advanced tools
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.
The library is organized by function, including:
npm i @socotra/ec-react-utils
This package has peer dependencies on @socotra/ec-react-schemas and zod, which you likely have installed already.
Import any utility directly from the package:
import { extractElementByType } from '@socotra/ec-react-utils';
const element = extractElementByType(quote, 'my_element_type');
The documentation for this package is generated from a script that must be run after the package is built.
To contribute to the documentation, clone the repo and run the following command:
git clone https://github.com/socotra/ec-react.git
cd ec-react/packages/docs/src/utils
Edit files under the utils directory.
Run pnpm run sync to update the documentation in the README.md files of the other packages.
Follow instructions in the ec-react/packages/docs/README.md file to build the documentation and update the Socotra Documentation repo.
| Function | Description | Returns |
|---|---|---|
getAccountEvaluatedConstraintsRequest | Creates a request payload to evaluate constraints for an account. | AccountEvaluateConstraintsRequest |
extractElementByLocator | Extracts the first element from a policy, quote, or transaction segment that matches the specified locator. | Element or undefined |
extractElementByType | Extracts the first element from a policy, quote, or transaction segment that matches the specified type. | Element or undefined |
extractElementsByType | Extracts all elements from a policy, quote, or transaction segment that match the specified type. | Element[] |
extractElementDataModelFromQuote | Extracts the data model for a specific element type from a quote response. | object or undefined |
extractElementDataModelFromSegment | Extracts the data model for a specific element type from a transaction segment. | object or undefined |
extractElementDataModelFromType | Extracts the data model for a specific element type from a policy response. | object or undefined |
extractElementsFromQuote | Extracts all elements from a quote's exposures. | Element[] |
extractElementsFromTransactionSegment | Extracts all elements from a transaction segment's exposures. | Element[] |
extractProductDataModel | Extracts the data model for a specific product from a policy or quote. | object or undefined |
extractProductElementMap | Extracts a flat map of element configurations for a given contents array from a product. | Record<string, ElementConfig> |
extractProductElements | Extracts all elements associated with a product from a policy or quote. | Element[] |
shouldEvaluateConstraints | Checks if the constraints should be evaluated based on the original and new data. | boolean |
| Function | Description | Returns |
|---|---|---|
getCoverageTermsDefaultValues | Generates default values for coverage terms based on the product configuration. | object |
getDefaultAccountFormValues | Generates default values for the account form. | object |
getDefaultDraftTransactionValues | Generates default values for a new draft transaction form. | object |
getDefaultElementValues | Generates default values for an element based on its data model. | object |
getDefaultInitializedTransactionValues | Generates default values for an initialized transaction form. | object |
getDefaultPolicyValues | Generates default values for a new policy. | object |
getDefaultQuoteValues | Generates default values for a new quote. | object |
getCoverageTermFields | Generates a JsonSchema for a coverage term field. | object |
| Function | Description | Returns |
|---|---|---|
getAccountRequest | Transforms form data into a request payload for creating or updating an account. | AccountCreateRequest or AccountUpdateRequest |
getElementRequest | Transforms form data into a request payload for creating or updating an element. | ElementCreateRequest or ElementUpdateRequest |
getEvaluatedConstraintsRequest | Creates a request payload to evaluate constraints for a specific element. | EvaluateConstraintsRequest |
getModifyChangeInstructionCreateRequestFromFormData | Transforms form data into a request to modify a transaction's change instructions. | ModifyChangeInstructionCreateRequest |
getParamsChangeInstructionCreateRequestFromFormData | Transforms form data into a request to update the parameters of a transaction. | ParamsChangeInstructionCreateRequest |
getElementTransactionUpdateRequestFromFormData | Transforms form data into a request to update an element within a transaction. | ElementTransactionUpdateRequest |
getPolicyRequest | Transforms form data into a request payload for creating a new policy. | PolicyCreateRequest |
getQuoteRequest | Transforms form data into a request payload for creating or updating a quote. | QuoteRequest |
| Function | Description | Returns |
|---|---|---|
compareData | Compares two data objects and returns a list of differences. | Diff[] |
dataModelToJSONSchema | Converts a Socotra data model into a JSON schema for form generation. | JSONSchema7 |
getElementNameByType | Retrieves the display name of an element based on its type from the product configuration. | string |
getRemoveDataFieldValues | Identifies fields that should be removed from a data object based on a comparison. | object |
getUpdatedDataFromConstraints | Applies the results of a constraint evaluation to a data object. | object |
parseToPrimitive | Safely parses a string into a boolean, number, or returns the original string. | `string |
splitInputAndQuantifier | Splits a string into its core name and a quantifier suffix (e.g., ?, *). | { name: string; quantifier: string } |
translateError | Translates a validation error object into a human-readable string. | string |
The documentation for this package is generated from a script that must be run after the package is built.
To contribute to the documentation, clone the repo and run the following command:
git clone https://github.com/socotra/ec-react.git
cd ec-react/packages/docs/src/utils
Edit files under the utils directory.
Run pnpm run sync to update the documentation in the README.md files of this package.
Run pnpm run build to build the documentation for the Socotra Documentation repo.
Follow instructions in the ec-react/packages/docs/README.md file to build the documentation and update the Socotra Documentation repo.
FAQs
Unknown package
We found that @socotra/ec-react-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.