Compare commits

..

3 Commits

Author SHA1 Message Date
Rıdvan Akca
686c834748 feat(firebase): add find cloud firestore document action 2024-04-17 16:15:47 +02:00
Rıdvan Akca
d6b9410932 feat(firebase): add create cloud firestore document action 2024-04-17 16:15:01 +02:00
Rıdvan Akca
dff1c5e387 feat(firebase): add new documents within firestore collection trigger 2024-04-17 16:14:21 +02:00
13 changed files with 367 additions and 1 deletions

View File

@@ -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,
});
},
});

View File

@@ -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,
});
},
});

View File

@@ -0,0 +1,4 @@
import createCloudFirestoreDocument from './create-cloud-firestore-document/index.js';
import findCloudFirestoreDocument from './find-cloud-firestore-document/index.js';
export default [createCloudFirestoreDocument, findCloudFirestoreDocument];

View File

@@ -0,0 +1,3 @@
import listFirestoreCollections from './list-firestore-collections/index.js';
export default [listFirestoreCollections];

View File

@@ -0,0 +1,32 @@
export default {
name: 'List firestore collections',
key: 'listFirestoreCollections',
async run($) {
const firestoreCollections = {
data: [],
};
const projectId = $.auth.data.projectId;
const { data } = await $.http.post(
`/v1/projects/${projectId}/databases/(default)/documents:listCollectionIds`,
null,
{
additionalProperties: {
setFirestoreBaseUrl: true,
},
}
);
if (data.collectionIds?.length) {
for (const collectionId of data.collectionIds) {
firestoreCollections.data.push({
value: collectionId,
name: collectionId,
});
}
}
return firestoreCollections;
},
};

View File

@@ -2,6 +2,9 @@ import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js'; import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js'; import auth from './auth/index.js';
import setBaseUrl from './common/set-base-url.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({ export default defineApp({
name: 'Firebase', name: 'Firebase',
@@ -14,4 +17,7 @@ export default defineApp({
supportsConnections: true, supportsConnections: true,
beforeRequest: [setBaseUrl, addAuthHeader], beforeRequest: [setBaseUrl, addAuthHeader],
auth, auth,
triggers,
dynamicData,
actions,
}); });

View File

@@ -0,0 +1,3 @@
import newDocumentsWithinFirestoreCollection from './new-documents-within-firestore-collection/index.js';
export default [newDocumentsWithinFirestoreCollection];

View File

@@ -0,0 +1,66 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'New documents within a firestore collection',
key: 'newDocumentsWithinFirestoreCollection',
pollInterval: 15,
description:
'Triggers when a new document is added 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',
},
],
},
},
],
async run($) {
const projectId = $.auth.data.projectId;
const collectionId = $.step.parameters.collectionId;
const params = {
pageSize: 100,
pageToken: undefined,
};
do {
const { data } = await $.http.get(
`/v1/projects/${projectId}/databases/(default)/documents/${collectionId}`,
{
params,
additionalProperties: {
setFirestoreBaseUrl: true,
},
}
);
params.pageToken = data.nextPageToken;
if (!data?.documents?.length) {
return;
}
for (const document of data.documents) {
const nameParts = document.name.split('/');
const id = nameParts[nameParts.length - 1];
$.pushTriggerItem({
raw: document,
meta: {
internalId: id,
},
});
}
} while (params.pageToken);
},
});

View File

@@ -99,7 +99,11 @@ export default defineConfig({
text: 'Firebase', text: 'Firebase',
collapsible: true, collapsible: true,
collapsed: true, collapsed: true,
items: [{ text: 'Connection', link: '/apps/firebase/connection' }], items: [
{ text: 'Actions', link: '/apps/firebase/actions' },
{ text: 'Triggers', link: '/apps/firebase/triggers' },
{ text: 'Connection', link: '/apps/firebase/connection' },
],
}, },
{ {
text: 'Flickr', text: 'Flickr',

View File

@@ -0,0 +1,14 @@
---
favicon: /favicons/firebase.svg
items:
- name: Create Cloud Firestore document
desc: Creates a new document within a Cloud Firestore collection.
- name: Find Cloud Firestore document
desc: Finds a document within a collection.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/firebase.svg
items:
- name: New documents within a firestore collection
desc: Triggers when a new document is added within a Cloud Firestore collection.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -9,6 +9,7 @@ The following integrations are currently supported by Automatisch.
- [Discord](/apps/discord/actions) - [Discord](/apps/discord/actions)
- [Dropbox](/apps/dropbox/actions) - [Dropbox](/apps/dropbox/actions)
- [Filter](/apps/filter/actions) - [Filter](/apps/filter/actions)
- [Firebase](/apps/firebase/triggers)
- [Flickr](/apps/flickr/triggers) - [Flickr](/apps/flickr/triggers)
- [Formatter](/apps/formatter/actions) - [Formatter](/apps/formatter/actions)
- [Ghost](/apps/ghost/triggers) - [Ghost](/apps/ghost/triggers)

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 21 KiB