Files
n8n-enterprise-unlocked/packages/nodes-base/nodes/Aws/Cognito/transport/index.ts
Valentina Lilova f6e5efc2e0 feat(n8n AWS Cognito Node): New node (#11767)
Co-authored-by: Stamsy <stams_89@abv.bg>
Co-authored-by: Adina Totorean <adinatotorean99@gmail.com>
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
Co-authored-by: AdinaTotorean <64439268+adina-hub@users.noreply.github.com>
Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
Co-authored-by: feelgood-interface <feelgood.interface@gmail.com>
2025-05-08 10:50:48 +01:00

73 lines
1.7 KiB
TypeScript

import type {
ILoadOptionsFunctions,
IPollFunctions,
IHttpRequestOptions,
IExecuteSingleFunctions,
IDataObject,
IHttpRequestMethods,
} from 'n8n-workflow';
import type { AwsCredentialsType } from '../../../../credentials/Aws.credentials';
export async function awsApiRequest(
this: ILoadOptionsFunctions | IPollFunctions | IExecuteSingleFunctions,
method: IHttpRequestMethods,
action: string,
body: string,
): Promise<any> {
const credentialsType = 'aws';
const credentials = await this.getCredentials<AwsCredentialsType>(credentialsType);
const requestOptions: IHttpRequestOptions = {
url: '',
method,
body,
headers: {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': `AWSCognitoIdentityProviderService.${action}`,
},
qs: {
service: 'cognito-idp',
_region: credentials.region,
},
};
return await this.helpers.httpRequestWithAuthentication.call(
this,
credentialsType,
requestOptions,
);
}
export async function awsApiRequestAllItems(
this: ILoadOptionsFunctions | IPollFunctions | IExecuteSingleFunctions,
method: IHttpRequestMethods,
action: string,
body: IDataObject,
propertyName: string,
): Promise<IDataObject[]> {
const returnData: IDataObject[] = [];
let nextToken: string | undefined;
do {
const requestBody: IDataObject = {
...body,
...(nextToken ? { NextToken: nextToken } : {}),
};
const response = (await awsApiRequest.call(
this,
method,
action,
JSON.stringify(requestBody),
)) as IDataObject;
const items = (response[propertyName] ?? []) as IDataObject[];
returnData.push(...items);
nextToken = response.NextToken as string | undefined;
} while (nextToken);
return returnData;
}