@star-insure/sdk 2.5.2 → 3.0.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.
@@ -1,5 +1,5 @@
1
- import { Product, VehicleType } from "../../api";
2
- import { QuoteRequestVehicleDriver } from "./QuoteRequestVehicleDriver";
1
+ import { Product, VehicleType } from '../../api';
2
+ import { QuoteRequestVehicleDriver } from './QuoteRequestVehicleDriver';
3
3
  export interface QuoteRequestVehicle {
4
4
  id?: number;
5
5
  vehicle_type?: VehicleType;
@@ -14,6 +14,7 @@ export interface QuoteRequestVehicle {
14
14
  owned_duration?: string;
15
15
  value?: number;
16
16
  storage_location?: string;
17
+ storage_location_other?: string;
17
18
  is_heavy?: boolean;
18
19
  quote_request_id?: string;
19
20
  drivers?: QuoteRequestVehicleDriver[];
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": "2.5.2",
5
+ "version": "3.0.1",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -3,168 +3,212 @@ import { Button } from '../common';
3
3
  import { useQuoteRequestForm } from '../../lib';
4
4
 
5
5
  interface Props {
6
- populatePurchaseOptions: boolean;
6
+ populatePurchaseOptions: boolean;
7
7
  }
8
8
 
9
9
  export default function FormTester({ populatePurchaseOptions = false }: Props) {
10
- const { form } = useQuoteRequestForm();
11
- const [keys, setKeys] = React.useState<string[]>([]);
12
- const [isDev, setDev] = React.useState<boolean>(false);
10
+ const { form } = useQuoteRequestForm();
11
+ const [keys, setKeys] = React.useState<string[]>([]);
12
+ const [isDev, setDev] = React.useState<boolean>(false);
13
13
 
14
- function handlePopulate() {
15
- form?.setData(prevData => ({
16
- ...prevData,
17
- first_name: 'TEST',
18
- last_name: 'TEST',
19
- email: 'dev@sual.co.nz',
20
- phone: '021 234 5678',
21
- mobile: '021 234 5678',
22
- dob: '1990-01-01',
23
- licence: 'Other',
24
- licence_other: 'Test',
25
- club_id: 50,
26
- club_membership_number: '12345',
27
- street_address: {
28
- address: '123 Street Name',
29
- unit: 'Level 1',
30
- suburb: 'Suburb',
31
- city: 'Auckland',
32
- post_code: '1234',
14
+ function handlePopulate() {
15
+ form?.setData(prevData => ({
16
+ ...prevData,
17
+ first_name: 'TEST',
18
+ last_name: 'TEST',
19
+ email: 'dev@sual.co.nz',
20
+ phone: '021 234 5678',
21
+ mobile: '021 234 5678',
22
+ dob: '1990-01-01',
23
+ licence: 'Other',
24
+ licence_other: 'Test',
25
+ club_id: 50,
26
+ club_membership_number: '12345',
27
+ street_address: {
28
+ address: '123 Street Name',
29
+ unit: 'Level 1',
30
+ suburb: 'Suburb',
31
+ city: 'Auckland',
32
+ post_code: '1234',
33
+ },
34
+ promo_code: 'TEST',
35
+ declaration: {
36
+ had_incident: true,
37
+ incidents: [
38
+ {
39
+ description: 'Lorem ipsum dolor sit amet.',
40
+ month: 'January',
41
+ year: '2020',
42
+ },
43
+ ],
44
+ has_demerit_points: true,
45
+ demerit_points: '1-24',
46
+ has_lost_licence: true,
47
+ lost_licence_details: 'Lorem ipsum dolor sit amet.',
48
+ was_refused_insurance: true,
49
+ refused_insurance_details: 'Lorem ipsum dolor sit amet.',
50
+ has_criminal_conviction: true,
51
+ criminal_conviction_details: 'Lorem ipsum dolor sit amet.',
52
+ has_vehicle_modifications: true,
53
+ vehicle_modifications_details: 'Lorem ipsum dolor sit amet.',
54
+ has_previous_insurer: true,
55
+ previous_insurer_details: 'AA',
56
+ previous_insurer_expires_at: '2020-01-01',
57
+ additional_details:
58
+ 'I am a robot, beep boop. Please ignore this submission.',
59
+ },
60
+ vehicles: [
61
+ {
62
+ make: 'Tesla',
63
+ model: 'Cybertruck',
64
+ year: '2023',
65
+ registration: 'ELMUSK',
66
+ vehicle_type: 'car',
67
+ product: 'star-enthusiast-prestige-everyday-plus',
68
+ value: 100000,
69
+ is_heavy: false,
70
+ usage: 'Childrens car',
71
+ storage_location: 'Carport',
72
+ has_financially_interested_party: true,
73
+ financially_interested_party_detail: 'MTA',
74
+ owned_duration: 'Less than 12 months',
75
+ main_driver: 'TEST TEST',
76
+ drivers: [
77
+ {
78
+ first_name: 'X Æ',
79
+ last_name: 'A-12',
80
+ dob: '2000-05-04',
81
+ licence: 'Other',
82
+ licence_other: 'None',
83
+ relationship: 'Child',
84
+ key: 'driver-test-key',
33
85
  },
34
- promo_code: 'TEST',
35
- declaration: {
36
- had_incident: true,
37
- incidents: [{
38
- description: 'Lorem ipsum dolor sit amet.',
39
- month: 'January',
40
- year: '2020',
41
- }],
42
- has_demerit_points: true,
43
- demerit_points: '1-24',
44
- has_lost_licence: true,
45
- lost_licence_details: 'Lorem ipsum dolor sit amet.',
46
- was_refused_insurance: true,
47
- refused_insurance_details: 'Lorem ipsum dolor sit amet.',
48
- has_criminal_conviction: true,
49
- criminal_conviction_details: 'Lorem ipsum dolor sit amet.',
50
- has_vehicle_modifications: true,
51
- vehicle_modifications_details: 'Lorem ipsum dolor sit amet.',
52
- has_previous_insurer: true,
53
- previous_insurer_details: 'AA',
54
- previous_insurer_expires_at: '2020-01-01',
55
- additional_details: 'I am a robot, beep boop. Please ignore this submission.',
56
- },
57
- vehicles: [
86
+ ],
87
+ key: 'vehicle-test-key',
88
+ },
89
+ ],
90
+ purchase_options: populatePurchaseOptions
91
+ ? [
92
+ {
93
+ premium_type: 'annual',
94
+ level_of_insurance_id: 12,
95
+ authorised_drivers: 'TEST',
96
+ excess_details: 'TEST',
97
+ terms: 'TEST',
98
+ description: 'This is a test purchase option',
99
+ premium: 100000,
100
+ monthly_premium: 8500,
101
+ show_monthly: true,
102
+ fsl: 100,
103
+ sort_order: 1,
104
+ enhancements: [
58
105
  {
59
- make: 'Tesla',
60
- model: 'Cybertruck',
61
- year: '2023',
62
- registration: 'ELMUSK',
63
- vehicle_type: 'car',
64
- product: 'star-enthusiast-prestige-everyday-plus',
65
- value: 100000,
66
- is_heavy: false,
67
- usage: 'Childrens car',
68
- storage_location: 'Carport',
69
- has_financially_interested_party: true,
70
- financially_interested_party_detail: 'MTA',
71
- owned_duration: 'Less than 12 months',
72
- drivers: [
73
- {
74
- first_name: 'X Æ',
75
- last_name: 'A-12',
76
- dob: '2000-05-04',
77
- licence: 'Other',
78
- licence_other: 'None',
79
- relationship: 'Child',
80
- key: 'driver-test-key',
81
- }
82
- ],
83
- key: 'vehicle-test-key',
106
+ name: 'Test enhancement',
107
+ premium: 2500,
108
+ disable_rounding: false,
109
+ description: 'Test enhancement',
110
+ auto_select: true,
111
+ key: 'enhancement-test-key-1',
84
112
  },
85
- ],
86
- purchase_options: populatePurchaseOptions ? [
87
113
  {
88
- premium_type: 'annual',
89
- level_of_insurance_id: 12,
90
- authorised_drivers: 'TEST',
91
- excess_details: 'TEST',
92
- terms: 'TEST',
93
- description: 'This is a test purchase option',
94
- premium: 100000,
95
- monthly_premium: 8500,
96
- show_monthly: true,
97
- fsl: 100,
98
- sort_order: 1,
99
- enhancements: [
100
- { name: 'Test enhancement', premium: 2500, disable_rounding: false, description: 'Test enhancement', auto_select: true, key: 'enhancement-test-key-1' },
101
- { name: 'Test enhancement', premium: 5000, disable_rounding: false, description: 'Test enhancement', auto_select: false, key: 'enhancement-test-key-2' }
102
- ],
103
- key: 'purchase-option-test-key-annual'
114
+ name: 'Test enhancement',
115
+ premium: 5000,
116
+ disable_rounding: false,
117
+ description: 'Test enhancement',
118
+ auto_select: false,
119
+ key: 'enhancement-test-key-2',
104
120
  },
121
+ ],
122
+ key: 'purchase-option-test-key-annual',
123
+ },
124
+ {
125
+ premium_type: 'total-due',
126
+ level_of_insurance_id: 13,
127
+ authorised_drivers: 'TEST',
128
+ excess_details: 'TEST',
129
+ terms: 'TEST',
130
+ description: 'This is a test purchase option',
131
+ premium: 100000,
132
+ show_monthly: false,
133
+ fsl: 100,
134
+ sort_order: 2,
135
+ enhancements: [
105
136
  {
106
- premium_type: 'total-due',
107
- level_of_insurance_id: 13,
108
- authorised_drivers: 'TEST',
109
- excess_details: 'TEST',
110
- terms: 'TEST',
111
- description: 'This is a test purchase option',
112
- premium: 100000,
113
- show_monthly: false,
114
- fsl: 100,
115
- sort_order: 2,
116
- enhancements: [
117
- { name: 'Test enhancement', premium: 2500, disable_rounding: false, description: 'Test enhancement', auto_select: true, key: 'enhancement-test-key-3' },
118
- { name: 'Test enhancement', premium: 5000, disable_rounding: false, description: 'Test enhancement', auto_select: false, key: 'enhancement-test-key-4' }
119
- ],
120
- key: 'purchase-option-test-key-total-due'
121
- }
122
- ] : [],
123
- }))
137
+ name: 'Test enhancement',
138
+ premium: 2500,
139
+ disable_rounding: false,
140
+ description: 'Test enhancement',
141
+ auto_select: true,
142
+ key: 'enhancement-test-key-3',
143
+ },
144
+ {
145
+ name: 'Test enhancement',
146
+ premium: 5000,
147
+ disable_rounding: false,
148
+ description: 'Test enhancement',
149
+ auto_select: false,
150
+ key: 'enhancement-test-key-4',
151
+ },
152
+ ],
153
+ key: 'purchase-option-test-key-total-due',
154
+ },
155
+ ]
156
+ : [],
157
+ }));
158
+ }
159
+
160
+ function handleKeydown(e: KeyboardEvent) {
161
+ if (e.key === 'Escape') {
162
+ return setKeys([]);
124
163
  }
125
164
 
126
- function handleKeydown(e: KeyboardEvent) {
127
- if (e.key === 'Escape') {
128
- return setKeys([]);
129
- }
165
+ setKeys(prevKeys => [...prevKeys, e.key]);
166
+ }
130
167
 
131
- setKeys(prevKeys => [...prevKeys, e.key]);
168
+ React.useEffect(() => {
169
+ // Detect when the user has typed the word "debug"
170
+ if (keys.join('') === 'debug') {
171
+ handlePopulate();
132
172
  }
173
+ }, [keys]);
133
174
 
134
- React.useEffect(() => {
135
- // Detect when the user has typed the word "debug"
136
- if (keys.join('') === 'debug') {
137
- handlePopulate();
138
- }
139
- }, [keys]);
140
-
141
- React.useEffect(() => {
142
- if (typeof window !== 'undefined') {
143
- if (window.location.href.includes('dev')
144
- || window.location.href.includes('localhost')
145
- || window.location.href.includes('test')
146
- || window.location.href.includes('local')
147
- ) {
148
- setDev(true);
149
- }
175
+ React.useEffect(() => {
176
+ if (typeof window !== 'undefined') {
177
+ if (
178
+ window.location.href.includes('dev') ||
179
+ window.location.href.includes('localhost') ||
180
+ window.location.href.includes('test') ||
181
+ window.location.href.includes('local')
182
+ ) {
183
+ setDev(true);
184
+ }
150
185
 
151
- window.addEventListener('keydown', (e: KeyboardEvent) => handleKeydown(e));
186
+ window.addEventListener('keydown', (e: KeyboardEvent) =>
187
+ handleKeydown(e)
188
+ );
152
189
 
153
- return () => {
154
- window.removeEventListener('keydown', (e: KeyboardEvent) => handleKeydown(e));
155
- }
156
- }
190
+ return () => {
191
+ window.removeEventListener('keydown', (e: KeyboardEvent) =>
192
+ handleKeydown(e)
193
+ );
194
+ };
195
+ }
157
196
 
158
- return;
159
- }, []);
197
+ return;
198
+ }, []);
160
199
 
161
- if (isDev) {
162
- return (
163
- <Button onClick={handlePopulate} type="button" status="primary" className="fixed bottom-4 right-4">
164
- Populate data
165
- </Button>
166
- )
167
- }
200
+ if (isDev) {
201
+ return (
202
+ <Button
203
+ onClick={handlePopulate}
204
+ type="button"
205
+ status="primary"
206
+ className="fixed bottom-4 right-4"
207
+ >
208
+ Populate data
209
+ </Button>
210
+ );
211
+ }
168
212
 
169
- return <></>;
213
+ return <></>;
170
214
  }
package/src/lib/auth.tsx CHANGED
@@ -14,5 +14,15 @@ interface AppPage extends Page {
14
14
  export function useAuth(): AuthContext {
15
15
  const { props } = usePage() as AppPage;
16
16
 
17
- return props.auth;
17
+ /**
18
+ * Check if the user has permission to perform the given ability.
19
+ */
20
+ function can(ability: string): boolean {
21
+ return props.auth.permissions.includes(ability);
22
+ }
23
+
24
+ return {
25
+ ...props.auth,
26
+ can,
27
+ };
18
28
  }
@@ -1,11 +1,37 @@
1
- import { User, Group } from "../models";
1
+ export type UserContext =
2
+ | 'staff'
3
+ | 'broker'
4
+ | 'agent'
5
+ | 'security'
6
+ | 'customer';
2
7
 
3
- export type UserContext = 'administrator' | 'staff' | 'broker' | 'agent' | 'security' | 'customer';
8
+ type AuthUser = {
9
+ id: number;
10
+ name: string;
11
+ email: string;
12
+ is_group_admin: boolean;
13
+ umbrella_filter?: string;
14
+ oracle_user_id?: string;
15
+ groups: AuthGroup[];
16
+ };
17
+
18
+ type AuthGroup = {
19
+ id: number;
20
+ name: string;
21
+ code: string;
22
+ role: AuthRole;
23
+ };
24
+
25
+ type AuthRole = {
26
+ name: string;
27
+ context: string;
28
+ };
4
29
 
5
30
  export interface AuthContext {
6
- user?: User;
7
- context?: UserContext;
8
- group?: Group;
9
- permissions: string[];
10
- is_app?: boolean;
31
+ user?: AuthUser;
32
+ context: UserContext;
33
+ group?: AuthGroup;
34
+ permissions: string[];
35
+ is_app?: boolean;
36
+ can: (permission: string) => boolean;
11
37
  }
@@ -1,14 +1,15 @@
1
- import { Group } from ".";
1
+ import { Group } from '.';
2
2
 
3
3
  export interface User {
4
- id: number;
5
- oracle_user_id?: string;
6
- name: string;
7
- email: string;
8
- mobile?: string;
9
- direct_dial?: string;
10
- position?: string;
11
- is_group_admin?: boolean;
12
- umbrella_filter?: string;
13
- groups?: Group[];
4
+ id: number;
5
+ oracle_user_id?: string;
6
+ name: string;
7
+ email: string;
8
+ mobile?: string;
9
+ direct_dial?: string;
10
+ position?: string;
11
+ is_group_admin?: boolean;
12
+ umbrella_filter?: string;
13
+ groups?: Group[];
14
+ permissions?: string[];
14
15
  }
@@ -1,23 +1,24 @@
1
- import { Product, VehicleType } from "../../api";
2
- import { QuoteRequestVehicleDriver } from "./QuoteRequestVehicleDriver";
1
+ import { Product, VehicleType } from '../../api';
2
+ import { QuoteRequestVehicleDriver } from './QuoteRequestVehicleDriver';
3
3
 
4
4
  export interface QuoteRequestVehicle {
5
- id?: number;
6
- vehicle_type?: VehicleType;
7
- registration?: string;
8
- make?: string;
9
- model?: string;
10
- year?: string;
11
- usage?: string;
12
- product?: Product;
13
- has_financially_interested_party?: boolean;
14
- financially_interested_party_detail?: string;
15
- owned_duration?: string;
16
- value?: number;
17
- storage_location?: string;
18
- is_heavy?: boolean;
19
- quote_request_id?: string;
20
- drivers?: QuoteRequestVehicleDriver[];
21
- key?: string;
22
- main_driver?: string;
5
+ id?: number;
6
+ vehicle_type?: VehicleType;
7
+ registration?: string;
8
+ make?: string;
9
+ model?: string;
10
+ year?: string;
11
+ usage?: string;
12
+ product?: Product;
13
+ has_financially_interested_party?: boolean;
14
+ financially_interested_party_detail?: string;
15
+ owned_duration?: string;
16
+ value?: number;
17
+ storage_location?: string;
18
+ storage_location_other?: string;
19
+ is_heavy?: boolean;
20
+ quote_request_id?: string;
21
+ drivers?: QuoteRequestVehicleDriver[];
22
+ key?: string;
23
+ main_driver?: string;
23
24
  }