Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
094c6c0c27 | ||
![]() |
1f520ed590 | ||
![]() |
686c834748 | ||
![]() |
d6b9410932 |
@@ -0,0 +1,116 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create Cloud Firestore document',
|
||||
key: 'createCloudFirestoreDocument',
|
||||
description: 'Creates a new document within a Cloud Firestore collection.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Collection',
|
||||
key: 'collectionId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listFirestoreCollections',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Convert Numerics',
|
||||
key: 'convertNumerics',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
"If any value represents a valid numerical value, whether it's an integer or a floating-point number, this field directs the database to store it as a numeric data type instead of a string.",
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Yes', value: true },
|
||||
{ label: 'No', value: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Document ID',
|
||||
key: 'documentId',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'The document ID to use for this document. If not specified, an ID will be assigned.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Document Data',
|
||||
key: 'documentData',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Key',
|
||||
key: 'key',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const projectId = $.auth.data.projectId;
|
||||
const { collectionId, documentId, documentData, convertNumerics } =
|
||||
$.step.parameters;
|
||||
|
||||
const documentDataObject = documentData.reduce((result, entry) => {
|
||||
const key = entry.key?.toLowerCase();
|
||||
const value = entry.value;
|
||||
const isNumber = !isNaN(parseFloat(value));
|
||||
|
||||
if (key && value) {
|
||||
const formattedValue =
|
||||
convertNumerics && isNumber
|
||||
? { integerValue: parseFloat(value) }
|
||||
: { stringValue: value };
|
||||
|
||||
return {
|
||||
...result,
|
||||
[key]: formattedValue,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
const body = {
|
||||
fields: documentDataObject,
|
||||
};
|
||||
|
||||
const { data } = await $.http.post(
|
||||
`/v1/projects/${projectId}/databases/(default)/documents/${collectionId}?documentId=${documentId}`,
|
||||
body,
|
||||
{
|
||||
additionalProperties: {
|
||||
setFirestoreBaseUrl: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
@@ -0,0 +1,100 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create Firebase Realtime Database Record',
|
||||
key: 'createFirebaseRealtimeDatabaseRecord',
|
||||
description: 'Creates a child object within your Firebase Realtime Database.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Path',
|
||||
key: 'path',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
"Indicate the path to the key of the object where the child objects to be queried are located, for example, 'foo/bar/here'.",
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Convert Numerics',
|
||||
key: 'convertNumerics',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
"If any value represents a valid numerical value, whether it's an integer or a floating-point number, this field directs the database to store it as a numeric data type instead of a string.",
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Yes', value: true },
|
||||
{ label: 'No', value: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'New ID',
|
||||
key: 'newId',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'The key to use for this object, or leave it blank for Firebase to create one automatically.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Data',
|
||||
key: 'childData',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Key',
|
||||
key: 'key',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
let path = $.step.parameters.path;
|
||||
const { convertNumerics, newId, childData } = $.step.parameters;
|
||||
|
||||
if (newId) {
|
||||
path = `${path}/${newId}.json`;
|
||||
} else {
|
||||
path = `${path}.json`;
|
||||
}
|
||||
|
||||
const formattedChildObjectData = childData.reduce((result, entry) => {
|
||||
const key = entry?.key;
|
||||
const value = entry?.value;
|
||||
const isNumber = !isNaN(parseFloat(value));
|
||||
|
||||
if (isNumber && convertNumerics) {
|
||||
result[key] = parseFloat(value);
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
const body = formattedChildObjectData;
|
||||
|
||||
const { data } = await $.http.post(path, body, {
|
||||
additionalProperties: {
|
||||
setFirestoreBaseUrl: false,
|
||||
},
|
||||
});
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
@@ -0,0 +1,53 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find Cloud Firestore document',
|
||||
key: 'findCloudFirestoreDocument',
|
||||
description: 'Finds a document within a collection.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Collection',
|
||||
key: 'collectionId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listFirestoreCollections',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Document ID',
|
||||
key: 'documentId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const projectId = $.auth.data.projectId;
|
||||
const { collectionId, documentId } = $.step.parameters;
|
||||
|
||||
const { data } = await $.http.get(
|
||||
`/v1/projects/${projectId}/databases/(default)/documents/${collectionId}/${documentId}`,
|
||||
{
|
||||
additionalProperties: {
|
||||
setFirestoreBaseUrl: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
9
packages/backend/src/apps/firebase/actions/index.js
Normal file
9
packages/backend/src/apps/firebase/actions/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import createCloudFirestoreDocument from './create-cloud-firestore-document/index.js';
|
||||
import createFirebaseRealtimeDatabaseRecord from './create-firebase-realtime-database-record/index.js';
|
||||
import findCloudFirestoreDocument from './find-cloud-firestore-document/index.js';
|
||||
|
||||
export default [
|
||||
createCloudFirestoreDocument,
|
||||
createFirebaseRealtimeDatabaseRecord,
|
||||
findCloudFirestoreDocument,
|
||||
];
|
@@ -4,6 +4,7 @@ import auth from './auth/index.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Firebase',
|
||||
@@ -18,4 +19,5 @@ export default defineApp({
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
actions,
|
||||
});
|
||||
|
@@ -1,3 +1,7 @@
|
||||
import newChildObjectInFirebaseRealtimeDatabase from './new-child-object-in-a-firebase-realtime-database/index.js';
|
||||
import newDocumentsWithinFirestoreCollection from './new-documents-within-firestore-collection/index.js';
|
||||
|
||||
export default [newDocumentsWithinFirestoreCollection];
|
||||
export default [
|
||||
newChildObjectInFirebaseRealtimeDatabase,
|
||||
newDocumentsWithinFirestoreCollection,
|
||||
];
|
||||
|
@@ -0,0 +1,75 @@
|
||||
import Crypto from 'crypto';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New child object in a firebase realtime database',
|
||||
key: 'newChildObjectInFirebaseRealtimeDatabase',
|
||||
pollInterval: 15,
|
||||
description:
|
||||
'Triggers when a new child object is generated within a specific path.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Path',
|
||||
key: 'path',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
"Indicate the path to the key of the object where the child objects to be queried are located, for example, 'foo/bar/here.json'.",
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Order',
|
||||
key: 'order',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'The key or path of the child that should be utilized for comparing objects/records. If unspecified, the order of $key is used.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Location of newest objects',
|
||||
key: 'locationOfNewestObjects',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
'Specifies whether the new 100 records are positioned at the "top" or the "bottom" of the ordering. If left unspecified, the assumption is that the bottom/last result represents the "newest objects" (limitToLast).',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Top of results', value: 'limitToFirst' },
|
||||
{ label: 'Bottom of results', value: 'limitToLast' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const { path, order, locationOfNewestObjects } = $.step.parameters;
|
||||
|
||||
const params = {};
|
||||
|
||||
if (order) {
|
||||
params.orderBy = `"${order}"`;
|
||||
}
|
||||
|
||||
if (locationOfNewestObjects) {
|
||||
params[`${locationOfNewestObjects}`] = 100;
|
||||
}
|
||||
|
||||
const { data } = await $.http.get(path, {
|
||||
params,
|
||||
additionalProperties: {
|
||||
setFirestoreBaseUrl: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.pushTriggerItem({
|
||||
raw: data,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
@@ -100,6 +100,7 @@ export default defineConfig({
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Actions', link: '/apps/firebase/actions' },
|
||||
{ text: 'Triggers', link: '/apps/firebase/triggers' },
|
||||
{ text: 'Connection', link: '/apps/firebase/connection' },
|
||||
],
|
||||
|
16
packages/docs/pages/apps/firebase/actions.md
Normal file
16
packages/docs/pages/apps/firebase/actions.md
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
favicon: /favicons/firebase.svg
|
||||
items:
|
||||
- name: Create Cloud Firestore document
|
||||
desc: Creates a new document within a Cloud Firestore collection.
|
||||
- name: Create Firebase Realtime Database Record
|
||||
desc: Creates a child object within your Firebase Realtime Database.
|
||||
- name: Find Cloud Firestore document
|
||||
desc: Finds a document within a collection.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -1,6 +1,8 @@
|
||||
---
|
||||
favicon: /favicons/firebase.svg
|
||||
items:
|
||||
- name: New child object in a firebase realtime database
|
||||
desc: Triggers when a new child object is generated within a specific path.
|
||||
- name: New documents within a firestore collection
|
||||
desc: Triggers when a new document is added within a Cloud Firestore collection.
|
||||
---
|
||||
|
Reference in New Issue
Block a user