update group description

This commit is contained in:
Stamsy 2024-11-26 14:20:53 +02:00
parent 133ba470ca
commit 9d2b60450e
3 changed files with 142 additions and 110 deletions

View file

@ -1,7 +1,14 @@
import type { INodeType, INodeTypeDescription } from 'n8n-workflow'; import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow';
import { userOperations, userFields, userPoolOperations, userPoolFields } from './descriptions'; import {
userOperations,
userFields,
userPoolOperations,
userPoolFields,
groupOperations,
groupFields,
} from './descriptions';
import { presendStringifyBody, searchUserPools } from './GenericFunctions'; import { presendStringifyBody, searchUserPools } from './GenericFunctions';
export class AwsCognito implements INodeType { export class AwsCognito implements INodeType {
@ -62,12 +69,18 @@ export class AwsCognito implements INodeType {
name: 'User Pool', name: 'User Pool',
value: 'userPool', value: 'userPool',
}, },
{
name: 'Group',
value: 'group',
},
], ],
}, },
...userPoolOperations, ...userPoolOperations,
...userPoolFields, ...userPoolFields,
...userOperations, ...userOperations,
...userFields, ...userFields,
...groupOperations,
...groupFields,
], ],
}; };

View file

@ -1,8 +1,7 @@
import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow'; import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow'; import { NodeOperationError } from 'n8n-workflow';
import { handleErrorPostReceive } from '../GenericFunctions'; import { handleErrorPostReceive, presendTest } from '../GenericFunctions';
export const groupOperations: INodeProperties[] = [ export const groupOperations: INodeProperties[] = [
{ {
@ -37,9 +36,6 @@ export const groupOperations: INodeProperties[] = [
// return await getUserIdForGroup.call(this, requestOptions); // return await getUserIdForGroup.call(this, requestOptions);
// }, // },
// ], // ],
body: {
groupName: '={{ $parameter["groupName"] }}',
},
}, },
output: { output: {
postReceive: [handleErrorPostReceive], postReceive: [handleErrorPostReceive],
@ -76,7 +72,7 @@ export const groupOperations: INodeProperties[] = [
request: { request: {
method: 'POST', method: 'POST',
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroup', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.GetGroup',
}, },
qs: { qs: {
pageSize: pageSize:
@ -191,7 +187,7 @@ const createFields: INodeProperties[] = [
}, },
{ {
displayName: 'Group Name', displayName: 'Group Name',
name: 'groupName', name: 'GroupName',
default: '', default: '',
placeholder: 'e.g. My New Group', placeholder: 'e.g. My New Group',
description: 'The name of the new group to create', description: 'The name of the new group to create',
@ -204,32 +200,10 @@ const createFields: INodeProperties[] = [
required: true, required: true,
routing: { routing: {
send: { send: {
property: 'groupName', property: 'GroupName',
type: 'body', type: 'body',
preSend: [ preSend: [presendTest], // ToDo: Remove this line before completing the pull request
async function ( paginate: true,
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const groupName = this.getNodeParameter('groupName') as string;
if (groupName.length < 1 || groupName.length > 128) {
throw new NodeOperationError(
this.getNode(),
'Group Name must be between 1 and 128 characters.',
);
}
// Regex validation
if (!/^[\w+=,.@-]+$/.test(groupName)) {
throw new NodeOperationError(
this.getNode(),
'Group Name contains invalid characters. Allowed characters: [\\w+=,.@-].',
);
}
return requestOptions;
},
],
}, },
}, },
type: 'string', type: 'string',
@ -344,8 +318,8 @@ const deleteFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group', displayName: 'Group Name',
name: 'group', name: 'GroupName',
default: { default: {
mode: 'list', mode: 'list',
value: '', value: '',
@ -359,107 +333,134 @@ const deleteFields: INodeProperties[] = [
}, },
modes: [ modes: [
{ {
displayName: 'From List', displayName: 'From list',
name: 'list', name: 'list',
type: 'list', type: 'list',
typeOptions: { typeOptions: {
searchListMethod: 'getGroups', searchListMethod: 'listGroups',
searchable: true, searchable: true,
}, },
}, },
{ {
displayName: 'By ID', displayName: 'By Name',
name: 'id', name: 'id',
placeholder: 'e.g. 02bd9fd6-8f93-4758-87c3-1fb73740a315',
type: 'string', type: 'string',
hint: 'Enter the group name',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the pattern "xxxxxx_xxxxxxxxxxx"',
},
},
],
placeholder: 'e.g. Admins',
}, },
], ],
required: true, required: true,
routing: {
send: {
type: 'body',
property: 'GroupName',
},
},
type: 'resourceLocator', type: 'resourceLocator',
}, },
]; ];
const getFields: INodeProperties[] = [ const getFields: INodeProperties[] = [
{ {
displayName: 'Group', displayName: 'User Pool ID',
name: 'group', name: 'userPoolId',
required: true,
type: 'resourceLocator',
default: { default: {
mode: 'list', mode: 'list',
value: '', value: '',
}, },
description: 'The user pool ID where the users are managed',
displayOptions: { displayOptions: {
show: { show: {
resource: ['group'], resource: ['group'],
operation: ['get'], operation: ['get'],
}, },
}, },
routing: {
send: {
type: 'body',
property: 'UserPoolId',
},
},
modes: [ modes: [
{ {
displayName: 'From List', displayName: 'From list', // ToDo: Fix error when selecting this option
name: 'list', name: 'list',
type: 'list', type: 'list',
typeOptions: { typeOptions: {
searchListMethod: 'getGroups', searchListMethod: 'searchUserPools',
searchable: true, searchable: true,
}, },
}, },
{ {
displayName: 'By ID', displayName: 'By ID',
name: 'id', name: 'id',
placeholder: 'e.g. 02bd9fd6-8f93-4758-87c3-1fb73740a315',
type: 'string', type: 'string',
hint: 'Enter the user pool ID',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w-]+_[0-9a-zA-Z]+$',
errorMessage: 'The ID must follow the pattern "xxxxxx_xxxxxxxxxxx"',
},
},
],
placeholder: 'e.g. eu-central-1_ab12cdefgh',
}, },
], ],
required: true,
type: 'resourceLocator',
}, },
{ {
displayName: 'Options', displayName: 'Group Name',
name: 'options', name: 'GroupName',
default: {}, required: true,
displayOptions: { type: 'resourceLocator',
show: { default: { mode: 'list', value: '' },
resource: ['group'], description: 'The name of the group to retrieve',
operation: ['get'], displayOptions: { show: { resource: ['group'], operation: ['get'] } },
routing: {
send: {
type: 'body',
property: 'GroupName',
}, },
}, },
options: [ modes: [
{ {
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-multi-options displayName: 'From list',
displayName: 'Fields', name: 'list',
name: 'select', type: 'list',
default: [],
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options
description: 'The fields to add to the output',
routing: {
send: {
property: '$select',
type: 'query',
value: '={{ $value?.join(",") }}',
},
},
typeOptions: { typeOptions: {
loadOptionsMethod: 'getGroupProperties', searchListMethod: 'listGroups',
searchable: true,
}, },
type: 'multiOptions',
}, },
{ {
displayName: 'Include Members', displayName: 'By Name',
name: 'includeMembers', name: 'id',
default: false, type: 'string',
routing: { hint: 'Enter the group name',
send: { validation: [
property: '$expand', {
type: 'query', type: 'regex',
value: '={{ $value ? "members" : undefined }}', properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the pattern "xxxxxx_xxxxxxxxxxx"',
},
}, },
}, ],
type: 'boolean', placeholder: 'e.g. Admins',
validateType: 'boolean',
}, },
], ],
placeholder: 'Add Option',
type: 'collection',
}, },
]; ];
@ -680,8 +681,8 @@ const updateFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group', displayName: 'Group Name',
name: 'group', name: 'GroupName',
default: { default: {
mode: 'list', mode: 'list',
value: '', value: '',
@ -699,18 +700,35 @@ const updateFields: INodeProperties[] = [
name: 'list', name: 'list',
type: 'list', type: 'list',
typeOptions: { typeOptions: {
searchListMethod: 'getGroups', searchListMethod: 'listGroups',
searchable: true, searchable: true,
}, },
}, },
{ {
displayName: 'By ID', displayName: 'By Name',
name: 'id', name: 'id',
placeholder: 'e.g. 02bd9fd6-8f93-4758-87c3-1fb73740a315',
type: 'string', type: 'string',
hint: 'Enter the group name',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the pattern "xxxxxx_xxxxxxxxxxx"',
},
},
],
placeholder: 'e.g. Admins',
}, },
], ],
required: true, required: true,
routing: {
send: {
preSend: [presendTest], // ToDo: Remove this line before completing the pull request
type: 'body',
property: 'GroupName',
},
},
type: 'resourceLocator', type: 'resourceLocator',
}, },
{ {
@ -727,32 +745,32 @@ const updateFields: INodeProperties[] = [
}, },
routing: { routing: {
send: { send: {
property: 'name', property: 'GroupName',
type: 'body', type: 'body',
preSend: [ // preSend: [
async function ( // async function (
this: IExecuteSingleFunctions, // this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions, // requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> { // ): Promise<IHttpRequestOptions> {
const groupName = this.getNodeParameter('name') as string; // const GroupName = this.getNodeParameter('name') as string;
if (groupName.length < 1 || groupName.length > 128) { // if (GroupName.length < 1 || GroupName.length > 128) {
throw new NodeOperationError( // throw new NodeOperationError(
this.getNode(), // this.getNode(),
'Group Name must be between 1 and 128 characters.', // 'Group Name must be between 1 and 128 characters.',
); // );
} // }
// Regex validation // // Regex validation
if (!/^[\w+=,.@-]+$/.test(groupName)) { // if (!/^[\w+=,.@-]+$/.test(GroupName)) {
throw new NodeOperationError( // throw new NodeOperationError(
this.getNode(), // this.getNode(),
'Group Name contains invalid characters. Allowed characters: [\\w+=,.@-].', // 'Group Name contains invalid characters. Allowed characters: [\\w+=,.@-].',
); // );
} // }
return requestOptions; // return requestOptions;
}, // },
], // ],
}, },
}, },
type: 'string', type: 'string',

View file

@ -1,2 +1,3 @@
export * from './UserDescription'; export * from './UserDescription';
export * from './UserPoolDescription'; export * from './UserPoolDescription';
export * from './GroupDescription';