@tinkoff/perfume 0.0.0-stage → 1.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.
- package/LICENSE +21 -0
- package/README.md +523 -2
- package/dist/index.d.ts +256 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +708 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { ReportOpts } from "web-vitals";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
export interface Metric {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the metric (in acronym form).
|
|
6
|
+
*/
|
|
7
|
+
name: 'CLS' | 'FCP' | 'FID' | 'LCP' | 'TTFB' | 'RT' | 'TBT' | 'NTBT' | 'ET' | 'INP';
|
|
8
|
+
/**
|
|
9
|
+
* The current value of the metric.
|
|
10
|
+
*/
|
|
11
|
+
value: number;
|
|
12
|
+
/**
|
|
13
|
+
* The rating as to whether the metric value is within the "good",
|
|
14
|
+
* "needs improvement", or "poor" thresholds of the metric.
|
|
15
|
+
*/
|
|
16
|
+
rating: IVitalsScore;
|
|
17
|
+
/**
|
|
18
|
+
* The delta between the current value and the last-reported value.
|
|
19
|
+
* On the first report, `delta` and `value` will always be the same.
|
|
20
|
+
*/
|
|
21
|
+
delta?: number;
|
|
22
|
+
/**
|
|
23
|
+
* A unique ID representing this particular metric instance. This ID can
|
|
24
|
+
* be used by an analytics tool to dedupe multiple values sent for the same
|
|
25
|
+
* metric instance, or to group multiple deltas together and calculate a
|
|
26
|
+
* total. It can also be used to differentiate multiple different metric
|
|
27
|
+
* instances sent from the same page, which can happen if the page is
|
|
28
|
+
* restored from the back/forward cache (in that case new metrics object
|
|
29
|
+
* get created).
|
|
30
|
+
*/
|
|
31
|
+
id?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Any performance entries relevant to the metric value calculation.
|
|
34
|
+
* The array may also be empty if the metric value was not based on any
|
|
35
|
+
* entries (e.g. a CLS value of 0 given no layout shifts).
|
|
36
|
+
*/
|
|
37
|
+
entries?: PerformanceEntry[];
|
|
38
|
+
/**
|
|
39
|
+
* The type of navigation
|
|
40
|
+
*
|
|
41
|
+
* Navigation Timing API (or `undefined` if the browser doesn't
|
|
42
|
+
* support that API). For pages that are restored from the bfcache, this
|
|
43
|
+
* value will be 'back-forward-cache'.
|
|
44
|
+
*/
|
|
45
|
+
navigationType?: INavigationType;
|
|
46
|
+
/**
|
|
47
|
+
* An object containing potentially-helpful debugging information that
|
|
48
|
+
* can be sent along with the metric value for the current page visit in
|
|
49
|
+
* order to help identify issues happening to real-users in the field.
|
|
50
|
+
*/
|
|
51
|
+
attribution: {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface IAnalyticsTrackerOptions {
|
|
56
|
+
attribution: object;
|
|
57
|
+
data: IPerfumeData;
|
|
58
|
+
metricName: string;
|
|
59
|
+
navigatorInformation: INavigatorInfo;
|
|
60
|
+
rating: IVitalsScore;
|
|
61
|
+
navigationType?: INavigationType;
|
|
62
|
+
}
|
|
63
|
+
interface WebVitalsReportOptions {
|
|
64
|
+
ttfb?: ReportOpts;
|
|
65
|
+
cls?: ReportOpts;
|
|
66
|
+
fcp?: ReportOpts;
|
|
67
|
+
fid?: ReportOpts;
|
|
68
|
+
lcp?: ReportOpts;
|
|
69
|
+
inp?: ReportOpts;
|
|
70
|
+
}
|
|
71
|
+
export interface IPerfumeConfig {
|
|
72
|
+
isResourceTiming: boolean;
|
|
73
|
+
isElementTiming: boolean;
|
|
74
|
+
analyticsTracker?: (options: IAnalyticsTrackerOptions) => void;
|
|
75
|
+
maxTime: number;
|
|
76
|
+
reportOptions: WebVitalsReportOptions;
|
|
77
|
+
steps?: IStepsConfig;
|
|
78
|
+
onMarkStep?: (mark: string, steps: string[]) => void;
|
|
79
|
+
}
|
|
80
|
+
export interface IPerfumeOptions {
|
|
81
|
+
resourceTiming?: boolean;
|
|
82
|
+
elementTiming?: boolean;
|
|
83
|
+
analyticsTracker?: (options: IAnalyticsTrackerOptions) => void;
|
|
84
|
+
maxMeasureTime?: number;
|
|
85
|
+
reportOptions?: WebVitalsReportOptions;
|
|
86
|
+
steps?: IStepsConfig;
|
|
87
|
+
onMarkStep?: (mark: string, steps: string[]) => void;
|
|
88
|
+
}
|
|
89
|
+
export interface IMetricMap {
|
|
90
|
+
[measureName: string]: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface INavigatorInfo {
|
|
93
|
+
deviceMemory?: number;
|
|
94
|
+
hardwareConcurrency?: number;
|
|
95
|
+
isLowEndDevice?: boolean;
|
|
96
|
+
isLowEndExperience?: boolean;
|
|
97
|
+
serviceWorkerStatus?: 'controlled' | 'supported' | 'unsupported';
|
|
98
|
+
}
|
|
99
|
+
export interface IPerfObservers {
|
|
100
|
+
[measureName: string]: any;
|
|
101
|
+
}
|
|
102
|
+
export type IPerformanceObserverType = 'first-input' | 'largest-contentful-paint' | 'layout-shift' | 'longtask' | 'measure' | 'navigation' | 'paint' | 'element' | 'resource';
|
|
103
|
+
export type IPerformanceEntryInitiatorType = 'beacon' | 'css' | 'fetch' | 'img' | 'other' | 'script' | 'xmlhttprequest';
|
|
104
|
+
export declare interface IPerformanceEntry {
|
|
105
|
+
decodedBodySize?: number;
|
|
106
|
+
duration: number;
|
|
107
|
+
entryType: IPerformanceObserverType;
|
|
108
|
+
initiatorType?: IPerformanceEntryInitiatorType;
|
|
109
|
+
loadTime: number;
|
|
110
|
+
name: string;
|
|
111
|
+
renderTime: number;
|
|
112
|
+
startTime: number;
|
|
113
|
+
hadRecentInput?: boolean;
|
|
114
|
+
value?: number;
|
|
115
|
+
identifier?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface PerformanceEventTiming extends PerformanceEntry {
|
|
118
|
+
processingStart: DOMHighResTimeStamp;
|
|
119
|
+
target?: Node;
|
|
120
|
+
}
|
|
121
|
+
export interface IPerformancePaintTiming {
|
|
122
|
+
name: string;
|
|
123
|
+
entryType: string;
|
|
124
|
+
startTime: number;
|
|
125
|
+
duration: number;
|
|
126
|
+
}
|
|
127
|
+
export interface IPerfumeNavigationTiming {
|
|
128
|
+
fetchTime?: number;
|
|
129
|
+
workerTime?: number;
|
|
130
|
+
totalTime?: number;
|
|
131
|
+
downloadTime?: number;
|
|
132
|
+
timeToFirstByte?: number;
|
|
133
|
+
headerSize?: number;
|
|
134
|
+
dnsLookupTime?: number;
|
|
135
|
+
redirectTime?: number;
|
|
136
|
+
}
|
|
137
|
+
export type EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g' | 'lte';
|
|
138
|
+
export interface IPerfumeNetworkInformation {
|
|
139
|
+
downlink?: number;
|
|
140
|
+
effectiveType?: EffectiveConnectionType;
|
|
141
|
+
onchange?: () => void;
|
|
142
|
+
rtt?: number;
|
|
143
|
+
saveData?: boolean;
|
|
144
|
+
}
|
|
145
|
+
export interface IPerfumeDataConsumption {
|
|
146
|
+
beacon: number;
|
|
147
|
+
css: number;
|
|
148
|
+
fetch: number;
|
|
149
|
+
img: number;
|
|
150
|
+
other: number;
|
|
151
|
+
script: number;
|
|
152
|
+
total: number;
|
|
153
|
+
xmlhttprequest: number;
|
|
154
|
+
}
|
|
155
|
+
export type IPerfumeData = number | IPerfumeNavigationTiming | IPerfumeNetworkInformation;
|
|
156
|
+
export type IVitalsScore = 'good' | 'needsImprovement' | 'poor' | null;
|
|
157
|
+
export type INavigationType = 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender';
|
|
158
|
+
export interface IVitalsThresholds {
|
|
159
|
+
vitalsThresholds: [number, number];
|
|
160
|
+
}
|
|
161
|
+
export interface IOutlierThreshold {
|
|
162
|
+
maxOutlierThreshold: number;
|
|
163
|
+
}
|
|
164
|
+
export declare enum IThresholdTier {
|
|
165
|
+
instant = "instant",
|
|
166
|
+
quick = "quick",
|
|
167
|
+
moderate = "moderate",
|
|
168
|
+
slow = "slow",
|
|
169
|
+
unavoidable = "unavoidable"
|
|
170
|
+
}
|
|
171
|
+
export type IStepsThresholdConfig = IVitalsThresholds & IOutlierThreshold;
|
|
172
|
+
export type IStepsThresholds = { [key in IThresholdTier]: IStepsThresholdConfig; };
|
|
173
|
+
export type ISteps<Steps extends string> = {
|
|
174
|
+
steps: Steps[];
|
|
175
|
+
} & Partial<IOutlierThreshold>;
|
|
176
|
+
export interface IStepMarks<Marks extends string> {
|
|
177
|
+
marks: [Marks | 'launch', Marks];
|
|
178
|
+
}
|
|
179
|
+
export type IStepConfig<Marks extends string> = {
|
|
180
|
+
threshold: IThresholdTier;
|
|
181
|
+
} & IStepMarks<Marks>;
|
|
182
|
+
export type IStepsConfig = Record<string, IStepConfig<string>>;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/initPerfume.d.ts
|
|
185
|
+
export declare const initPerfume: (options?: IPerfumeOptions) => void;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/steps/markStep.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* Function which creates a step mark with a name generated
|
|
190
|
+
* from the provided mark when called.
|
|
191
|
+
*
|
|
192
|
+
* The generated mark name has the following format:
|
|
193
|
+
* `mark.${mark}`
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
export declare const markStep: (mark: string) => void;
|
|
197
|
+
/**
|
|
198
|
+
* Start performance measurement
|
|
199
|
+
*/
|
|
200
|
+
export declare const start: (markName: string) => void;
|
|
201
|
+
/**
|
|
202
|
+
* End performance measurement
|
|
203
|
+
*/
|
|
204
|
+
export declare const end: (markName: string, customProperties?: {}, doLogData?: boolean) => void;
|
|
205
|
+
/**
|
|
206
|
+
* Removes the named mark from the browser's performance entry buffer.
|
|
207
|
+
*/
|
|
208
|
+
export declare const clear: (markName: string) => void;
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/steps/markStepOnce.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Function which creates a step mark with a name generated
|
|
213
|
+
* from the provided mark if a mark with the same name does not
|
|
214
|
+
* already exist when called.
|
|
215
|
+
*
|
|
216
|
+
* The generated mark name has the following format:
|
|
217
|
+
* `mark.${mark}`
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
export declare const markStepOnce: (mark: string) => void;
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/steps/navigationSteps.d.ts
|
|
223
|
+
/**
|
|
224
|
+
* An API consumers must use to update internal state based on page/screen navigations.
|
|
225
|
+
* Internal state must be updated when the following are true
|
|
226
|
+
* 1. Journey marks are hit
|
|
227
|
+
* 2. Page navigations occur
|
|
228
|
+
* This function ensures the 2nd case is covered to help prevent "stale"
|
|
229
|
+
* steps that don't hit their final mark because the users navigates
|
|
230
|
+
* backwards in journey.
|
|
231
|
+
*/
|
|
232
|
+
export declare const trackUJNavigation: () => void;
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/markNTBT.d.ts
|
|
235
|
+
/**
|
|
236
|
+
* NTBT = Navigation Total Blocking Time
|
|
237
|
+
*
|
|
238
|
+
* This metric measures the amount of time the application may be blocked
|
|
239
|
+
* from processing code during the 2s window after a user navigates
|
|
240
|
+
* from page A to page B.
|
|
241
|
+
*
|
|
242
|
+
* Because this library is navigation agnostic, we have this method
|
|
243
|
+
* to mark when the navigation starts.
|
|
244
|
+
*
|
|
245
|
+
* The NTBT metric is the summation of the blocking time of all long tasks
|
|
246
|
+
* in the 2s window after this method is invoked.
|
|
247
|
+
*
|
|
248
|
+
* If this method is called before the 2s window ends; it will trigger a new
|
|
249
|
+
* NTBT measurement and interrupt the previous one.
|
|
250
|
+
*
|
|
251
|
+
* Credit: Thank you Steven Lam for helping with this!
|
|
252
|
+
*/
|
|
253
|
+
export declare const markNTBT: () => void;
|
|
254
|
+
//#endregion
|
|
255
|
+
export {};
|
|
256
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/initPerfume.ts","../src/steps/markStep.ts","../src/steps/markStepOnce.ts","../src/steps/navigationSteps.ts","../src/markNTBT.ts"],"mappings":";;iBAEiB;;;;EAIf;;;;EAcA;;;;;EAKA,QAAQ;;;;;EAKR;;;;;;;;;;EAUA;;;;;;EAMA,UAAU;;;;;;;;EAQV,iBAAiB;;;;;;EAOjB;KACG;;;iBAIY;EACf;EACA,MAAM;EACN;EACA,sBAAsB;EACtB,QAAQ;EACR,iBAAiB;;UAGT;EACR,OAAO;EACP,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;;iBAGS;EAEf;EACA;EAEA,oBAAoB,SAAS;EAE7B;EAEA,eAAe;EAEf,QAAQ;EAER,cAAc,cAAc;;iBAGb;EAEf;EACA;EAEA,oBAAoB,SAAS;EAE7B;EAEA,gBAAgB;EAEhB,QAAQ;EAER,cAAc,cAAc;;iBAGb;GACd;;iBAGc;EACf;EACA;EACA;EACA;EACA;;iBAGe;GACd;;YAGS;YAWA;yBAGa;EACvB;EACA;EACA,WAAW;EACX,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;;iBAIe,+BAA+B;EAC9C,iBAAiB;EACjB,SAAS;;iBAGM;EACf;EACA;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU;iBAEK;EACf;EACA,gBAAgB;EAChB;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,wBACD,2BAA2B;YAE1B;YAEA;iBAGK;EACf;;iBAEe;EACf;;oBAGU;EACV;EACA;EACA;EACA;EACA;;YAGU,wBAAwB,oBAAoB;YAC5C,sBACT,OAAO,iBAAiB;YAGf,OAAO;EACjB,OAAO;IACL,QAAQ;iBAEK,WAAW;EAC1B,QAAQ,kBAAkB;;YAGhB,YAAY;EACtB,WAAW;IACT,WAAW;YAEH,eAAe,eAAe;;;qBCjO7B,cAAe,UAAS;;;;;;;;;;;qBCHxB,WAAY;;;;qBAcZ,QAAS;;;;qBAYT,MACX,kBACA,uBACA;;;;qBAiBW,QAAS;;;;;;;;;;;;qBClDT,eAAgB;;;;;;;;;;;;qBC0GhB;;;;;;;;;;;;;;;;;;;;;qBC7FA"}
|