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,
|
||||
groupFields,
|
||||
} from './descriptions';
|
||||
import { presendStringifyBody, searchUserPools } from './GenericFunctions';
|
||||
import { presendStringifyBody, searchUserPools, searchGroups } from './GenericFunctions';
|
||||
|
||||
export class AwsCognito implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -87,6 +87,7 @@ export class AwsCognito implements INodeType {
|
|||
methods = {
|
||||
listSearch: {
|
||||
searchUserPools,
|
||||
searchGroups,
|
||||
// Todo: Add more search methods
|
||||
},
|
||||
};
|
||||
|
|
|
@ -382,37 +382,56 @@ export async function searchGroups(
|
|||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): 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 = {
|
||||
url: '', // the base url is set in "awsRequest"
|
||||
url: '', // the base URL is set in "awsRequest"
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
MaxResults: 60, // the maximum number by documentation is 60
|
||||
UserPoolId: userPoolId,
|
||||
MaxResults: 60,
|
||||
NextToken: paginationToken ?? undefined,
|
||||
}),
|
||||
};
|
||||
|
||||
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
|
||||
.map((a) => ({
|
||||
name: a.Name,
|
||||
value: a.Id,
|
||||
.filter((group) => group.GroupName)
|
||||
.map((group) => ({
|
||||
name: group.GroupName as string,
|
||||
value: group.GroupName as string,
|
||||
}))
|
||||
.filter(
|
||||
(a) =>
|
||||
(group) =>
|
||||
!filter ||
|
||||
a.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
a.value.toLowerCase().includes(filter.toLowerCase()),
|
||||
group.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
group.value.toLowerCase().includes(filter.toLowerCase()),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
|
||||
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
|
||||
return 0;
|
||||
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
||||
});
|
||||
|
||||
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: [
|
||||
{
|
||||
displayName: 'From list', // ToDo: Fix error when selecting this option
|
||||
displayName: 'From list',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
|
@ -427,7 +427,12 @@ const getFields: INodeProperties[] = [
|
|||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
description: 'The name of the group to retrieve',
|
||||
displayOptions: { show: { resource: ['group'], operation: ['get'] } },
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['group'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
|
@ -440,13 +445,13 @@ const getFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'listGroups',
|
||||
searchListMethod: 'searchGroups',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By Name',
|
||||
name: 'id',
|
||||
name: 'GroupName',
|
||||
type: 'string',
|
||||
hint: 'Enter the group name',
|
||||
validation: [
|
||||
|
@ -454,7 +459,7 @@ const getFields: INodeProperties[] = [
|
|||
type: 'regex',
|
||||
properties: {
|
||||
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',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'listGroups',
|
||||
searchListMethod: 'searchGroups',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By Name',
|
||||
name: 'id',
|
||||
name: 'GroupName',
|
||||
type: 'string',
|
||||
hint: 'Enter the group name',
|
||||
validation: [
|
||||
|
@ -714,7 +719,7 @@ const updateFields: INodeProperties[] = [
|
|||
type: 'regex',
|
||||
properties: {
|
||||
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