feat: add forms feature set

This commit is contained in:
Ali BARIN
2025-04-17 20:09:00 +00:00
committed by Faruk AYDIN
parent 2a89f92dc7
commit 510310e43c
28 changed files with 511 additions and 3 deletions

View File

@@ -0,0 +1 @@
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#000000" d="M17 20v-9h-2V4h7l-2 5h2zm-2-7v7H4c-1.1 0-2-.9-2-2v-3c0-1.1.9-2 2-2zm-8.75 2.75h-1.5v1.5h1.5zM13 4v7H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2zM6.25 6.75h-1.5v1.5h1.5z"></path></svg>

After

Width:  |  Height:  |  Size: 324 B

View File

@@ -0,0 +1,16 @@
const addAuthHeader = ($, requestConfig) => {
requestConfig.headers['Content-Type'] = 'application/json';
if ($.auth.data?.apiKey && $.auth.data?.projectId) {
requestConfig.headers['X-Appwrite-Project'] = $.auth.data.projectId;
requestConfig.headers['X-Appwrite-Key'] = $.auth.data.apiKey;
}
if ($.auth.data?.host) {
requestConfig.headers['Host'] = $.auth.data.host;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,13 @@
const setBaseUrl = ($, requestConfig) => {
const instanceUrl = $.auth.data.instanceUrl;
if (instanceUrl) {
requestConfig.baseURL = instanceUrl;
} else if ($.app.apiBaseUrl) {
requestConfig.baseURL = $.app.apiBaseUrl;
}
return requestConfig;
};
export default setBaseUrl;

View File

@@ -0,0 +1,4 @@
import listCollections from './list-collections/index.js';
import listDatabases from './list-databases/index.js';
export default [listCollections, listDatabases];

View File

@@ -0,0 +1,44 @@
export default {
name: 'List collections',
key: 'listCollections',
async run($) {
const collections = {
data: [],
};
const databaseId = $.step.parameters.databaseId;
if (!databaseId) {
return collections;
}
const params = {
queries: [
JSON.stringify({
method: 'orderAsc',
attribute: 'name',
}),
JSON.stringify({
method: 'limit',
values: [100],
}),
],
};
const { data } = await $.http.get(
`/v1/databases/${databaseId}/collections`,
{ params }
);
if (data?.collections) {
for (const collection of data.collections) {
collections.data.push({
value: collection.$id,
name: collection.name,
});
}
}
return collections;
},
};

View File

@@ -0,0 +1,36 @@
export default {
name: 'List databases',
key: 'listDatabases',
async run($) {
const databases = {
data: [],
};
const params = {
queries: [
JSON.stringify({
method: 'orderAsc',
attribute: 'name',
}),
JSON.stringify({
method: 'limit',
values: [100],
}),
],
};
const { data } = await $.http.get('/v1/databases', { params });
if (data?.databases) {
for (const database of data.databases) {
databases.data.push({
value: database.$id,
name: database.name,
});
}
}
return databases;
},
};

View File

@@ -0,0 +1,14 @@
import defineApp from '../../helpers/define-app.js';
import triggers from './triggers/index.js';
export default defineApp({
name: 'Forms',
key: 'forms',
iconUrl: '{BASE_URL}/apps/forms/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/forms/connection',
supportsConnections: false,
baseUrl: '',
apiBaseUrl: '',
primaryColor: '#0059F7',
triggers,
});

View File

@@ -0,0 +1,64 @@
import Crypto from 'crypto';
import isEmpty from 'lodash/isEmpty.js';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'New form submission',
key: 'newFormSubmission',
pollInterval: 15,
type: 'webhook',
description: 'Triggers when a new form is submitted.',
arguments: [
{
label: 'Fields',
key: 'fields',
type: 'dynamic',
required: false,
description: 'Add or remove fields as needed',
value: [],
fields: [
{
label: 'Field name',
key: 'fieldName',
type: 'string',
required: true,
description: 'Displayed name to the user',
variables: true,
},
{
label: 'Type',
key: 'fieldType',
type: 'dropdown',
required: true,
description: 'Field type',
variables: true,
options: [{ label: 'String', value: 'string' }],
},
],
},
],
async run($) {
const dataItem = {
raw: $.request.body,
meta: {
internalId: Crypto.randomUUID(),
},
};
$.pushTriggerItem(dataItem);
},
async testRun($) {
const lastExecutionStep = await $.getLastExecutionStep();
if (!isEmpty(lastExecutionStep?.dataOut)) {
$.pushTriggerItem({
raw: lastExecutionStep.dataOut,
meta: {
internalId: '',
},
});
}
},
});

View File

@@ -0,0 +1,3 @@
import formSubmittion from './form-submission/index.js';
export default [formSubmittion];