@star-insure/sdk 1.0.1 → 1.1.2
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 +16 -12
- package/src/components/common/Button.tsx +60 -0
- package/src/components/common/Card.tsx +14 -0
- package/src/components/common/Modal.tsx +54 -0
- package/src/components/common/Pagination.tsx +77 -0
- package/src/components/common/ToastItem.tsx +54 -0
- package/src/components/common/Toasts.tsx +16 -0
- package/src/components/common/index.ts +15 -0
- package/src/components/forms/DateOfBirthField.tsx +84 -0
- package/src/components/forms/Errors.tsx +32 -0
- package/src/components/forms/FormTester.tsx +170 -0
- package/src/components/forms/MoneyField.tsx +45 -0
- package/src/components/forms/RegistrationSearchField.tsx +187 -0
- package/src/components/forms/index.ts +13 -0
- package/src/components/index.ts +3 -0
- package/src/components/tables/Table.tsx +19 -0
- package/src/components/tables/TableActions.tsx +14 -0
- package/src/components/tables/TableBody.tsx +14 -0
- package/src/components/tables/TableCell.tsx +14 -0
- package/src/components/tables/TableHead.tsx +14 -0
- package/src/components/tables/TableHeader.tsx +49 -0
- package/src/components/tables/TableRow.tsx +17 -0
- package/src/components/tables/index.ts +17 -0
- package/src/index.ts +1 -0
- package/src/lib/addressFinder.tsx +100 -0
- package/src/lib/auth.tsx +8 -0
- package/src/lib/calculateAge.ts +19 -0
- package/src/lib/clickOutside.tsx +24 -0
- package/src/lib/index.ts +9 -0
- package/src/lib/inertiaOptions.tsx +27 -0
- package/src/lib/localStorage.tsx +41 -0
- package/src/lib/quoteRequestForm.tsx +144 -0
- package/src/lib/quoteRequestOptions.tsx +21 -0
- package/src/lib/toast.tsx +55 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -8
- package/dist/lib/dates.d.ts +0 -8
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/money.d.ts +0 -32
- package/dist/lib/vehicles.d.ts +0 -2
- package/dist/sdk.cjs.development.js +0 -161
- package/dist/sdk.cjs.development.js.map +0 -1
- package/dist/sdk.cjs.production.min.js +0 -2
- package/dist/sdk.cjs.production.min.js.map +0 -1
- package/dist/sdk.esm.js +0 -148
- package/dist/sdk.esm.js.map +0 -1
- package/dist/types/api/auth.d.ts +0 -9
- package/dist/types/api/enums.d.ts +0 -4
- package/dist/types/api/index.d.ts +0 -31
- package/dist/types/api/responses/claimRequestActions.d.ts +0 -12
- package/dist/types/api/responses/index.d.ts +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/misc/index.d.ts +0 -8
- package/dist/types/misc/inertia.d.ts +0 -8
- package/dist/types/models/auth/Group.d.ts +0 -10
- package/dist/types/models/auth/Permission.d.ts +0 -4
- package/dist/types/models/auth/Role.d.ts +0 -6
- package/dist/types/models/auth/User.d.ts +0 -12
- package/dist/types/models/auth/index.d.ts +0 -4
- package/dist/types/models/claims/ClaimRequest.d.ts +0 -287
- package/dist/types/models/claims/index.d.ts +0 -1
- package/dist/types/models/index.d.ts +0 -6
- package/dist/types/models/oracle/Risk.d.ts +0 -8
- package/dist/types/models/oracle/TableData.d.ts +0 -9
- package/dist/types/models/oracle/index.d.ts +0 -2
- package/dist/types/models/payments/Gateways.d.ts +0 -1
- package/dist/types/models/payments/Payment.d.ts +0 -35
- package/dist/types/models/payments/index.d.ts +0 -2
- package/dist/types/models/quotes/Club.d.ts +0 -4
- package/dist/types/models/quotes/EmailContentOption.d.ts +0 -7
- package/dist/types/models/quotes/InformationRequest.d.ts +0 -34
- package/dist/types/models/quotes/Lead.d.ts +0 -17
- package/dist/types/models/quotes/MotorwebVehicle.d.ts +0 -120
- package/dist/types/models/quotes/PolicyBenefit.d.ts +0 -16
- package/dist/types/models/quotes/PolicyEnhancement.d.ts +0 -11
- package/dist/types/models/quotes/PostalAddress.d.ts +0 -7
- package/dist/types/models/quotes/PromoCode.d.ts +0 -18
- package/dist/types/models/quotes/QuoteRequest.d.ts +0 -88
- package/dist/types/models/quotes/QuoteRequestDeclaration.d.ts +0 -22
- package/dist/types/models/quotes/QuoteRequestForm.d.ts +0 -112
- package/dist/types/models/quotes/QuoteRequestIncident.d.ts +0 -5
- package/dist/types/models/quotes/QuoteRequestLog.d.ts +0 -10
- package/dist/types/models/quotes/QuoteRequestOptions.d.ts +0 -59
- package/dist/types/models/quotes/QuoteRequestPurchaseOption.d.ts +0 -35
- package/dist/types/models/quotes/QuoteRequestReferrer.d.ts +0 -7
- package/dist/types/models/quotes/QuoteRequestReferrerCategory.d.ts +0 -4
- package/dist/types/models/quotes/QuoteRequestVehicle.d.ts +0 -20
- package/dist/types/models/quotes/QuoteRequestVehicleDriver.d.ts +0 -10
- package/dist/types/models/quotes/RedbookVehicle.d.ts +0 -55
- package/dist/types/models/quotes/StreetAddress.d.ts +0 -8
- package/dist/types/models/quotes/index.d.ts +0 -22
- package/dist/types/models/sms-messages/SmsContentOption.d.ts +0 -7
- package/dist/types/models/sms-messages/SmsMessage.d.ts +0 -18
- package/dist/types/models/sms-messages/SmsMessageReply.d.ts +0 -10
- package/dist/types/models/sms-messages/index.d.ts +0 -3
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InertiaFormProps, useForm } from "@inertiajs/inertia-react";
|
|
3
|
+
import type { QuoteRequest } from '../types';
|
|
4
|
+
|
|
5
|
+
interface QuoteRequestFormContextInterface {
|
|
6
|
+
form?: InertiaFormProps<QuoteRequest>;
|
|
7
|
+
handleChange?: (e: React.ChangeEvent<HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement>) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const initialData: QuoteRequest = {
|
|
11
|
+
id: undefined,
|
|
12
|
+
status: 'new',
|
|
13
|
+
source: 'web',
|
|
14
|
+
reference: '',
|
|
15
|
+
client_number: '',
|
|
16
|
+
first_name: '',
|
|
17
|
+
last_name: '',
|
|
18
|
+
phone: '',
|
|
19
|
+
mobile: '',
|
|
20
|
+
email: '',
|
|
21
|
+
licence: '',
|
|
22
|
+
licence_other: '',
|
|
23
|
+
promo_code: '',
|
|
24
|
+
club_membership_number: '',
|
|
25
|
+
length_of_insurance: '',
|
|
26
|
+
dob: '',
|
|
27
|
+
club_id: undefined,
|
|
28
|
+
street_address: {
|
|
29
|
+
address: '',
|
|
30
|
+
unit: '',
|
|
31
|
+
suburb: '',
|
|
32
|
+
city: '',
|
|
33
|
+
post_code: '',
|
|
34
|
+
},
|
|
35
|
+
declaration: {
|
|
36
|
+
had_incident: undefined,
|
|
37
|
+
incidents: [],
|
|
38
|
+
has_demerit_points: undefined,
|
|
39
|
+
demerit_points: '',
|
|
40
|
+
has_lost_licence: undefined,
|
|
41
|
+
lost_licence_details: '',
|
|
42
|
+
was_refused_insurance: undefined,
|
|
43
|
+
refused_insurance_details: '',
|
|
44
|
+
has_criminal_conviction: undefined,
|
|
45
|
+
criminal_conviction_details: '',
|
|
46
|
+
has_vehicle_modifications: undefined,
|
|
47
|
+
vehicle_modifications_details: '',
|
|
48
|
+
has_previous_insurer: undefined,
|
|
49
|
+
previous_insurer_details: '',
|
|
50
|
+
previous_insurer_expires_at: '',
|
|
51
|
+
additional_details: '',
|
|
52
|
+
},
|
|
53
|
+
vehicles: [],
|
|
54
|
+
// Portal specific fields:
|
|
55
|
+
purchase_options: [],
|
|
56
|
+
theme: '',
|
|
57
|
+
broker_fee: undefined,
|
|
58
|
+
broker_id: undefined,
|
|
59
|
+
broker_firm_id: undefined,
|
|
60
|
+
agent_id: undefined,
|
|
61
|
+
agent_firm_id: undefined,
|
|
62
|
+
staff_member_id: undefined,
|
|
63
|
+
sent_at: undefined,
|
|
64
|
+
sold_at: undefined,
|
|
65
|
+
referrer_id: undefined,
|
|
66
|
+
referrer_category_id: undefined,
|
|
67
|
+
pricing_expires_at: undefined,
|
|
68
|
+
follow_up_at: undefined,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const QuoteRequestFormContext = React.createContext<QuoteRequestFormContextInterface>({});
|
|
72
|
+
|
|
73
|
+
export function QuoteRequestFormProvider({ children }: { children: React.ReactNode }) {
|
|
74
|
+
const form = useForm<QuoteRequest>(initialData);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Handle the change event for all form inputs
|
|
78
|
+
*/
|
|
79
|
+
function handleChange(e: React.SyntheticEvent<HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement>) {
|
|
80
|
+
const { name } = e.currentTarget;
|
|
81
|
+
let value: string|boolean|undefined = e.currentTarget.value;
|
|
82
|
+
|
|
83
|
+
if (e.currentTarget.type === 'checkbox' || e.currentTarget.type === 'radio') {
|
|
84
|
+
const target = e.currentTarget as HTMLInputElement;
|
|
85
|
+
value = target.value === '1' ? true : false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (name.includes('.')) {
|
|
89
|
+
const parts = name.split('.');
|
|
90
|
+
|
|
91
|
+
if (parts.length === 2) {
|
|
92
|
+
return form.setData(prevData => ({
|
|
93
|
+
...prevData,
|
|
94
|
+
[parts[0]]: {
|
|
95
|
+
// @ts-ignore TODO: Maybe fix these TS errors
|
|
96
|
+
...prevData[parts[0]],
|
|
97
|
+
[parts[1]]: value,
|
|
98
|
+
},
|
|
99
|
+
}));
|
|
100
|
+
} else {
|
|
101
|
+
// We don't want to handle anything double-nested. These should be handled by their own local state.
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return form.setData(prevData => ({
|
|
107
|
+
...prevData,
|
|
108
|
+
[name]: value,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<QuoteRequestFormContext.Provider value={{ form, handleChange }}>
|
|
114
|
+
{children}
|
|
115
|
+
</QuoteRequestFormContext.Provider>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Takes in a quote request and returns data suitable to populate a form
|
|
121
|
+
* by recursively calling this function, converting null to undefined.
|
|
122
|
+
*/
|
|
123
|
+
export function sanitiseQuoteRequestFormData(value: any): any {
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
return value.map(item => sanitiseQuoteRequestFormData(item));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (value === null) {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (typeof value === 'object') {
|
|
133
|
+
// Map over each property and convert null to undefined
|
|
134
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
acc[key] = sanitiseQuoteRequestFormData(value[key]);
|
|
137
|
+
return acc;
|
|
138
|
+
}, {});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const useQuoteRequestForm = () => React.useContext(QuoteRequestFormContext);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QuoteRequestOptions } from '../';
|
|
3
|
+
|
|
4
|
+
interface QuoteRequestFormContextInterface {
|
|
5
|
+
options?: QuoteRequestOptions;
|
|
6
|
+
setOptions: (options: QuoteRequestOptions) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const QuoteRequestOptionsContext = React.createContext<QuoteRequestFormContextInterface>({ setOptions: () => {} });
|
|
10
|
+
|
|
11
|
+
export function QuoteRequestOptionsProvider({ children }: { children: React.ReactNode }) {
|
|
12
|
+
const [options, setOptions] = React.useState<QuoteRequestOptions>();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<QuoteRequestOptionsContext.Provider value={{ options, setOptions }}>
|
|
16
|
+
{children}
|
|
17
|
+
</QuoteRequestOptionsContext.Provider>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useQuoteRequestOptions = () => React.useContext(QuoteRequestOptionsContext);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Toast } from "../types";
|
|
3
|
+
import { v4 as uuid } from 'uuid';
|
|
4
|
+
|
|
5
|
+
interface ToastContextInterface {
|
|
6
|
+
toasts: Toast[];
|
|
7
|
+
addToast: (toast: Toast) => void;
|
|
8
|
+
removeToast: (id: Toast['_id']) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ToastContext = React.createContext<ToastContextInterface>({
|
|
12
|
+
toasts: [],
|
|
13
|
+
addToast: (t: Toast) => {t},
|
|
14
|
+
removeToast: (t: Toast['_id']) => {t},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export function ToastProvider({ children }: any) {
|
|
18
|
+
const [toasts, setToasts] = React.useState<Toast[]>([]);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add a new toast popup message
|
|
22
|
+
*/
|
|
23
|
+
function addToast({ message, status, timeout = 4000 }: Toast) {
|
|
24
|
+
const newToast: Toast = { message, status, timeout };
|
|
25
|
+
|
|
26
|
+
newToast._id = uuid();
|
|
27
|
+
|
|
28
|
+
setToasts(curr => [...curr, newToast]);
|
|
29
|
+
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
removeToast(newToast._id);
|
|
32
|
+
}, timeout);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Remove a toast message
|
|
37
|
+
*/
|
|
38
|
+
function removeToast(id: Toast['_id']) {
|
|
39
|
+
setToasts(curr => curr.filter(toast => toast._id !== id));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const context: ToastContextInterface = {
|
|
43
|
+
toasts,
|
|
44
|
+
addToast,
|
|
45
|
+
removeToast,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<ToastContext.Provider value={context}>
|
|
50
|
+
{children}
|
|
51
|
+
</ToastContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const useToast = () => React.useContext(ToastContext);
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/lib/dates.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats a date like "Jan 1, 2022 at 9:50am"
|
|
3
|
-
*/
|
|
4
|
-
export declare function formatDateNice(date: string, includeTime?: boolean): string;
|
|
5
|
-
/**
|
|
6
|
-
* Formats a date like "01/01/2022 9:50AM"
|
|
7
|
-
*/
|
|
8
|
-
export declare function formatDateForTable(date: string, includeTime?: boolean): string;
|
package/dist/lib/index.d.ts
DELETED
package/dist/lib/money.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Safely rounds a number
|
|
3
|
-
*/
|
|
4
|
-
export declare function round(value: number): number;
|
|
5
|
-
/**
|
|
6
|
-
* Gets the GST value from a number
|
|
7
|
-
*/
|
|
8
|
-
export declare function getGst(value: number): number;
|
|
9
|
-
/**
|
|
10
|
-
* Adds GST to a number
|
|
11
|
-
*/
|
|
12
|
-
export declare function addGst(value: number): number;
|
|
13
|
-
/**
|
|
14
|
-
* Subtracts GST from a number
|
|
15
|
-
*/
|
|
16
|
-
export declare function subtractGst(value: number): number;
|
|
17
|
-
/**
|
|
18
|
-
* Calculates the various GST values on a figure
|
|
19
|
-
*/
|
|
20
|
-
export declare function gstCalc(input: number | string): {
|
|
21
|
-
gst: number;
|
|
22
|
-
amountInclusive: number;
|
|
23
|
-
amountExclusive: number;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Formats a value nicely
|
|
27
|
-
*/
|
|
28
|
-
export declare function formatMoney(value: string | number, decimals?: number): string;
|
|
29
|
-
/**
|
|
30
|
-
* Turns a formatted value in to a float
|
|
31
|
-
*/
|
|
32
|
-
export declare function formatNumber(value: string): number;
|
package/dist/lib/vehicles.d.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var dateFns = require('date-fns');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Formats a date like "Jan 1, 2022 at 9:50am"
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
function formatDateNice(date, includeTime) {
|
|
12
|
-
if (includeTime === void 0) {
|
|
13
|
-
includeTime = true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var formatString = includeTime ? "MMM d, yyyy 'at' h:mma" : 'MMM d, yyyy';
|
|
17
|
-
return dateFns.format(new Date(date), formatString);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Formats a date like "01/01/2022 9:50AM"
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
function formatDateForTable(date, includeTime) {
|
|
24
|
-
if (includeTime === void 0) {
|
|
25
|
-
includeTime = true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';
|
|
29
|
-
return dateFns.format(new Date(date), formatString);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Safely rounds a number
|
|
34
|
-
*/
|
|
35
|
-
function round(value) {
|
|
36
|
-
return Number(Math.round(parseFloat(value + 'e' + 2)) + 'e-' + 2);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Gets the GST value from a number
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function getGst(value) {
|
|
43
|
-
return round(value * 3 / 23);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Adds GST to a number
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
function addGst(value) {
|
|
50
|
-
return round(value * 1.15);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Subtracts GST from a number
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
function subtractGst(value) {
|
|
57
|
-
return round(value - getGst(value));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Calculates the various GST values on a figure
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
function gstCalc(input) {
|
|
64
|
-
var value = input;
|
|
65
|
-
|
|
66
|
-
if (typeof value === 'string') {
|
|
67
|
-
value = parseFloat(value.replace(/[^0-9.]/g, ''));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
value = round(value);
|
|
71
|
-
return {
|
|
72
|
-
gst: getGst(value),
|
|
73
|
-
amountInclusive: addGst(value),
|
|
74
|
-
amountExclusive: subtractGst(value)
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Formats a value nicely
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
function formatMoney(value, decimals) {
|
|
82
|
-
if (decimals === void 0) {
|
|
83
|
-
decimals = 2;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
var toFormat = value;
|
|
87
|
-
|
|
88
|
-
if (typeof value === 'string') {
|
|
89
|
-
toFormat = value.replace(/[^\d.-]/g, '');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return Number(toFormat).toLocaleString('en', {
|
|
93
|
-
minimumFractionDigits: decimals,
|
|
94
|
-
maximumFractionDigits: decimals
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Turns a formatted value in to a float
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
function formatNumber(value) {
|
|
102
|
-
return parseFloat(value.replace(/[^0-9.]/g, ''));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function sanitiseVehicleType(inputType) {
|
|
106
|
-
var type;
|
|
107
|
-
|
|
108
|
-
switch (inputType) {
|
|
109
|
-
case 'Camper':
|
|
110
|
-
case 'Goods Van/Truck/Utility':
|
|
111
|
-
case 'Bus':
|
|
112
|
-
case 'Motor Caravan':
|
|
113
|
-
case 'Trailer/Caravan':
|
|
114
|
-
case 'TRAILER_CARAVAN':
|
|
115
|
-
case 'TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE':
|
|
116
|
-
case 'MOBILE_MACHINE':
|
|
117
|
-
case 'GOODS_VAN_TRUCK_UTILITY':
|
|
118
|
-
case 'BUS':
|
|
119
|
-
case 'MOTOR_CARAVAN':
|
|
120
|
-
{
|
|
121
|
-
type = 'motorhome';
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
case 'Motorcycle':
|
|
126
|
-
case 'Moped':
|
|
127
|
-
case 'ATV':
|
|
128
|
-
case 'Agricultural Machine':
|
|
129
|
-
case 'MOTORCYCLE':
|
|
130
|
-
case 'ATV':
|
|
131
|
-
case 'MOPED':
|
|
132
|
-
case 'TRACTOR':
|
|
133
|
-
case 'AGRICULTURAL_MACHINE':
|
|
134
|
-
case 'HIGH_SPEED_AGRICULTURAL_VEHICLE':
|
|
135
|
-
{
|
|
136
|
-
type = 'motorcycle';
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
case 'Passenger Car/Van':
|
|
141
|
-
case 'PASSENGER_CAR_VAN':
|
|
142
|
-
case 'SPECIAL_PURPOSE_VEHICLE':
|
|
143
|
-
case 'UNKNOWN':
|
|
144
|
-
default:
|
|
145
|
-
type = 'car';
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return type;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
exports.addGst = addGst;
|
|
152
|
-
exports.formatDateForTable = formatDateForTable;
|
|
153
|
-
exports.formatDateNice = formatDateNice;
|
|
154
|
-
exports.formatMoney = formatMoney;
|
|
155
|
-
exports.formatNumber = formatNumber;
|
|
156
|
-
exports.getGst = getGst;
|
|
157
|
-
exports.gstCalc = gstCalc;
|
|
158
|
-
exports.round = round;
|
|
159
|
-
exports.sanitiseVehicleType = sanitiseVehicleType;
|
|
160
|
-
exports.subtractGst = subtractGst;
|
|
161
|
-
//# sourceMappingURL=sdk.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.cjs.development.js","sources":["../src/lib/dates.ts","../src/lib/money.ts","../src/lib/vehicles.ts"],"sourcesContent":["import { format } from \"date-fns\";\n\n/**\n * Formats a date like \"Jan 1, 2022 at 9:50am\"\n */\nexport function formatDateNice(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? \"MMM d, yyyy 'at' h:mma\" : 'MMM d, yyyy';\n return format(new Date(date), formatString);\n}\n\n/**\n * Formats a date like \"01/01/2022 9:50AM\"\n */\nexport function formatDateForTable(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';\n return format(new Date(date), formatString);\n}\n","/**\n * Safely rounds a number\n */\nexport function round(value: number): number {\n return Number(Math.round(parseFloat(value + 'e' + 2)) + 'e-' + 2)\n}\n\n/**\n * Gets the GST value from a number\n */\nexport function getGst(value: number): number {\n return round(value * 3 / 23);\n}\n\n/**\n * Adds GST to a number\n */\nexport function addGst(value: number): number {\n return round(value * 1.15);\n}\n\n/**\n * Subtracts GST from a number\n */\nexport function subtractGst(value: number): number {\n return round(value - getGst(value));\n}\n\n/**\n * Calculates the various GST values on a figure\n */\nexport function gstCalc(input: number|string): {\n gst: number,\n amountInclusive: number,\n amountExclusive: number\n} {\n let value = input;\n\n if (typeof value === 'string') {\n value = parseFloat(value.replace(/[^0-9.]/g, ''));\n }\n\n value = round(value);\n\n return {\n gst: getGst(value),\n amountInclusive: addGst(value),\n amountExclusive: subtractGst(value)\n }\n}\n\n/**\n * Formats a value nicely\n */\n export function formatMoney(value: string|number, decimals: number = 2): string {\n let toFormat = value;\n if (typeof value === 'string') {\n toFormat = value.replace(/[^\\d.-]/g, '')\n }\n\n return Number(toFormat).toLocaleString('en', {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n}\n\n/**\n * Turns a formatted value in to a float\n */\nexport function formatNumber(value: string): number {\n return parseFloat(value.replace(/[^0-9.]/g, ''));\n}\n","import { VehicleType } from \"../types\";\n\nexport function sanitiseVehicleType(inputType: string): VehicleType {\n let type: VehicleType;\n\n switch (inputType) {\n case 'Camper':\n case 'Goods Van/Truck/Utility':\n case 'Bus':\n case 'Motor Caravan':\n case 'Trailer/Caravan':\n case 'TRAILER_CARAVAN':\n case 'TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE':\n case 'MOBILE_MACHINE':\n case 'GOODS_VAN_TRUCK_UTILITY':\n case 'BUS':\n case 'MOTOR_CARAVAN': {\n type = 'motorhome';\n break;\n }\n\n case 'Motorcycle':\n case 'Moped':\n case 'ATV':\n case 'Agricultural Machine':\n case 'MOTORCYCLE':\n case 'ATV':\n case 'MOPED':\n case 'TRACTOR':\n case 'AGRICULTURAL_MACHINE':\n case 'HIGH_SPEED_AGRICULTURAL_VEHICLE': {\n type = 'motorcycle';\n break;\n }\n\n case 'Passenger Car/Van':\n case 'PASSENGER_CAR_VAN':\n case 'SPECIAL_PURPOSE_VEHICLE':\n case 'UNKNOWN':\n default:\n type = 'car';\n }\n\n return type;\n}\n"],"names":["formatDateNice","date","includeTime","formatString","format","Date","formatDateForTable","round","value","Number","Math","parseFloat","getGst","addGst","subtractGst","gstCalc","input","replace","gst","amountInclusive","amountExclusive","formatMoney","decimals","toFormat","toLocaleString","minimumFractionDigits","maximumFractionDigits","formatNumber","sanitiseVehicleType","inputType","type"],"mappings":"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"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("date-fns");function a(e){return Number(Math.round(parseFloat(e+"e2"))+"e-2")}function r(e){return a(3*e/23)}function t(e){return a(1.15*e)}function s(e){return a(e-r(e))}exports.addGst=t,exports.formatDateForTable=function(a,r){void 0===r&&(r=!0);var t=r?"dd/MM/yyyy h:mma":"dd/MM/yyyy";return e.format(new Date(a),t)},exports.formatDateNice=function(a,r){void 0===r&&(r=!0);var t=r?"MMM d, yyyy 'at' h:mma":"MMM d, yyyy";return e.format(new Date(a),t)},exports.formatMoney=function(e,a){void 0===a&&(a=2);var r=e;return"string"==typeof e&&(r=e.replace(/[^\d.-]/g,"")),Number(r).toLocaleString("en",{minimumFractionDigits:a,maximumFractionDigits:a})},exports.formatNumber=function(e){return parseFloat(e.replace(/[^0-9.]/g,""))},exports.getGst=r,exports.gstCalc=function(e){var o=e;return"string"==typeof o&&(o=parseFloat(o.replace(/[^0-9.]/g,""))),{gst:r(o=a(o)),amountInclusive:t(o),amountExclusive:s(o)}},exports.round=a,exports.sanitiseVehicleType=function(e){var a;switch(e){case"Camper":case"Goods Van/Truck/Utility":case"Bus":case"Motor Caravan":case"Trailer/Caravan":case"TRAILER_CARAVAN":case"TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE":case"MOBILE_MACHINE":case"GOODS_VAN_TRUCK_UTILITY":case"BUS":case"MOTOR_CARAVAN":a="motorhome";break;case"Motorcycle":case"Moped":case"ATV":case"Agricultural Machine":case"MOTORCYCLE":case"ATV":case"MOPED":case"TRACTOR":case"AGRICULTURAL_MACHINE":case"HIGH_SPEED_AGRICULTURAL_VEHICLE":a="motorcycle";break;case"Passenger Car/Van":case"PASSENGER_CAR_VAN":case"SPECIAL_PURPOSE_VEHICLE":case"UNKNOWN":default:a="car"}return a},exports.subtractGst=s;
|
|
2
|
-
//# sourceMappingURL=sdk.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.cjs.production.min.js","sources":["../src/lib/money.ts","../src/lib/dates.ts","../src/lib/vehicles.ts"],"sourcesContent":["/**\n * Safely rounds a number\n */\nexport function round(value: number): number {\n return Number(Math.round(parseFloat(value + 'e' + 2)) + 'e-' + 2)\n}\n\n/**\n * Gets the GST value from a number\n */\nexport function getGst(value: number): number {\n return round(value * 3 / 23);\n}\n\n/**\n * Adds GST to a number\n */\nexport function addGst(value: number): number {\n return round(value * 1.15);\n}\n\n/**\n * Subtracts GST from a number\n */\nexport function subtractGst(value: number): number {\n return round(value - getGst(value));\n}\n\n/**\n * Calculates the various GST values on a figure\n */\nexport function gstCalc(input: number|string): {\n gst: number,\n amountInclusive: number,\n amountExclusive: number\n} {\n let value = input;\n\n if (typeof value === 'string') {\n value = parseFloat(value.replace(/[^0-9.]/g, ''));\n }\n\n value = round(value);\n\n return {\n gst: getGst(value),\n amountInclusive: addGst(value),\n amountExclusive: subtractGst(value)\n }\n}\n\n/**\n * Formats a value nicely\n */\n export function formatMoney(value: string|number, decimals: number = 2): string {\n let toFormat = value;\n if (typeof value === 'string') {\n toFormat = value.replace(/[^\\d.-]/g, '')\n }\n\n return Number(toFormat).toLocaleString('en', {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n}\n\n/**\n * Turns a formatted value in to a float\n */\nexport function formatNumber(value: string): number {\n return parseFloat(value.replace(/[^0-9.]/g, ''));\n}\n","import { format } from \"date-fns\";\n\n/**\n * Formats a date like \"Jan 1, 2022 at 9:50am\"\n */\nexport function formatDateNice(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? \"MMM d, yyyy 'at' h:mma\" : 'MMM d, yyyy';\n return format(new Date(date), formatString);\n}\n\n/**\n * Formats a date like \"01/01/2022 9:50AM\"\n */\nexport function formatDateForTable(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';\n return format(new Date(date), formatString);\n}\n","import { VehicleType } from \"../types\";\n\nexport function sanitiseVehicleType(inputType: string): VehicleType {\n let type: VehicleType;\n\n switch (inputType) {\n case 'Camper':\n case 'Goods Van/Truck/Utility':\n case 'Bus':\n case 'Motor Caravan':\n case 'Trailer/Caravan':\n case 'TRAILER_CARAVAN':\n case 'TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE':\n case 'MOBILE_MACHINE':\n case 'GOODS_VAN_TRUCK_UTILITY':\n case 'BUS':\n case 'MOTOR_CARAVAN': {\n type = 'motorhome';\n break;\n }\n\n case 'Motorcycle':\n case 'Moped':\n case 'ATV':\n case 'Agricultural Machine':\n case 'MOTORCYCLE':\n case 'ATV':\n case 'MOPED':\n case 'TRACTOR':\n case 'AGRICULTURAL_MACHINE':\n case 'HIGH_SPEED_AGRICULTURAL_VEHICLE': {\n type = 'motorcycle';\n break;\n }\n\n case 'Passenger Car/Van':\n case 'PASSENGER_CAR_VAN':\n case 'SPECIAL_PURPOSE_VEHICLE':\n case 'UNKNOWN':\n default:\n type = 'car';\n }\n\n return type;\n}\n"],"names":["round","value","Number","Math","parseFloat","getGst","addGst","subtractGst","date","includeTime","formatString","format","Date","decimals","toFormat","replace","toLocaleString","minimumFractionDigits","maximumFractionDigits","input","gst","amountInclusive","amountExclusive","inputType","type"],"mappings":"uGAGgBA,EAAMC,GAClB,OAAOC,OAAOC,KAAKH,MAAMI,WAAWH,EAAAA,OAAtBE,gBAMFE,EAAOJ,GACnB,OAAOD,EAAc,EAARC,EAAY,aAMbK,EAAOL,GACnB,OAAOD,EAAc,KAARC,YAMDM,EAAYN,GACxB,OAAOD,EAAMC,EAAQI,EAAOJ,yDCZGO,EAAcC,YAAAA,IAAAA,GAAuB,GACpE,IAAMC,EAAeD,EAAc,mBAAqB,aACxD,OAAOE,SAAO,IAAIC,KAAKJ,GAAOE,oCAVHF,EAAcC,YAAAA,IAAAA,GAAuB,GAChE,IAAMC,EAAeD,EAAc,yBAA2B,cAC9D,OAAOE,SAAO,IAAIC,KAAKJ,GAAOE,iCD+CLT,EAAsBY,YAAAA,IAAAA,EAAmB,GAClE,IAAIC,EAAWb,EAKf,MAJqB,iBAAVA,IACPa,EAAWb,EAAMc,QAAQ,WAAY,KAGlCb,OAAOY,GAAUE,eAAe,KAAM,CACzCC,sBAAuBJ,EACvBK,sBAAuBL,mCAOFZ,GACzB,OAAOG,WAAWH,EAAMc,QAAQ,WAAY,gDAvCxBI,GAKpB,IAAIlB,EAAQkB,EAQZ,MANqB,iBAAVlB,IACPA,EAAQG,WAAWH,EAAMc,QAAQ,WAAY,MAK1C,CACHK,IAAKf,EAHTJ,EAAQD,EAAMC,IAIVoB,gBAAiBf,EAAOL,GACxBqB,gBAAiBf,EAAYN,0DE7CDsB,GAChC,IAAIC,EAEJ,OAAQD,GACJ,IAAK,SACL,IAAK,0BACL,IAAK,MACL,IAAK,gBACL,IAAK,kBACL,IAAK,kBACL,IAAK,uCACL,IAAK,iBACL,IAAK,0BACL,IAAK,MACL,IAAK,gBACDC,EAAO,YACP,MAGJ,IAAK,aACL,IAAK,QACL,IAAK,MACL,IAAK,uBACL,IAAK,aACL,IAAK,MACL,IAAK,QACL,IAAK,UACL,IAAK,uBACL,IAAK,kCACDA,EAAO,aACP,MAGJ,IAAK,oBACL,IAAK,oBACL,IAAK,0BACL,IAAK,UACL,QACIA,EAAO,MAGf,OAAOA"}
|
package/dist/sdk.esm.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { format } from 'date-fns';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Formats a date like "Jan 1, 2022 at 9:50am"
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function formatDateNice(date, includeTime) {
|
|
8
|
-
if (includeTime === void 0) {
|
|
9
|
-
includeTime = true;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
var formatString = includeTime ? "MMM d, yyyy 'at' h:mma" : 'MMM d, yyyy';
|
|
13
|
-
return format(new Date(date), formatString);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Formats a date like "01/01/2022 9:50AM"
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
function formatDateForTable(date, includeTime) {
|
|
20
|
-
if (includeTime === void 0) {
|
|
21
|
-
includeTime = true;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';
|
|
25
|
-
return format(new Date(date), formatString);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Safely rounds a number
|
|
30
|
-
*/
|
|
31
|
-
function round(value) {
|
|
32
|
-
return Number(Math.round(parseFloat(value + 'e' + 2)) + 'e-' + 2);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Gets the GST value from a number
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
function getGst(value) {
|
|
39
|
-
return round(value * 3 / 23);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Adds GST to a number
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
function addGst(value) {
|
|
46
|
-
return round(value * 1.15);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Subtracts GST from a number
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
function subtractGst(value) {
|
|
53
|
-
return round(value - getGst(value));
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Calculates the various GST values on a figure
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function gstCalc(input) {
|
|
60
|
-
var value = input;
|
|
61
|
-
|
|
62
|
-
if (typeof value === 'string') {
|
|
63
|
-
value = parseFloat(value.replace(/[^0-9.]/g, ''));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
value = round(value);
|
|
67
|
-
return {
|
|
68
|
-
gst: getGst(value),
|
|
69
|
-
amountInclusive: addGst(value),
|
|
70
|
-
amountExclusive: subtractGst(value)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Formats a value nicely
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
function formatMoney(value, decimals) {
|
|
78
|
-
if (decimals === void 0) {
|
|
79
|
-
decimals = 2;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
var toFormat = value;
|
|
83
|
-
|
|
84
|
-
if (typeof value === 'string') {
|
|
85
|
-
toFormat = value.replace(/[^\d.-]/g, '');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return Number(toFormat).toLocaleString('en', {
|
|
89
|
-
minimumFractionDigits: decimals,
|
|
90
|
-
maximumFractionDigits: decimals
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Turns a formatted value in to a float
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
function formatNumber(value) {
|
|
98
|
-
return parseFloat(value.replace(/[^0-9.]/g, ''));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function sanitiseVehicleType(inputType) {
|
|
102
|
-
var type;
|
|
103
|
-
|
|
104
|
-
switch (inputType) {
|
|
105
|
-
case 'Camper':
|
|
106
|
-
case 'Goods Van/Truck/Utility':
|
|
107
|
-
case 'Bus':
|
|
108
|
-
case 'Motor Caravan':
|
|
109
|
-
case 'Trailer/Caravan':
|
|
110
|
-
case 'TRAILER_CARAVAN':
|
|
111
|
-
case 'TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE':
|
|
112
|
-
case 'MOBILE_MACHINE':
|
|
113
|
-
case 'GOODS_VAN_TRUCK_UTILITY':
|
|
114
|
-
case 'BUS':
|
|
115
|
-
case 'MOTOR_CARAVAN':
|
|
116
|
-
{
|
|
117
|
-
type = 'motorhome';
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
case 'Motorcycle':
|
|
122
|
-
case 'Moped':
|
|
123
|
-
case 'ATV':
|
|
124
|
-
case 'Agricultural Machine':
|
|
125
|
-
case 'MOTORCYCLE':
|
|
126
|
-
case 'ATV':
|
|
127
|
-
case 'MOPED':
|
|
128
|
-
case 'TRACTOR':
|
|
129
|
-
case 'AGRICULTURAL_MACHINE':
|
|
130
|
-
case 'HIGH_SPEED_AGRICULTURAL_VEHICLE':
|
|
131
|
-
{
|
|
132
|
-
type = 'motorcycle';
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
case 'Passenger Car/Van':
|
|
137
|
-
case 'PASSENGER_CAR_VAN':
|
|
138
|
-
case 'SPECIAL_PURPOSE_VEHICLE':
|
|
139
|
-
case 'UNKNOWN':
|
|
140
|
-
default:
|
|
141
|
-
type = 'car';
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return type;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export { addGst, formatDateForTable, formatDateNice, formatMoney, formatNumber, getGst, gstCalc, round, sanitiseVehicleType, subtractGst };
|
|
148
|
-
//# sourceMappingURL=sdk.esm.js.map
|
package/dist/sdk.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.esm.js","sources":["../src/lib/dates.ts","../src/lib/money.ts","../src/lib/vehicles.ts"],"sourcesContent":["import { format } from \"date-fns\";\n\n/**\n * Formats a date like \"Jan 1, 2022 at 9:50am\"\n */\nexport function formatDateNice(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? \"MMM d, yyyy 'at' h:mma\" : 'MMM d, yyyy';\n return format(new Date(date), formatString);\n}\n\n/**\n * Formats a date like \"01/01/2022 9:50AM\"\n */\nexport function formatDateForTable(date: string, includeTime: boolean = true) {\n const formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';\n return format(new Date(date), formatString);\n}\n","/**\n * Safely rounds a number\n */\nexport function round(value: number): number {\n return Number(Math.round(parseFloat(value + 'e' + 2)) + 'e-' + 2)\n}\n\n/**\n * Gets the GST value from a number\n */\nexport function getGst(value: number): number {\n return round(value * 3 / 23);\n}\n\n/**\n * Adds GST to a number\n */\nexport function addGst(value: number): number {\n return round(value * 1.15);\n}\n\n/**\n * Subtracts GST from a number\n */\nexport function subtractGst(value: number): number {\n return round(value - getGst(value));\n}\n\n/**\n * Calculates the various GST values on a figure\n */\nexport function gstCalc(input: number|string): {\n gst: number,\n amountInclusive: number,\n amountExclusive: number\n} {\n let value = input;\n\n if (typeof value === 'string') {\n value = parseFloat(value.replace(/[^0-9.]/g, ''));\n }\n\n value = round(value);\n\n return {\n gst: getGst(value),\n amountInclusive: addGst(value),\n amountExclusive: subtractGst(value)\n }\n}\n\n/**\n * Formats a value nicely\n */\n export function formatMoney(value: string|number, decimals: number = 2): string {\n let toFormat = value;\n if (typeof value === 'string') {\n toFormat = value.replace(/[^\\d.-]/g, '')\n }\n\n return Number(toFormat).toLocaleString('en', {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n}\n\n/**\n * Turns a formatted value in to a float\n */\nexport function formatNumber(value: string): number {\n return parseFloat(value.replace(/[^0-9.]/g, ''));\n}\n","import { VehicleType } from \"../types\";\n\nexport function sanitiseVehicleType(inputType: string): VehicleType {\n let type: VehicleType;\n\n switch (inputType) {\n case 'Camper':\n case 'Goods Van/Truck/Utility':\n case 'Bus':\n case 'Motor Caravan':\n case 'Trailer/Caravan':\n case 'TRAILER_CARAVAN':\n case 'TRAILER_NOT_DESIGNED_FOR_HIGHWAY_USE':\n case 'MOBILE_MACHINE':\n case 'GOODS_VAN_TRUCK_UTILITY':\n case 'BUS':\n case 'MOTOR_CARAVAN': {\n type = 'motorhome';\n break;\n }\n\n case 'Motorcycle':\n case 'Moped':\n case 'ATV':\n case 'Agricultural Machine':\n case 'MOTORCYCLE':\n case 'ATV':\n case 'MOPED':\n case 'TRACTOR':\n case 'AGRICULTURAL_MACHINE':\n case 'HIGH_SPEED_AGRICULTURAL_VEHICLE': {\n type = 'motorcycle';\n break;\n }\n\n case 'Passenger Car/Van':\n case 'PASSENGER_CAR_VAN':\n case 'SPECIAL_PURPOSE_VEHICLE':\n case 'UNKNOWN':\n default:\n type = 'car';\n }\n\n return type;\n}\n"],"names":["formatDateNice","date","includeTime","formatString","format","Date","formatDateForTable","round","value","Number","Math","parseFloat","getGst","addGst","subtractGst","gstCalc","input","replace","gst","amountInclusive","amountExclusive","formatMoney","decimals","toFormat","toLocaleString","minimumFractionDigits","maximumFractionDigits","formatNumber","sanitiseVehicleType","inputType","type"],"mappings":";;AAEA;;;;SAGgBA,eAAeC,MAAcC;MAAAA;IAAAA,cAAuB;;;EAChE,IAAMC,YAAY,GAAGD,WAAW,GAAG,wBAAH,GAA8B,aAA9D;EACA,OAAOE,MAAM,CAAC,IAAIC,IAAJ,CAASJ,IAAT,CAAD,EAAiBE,YAAjB,CAAb;AACH;AAED;;;;SAGgBG,mBAAmBL,MAAcC;MAAAA;IAAAA,cAAuB;;;EACpE,IAAMC,YAAY,GAAGD,WAAW,GAAG,kBAAH,GAAwB,YAAxD;EACA,OAAOE,MAAM,CAAC,IAAIC,IAAJ,CAASJ,IAAT,CAAD,EAAiBE,YAAjB,CAAb;AACH;;AChBD;;;AAGA,SAAgBI,MAAMC;EAClB,OAAOC,MAAM,CAACC,IAAI,CAACH,KAAL,CAAWI,UAAU,CAACH,KAAK,GAAG,GAAR,GAAc,CAAf,CAArB,IAA0C,IAA1C,GAAiD,CAAlD,CAAb;AACH;AAED;;;;AAGA,SAAgBI,OAAOJ;EACnB,OAAOD,KAAK,CAACC,KAAK,GAAG,CAAR,GAAY,EAAb,CAAZ;AACH;AAED;;;;AAGA,SAAgBK,OAAOL;EACnB,OAAOD,KAAK,CAACC,KAAK,GAAG,IAAT,CAAZ;AACH;AAED;;;;AAGA,SAAgBM,YAAYN;EACxB,OAAOD,KAAK,CAACC,KAAK,GAAGI,MAAM,CAACJ,KAAD,CAAf,CAAZ;AACH;AAED;;;;AAGA,SAAgBO,QAAQC;EAKpB,IAAIR,KAAK,GAAGQ,KAAZ;;EAEA,IAAI,OAAOR,KAAP,KAAiB,QAArB,EAA+B;IAC3BA,KAAK,GAAGG,UAAU,CAACH,KAAK,CAACS,OAAN,CAAc,UAAd,EAA0B,EAA1B,CAAD,CAAlB;;;EAGJT,KAAK,GAAGD,KAAK,CAACC,KAAD,CAAb;EAEA,OAAO;IACHU,GAAG,EAAEN,MAAM,CAACJ,KAAD,CADR;IAEHW,eAAe,EAAEN,MAAM,CAACL,KAAD,CAFpB;IAGHY,eAAe,EAAEN,WAAW,CAACN,KAAD;GAHhC;AAKH;AAED;;;;AAGC,SAAgBa,YAAYb,OAAsBc;MAAAA;IAAAA,WAAmB;;;EAClE,IAAIC,QAAQ,GAAGf,KAAf;;EACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC3Be,QAAQ,GAAGf,KAAK,CAACS,OAAN,CAAc,UAAd,EAA0B,EAA1B,CAAX;;;EAGJ,OAAOR,MAAM,CAACc,QAAD,CAAN,CAAiBC,cAAjB,CAAgC,IAAhC,EAAsC;IACzCC,qBAAqB,EAAEH,QADkB;IAEzCI,qBAAqB,EAAEJ;GAFpB,CAAP;AAIH;AAED;;;;AAGA,SAAgBK,aAAanB;EACzB,OAAOG,UAAU,CAACH,KAAK,CAACS,OAAN,CAAc,UAAd,EAA0B,EAA1B,CAAD,CAAjB;AACH;;SCrEeW,oBAAoBC;EAChC,IAAIC,IAAJ;;EAEA,QAAQD,SAAR;IACI,KAAK,QAAL;IACA,KAAK,yBAAL;IACA,KAAK,KAAL;IACA,KAAK,eAAL;IACA,KAAK,iBAAL;IACA,KAAK,iBAAL;IACA,KAAK,sCAAL;IACA,KAAK,gBAAL;IACA,KAAK,yBAAL;IACA,KAAK,KAAL;IACA,KAAK,eAAL;MAAsB;QAClBC,IAAI,GAAG,WAAP;QACA;;;IAGJ,KAAK,YAAL;IACA,KAAK,OAAL;IACA,KAAK,KAAL;IACA,KAAK,sBAAL;IACA,KAAK,YAAL;IACA,KAAK,KAAL;IACA,KAAK,OAAL;IACA,KAAK,SAAL;IACA,KAAK,sBAAL;IACA,KAAK,iCAAL;MAAwC;QACpCA,IAAI,GAAG,YAAP;QACA;;;IAGJ,KAAK,mBAAL;IACA,KAAK,mBAAL;IACA,KAAK,yBAAL;IACA,KAAK,SAAL;IACA;MACIA,IAAI,GAAG,KAAP;;;EAGR,OAAOA,IAAP;AACH;;;;"}
|
package/dist/types/api/auth.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { User, Group } from "../models";
|
|
2
|
-
export declare type UserContext = 'administrator' | 'staff' | 'broker' | 'agent' | 'security' | 'customer';
|
|
3
|
-
export interface AuthContext {
|
|
4
|
-
user?: User;
|
|
5
|
-
context?: UserContext;
|
|
6
|
-
group?: Group;
|
|
7
|
-
permissions: string[];
|
|
8
|
-
is_app?: boolean;
|
|
9
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare type VehicleType = 'car' | 'motorcycle' | 'motorhome';
|
|
2
|
-
export declare type Frequency = 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'quarterly' | 'annually';
|
|
3
|
-
export declare type Condition = 'poor' | 'fair' | 'good';
|
|
4
|
-
export declare type Product = 'star-enthusiast-prestige-everyday-plus' | 'star-enthusiast' | 'star-prestige' | 'star-everyday' | 'star-plus' | 'star-motorcycle' | 'star-campercare';
|