@sentry-internal/global-search
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import React, { useState, useEffect } from 'react'; | ||
@@ -8,7 +9,7 @@ import ReactDOM from 'react-dom'; | ||
useEffect(() => { | ||
(async () => { | ||
const generateRecord = async () => { | ||
const { html, title, url } = await sampleDocument(); | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
const generateRecord = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const { html, title, url } = yield sampleDocument(); | ||
const document = `<p>This is outside of the main parser area.</p><main>${html}</main>`; | ||
const records = await htmlToAlgoliaRecord(document, { title, url }, 'main'); | ||
const records = yield htmlToAlgoliaRecord(document, { title, url }, 'main'); | ||
setRendered({ | ||
@@ -18,5 +19,5 @@ html: document, | ||
}); | ||
}; | ||
}); | ||
generateRecord(); | ||
})(); | ||
}))(); | ||
}, [htmlToAlgoliaRecord]); | ||
@@ -23,0 +24,0 @@ return (<> |
@@ -14,6 +14,3 @@ import React, { useState } from 'react'; | ||
const togglePlatform = (slug, checked) => { | ||
const newPlatforms = platforms.map(x => ({ | ||
...x, | ||
...(slug === x.slug && { selected: checked }), | ||
})); | ||
const newPlatforms = platforms.map(x => (Object.assign(Object.assign({}, x), (slug === x.slug && { selected: checked })))); | ||
setPlatforms(newPlatforms); | ||
@@ -45,6 +42,3 @@ }; | ||
<Search {...{ | ||
...(selectedPlatformSlugs && { platforms: selectedPlatformSlugs }), | ||
...(path && { path }), | ||
}}/> | ||
<Search {...Object.assign(Object.assign({}, (selectedPlatformSlugs && { platforms: selectedPlatformSlugs })), (path && { path }))}/> | ||
</div>); | ||
@@ -51,0 +45,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { hashObject } from './lib/hash-object'; | ||
@@ -25,3 +26,3 @@ import { getChildText } from './lib/get-child-text'; | ||
*/ | ||
export const parseRecordsFromHTML = async (html, meta, baseSelector) => { | ||
export const parseRecordsFromHTML = (html, meta, baseSelector) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { title } = meta; | ||
@@ -43,3 +44,3 @@ const records = []; | ||
// Fetch the initial AST | ||
let dom = await htmlToAST(html); | ||
let dom = yield htmlToAST(html); | ||
if (baseSelector) | ||
@@ -66,8 +67,8 @@ dom = selectOne(baseSelector, dom); | ||
acc.position++; | ||
const record = { text, ...meta, ...acc }; | ||
records.push({ objectID: hashObject(record), ...record }); | ||
const record = Object.assign(Object.assign({ text }, meta), acc); | ||
records.push(Object.assign({ objectID: hashObject(record) }, record)); | ||
return acc; | ||
}, initialValues); | ||
return records; | ||
}; | ||
}); | ||
//# sourceMappingURL=html-to-algolia-record.js.map |
@@ -14,3 +14,3 @@ /** | ||
} | ||
newStr = newStr?.trim(); | ||
newStr = newStr === null || newStr === void 0 ? void 0 : newStr.trim(); | ||
if (newStr) { | ||
@@ -17,0 +17,0 @@ str += str ? ` ${newStr}` : newStr; |
@@ -14,3 +14,4 @@ import React, { useState, useEffect, useRef } from 'react'; | ||
const detectClickOutside = (event) => { | ||
return !ref.current?.contains(event.target) && handler(); | ||
var _a; | ||
return !((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) && handler(); | ||
}; | ||
@@ -43,8 +44,4 @@ useEffect(() => { | ||
search | ||
.query(query, { | ||
platforms, | ||
path, | ||
searchAllIndexes: showOffsiteResults, | ||
...args, | ||
}) | ||
.query(query, Object.assign({ platforms, | ||
path, searchAllIndexes: showOffsiteResults }, args)) | ||
.then(results => { | ||
@@ -51,0 +48,0 @@ if (loading) |
import * as Transformers from './transformers'; | ||
const config = (settings) => { | ||
return { | ||
pathBias: false, | ||
platformBias: true, | ||
legacyBias: true, | ||
...settings, | ||
}; | ||
return Object.assign({ pathBias: false, platformBias: true, legacyBias: true }, settings); | ||
}; | ||
@@ -10,0 +5,0 @@ export const defaultQueryParams = { |
@@ -11,3 +11,3 @@ import { titleCase } from 'title-case'; | ||
const prettyPath = (input) => { | ||
const specialCases = Object.keys(SPECIAL_CASES).reduce((a, k) => ({ ...a, [k.toLowerCase()]: SPECIAL_CASES[k] }), {}); | ||
const specialCases = Object.keys(SPECIAL_CASES).reduce((a, k) => (Object.assign(Object.assign({}, a), { [k.toLowerCase()]: SPECIAL_CASES[k] })), {}); | ||
const segments = input.split('/').filter(Boolean); | ||
@@ -14,0 +14,0 @@ const re = new RegExp(`(${Object.keys(specialCases).join('|')})`, 'gi'); |
@@ -46,2 +46,3 @@ // SDK slugs must follow the format entity.ecosystem[.flavor]¹. This provides a | ||
export const standardSDKSlug = (slug) => { | ||
var _a, _b; | ||
if (typeof slug !== 'string') | ||
@@ -53,5 +54,4 @@ return; | ||
? slug | ||
: synonyms[slug.toLowerCase()] ?? slug; | ||
const name = names[standardSlug] ?? | ||
standardSlug.charAt(0).toUpperCase() + standardSlug.slice(1); | ||
: (_a = synonyms[slug.toLowerCase()]) !== null && _a !== void 0 ? _a : slug; | ||
const name = (_b = names[standardSlug]) !== null && _b !== void 0 ? _b : standardSlug.charAt(0).toUpperCase() + standardSlug.slice(1); | ||
return { | ||
@@ -58,0 +58,0 @@ slug: standardSlug, |
@@ -36,5 +36,3 @@ import prettyPath from './pretty-path'; | ||
site: 'blog', | ||
context: { | ||
...hit.context | ||
}, | ||
context: Object.assign({}, hit.context), | ||
url: `https://help.sentry.io${hit.url}${hit.anchor ? `#${hit.anchor}` : ''}`, | ||
@@ -41,0 +39,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import algoliasearch from 'algoliasearch/lite'; | ||
@@ -17,3 +18,3 @@ import { sites, defaultQueryParams } from './lib/config'; | ||
if (!!defaults) | ||
return { ...defaults, ...config }; | ||
return Object.assign(Object.assign({}, defaults), config); | ||
throw new Error(`${errorType}: unknown site "${config.site}" in config.include`); | ||
@@ -25,62 +26,60 @@ }); | ||
} | ||
async query(query, globalSearchQueryOptions = {}, algoliaSearchOptions = {}) { | ||
if (!query) | ||
return []; | ||
// Strip out all but Basic Latin, to minimize impact from bot search that | ||
// uses random characters. We don't have localized docs so there's no point | ||
// in searching non-latin characters. | ||
const sanitizedQuery = query.replace(/[^\u0020-\u007f]/gi, ''); | ||
const searchAllIndexes = globalSearchQueryOptions.searchAllIndexes || false; | ||
const configsToSearch = searchAllIndexes ? this.configs : [this.configs[0]]; | ||
// Create a list of Algolia query objects from our configs | ||
const queries = configsToSearch.reduce((queries, config) => { | ||
const optionalFilters = []; | ||
if (config.pathBias && globalSearchQueryOptions.path) { | ||
optionalFilters.push(`pathSegments:${globalSearchQueryOptions.path}`); | ||
} | ||
if (config.platformBias && | ||
globalSearchQueryOptions.platforms && | ||
globalSearchQueryOptions.platforms.length > 0) { | ||
optionalFilters.push(globalSearchQueryOptions.platforms.map(x => `platforms:${x}`)); | ||
} | ||
if (config.legacyBias) { | ||
optionalFilters.push(`legacy:0`); | ||
} | ||
const newQueries = config.indexes.map(({ indexName, clickAnalytics }) => { | ||
query(query, globalSearchQueryOptions = {}, algoliaSearchOptions = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!query) | ||
return []; | ||
// Strip out all but Basic Latin, to minimize impact from bot search that | ||
// uses random characters. We don't have localized docs so there's no point | ||
// in searching non-latin characters. | ||
const sanitizedQuery = query.replace(/[^\u0020-\u007f]/gi, ''); | ||
const searchAllIndexes = globalSearchQueryOptions.searchAllIndexes || false; | ||
const configsToSearch = searchAllIndexes ? this.configs : [this.configs[0]]; | ||
// Create a list of Algolia query objects from our configs | ||
const queries = configsToSearch.reduce((queries, config) => { | ||
const optionalFilters = []; | ||
if (config.pathBias && globalSearchQueryOptions.path) { | ||
optionalFilters.push(`pathSegments:${globalSearchQueryOptions.path}`); | ||
} | ||
if (config.platformBias && | ||
globalSearchQueryOptions.platforms && | ||
globalSearchQueryOptions.platforms.length > 0) { | ||
optionalFilters.push(globalSearchQueryOptions.platforms.map(x => `platforms:${x}`)); | ||
} | ||
if (config.legacyBias) { | ||
optionalFilters.push(`legacy:0`); | ||
} | ||
const newQueries = config.indexes.map(({ indexName, clickAnalytics }) => { | ||
return { | ||
indexName, | ||
query: sanitizedQuery, | ||
params: Object.assign(Object.assign(Object.assign(Object.assign({}, defaultQueryParams), algoliaSearchOptions), (clickAnalytics ? { clickAnalytics: true } : {})), (optionalFilters.length > 0 ? { optionalFilters } : {})), | ||
}; | ||
}); | ||
return queries.concat(newQueries); | ||
}, []); | ||
// Get the search results | ||
const { results: algoliaResults } = yield this.client.search(queries); | ||
// Reduce and normalize the Algolia results | ||
const results = configsToSearch.map(config => { | ||
var _a; | ||
// If a site has more than one index, reduce them to one array. | ||
const hits = config.indexes.reduce((acc, index) => { | ||
const algoliaResult = algoliaResults.find(result => result.index === index.indexName); | ||
// if no result return early | ||
if (!algoliaResult) { | ||
return acc; | ||
} | ||
// Normalize the results into a consistent format | ||
return acc.concat(algoliaResult.hits.map(hit => index.transformer(hit, algoliaResult))); | ||
}, []); | ||
return { | ||
indexName, | ||
query: sanitizedQuery, | ||
params: { | ||
...defaultQueryParams, | ||
...algoliaSearchOptions, | ||
...(clickAnalytics ? { clickAnalytics: true } : {}), | ||
...(optionalFilters.length > 0 ? { optionalFilters } : {}), | ||
}, | ||
site: config.site, | ||
name: (_a = config.name) !== null && _a !== void 0 ? _a : "", | ||
hits, | ||
}; | ||
}); | ||
return queries.concat(newQueries); | ||
}, []); | ||
// Get the search results | ||
const { results: algoliaResults } = await this.client.search(queries); | ||
// Reduce and normalize the Algolia results | ||
const results = configsToSearch.map(config => { | ||
// If a site has more than one index, reduce them to one array. | ||
const hits = config.indexes.reduce((acc, index) => { | ||
const algoliaResult = algoliaResults.find(result => result.index === index.indexName); | ||
// if no result return early | ||
if (!algoliaResult) { | ||
return acc; | ||
} | ||
// Normalize the results into a consistent format | ||
return acc.concat(algoliaResult.hits.map(hit => index.transformer(hit, algoliaResult))); | ||
}, []); | ||
return { | ||
site: config.site, | ||
name: config.name ?? "", | ||
hits, | ||
}; | ||
return results; | ||
}); | ||
return results; | ||
} | ||
} | ||
//# sourceMappingURL=sentry-global-search.js.map |
{ | ||
"name": "@sentry-internal/global-search", | ||
"description": "JavaScript library and helper utilities for searching Sentry sites via Algolia.", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"author": "Sentry", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152342
1805