mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
add search method to get group from list
This commit is contained in:
parent
bcc479e502
commit
6eb585dc1a
|
@ -9,7 +9,7 @@ import {
|
||||||
groupOperations,
|
groupOperations,
|
||||||
groupFields,
|
groupFields,
|
||||||
} from './descriptions';
|
} from './descriptions';
|
||||||
import { presendStringifyBody, searchUserPools } from './GenericFunctions';
|
import { presendStringifyBody, searchUserPools, searchGroups } from './GenericFunctions';
|
||||||
|
|
||||||
export class AwsCognito implements INodeType {
|
export class AwsCognito implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -87,6 +87,7 @@ export class AwsCognito implements INodeType {
|
||||||
methods = {
|
methods = {
|
||||||
listSearch: {
|
listSearch: {
|
||||||
searchUserPools,
|
searchUserPools,
|
||||||
|
searchGroups,
|
||||||
// Todo: Add more search methods
|
// Todo: Add more search methods
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -382,37 +382,56 @@ export async function searchGroups(
|
||||||
filter?: string,
|
filter?: string,
|
||||||
paginationToken?: string,
|
paginationToken?: string,
|
||||||
): Promise<INodeListSearchResult> {
|
): Promise<INodeListSearchResult> {
|
||||||
|
// Get the userPoolId from the input
|
||||||
|
const userPoolIdRaw = this.getNodeParameter('userPoolId', '') as IDataObject;
|
||||||
|
console.log('Raw User Pool ID:', userPoolIdRaw);
|
||||||
|
|
||||||
|
// Extract the actual value
|
||||||
|
const userPoolId = userPoolIdRaw.value as string;
|
||||||
|
|
||||||
|
// Ensure that userPoolId is provided
|
||||||
|
if (!userPoolId) {
|
||||||
|
throw new ApplicationError('User Pool ID is required to search groups');
|
||||||
|
}
|
||||||
|
// Setup the options for the AWS request
|
||||||
const opts: IHttpRequestOptions = {
|
const opts: IHttpRequestOptions = {
|
||||||
url: '', // the base url is set in "awsRequest"
|
url: '', // the base URL is set in "awsRequest"
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups',
|
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
MaxResults: 60, // the maximum number by documentation is 60
|
UserPoolId: userPoolId,
|
||||||
|
MaxResults: 60,
|
||||||
NextToken: paginationToken ?? undefined,
|
NextToken: paginationToken ?? undefined,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const responseData: IDataObject = await awsRequest.call(this, opts);
|
const responseData: IDataObject = await awsRequest.call(this, opts);
|
||||||
|
|
||||||
const groups = responseData.Groups as Array<{ Name: string; Id: string }>;
|
const groups = responseData.Groups as Array<{ GroupName?: string }> | undefined;
|
||||||
|
|
||||||
|
// If no groups exist, return an empty list
|
||||||
|
if (!groups) {
|
||||||
|
return { results: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map and filter the response
|
||||||
const results: INodeListSearchItems[] = groups
|
const results: INodeListSearchItems[] = groups
|
||||||
.map((a) => ({
|
.filter((group) => group.GroupName)
|
||||||
name: a.Name,
|
.map((group) => ({
|
||||||
value: a.Id,
|
name: group.GroupName as string,
|
||||||
|
value: group.GroupName as string,
|
||||||
}))
|
}))
|
||||||
.filter(
|
.filter(
|
||||||
(a) =>
|
(group) =>
|
||||||
!filter ||
|
!filter ||
|
||||||
a.name.toLowerCase().includes(filter.toLowerCase()) ||
|
group.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||||
a.value.toLowerCase().includes(filter.toLowerCase()),
|
group.value.toLowerCase().includes(filter.toLowerCase()),
|
||||||
)
|
)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
||||||
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { results, paginationToken: responseData.NextToken }; // ToDo: Test if pagination for the search methods works
|
return { results, paginationToken: responseData.NextToken };
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,7 +394,7 @@ const getFields: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
modes: [
|
modes: [
|
||||||
{
|
{
|
||||||
displayName: 'From list', // ToDo: Fix error when selecting this option
|
displayName: 'From list',
|
||||||
name: 'list',
|
name: 'list',
|
||||||
type: 'list',
|
type: 'list',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
@ -427,7 +427,12 @@ const getFields: INodeProperties[] = [
|
||||||
type: 'resourceLocator',
|
type: 'resourceLocator',
|
||||||
default: { mode: 'list', value: '' },
|
default: { mode: 'list', value: '' },
|
||||||
description: 'The name of the group to retrieve',
|
description: 'The name of the group to retrieve',
|
||||||
displayOptions: { show: { resource: ['group'], operation: ['get'] } },
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: ['group'],
|
||||||
|
operation: ['get'],
|
||||||
|
},
|
||||||
|
},
|
||||||
routing: {
|
routing: {
|
||||||
send: {
|
send: {
|
||||||
type: 'body',
|
type: 'body',
|
||||||
|
@ -440,13 +445,13 @@ const getFields: INodeProperties[] = [
|
||||||
name: 'list',
|
name: 'list',
|
||||||
type: 'list',
|
type: 'list',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
searchListMethod: 'listGroups',
|
searchListMethod: 'searchGroups',
|
||||||
searchable: true,
|
searchable: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'By Name',
|
displayName: 'By Name',
|
||||||
name: 'id',
|
name: 'GroupName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
hint: 'Enter the group name',
|
hint: 'Enter the group name',
|
||||||
validation: [
|
validation: [
|
||||||
|
@ -454,7 +459,7 @@ const getFields: INodeProperties[] = [
|
||||||
type: 'regex',
|
type: 'regex',
|
||||||
properties: {
|
properties: {
|
||||||
regex: '^[\\w+=,.@-]+$',
|
regex: '^[\\w+=,.@-]+$',
|
||||||
errorMessage: 'The group name must follow the pattern "xxxxxx_xxxxxxxxxxx"',
|
errorMessage: 'The group name must follow the allowed pattern.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -700,13 +705,13 @@ const updateFields: INodeProperties[] = [
|
||||||
name: 'list',
|
name: 'list',
|
||||||
type: 'list',
|
type: 'list',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
searchListMethod: 'listGroups',
|
searchListMethod: 'searchGroups',
|
||||||
searchable: true,
|
searchable: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'By Name',
|
displayName: 'By Name',
|
||||||
name: 'id',
|
name: 'GroupName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
hint: 'Enter the group name',
|
hint: 'Enter the group name',
|
||||||
validation: [
|
validation: [
|
||||||
|
@ -714,7 +719,7 @@ const updateFields: INodeProperties[] = [
|
||||||
type: 'regex',
|
type: 'regex',
|
||||||
properties: {
|
properties: {
|
||||||
regex: '^[\\w+=,.@-]+$',
|
regex: '^[\\w+=,.@-]+$',
|
||||||
errorMessage: 'The group name must follow the pattern "xxxxxx_xxxxxxxxxxx"',
|
errorMessage: 'The group name must follow the allowed pattern.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue