@amplitude/analytics-core 2.12.0 → 2.12.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/README.md +1 -1
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/network-observer.d.ts +5 -27
- package/lib/cjs/network-observer.d.ts.map +1 -1
- package/lib/cjs/network-observer.js +195 -122
- package/lib/cjs/network-observer.js.map +1 -1
- package/lib/cjs/network-request-event.d.ts +141 -0
- package/lib/cjs/network-request-event.d.ts.map +1 -0
- package/lib/cjs/network-request-event.js +333 -0
- package/lib/cjs/network-request-event.js.map +1 -0
- package/lib/cjs/storage/cookie.js +5 -5
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/types/browser-config.d.ts +3 -2
- package/lib/cjs/types/browser-config.d.ts.map +1 -1
- package/lib/cjs/types/browser-config.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/network-observer.d.ts +5 -27
- package/lib/esm/network-observer.d.ts.map +1 -1
- package/lib/esm/network-observer.js +193 -119
- package/lib/esm/network-observer.js.map +1 -1
- package/lib/esm/network-request-event.d.ts +141 -0
- package/lib/esm/network-request-event.d.ts.map +1 -0
- package/lib/esm/network-request-event.js +330 -0
- package/lib/esm/network-request-event.js.map +1 -0
- package/lib/esm/storage/cookie.js +5 -5
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/types/browser-config.d.ts +3 -2
- package/lib/esm/types/browser-config.d.ts.map +1 -1
- package/lib/esm/types/browser-config.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
type BlobSafe = {
|
|
2
|
+
size: number;
|
|
3
|
+
};
|
|
4
|
+
type ArrayBufferSafe = {
|
|
5
|
+
byteLength: number;
|
|
6
|
+
};
|
|
7
|
+
type ArrayBufferViewSafe = {
|
|
8
|
+
byteLength: number;
|
|
9
|
+
};
|
|
10
|
+
type URLSearchParamsSafe = {
|
|
11
|
+
toString(): string;
|
|
12
|
+
};
|
|
13
|
+
type FormDataEntryValueSafe = string | BlobSafe | null;
|
|
14
|
+
type BodyInitSafe = string | Blob | ArrayBufferSafe | FormDataSafe | URLSearchParamsSafe | ArrayBufferViewSafe | null | undefined;
|
|
15
|
+
type HeadersRequestSafe = {
|
|
16
|
+
entries(): IterableIterator<[string, string]>;
|
|
17
|
+
forEach(callbackfn: (value: string, key: string) => void): void;
|
|
18
|
+
};
|
|
19
|
+
type HeadersResponseSafe = {
|
|
20
|
+
get(name: string): string | null;
|
|
21
|
+
forEach(callbackfn: (value: string, key: string) => void): void;
|
|
22
|
+
};
|
|
23
|
+
type HeadersInitSafe = HeadersRequestSafe | Record<string, string> | string[][];
|
|
24
|
+
type ResponseSafe = {
|
|
25
|
+
status: number;
|
|
26
|
+
headers: HeadersResponseSafe | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type RequestInitSafe = {
|
|
29
|
+
method?: string;
|
|
30
|
+
headers?: HeadersInitSafe;
|
|
31
|
+
body?: BodyInitSafe;
|
|
32
|
+
};
|
|
33
|
+
export interface FormDataSafe {
|
|
34
|
+
entries(): IterableIterator<[string, FormDataEntryValueSafe]>;
|
|
35
|
+
}
|
|
36
|
+
export type XMLHttpRequestBodyInitSafe = BlobSafe | FormDataSafe | URLSearchParamsSafe | string;
|
|
37
|
+
export type FetchRequestBody = string | BlobSafe | ArrayBufferSafe | FormDataSafe | URLSearchParamsSafe | ArrayBufferViewSafe | null | undefined;
|
|
38
|
+
export interface IRequestWrapper {
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
bodySize?: number;
|
|
41
|
+
method?: string;
|
|
42
|
+
body?: FetchRequestBody | XMLHttpRequestBodyInitSafe | null;
|
|
43
|
+
}
|
|
44
|
+
export declare const MAXIMUM_ENTRIES = 100;
|
|
45
|
+
/**
|
|
46
|
+
* This class encapsulates the RequestInit (https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
47
|
+
* object so that the consumer can only get access to the headers, method and body size.
|
|
48
|
+
*
|
|
49
|
+
* This is to prevent consumers from directly accessing the Request object
|
|
50
|
+
* and mutating it or running costly operations on it.
|
|
51
|
+
*
|
|
52
|
+
* IMPORTANT:
|
|
53
|
+
* * Do not make changes to this class without careful consideration
|
|
54
|
+
* of performance implications, memory usage and potential to mutate the customer's
|
|
55
|
+
* request.
|
|
56
|
+
* * NEVER .clone() the RequestInit object. This will 2x's the memory overhead of the request
|
|
57
|
+
* * NEVER: call .arrayBuffer(), text(), json() or any other method on the body that
|
|
58
|
+
* consumes the body's stream. This will cause the response to be consumed
|
|
59
|
+
* meaning the body will be empty when the customer tries to access it.
|
|
60
|
+
* (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
61
|
+
* never call any of the methods on it)
|
|
62
|
+
*/
|
|
63
|
+
export declare class RequestWrapperFetch implements IRequestWrapper {
|
|
64
|
+
private request;
|
|
65
|
+
private _headers;
|
|
66
|
+
private _bodySize;
|
|
67
|
+
constructor(request: RequestInitSafe);
|
|
68
|
+
get headers(): Record<string, string> | undefined;
|
|
69
|
+
get bodySize(): number | undefined;
|
|
70
|
+
get method(): string | undefined;
|
|
71
|
+
}
|
|
72
|
+
export declare class RequestWrapperXhr implements IRequestWrapper {
|
|
73
|
+
readonly body: XMLHttpRequestBodyInitSafe | null;
|
|
74
|
+
constructor(body: XMLHttpRequestBodyInitSafe | null);
|
|
75
|
+
get bodySize(): number | undefined;
|
|
76
|
+
}
|
|
77
|
+
export interface IResponseWrapper {
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
bodySize?: number;
|
|
80
|
+
status?: number;
|
|
81
|
+
body?: string | Blob | ReadableStream | ArrayBuffer | FormDataSafe | URLSearchParams | ArrayBufferView | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* This class encapsulates the Fetch API Response object
|
|
85
|
+
* (https://developer.mozilla.org/en-US/docs/Web/API/Response) so that the consumer can
|
|
86
|
+
* only get access to the headers and body size.
|
|
87
|
+
*
|
|
88
|
+
* This is to prevent consumers from directly accessing the Response object
|
|
89
|
+
* and mutating it or running costly operations on it.
|
|
90
|
+
*
|
|
91
|
+
* IMPORTANT:
|
|
92
|
+
* * Do not make changes to this class without careful consideration
|
|
93
|
+
* of performance implications, memory usage and potential to mutate the customer's
|
|
94
|
+
* response.
|
|
95
|
+
* * NEVER .clone() the Response object. This will 2x's the memory overhead of the response
|
|
96
|
+
* * NEVER consume the body's stream. This will cause the response to be consumed
|
|
97
|
+
* meaning the body will be empty when the customer tries to access it.
|
|
98
|
+
* (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
99
|
+
* never call any of the methods on it)
|
|
100
|
+
*/
|
|
101
|
+
export declare class ResponseWrapperFetch implements IResponseWrapper {
|
|
102
|
+
private response;
|
|
103
|
+
private _headers;
|
|
104
|
+
private _bodySize;
|
|
105
|
+
constructor(response: ResponseSafe);
|
|
106
|
+
get headers(): Record<string, string> | undefined;
|
|
107
|
+
get bodySize(): number | undefined;
|
|
108
|
+
get status(): number;
|
|
109
|
+
}
|
|
110
|
+
export declare class ResponseWrapperXhr implements IResponseWrapper {
|
|
111
|
+
readonly statusCode: number;
|
|
112
|
+
readonly headersString: string;
|
|
113
|
+
readonly size: number | undefined;
|
|
114
|
+
constructor(statusCode: number, headersString: string, size: number | undefined);
|
|
115
|
+
get bodySize(): number | undefined;
|
|
116
|
+
get status(): number;
|
|
117
|
+
get headers(): Record<string, string> | undefined;
|
|
118
|
+
}
|
|
119
|
+
export declare class NetworkRequestEvent {
|
|
120
|
+
readonly type: 'xhr' | 'fetch';
|
|
121
|
+
readonly method: string;
|
|
122
|
+
readonly timestamp: number;
|
|
123
|
+
readonly startTime: number;
|
|
124
|
+
readonly url?: string | undefined;
|
|
125
|
+
readonly requestWrapper?: IRequestWrapper | undefined;
|
|
126
|
+
readonly status: number;
|
|
127
|
+
readonly duration?: number | undefined;
|
|
128
|
+
readonly responseWrapper?: IResponseWrapper | undefined;
|
|
129
|
+
readonly error?: {
|
|
130
|
+
name: string;
|
|
131
|
+
message: string;
|
|
132
|
+
} | undefined;
|
|
133
|
+
readonly endTime?: number | undefined;
|
|
134
|
+
constructor(type: 'xhr' | 'fetch', method: string, timestamp: number, startTime: number, url?: string | undefined, requestWrapper?: IRequestWrapper | undefined, status?: number, duration?: number | undefined, responseWrapper?: IResponseWrapper | undefined, error?: {
|
|
135
|
+
name: string;
|
|
136
|
+
message: string;
|
|
137
|
+
} | undefined, endTime?: number | undefined);
|
|
138
|
+
toSerializable(): Record<string, any>;
|
|
139
|
+
}
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=network-request-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-request-event.d.ts","sourceRoot":"","sources":["../../src/network-request-event.ts"],"names":[],"mappings":"AAMA,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,QAAQ,IAAI,MAAM,CAAC;CACpB,CAAC;AAKF,KAAK,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEvD,KAAK,YAAY,GACb,MAAM,GACN,IAAI,GACJ,eAAe,GACf,YAAY,GACZ,mBAAmB,GACnB,mBAAmB,GACnB,IAAI,GACJ,SAAS,CAAC;AAEd,KAAK,kBAAkB,GAAG;IACxB,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAA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export var MAXIMUM_ENTRIES = 100;
|
|
4
|
+
/**
|
|
5
|
+
* This class encapsulates the RequestInit (https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
6
|
+
* object so that the consumer can only get access to the headers, method and body size.
|
|
7
|
+
*
|
|
8
|
+
* This is to prevent consumers from directly accessing the Request object
|
|
9
|
+
* and mutating it or running costly operations on it.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT:
|
|
12
|
+
* * Do not make changes to this class without careful consideration
|
|
13
|
+
* of performance implications, memory usage and potential to mutate the customer's
|
|
14
|
+
* request.
|
|
15
|
+
* * NEVER .clone() the RequestInit object. This will 2x's the memory overhead of the request
|
|
16
|
+
* * NEVER: call .arrayBuffer(), text(), json() or any other method on the body that
|
|
17
|
+
* consumes the body's stream. This will cause the response to be consumed
|
|
18
|
+
* meaning the body will be empty when the customer tries to access it.
|
|
19
|
+
* (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
20
|
+
* never call any of the methods on it)
|
|
21
|
+
*/
|
|
22
|
+
var RequestWrapperFetch = /** @class */ (function () {
|
|
23
|
+
function RequestWrapperFetch(request) {
|
|
24
|
+
this.request = request;
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(RequestWrapperFetch.prototype, "headers", {
|
|
27
|
+
get: function () {
|
|
28
|
+
if (this._headers)
|
|
29
|
+
return this._headers;
|
|
30
|
+
var headersUnsafe = this.request.headers;
|
|
31
|
+
if (Array.isArray(headersUnsafe)) {
|
|
32
|
+
var headers = headersUnsafe;
|
|
33
|
+
this._headers = headers.reduce(function (acc, _a) {
|
|
34
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
35
|
+
acc[key] = value;
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
}
|
|
39
|
+
else if (headersUnsafe instanceof Headers) {
|
|
40
|
+
var headersSafe = headersUnsafe;
|
|
41
|
+
var headersObj_1 = {};
|
|
42
|
+
headersSafe.forEach(function (value, key) {
|
|
43
|
+
headersObj_1[key] = value;
|
|
44
|
+
});
|
|
45
|
+
this._headers = headersObj_1;
|
|
46
|
+
}
|
|
47
|
+
else if (typeof headersUnsafe === 'object') {
|
|
48
|
+
this._headers = headersUnsafe;
|
|
49
|
+
}
|
|
50
|
+
return this._headers;
|
|
51
|
+
},
|
|
52
|
+
enumerable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(RequestWrapperFetch.prototype, "bodySize", {
|
|
56
|
+
get: function () {
|
|
57
|
+
if (typeof this._bodySize === 'number')
|
|
58
|
+
return this._bodySize;
|
|
59
|
+
var global = getGlobalScope();
|
|
60
|
+
/* istanbul ignore if */
|
|
61
|
+
if (!(global === null || global === void 0 ? void 0 : global.TextEncoder)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var body = this.request.body;
|
|
65
|
+
this._bodySize = getBodySize(body, MAXIMUM_ENTRIES);
|
|
66
|
+
return this._bodySize;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(RequestWrapperFetch.prototype, "method", {
|
|
72
|
+
get: function () {
|
|
73
|
+
return this.request.method;
|
|
74
|
+
},
|
|
75
|
+
enumerable: false,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
return RequestWrapperFetch;
|
|
79
|
+
}());
|
|
80
|
+
export { RequestWrapperFetch };
|
|
81
|
+
var RequestWrapperXhr = /** @class */ (function () {
|
|
82
|
+
function RequestWrapperXhr(body) {
|
|
83
|
+
this.body = body;
|
|
84
|
+
}
|
|
85
|
+
Object.defineProperty(RequestWrapperXhr.prototype, "bodySize", {
|
|
86
|
+
get: function () {
|
|
87
|
+
return getBodySize(this.body, MAXIMUM_ENTRIES);
|
|
88
|
+
},
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
return RequestWrapperXhr;
|
|
93
|
+
}());
|
|
94
|
+
export { RequestWrapperXhr };
|
|
95
|
+
function getBodySize(bodyUnsafe, maxEntries) {
|
|
96
|
+
var e_1, _a;
|
|
97
|
+
var bodySize;
|
|
98
|
+
var global = getGlobalScope();
|
|
99
|
+
/* istanbul ignore next */
|
|
100
|
+
var TextEncoder = global === null || global === void 0 ? void 0 : global.TextEncoder;
|
|
101
|
+
/* istanbul ignore next */
|
|
102
|
+
if (!TextEncoder) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
var bodySafe;
|
|
106
|
+
if (typeof bodyUnsafe === 'string') {
|
|
107
|
+
bodySafe = bodyUnsafe;
|
|
108
|
+
bodySize = new TextEncoder().encode(bodySafe).length;
|
|
109
|
+
}
|
|
110
|
+
else if (bodyUnsafe instanceof Blob) {
|
|
111
|
+
bodySafe = bodyUnsafe;
|
|
112
|
+
bodySize = bodySafe.size;
|
|
113
|
+
}
|
|
114
|
+
else if (bodyUnsafe instanceof URLSearchParams) {
|
|
115
|
+
bodySafe = bodyUnsafe;
|
|
116
|
+
bodySize = new TextEncoder().encode(bodySafe.toString()).length;
|
|
117
|
+
}
|
|
118
|
+
else if (ArrayBuffer.isView(bodyUnsafe)) {
|
|
119
|
+
bodySafe = bodyUnsafe;
|
|
120
|
+
bodySize = bodySafe.byteLength;
|
|
121
|
+
}
|
|
122
|
+
else if (bodyUnsafe instanceof ArrayBuffer) {
|
|
123
|
+
bodySafe = bodyUnsafe;
|
|
124
|
+
bodySize = bodySafe.byteLength;
|
|
125
|
+
}
|
|
126
|
+
else if (bodyUnsafe instanceof FormData) {
|
|
127
|
+
// Estimating only for text parts; not accurate for files
|
|
128
|
+
var formData = bodyUnsafe;
|
|
129
|
+
var total = 0;
|
|
130
|
+
var count = 0;
|
|
131
|
+
try {
|
|
132
|
+
for (var _b = __values(formData.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
133
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
134
|
+
total += key.length;
|
|
135
|
+
if (typeof value === 'string') {
|
|
136
|
+
total += new TextEncoder().encode(value).length;
|
|
137
|
+
}
|
|
138
|
+
else if (value instanceof Blob) {
|
|
139
|
+
total += value.size;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// encountered an unknown type
|
|
143
|
+
// we can't estimate the size of this entry
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// terminate if we reach the maximum number of entries
|
|
147
|
+
// to avoid performance issues in case of very large FormData
|
|
148
|
+
if (++count >= maxEntries) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
154
|
+
finally {
|
|
155
|
+
try {
|
|
156
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
157
|
+
}
|
|
158
|
+
finally { if (e_1) throw e_1.error; }
|
|
159
|
+
}
|
|
160
|
+
bodySize = total;
|
|
161
|
+
}
|
|
162
|
+
else if (bodyUnsafe instanceof ReadableStream) {
|
|
163
|
+
// If bodyUnsafe is an instanceof ReadableStream, we can't determine the size,
|
|
164
|
+
// without consuming it, so we return undefined.
|
|
165
|
+
// Never ever consume ReadableStream! DO NOT DO IT!!!
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
167
|
+
bodySafe = bodyUnsafe;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
return bodySize;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* This class encapsulates the Fetch API Response object
|
|
174
|
+
* (https://developer.mozilla.org/en-US/docs/Web/API/Response) so that the consumer can
|
|
175
|
+
* only get access to the headers and body size.
|
|
176
|
+
*
|
|
177
|
+
* This is to prevent consumers from directly accessing the Response object
|
|
178
|
+
* and mutating it or running costly operations on it.
|
|
179
|
+
*
|
|
180
|
+
* IMPORTANT:
|
|
181
|
+
* * Do not make changes to this class without careful consideration
|
|
182
|
+
* of performance implications, memory usage and potential to mutate the customer's
|
|
183
|
+
* response.
|
|
184
|
+
* * NEVER .clone() the Response object. This will 2x's the memory overhead of the response
|
|
185
|
+
* * NEVER consume the body's stream. This will cause the response to be consumed
|
|
186
|
+
* meaning the body will be empty when the customer tries to access it.
|
|
187
|
+
* (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
188
|
+
* never call any of the methods on it)
|
|
189
|
+
*/
|
|
190
|
+
var ResponseWrapperFetch = /** @class */ (function () {
|
|
191
|
+
function ResponseWrapperFetch(response) {
|
|
192
|
+
this.response = response;
|
|
193
|
+
}
|
|
194
|
+
Object.defineProperty(ResponseWrapperFetch.prototype, "headers", {
|
|
195
|
+
get: function () {
|
|
196
|
+
var _a;
|
|
197
|
+
if (this._headers)
|
|
198
|
+
return this._headers;
|
|
199
|
+
if (this.response.headers instanceof Headers) {
|
|
200
|
+
var headersSafe = this.response.headers;
|
|
201
|
+
var headersOut_1 = {};
|
|
202
|
+
/* istanbul ignore next */
|
|
203
|
+
(_a = headersSafe === null || headersSafe === void 0 ? void 0 : headersSafe.forEach) === null || _a === void 0 ? void 0 : _a.call(headersSafe, function (value, key) {
|
|
204
|
+
headersOut_1[key] = value;
|
|
205
|
+
});
|
|
206
|
+
this._headers = headersOut_1;
|
|
207
|
+
return headersOut_1;
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
},
|
|
211
|
+
enumerable: false,
|
|
212
|
+
configurable: true
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(ResponseWrapperFetch.prototype, "bodySize", {
|
|
215
|
+
get: function () {
|
|
216
|
+
var _a, _b;
|
|
217
|
+
if (this._bodySize !== undefined)
|
|
218
|
+
return this._bodySize;
|
|
219
|
+
/* istanbul ignore next */
|
|
220
|
+
var contentLength = (_b = (_a = this.response.headers) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, 'content-length');
|
|
221
|
+
var bodySize = contentLength ? parseInt(contentLength, 10) : undefined;
|
|
222
|
+
this._bodySize = bodySize;
|
|
223
|
+
return bodySize;
|
|
224
|
+
},
|
|
225
|
+
enumerable: false,
|
|
226
|
+
configurable: true
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(ResponseWrapperFetch.prototype, "status", {
|
|
229
|
+
get: function () {
|
|
230
|
+
return this.response.status;
|
|
231
|
+
},
|
|
232
|
+
enumerable: false,
|
|
233
|
+
configurable: true
|
|
234
|
+
});
|
|
235
|
+
return ResponseWrapperFetch;
|
|
236
|
+
}());
|
|
237
|
+
export { ResponseWrapperFetch };
|
|
238
|
+
var ResponseWrapperXhr = /** @class */ (function () {
|
|
239
|
+
function ResponseWrapperXhr(statusCode, headersString, size) {
|
|
240
|
+
this.statusCode = statusCode;
|
|
241
|
+
this.headersString = headersString;
|
|
242
|
+
this.size = size;
|
|
243
|
+
}
|
|
244
|
+
Object.defineProperty(ResponseWrapperXhr.prototype, "bodySize", {
|
|
245
|
+
get: function () {
|
|
246
|
+
return this.size;
|
|
247
|
+
},
|
|
248
|
+
enumerable: false,
|
|
249
|
+
configurable: true
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(ResponseWrapperXhr.prototype, "status", {
|
|
252
|
+
get: function () {
|
|
253
|
+
return this.statusCode;
|
|
254
|
+
},
|
|
255
|
+
enumerable: false,
|
|
256
|
+
configurable: true
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(ResponseWrapperXhr.prototype, "headers", {
|
|
259
|
+
get: function () {
|
|
260
|
+
var e_2, _a;
|
|
261
|
+
if (!this.headersString) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
var headers = {};
|
|
265
|
+
var headerLines = this.headersString.split('\r\n');
|
|
266
|
+
try {
|
|
267
|
+
for (var headerLines_1 = __values(headerLines), headerLines_1_1 = headerLines_1.next(); !headerLines_1_1.done; headerLines_1_1 = headerLines_1.next()) {
|
|
268
|
+
var line = headerLines_1_1.value;
|
|
269
|
+
var _b = __read(line.split(': '), 2), key = _b[0], value = _b[1];
|
|
270
|
+
if (key && value) {
|
|
271
|
+
headers[key] = value;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
276
|
+
finally {
|
|
277
|
+
try {
|
|
278
|
+
if (headerLines_1_1 && !headerLines_1_1.done && (_a = headerLines_1.return)) _a.call(headerLines_1);
|
|
279
|
+
}
|
|
280
|
+
finally { if (e_2) throw e_2.error; }
|
|
281
|
+
}
|
|
282
|
+
return headers;
|
|
283
|
+
},
|
|
284
|
+
enumerable: false,
|
|
285
|
+
configurable: true
|
|
286
|
+
});
|
|
287
|
+
return ResponseWrapperXhr;
|
|
288
|
+
}());
|
|
289
|
+
export { ResponseWrapperXhr };
|
|
290
|
+
var NetworkRequestEvent = /** @class */ (function () {
|
|
291
|
+
function NetworkRequestEvent(type, method, timestamp, startTime, url, requestWrapper, status, duration, responseWrapper, error, endTime) {
|
|
292
|
+
if (status === void 0) { status = 0; }
|
|
293
|
+
this.type = type;
|
|
294
|
+
this.method = method;
|
|
295
|
+
this.timestamp = timestamp;
|
|
296
|
+
this.startTime = startTime;
|
|
297
|
+
this.url = url;
|
|
298
|
+
this.requestWrapper = requestWrapper;
|
|
299
|
+
this.status = status;
|
|
300
|
+
this.duration = duration;
|
|
301
|
+
this.responseWrapper = responseWrapper;
|
|
302
|
+
this.error = error;
|
|
303
|
+
this.endTime = endTime;
|
|
304
|
+
}
|
|
305
|
+
NetworkRequestEvent.prototype.toSerializable = function () {
|
|
306
|
+
var _a, _b, _c, _d;
|
|
307
|
+
var serialized = {
|
|
308
|
+
type: this.type,
|
|
309
|
+
method: this.method,
|
|
310
|
+
url: this.url,
|
|
311
|
+
timestamp: this.timestamp,
|
|
312
|
+
status: this.status,
|
|
313
|
+
duration: this.duration,
|
|
314
|
+
error: this.error,
|
|
315
|
+
startTime: this.startTime,
|
|
316
|
+
endTime: this.endTime,
|
|
317
|
+
requestHeaders: (_a = this.requestWrapper) === null || _a === void 0 ? void 0 : _a.headers,
|
|
318
|
+
requestBodySize: (_b = this.requestWrapper) === null || _b === void 0 ? void 0 : _b.bodySize,
|
|
319
|
+
responseHeaders: (_c = this.responseWrapper) === null || _c === void 0 ? void 0 : _c.headers,
|
|
320
|
+
responseBodySize: (_d = this.responseWrapper) === null || _d === void 0 ? void 0 : _d.bodySize,
|
|
321
|
+
};
|
|
322
|
+
return Object.fromEntries(Object.entries(serialized).filter(function (_a) {
|
|
323
|
+
var _b = __read(_a, 2), _ = _b[0], v = _b[1];
|
|
324
|
+
return v !== undefined;
|
|
325
|
+
}));
|
|
326
|
+
};
|
|
327
|
+
return NetworkRequestEvent;
|
|
328
|
+
}());
|
|
329
|
+
export { NetworkRequestEvent };
|
|
330
|
+
//# sourceMappingURL=network-request-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-request-event.js","sourceRoot":"","sources":["../../src/network-request-event.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiFhD,MAAM,CAAC,IAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AACH;IAGE,6BAAoB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEhD,sBAAI,wCAAO;aAAX;YACE,IAAI,IAAI,CAAC,QAAQ;gBAAE,OAAO,IAAI,CAAC,QAAQ,CAAC;YAExC,IAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;gBAChC,IAAM,OAAO,GAAG,aAAa,CAAC;gBAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAC,GAAG,EAAE,EAAY;wBAAZ,KAAA,aAAY,EAAX,GAAG,QAAA,EAAE,KAAK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AM;YACnB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,cAAc,EAAE,MAAA,IAAI,CAAC,cAAc,0CAAE,OAAO;YAC5C,eAAe,EAAE,MAAA,IAAI,CAAC,cAAc,0CAAE,QAAQ;YAC9C,eAAe,EAAE,MAAA,IAAI,CAAC,eAAe,0CAAE,OAAO;YAC9C,gBAAgB,EAAE,MAAA,IAAI,CAAC,eAAe,0CAAE,QAAQ;SACjD,CAAC;QAEF,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,UAAC,EAAM;gBAAN,KAAA,aAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;YAAM,OAAA,CAAC,KAAK,SAAS;QAAf,CAAe,CAAC,CAAC,CAAC;IAC5F,CAAC;IACH,0BAAC;AAAD,CAAC,AArCD,IAqCC","sourcesContent":["import { getGlobalScope } from './global-scope';\n\n/* SAFE TYPE DEFINITIONS\n These type definitions expose limited properties of the original types\n to prevent the consumer from mutating them or consuming them.\n*/\ntype BlobSafe = {\n size: number;\n};\n\ntype ArrayBufferSafe = {\n byteLength: number;\n};\n\ntype ArrayBufferViewSafe = {\n byteLength: number;\n};\n\ntype URLSearchParamsSafe = {\n toString(): string;\n};\n\n// no method on readablestream is safe to call\ntype ReadableStreamSafe = Record<string, never>;\n\ntype FormDataEntryValueSafe = string | BlobSafe | null;\n\ntype BodyInitSafe =\n | string\n | Blob\n | ArrayBufferSafe\n | FormDataSafe\n | URLSearchParamsSafe\n | ArrayBufferViewSafe\n | null\n | undefined;\n\ntype HeadersRequestSafe = {\n entries(): IterableIterator<[string, string]>;\n forEach(callbackfn: (value: string, key: string) => void): void;\n};\n\ntype HeadersResponseSafe = {\n get(name: string): string | null;\n forEach(callbackfn: (value: string, key: string) => void): void;\n};\n\ntype HeadersInitSafe = HeadersRequestSafe | Record<string, string> | string[][];\n\ntype ResponseSafe = {\n status: number;\n headers: HeadersResponseSafe | undefined;\n};\n\nexport type RequestInitSafe = {\n method?: string;\n headers?: HeadersInitSafe;\n body?: BodyInitSafe;\n};\nexport interface FormDataSafe {\n entries(): IterableIterator<[string, FormDataEntryValueSafe]>;\n}\nexport type XMLHttpRequestBodyInitSafe = BlobSafe | FormDataSafe | URLSearchParamsSafe | string;\n\nexport type FetchRequestBody =\n | string\n | BlobSafe\n | ArrayBufferSafe\n | FormDataSafe\n | URLSearchParamsSafe\n | ArrayBufferViewSafe\n | null\n | undefined;\n\nexport interface IRequestWrapper {\n headers?: Record<string, string>;\n bodySize?: number;\n method?: string;\n body?: FetchRequestBody | XMLHttpRequestBodyInitSafe | null;\n}\n\nexport const MAXIMUM_ENTRIES = 100;\n\n/**\n * This class encapsulates the RequestInit (https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)\n * object so that the consumer can only get access to the headers, method and body size.\n *\n * This is to prevent consumers from directly accessing the Request object\n * and mutating it or running costly operations on it.\n *\n * IMPORTANT:\n * * Do not make changes to this class without careful consideration\n * of performance implications, memory usage and potential to mutate the customer's\n * request.\n * * NEVER .clone() the RequestInit object. This will 2x's the memory overhead of the request\n * * NEVER: call .arrayBuffer(), text(), json() or any other method on the body that\n * consumes the body's stream. This will cause the response to be consumed\n * meaning the body will be empty when the customer tries to access it.\n * (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n * never call any of the methods on it)\n */\nexport class RequestWrapperFetch implements IRequestWrapper {\n private _headers: Record<string, string> | undefined;\n private _bodySize: number | undefined;\n constructor(private request: RequestInitSafe) {}\n\n get headers(): Record<string, string> | undefined {\n if (this._headers) return this._headers;\n\n const headersUnsafe = this.request.headers;\n if (Array.isArray(headersUnsafe)) {\n const headers = headersUnsafe;\n this._headers = headers.reduce((acc, [key, value]) => {\n acc[key] = value;\n return acc;\n }, {} as Record<string, string>);\n } else if (headersUnsafe instanceof Headers) {\n const headersSafe = headersUnsafe as HeadersRequestSafe;\n const headersObj: Record<string, string> = {};\n headersSafe.forEach((value, key) => {\n headersObj[key] = value;\n });\n this._headers = headersObj;\n } else if (typeof headersUnsafe === 'object') {\n this._headers = headersUnsafe as Record<string, string>;\n }\n\n return this._headers;\n }\n\n get bodySize(): number | undefined {\n if (typeof this._bodySize === 'number') return this._bodySize;\n const global = getGlobalScope();\n\n /* istanbul ignore if */\n if (!global?.TextEncoder) {\n return;\n }\n const body = this.request.body as FetchRequestBody;\n this._bodySize = getBodySize(body, MAXIMUM_ENTRIES);\n return this._bodySize;\n }\n\n get method(): string | undefined {\n return this.request.method;\n }\n}\n\nexport class RequestWrapperXhr implements IRequestWrapper {\n constructor(readonly body: XMLHttpRequestBodyInitSafe | null) {}\n\n get bodySize(): number | undefined {\n return getBodySize(this.body as FetchRequestBody, MAXIMUM_ENTRIES);\n }\n}\n\nfunction getBodySize(bodyUnsafe: FetchRequestBody, maxEntries: number): number | undefined {\n let bodySize: number | undefined;\n const global = getGlobalScope();\n /* istanbul ignore next */\n const TextEncoder = global?.TextEncoder;\n /* istanbul ignore next */\n if (!TextEncoder) {\n return;\n }\n let bodySafe;\n if (typeof bodyUnsafe === 'string') {\n bodySafe = bodyUnsafe;\n bodySize = new TextEncoder().encode(bodySafe).length;\n } else if (bodyUnsafe instanceof Blob) {\n bodySafe = bodyUnsafe as BlobSafe;\n bodySize = bodySafe.size;\n } else if (bodyUnsafe instanceof URLSearchParams) {\n bodySafe = bodyUnsafe as URLSearchParamsSafe;\n bodySize = new TextEncoder().encode(bodySafe.toString()).length;\n } else if (ArrayBuffer.isView(bodyUnsafe)) {\n bodySafe = bodyUnsafe as ArrayBufferViewSafe;\n bodySize = bodySafe.byteLength;\n } else if (bodyUnsafe instanceof ArrayBuffer) {\n bodySafe = bodyUnsafe as ArrayBufferSafe;\n bodySize = bodySafe.byteLength;\n } else if (bodyUnsafe instanceof FormData) {\n // Estimating only for text parts; not accurate for files\n const formData = bodyUnsafe as unknown as FormDataSafe;\n\n let total = 0;\n let count = 0;\n for (const [key, value] of formData.entries()) {\n total += key.length;\n if (typeof value === 'string') {\n total += new TextEncoder().encode(value).length;\n } else if (value instanceof Blob) {\n total += value.size;\n } else {\n // encountered an unknown type\n // we can't estimate the size of this entry\n return;\n }\n // terminate if we reach the maximum number of entries\n // to avoid performance issues in case of very large FormData\n if (++count >= maxEntries) {\n return;\n }\n }\n bodySize = total;\n } else if (bodyUnsafe instanceof ReadableStream) {\n // If bodyUnsafe is an instanceof ReadableStream, we can't determine the size,\n // without consuming it, so we return undefined.\n // Never ever consume ReadableStream! DO NOT DO IT!!!\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n bodySafe = bodyUnsafe as unknown as ReadableStreamSafe;\n return;\n }\n return bodySize;\n}\n\nexport interface IResponseWrapper {\n headers?: Record<string, string>;\n bodySize?: number;\n status?: number;\n body?: string | Blob | ReadableStream | ArrayBuffer | FormDataSafe | URLSearchParams | ArrayBufferView | null;\n}\n\n/**\n * This class encapsulates the Fetch API Response object\n * (https://developer.mozilla.org/en-US/docs/Web/API/Response) so that the consumer can\n * only get access to the headers and body size.\n *\n * This is to prevent consumers from directly accessing the Response object\n * and mutating it or running costly operations on it.\n *\n * IMPORTANT:\n * * Do not make changes to this class without careful consideration\n * of performance implications, memory usage and potential to mutate the customer's\n * response.\n * * NEVER .clone() the Response object. This will 2x's the memory overhead of the response\n * * NEVER consume the body's stream. This will cause the response to be consumed\n * meaning the body will be empty when the customer tries to access it.\n * (ie: if the body is an instanceof https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n * never call any of the methods on it)\n */\nexport class ResponseWrapperFetch implements IResponseWrapper {\n private _headers: Record<string, string> | undefined;\n private _bodySize: number | undefined;\n constructor(private response: ResponseSafe) {}\n\n get headers(): Record<string, string> | undefined {\n if (this._headers) return this._headers;\n\n if (this.response.headers instanceof Headers) {\n const headersSafe = this.response.headers as HeadersResponseSafe;\n const headersOut: Record<string, string> = {};\n /* istanbul ignore next */\n headersSafe?.forEach?.((value, key) => {\n headersOut[key] = value;\n });\n this._headers = headersOut;\n return headersOut;\n }\n\n return;\n }\n\n get bodySize(): number | undefined {\n if (this._bodySize !== undefined) return this._bodySize;\n /* istanbul ignore next */\n const contentLength = this.response.headers?.get?.('content-length');\n const bodySize = contentLength ? parseInt(contentLength, 10) : undefined;\n this._bodySize = bodySize;\n return bodySize;\n }\n\n get status(): number {\n return this.response.status;\n }\n}\n\nexport class ResponseWrapperXhr implements IResponseWrapper {\n constructor(readonly statusCode: number, readonly headersString: string, readonly size: number | undefined) {}\n\n get bodySize(): number | undefined {\n return this.size;\n }\n\n get status(): number {\n return this.statusCode;\n }\n\n get headers(): Record<string, string> | undefined {\n if (!this.headersString) {\n return;\n }\n const headers: Record<string, string> = {};\n const headerLines = this.headersString.split('\\r\\n');\n for (const line of headerLines) {\n const [key, value] = line.split(': ');\n if (key && value) {\n headers[key] = value;\n }\n }\n return headers;\n }\n}\n\nexport class NetworkRequestEvent {\n constructor(\n public readonly type: 'xhr' | 'fetch',\n public readonly method: string,\n public readonly timestamp: number,\n public readonly startTime: number,\n public readonly url?: string,\n public readonly requestWrapper?: IRequestWrapper,\n public readonly status: number = 0,\n public readonly duration?: number,\n public readonly responseWrapper?: IResponseWrapper,\n public readonly error?: {\n name: string;\n message: string;\n },\n public readonly endTime?: number,\n ) {}\n\n toSerializable(): Record<string, any> {\n const serialized: Record<string, any> = {\n type: this.type,\n method: this.method,\n url: this.url,\n timestamp: this.timestamp,\n status: this.status,\n duration: this.duration,\n error: this.error,\n startTime: this.startTime,\n endTime: this.endTime,\n requestHeaders: this.requestWrapper?.headers,\n requestBodySize: this.requestWrapper?.bodySize,\n responseHeaders: this.responseWrapper?.headers,\n responseBodySize: this.responseWrapper?.bodySize,\n };\n\n return Object.fromEntries(Object.entries(serialized).filter(([_, v]) => v !== undefined));\n }\n}\n"]}
|
|
@@ -6,7 +6,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
6
6
|
}
|
|
7
7
|
CookieStorage.prototype.isEnabled = function () {
|
|
8
8
|
return __awaiter(this, void 0, void 0, function () {
|
|
9
|
-
var
|
|
9
|
+
var testStorage, testKey, value, _a;
|
|
10
10
|
return __generator(this, function (_b) {
|
|
11
11
|
switch (_b.label) {
|
|
12
12
|
case 0:
|
|
@@ -15,15 +15,15 @@ var CookieStorage = /** @class */ (function () {
|
|
|
15
15
|
return [2 /*return*/, false];
|
|
16
16
|
}
|
|
17
17
|
CookieStorage.testValue = String(Date.now());
|
|
18
|
-
|
|
18
|
+
testStorage = new CookieStorage(this.options);
|
|
19
19
|
testKey = 'AMP_TEST';
|
|
20
20
|
_b.label = 1;
|
|
21
21
|
case 1:
|
|
22
22
|
_b.trys.push([1, 4, 5, 7]);
|
|
23
|
-
return [4 /*yield*/,
|
|
23
|
+
return [4 /*yield*/, testStorage.set(testKey, CookieStorage.testValue)];
|
|
24
24
|
case 2:
|
|
25
25
|
_b.sent();
|
|
26
|
-
return [4 /*yield*/,
|
|
26
|
+
return [4 /*yield*/, testStorage.get(testKey)];
|
|
27
27
|
case 3:
|
|
28
28
|
value = _b.sent();
|
|
29
29
|
return [2 /*return*/, value === CookieStorage.testValue];
|
|
@@ -31,7 +31,7 @@ var CookieStorage = /** @class */ (function () {
|
|
|
31
31
|
_a = _b.sent();
|
|
32
32
|
/* istanbul ignore next */
|
|
33
33
|
return [2 /*return*/, false];
|
|
34
|
-
case 5: return [4 /*yield*/,
|
|
34
|
+
case 5: return [4 /*yield*/, testStorage.remove(testKey)];
|
|
35
35
|
case 6:
|
|
36
36
|
_b.sent();
|
|
37
37
|
return [7 /*endfinally*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;IAIE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,cAAc,EAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;wBAED,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBACvC,
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;IAIE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,cAAc,EAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;wBAED,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBACvC,WAAW,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACtD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAA;;wBAAvD,SAAuD,CAAC;wBAC1C,qBAAM,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAAtC,KAAK,GAAG,SAA8B;wBAC5C,sBAAO,KAAK,KAAK,aAAa,CAAC,SAAS,EAAC;;;wBAEzC,0BAA0B;wBAC1B,sBAAO,KAAK,EAAC;4BAEb,qBAAM,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;wBA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AK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,OAAO,CAAC,KAAK,CAAC,kEAA2D,GAAG,sBAAY,YAAY,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;4BACtB,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;;;;;KAC3B;IAEK,6BAAK,GAAX;;;gBACE,sBAAO;;;KACR;IACH,oBAAC;AAAD,CAAC,AAnGD,IAmGC;;AAED,IAAM,sBAAsB,GAAG,UAAC,KAAa;IAC3C,IAAI;QACF,OAAO,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;KACxC;IAAC,WAAM;QACN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAEF,IAAM,kCAAkC,GAAG,UAAC,KAAa;IACvD,uEAAuE;IACvE,kEAAkE;IAClE,IAAI;QACF,OAAO,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC5D;IAAC,WAAM;QACN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC","sourcesContent":["import { Storage, CookieStorageOptions } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n private static testValue: undefined | string;\n\n constructor(options?: CookieStorageOptions) {\n this.options = { ...options };\n }\n\n async isEnabled(): Promise<boolean> {\n /* istanbul ignore if */\n if (!getGlobalScope()) {\n return false;\n }\n\n CookieStorage.testValue = String(Date.now());\n const testStorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStorage.set(testKey, CookieStorage.testValue);\n const value = await testStorage.get(testKey);\n return value === CookieStorage.testValue;\n } catch {\n /* istanbul ignore next */\n return false;\n } finally {\n await testStorage.remove(testKey);\n }\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n const cookie = globalScope?.document?.cookie.split('; ') ?? [];\n const match = cookie.find((c) => c.indexOf(key + '=') === 0);\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n"]}
|
|
@@ -84,6 +84,7 @@ export interface ExternalBrowserConfig extends IConfig {
|
|
|
84
84
|
/**
|
|
85
85
|
* Captures network requests and responses.
|
|
86
86
|
* @defaultValue `undefined`
|
|
87
|
+
* @deprecated use autocapture.networkTracking instead
|
|
87
88
|
*/
|
|
88
89
|
networkTrackingOptions?: NetworkTrackingOptions;
|
|
89
90
|
}
|
|
@@ -156,10 +157,10 @@ export interface AutocaptureOptions {
|
|
|
156
157
|
*/
|
|
157
158
|
elementInteractions?: boolean | ElementInteractionsOptions;
|
|
158
159
|
/**
|
|
159
|
-
* Enables/disables network request tracking.
|
|
160
|
+
* Enables/disables network request tracking or config with detailed network tracking options.
|
|
160
161
|
* @defaultValue `false`
|
|
161
162
|
*/
|
|
162
|
-
networkTracking?: boolean;
|
|
163
|
+
networkTracking?: boolean | NetworkTrackingOptions;
|
|
163
164
|
}
|
|
164
165
|
export interface TrackingOptions {
|
|
165
166
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-config.d.ts","sourceRoot":"","sources":["../../../src/types/browser-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB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