feat: add forms feature set
This commit is contained in:
1
packages/backend/src/apps/forms/assets/favicon.svg
Normal file
1
packages/backend/src/apps/forms/assets/favicon.svg
Normal 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 |
16
packages/backend/src/apps/forms/common/add-auth-header.js
Normal file
16
packages/backend/src/apps/forms/common/add-auth-header.js
Normal 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;
|
||||
13
packages/backend/src/apps/forms/common/set-base-url.js
Normal file
13
packages/backend/src/apps/forms/common/set-base-url.js
Normal 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;
|
||||
4
packages/backend/src/apps/forms/dynamic-data/index.js
Normal file
4
packages/backend/src/apps/forms/dynamic-data/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import listCollections from './list-collections/index.js';
|
||||
import listDatabases from './list-databases/index.js';
|
||||
|
||||
export default [listCollections, listDatabases];
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
14
packages/backend/src/apps/forms/index.js
Normal file
14
packages/backend/src/apps/forms/index.js
Normal 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,
|
||||
});
|
||||
@@ -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: '',
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
3
packages/backend/src/apps/forms/triggers/index.js
Normal file
3
packages/backend/src/apps/forms/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import formSubmittion from './form-submission/index.js';
|
||||
|
||||
export default [formSubmittion];
|
||||
Reference in New Issue
Block a user