@socotra/ec-react-utils 2.25.1 → 2.25.2-next.1

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/dist/index.d.ts CHANGED
@@ -155,16 +155,18 @@ declare interface ElementFormData {
155
155
  }
156
156
 
157
157
  /**
158
- * The function `extractElementFromElement takes a `QuoteResponse`, `SegmentResponse` or `ElementResponse` object and an element locator string,
159
- * and returns the element with the matching locator from the quote or its nested elements.
160
- * @param {QuoteResponse} quote - The `quote` parameter is of type `QuoteResponse`, which is an object
158
+ * The function `extractElementByLocator` takes a `QuoteResponse`, `SegmentResponse` or `ElementResponse` object and an locator string,
159
+ * and returns the element with the matching locator from the response objector its nested elements.
160
+ * @param {QuoteResponse | SegmentResponse | ElementResponse} response - The `response` parameter is of type `QuoteResponse`, which is an object
161
161
  * containing information about a quote.
162
162
  * @param {string} elementLocator - The `elementLocator` parameter is a string that represents the
163
- * locator of the element you want to extract from the `quote` object.
163
+ * locator of the element you want to extract from the `response` object.
164
+ * @param {string} locatorType - The `locatorType` parameter is a string that represents the
165
+ * type of locator you want to use to extract the element from the `response` object.
164
166
  * @returns The function `extractElementByLocator` returns the element from the response object
165
167
  * that matches the provided `elementLocator`.
166
168
  */
167
- export declare const extractElementByLocator: <T extends ElementResponse>(response: QuoteResponse | SegmentResponse | ElementResponse, elementLocator: string) => T | null;
169
+ export declare const extractElementByLocator: <T extends ElementResponse>(response: QuoteResponse | SegmentResponse | ElementResponse, elementLocator: string, locatorType?: "locator" | "staticLocator") => T | null;
168
170
 
169
171
  /**
170
172
  * The function `extractElementFromElement takes a `QuoteResponse`, `SegmentResponse` or `ElementResponse` object and an element type string,
@@ -377,41 +379,57 @@ export declare function getAccountRequest(params: {
377
379
  }): AccountCreateRequest;
378
380
 
379
381
  /**
380
- * Converts a JSONForms data path to a constraint record lookup path key.
382
+ * Converts a JSONForms data path to constraint record lookup path keys.
381
383
  *
382
384
  * This function processes a path string by filtering out ignored prefixes from the first token only
383
- * and converting numeric tokens to array notation for constraint record lookups.
385
+ * and converting numeric tokens to array notation for constraint record lookups. It returns both
386
+ * the full path with array notation and a simplified path without array indices.
384
387
  *
385
388
  * @param path - The data path generated by JSONForms library (e.g., "practiceLocation.0.state", "practiceLocation.state")
386
389
  * @param ignoredPrefixes - Array of prefixes to ignore from the first token only (e.g., ["data", "static"])
387
- * @returns The path key formatted for constraint record lookup (e.g., "practiceLocation[0].state", "practiceLocation.state")
390
+ * @returns An object containing:
391
+ * - `pathKey`: The full path with array notation for numeric tokens (e.g., "practiceLocation[0].state")
392
+ * - `pathKeyWithoutIndex`: The simplified path with numeric tokens removed (e.g., "practiceLocation.state")
388
393
  *
389
394
  * @example
390
395
  * // Basic usage
391
- * getConstraintRecordLookupPathKey("practiceLocation.0.state", ["data"])
392
- * // Returns: "practiceLocation[0].state"
396
+ * getConstraintRecordLookupPathKey("practiceLocation.0.state", [])
397
+ * // Returns: { pathKey: "practiceLocation[0].state", pathKeyWithoutIndex: "practiceLocation.state" }
393
398
  *
394
399
  * @example
395
400
  * // With ignored prefix (first token only)
396
401
  * getConstraintRecordLookupPathKey("data.practiceLocation.state", ["data"])
397
- * // Returns: "practiceLocation.state"
402
+ * // Returns: { pathKey: "practiceLocation.state", pathKeyWithoutIndex: "practiceLocation.state" }
398
403
  *
399
404
  * @example
400
405
  * // Multiple ignored prefixes (first token only)
401
406
  * getConstraintRecordLookupPathKey("static.policyNumber", ["data", "static"])
402
- * // Returns: "policyNumber"
407
+ * // Returns: { pathKey: "policyNumber", pathKeyWithoutIndex: "policyNumber" }
408
+ *
409
+ * @example
410
+ * // Complex path with multiple array indices
411
+ * getConstraintRecordLookupPathKey("data.accounts.0.policies.1.coverage.terms", ["data"])
412
+ * // Returns: { pathKey: "accounts[0].policies[1].coverage.terms", pathKeyWithoutIndex: "accounts.policies.coverage.terms" }
403
413
  *
404
414
  * @example
405
415
  * // Prefixes in middle tokens are not filtered
406
416
  * getConstraintRecordLookupPathKey("form.data.field", ["data"])
407
- * // Returns: "form.data.field" (data in middle is not filtered)
417
+ * // Returns: { pathKey: "form.data.field", pathKeyWithoutIndex: "form.data.field" }
408
418
  *
409
419
  * @example
410
420
  * // Empty path
411
421
  * getConstraintRecordLookupPathKey("", ["data"])
412
- * // Returns: ""
422
+ * // Returns: { pathKey: "", pathKeyWithoutIndex: "" }
423
+ *
424
+ * @example
425
+ * // Numeric-only token
426
+ * getConstraintRecordLookupPathKey("0", [])
427
+ * // Returns: { pathKey: "[0]", pathKeyWithoutIndex: "" }
413
428
  */
414
- export declare const getConstraintRecordLookupPathKey: (path: string, ignoredPrefixes: string[]) => string;
429
+ export declare const getConstraintRecordLookupPathKey: (path: string, ignoredPrefixes: string[]) => {
430
+ pathKey: string;
431
+ pathKeyWithoutIndex: string;
432
+ };
415
433
 
416
434
  /**
417
435
  * Generates JSON schema fields for coverage terms based on the provided configuration.
@@ -743,41 +761,6 @@ export declare type QuoteRequestDefaultFields = z.infer<typeof defaultFieldSchem
743
761
 
744
762
  export declare const shouldEvaluateConstraints: (data: Record<string, unknown>, localData: Record<string, unknown>, constraintFieldNames: string[]) => boolean;
745
763
 
746
- /**
747
- * Determines if a form should be submitted based on changes to constraint-related array fields.
748
- *
749
- * This function checks if any of the specified constraint fields have changed in a way that
750
- * requires form submission. It specifically looks for:
751
- * - Type changes (one value is an array, the other is not)
752
- * - Array length changes (both are arrays but have different lengths)
753
- *
754
- * @param data - The original data object to compare against
755
- * @param localData - The new/updated data object to compare
756
- * @param constraintFieldNames - Array of field names that are constraint-related
757
- * @returns `true` if the form should be submitted due to constraint field changes, `false` otherwise
758
- *
759
- * @example
760
- * ```typescript
761
- * const originalData = { practiceLocation: [{ state: 'CA' }] };
762
- * const newData = { practiceLocation: [{ state: 'CA' }, { state: 'NY' }] };
763
- * const constraintFields = ['practiceLocation.0.state', 'practiceLocation.1.state'];
764
- *
765
- * const shouldSubmit = shouldSubmitForm(originalData, newData, constraintFields);
766
- * // Returns true because array length changed
767
- * ```
768
- *
769
- * @example
770
- * ```typescript
771
- * const originalData = { riskType: 'Physician' };
772
- * const newData = { riskType: ['Physician', 'Nurse'] };
773
- * const constraintFields = ['riskType'];
774
- *
775
- * const shouldSubmit = shouldSubmitForm(originalData, newData, constraintFields);
776
- * // Returns true because type changed from string to array
777
- * ```
778
- */
779
- export declare const shouldSubmitForm: (data: Record<string, unknown>, localData: Record<string, unknown>, constraintFieldNames: string[]) => boolean;
780
-
781
764
  /**
782
765
  * The function `splitInputAndQuantifier` takes a string input, removes certain characters from it, and
783
766
  * extracts a quantifier if present.