-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
88 lines (72 loc) · 2.98 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
export type FasterBaseUrl = `https://${string}/FASTER`
/**
* Tests if a base URL is valid.
* @param fasterBaseUrl - A possible FASTER Web base URL.
* @returns `true` if the base URL is valid.
*/
export function isValidBaseUrl(
fasterBaseUrl: string
): fasterBaseUrl is FasterBaseUrl {
return (
fasterBaseUrl.startsWith('https://') && fasterBaseUrl.endsWith('/FASTER')
)
}
export class FasterUrlBuilder {
/** Base URL */
readonly baseUrl: FasterBaseUrl
/** Login URL */
readonly loginUrl: `${FasterBaseUrl}/Login`
readonly #inventorySearchUrl: `${FasterBaseUrl}/Domains/Parts/Search/Default.aspx?xact=False&type=False&str=`
// eslint-disable-next-line no-secrets/no-secrets
readonly #workOrderSearchUrl: `${FasterBaseUrl}/Domains/Maintenance/WorkOrder/Search/Default.aspx?xact=False&type=False&str=`
readonly #workOrderUrl: `${FasterBaseUrl}/Domains/Maintenance/WorkOrder/WorkOrderMaster.aspx?workOrderID=`
/** Report Viewer URL - Parameters required */
readonly reportViewerUrl: `${FasterBaseUrl}/Domains/Reports/ReportViewer.aspx`
/**
* Initializes the FasterUrlBuilder
* @param fasterTenantOrBaseUrl - The subdomain of the FASTER Web URL before ".fasterwebcloud.com"
* or the full domain and path including "/FASTER"
*/
constructor(fasterTenantOrBaseUrl: string) {
this.baseUrl = fasterTenantOrBaseUrl.startsWith('https')
? (fasterTenantOrBaseUrl as FasterBaseUrl)
: `https://${fasterTenantOrBaseUrl}.fasterwebcloud.com/FASTER`
if (!isValidBaseUrl(this.baseUrl)) {
throw new Error(`Invalid base URL: ${this.baseUrl as string}`)
}
this.loginUrl = `${this.baseUrl}/Login`
/* Inventory */
this.#inventorySearchUrl = `${this.baseUrl}/Domains/Parts/Search/Default.aspx?xact=False&type=False&str=`
/* Maintenance */
// eslint-disable-next-line no-secrets/no-secrets
this.#workOrderSearchUrl = `${this.baseUrl}/Domains/Maintenance/WorkOrder/Search/Default.aspx?xact=False&type=False&str=`
this.#workOrderUrl = `${this.baseUrl}/Domains/Maintenance/WorkOrder/WorkOrderMaster.aspx?workOrderID=`
/* Reports */
this.reportViewerUrl = `${this.baseUrl}/Domains/Reports/ReportViewer.aspx`
}
/**
* Builds a URL for the inventory search.
* @param searchString - Item number search string
* @returns Inventory search URL
*/
inventorySearchUrl(searchString = ''): string {
return `${this.#inventorySearchUrl}${searchString}`
}
/**
* Builds a URL for a given work order.
* @param workOrderNumber - Work order number
* @returns Work order URL
*/
workOrderUrl(workOrderNumber: number | string): string {
return `${this.#workOrderUrl}${workOrderNumber}`
}
/**
* Builds a URL for the work order search.
* @param searchString - Work order number or asset number search string
* @returns Work order search URL
*/
workOrderSearchUrl(searchString = ''): string {
return `${this.#workOrderSearchUrl}${searchString}`
}
}
export default FasterUrlBuilder