|
| 1 | +// Type definitions for psi 4.0 |
| 2 | +// Project: https://github.com/GoogleChromeLabs/psi#readme |
| 3 | +// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +/** |
| 7 | + * PageSpeed Insights with reporting |
| 8 | + */ |
| 9 | +declare function psi(url: string, options?: psi.Options): Promise<psi.ResponseData>; |
| 10 | + |
| 11 | +declare namespace psi { |
| 12 | + /** |
| 13 | + * Output the formatted report to the terminal. |
| 14 | + */ |
| 15 | + function output(url: string, options?: Options): Promise<ResponseData>; |
| 16 | + |
| 17 | + interface Options { |
| 18 | + /** |
| 19 | + * When using this module for a production-level build process, |
| 20 | + * registering for an API key from the Google Developer Console is recommended. |
| 21 | + */ |
| 22 | + key?: string; |
| 23 | + nokey?: string; |
| 24 | + /** |
| 25 | + * Strategy to use when analyzing the page. |
| 26 | + * @default 'mobile' |
| 27 | + */ |
| 28 | + strategy?: 'mobile' | 'desktop'; |
| 29 | + /** |
| 30 | + * Locale results should be generated in. |
| 31 | + * @default 'en_US' |
| 32 | + */ |
| 33 | + locale?: string; |
| 34 | + /** |
| 35 | + * Threshold score to pass the PageSpeed test. Useful for setting a performance budget. |
| 36 | + * @default 70 |
| 37 | + */ |
| 38 | + treshold?: number; |
| 39 | + } |
| 40 | + |
| 41 | + interface Experience { |
| 42 | + id: string; |
| 43 | + metrics: { |
| 44 | + [key: string]: { |
| 45 | + percentile: number; |
| 46 | + distributions: Array<{ |
| 47 | + min: number; |
| 48 | + max: number; |
| 49 | + proportion: number; |
| 50 | + }>; |
| 51 | + category: string; |
| 52 | + }; |
| 53 | + }; |
| 54 | + overall_category: string; |
| 55 | + initial_url: string; |
| 56 | + } |
| 57 | + |
| 58 | + interface Environment { |
| 59 | + networkUserAgent: string; |
| 60 | + hostUserAgent: string; |
| 61 | + benchmarkIndex: number; |
| 62 | + } |
| 63 | + |
| 64 | + interface ConfigSettings { |
| 65 | + emulatedFormFactor: string; |
| 66 | + locale: string; |
| 67 | + onlyCategories: object; |
| 68 | + } |
| 69 | + |
| 70 | + interface Audit { |
| 71 | + id: string; |
| 72 | + title: string; |
| 73 | + description: string; |
| 74 | + score: object; |
| 75 | + displayValue: string; |
| 76 | + scoreDisplayMode: string; |
| 77 | + explanation: string; |
| 78 | + errorMessage: string; |
| 79 | + warnings: object; |
| 80 | + details: { |
| 81 | + [key: string]: object; |
| 82 | + }; |
| 83 | + } |
| 84 | + |
| 85 | + interface AuditRef { |
| 86 | + id: string; |
| 87 | + weight: number; |
| 88 | + group: string; |
| 89 | + } |
| 90 | + |
| 91 | + interface Category { |
| 92 | + id: string; |
| 93 | + title: string; |
| 94 | + description: string; |
| 95 | + score: object; |
| 96 | + manualDescription: string; |
| 97 | + auditRefs: AuditRef[]; |
| 98 | + } |
| 99 | + |
| 100 | + interface CategoryGroup { |
| 101 | + title: string; |
| 102 | + description: string; |
| 103 | + } |
| 104 | + |
| 105 | + interface RuntimeError { |
| 106 | + code: string; |
| 107 | + message: string; |
| 108 | + } |
| 109 | + |
| 110 | + interface Timing { |
| 111 | + total: number; |
| 112 | + } |
| 113 | + |
| 114 | + interface RendererFormattedStrings { |
| 115 | + varianceDisclaimer: string; |
| 116 | + opportunityResourceColumnLabel: string; |
| 117 | + opportunitySavingsColumnLabel: string; |
| 118 | + errorMissingAuditInfo: string; |
| 119 | + errorLabel: string; |
| 120 | + warningHeader: string; |
| 121 | + auditGroupExpandTooltip: string; |
| 122 | + passedAuditsGroupTitle: string; |
| 123 | + notApplicableAuditsGroupTitle: string; |
| 124 | + manualAuditsGroupTitle: string; |
| 125 | + toplevelWarningsMessage: string; |
| 126 | + scorescaleLabel: string; |
| 127 | + crcLongestDurationLabel: string; |
| 128 | + crcInitialNavigation: string; |
| 129 | + lsPerformanceCategoryDescription: string; |
| 130 | + labDataTitle: string; |
| 131 | + } |
| 132 | + |
| 133 | + // tslint:disable-next-line:interface-name I18N is established convention |
| 134 | + interface I18N { |
| 135 | + rendererFormattedStrings: RendererFormattedStrings; |
| 136 | + } |
| 137 | + |
| 138 | + interface Version { |
| 139 | + major: number; |
| 140 | + minor: number; |
| 141 | + } |
| 142 | + |
| 143 | + interface ResponseData { |
| 144 | + data: Result; |
| 145 | + } |
| 146 | + |
| 147 | + interface LighthouseResult { |
| 148 | + requestedUrl: string; |
| 149 | + finalUrl: string; |
| 150 | + lighthouseVersion: string; |
| 151 | + userAgent: string; |
| 152 | + fetchTime: string; |
| 153 | + environment: Environment; |
| 154 | + runWarnings: string[]; |
| 155 | + configSettings: ConfigSettings; |
| 156 | + audits: { |
| 157 | + [key: string]: Audit; |
| 158 | + }; |
| 159 | + categories: { |
| 160 | + [key: string]: Category; |
| 161 | + }; |
| 162 | + categoryGroups: { |
| 163 | + [key: string]: CategoryGroup; |
| 164 | + }; |
| 165 | + runtimeError: RuntimeError; |
| 166 | + timing: Timing; |
| 167 | + i18n: I18N; |
| 168 | + } |
| 169 | + interface Result { |
| 170 | + captchaResult: string; |
| 171 | + kind: string; |
| 172 | + id: string; |
| 173 | + loadingExperience: Experience; |
| 174 | + originLoadingExperience: Experience; |
| 175 | + lighthouseResult: LighthouseResult; |
| 176 | + analysisUTCTimestamp: string; |
| 177 | + version: Version; |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +export = psi; |
0 commit comments