@star-insure/sdk 1.1.17 → 1.1.19

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/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.17",
5
+ "version": "1.1.19",
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
@@ -10,3 +10,4 @@ export * from './quoteRequestForm';
10
10
  export * from './quoteRequestOptions';
11
11
  export * from './addressFinder';
12
12
  export * from './calculateAge';
13
+ export * from './calculatePricing';
@@ -0,0 +1,22 @@
1
+ import { User } from "../auth";
2
+
3
+ export interface BlacklistEntry {
4
+ id?: number;
5
+ created_at?: string;
6
+ name?: string;
7
+ description?: string;
8
+ profiles?: BlacklistEntryProfile[];
9
+ user_id?: number;
10
+ user?: User;
11
+ }
12
+
13
+ export interface BlacklistEntryProfile {
14
+ id?: number;
15
+ created_at?: string;
16
+ email?: string;
17
+ client_number?: string;
18
+ phone?: string;
19
+ mobile?: string;
20
+ registration?: string;
21
+ blacklist_entry_id: BlacklistEntry['id'];
22
+ }
@@ -1,3 +1,4 @@
1
+ import { BlacklistEntry } from "./Blacklist";
1
2
  import { Club } from "./Club";
2
3
  import { InformationRequest } from "./InformationRequest";
3
4
  import { Lead } from "./Lead";
@@ -72,6 +73,7 @@ export interface QuoteRequest {
72
73
  broker_id?: QuoteRequestUser['id'];
73
74
  club_id?: Club['id'];
74
75
  lead_id?: Lead['id'];
76
+ blacklist_entry_id?: BlacklistEntry['id'];
75
77
 
76
78
  // Relationships
77
79
  declaration?: QuoteRequestDeclaration;
@@ -96,5 +98,6 @@ export interface QuoteRequest {
96
98
  purchase_preview: string;
97
99
  purchase_options_pdf: string;
98
100
  documentation_pdf: string;
99
- }
101
+ },
102
+ blacklist_entry?: BlacklistEntry;
100
103
  }
@@ -20,3 +20,4 @@ export * from './InformationRequest';
20
20
  export * from './EmailContentOption';
21
21
  export * from './MotorwebVehicle';
22
22
  export * from './PromoCode';
23
+ export * from './Blacklist';