Added more fields for create action

This commit is contained in:
Adina Totorean 2024-11-27 10:33:23 +02:00
parent e85ced02df
commit 39d4d9d72c
2 changed files with 228 additions and 32 deletions

View file

@ -81,6 +81,41 @@ export async function presendFilter(
return requestOptions; return requestOptions;
} }
/* Helper function to process attributes in UserAttributes */
export async function processAttributes(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
let body: Record<string, any>;
if (typeof requestOptions.body === 'string') {
try {
body = JSON.parse(requestOptions.body);
} catch (error) {
throw new ApplicationError('Invalid JSON body: Unable to parse.');
}
} else if (typeof requestOptions.body === 'object' && requestOptions.body !== null) {
body = requestOptions.body;
} else {
throw new ApplicationError('Invalid request body: Expected a JSON string or object.');
}
const attributes = this.getNodeParameter('UserAttributes.attributes', []) as Array<{
Name: string;
Value: string;
}>;
const processedAttributes = attributes.map((attribute) => ({
Name: attribute.Name.startsWith('custom:') ? attribute.Name : attribute.Name,
Value: attribute.Value,
}));
body.UserAttributes = processedAttributes;
requestOptions.body = JSON.stringify(body);
return requestOptions;
}
/* Helper function to handle pagination */ /* Helper function to handle pagination */
const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API
// ToDo: Test if pagination works // ToDo: Test if pagination works
@ -296,7 +331,6 @@ export async function awsRequest(
} }
/* listSearch methods */ /* listSearch methods */
export async function searchUserPools( export async function searchUserPools(
this: ILoadOptionsFunctions, this: ILoadOptionsFunctions,
filter?: string, filter?: string,

View file

@ -1,6 +1,11 @@
import type { INodeProperties } from 'n8n-workflow'; import type { INodeProperties } from 'n8n-workflow';
import { handleErrorPostReceive, presendFilter, presendTest } from '../GenericFunctions'; import {
handleErrorPostReceive,
presendFilter,
presendTest,
processAttributes,
} from '../GenericFunctions';
export const userOperations: INodeProperties[] = [ export const userOperations: INodeProperties[] = [
{ {
@ -198,7 +203,7 @@ const createFields: INodeProperties[] = [
], ],
}, },
{ {
displayName: 'Username', displayName: 'User Name',
name: 'Username', name: 'Username',
default: '', default: '',
description: 'The username of the new user to create', description: 'The username of the new user to create',
@ -221,10 +226,10 @@ const createFields: INodeProperties[] = [
validateType: 'string', validateType: 'string',
}, },
{ {
displayName: 'Options', displayName: 'Additional Fields',
name: 'options', name: 'additionalFields',
type: 'collection', type: 'collection',
placeholder: 'Add Option', placeholder: 'Add Field',
default: {}, default: {},
displayOptions: { displayOptions: {
show: { show: {
@ -234,55 +239,212 @@ const createFields: INodeProperties[] = [
}, },
options: [ options: [
{ {
displayName: 'Path', displayName: 'Client Metadata',
name: 'Path', name: 'clientMetadata',
type: 'string', type: 'fixedCollection',
validateType: 'string', placeholder: 'Add Metadata Pair',
default: '/', default: { metadata: [] },
placeholder: 'e.g. /division_abc/engineering/', description: 'A map of custom key-value pairs for workflows triggered by this action',
description: typeOptions: {
'The path for the user name, if it is not included, it defaults to a slash (/)', multipleValues: true,
},
options: [
{
displayName: 'Metadata',
name: 'metadata',
values: [
{
displayName: 'Key',
name: 'key',
type: 'string',
default: '',
description: 'The key of the metadata attribute',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'The value of the metadata attribute',
},
],
},
],
routing: { routing: {
send: { send: {
property: 'Path',
type: 'body', type: 'body',
preSend: [presendTest], property: 'ClientMetadata',
value:
'={{ $value.metadata && $value.metadata.length > 0 ? Object.fromEntries($value.metadata.map(attribute => [attribute.Name, attribute.Value])) : {} }}',
}, },
}, },
}, },
{ {
displayName: 'Permissions Boundary', displayName: 'Temporary Password',
name: 'PermissionsBoundary', name: 'TemporaryPassword',
type: 'string',
validateType: 'string',
default: '', default: '',
placeholder: 'e.g. arn:aws:iam::123456789012:policy/ExampleBoundaryPolicy', description: "The user's temporary password",
description: 'Enter the ARN of a policy to set as the Permissions Boundary',
routing: { routing: {
send: { send: {
property: 'PermissionsBoundary', property: 'TemporaryPassword',
type: 'body',
preSend: [presendTest],
},
},
type: 'string',
typeOptions: { password: true },
},
{
displayName: 'Message Action',
name: 'MessageAction',
default: 'RESEND',
description:
"Set to RESEND to resend the invitation message to a user that already exists and reset the expiration limit on the user's account. Set to SUPPRESS to suppress sending the message. You can specify only one value.",
type: 'options',
options: [
{
name: 'Resend',
value: 'RESEND',
},
{
name: 'Suppress',
value: 'SUPPRESS',
},
],
routing: {
send: {
property: 'MessageAction',
type: 'body', type: 'body',
preSend: [presendTest], preSend: [presendTest],
}, },
}, },
}, },
{ {
displayName: 'Tags', displayName: 'Force Alias Creation',
name: 'Tags', name: 'ForceAliasCreation',
type: 'multiOptions', type: 'boolean',
placeholder: 'Add Tags', validateType: 'boolean',
default: [], default: false,
description: 'A list of tags that you want to attach to the new user', description:
//TO-DO-GET TAGS LIST 'Whether this parameter is used only if the phone_number_verified or email_verified attribute is set to True. Otherwise, it is ignored. If set to True, and the phone number or email address specified in the UserAttributes parameter already exists as an alias with a different user, the alias will be migrated. If set to False, an AliasExistsException error is thrown if the alias already exists',
options: [],
routing: { routing: {
send: { send: {
property: 'Tags', type: 'body',
property: 'ForceAliasCreation',
},
},
},
{
displayName: 'Desired Delivery Mediums',
name: 'DesiredDeliveryMediums',
default: ['SMS'],
description:
'Specify EMAIL if email will be used to send the welcome message. Specify SMS if the phone number will be used. The default value is SMS. You can specify more than one value.',
type: 'multiOptions',
options: [
{
name: 'SMS',
value: 'SMS',
},
{
name: 'Email',
value: 'EMAIL',
},
],
routing: {
send: {
property: 'DesiredDeliveryMediums',
type: 'body', type: 'body',
preSend: [presendTest], preSend: [presendTest],
}, },
}, },
}, },
{
displayName: 'User Attributes',
name: 'UserAttributes',
type: 'fixedCollection',
placeholder: 'Add Attribute',
default: {
attributes: [],
},
description: 'Attributes to add for the user',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Attributes',
name: 'attributes',
values: [
{
displayName: 'Name',
name: 'Name',
type: 'string',
default: '',
description: 'The name of the attribute (e.g., custom:deliverables)',
},
{
displayName: 'Value',
name: 'Value',
type: 'string',
default: '',
description: 'The value of the attribute',
},
],
},
],
routing: {
send: {
type: 'body',
property: 'UserAttributes',
value:
'={{ $value.attributes?.map(attribute => ({ Name: attribute.Name, Value: attribute.Value })) || [] }}',
preSend: [processAttributes],
},
},
},
{
displayName: 'Validation Data',
name: 'ValidationData',
type: 'fixedCollection',
placeholder: 'Add Attribute',
default: {
attributes: [],
},
description: 'Validation data to add for the user',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Data',
name: 'data',
values: [
{
displayName: 'Key',
name: 'Key',
type: 'string',
default: '',
description: 'The name of the data (e.g., custom:deliverables)',
},
{
displayName: 'Value',
name: 'Value',
type: 'string',
default: '',
description: 'The value of the data',
},
],
},
],
routing: {
send: {
type: 'body',
property: 'ValidationData',
value: '={{ $value.data?.map(data => ({ Name: data.Key, Value: data.Value })) || [] }}',
},
},
},
], ],
}, },
]; ];