this repo has no description
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.searchTermFromRefURL = exports.extractSiriRefAppFromRefURL = exports.idTypeForMetricsOptions = exports.targetTypeForMetricsOptions = void 0;
4const optional_1 = require("../../types/optional");
5const urls = require("../../util/urls");
6/**
7 * Returns click target type for given base metrics options.
8 * @param options - Base metrics options to derive click target type for.
9 */
10function targetTypeForMetricsOptions(options) {
11 let type = options.targetType;
12 if ((0, optional_1.isNothing)(type)) {
13 type = "lockup" /* MetricsClickTargetType.lockup */;
14 }
15 return type;
16}
17exports.targetTypeForMetricsOptions = targetTypeForMetricsOptions;
18/**
19 * Returns metrics ID type for given content metrics options.
20 * @param options - Content metrics options to derive metrics ID type for.
21 */
22function idTypeForMetricsOptions(options) {
23 let type = options.idType;
24 if ((0, optional_1.isNothing)(type)) {
25 type = "its_id" /* MetricsIDType.itsID */;
26 }
27 return type;
28}
29exports.idTypeForMetricsOptions = idTypeForMetricsOptions;
30/**
31 * Extract and return Siri reference app from URL string.
32 * @param refUrlString - URL string.
33 * @returns An optional Siri reference app string.
34 */
35function extractSiriRefAppFromRefURL(urlString) {
36 const refUrl = new urls.URL(urlString);
37 if ((0, optional_1.isNothing)(refUrl.query)) {
38 return null;
39 }
40 let extractedRefApp = null;
41 for (const key of Object.keys(refUrl.query)) {
42 if (key === "referrer") {
43 if (refUrl.query[key] === "siri") {
44 extractedRefApp = "com.apple.siri";
45 }
46 break;
47 }
48 }
49 return extractedRefApp;
50}
51exports.extractSiriRefAppFromRefURL = extractSiriRefAppFromRefURL;
52/**
53 * Extract and return search term from reference URL string.
54 * @param refUrlString - Reference URL string.
55 * @returns An optional search term string.
56 */
57function searchTermFromRefURL(refUrlString) {
58 const refUrl = new urls.URL(refUrlString);
59 const queryItems = refUrl.query;
60 if ((0, optional_1.isNothing)(queryItems)) {
61 return null;
62 }
63 const searchTerm = queryItems["term"];
64 const path = refUrl.pathname;
65 if ((0, optional_1.isNothing)(searchTerm) || (0, optional_1.isNothing)(path)) {
66 return null;
67 }
68 if (!path.endsWith("/search")) {
69 return null;
70 }
71 // the url object has already url-decoded this query parameter
72 const plainTerm = searchTerm;
73 return plainTerm;
74}
75exports.searchTermFromRefURL = searchTermFromRefURL;
76//# sourceMappingURL=util.js.map