deploy: ebd4cc0010
This commit is contained in:
25
node_modules/search-insights/lib/utils/extractAdditionalParams.ts
generated
vendored
25
node_modules/search-insights/lib/utils/extractAdditionalParams.ts
generated
vendored
@@ -1,25 +0,0 @@
|
||||
import type { InsightsAdditionalEventParams } from "../types";
|
||||
|
||||
export type WithAdditionalParams<TEventType> =
|
||||
| InsightsAdditionalEventParams
|
||||
| TEventType;
|
||||
|
||||
export function extractAdditionalParams<TEventType extends { index: string }>(
|
||||
params: Array<InsightsAdditionalEventParams | TEventType>
|
||||
): { events: TEventType[]; additionalParams?: InsightsAdditionalEventParams } {
|
||||
return params.reduce(
|
||||
({ events, additionalParams }, param) => {
|
||||
// Real events all have `index` as a mandatory parameter, which we
|
||||
// can rely on to distinguish them from additional parameters
|
||||
if ("index" in param) {
|
||||
return { additionalParams, events: [...events, param] };
|
||||
}
|
||||
|
||||
return { events, additionalParams: param };
|
||||
},
|
||||
{
|
||||
events: [] as TEventType[],
|
||||
additionalParams: undefined as InsightsAdditionalEventParams | undefined
|
||||
}
|
||||
);
|
||||
}
|
||||
35
node_modules/search-insights/lib/utils/featureDetection.ts
generated
vendored
35
node_modules/search-insights/lib/utils/featureDetection.ts
generated
vendored
@@ -1,35 +0,0 @@
|
||||
export const supportsCookies = (): boolean => {
|
||||
try {
|
||||
return Boolean(navigator.cookieEnabled);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const supportsSendBeacon = (): boolean => {
|
||||
try {
|
||||
return Boolean(navigator.sendBeacon);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const supportsXMLHttpRequest = (): boolean => {
|
||||
try {
|
||||
return Boolean(XMLHttpRequest);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const supportsNodeHttpModule = (): boolean => {
|
||||
try {
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { request: nodeHttpRequest } = require("http");
|
||||
const { request: nodeHttpsRequest } = require("https");
|
||||
/* eslint-enable */
|
||||
return Boolean(nodeHttpRequest) && Boolean(nodeHttpsRequest);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
17
node_modules/search-insights/lib/utils/getRequesterForBrowser.ts
generated
vendored
17
node_modules/search-insights/lib/utils/getRequesterForBrowser.ts
generated
vendored
@@ -1,17 +0,0 @@
|
||||
import { supportsSendBeacon, supportsXMLHttpRequest } from "./featureDetection";
|
||||
import type { RequestFnType } from "./request";
|
||||
import { requestWithSendBeacon, requestWithXMLHttpRequest } from "./request";
|
||||
|
||||
export function getRequesterForBrowser(): RequestFnType {
|
||||
if (supportsSendBeacon()) {
|
||||
return requestWithSendBeacon;
|
||||
}
|
||||
|
||||
if (supportsXMLHttpRequest()) {
|
||||
return requestWithXMLHttpRequest;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Could not find a supported HTTP request client in this environment."
|
||||
);
|
||||
}
|
||||
13
node_modules/search-insights/lib/utils/getRequesterForNode.ts
generated
vendored
13
node_modules/search-insights/lib/utils/getRequesterForNode.ts
generated
vendored
@@ -1,13 +0,0 @@
|
||||
import { supportsNodeHttpModule } from "./featureDetection";
|
||||
import type { RequestFnType } from "./request";
|
||||
import { requestWithNodeHttpModule } from "./request";
|
||||
|
||||
export function getRequesterForNode(): RequestFnType {
|
||||
if (supportsNodeHttpModule()) {
|
||||
return requestWithNodeHttpModule;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Could not find a supported HTTP request client in this environment."
|
||||
);
|
||||
}
|
||||
15
node_modules/search-insights/lib/utils/index.ts
generated
vendored
15
node_modules/search-insights/lib/utils/index.ts
generated
vendored
@@ -1,15 +0,0 @@
|
||||
// use theses type checking helpers to avoid mistyping "undefind", I mean "undfined"
|
||||
export const isUndefined = (value: any): value is undefined =>
|
||||
typeof value === "undefined";
|
||||
export const isString = (value: any): value is string =>
|
||||
typeof value === "string";
|
||||
export const isNumber = (value: any): value is number =>
|
||||
typeof value === "number";
|
||||
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
export const isFunction = (value: any): value is Function =>
|
||||
typeof value === "function";
|
||||
/* eslint-enable */
|
||||
|
||||
export * from "./extractAdditionalParams";
|
||||
export * from "./featureDetection";
|
||||
80
node_modules/search-insights/lib/utils/request.ts
generated
vendored
80
node_modules/search-insights/lib/utils/request.ts
generated
vendored
@@ -1,80 +0,0 @@
|
||||
import type { request as nodeRequest } from "http";
|
||||
import type { UrlWithStringQuery } from "url";
|
||||
|
||||
export type RequestFnType = (
|
||||
url: string,
|
||||
data: Record<string, unknown>
|
||||
) => Promise<boolean>;
|
||||
|
||||
export const requestWithXMLHttpRequest: RequestFnType = (url, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const serializedData = JSON.stringify(data);
|
||||
const req = new XMLHttpRequest();
|
||||
req.addEventListener("readystatechange", () => {
|
||||
if (req.readyState === 4 && req.status === 200) {
|
||||
resolve(true);
|
||||
} else if (req.readyState === 4) {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
/* eslint-disable prefer-promise-reject-errors */
|
||||
req.addEventListener("error", () => reject());
|
||||
/* eslint-enable */
|
||||
req.addEventListener("timeout", () => resolve(false));
|
||||
req.open("POST", url);
|
||||
req.setRequestHeader("Content-Type", "application/json");
|
||||
req.setRequestHeader("Content-Length", `${serializedData.length}`);
|
||||
req.send(serializedData);
|
||||
});
|
||||
};
|
||||
|
||||
export const requestWithSendBeacon: RequestFnType = (url, data) => {
|
||||
const serializedData = JSON.stringify(data);
|
||||
const beacon = navigator.sendBeacon(url, serializedData);
|
||||
return Promise.resolve(beacon ? true : requestWithXMLHttpRequest(url, data));
|
||||
};
|
||||
|
||||
export const requestWithNodeHttpModule: RequestFnType = (url, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const serializedData = JSON.stringify(data);
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { protocol, host, path }: UrlWithStringQuery =
|
||||
require("url").parse(url);
|
||||
/* eslint-enable */
|
||||
const options = {
|
||||
protocol,
|
||||
host,
|
||||
path,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": serializedData.length
|
||||
}
|
||||
};
|
||||
|
||||
const { request }: { request: typeof nodeRequest } = url.startsWith(
|
||||
"https://"
|
||||
)
|
||||
? require("https")
|
||||
: require("http");
|
||||
const req = request(options, ({ statusCode }) => {
|
||||
if (statusCode === 200) {
|
||||
resolve(true);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
req.on("error", (error: any) => {
|
||||
/* eslint-disable no-console */
|
||||
console.error(error);
|
||||
/* eslint-enable */
|
||||
reject(error);
|
||||
});
|
||||
req.on("timeout", () => resolve(false));
|
||||
|
||||
req.write(serializedData);
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
15
node_modules/search-insights/lib/utils/uuid.ts
generated
vendored
15
node_modules/search-insights/lib/utils/uuid.ts
generated
vendored
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Create UUID according to
|
||||
* https://www.ietf.org/rfc/rfc4122.txt.
|
||||
*
|
||||
* @returns Generated UUID.
|
||||
*/
|
||||
export function createUUID(): string {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
||||
/* eslint-disable no-bitwise */
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
||||
/* eslint-enable */
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user