Files
flipper/desktop/plugin-lib/src/getNpmHostedPlugins.tsx
Anton Kastritskiy 69bac4a3d6 Rename second batch for '.ts' files to '.tsx' in plugin-lib dir
Summary: Rename first batch for '.ts' files to '.tsx'

Reviewed By: passy

Differential Revision: D33843245

fbshipit-source-id: 28fd161e258e4d20200620b083aea48f9e58ea64
2022-01-31 06:08:28 -08:00

47 lines
1.1 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {default as algoliasearch, SearchIndex} from 'algoliasearch';
const ALGOLIA_APPLICATION_ID = 'OFCNCOG2CU';
const ALGOLIA_API_KEY = 'f54e21fa3a2a0160595bb058179bfb1e';
function provideSearchIndex(): SearchIndex {
const client = algoliasearch(ALGOLIA_APPLICATION_ID, ALGOLIA_API_KEY);
return client.initIndex('npm-search');
}
export type NpmPackageDescriptor = {
name: string;
version: string;
};
export type NpmHostedPluginsSearchArgs = {
query?: string;
};
export async function getNpmHostedPlugins(
args: NpmHostedPluginsSearchArgs = {},
): Promise<readonly NpmPackageDescriptor[]> {
const index = provideSearchIndex();
args = Object.assign(
{
query: '',
filters: 'keywords:flipper-plugin',
hitsPerPage: 50,
},
args,
);
const {hits} = await index.search<NpmPackageDescriptor>(
args.query || '',
args,
);
return hits;
}