@star-insure/sdk 1.1.18 → 1.1.20
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/lib/calculatePricing.d.ts +14 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/inertiaOptions.d.ts +1 -1
- package/dist/sdk.cjs.development.js +81 -3
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +80 -4
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/models/quotes/QuoteRequest.d.ts +1 -2
- package/package.json +1 -1
- package/src/lib/calculatePricing.tsx +64 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/inertiaOptions.tsx +1 -1
- package/src/lib/quoteRequestForm.tsx +1 -1
- package/src/types/models/quotes/QuoteRequest.ts +1 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@star-insure/sdk",
|
|
3
3
|
"description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
|
|
4
4
|
"author": "alexclark_nz",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.20",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { addGst } from ".";
|
|
2
|
+
import type { PolicyEnhancement, QuoteRequestPurchaseOption } from "../types";
|
|
3
|
+
|
|
4
|
+
interface CalculationArguments {
|
|
5
|
+
option: QuoteRequestPurchaseOption;
|
|
6
|
+
selectedEnhancements: PolicyEnhancement['id'][];
|
|
7
|
+
brokerFee?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function calculateMonthly({ option, selectedEnhancements }: CalculationArguments) {
|
|
11
|
+
const premium = option.monthly_premium || 0;
|
|
12
|
+
|
|
13
|
+
const enhancementsCost = selectedEnhancements.reduce((acc, id) => {
|
|
14
|
+
const enhancement = option.enhancements?.find(e => e.id === id);
|
|
15
|
+
if (!enhancement) return acc;
|
|
16
|
+
const enhancementPremium = calcMonthlyEnhancementPrice(enhancement);
|
|
17
|
+
|
|
18
|
+
if (!acc) {
|
|
19
|
+
return enhancementPremium;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return acc + enhancementPremium;
|
|
23
|
+
}, 0) || 0;
|
|
24
|
+
|
|
25
|
+
return premium + enhancementsCost;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function calculateAnnually({ option, selectedEnhancements, brokerFee = 0 }: CalculationArguments) {
|
|
29
|
+
const premium = option.premium || 0;
|
|
30
|
+
const fsl = option.fsl || 0;
|
|
31
|
+
const enhancementsCost = selectedEnhancements.reduce((acc, id) => {
|
|
32
|
+
const enhancement = option.enhancements?.find(e => e.id === id);
|
|
33
|
+
if (!enhancement) return acc;
|
|
34
|
+
return (acc || 0) + (enhancement.premium || 0);
|
|
35
|
+
}, 0) || 0;
|
|
36
|
+
|
|
37
|
+
return premium + fsl + enhancementsCost + brokerFee;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function calcMonthlyEnhancementPrice(enhancement: PolicyEnhancement): number {
|
|
41
|
+
if (!enhancement.premium) return 0;
|
|
42
|
+
|
|
43
|
+
const monthlyPremium = (enhancement.premium / 100) / 12;
|
|
44
|
+
|
|
45
|
+
if (enhancement.disable_rounding) {
|
|
46
|
+
return Math.round(monthlyPremium * 100);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return Math.round(Math.ceil(monthlyPremium) * 100);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function calcPurchaseOptionPricing({ option, selectedEnhancements, brokerFee = 0 }: CalculationArguments) {
|
|
53
|
+
const monthly = calculateMonthly({ option, selectedEnhancements });
|
|
54
|
+
const annually = calculateAnnually({ option, selectedEnhancements, brokerFee });
|
|
55
|
+
const monthlyWithGst = addGst(monthly);
|
|
56
|
+
const annuallyWithGst = addGst(annually);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
monthly,
|
|
60
|
+
annually,
|
|
61
|
+
monthlyWithGst,
|
|
62
|
+
annuallyWithGst,
|
|
63
|
+
};
|
|
64
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface Options {
|
|
|
5
5
|
successMessage?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function useInertiaOptions({ successMessage = '' }: Options): VisitOptions {
|
|
8
|
+
export function useInertiaOptions({ successMessage = '' }: Options = {}): VisitOptions {
|
|
9
9
|
const { addToast } = useToast();
|
|
10
10
|
|
|
11
11
|
return {
|
|
@@ -13,7 +13,7 @@ import { StreetAddress } from "./StreetAddress";
|
|
|
13
13
|
|
|
14
14
|
export type QuoteRequestStatus = 'new' | 'draft' | 'in-progress' | 'with-customer' | 'sold' | 'bound' | 'customer-modified' | 'closed';
|
|
15
15
|
|
|
16
|
-
export type QuoteRequestSource = 'web' | 'phone' | 'show' | 'existing-customer' | 'mighway' | 'agent' | 'entry-form' | 'bularangi';
|
|
16
|
+
export type QuoteRequestSource = 'web' | 'phone' | 'show' | 'existing-customer' | 'mighway' | 'agent' | 'broker' | 'entry-form' | 'bularangi';
|
|
17
17
|
|
|
18
18
|
export type QuoteRequestAutomatch = 'quote' | 'email' | 'registration' | 'duplicate';
|
|
19
19
|
|
|
@@ -44,7 +44,6 @@ export interface QuoteRequest {
|
|
|
44
44
|
licence_other?: string;
|
|
45
45
|
has_automatch?: boolean;
|
|
46
46
|
automatch_by?: QuoteRequestAutomatch;
|
|
47
|
-
automatch_client_id?: string;
|
|
48
47
|
automatch_registrations?: string;
|
|
49
48
|
promo_code?: string;
|
|
50
49
|
club_membership_number?: string;
|