@socotra/ec-react-utils 2.3.0-next.1 → 2.3.0-next.11

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
@@ -1,4 +1,5 @@
1
1
  import { AccountResponse } from '@socotra/ec-react-schemas';
2
+ import { CoverageTermsConfigRecord } from '@socotra/ec-react-schemas';
2
3
  import { DataModel } from '@socotra/ec-react-schemas';
3
4
  import { DataTypeConfigRecord } from '@socotra/ec-react-schemas';
4
5
  import { ElementConfig } from '@socotra/ec-react-schemas';
@@ -10,24 +11,65 @@ import { ProductConfig } from '@socotra/ec-react-schemas';
10
11
  import { QuoteRequest } from '@socotra/ec-react-schemas';
11
12
  import { QuoteResponse } from '@socotra/ec-react-schemas';
12
13
 
14
+ /**
15
+ * The function `dataModelToJSONSchema` converts a data model to a JSON schema based on specified
16
+ * criteria and data types.
17
+ * @param {DataModelToJsonSchemaProps} args - The `dataModelToJSONSchema` function takes in an object
18
+ * `args` with the following properties:
19
+ * @returns The function `dataModelToJSONSchema` returns a JSON schema object based on the provided
20
+ * arguments `args`. The JSON schema object includes properties, definitions, required fields, and
21
+ * other schema details based on the input data model and configuration.
22
+ */
13
23
  export declare const dataModelToJSONSchema: (args: DataModelToJsonSchemaProps) => JsonSchema7;
14
24
 
15
25
  declare interface DataModelToJsonSchemaProps {
16
26
  data: FieldConfigRecord;
17
27
  dataTypes?: DataTypeConfigRecord;
18
- scope: 'P' | 'Q';
19
- rootDisplayName: string;
28
+ scope: Array<'P' | 'Q' | 'QQ'>;
29
+ rootDisplayName?: string;
20
30
  account?: AccountResponse;
21
31
  quote?: QuoteResponse;
22
32
  element?: ElementResponse;
23
33
  }
24
34
 
35
+ /**
36
+ * The function `extractElementDataModel` extracts element data model based on a given quote, data
37
+ * model, and element locator.
38
+ * @param - - `quote`: A QuoteResponse object containing information about a quote.
39
+ * @param - - `dataModel`: A DataModel object containing information about a data model.
40
+ * @param - - `elementLocator`: A string containing the element locator.
41
+ * @returns The function `extractElementDataModel` returns either an `ElementConfig` object or `false`
42
+ * based on the provided parameters and data model.
43
+ */
25
44
  export declare const extractElementDataModel: ({ dataModel, quote, elementLocator, }: {
26
45
  quote: QuoteResponse;
27
46
  dataModel: DataModel;
28
47
  elementLocator: string;
29
48
  }) => ElementConfig | false;
30
49
 
50
+ /**
51
+ * The function `extractElementDataModelFromType` extracts element data model given a data model and
52
+ * element type.
53
+ * @param - - `dataModel`: A DataModel object containing information about a data model.
54
+ * @param - - `elementType`: A string containing the element type.
55
+ * @returns The function `extractElementDataModelFromType` returns either an `ElementConfig` object or `false`
56
+ * based on the provided parameters and data model.
57
+ */
58
+ export declare const extractElementDataModelFromType: ({ dataModel, elementType, }: {
59
+ dataModel: DataModel;
60
+ elementType: string;
61
+ }) => ElementConfig | false;
62
+
63
+ /**
64
+ * The function `extractElementFromQuote` takes a `QuoteResponse` object and an element locator string,
65
+ * and returns the element with the matching locator from the quote or its nested elements.
66
+ * @param {QuoteResponse} quote - The `quote` parameter is of type `QuoteResponse`, which is an object
67
+ * containing information about a quote.
68
+ * @param {string} elementLocator - The `elementLocator` parameter is a string that represents the
69
+ * locator of the element you want to extract from the `quote` object.
70
+ * @returns The function `extractElementFromQuote` returns the element from the `QuoteResponse` object
71
+ * that matches the provided `elementLocator`.
72
+ */
31
73
  export declare const extractElementFromQuote: (quote: QuoteResponse, elementLocator: string) => false | ({
32
74
  locator: string;
33
75
  type: string;
@@ -37,6 +79,7 @@ export declare const extractElementFromQuote: (quote: QuoteResponse, elementLoca
37
79
  rootLocator?: string | undefined;
38
80
  tenantLocator?: string | undefined;
39
81
  parentLocator?: string | undefined;
82
+ originalEffectiveTime?: string | undefined;
40
83
  } & {
41
84
  elements?: ({
42
85
  locator: string;
@@ -47,9 +90,41 @@ export declare const extractElementFromQuote: (quote: QuoteResponse, elementLoca
47
90
  rootLocator?: string | undefined;
48
91
  tenantLocator?: string | undefined;
49
92
  parentLocator?: string | undefined;
93
+ originalEffectiveTime?: string | undefined;
50
94
  } & any)[];
51
95
  });
52
96
 
97
+ export declare const extractElementsFromQuote: (elements: Array<ElementResponse>, elementType: string) => ({
98
+ locator: string;
99
+ type: string;
100
+ staticLocator: string;
101
+ data?: Record<string, any> | undefined;
102
+ coverageTerms?: Record<string, string> | undefined;
103
+ rootLocator?: string | undefined;
104
+ tenantLocator?: string | undefined;
105
+ parentLocator?: string | undefined;
106
+ originalEffectiveTime?: string | undefined;
107
+ } & {
108
+ elements?: ({
109
+ locator: string;
110
+ type: string;
111
+ staticLocator: string;
112
+ data?: Record<string, any> | undefined;
113
+ coverageTerms?: Record<string, string> | undefined;
114
+ rootLocator?: string | undefined;
115
+ tenantLocator?: string | undefined;
116
+ parentLocator?: string | undefined;
117
+ originalEffectiveTime?: string | undefined;
118
+ } & any)[];
119
+ })[];
120
+
121
+ /**
122
+ * The function `extractProductDataModel` extracts product data model based on the product name from a
123
+ * given data model.
124
+ * @param - The `extractProductDataModel` function takes in two parameters:
125
+ * @returns The function `extractProductDataModel` returns the product configuration data for the
126
+ * specified product name from the provided data model.
127
+ */
53
128
  export declare const extractProductDataModel: ({ dataModel, element: { productName }, }: {
54
129
  element: {
55
130
  productName: string;
@@ -57,13 +132,56 @@ export declare const extractProductDataModel: ({ dataModel, element: { productNa
57
132
  dataModel: DataModel;
58
133
  }) => ProductConfig;
59
134
 
60
- export declare const extractProductElements: ({ dataModel, productDataModel, }: {
135
+ /**
136
+ * The function `extractProductElements` extracts specific elements from a data model based on a
137
+ * product data model configuration.
138
+ * @param - The `extractProductElements` function takes in two parameters:
139
+ * @returns The function `extractProductElements` returns a `ProductElementMap` object containing
140
+ * elements related to coverages, exposures, policy lines, and exposure groups that are available based
141
+ * on the provided `dataModel` and `productDataModel`.
142
+ */
143
+ export declare const extractProductElements: ({ dataModel, contents, }: {
61
144
  dataModel: DataModel;
62
- productDataModel: ProductConfig;
145
+ contents: string[];
63
146
  }) => ProductElementMap;
64
147
 
65
- export declare const getDefaultElementValues: (element: ElementResponse) => Partial<ElementResponse>;
148
+ /**
149
+ * The `getCoverageTermsDefaultValues` function extracts default coverage terms values from a
150
+ * `CoverageTermsConfigRecord` object and sets them based on certain conditions.
151
+ * @param {Record<string, string>} coverageTermOptions - The `coverageTermOptions` parameter in the
152
+ * `getCoverageTermsDefaultValues` function represents the options for coverage terms.
153
+ * @param {CoverageTermsConfigRecord} coverageTermDataModel - The `coverageTermDataModel` parameter in the
154
+ * `getCoverageTermsDefaultValues` function represents the configuration settings for coverage terms.
155
+ * @returns The `getCoverageTermsDefaultValues` function returns an object with default values for
156
+ * coverage terms.
157
+ */
158
+ export declare const getCoverageTermsDefaultValues: ({ coverageTermOptions, coverageTermDataModel, }: {
159
+ coverageTermOptions: Record<string, string>;
160
+ coverageTermDataModel: CoverageTermsConfigRecord;
161
+ }) => Record<string, string>;
66
162
 
163
+ /**
164
+ * The function `getDefaultElementValues` returns a partial copy of an ElementResponse object with
165
+ * default values for coverageTerms if not provided.
166
+ * @param {ElementResponse} element - The `element` parameter in the `getDefaultElementValues` function
167
+ * is of type `ElementResponse`, which contains data related to an element in a system or
168
+ * application.
169
+ * @returns A partial ElementResponse object is being returned, with the data from the input element
170
+ * and the coverageTerms property set to element.coverageTerms if it exists, otherwise an empty object.
171
+ */
172
+ export declare const getDefaultElementValues: (element: ElementResponse, coverageTermDataModel: CoverageTermsConfigRecord) => Partial<ElementResponse>;
173
+
174
+ /**
175
+ * The `getDefaultQuoteValues` function extracts default values from a `QuoteResponse`
176
+ * object and sets them based on certain conditions.
177
+ * @param {QuoteResponse} quote - The `getDefaultQuoteValues` function takes in three parameters:
178
+ * @param {ProductConfig} productModel - The `productModel` parameter in the `getDefaultQuoteValues`
179
+ * function represents the configuration settings for a specific product.
180
+ * @param {DataModel} dataModel - The `dataModel` parameter in the `getDefaultQuoteValues` function
181
+ * represents the data model used in the context of generating default values for a quote.
182
+ * @returns The `getDefaultQuoteValues` function returns an object with properties `default` and
183
+ * `advanced`.
184
+ */
67
185
  export declare const getDefaultQuoteValues: (quote: QuoteResponse, productModel: ProductConfig, dataModel: DataModel) => {
68
186
  default: {
69
187
  expirationTime?: string | undefined;
@@ -79,25 +197,17 @@ export declare const getDefaultQuoteValues: (quote: QuoteResponse, productModel:
79
197
  delinquencyPlanName: string | undefined;
80
198
  autoRenewalPlanName: string | undefined;
81
199
  };
200
+ coverageTerms: Record<string, string>;
82
201
  };
83
202
 
84
- export declare const getQuoteElementRequest: ({ formData, locator, }: GetQuoteElementRequestAttributes) => QuoteRequest;
85
-
86
- declare type GetQuoteElementRequestAttributes = {
87
- formData: {
88
- [key: string]: unknown;
89
- };
90
- locator: string;
91
- };
92
-
93
- export declare const getQuoteRequest: ({ data }: QuoteFormData) => QuoteRequest;
94
-
95
203
  /**
96
- * Takes an element type and splits the postfix scope from the base model name. E.g., 'PersonalAutoQuote' becomes ['PersonalAuto', 'Quote']
97
- * @param elementType The element type to parse, e.g. `element.type` from an `ElementResponse`
98
- * @returns [elementName: string, scope: 'Quote' | 'QuickQuote' | 'Policy' | null]
204
+ * The function `getQuoteRequest` processes form data to create a `QuoteRequest` object.
205
+ * @param {QuoteFormData} - The `getQuoteRequest` function takes in a parameter `data` of type
206
+ * `QuoteFormData` and returns a `QuoteRequest` object.
207
+ * @returns The function `getQuoteRequest` returns a `QuoteRequest` object based on the provided
208
+ * `QuoteFormData` data.
99
209
  */
100
- export declare const parseElementTypeAndScopeByElementType: (elementType: string) => [elementName: string, scope: "Quote" | "QuickQuote" | "Policy" | null];
210
+ export declare const getQuoteRequest: ({ data }: QuoteFormData) => QuoteRequest;
101
211
 
102
212
  declare type ProductElement = Record<string, ElementConfig>;
103
213
 
@@ -124,50 +234,24 @@ declare interface QuoteFormData {
124
234
  durationBasis?: string;
125
235
  delinquencyPlanName?: string;
126
236
  };
237
+ coverageTerms?: {
238
+ [key: string]: string;
239
+ };
127
240
  [key: string]: any;
128
241
  };
129
242
  }
130
243
 
131
244
  /**
132
- * Looks through a data model for a matching element type and returns the element model
133
- * @param element The element to retrieve the data model for
134
- * @param dataModel The full resolved data model to search
135
- * @returns ElementConfig
245
+ * The function `splitInputAndQuantifier` takes a string input, removes certain characters from it, and
246
+ * extracts a quantifier if present.
247
+ * @param {string | undefined} input - The `splitInputAndQuantifier` function takes a string input and
248
+ * splits it into two parts: the name and the quantifier. The quantifier is extracted from the end of
249
+ * the input string, while the name is the input string with certain characters (? * ! +) removed.
250
+ * @returns The function `splitInputAndQuantifier` returns an object with two properties:
251
+ * - `name`: a string that is the input with any of the characters '?', '*', '!', or '+' removed
252
+ * - `quantifier`: a string that represents the quantifier found at the end of the input string, or an
253
+ * empty string if no quantifier is found
136
254
  */
137
- export declare function retrieveDataModelFromElement(element: ElementResponse, dataModel: DataModel): {
138
- displayName?: string | undefined;
139
- abstract?: boolean | undefined;
140
- extend?: string | undefined;
141
- data?: Record<string, {
142
- options?: string[] | undefined;
143
- type?: string | undefined;
144
- displayName?: string | undefined;
145
- defaultValue?: string | undefined;
146
- minLength?: number | undefined;
147
- maxLength?: number | undefined;
148
- regex?: string | undefined;
149
- min?: string | undefined;
150
- multiline?: boolean | undefined;
151
- max?: string | undefined;
152
- overrides?: string | undefined;
153
- scope?: string | undefined;
154
- inherited?: boolean | undefined;
155
- precision?: number | undefined;
156
- readOnly?: boolean | undefined;
157
- }> | undefined;
158
- contents?: string[] | undefined;
159
- coverageTerms?: string[] | undefined;
160
- charges?: string[] | undefined;
161
- };
162
-
163
- /**
164
- * Takes the root element of a quote and a locator and returns the element with the matching locator
165
- * @param quoteElement The root element from the QuoteResponse
166
- * @param locator The locator of the element to retrieve
167
- * @returns ElementResponse | undefined
168
- */
169
- export declare function retrieveElementFromQuoteByLocator(quoteElement: ElementResponse, locator: string): ElementResponse | undefined;
170
-
171
255
  export declare const splitInputAndQuantifier: (input: string | undefined) => {
172
256
  name: string;
173
257
  quantifier: "" | "*" | "?" | "+" | "!";