first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,85 @@
import type {
IDataObject,
IExecuteFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
IRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
export async function googleApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
projectId: string,
method: IHttpRequestMethods,
resource: string,
body: any = {},
qs: IDataObject = {},
headers: IDataObject = {},
uri: string | null = null,
): Promise<any> {
const { region } = await this.getCredentials('googleFirebaseRealtimeDatabaseOAuth2Api');
const options: IRequestOptions = {
headers: {
'Content-Type': 'application/json',
},
method,
body,
qs,
url: uri || `https://${projectId}.${region}/${resource}.json`,
json: true,
};
try {
if (Object.keys(headers).length !== 0) {
options.headers = Object.assign({}, options.headers, headers);
}
if (Object.keys(body as IDataObject).length === 0) {
delete options.body;
}
return await this.helpers.requestOAuth2.call(
this,
'googleFirebaseRealtimeDatabaseOAuth2Api',
options,
);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}
export async function googleApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
projectId: string,
method: IHttpRequestMethods,
resource: string,
body: any = {},
qs: IDataObject = {},
_headers: IDataObject = {},
uri: string | null = null,
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
qs.pageSize = 100;
do {
responseData = await googleApiRequest.call(
this,
projectId,
method,
resource,
body,
qs,
{},
uri,
);
qs.pageToken = responseData.nextPageToken;
returnData.push.apply(returnData, responseData[resource] as IDataObject[]);
} while (responseData.nextPageToken !== undefined && responseData.nextPageToken !== '');
return returnData;
}
@@ -0,0 +1,25 @@
{
"node": "n8n-nodes-base.googleFirebaseRealtimeDatabase",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Data & Storage"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/google/oauth-single-service/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlecloudrealtimedatabase/"
}
],
"generic": [
{
"label": "15 Google apps you can combine and automate to increase productivity",
"icon": "💡",
"url": "https://n8n.io/blog/automate-google-apps-for-productivity/"
}
]
}
}
@@ -0,0 +1,256 @@
import type {
IExecuteFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
JsonObject,
IHttpRequestMethods,
} from 'n8n-workflow';
import { NodeApiError, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
export class GoogleFirebaseRealtimeDatabase implements INodeType {
description: INodeTypeDescription = {
displayName: 'Google Cloud Realtime Database',
name: 'googleFirebaseRealtimeDatabase',
icon: 'file:googleFirebaseRealtimeDatabase.svg',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Interact with Google Firebase - Realtime Database API',
defaults: {
name: 'Google Cloud Realtime Database',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'googleFirebaseRealtimeDatabaseOAuth2Api',
},
],
properties: [
{
displayName: 'Project Name or ID',
name: 'projectId',
type: 'options',
default: '',
typeOptions: {
loadOptionsMethod: 'getProjects',
},
description:
'As displayed in firebase console URL. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
required: true,
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Create',
value: 'create',
description: 'Write data to a database',
action: 'Write data to a database',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete data from a database',
action: 'Delete data from a database',
},
{
name: 'Get',
value: 'get',
description: 'Get a record from a database',
action: 'Get a record from a database',
},
{
name: 'Push',
value: 'push',
description: 'Append to a list of data',
action: 'Append to a list of data',
},
{
name: 'Update',
value: 'update',
description: 'Update item on a database',
action: 'Update item in a database',
},
],
default: 'create',
required: true,
},
{
displayName: 'Object Path',
name: 'path',
type: 'string',
default: '',
placeholder: 'e.g. /app/users',
// eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-json
description: 'Object path on database. Do not append .json.',
required: true,
displayOptions: {
hide: {
operation: ['get'],
},
},
},
{
displayName: 'Object Path',
name: 'path',
type: 'string',
default: '',
placeholder: 'e.g. /app/users',
// eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-json
description: 'Object path on database. Do not append .json.',
hint: 'Leave blank to get a whole database object',
displayOptions: {
show: {
operation: ['get'],
},
},
},
{
displayName: 'Columns / Attributes',
name: 'attributes',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['create', 'push', 'update'],
},
},
description: 'Attributes to save',
required: true,
placeholder: 'age, name, city',
},
],
};
methods = {
loadOptions: {
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const projects = await googleApiRequestAllItems.call(
this,
'',
'GET',
'results',
{},
{},
{},
'https://firebase.googleapis.com/v1beta1/projects',
);
const returnData = projects
// select only realtime database projects
.filter(
(project: IDataObject) => (project.resources as IDataObject).realtimeDatabaseInstance,
)
.map((project: IDataObject) => ({
name: project.projectId,
value: (project.resources as IDataObject).realtimeDatabaseInstance,
})) as INodePropertyOptions[];
return returnData;
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
let responseData;
const operation = this.getNodeParameter('operation', 0);
//https://firebase.google.com/docs/reference/rest/database
if (
['push', 'create', 'update'].includes(operation) &&
items.length === 1 &&
Object.keys(items[0].json).length === 0
) {
throw new NodeOperationError(this.getNode(), `The ${operation} operation needs input data`);
}
for (let i = 0; i < length; i++) {
try {
const projectId = this.getNodeParameter('projectId', i) as string;
let method: IHttpRequestMethods = 'GET',
attributes = '';
const document: IDataObject = {};
if (operation === 'create') {
method = 'PUT';
attributes = this.getNodeParameter('attributes', i) as string;
} else if (operation === 'delete') {
method = 'DELETE';
} else if (operation === 'get') {
method = 'GET';
} else if (operation === 'push') {
method = 'POST';
attributes = this.getNodeParameter('attributes', i) as string;
} else if (operation === 'update') {
method = 'PATCH';
attributes = this.getNodeParameter('attributes', i) as string;
}
if (attributes) {
const attributeList = attributes.split(',').map((el) => el.trim());
attributeList.map((attribute: string) => {
if (items[i].json.hasOwnProperty(attribute)) {
document[attribute] = items[i].json[attribute];
}
});
}
responseData = await googleApiRequest.call(
this,
projectId,
method,
this.getNodeParameter('path', i) as string,
document,
);
if (responseData === null) {
if (operation === 'get') {
throw new NodeApiError(this.getNode(), responseData as JsonObject, {
message: 'Requested entity was not found.',
});
} else if (method === 'DELETE') {
responseData = { success: true };
}
}
} catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: i } },
);
returnData.push(...executionErrorData);
continue;
}
throw error;
}
if (typeof responseData === 'string' || typeof responseData === 'number') {
responseData = {
[this.getNodeParameter('path', i) as string]: responseData,
};
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
return [returnData];
}
}
@@ -0,0 +1,242 @@
import { mock, mockDeep } from 'jest-mock-extended';
import type { IExecuteFunctions, ILoadOptionsFunctions, INode } from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { googleApiRequest } from '../GenericFunctions';
describe('GoogleFirebaseRealtimeDatabase > GenericFunctions', () => {
let mockExecuteFunctions: jest.Mocked<IExecuteFunctions>;
let mockLoadOptionsFunctions: jest.Mocked<ILoadOptionsFunctions>;
let mockNode: INode;
beforeEach(() => {
mockExecuteFunctions = mockDeep<IExecuteFunctions>();
mockLoadOptionsFunctions = mockDeep<ILoadOptionsFunctions>();
mockNode = mock<INode>({
id: 'test-node',
name: 'Test RealtimeDatabase Node',
type: 'n8n-nodes-base.googleFirebaseRealtimeDatabase',
typeVersion: 1,
position: [0, 0],
parameters: {},
});
mockExecuteFunctions.getNode.mockReturnValue(mockNode);
mockLoadOptionsFunctions.getNode.mockReturnValue(mockNode);
jest.clearAllMocks();
});
describe('googleApiRequest', () => {
const mockRequestOAuth2 = jest.fn();
beforeEach(() => {
mockExecuteFunctions.helpers.requestOAuth2 = mockRequestOAuth2;
mockLoadOptionsFunctions.helpers.requestOAuth2 = mockRequestOAuth2;
});
describe('successful requests', () => {
beforeEach(() => {
mockExecuteFunctions.getCredentials.mockResolvedValue({
region: 'firebaseio.com',
});
mockLoadOptionsFunctions.getCredentials.mockResolvedValue({
region: 'firebaseio.com',
});
});
it('should make successful API request with default options', async () => {
const mockResponse = { data: { test: 'value' } };
mockRequestOAuth2.mockResolvedValue(mockResponse);
const result = await googleApiRequest.call(
mockExecuteFunctions,
'test-project',
'GET',
'/users',
);
expect(result).toEqual(mockResponse);
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://test-project.firebaseio.com//users.json',
headers: {
'Content-Type': 'application/json',
},
qs: {},
json: true,
}),
);
});
it('should include body for POST requests', async () => {
const mockResponse = { success: true };
const requestBody = { name: 'John Doe', email: 'john@example.com' };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(
mockExecuteFunctions,
'test-project',
'POST',
'/users',
requestBody,
);
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
method: 'POST',
body: requestBody,
}),
);
});
it('should remove empty body for GET requests', async () => {
const mockResponse = { data: [] };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(mockExecuteFunctions, 'test-project', 'GET', '/users', {});
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
expect.not.objectContaining({ body: expect.anything() }),
);
});
it('should include query parameters', async () => {
const mockResponse = { data: [] };
const queryParams = { orderBy: '"$key"', limitToFirst: 10 };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(
mockExecuteFunctions,
'test-project',
'GET',
'/users',
{},
queryParams,
);
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
qs: queryParams,
}),
);
});
it('should include custom headers', async () => {
const mockResponse = { data: [] };
const customHeaders = { 'X-Custom-Header': 'custom-value' };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(
mockExecuteFunctions,
'test-project',
'GET',
'/users',
{},
{},
customHeaders,
);
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
headers: {
'Content-Type': 'application/json',
'X-Custom-Header': 'custom-value',
},
}),
);
});
it('should use custom URI when provided', async () => {
const mockResponse = { data: [] };
const customUri = 'https://custom-project.firebaseio.com/custom/path.json';
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(
mockExecuteFunctions,
'test-project',
'GET',
'/users',
{},
{},
{},
customUri,
);
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
url: customUri,
}),
);
});
it('should use different regions correctly', async () => {
mockExecuteFunctions.getCredentials.mockResolvedValue({
region: 'europe-west1-firebase.cloudfunctions.net',
});
const mockResponse = { data: [] };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(mockExecuteFunctions, 'test-project', 'GET', '/users');
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
url: 'https://test-project.europe-west1-firebase.cloudfunctions.net//users.json',
}),
);
});
});
describe('error handling', () => {
beforeEach(() => {
mockExecuteFunctions.getCredentials.mockResolvedValue({
region: 'firebaseio.com',
});
});
it('should throw NodeApiError on API failure', async () => {
const apiError = new Error('API request failed');
mockRequestOAuth2.mockRejectedValue(apiError);
await expect(
googleApiRequest.call(mockExecuteFunctions, 'test-project', 'GET', '/users'),
).rejects.toThrow(NodeApiError);
expect(mockExecuteFunctions.getNode).toHaveBeenCalled();
});
it('should handle credential errors', async () => {
const credentialError = new Error('Invalid credentials');
mockExecuteFunctions.getCredentials.mockRejectedValue(credentialError);
await expect(
googleApiRequest.call(mockExecuteFunctions, 'test-project', 'GET', '/users'),
).rejects.toThrow('Invalid credentials');
});
it('should handle missing region in credentials', async () => {
mockExecuteFunctions.getCredentials.mockResolvedValue({});
const mockResponse = { data: [] };
mockRequestOAuth2.mockResolvedValue(mockResponse);
await googleApiRequest.call(mockExecuteFunctions, 'test-project', 'GET', '/users');
expect(mockRequestOAuth2).toHaveBeenCalledWith(
'googleFirebaseRealtimeDatabaseOAuth2Api',
expect.objectContaining({
url: 'https://test-project.undefined//users.json',
}),
);
});
});
});
});
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192"><defs><linearGradient id="b" x1="56.9" x2="48.9" y1="102.54" y2="98.36" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#a52714"/><stop offset=".4" stop-color="#a52714" stop-opacity=".5"/><stop offset=".8" stop-color="#a52714" stop-opacity="0"/></linearGradient><linearGradient id="c" x1="90.89" x2="87.31" y1="90.91" y2="87.33" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#a52714" stop-opacity=".8"/><stop offset=".5" stop-color="#a52714" stop-opacity=".21"/><stop offset="1" stop-color="#a52714" stop-opacity="0"/></linearGradient><linearGradient id="d" x1="27.188" x2="160.875" y1="40.281" y2="173.968" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#fff" stop-opacity=".1"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></linearGradient><clipPath id="a"><path fill="none" d="M143.41 47.34a4 4 0 0 0-6.77-2.16L115.88 66 99.54 34.89a4 4 0 0 0-7.08 0l-8.93 17-22.4-41.77a4 4 0 0 0-7.48 1.28L32 150l57.9 32.46a12 12 0 0 0 11.7 0L160 150z"/></clipPath></defs><g fill="none"><path d="M0 0h192v192H0z"/><g clip-path="url(#a)"><path fill="#ffa000" d="M32 150 53.66 11.39a4 4 0 0 1 7.48-1.27l22.4 41.78 8.93-17a4 4 0 0 1 7.08 0L160 150z"/><path fill="url(#b)" d="M106 9 0 0v192l32-42z" opacity=".12"/><path fill="#f57c00" d="m106.83 96.01-23.3-44.12L32 150z"/><path fill="url(#c)" d="M0 0h192v192H0z" opacity=".2"/><path fill="#ffca28" d="M160 150 143.41 47.34a4 4 0 0 0-6.77-2.16L32 150l57.9 32.47a12 12 0 0 0 11.7 0z"/><path fill="#fff" fill-opacity=".2" d="M143.41 47.34a4 4 0 0 0-6.77-2.16L115.88 66 99.54 34.89a4 4 0 0 0-7.08 0l-8.93 17-22.4-41.77a4 4 0 0 0-7.48 1.28L32 150h-.08l.07.08.57.28L115.83 67l20.78-20.8a4 4 0 0 1 6.78 2.16l16.45 101.74.16-.1zM32.19 149.81 53.66 12.39a4 4 0 0 1 7.48-1.28l22.4 41.78 8.93-17a4 4 0 0 1 7.08 0l16 30.43z"/><path fill="#a52714" d="M101.6 181.49a12 12 0 0 1-11.7 0l-57.76-32.4-.14.91 57.9 32.46a12 12 0 0 0 11.7 0L160 150l-.15-.92z" opacity=".2"/><path fill="url(#d)" d="M143.41 47.34a4 4 0 0 0-6.77-2.16L115.88 66 99.54 34.89a4 4 0 0 0-7.08 0l-8.93 17-22.4-41.77a4 4 0 0 0-7.48 1.28L32 150l57.9 32.46a12 12 0 0 0 11.7 0L160 150z"/></g><circle cx="144" cy="144" r="40" fill="#757575"/><path fill="#fff" fill-rule="evenodd" d="M126 150h36v8.004a3.99 3.99 0 0 1-3.99 3.996h-28.02a4 4 0 0 1-3.99-3.996zm0-20.016c0-2.2 1.786-3.984 3.99-3.984h28.02c2.204 0 3.99 1.8 3.99 3.984v14.032c0 2.2-1.786 3.984-3.99 3.984h-28.02c-2.204 0-3.99-1.8-3.99-3.984zm4 .016h28v6h-28zm0 11.01c0-.56.428-1.01 1.01-1.01h1.98c.56 0 1.01.428 1.01 1.01v1.98a.994.994 0 0 1-1.01 1.01h-1.98a.994.994 0 0 1-1.01-1.01zm0 14c0-.56.428-1.01 1.01-1.01h1.98c.56 0 1.01.428 1.01 1.01v1.98a.994.994 0 0 1-1.01 1.01h-1.98a.994.994 0 0 1-1.01-1.01z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.7 KiB