feat(Google Cloud Firestore Node): Add support for service account and document creation with id (#9713)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
adrian-martinez-onestic
2024-07-08 13:40:52 +02:00
committed by GitHub
parent 8f970b5d37
commit cb1bbf5fd3
4 changed files with 63 additions and 6 deletions

View File

@@ -9,12 +9,12 @@ import type {
import { NodeApiError } from 'n8n-workflow';
import moment from 'moment-timezone';
import { getGoogleAccessToken } from '../../GenericFunctions';
export async function googleApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
resource: string,
body: any = {},
qs: IDataObject = {},
uri: string | null = null,
@@ -37,12 +37,20 @@ export async function googleApiRequest(
delete options.body;
}
let credentialType = 'googleFirebaseCloudFirestoreOAuth2Api';
const authentication = this.getNodeParameter('authentication', 0) as string;
if (authentication === 'serviceAccount') {
const credentials = await this.getCredentials('googleApi');
credentialType = 'googleApi';
const { access_token } = await getGoogleAccessToken.call(this, credentials, 'firestore');
(options.headers as IDataObject).Authorization = `Bearer ${access_token}`;
}
//@ts-ignore
return await this.helpers.requestOAuth2.call(
this,
'googleFirebaseCloudFirestoreOAuth2Api',
options,
);
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}