n8n/packages/nodes-base/nodes/Aws/Cognito/descriptions/GroupDescription.ts
2024-11-27 12:12:51 +02:00

927 lines
19 KiB
TypeScript

import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { handleErrorPostReceive, processGroupsResponse } from '../GenericFunctions';
export const groupOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
default: 'getAll',
displayOptions: {
show: {
resource: ['group'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new group',
routing: {
request: {
method: 'POST',
headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateGroup',
},
// preSend: [
// async function (this: IExecuteSingleFunctions, requestOptions: IHttpRequestOptions) {
// // Call the function you created in GenericFunctions
// return await getUserIdForGroup.call(this, requestOptions);
// },
// ],
},
output: {
postReceive: [handleErrorPostReceive],
},
},
action: 'Create group',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete an existing group',
routing: {
request: {
method: 'POST',
headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.DeleteGroup',
},
},
output: {
postReceive: [
handleErrorPostReceive,
{
type: 'set',
properties: {
value: '={{ { "deleted": true } }}',
},
},
],
},
},
action: 'Delete group',
},
{
name: 'Get',
value: 'get',
description: 'Retrieve details of an existing group',
routing: {
request: {
method: 'POST',
headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.GetGroup',
},
},
output: {
postReceive: [handleErrorPostReceive],
},
},
action: 'Get group',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Retrieve a list of groups',
routing: {
send: {
paginate: true,
},
request: {
method: 'POST',
headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListGroups',
},
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}', // The API allows maximum 60 results per page
},
},
output: {
postReceive: [handleErrorPostReceive, processGroupsResponse],
},
},
action: 'Get many groups',
},
{
name: 'Update',
value: 'update',
description: 'Update an existing group',
routing: {
request: {
method: 'POST',
headers: {
'X-Amz-Target': 'AWSCognitoIdentityProviderService.UpdateGroup',
},
},
output: {
postReceive: [
handleErrorPostReceive,
{
type: 'set',
properties: {
value: '={{ { "updated": true } }}',
},
},
],
},
},
action: 'Update group',
},
],
},
];
const createFields: 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: ['create'],
},
},
routing: {
send: {
type: 'body',
property: 'UserPoolId',
},
},
modes: [
{
displayName: 'From list',
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: 'Name',
name: 'GroupName',
default: '',
placeholder: 'e.g. My New Group',
description: 'The name of the new group to create',
displayOptions: {
show: {
resource: ['group'],
operation: ['create'],
},
},
required: true,
routing: {
send: {
property: 'GroupName',
type: 'body',
paginate: true,
},
},
type: 'string',
validateType: 'string',
},
{
displayName: 'Options',
name: 'options',
default: {},
displayOptions: {
show: {
resource: ['group'],
operation: ['create'],
},
},
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',
name: 'path',
type: 'string',
default: '',
placeholder: 'e.g. /division_abc/engineering/',
description: 'The path to the group, if it is not included, it defaults to a slash (/)',
routing: {
send: {
property: 'Path',
type: 'body',
preSend: [
async function (
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const path = this.getNodeParameter('path', '/') as string;
// Length validation
if (path.length < 1 || path.length > 512) {
throw new NodeOperationError(
this.getNode(),
'Path must be between 1 and 512 characters.',
);
}
// Regex validation
if (!/^\/$|^\/[\u0021-\u007E]+\/$/.test(path)) {
throw new NodeOperationError(
this.getNode(),
'Path must begin and end with a forward slash and contain valid ASCII characters.',
);
}
return requestOptions;
},
],
},
},
},
{
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',
type: 'collection',
},
];
const deleteFields: 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: ['delete'],
},
},
routing: {
send: {
type: 'body',
property: 'UserPoolId',
},
},
modes: [
{
displayName: 'From list',
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: 'Group',
name: 'GroupName',
default: {
mode: 'list',
value: '',
},
description: 'Select the group you want to delete',
displayOptions: {
show: {
resource: ['group'],
operation: ['delete'],
},
},
modes: [
{
displayName: 'From list',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'searchGroups',
searchable: true,
},
},
{
displayName: 'By Name',
name: 'GroupName',
type: 'string',
hint: 'Enter the group name',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the allowed pattern.',
},
},
],
placeholder: 'e.g. Admins',
},
],
required: true,
routing: {
send: {
type: 'body',
property: 'GroupName',
},
},
type: 'resourceLocator',
},
];
const getFields: 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: ['get'],
},
},
routing: {
send: {
type: 'body',
property: 'UserPoolId',
},
},
modes: [
{
displayName: 'From list',
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: 'Group',
name: 'GroupName',
required: true,
type: 'resourceLocator',
default: {
mode: 'list',
value: '',
},
description: 'Select the group you want to retrieve',
displayOptions: {
show: {
resource: ['group'],
operation: ['get'],
},
},
routing: {
send: {
type: 'body',
property: 'GroupName',
},
},
modes: [
{
displayName: 'From list',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'searchGroups',
searchable: true,
},
},
{
displayName: 'By Name',
name: 'GroupName',
type: 'string',
hint: 'Enter the group name',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the allowed pattern.',
},
},
],
placeholder: 'e.g. Admins',
},
],
},
{
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[] = [
{
displayName: 'Return All',
name: 'returnAll',
default: false,
description: 'Whether to return all results or only up to a given limit',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
},
},
type: 'boolean',
},
{
displayName: 'Limit',
name: 'limit',
default: 50,
description: 'Max number of results to return',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
returnAll: [false],
},
},
routing: {
send: {
property: '$top',
type: 'query',
value: '={{ $value }}',
},
},
type: 'number',
typeOptions: {
minValue: 1,
},
validateType: 'number',
},
{
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',
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: 'Include Members',
name: 'includeMembers',
type: 'boolean',
default: false,
description: 'Whether include members of the group in the result',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
},
},
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: ['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',
},
},
},
];
const updateFields: 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: ['update'],
},
},
routing: {
send: {
type: 'body',
property: 'UserPoolId',
},
},
modes: [
{
displayName: 'From list',
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: 'Group',
name: 'GroupName',
default: {
mode: 'list',
value: '',
},
description: 'Select the group you want to update',
displayOptions: {
show: {
resource: ['group'],
operation: ['update'],
},
},
routing: {
send: {
type: 'body',
property: 'GroupName',
},
},
modes: [
{
displayName: 'From list',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'searchGroups',
searchable: true,
},
},
{
displayName: 'By Name',
name: 'GroupName',
type: 'string',
hint: 'Enter the group name',
validation: [
{
type: 'regex',
properties: {
regex: '^[\\w+=,.@-]+$',
errorMessage: 'The group name must follow the allowed pattern.',
},
},
],
placeholder: 'e.g. Admins',
},
],
required: true,
type: 'resourceLocator',
},
{
displayName: 'Options',
name: 'options',
default: {},
displayOptions: {
show: {
resource: ['group'],
operation: ['update'],
},
},
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',
name: 'path',
type: 'string',
default: '',
placeholder: 'e.g. /division_abc/engineering/',
description: 'The path to the group, if it is not included, it defaults to a slash (/)',
routing: {
send: {
property: 'Path',
type: 'body',
preSend: [
async function (
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const path = this.getNodeParameter('path', '/') as string;
// Length validation
if (path.length < 1 || path.length > 512) {
throw new NodeOperationError(
this.getNode(),
'Path must be between 1 and 512 characters.',
);
}
// Regex validation
if (!/^\/$|^\/[\u0021-\u007E]+\/$/.test(path)) {
throw new NodeOperationError(
this.getNode(),
'Path must begin and end with a forward slash and contain valid ASCII characters.',
);
}
return requestOptions;
},
],
},
},
},
{
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',
type: 'collection',
},
];
export const groupFields: INodeProperties[] = [
...createFields,
...deleteFields,
...getFields,
...getAllFields,
...updateFields,
];