-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
8,680 additions
and
8,651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": ["./tsconfig.json"], | ||
"ecmaVersion": 2022, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["eslint-config-cityssm"] | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": ["./tsconfig.json"], | ||
"ecmaVersion": 2022, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["eslint-config-cityssm"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
*.ejs | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"trailingComma": "none", | ||
"tabWidth": 4, | ||
"semi": true, | ||
"singleQuote": false, | ||
"printWidth": 100 | ||
} | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true, | ||
"bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import type { Browser } from 'puppeteer' | ||
import puppeteer from 'puppeteer' | ||
import { clearIntervalAsync } from 'set-interval-async' | ||
import { setIntervalAsync } from 'set-interval-async/dynamic' | ||
|
||
/* | ||
* Headless Debug Setting | ||
*/ | ||
|
||
let headless = true | ||
|
||
export const setHeadless = (headlessStatus: boolean): void => { | ||
headless = headlessStatus | ||
} | ||
|
||
/* | ||
* Browser Global | ||
*/ | ||
|
||
export const pageTimeoutMillis = 90_000 | ||
const browserStartupTimeoutMillis = 3 * 60_000 | ||
|
||
const browserGlobalExpiryMillis = | ||
Math.max(browserStartupTimeoutMillis, pageTimeoutMillis) + 10_000 | ||
|
||
let browserGlobal: Browser | undefined | ||
let browserGlobalInitializedTime = 0 | ||
let browserGlobalTimer | ||
|
||
function isBrowserGlobalReady(): boolean { | ||
return Boolean( | ||
browserGlobal !== undefined && | ||
browserGlobalInitializedTime + browserGlobalExpiryMillis > Date.now() | ||
) | ||
} | ||
|
||
export async function getBrowserGlobal(): Promise<Browser> { | ||
if (!isBrowserGlobalReady()) { | ||
await cleanUpBrowserGlobal() | ||
|
||
keepBrowserGlobalAlive() | ||
|
||
browserGlobal = await puppeteer.launch({ | ||
headless: headless ? 'new' : false, | ||
timeout: browserStartupTimeoutMillis, | ||
args: ['--lang-en-CA,en'] | ||
}) | ||
|
||
keepBrowserGlobalAlive() | ||
|
||
browserGlobalTimer = setIntervalAsync( | ||
cleanUpBrowserGlobal, | ||
browserGlobalExpiryMillis | ||
) | ||
} | ||
|
||
return browserGlobal as Browser | ||
} | ||
|
||
export function keepBrowserGlobalAlive(): void { | ||
browserGlobalInitializedTime = Date.now() | ||
} | ||
|
||
export async function cleanUpBrowserGlobal(useForce = false): Promise<void> { | ||
if (useForce) { | ||
browserGlobalInitializedTime = 0 | ||
} | ||
|
||
if (!isBrowserGlobalReady()) { | ||
try { | ||
await browserGlobal.close() | ||
} catch { | ||
// ignore | ||
} | ||
|
||
browserGlobal = undefined | ||
|
||
if (browserGlobalTimer) { | ||
try { | ||
await clearIntervalAsync(browserGlobalTimer) | ||
} catch { | ||
// ignore | ||
} | ||
|
||
browserGlobalTimer = undefined | ||
} | ||
|
||
browserGlobalInitializedTime = 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { getClearanceByAccountNumber, cleanUpBrowser } from "./index.js"; | ||
import { getClearanceByAccountNumber, cleanUpBrowser } from './index.js' | ||
|
||
const cli = async () => { | ||
const accountNumbers = process.argv[2].split(","); | ||
const accountNumbers = process.argv[2].split(',') | ||
|
||
for (const accountNumber of accountNumbers) { | ||
const results = await getClearanceByAccountNumber(accountNumber); | ||
console.log(results); | ||
} | ||
for (const accountNumber of accountNumbers) { | ||
const results = await getClearanceByAccountNumber(accountNumber) | ||
console.log(results) | ||
} | ||
|
||
await cleanUpBrowser(); | ||
}; | ||
await cleanUpBrowser() | ||
} | ||
|
||
cli(); | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
export const clearanceStart_url = "https://clearances.wsib.ca/Clearances/eclearance/start"; | ||
export const clearanceStart_searchFormSelector = "#TOKENSimpleSearchForm"; | ||
export const clearanceStart_searchFieldSelector = "#simpleAccountNumbersTOKEN"; | ||
export const clearanceStart_url = 'https://clearances.wsib.ca/Clearances/eclearance/start'; | ||
export const clearanceStart_searchFormSelector = '#TOKENSimpleSearchForm'; | ||
export const clearanceStart_searchFieldSelector = '#simpleAccountNumbersTOKEN'; | ||
export const clearanceResult_certificateLinkSelector = "#eClearanceWorkspaceTargSubDivFormXX .fancytable a[rel='eClearanceWorkspaceContent'][href^='GCSearchCertDet']"; | ||
export const clearanceResult_certificateBadStandingSelector = "#eClearanceWorkspaceTargSubDivFormXX .fancytable .badstanding"; | ||
export const clearanceResult_defaultErrorMessage = "Clearance certificate link not found."; | ||
export const certificate_tableSelector = "#eClearanceWorkspaceDivForm .fancytable"; | ||
export const certificateField_contractorLegalTradeName = "Contractor Legal / Trade Name"; | ||
export const certificateField_contractorAddress = "Contractor Address"; | ||
export const certificateField_naicsCodes = "Contractor NAICS Code and Code Description"; | ||
export const certificateField_clearanceCertificateNumber = "Clearance certificate number"; | ||
export const certificateField_validityPeriod = "Validity period (dd-mmm-yyyy)"; | ||
export const certificateField_principalLegalTradeName = "Principal Legal / Trade Name"; | ||
export const certificateField_principalAddress = "Principal Address"; | ||
export const clearanceResult_certificateBadStandingSelector = '#eClearanceWorkspaceTargSubDivFormXX .fancytable .badstanding'; | ||
export const clearanceResult_defaultErrorMessage = 'Clearance certificate link not found.'; | ||
export const certificate_tableSelector = '#eClearanceWorkspaceDivForm .fancytable'; | ||
export const certificateField_contractorLegalTradeName = 'Contractor Legal / Trade Name'; | ||
export const certificateField_contractorAddress = 'Contractor Address'; | ||
export const certificateField_naicsCodes = 'Contractor NAICS Code and Code Description'; | ||
export const certificateField_clearanceCertificateNumber = 'Clearance certificate number'; | ||
export const certificateField_validityPeriod = 'Validity period (dd-mmm-yyyy)'; | ||
export const certificateField_principalLegalTradeName = 'Principal Legal / Trade Name'; | ||
export const certificateField_principalAddress = 'Principal Address'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
// Search Form | ||
|
||
export const clearanceStart_url = "https://clearances.wsib.ca/Clearances/eclearance/start"; | ||
export const clearanceStart_url = | ||
'https://clearances.wsib.ca/Clearances/eclearance/start' | ||
|
||
export const clearanceStart_searchFormSelector = "#TOKENSimpleSearchForm"; | ||
export const clearanceStart_searchFieldSelector = "#simpleAccountNumbersTOKEN"; | ||
export const clearanceStart_searchFormSelector = '#TOKENSimpleSearchForm' | ||
export const clearanceStart_searchFieldSelector = '#simpleAccountNumbersTOKEN' | ||
|
||
// Search Results | ||
|
||
export const clearanceResult_certificateLinkSelector = | ||
"#eClearanceWorkspaceTargSubDivFormXX .fancytable a[rel='eClearanceWorkspaceContent'][href^='GCSearchCertDet']"; | ||
"#eClearanceWorkspaceTargSubDivFormXX .fancytable a[rel='eClearanceWorkspaceContent'][href^='GCSearchCertDet']" | ||
export const clearanceResult_certificateBadStandingSelector = | ||
"#eClearanceWorkspaceTargSubDivFormXX .fancytable .badstanding"; | ||
export const clearanceResult_defaultErrorMessage = "Clearance certificate link not found."; | ||
'#eClearanceWorkspaceTargSubDivFormXX .fancytable .badstanding' | ||
export const clearanceResult_defaultErrorMessage = | ||
'Clearance certificate link not found.' | ||
|
||
// Certificate | ||
|
||
export const certificate_tableSelector = "#eClearanceWorkspaceDivForm .fancytable"; | ||
export const certificate_tableSelector = | ||
'#eClearanceWorkspaceDivForm .fancytable' | ||
|
||
export const certificateField_contractorLegalTradeName = "Contractor Legal / Trade Name"; | ||
export const certificateField_contractorAddress = "Contractor Address"; | ||
export const certificateField_naicsCodes = "Contractor NAICS Code and Code Description"; | ||
export const certificateField_clearanceCertificateNumber = "Clearance certificate number"; | ||
export const certificateField_validityPeriod = "Validity period (dd-mmm-yyyy)"; | ||
export const certificateField_principalLegalTradeName = "Principal Legal / Trade Name"; | ||
export const certificateField_principalAddress = "Principal Address"; | ||
export const certificateField_contractorLegalTradeName = | ||
'Contractor Legal / Trade Name' | ||
export const certificateField_contractorAddress = 'Contractor Address' | ||
export const certificateField_naicsCodes = | ||
'Contractor NAICS Code and Code Description' | ||
export const certificateField_clearanceCertificateNumber = | ||
'Clearance certificate number' | ||
export const certificateField_validityPeriod = 'Validity period (dd-mmm-yyyy)' | ||
export const certificateField_principalLegalTradeName = | ||
'Principal Legal / Trade Name' | ||
export const certificateField_principalAddress = 'Principal Address' |
Oops, something went wrong.