Skip to content

Commit

Permalink
add npm search
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 9, 2023
1 parent 8d4d20a commit 11269fc
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion packages/nodes-base/nodes/Npm/PackageDescription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { valid as isValidSemver } from 'semver';
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';

interface PackageJson {
name: string;
version: string;
description: string;
}

export const packageOperations: INodeProperties[] = [
{
displayName: 'Operation',
Expand Down Expand Up @@ -38,7 +44,7 @@ export const packageOperations: INodeProperties[] = [
},
output: {
postReceive: [
async function (this, items) {
async function (items) {
const allVersions: INodeExecutionData[] = [];
for (const { json } of items) {
const itemVersions = json.time as Record<string, string>;
Expand All @@ -64,6 +70,35 @@ export const packageOperations: INodeProperties[] = [
},
},
},
{
name: 'Search',
value: 'search',
action: 'Search for packages',
description: 'Search for packages',
routing: {
request: {
method: 'GET',
url: '/-/v1/search',
qs: {
text: '={{$parameter.query}}',
size: '={{$parameter.limit}}',
popularity: 0.99,
},
},
output: {
postReceive: [
async function (items) {
return items.flatMap(({ json }) =>
(json.objects as Array<{ package: PackageJson }>).map(
({ package: { name, version, description } }) =>
({ json: { name, version, description } } as INodeExecutionData),
),
);
},
],
},
},
},
],
},
];
Expand Down Expand Up @@ -95,4 +130,35 @@ export const packageFields: INodeProperties[] = [
},
},
},
{
displayName: 'Query',
name: 'query',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['package'],
operation: ['search'],
},
},
default: '',
description: 'The query text used to search for packages',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 10,
typeOptions: {
minValue: 1,
maxValue: 100,
},
displayOptions: {
show: {
resource: ['package'],
operation: ['search'],
},
},
description: 'Max number of results to return',
},
];

0 comments on commit 11269fc

Please sign in to comment.