Files
flipper/desktop/plugin-lib/src/getNpmHostedPlugins.ts
Andres Suarez 79023ee190 Update copyright headers from Facebook to Meta
Reviewed By: bhamodi

Differential Revision: D33331422

fbshipit-source-id: 016e8dcc0c0c7f1fc353a348b54fda0d5e2ddc01
2021-12-27 14:31:45 -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;
}