Socket
Book a DemoInstallSign in
Socket

@socotra/ec-react-utils

Package Overview
Dependencies
Maintainers
9
Versions
294
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socotra/ec-react-utils

latest
Source
npmnpm
Version
2.26.0
Version published
Maintainers
9
Created
Source

title: Utils description: Utils for the @socotra/ec-react-utils package.

EC React Utils

Utils for the Socotra Insurance Suite

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:

  • Data Extraction: Functions for safely extracting nested data from large, complex objects.
  • Default Value Getters: Functions for generating default values for forms.
  • API Request Builders: Functions for mapping form data to API request payloads.
  • Miscellaneous Helpers: A variety of other useful functions for data manipulation and comparison.

Installation

npm i @socotra/ec-react-utils

This package has peer dependencies on @socotra/ec-react-schemas and zod, which you likely have installed already.

Usage

Import any utility directly from the package:

import { extractElementByType } from '@socotra/ec-react-utils';

const element = extractElementByType(quote, 'my_element_type');

Documentation

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.

Available Utilities

Data Extraction

FunctionDescriptionReturns
getAccountEvaluatedConstraintsRequestCreates a request payload to evaluate constraints for an account.AccountEvaluateConstraintsRequest
extractElementByLocatorExtracts the first element from a policy, quote, or transaction segment that matches the specified locator.Element or undefined
extractElementByTypeExtracts the first element from a policy, quote, or transaction segment that matches the specified type.Element or undefined
extractElementsByTypeExtracts all elements from a policy, quote, or transaction segment that match the specified type.Element[]
extractElementDataModelFromQuoteExtracts the data model for a specific element type from a quote response.object or undefined
extractElementDataModelFromSegmentExtracts the data model for a specific element type from a transaction segment.object or undefined
extractElementDataModelFromTypeExtracts the data model for a specific element type from a policy response.object or undefined
extractElementsFromQuoteExtracts all elements from a quote's exposures.Element[]
extractElementsFromTransactionSegmentExtracts all elements from a transaction segment's exposures.Element[]
extractProductDataModelExtracts the data model for a specific product from a policy or quote.object or undefined
extractProductElementMapExtracts a flat map of element configurations for a given contents array from a product.Record<string, ElementConfig>
extractProductElementsExtracts all elements associated with a product from a policy or quote.Element[]
shouldEvaluateConstraintsChecks if the constraints should be evaluated based on the original and new data.boolean

Default Value Getters

FunctionDescriptionReturns
getCoverageTermsDefaultValuesGenerates default values for coverage terms based on the product configuration.object
getDefaultAccountFormValuesGenerates default values for the account form.object
getDefaultDraftTransactionValuesGenerates default values for a new draft transaction form.object
getDefaultElementValuesGenerates default values for an element based on its data model.object
getDefaultInitializedTransactionValuesGenerates default values for an initialized transaction form.object
getDefaultPolicyValuesGenerates default values for a new policy.object
getDefaultQuoteValuesGenerates default values for a new quote.object
getCoverageTermFieldsGenerates a JsonSchema for a coverage term field.object

API Request Builders

FunctionDescriptionReturns
getAccountRequestTransforms form data into a request payload for creating or updating an account.AccountCreateRequest or AccountUpdateRequest
getElementRequestTransforms form data into a request payload for creating or updating an element.ElementCreateRequest or ElementUpdateRequest
getEvaluatedConstraintsRequestCreates a request payload to evaluate constraints for a specific element.EvaluateConstraintsRequest
getModifyChangeInstructionCreateRequestFromFormDataTransforms form data into a request to modify a transaction's change instructions.ModifyChangeInstructionCreateRequest
getParamsChangeInstructionCreateRequestFromFormDataTransforms form data into a request to update the parameters of a transaction.ParamsChangeInstructionCreateRequest
getElementTransactionUpdateRequestFromFormDataTransforms form data into a request to update an element within a transaction.ElementTransactionUpdateRequest
getPolicyRequestTransforms form data into a request payload for creating a new policy.PolicyCreateRequest
getQuoteRequestTransforms form data into a request payload for creating or updating a quote.QuoteRequest

Miscellaneous

FunctionDescriptionReturns
compareDataCompares two data objects and returns a list of differences.Diff[]
dataModelToJSONSchemaConverts a Socotra data model into a JSON schema for form generation.JSONSchema7
getElementNameByTypeRetrieves the display name of an element based on its type from the product configuration.string
getRemoveDataFieldValuesIdentifies fields that should be removed from a data object based on a comparison.object
getUpdatedDataFromConstraintsApplies the results of a constraint evaluation to a data object.object
parseToPrimitiveSafely parses a string into a boolean, number, or returns the original string.`string
splitInputAndQuantifierSplits a string into its core name and a quantifier suffix (e.g., ?, *).{ name: string; quantifier: string }
translateErrorTranslates a validation error object into a human-readable string.string

Documentation

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

Package last updated on 09 Oct 2025

Did you know?

Socket

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.

Install

Related posts