@mychoice/mychoice-sdk-store 2.2.10 → 2.2.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.
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './utils';
3
3
  export * from './useAutofillCarForm';
4
+ export * from './useAutofillLifeForm';
@@ -74,3 +74,29 @@ export interface MappedAutofillData {
74
74
  postalData: any;
75
75
  configData: any;
76
76
  }
77
+ export interface LifeAutofillQuoterInfo {
78
+ phone: number;
79
+ last_name: string;
80
+ first_name: string;
81
+ utm_source: string | null;
82
+ recalculate: boolean;
83
+ utm_campaign: string | null;
84
+ }
85
+ export interface LifeAutofillData {
86
+ Sex: string;
87
+ uuid: string;
88
+ City: string;
89
+ State: string;
90
+ Health: string;
91
+ Smoker: string;
92
+ Birthday: string;
93
+ ModeUsed: string;
94
+ email_to: string;
95
+ BirthYear: string;
96
+ BirthMonth: string;
97
+ FaceAmount: number;
98
+ IsUsaQuote: boolean;
99
+ PostalCode: string;
100
+ NewCategory: string;
101
+ quoter_info: LifeAutofillQuoterInfo;
102
+ }
@@ -0,0 +1,8 @@
1
+ interface AutofillOptions {
2
+ onComplete?: () => void;
3
+ }
4
+ /**
5
+ * Hook to initialize life insurance form with autofill data from query parameter
6
+ */
7
+ export declare const useAutofillLifeForm: (options?: AutofillOptions) => void;
8
+ export {};
@@ -92,3 +92,51 @@ export declare const mapToDriverState: (autofillData: AutofillData) => {
92
92
  export declare const mapToConfigState: (autofillData: AutofillData) => {
93
93
  province: string;
94
94
  };
95
+ /**
96
+ * Parse URL-encoded JSON from query parameter for life insurance
97
+ */
98
+ export declare const parseLifeAutofillParam: (urlEncodedJson: string) => any;
99
+ /**
100
+ * Get province code from state number
101
+ */
102
+ export declare const getProvinceCodeFromState: (stateNumber: string) => string;
103
+ /**
104
+ * Map life autofill data to coverage state format
105
+ */
106
+ export declare const mapToLifeCoverageState: (autofillData: any) => {
107
+ province: string;
108
+ type: any;
109
+ coverage: string;
110
+ postalCode: any;
111
+ city: any;
112
+ };
113
+ /**
114
+ * Map life autofill data to applicant state format
115
+ */
116
+ export declare const mapToLifeApplicantState: (autofillData: any) => {
117
+ birthYear: any;
118
+ birthMonth: any;
119
+ birthDay: any;
120
+ gender: any;
121
+ smoker: boolean;
122
+ emailTo: {
123
+ email: any;
124
+ };
125
+ quoterInfo: {
126
+ firstName: any;
127
+ lastName: any;
128
+ phone: string;
129
+ utmSource: any;
130
+ utmCampaign: any;
131
+ };
132
+ };
133
+ /**
134
+ * Map life autofill data to postal state format
135
+ */
136
+ export declare const mapToLifePostalState: (autofillData: any) => {
137
+ postalCode: any;
138
+ provinceCode: string;
139
+ provinceName: string;
140
+ city: any;
141
+ locationIndex: string;
142
+ };
package/dist/esm/index.js CHANGED
@@ -6823,6 +6823,83 @@ const mapToConfigState = (autofillData) => {
6823
6823
  province: autofillData.province_code || '',
6824
6824
  };
6825
6825
  };
6826
+ // Life insurance autofill utilities
6827
+ // State number to province code mapping (reverse of stateMapper in LifeQuoteDataHandler)
6828
+ const STATE_TO_PROVINCE_CODE_MAP = {
6829
+ '1': 'AB',
6830
+ '2': 'BC',
6831
+ '3': 'MB',
6832
+ '4': 'NB',
6833
+ '5': 'NF',
6834
+ '6': 'NS',
6835
+ '7': 'NT',
6836
+ '9': 'ON',
6837
+ '10': 'PE',
6838
+ '11': 'QC',
6839
+ '12': 'SK',
6840
+ '13': 'YT',
6841
+ };
6842
+ /**
6843
+ * Parse URL-encoded JSON from query parameter for life insurance
6844
+ */
6845
+ const parseLifeAutofillParam = (urlEncodedJson) => {
6846
+ const decoded = decodeURIComponent(urlEncodedJson);
6847
+ return JSON.parse(decoded);
6848
+ };
6849
+ /**
6850
+ * Get province code from state number
6851
+ */
6852
+ const getProvinceCodeFromState = (stateNumber) => {
6853
+ return STATE_TO_PROVINCE_CODE_MAP[stateNumber] || '';
6854
+ };
6855
+ /**
6856
+ * Map life autofill data to coverage state format
6857
+ */
6858
+ const mapToLifeCoverageState = (autofillData) => {
6859
+ const provinceCode = getProvinceCodeFromState(autofillData.State || '');
6860
+ return {
6861
+ province: provinceCode,
6862
+ type: autofillData.NewCategory || '',
6863
+ coverage: String(autofillData.FaceAmount || ''),
6864
+ postalCode: autofillData.PostalCode || '',
6865
+ city: autofillData.City || '',
6866
+ };
6867
+ };
6868
+ /**
6869
+ * Map life autofill data to applicant state format
6870
+ */
6871
+ const mapToLifeApplicantState = (autofillData) => {
6872
+ return {
6873
+ birthYear: autofillData.BirthYear || '',
6874
+ birthMonth: autofillData.BirthMonth || '',
6875
+ birthDay: autofillData.Birthday || '',
6876
+ gender: autofillData.Sex || 'M',
6877
+ smoker: autofillData.Smoker === 'Y',
6878
+ emailTo: {
6879
+ email: autofillData.email_to || '',
6880
+ },
6881
+ quoterInfo: {
6882
+ firstName: autofillData.quoter_info?.first_name || '',
6883
+ lastName: autofillData.quoter_info?.last_name || '',
6884
+ phone: autofillData.quoter_info?.phone ? String(autofillData.quoter_info.phone) : '',
6885
+ utmSource: autofillData.quoter_info?.utm_source || '',
6886
+ utmCampaign: autofillData.quoter_info?.utm_campaign || '',
6887
+ },
6888
+ };
6889
+ };
6890
+ /**
6891
+ * Map life autofill data to postal state format
6892
+ */
6893
+ const mapToLifePostalState = (autofillData) => {
6894
+ const provinceCode = getProvinceCodeFromState(autofillData.State || '');
6895
+ return {
6896
+ postalCode: autofillData.PostalCode || '',
6897
+ provinceCode,
6898
+ provinceName: getProvinceName(provinceCode),
6899
+ city: autofillData.City || '',
6900
+ locationIndex: '',
6901
+ };
6902
+ };
6826
6903
 
6827
6904
  /**
6828
6905
  * Hook to initialize car insurance form with autofill data from query parameter
@@ -7168,5 +7245,180 @@ const useAutofillCarForm = (options) => {
7168
7245
  ]);
7169
7246
  };
7170
7247
 
7171
- export { CarBrokerTypeEnum, CarQuoteDataHandler, ClearFormDataHandler, HomeBrokerTypeEnum, HomeQuoteDataHandler, LifeQuoteDataHandler, StoreClientActionTypes, StoreConfigAppConfigActionTypes, StoreConfigAppDeviceActionTypes, StoreConfigAppLoaderActionTypes, StoreConfigAppModalActionTypes, StoreFormCarConfigActionTypes, StoreFormCarDiscountActionTypes, StoreFormCarDriverAccidentActionTypes, StoreFormCarDriverBaseActionTypes, StoreFormCarDriverCancellationActionTypes, StoreFormCarDriverInfoActionTypes, StoreFormCarDriverInsuranceActionTypes, StoreFormCarDriverLicenceActionTypes, StoreFormCarDriverSuspensionActionTypes, StoreFormCarDriverTicketActionTypes, StoreFormCarPostalActionTypes, StoreFormCarQuoteActionTypes, StoreFormCarVehicleActionTypes, StoreFormHomeApplicantBaseActionTypes, StoreFormHomeApplicantCancellationActionTypes, StoreFormHomeApplicantClaimActionTypes, StoreFormHomeApplicantInfoActionTypes, StoreFormHomeApplicantInsuranceActionTypes, StoreFormHomeDiscountActionTypes, StoreFormHomeDwellingActionTypes, StoreFormHomePostalActionTypes, StoreFormHomeQuoteActionTypes, StoreFormLifeApplicantActionTypes, StoreFormLifeCoverageActionTypes, StoreFormLifePostalActionTypes, StoreFormLifeQuoteActionTypes, StorePartnerActionTypes, StoreProvider, addDayToDate, configStateReducer, differenceInHoursFromNow, formCarReducer, formCondoDwellingInitialState, formHomeDwellingInitialState, formHomeReducer, formLifeReducer, formTenantDwellingInitialState, getDwellingInitialState, getProvinceName, globalStateReducer, initHttpResponse, mapToConfigState, mapToDriverState, mapToPostalState, mapToVehicleState, parseAutofillParam, reducers, default_1 as token, useAutofillCarForm, useHandlerAuth, useHandlerCarMake, useHandlerCarModel, useHandlerCarQuoterEmail, useHandlerHomeQuoterEmail, useHandlerLifeQuoterEmail, useHandlerPartner, useHandlerPostal, useProvince, useStoreAppConfig, useStoreAppDevice, useStoreAppLoader, useStoreAppModal, useStoreClient, useStoreClientLoggedIn, useStoreClientProfile, useStoreClientToken, useStoreDeviceBP, useStoreDeviceType, useStoreFormCarConfig, useStoreFormCarDiscount, useStoreFormCarDriverAccident, useStoreFormCarDriverBase, useStoreFormCarDriverCancellation, useStoreFormCarDriverInfo, useStoreFormCarDriverInsurance, useStoreFormCarDriverLicence, useStoreFormCarDriverSuspension, useStoreFormCarDriverTicket, useStoreFormCarPostal, useStoreFormCarQuote, useStoreFormCarVehicle, useStoreFormHomeApplicantBase, useStoreFormHomeApplicantCancellation, useStoreFormHomeApplicantClaim, useStoreFormHomeApplicantInfo, useStoreFormHomeApplicantInsurance, useStoreFormHomeDiscount, useStoreFormHomeDwelling, useStoreFormHomePostal, useStoreFormHomeQuote, useStoreFormLifeApplicant, useStoreFormLifeCoverage, useStoreFormLifePostal, useStoreFormLifeQuote, useStorePartner, useValidationAddress, useValidationApplicant, useValidationCarDiscount, useValidationCoverage, useValidationDriver, useValidationDwelling, useValidationHomeDiscount, useValidationLifeApplicant, useValidationVehicle };
7248
+ /**
7249
+ * Hook to initialize life insurance form with autofill data from query parameter
7250
+ */
7251
+ const useAutofillLifeForm = (options) => {
7252
+ const { dispatchPostalState } = useStoreFormLifePostal();
7253
+ const { dispatchCoverageState } = useStoreFormLifeCoverage();
7254
+ const { dispatchApplicantState } = useStoreFormLifeApplicant();
7255
+ const { dispatchAppModalState } = useStoreAppModal();
7256
+ const autofillProcessedRef = useRef(false);
7257
+ useEffect(() => {
7258
+ // Prevent double execution in development strict mode
7259
+ if (autofillProcessedRef.current) {
7260
+ return;
7261
+ }
7262
+ try {
7263
+ const urlParams = new URLSearchParams(window.location.search);
7264
+ const autofillParam = urlParams.get('autofill');
7265
+ if (!autofillParam) {
7266
+ return;
7267
+ }
7268
+ // Parse the autofill data
7269
+ const autofillData = parseLifeAutofillParam(autofillParam);
7270
+ // Map and dispatch postal state
7271
+ const postalData = mapToLifePostalState(autofillData);
7272
+ dispatchPostalState({
7273
+ type: StoreFormLifePostalActionTypes.FormLifePostalSet,
7274
+ payload: postalData,
7275
+ });
7276
+ // Close the postal modal since we have postal data from autofill
7277
+ dispatchAppModalState({
7278
+ type: StoreConfigAppModalActionTypes.AppModalClose,
7279
+ });
7280
+ // Map and dispatch coverage state
7281
+ const coverageData = mapToLifeCoverageState(autofillData);
7282
+ // Dispatch province
7283
+ dispatchCoverageState({
7284
+ type: StoreFormLifeCoverageActionTypes.FormLifeProvinceSelect,
7285
+ payload: {
7286
+ province: coverageData.province,
7287
+ },
7288
+ });
7289
+ // Dispatch coverage type
7290
+ dispatchCoverageState({
7291
+ type: StoreFormLifeCoverageActionTypes.FormLifeCoverageTypeSelect,
7292
+ payload: {
7293
+ type: coverageData.type,
7294
+ },
7295
+ });
7296
+ // Dispatch coverage amount
7297
+ dispatchCoverageState({
7298
+ type: StoreFormLifeCoverageActionTypes.FormLifeCoverageSelect,
7299
+ payload: {
7300
+ coverage: coverageData.coverage,
7301
+ },
7302
+ });
7303
+ // Dispatch postal code
7304
+ dispatchCoverageState({
7305
+ type: StoreFormLifeCoverageActionTypes.FormLifePostalCodeSelect,
7306
+ payload: {
7307
+ postalCode: coverageData.postalCode,
7308
+ },
7309
+ });
7310
+ // Dispatch city
7311
+ if (coverageData.city) {
7312
+ dispatchCoverageState({
7313
+ type: StoreFormLifeCoverageActionTypes.FormLifeCitySelect,
7314
+ payload: {
7315
+ city: coverageData.city,
7316
+ },
7317
+ });
7318
+ }
7319
+ // Map and dispatch applicant state
7320
+ const applicantData = mapToLifeApplicantState(autofillData);
7321
+ // Dispatch birth year
7322
+ dispatchApplicantState({
7323
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthYearSelect,
7324
+ payload: {
7325
+ birthYear: applicantData.birthYear,
7326
+ },
7327
+ });
7328
+ // Dispatch birth month
7329
+ dispatchApplicantState({
7330
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthMonthSelect,
7331
+ payload: {
7332
+ birthMonth: applicantData.birthMonth,
7333
+ },
7334
+ });
7335
+ // Dispatch birth day
7336
+ dispatchApplicantState({
7337
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthDaySelect,
7338
+ payload: {
7339
+ birthDay: applicantData.birthDay,
7340
+ },
7341
+ });
7342
+ // Dispatch gender
7343
+ dispatchApplicantState({
7344
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantGenderSelect,
7345
+ payload: {
7346
+ gender: applicantData.gender,
7347
+ },
7348
+ });
7349
+ // Dispatch smoker status
7350
+ dispatchApplicantState({
7351
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantSmokerSelect,
7352
+ payload: {
7353
+ smoker: applicantData.smoker,
7354
+ },
7355
+ });
7356
+ // Dispatch email
7357
+ if (applicantData.emailTo.email) {
7358
+ dispatchApplicantState({
7359
+ type: StoreFormLifeApplicantActionTypes.FormLifeApplicantEmailSet,
7360
+ payload: {
7361
+ email: applicantData.emailTo.email,
7362
+ emailStatus: ValidationStatusTypes.Approved,
7363
+ },
7364
+ });
7365
+ }
7366
+ // Dispatch quoter info - first name
7367
+ if (applicantData.quoterInfo.firstName) {
7368
+ dispatchApplicantState({
7369
+ type: StoreFormLifeApplicantActionTypes.FormLifeQuoterFirstNameSet,
7370
+ payload: {
7371
+ firstName: applicantData.quoterInfo.firstName,
7372
+ },
7373
+ });
7374
+ }
7375
+ // Dispatch quoter info - last name
7376
+ if (applicantData.quoterInfo.lastName) {
7377
+ dispatchApplicantState({
7378
+ type: StoreFormLifeApplicantActionTypes.FormLifeQuoterLastNameSet,
7379
+ payload: {
7380
+ lastName: applicantData.quoterInfo.lastName,
7381
+ },
7382
+ });
7383
+ }
7384
+ // Dispatch quoter info - phone
7385
+ if (applicantData.quoterInfo.phone) {
7386
+ dispatchApplicantState({
7387
+ type: StoreFormLifeApplicantActionTypes.FormLifeQuoterPhoneSet,
7388
+ payload: {
7389
+ phone: applicantData.quoterInfo.phone,
7390
+ },
7391
+ });
7392
+ }
7393
+ // Dispatch quoter info - utm source
7394
+ if (applicantData.quoterInfo.utmSource) {
7395
+ dispatchApplicantState({
7396
+ type: StoreFormLifeApplicantActionTypes.FormLifeUtmSourceSet,
7397
+ payload: {
7398
+ utmSource: applicantData.quoterInfo.utmSource,
7399
+ },
7400
+ });
7401
+ }
7402
+ // Dispatch quoter info - utm campaign
7403
+ if (applicantData.quoterInfo.utmCampaign) {
7404
+ dispatchApplicantState({
7405
+ type: StoreFormLifeApplicantActionTypes.FormLifeUtmCampaignSet,
7406
+ payload: {
7407
+ utmCampaign: applicantData.quoterInfo.utmCampaign,
7408
+ },
7409
+ });
7410
+ }
7411
+ autofillProcessedRef.current = true;
7412
+ if (options?.onComplete) {
7413
+ options.onComplete();
7414
+ }
7415
+ }
7416
+ catch (error) {
7417
+ // Silently fail - let the app continue with normal flow
7418
+ console.error('Life autofill initialization error:', error);
7419
+ }
7420
+ }, [dispatchPostalState, dispatchCoverageState, dispatchApplicantState, dispatchAppModalState]);
7421
+ };
7422
+
7423
+ export { CarBrokerTypeEnum, CarQuoteDataHandler, ClearFormDataHandler, HomeBrokerTypeEnum, HomeQuoteDataHandler, LifeQuoteDataHandler, StoreClientActionTypes, StoreConfigAppConfigActionTypes, StoreConfigAppDeviceActionTypes, StoreConfigAppLoaderActionTypes, StoreConfigAppModalActionTypes, StoreFormCarConfigActionTypes, StoreFormCarDiscountActionTypes, StoreFormCarDriverAccidentActionTypes, StoreFormCarDriverBaseActionTypes, StoreFormCarDriverCancellationActionTypes, StoreFormCarDriverInfoActionTypes, StoreFormCarDriverInsuranceActionTypes, StoreFormCarDriverLicenceActionTypes, StoreFormCarDriverSuspensionActionTypes, StoreFormCarDriverTicketActionTypes, StoreFormCarPostalActionTypes, StoreFormCarQuoteActionTypes, StoreFormCarVehicleActionTypes, StoreFormHomeApplicantBaseActionTypes, StoreFormHomeApplicantCancellationActionTypes, StoreFormHomeApplicantClaimActionTypes, StoreFormHomeApplicantInfoActionTypes, StoreFormHomeApplicantInsuranceActionTypes, StoreFormHomeDiscountActionTypes, StoreFormHomeDwellingActionTypes, StoreFormHomePostalActionTypes, StoreFormHomeQuoteActionTypes, StoreFormLifeApplicantActionTypes, StoreFormLifeCoverageActionTypes, StoreFormLifePostalActionTypes, StoreFormLifeQuoteActionTypes, StorePartnerActionTypes, StoreProvider, addDayToDate, configStateReducer, differenceInHoursFromNow, formCarReducer, formCondoDwellingInitialState, formHomeDwellingInitialState, formHomeReducer, formLifeReducer, formTenantDwellingInitialState, getDwellingInitialState, getProvinceCodeFromState, getProvinceName, globalStateReducer, initHttpResponse, mapToConfigState, mapToDriverState, mapToLifeApplicantState, mapToLifeCoverageState, mapToLifePostalState, mapToPostalState, mapToVehicleState, parseAutofillParam, parseLifeAutofillParam, reducers, default_1 as token, useAutofillCarForm, useAutofillLifeForm, useHandlerAuth, useHandlerCarMake, useHandlerCarModel, useHandlerCarQuoterEmail, useHandlerHomeQuoterEmail, useHandlerLifeQuoterEmail, useHandlerPartner, useHandlerPostal, useProvince, useStoreAppConfig, useStoreAppDevice, useStoreAppLoader, useStoreAppModal, useStoreClient, useStoreClientLoggedIn, useStoreClientProfile, useStoreClientToken, useStoreDeviceBP, useStoreDeviceType, useStoreFormCarConfig, useStoreFormCarDiscount, useStoreFormCarDriverAccident, useStoreFormCarDriverBase, useStoreFormCarDriverCancellation, useStoreFormCarDriverInfo, useStoreFormCarDriverInsurance, useStoreFormCarDriverLicence, useStoreFormCarDriverSuspension, useStoreFormCarDriverTicket, useStoreFormCarPostal, useStoreFormCarQuote, useStoreFormCarVehicle, useStoreFormHomeApplicantBase, useStoreFormHomeApplicantCancellation, useStoreFormHomeApplicantClaim, useStoreFormHomeApplicantInfo, useStoreFormHomeApplicantInsurance, useStoreFormHomeDiscount, useStoreFormHomeDwelling, useStoreFormHomePostal, useStoreFormHomeQuote, useStoreFormLifeApplicant, useStoreFormLifeCoverage, useStoreFormLifePostal, useStoreFormLifeQuote, useStorePartner, useValidationAddress, useValidationApplicant, useValidationCarDiscount, useValidationCoverage, useValidationDriver, useValidationDwelling, useValidationHomeDiscount, useValidationLifeApplicant, useValidationVehicle };
7172
7424
  //# sourceMappingURL=index.js.map