diff --git a/x-pack/plugins/fleet/common/types/rest_spec/epm.ts b/x-pack/plugins/fleet/common/types/rest_spec/epm.ts index 61b2a0bc3e474..e9df09206ca6f 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/epm.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/epm.ts @@ -61,7 +61,7 @@ interface InstalledPackage { export interface GetInstalledPackagesResponse { items: InstalledPackage[]; total: number; - pageAfter?: SortResults; + searchAfter?: SortResults; } export interface GetEpmDataStreamsResponse { diff --git a/x-pack/plugins/fleet/server/services/epm/data_streams/get.ts b/x-pack/plugins/fleet/server/services/epm/data_streams/get.ts index 5043887069fd9..562a8280ca051 100644 --- a/x-pack/plugins/fleet/server/services/epm/data_streams/get.ts +++ b/x-pack/plugins/fleet/server/services/epm/data_streams/get.ts @@ -15,10 +15,10 @@ export async function getDataStreams(options: { esClient: ElasticsearchClient; type?: PackageDataStreamTypes; datasetQuery?: string; - sortDirection: 'asc' | 'desc'; + sortOrder: 'asc' | 'desc'; uncategorisedOnly: boolean; }) { - const { esClient, type, datasetQuery, uncategorisedOnly, sortDirection } = options; + const { esClient, type, datasetQuery, uncategorisedOnly, sortOrder } = options; const allDataStreams = await dataStreamService.getMatchingDataStreams(esClient, { type: type ? type : '*', @@ -39,7 +39,7 @@ export async function getDataStreams(options: { return a.name.localeCompare(b.name); }); - const dataStreams = sortDirection === 'asc' ? sortedDataStreams : sortedDataStreams.reverse(); + const dataStreams = sortOrder === 'asc' ? sortedDataStreams : sortedDataStreams.reverse(); return { items: dataStreams, diff --git a/x-pack/plugins/fleet/server/services/epm/packages/get.ts b/x-pack/plugins/fleet/server/services/epm/packages/get.ts index 8422d47c1e190..036ec2512a4a9 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/get.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/get.ts @@ -152,22 +152,23 @@ export async function getPackages( export async function getInstalledPackages(options: { savedObjectsClient: SavedObjectsClientContract; - type?: PackageDataStreamTypes; + dataStreamType?: PackageDataStreamTypes; nameQuery?: string; - pageAfter?: SortResults; - pageSize: number; - sortDirection: 'asc' | 'desc'; + searchAfter?: SortResults; + perPage: number; + sortOrder: 'asc' | 'desc'; }) { - const { savedObjectsClient, pageAfter, pageSize, nameQuery, sortDirection, type } = options; + const { savedObjectsClient, searchAfter, perPage, nameQuery, sortOrder, dataStreamType } = + options; const packageSavedObjects = await savedObjectsClient.find({ type: PACKAGES_SAVED_OBJECT_TYPE, // Pagination - perPage: pageSize, - ...(pageAfter && { searchAfter: pageAfter }), + perPage, + ...(searchAfter && { searchAfter }), // Sort sortField: 'name', - sortOrder: sortDirection, + sortOrder, // Name filter ...(nameQuery && { searchFields: ['name'] }), ...(nameQuery && { search: `${nameQuery}* | ${nameQuery}` }), @@ -184,12 +185,12 @@ export async function getInstalledPackages(options: { nodeBuilder.is('type', 'index_template') ), // "Type" filter - ...(type + ...(dataStreamType ? [ buildFunctionNode( 'nested', `${PACKAGES_SAVED_OBJECT_TYPE}.attributes.installed_es`, - nodeBuilder.is('id', buildWildcardNode(`${type}-*`)) + nodeBuilder.is('id', buildWildcardNode(`${dataStreamType}-*`)) ), ] : []), @@ -212,10 +213,10 @@ export async function getInstalledPackages(options: { }; }) .filter((stream) => { - if (!type) { + if (!dataStreamType) { return true; } else { - return stream.title.startsWith(`${type}-`); + return stream.title.startsWith(`${dataStreamType}-`); } }); @@ -230,7 +231,7 @@ export async function getInstalledPackages(options: { return { items: integrations, total: packageSavedObjects.total, - pageAfter: packageSavedObjects.saved_objects.at(-1)?.sort, // Enable ability to use searchAfter in subsequent queries + searchAfter: packageSavedObjects.saved_objects.at(-1)?.sort, // Enable ability to use searchAfter in subsequent queries }; } diff --git a/x-pack/plugins/fleet/server/types/rest_spec/epm.ts b/x-pack/plugins/fleet/server/types/rest_spec/epm.ts index a22b982792c3e..dcdb440d2d424 100644 --- a/x-pack/plugins/fleet/server/types/rest_spec/epm.ts +++ b/x-pack/plugins/fleet/server/types/rest_spec/epm.ts @@ -26,7 +26,7 @@ export const GetPackagesRequestSchema = { export const GetInstalledPackagesRequestSchema = { query: schema.object({ - type: schema.maybe( + dataStreamType: schema.maybe( schema.oneOf([ schema.literal('logs'), schema.literal('metrics'), @@ -36,9 +36,9 @@ export const GetInstalledPackagesRequestSchema = { ]) ), nameQuery: schema.maybe(schema.string()), - pageAfter: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))), - pageSize: schema.number({ defaultValue: 30 }), - sortDirection: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { + searchAfter: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))), + perPage: schema.number({ defaultValue: 30 }), + sortOrder: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { defaultValue: 'asc', }), }), @@ -56,7 +56,7 @@ export const GetDataStreamsRequestSchema = { ]) ), datasetQuery: schema.maybe(schema.string()), - sortDirection: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { + sortOrder: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { defaultValue: 'asc', }), uncategorisedOnly: schema.boolean({ defaultValue: true }),