Merge branch 'node-aws-cognito' of https://github.com/digital-boss/n8n into node-aws-cognito

This commit is contained in:
Adina Totorean 2024-11-27 10:34:06 +02:00
commit b4406c48a8
2 changed files with 290 additions and 196 deletions

View file

@ -461,7 +461,7 @@ export async function searchGroups(
} }
// Setup the options for the AWS request // Setup the options for the AWS request
const opts: IHttpRequestOptions = { const opts: IHttpRequestOptions = {
url: '', // the base URL is set in "awsRequest" url: '',
method: 'POST', method: 'POST',
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups',

View file

@ -1,7 +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, presendTest } from '../GenericFunctions'; import { handleErrorPostReceive } from '../GenericFunctions';
export const groupOperations: INodeProperties[] = [ export const groupOperations: INodeProperties[] = [
{ {
@ -26,10 +26,6 @@ export const groupOperations: INodeProperties[] = [
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateGroup', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateGroup',
}, },
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}', // The API allows maximum 60 results per page
},
// preSend: [ // preSend: [
// async function (this: IExecuteSingleFunctions, requestOptions: IHttpRequestOptions) { // async function (this: IExecuteSingleFunctions, requestOptions: IHttpRequestOptions) {
// // Call the function you created in GenericFunctions // // Call the function you created in GenericFunctions
@ -53,13 +49,17 @@ export const groupOperations: INodeProperties[] = [
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.DeleteGroup', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.DeleteGroup',
}, },
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}', // The API allows maximum 60 results per page
},
}, },
output: { output: {
postReceive: [handleErrorPostReceive], postReceive: [
handleErrorPostReceive,
{
type: 'set',
properties: {
value: '={{ { "deleted": true } }}',
},
},
],
}, },
}, },
action: 'Delete group', action: 'Delete group',
@ -74,10 +74,6 @@ export const groupOperations: INodeProperties[] = [
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.GetGroup', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.GetGroup',
}, },
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}', // The API allows maximum 60 results per page
},
}, },
output: { output: {
postReceive: [handleErrorPostReceive], postReceive: [handleErrorPostReceive],
@ -104,7 +100,22 @@ export const groupOperations: INodeProperties[] = [
}, },
}, },
output: { output: {
postReceive: [handleErrorPostReceive], postReceive: [
handleErrorPostReceive,
{
type: 'set',
properties: {
value: '={{ $response.body.Groups }}',
},
},
{
type: 'set',
properties: {
value:
'={{ $response.body.Groups.length > 10 && $parameter.simplified ? $response.body.Groups.map(group => ({ CreatedDate: group.CreatedDate, Description: group.Description, GroupName: group.GroupName, LastModifiedDate: group.LastModifiedDate })) : $response.body.Groups }}', // Simplify if more than 10 fields
},
},
],
}, },
}, },
action: 'Get many groups', action: 'Get many groups',
@ -119,13 +130,17 @@ export const groupOperations: INodeProperties[] = [
headers: { headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.UpdateGroup', 'X-Amz-Target': 'AWSCognitoIdentityProviderService.UpdateGroup',
}, },
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}', // The API allows maximum 60 results per page
},
}, },
output: { output: {
postReceive: [handleErrorPostReceive], postReceive: [
handleErrorPostReceive,
{
type: 'set',
properties: {
value: '={{ { "updated": true } }}',
},
},
],
}, },
}, },
action: 'Update group', action: 'Update group',
@ -159,7 +174,7 @@ const createFields: 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: {
@ -177,7 +192,7 @@ const createFields: INodeProperties[] = [
type: 'regex', type: 'regex',
properties: { properties: {
regex: '^[\\w-]+_[0-9a-zA-Z]+$', regex: '^[\\w-]+_[0-9a-zA-Z]+$',
errorMessage: 'The ID must follow the pattern "xxxxxx_xxxxxxxxxxx"', errorMessage: 'The ID must follow the pattern "xxxxxx_xxxxxxxxxxx".',
}, },
}, },
], ],
@ -186,7 +201,7 @@ const createFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group Name', displayName: 'Name',
name: 'GroupName', name: 'GroupName',
default: '', default: '',
placeholder: 'e.g. My New Group', placeholder: 'e.g. My New Group',
@ -202,7 +217,6 @@ const createFields: INodeProperties[] = [
send: { send: {
property: 'GroupName', property: 'GroupName',
type: 'body', type: 'body',
preSend: [presendTest], // ToDo: Remove this line before completing the pull request
paginate: true, paginate: true,
}, },
}, },
@ -220,6 +234,35 @@ const createFields: INodeProperties[] = [
}, },
}, },
options: [ options: [
{
displayName: 'Description',
name: 'Description',
default: '',
placeholder: 'e.g. New group description',
description: 'A description for the new group',
type: 'string',
routing: {
send: {
type: 'body',
property: 'Description',
},
},
},
{
displayName: 'Precedence',
name: 'Precedence',
default: '',
placeholder: 'e.g. 10',
description: 'Precedence value for the group. Lower values indicate higher priority.',
type: 'number',
routing: {
send: {
type: 'body',
property: 'Precedence',
},
},
validateType: 'number',
},
{ {
displayName: 'Path', displayName: 'Path',
name: 'path', name: 'path',
@ -260,6 +303,20 @@ const createFields: INodeProperties[] = [
}, },
}, },
}, },
{
displayName: 'Role ARN',
name: 'RoleArn',
default: '',
placeholder: 'e.g. arn:aws:iam::123456789012:role/GroupRole',
description: 'The role ARN for the group, used for setting claims in tokens',
type: 'string',
routing: {
send: {
type: 'body',
property: 'RoleArn',
},
},
},
], ],
placeholder: 'Add Option', placeholder: 'Add Option',
type: 'collection', type: 'collection',
@ -291,7 +348,7 @@ const deleteFields: 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: {
@ -318,7 +375,7 @@ const deleteFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group Name', displayName: 'Group',
name: 'GroupName', name: 'GroupName',
default: { default: {
mode: 'list', mode: 'list',
@ -337,13 +394,13 @@ const deleteFields: 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: [
@ -351,7 +408,7 @@ const deleteFields: 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.',
}, },
}, },
], ],
@ -421,12 +478,15 @@ const getFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group Name', displayName: 'Group',
name: 'GroupName', name: 'GroupName',
required: true, required: true,
type: 'resourceLocator', type: 'resourceLocator',
default: { mode: 'list', value: '' }, default: {
description: 'The name of the group to retrieve', mode: 'list',
value: '',
},
description: 'Select the group you want to retrieve',
displayOptions: { displayOptions: {
show: { show: {
resource: ['group'], resource: ['group'],
@ -467,46 +527,70 @@ const getFields: INodeProperties[] = [
}, },
], ],
}, },
{
displayName: 'Include Members',
name: 'includeMembers',
type: 'boolean',
default: false,
description: 'Whether include members of the group in the result',
displayOptions: {
show: {
resource: ['group'],
operation: ['get'],
},
},
routing: {
send: {
property: '$expand',
type: 'query',
value:
'={{ $value ? "members($select=CreatedDate,Description,GroupName,LastModifiedDate,Precedence,UserPoolId)" : undefined }}',
},
},
},
{
displayName: 'Include Group Policy',
name: 'includeGroupPolicy',
type: 'boolean',
default: false,
description: 'Whether include group policy details in the result',
displayOptions: {
show: {
resource: ['group'],
operation: ['get'],
},
},
routing: {
send: {
property: '$expand',
type: 'query',
value: '={{ $value ? "groupPolicy($select=policyName,policyType)" : undefined }}',
},
},
},
{
displayName: 'Simplified',
name: 'simplified',
type: 'boolean',
default: false,
description: 'Whether simplify the response if there are more than 10 fields',
displayOptions: {
show: {
resource: ['group'],
operation: ['get'],
},
},
routing: {
send: {
property: '$select',
type: 'query',
value: 'CreatedDate,Description,GroupName,LastModifiedDate,Precedence,UserPoolId',
},
},
},
]; ];
const getAllFields: INodeProperties[] = [ const getAllFields: INodeProperties[] = [
{
displayName: 'User Pool ID',
name: 'userPoolId',
required: true,
type: 'resourceLocator',
default: { mode: 'list', value: '' },
description: 'The user pool ID where the users are managed',
displayOptions: { show: { resource: ['group'], operation: ['getAll'] } },
routing: { send: { type: 'body', property: 'UserPoolId' } },
modes: [
{
displayName: 'From list', // ToDo: Fix error when selecting this option
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'searchUserPools',
searchable: true,
},
},
{
displayName: 'By ID',
name: 'id',
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',
},
],
},
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
@ -518,28 +602,6 @@ const getAllFields: INodeProperties[] = [
operation: ['getAll'], operation: ['getAll'],
}, },
}, },
routing: {
send: {
paginate: '={{ $value }}',
},
operations: {
pagination: {
type: 'generic',
properties: {
continue: '={{ !!$response.body?.["@odata.nextLink"] }}',
request: {
url: '={{ $response.body?.["@odata.nextLink"] ?? $request.url }}',
qs: {
$filter:
'={{ !!$response.body?.["@odata.nextLink"] ? undefined : $request.qs?.$filter }}',
$select:
'={{ !!$response.body?.["@odata.nextLink"] ? undefined : $request.qs?.$select }}',
},
},
},
},
},
},
type: 'boolean', type: 'boolean',
}, },
{ {
@ -568,69 +630,102 @@ const getAllFields: INodeProperties[] = [
validateType: 'number', validateType: 'number',
}, },
{ {
displayName: 'Options', displayName: 'User Pool ID',
name: 'options', name: 'userPoolId',
default: {}, required: true,
displayOptions: { type: 'resourceLocator',
show: { default: { mode: 'list', value: '' },
resource: ['group'], description: 'The user pool ID where the users are managed',
operation: ['getAll'], displayOptions: { show: { resource: ['group'], operation: ['getAll'] } },
}, routing: { send: { type: 'body', property: 'UserPoolId' } },
}, modes: [
options: [
{ {
// 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: 'searchUserPools',
searchable: true,
}, },
type: 'multiOptions', },
{
displayName: 'By ID',
name: 'id',
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',
}, },
], ],
placeholder: 'Add Option',
type: 'collection',
}, },
{ {
displayName: 'Filters', displayName: 'Include Members',
name: 'filters', name: 'includeMembers',
default: {}, type: 'boolean',
default: false,
description: 'Whether include members of the group in the result',
displayOptions: { displayOptions: {
show: { show: {
resource: ['group'], resource: ['group'],
operation: ['getAll'], operation: ['getAll'],
}, },
}, },
options: [ routing: {
{ send: {
displayName: 'Filter Query Parameter', property: '$expand',
name: 'filter', type: 'query',
default: '', value:
description: '={{ $value ? "members($select=CreatedDate,Description,GroupName,LastModifiedDate,Precedence,UserPoolId)" : undefined }}',
'<a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter">Query parameter</a> to filter results by',
placeholder: "startswith(displayName, 'a')",
routing: {
send: {
property: '$filter',
type: 'query',
},
},
type: 'string',
validateType: 'string',
}, },
], },
placeholder: 'Add Filter', },
type: 'collection', {
displayName: 'Include Group Policy',
name: 'includeGroupPolicy',
type: 'boolean',
default: false,
description: 'Whether include group policy details in the result',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
},
},
routing: {
send: {
property: '$expand',
type: 'query',
value: '={{ $value ? "groupPolicy($select=policyName,policyType)" : undefined }}',
},
},
},
{
displayName: 'Simplified',
name: 'simplified',
type: 'boolean',
default: false,
description: 'Whether simplify the response if there are more than 10 fields',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
},
},
routing: {
send: {
property: '$select',
type: 'query',
value: 'CreatedDate,Description,GroupName,LastModifiedDate,Precedence,UserPoolId',
},
},
}, },
]; ];
@ -659,7 +754,7 @@ const updateFields: 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: {
@ -686,7 +781,7 @@ const updateFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Group Name', displayName: 'Group',
name: 'GroupName', name: 'GroupName',
default: { default: {
mode: 'list', mode: 'list',
@ -699,9 +794,15 @@ const updateFields: INodeProperties[] = [
operation: ['update'], operation: ['update'],
}, },
}, },
routing: {
send: {
type: 'body',
property: 'GroupName',
},
},
modes: [ modes: [
{ {
displayName: 'From List', displayName: 'From list',
name: 'list', name: 'list',
type: 'list', type: 'list',
typeOptions: { typeOptions: {
@ -727,60 +828,8 @@ const updateFields: INodeProperties[] = [
}, },
], ],
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',
}, },
{
displayName: 'New Name',
name: 'name',
default: '',
placeholder: 'e.g. My New Group',
description: 'The new name of the group',
displayOptions: {
show: {
resource: ['group'],
operation: ['update'],
},
},
routing: {
send: {
property: 'GroupName',
type: 'body',
// preSend: [
// async function (
// this: IExecuteSingleFunctions,
// requestOptions: IHttpRequestOptions,
// ): Promise<IHttpRequestOptions> {
// const GroupName = this.getNodeParameter('name') 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',
validateType: 'string',
},
{ {
displayName: 'Options', displayName: 'Options',
name: 'options', name: 'options',
@ -792,6 +841,36 @@ const updateFields: INodeProperties[] = [
}, },
}, },
options: [ options: [
{
displayName: 'Description',
name: 'Description',
default: '',
placeholder: 'e.g. Updated group description',
description: 'A new description for the group',
type: 'string',
routing: {
send: {
type: 'body',
property: 'Description',
},
},
},
{
displayName: 'Precedence',
name: 'Precedence',
default: '',
placeholder: 'e.g. 10',
description:
'The new precedence value for the group. Lower values indicate higher priority.',
type: 'number',
routing: {
send: {
type: 'body',
property: 'Precedence',
},
},
validateType: 'number',
},
{ {
displayName: 'Path', displayName: 'Path',
name: 'path', name: 'path',
@ -832,6 +911,21 @@ const updateFields: INodeProperties[] = [
}, },
}, },
}, },
{
displayName: 'Role ARN',
name: 'RoleArn',
default: '',
placeholder: 'e.g. arn:aws:iam::123456789012:role/GroupRole',
description:
'A new role Amazon Resource Name (ARN) for the group. Used for setting claims in tokens.',
type: 'string',
routing: {
send: {
type: 'body',
property: 'RoleArn',
},
},
},
], ],
placeholder: 'Add Option', placeholder: 'Add Option',
type: 'collection', type: 'collection',