feat: Convert all app files to JS
This commit is contained in:
3
packages/backend/src/apps/azure-openai/actions/index.js
Normal file
3
packages/backend/src/apps/azure-openai/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import sendPrompt from './send-prompt/index.js';
|
||||||
|
|
||||||
|
export default [sendPrompt];
|
@@ -1,3 +0,0 @@
|
|||||||
import sendPrompt from './send-prompt';
|
|
||||||
|
|
||||||
export default [sendPrompt];
|
|
@@ -0,0 +1,97 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
const castFloatOrUndefined = (value) => {
|
||||||
|
return value === '' ? undefined : parseFloat(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Send prompt',
|
||||||
|
key: 'sendPrompt',
|
||||||
|
description: 'Creates a completion for the provided prompt and parameters.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Prompt',
|
||||||
|
key: 'prompt',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description: 'The text to analyze.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Temperature',
|
||||||
|
key: 'temperature',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'What sampling temperature to use, between 0 and 2. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. We generally recommend altering this or Top P but not both.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Maximum tokens',
|
||||||
|
key: 'maxTokens',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'The maximum number of tokens to generate in the completion.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Stop Sequence',
|
||||||
|
key: 'stopSequence',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'Single stop sequence where the API will stop generating further tokens. The returned text will not contain the stop sequence.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Top P',
|
||||||
|
key: 'topP',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description:
|
||||||
|
'An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Frequency Penalty',
|
||||||
|
key: 'frequencyPenalty',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description: `Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Presence Penalty',
|
||||||
|
key: 'presencePenalty',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
description: `Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const payload = {
|
||||||
|
model: $.step.parameters.model,
|
||||||
|
prompt: $.step.parameters.prompt,
|
||||||
|
temperature: castFloatOrUndefined($.step.parameters.temperature),
|
||||||
|
max_tokens: castFloatOrUndefined($.step.parameters.maxTokens),
|
||||||
|
stop: $.step.parameters.stopSequence || null,
|
||||||
|
top_p: castFloatOrUndefined($.step.parameters.topP),
|
||||||
|
frequency_penalty: castFloatOrUndefined(
|
||||||
|
$.step.parameters.frequencyPenalty
|
||||||
|
),
|
||||||
|
presence_penalty: castFloatOrUndefined($.step.parameters.presencePenalty),
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.post(
|
||||||
|
`/deployments/${$.auth.data.deploymentId}/completions`,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,87 +0,0 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
|
||||||
|
|
||||||
const castFloatOrUndefined = (value: string | null) => {
|
|
||||||
return value === '' ? undefined : parseFloat(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineAction({
|
|
||||||
name: 'Send prompt',
|
|
||||||
key: 'sendPrompt',
|
|
||||||
description: 'Creates a completion for the provided prompt and parameters.',
|
|
||||||
arguments: [
|
|
||||||
{
|
|
||||||
label: 'Prompt',
|
|
||||||
key: 'prompt',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: true,
|
|
||||||
variables: true,
|
|
||||||
description: 'The text to analyze.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Temperature',
|
|
||||||
key: 'temperature',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: 'What sampling temperature to use, between 0 and 2. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. We generally recommend altering this or Top P but not both.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Maximum tokens',
|
|
||||||
key: 'maxTokens',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: 'The maximum number of tokens to generate in the completion.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Stop Sequence',
|
|
||||||
key: 'stopSequence',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: 'Single stop sequence where the API will stop generating further tokens. The returned text will not contain the stop sequence.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Top P',
|
|
||||||
key: 'topP',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: 'An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Frequency Penalty',
|
|
||||||
key: 'frequencyPenalty',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: `Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Presence Penalty',
|
|
||||||
key: 'presencePenalty',
|
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
variables: true,
|
|
||||||
description: `Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.`
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
async run($) {
|
|
||||||
const payload = {
|
|
||||||
model: $.step.parameters.model as string,
|
|
||||||
prompt: $.step.parameters.prompt as string,
|
|
||||||
temperature: castFloatOrUndefined($.step.parameters.temperature as string),
|
|
||||||
max_tokens: castFloatOrUndefined($.step.parameters.maxTokens as string),
|
|
||||||
stop: ($.step.parameters.stopSequence as string || null),
|
|
||||||
top_p: castFloatOrUndefined($.step.parameters.topP as string),
|
|
||||||
frequency_penalty: castFloatOrUndefined($.step.parameters.frequencyPenalty as string),
|
|
||||||
presence_penalty: castFloatOrUndefined($.step.parameters.presencePenalty as string),
|
|
||||||
};
|
|
||||||
const { data } = await $.http.post(`/deployments/${$.auth.data.deploymentId}/completions`, payload);
|
|
||||||
|
|
||||||
$.setActionItem({
|
|
||||||
raw: data,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
@@ -1,12 +1,12 @@
|
|||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'screenName',
|
key: 'screenName',
|
||||||
label: 'Screen Name',
|
label: 'Screen Name',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -18,7 +18,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'yourResourceName',
|
key: 'yourResourceName',
|
||||||
label: 'Your Resource Name',
|
label: 'Your Resource Name',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -30,7 +30,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'deploymentId',
|
key: 'deploymentId',
|
||||||
label: 'Deployment ID',
|
label: 'Deployment ID',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -42,7 +42,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'apiKey',
|
key: 'apiKey',
|
||||||
label: 'API Key',
|
label: 'API Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -0,0 +1,6 @@
|
|||||||
|
const isStillVerified = async ($) => {
|
||||||
|
await $.http.get('/fine_tuning/jobs');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -1,8 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
await $.http.get('/fine_tuning/jobs');
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
@@ -0,0 +1,5 @@
|
|||||||
|
const verifyCredentials = async ($) => {
|
||||||
|
await $.http.get('/fine_tuning/jobs');
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyCredentials;
|
@@ -1,7 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
|
||||||
await $.http.get('/fine_tuning/jobs');
|
|
||||||
};
|
|
||||||
|
|
||||||
export default verifyCredentials;
|
|
@@ -0,0 +1,13 @@
|
|||||||
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
if ($.auth.data?.apiKey) {
|
||||||
|
requestConfig.headers['api-key'] = $.auth.data.apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
requestConfig.params = {
|
||||||
|
'api-version': '2023-10-01-preview',
|
||||||
|
};
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
@@ -1,15 +0,0 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
if ($.auth.data?.apiKey) {
|
|
||||||
requestConfig.headers['api-key'] = $.auth.data.apiKey as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
requestConfig.params = {
|
|
||||||
'api-version': '2023-10-01-preview'
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default addAuthHeader;
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
const setBaseUrl = ($, requestConfig) => {
|
||||||
|
const yourResourceName = $.auth.data.yourResourceName;
|
||||||
|
|
||||||
|
if (yourResourceName) {
|
||||||
|
requestConfig.baseURL = `https://${yourResourceName}.openai.azure.com/openai`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default setBaseUrl;
|
@@ -1,13 +0,0 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
|
||||||
|
|
||||||
const setBaseUrl: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
const yourResourceName = $.auth.data.yourResourceName as string;
|
|
||||||
|
|
||||||
if (yourResourceName) {
|
|
||||||
requestConfig.baseURL = `https://${yourResourceName}.openai.azure.com/openai`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default setBaseUrl;
|
|
@@ -1,8 +1,8 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import setBaseUrl from './common/set-base-url';
|
import setBaseUrl from './common/set-base-url.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Azure OpenAI',
|
name: 'Azure OpenAI',
|
@@ -1,4 +1,4 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Add Template',
|
name: 'Add Template',
|
||||||
@@ -9,7 +9,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Templete Data',
|
label: 'Templete Data',
|
||||||
key: 'templateData',
|
key: 'templateData',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
variables: true,
|
variables: true,
|
||||||
description: 'The content of your new Template in XML/HTML format.',
|
description: 'The content of your new Template in XML/HTML format.',
|
||||||
@@ -17,7 +17,7 @@ export default defineAction({
|
|||||||
],
|
],
|
||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
const templateData = $.step.parameters.templateData as string;
|
const templateData = $.step.parameters.templateData;
|
||||||
|
|
||||||
const base64Data = Buffer.from(templateData).toString('base64');
|
const base64Data = Buffer.from(templateData).toString('base64');
|
||||||
const dataURI = `data:application/xml;base64,${base64Data}`;
|
const dataURI = `data:application/xml;base64,${base64Data}`;
|
3
packages/backend/src/apps/carbone/actions/index.js
Normal file
3
packages/backend/src/apps/carbone/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import addTemplate from './add-template/index.js';
|
||||||
|
|
||||||
|
export default [addTemplate];
|
@@ -1,3 +0,0 @@
|
|||||||
import addTemplate from './add-template';
|
|
||||||
|
|
||||||
export default [addTemplate];
|
|
@@ -1,12 +1,12 @@
|
|||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'screenName',
|
key: 'screenName',
|
||||||
label: 'Screen Name',
|
label: 'Screen Name',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -18,7 +18,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'apiKey',
|
key: 'apiKey',
|
||||||
label: 'API Key',
|
label: 'API Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -0,0 +1,8 @@
|
|||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
await verifyCredentials($);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import verifyCredentials from './verify-credentials';
|
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
await verifyCredentials($);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
@@ -1,6 +1,4 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
const verifyCredentials = async ($) => {
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
|
||||||
await $.http.get('/templates');
|
await $.http.get('/templates');
|
||||||
|
|
||||||
await $.auth.set({
|
await $.auth.set({
|
@@ -1,6 +1,4 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
const addAuthHeader = ($) => {
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
if ($.auth.data?.apiKey) {
|
if ($.auth.data?.apiKey) {
|
||||||
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
|
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
|
||||||
requestConfig.headers['carbone-version'] = '4';
|
requestConfig.headers['carbone-version'] = '4';
|
@@ -1,7 +1,7 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Carbone',
|
name: 'Carbone',
|
3
packages/backend/src/apps/deepl/actions/index.js
Normal file
3
packages/backend/src/apps/deepl/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import translateText from './translate-text/index.js';
|
||||||
|
|
||||||
|
export default [translateText];
|
@@ -1,3 +0,0 @@
|
|||||||
import translateText from './translate-text';
|
|
||||||
|
|
||||||
export default [translateText];
|
|
@@ -1,5 +1,5 @@
|
|||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Translate text',
|
name: 'Translate text',
|
||||||
@@ -9,7 +9,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Text',
|
label: 'Text',
|
||||||
key: 'text',
|
key: 'text',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Text to be translated.',
|
description: 'Text to be translated.',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -17,7 +17,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Target Language',
|
label: 'Target Language',
|
||||||
key: 'targetLanguage',
|
key: 'targetLanguage',
|
||||||
type: 'dropdown' as const,
|
type: 'dropdown',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Language to translate the text to.',
|
description: 'Language to translate the text to.',
|
||||||
variables: true,
|
variables: true,
|
@@ -1,12 +1,12 @@
|
|||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'screenName',
|
key: 'screenName',
|
||||||
label: 'Screen Name',
|
label: 'Screen Name',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -18,7 +18,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'authenticationKey',
|
key: 'authenticationKey',
|
||||||
label: 'Authentication Key',
|
label: 'Authentication Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -0,0 +1,8 @@
|
|||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
await verifyCredentials($);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import verifyCredentials from './verify-credentials';
|
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
await verifyCredentials($);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
@@ -1,6 +1,4 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
const verifyCredentials = async ($) => {
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
|
||||||
await $.http.get('/v2/usage');
|
await $.http.get('/v2/usage');
|
||||||
|
|
||||||
await $.auth.set({
|
await $.auth.set({
|
@@ -1,6 +1,4 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
if ($.auth.data?.authenticationKey) {
|
if ($.auth.data?.authenticationKey) {
|
||||||
const authorizationHeader = `DeepL-Auth-Key ${$.auth.data.authenticationKey}`;
|
const authorizationHeader = `DeepL-Auth-Key ${$.auth.data.authenticationKey}`;
|
||||||
requestConfig.headers.Authorization = authorizationHeader;
|
requestConfig.headers.Authorization = authorizationHeader;
|
@@ -1,7 +1,7 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'DeepL',
|
name: 'DeepL',
|
@@ -1,4 +1,4 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Delay for',
|
name: 'Delay for',
|
||||||
@@ -9,7 +9,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Delay for unit',
|
label: 'Delay for unit',
|
||||||
key: 'delayForUnit',
|
key: 'delayForUnit',
|
||||||
type: 'dropdown' as const,
|
type: 'dropdown',
|
||||||
required: true,
|
required: true,
|
||||||
value: null,
|
value: null,
|
||||||
description: 'Delay for unit, e.g. minutes, hours, days, weeks.',
|
description: 'Delay for unit, e.g. minutes, hours, days, weeks.',
|
||||||
@@ -36,7 +36,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Delay for value',
|
label: 'Delay for value',
|
||||||
key: 'delayForValue',
|
key: 'delayForValue',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Delay for value, use a number, e.g. 1, 2, 3.',
|
description: 'Delay for value, use a number, e.g. 1, 2, 3.',
|
||||||
variables: true,
|
variables: true,
|
@@ -1,4 +1,4 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Delay until',
|
name: 'Delay until',
|
||||||
@@ -9,7 +9,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Delay until (Date)',
|
label: 'Delay until (Date)',
|
||||||
key: 'delayUntil',
|
key: 'delayUntil',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Delay until the date. E.g. 2022-12-18',
|
description: 'Delay until the date. E.g. 2022-12-18',
|
||||||
variables: true,
|
variables: true,
|
4
packages/backend/src/apps/delay/actions/index.js
Normal file
4
packages/backend/src/apps/delay/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import delayFor from './delay-for/index.js';
|
||||||
|
import delayUntil from './delay-until/index.js';
|
||||||
|
|
||||||
|
export default [delayFor, delayUntil];
|
@@ -1,4 +0,0 @@
|
|||||||
import delayFor from './delay-for';
|
|
||||||
import delayUntil from './delay-until';
|
|
||||||
|
|
||||||
export default [delayFor, delayUntil];
|
|
@@ -1,5 +1,5 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Delay',
|
name: 'Delay',
|
@@ -1,4 +1,4 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Create a scheduled event',
|
name: 'Create a scheduled event',
|
||||||
@@ -8,13 +8,13 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Type',
|
label: 'Type',
|
||||||
key: 'entityType',
|
key: 'entityType',
|
||||||
type: 'dropdown' as const,
|
type: 'dropdown',
|
||||||
required: true,
|
required: true,
|
||||||
variables: true,
|
variables: true,
|
||||||
options: [
|
options: [
|
||||||
{ label: 'Stage channel', value: 1 },
|
{ label: 'Stage channel', value: 1 },
|
||||||
{ label: 'Voice channel', value: 2 },
|
{ label: 'Voice channel', value: 2 },
|
||||||
{ label: 'External', value: 3 }
|
{ label: 'External', value: 3 },
|
||||||
],
|
],
|
||||||
additionalFields: {
|
additionalFields: {
|
||||||
type: 'query',
|
type: 'query',
|
||||||
@@ -34,61 +34,47 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Description',
|
label: 'Description',
|
||||||
key: 'description',
|
key: 'description',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Image',
|
label: 'Image',
|
||||||
key: 'image',
|
key: 'image',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
description: 'Image as DataURI scheme [data:image/<jpeg/png/gif>;base64,BASE64_ENCODED_<JPEG/PNG/GIF>_IMAGE_DATA]',
|
description:
|
||||||
|
'Image as DataURI scheme [data:image/<jpeg/png/gif>;base64,BASE64_ENCODED_<JPEG/PNG/GIF>_IMAGE_DATA]',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
type entity_metadata = {
|
const data = {
|
||||||
location: string
|
channel_id: $.step.parameters.channel_id,
|
||||||
}
|
name: $.step.parameters.name,
|
||||||
|
|
||||||
type guild_event = {
|
|
||||||
channel_id: number,
|
|
||||||
name: string,
|
|
||||||
privacy_level: number,
|
|
||||||
scheduled_start_time: string,
|
|
||||||
scheduled_end_time?: string,
|
|
||||||
description?: string,
|
|
||||||
entity_type?: number,
|
|
||||||
entity_metadata?: entity_metadata,
|
|
||||||
image?: string, //data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const data: guild_event = {
|
|
||||||
channel_id: $.step.parameters.channel_id as number,
|
|
||||||
name: $.step.parameters.name as string,
|
|
||||||
privacy_level: 2,
|
privacy_level: 2,
|
||||||
scheduled_start_time: $.step.parameters.scheduledStartTime as string,
|
scheduled_start_time: $.step.parameters.scheduledStartTime,
|
||||||
scheduled_end_time: $.step.parameters.scheduledEndTime as string,
|
scheduled_end_time: $.step.parameters.scheduledEndTime,
|
||||||
description: $.step.parameters.description as string,
|
description: $.step.parameters.description,
|
||||||
entity_type: $.step.parameters.entityType as number,
|
entity_type: $.step.parameters.entityType,
|
||||||
image: $.step.parameters.image as string,
|
image: $.step.parameters.image,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isExternal = $.step.parameters.entityType === 3;
|
const isExternal = $.step.parameters.entityType === 3;
|
||||||
|
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
data.entity_metadata = {
|
data.entity_metadata = {
|
||||||
location: $.step.parameters.location as string,
|
location: $.step.parameters.location,
|
||||||
};
|
};
|
||||||
|
|
||||||
data.channel_id = null;
|
data.channel_id = null;
|
||||||
}
|
}
|
||||||
|
|
4
packages/backend/src/apps/discord/actions/index.js
Normal file
4
packages/backend/src/apps/discord/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import sendMessageToChannel from './send-message-to-channel/index.js';
|
||||||
|
import createScheduledEvent from './create-scheduled-event/index.js';
|
||||||
|
|
||||||
|
export default [sendMessageToChannel, createScheduledEvent];
|
@@ -1,4 +0,0 @@
|
|||||||
import sendMessageToChannel from './send-message-to-channel';
|
|
||||||
import createScheduledEvent from './create-scheduled-event';
|
|
||||||
|
|
||||||
export default [sendMessageToChannel, createScheduledEvent];
|
|
@@ -1,4 +1,4 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Send a message to channel',
|
name: 'Send a message to channel',
|
||||||
@@ -8,7 +8,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Channel',
|
label: 'Channel',
|
||||||
key: 'channel',
|
key: 'channel',
|
||||||
type: 'dropdown' as const,
|
type: 'dropdown',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Pick a channel to send the message to.',
|
description: 'Pick a channel to send the message to.',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -26,7 +26,7 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'Message text',
|
label: 'Message text',
|
||||||
key: 'message',
|
key: 'message',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The content of your new message.',
|
description: 'The content of your new message.',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -35,8 +35,9 @@ export default defineAction({
|
|||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
const data = {
|
const data = {
|
||||||
content: $.step.parameters.message as string,
|
content: $.step.parameters.message,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await $.http?.post(
|
const response = await $.http?.post(
|
||||||
`/channels/${$.step.parameters.channel}/messages`,
|
`/channels/${$.step.parameters.channel}/messages`,
|
||||||
data
|
data
|
@@ -1,15 +1,15 @@
|
|||||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
import scopes from '../common/scopes';
|
import scopes from '../common/scopes.js';
|
||||||
|
|
||||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
export default async function generateAuthUrl($) {
|
||||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
);
|
);
|
||||||
const callbackUrl = oauthRedirectUrlField.value as string;
|
|
||||||
|
const callbackUrl = oauthRedirectUrlField.value;
|
||||||
|
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
client_id: $.auth.data.consumerKey as string,
|
client_id: $.auth.data.consumerKey,
|
||||||
redirect_uri: callbackUrl,
|
redirect_uri: callbackUrl,
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
permissions: '2146958591',
|
permissions: '2146958591',
|
@@ -1,13 +1,13 @@
|
|||||||
import generateAuthUrl from './generate-auth-url';
|
import generateAuthUrl from './generate-auth-url.js';
|
||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'oAuthRedirectUrl',
|
key: 'oAuthRedirectUrl',
|
||||||
label: 'OAuth Redirect URL',
|
label: 'OAuth Redirect URL',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
value: '{WEB_APP_URL}/app/discord/connections/add',
|
value: '{WEB_APP_URL}/app/discord/connections/add',
|
||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'consumerKey',
|
key: 'consumerKey',
|
||||||
label: 'Consumer Key',
|
label: 'Consumer Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -32,7 +32,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'consumerSecret',
|
key: 'consumerSecret',
|
||||||
label: 'Consumer Secret',
|
label: 'Consumer Secret',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -44,7 +44,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'botToken',
|
key: 'botToken',
|
||||||
label: 'Bot token',
|
label: 'Bot token',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -0,0 +1,9 @@
|
|||||||
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
await getCurrentUser($);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -1,10 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import getCurrentUser from '../common/get-current-user';
|
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
await getCurrentUser($);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
@@ -1,22 +1,24 @@
|
|||||||
import { IGlobalVariable, IField } from '@automatisch/types';
|
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
import scopes from '../common/scopes';
|
import scopes from '../common/scopes.js';
|
||||||
import getCurrentUser from '../common/get-current-user';
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
const verifyCredentials = async ($) => {
|
||||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
);
|
);
|
||||||
const callbackUrl = oauthRedirectUrlField.value as string;
|
|
||||||
|
const callbackUrl = oauthRedirectUrlField.value;
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
client_id: $.auth.data.consumerKey as string,
|
client_id: $.auth.data.consumerKey,
|
||||||
redirect_uri: callbackUrl,
|
redirect_uri: callbackUrl,
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
scope: scopes.join(' '),
|
scope: scopes.join(' '),
|
||||||
client_secret: $.auth.data.consumerSecret as string,
|
client_secret: $.auth.data.consumerSecret,
|
||||||
code: $.auth.data.code as string,
|
code: $.auth.data.code,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: verifiedCredentials } = await $.http.post(
|
const { data: verifiedCredentials } = await $.http.post(
|
||||||
'/oauth2/token',
|
'/oauth2/token',
|
||||||
params.toString()
|
params.toString()
|
@@ -1,6 +1,4 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
const { tokenType, botToken } = $.auth.data;
|
const { tokenType, botToken } = $.auth.data;
|
||||||
if (tokenType && botToken) {
|
if (tokenType && botToken) {
|
||||||
requestConfig.headers.Authorization = `Bot ${botToken}`;
|
requestConfig.headers.Authorization = `Bot ${botToken}`;
|
@@ -1,6 +1,4 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
const getCurrentUser = async ($) => {
|
||||||
|
|
||||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
|
||||||
const response = await $.http.get('/users/@me');
|
const response = await $.http.get('/users/@me');
|
||||||
const currentUser = response.data;
|
const currentUser = response.data;
|
||||||
|
|
4
packages/backend/src/apps/discord/dynamic-data/index.js
Normal file
4
packages/backend/src/apps/discord/dynamic-data/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import listChannels from './list-channels/index.js';
|
||||||
|
import listVoiceChannels from './list-voice-channels/index.js';
|
||||||
|
|
||||||
|
export default [listChannels, listVoiceChannels];
|
@@ -1,4 +0,0 @@
|
|||||||
import listChannels from './list-channels';
|
|
||||||
import listVoiceChannels from './list-voice-channels';
|
|
||||||
|
|
||||||
export default [listChannels, listVoiceChannels];
|
|
@@ -1,14 +1,9 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'List channels',
|
name: 'List channels',
|
||||||
key: 'listChannels',
|
key: 'listChannels',
|
||||||
|
|
||||||
async run($: IGlobalVariable) {
|
async run($) {
|
||||||
const channels: {
|
const channels = {
|
||||||
data: IJSONObject[];
|
|
||||||
error: IJSONObject | null;
|
|
||||||
} = {
|
|
||||||
data: [],
|
data: [],
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
@@ -18,11 +13,11 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
channels.data = response.data
|
channels.data = response.data
|
||||||
.filter((channel: IJSONObject) => {
|
.filter((channel) => {
|
||||||
// filter in text channels and announcement channels only
|
// filter in text channels and announcement channels only
|
||||||
return channel.type === 0 || channel.type === 5;
|
return channel.type === 0 || channel.type === 5;
|
||||||
})
|
})
|
||||||
.map((channel: IJSONObject) => {
|
.map((channel) => {
|
||||||
return {
|
return {
|
||||||
value: channel.id,
|
value: channel.id,
|
||||||
name: channel.name,
|
name: channel.name,
|
@@ -1,14 +1,9 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'List voice channels',
|
name: 'List voice channels',
|
||||||
key: 'listVoiceChannels',
|
key: 'listVoiceChannels',
|
||||||
|
|
||||||
async run($: IGlobalVariable) {
|
async run($) {
|
||||||
const channels: {
|
const channels = {
|
||||||
data: IJSONObject[];
|
|
||||||
error: IJSONObject | null;
|
|
||||||
} = {
|
|
||||||
data: [],
|
data: [],
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
@@ -18,11 +13,11 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
channels.data = response.data
|
channels.data = response.data
|
||||||
.filter((channel: IJSONObject) => {
|
.filter((channel) => {
|
||||||
// filter in voice and stage channels only
|
// filter in voice and stage channels only
|
||||||
return channel.type === 2 || channel.type === 13;
|
return channel.type === 2 || channel.type === 13;
|
||||||
})
|
})
|
||||||
.map((channel: IJSONObject) => {
|
.map((channel) => {
|
||||||
return {
|
return {
|
||||||
value: channel.id,
|
value: channel.id,
|
||||||
name: channel.name,
|
name: channel.name,
|
@@ -1,3 +1,3 @@
|
|||||||
import listExternalScheduledEventFields from './list-external-scheduled-event-fields';
|
import listExternalScheduledEventFields from './list-external-scheduled-event-fields/index.js';
|
||||||
|
|
||||||
export default [listExternalScheduledEventFields];
|
export default [listExternalScheduledEventFields];
|
@@ -1,9 +1,8 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
export default {
|
export default {
|
||||||
name: 'List external scheduled event fields',
|
name: 'List external scheduled event fields',
|
||||||
key: 'listExternalScheduledEventFields',
|
key: 'listExternalScheduledEventFields',
|
||||||
|
|
||||||
async run($: IGlobalVariable) {
|
async run($) {
|
||||||
const isExternal = $.step.parameters.entityType === 3;
|
const isExternal = $.step.parameters.entityType === 3;
|
||||||
|
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
@@ -11,15 +10,16 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'Location',
|
label: 'Location',
|
||||||
key: 'location',
|
key: 'location',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
description:
|
||||||
|
'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Start-Time',
|
label: 'Start-Time',
|
||||||
key: 'scheduledStartTime',
|
key: 'scheduledStartTime',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The time the event will start [ISO8601]',
|
description: 'The time the event will start [ISO8601]',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -27,9 +27,10 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'End-Time',
|
label: 'End-Time',
|
||||||
key: 'scheduledEndTime',
|
key: 'scheduledEndTime',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
description:
|
||||||
|
'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -39,9 +40,10 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'Channel',
|
label: 'Channel',
|
||||||
key: 'channel_id',
|
key: 'channel_id',
|
||||||
type: 'dropdown' as const,
|
type: 'dropdown',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Pick a voice or stage channel to link the event to. This will be omitted if type is EXTERNAL',
|
description:
|
||||||
|
'Pick a voice or stage channel to link the event to. This will be omitted if type is EXTERNAL',
|
||||||
variables: true,
|
variables: true,
|
||||||
source: {
|
source: {
|
||||||
type: 'query',
|
type: 'query',
|
||||||
@@ -57,15 +59,16 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'Location',
|
label: 'Location',
|
||||||
key: 'location',
|
key: 'location',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
description:
|
||||||
|
'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Start-Time',
|
label: 'Start-Time',
|
||||||
key: 'scheduledStartTime',
|
key: 'scheduledStartTime',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The time the event will start [ISO8601]',
|
description: 'The time the event will start [ISO8601]',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -73,9 +76,10 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'End-Time',
|
label: 'End-Time',
|
||||||
key: 'scheduledEndTime',
|
key: 'scheduledEndTime',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
description:
|
||||||
|
'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
@@ -1,10 +1,10 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import dynamicData from './dynamic-data';
|
import dynamicData from './dynamic-data/index.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
import triggers from './triggers';
|
import triggers from './triggers/index.js';
|
||||||
import dynamicFields from './dynamic-fields';
|
import dynamicFields from './dynamic-fields/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Discord',
|
name: 'Discord',
|
@@ -1,23 +1,25 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Create folder',
|
name: 'Create folder',
|
||||||
key: 'createFolder',
|
key: 'createFolder',
|
||||||
description: 'Create a new folder with the given parent folder and folder name',
|
description:
|
||||||
|
'Create a new folder with the given parent folder and folder name',
|
||||||
arguments: [
|
arguments: [
|
||||||
{
|
{
|
||||||
label: 'Folder',
|
label: 'Folder',
|
||||||
key: 'parentFolder',
|
key: 'parentFolder',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Enter the parent folder path, like /TextFiles/ or /Documents/Taxes/',
|
description:
|
||||||
|
'Enter the parent folder path, like /TextFiles/ or /Documents/Taxes/',
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Folder Name',
|
label: 'Folder Name',
|
||||||
key: 'folderName',
|
key: 'folderName',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Enter the name for the new folder',
|
description: 'Enter the name for the new folder',
|
||||||
variables: true,
|
variables: true,
|
||||||
@@ -25,11 +27,13 @@ export default defineAction({
|
|||||||
],
|
],
|
||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
const parentFolder = $.step.parameters.parentFolder as string;
|
const parentFolder = $.step.parameters.parentFolder;
|
||||||
const folderName = $.step.parameters.folderName as string;
|
const folderName = $.step.parameters.folderName;
|
||||||
const folderPath = path.join(parentFolder, folderName);
|
const folderPath = path.join(parentFolder, folderName);
|
||||||
|
|
||||||
const response = await $.http.post('/2/files/create_folder_v2', { path: folderPath });
|
const response = await $.http.post('/2/files/create_folder_v2', {
|
||||||
|
path: folderPath,
|
||||||
|
});
|
||||||
|
|
||||||
$.setActionItem({ raw: response.data });
|
$.setActionItem({ raw: response.data });
|
||||||
},
|
},
|
4
packages/backend/src/apps/dropbox/actions/index.js
Normal file
4
packages/backend/src/apps/dropbox/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import createFolder from './create-folder/index.js';
|
||||||
|
import renameFile from './rename-file/index.js';
|
||||||
|
|
||||||
|
export default [createFolder, renameFile];
|
@@ -1,4 +0,0 @@
|
|||||||
import createFolder from "./create-folder";
|
|
||||||
import renameFile from "./rename-file";
|
|
||||||
|
|
||||||
export default [createFolder, renameFile];
|
|
@@ -1,5 +1,5 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import defineAction from '../../../../helpers/define-action';
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
export default defineAction({
|
export default defineAction({
|
||||||
name: 'Rename file',
|
name: 'Rename file',
|
||||||
@@ -9,25 +9,25 @@ export default defineAction({
|
|||||||
{
|
{
|
||||||
label: 'File Path',
|
label: 'File Path',
|
||||||
key: 'filePath',
|
key: 'filePath',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description:
|
description: 'Write the full path to the file such as /Folder1/File.pdf',
|
||||||
'Write the full path to the file such as /Folder1/File.pdf',
|
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'New Name',
|
label: 'New Name',
|
||||||
key: 'newName',
|
key: 'newName',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: "Enter the new name for the file (without the extension, e.g., '.pdf')",
|
description:
|
||||||
|
"Enter the new name for the file (without the extension, e.g., '.pdf')",
|
||||||
variables: true,
|
variables: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
const filePath = $.step.parameters.filePath as string;
|
const filePath = $.step.parameters.filePath;
|
||||||
const newName = $.step.parameters.newName as string;
|
const newName = $.step.parameters.newName;
|
||||||
const fileObject = path.parse(filePath);
|
const fileObject = path.parse(filePath);
|
||||||
const newPath = path.format({
|
const newPath = path.format({
|
||||||
dir: fileObject.dir,
|
dir: fileObject.dir,
|
@@ -1,15 +1,15 @@
|
|||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
import scopes from '../common/scopes.js';
|
||||||
import scopes from '../common/scopes';
|
|
||||||
|
|
||||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
export default async function generateAuthUrl($) {
|
||||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
);
|
);
|
||||||
const callbackUrl = oauthRedirectUrlField.value as string;
|
|
||||||
|
const callbackUrl = oauthRedirectUrlField.value;
|
||||||
|
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
client_id: $.auth.data.clientId as string,
|
client_id: $.auth.data.clientId,
|
||||||
redirect_uri: callbackUrl,
|
redirect_uri: callbackUrl,
|
||||||
response_type: 'code',
|
response_type: 'code',
|
||||||
scope: scopes.join(' '),
|
scope: scopes.join(' '),
|
@@ -1,14 +1,14 @@
|
|||||||
import generateAuthUrl from './generate-auth-url';
|
import generateAuthUrl from './generate-auth-url.js';
|
||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
import refreshToken from './refresh-token';
|
import refreshToken from './refresh-token.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'oAuthRedirectUrl',
|
key: 'oAuthRedirectUrl',
|
||||||
label: 'OAuth Redirect URL',
|
label: 'OAuth Redirect URL',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
value: '{WEB_APP_URL}/app/dropbox/connections/add',
|
value: '{WEB_APP_URL}/app/dropbox/connections/add',
|
||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'clientId',
|
key: 'clientId',
|
||||||
label: 'App Key',
|
label: 'App Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -31,7 +31,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'clientSecret',
|
key: 'clientSecret',
|
||||||
label: 'App Secret',
|
label: 'App Secret',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -0,0 +1,8 @@
|
|||||||
|
import getCurrentAccount from '../common/get-current-account.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
const account = await getCurrentAccount($);
|
||||||
|
return !!account;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import getCurrentAccount from '../common/get-current-account';
|
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
const account = await getCurrentAccount($);
|
|
||||||
return !!account;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
36
packages/backend/src/apps/dropbox/auth/refresh-token.js
Normal file
36
packages/backend/src/apps/dropbox/auth/refresh-token.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Buffer } from 'node:buffer';
|
||||||
|
|
||||||
|
const refreshToken = async ($) => {
|
||||||
|
const params = {
|
||||||
|
grant_type: 'refresh_token',
|
||||||
|
refresh_token: $.auth.data.refreshToken,
|
||||||
|
};
|
||||||
|
|
||||||
|
const basicAuthToken = Buffer.from(
|
||||||
|
`${$.auth.data.clientId}:${$.auth.data.clientSecret}`
|
||||||
|
).toString('base64');
|
||||||
|
|
||||||
|
const { data } = await $.http.post('oauth2/token', null, {
|
||||||
|
params,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${basicAuthToken}`,
|
||||||
|
},
|
||||||
|
additionalProperties: {
|
||||||
|
skipAddingAuthHeader: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
access_token: accessToken,
|
||||||
|
expires_in: expiresIn,
|
||||||
|
token_type: tokenType,
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
accessToken,
|
||||||
|
expiresIn,
|
||||||
|
tokenType,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default refreshToken;
|
@@ -1,41 +0,0 @@
|
|||||||
import { Buffer } from 'node:buffer';
|
|
||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
|
|
||||||
const refreshToken = async ($: IGlobalVariable) => {
|
|
||||||
const params = {
|
|
||||||
grant_type: 'refresh_token',
|
|
||||||
refresh_token: $.auth.data.refreshToken as string,
|
|
||||||
};
|
|
||||||
|
|
||||||
const basicAuthToken = Buffer
|
|
||||||
.from(`${$.auth.data.clientId}:${$.auth.data.clientSecret}`)
|
|
||||||
.toString('base64');
|
|
||||||
|
|
||||||
const { data } = await $.http.post(
|
|
||||||
'oauth2/token',
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
params,
|
|
||||||
headers: {
|
|
||||||
Authorization: `Basic ${basicAuthToken}`
|
|
||||||
},
|
|
||||||
additionalProperties: {
|
|
||||||
skipAddingAuthHeader: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
|
||||||
access_token: accessToken,
|
|
||||||
expires_in: expiresIn,
|
|
||||||
token_type: tokenType,
|
|
||||||
} = data;
|
|
||||||
|
|
||||||
await $.auth.set({
|
|
||||||
accessToken,
|
|
||||||
expiresIn,
|
|
||||||
tokenType,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default refreshToken;
|
|
@@ -1,44 +1,20 @@
|
|||||||
import { IGlobalVariable, IField } from '@automatisch/types';
|
import getCurrentAccount from '../common/get-current-account.js';
|
||||||
import getCurrentAccount from '../common/get-current-account';
|
|
||||||
|
|
||||||
type TAccount = {
|
const verifyCredentials = async ($) => {
|
||||||
account_id: string,
|
|
||||||
name: {
|
|
||||||
given_name: string,
|
|
||||||
surname: string,
|
|
||||||
familiar_name: string,
|
|
||||||
display_name: string,
|
|
||||||
abbreviated_name: string,
|
|
||||||
},
|
|
||||||
email: string,
|
|
||||||
email_verified: boolean,
|
|
||||||
disabled: boolean,
|
|
||||||
country: string,
|
|
||||||
locale: string,
|
|
||||||
referral_link: string,
|
|
||||||
is_paired: boolean,
|
|
||||||
account_type: {
|
|
||||||
".tag": string,
|
|
||||||
},
|
|
||||||
root_info: {
|
|
||||||
".tag": string,
|
|
||||||
root_namespace_id: string,
|
|
||||||
home_namespace_id: string,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
|
||||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
);
|
);
|
||||||
const redirectUrl = oauthRedirectUrlField.value as string;
|
|
||||||
|
const redirectUrl = oauthRedirectUrlField.value;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
client_id: $.auth.data.clientId as string,
|
client_id: $.auth.data.clientId,
|
||||||
redirect_uri: redirectUrl,
|
redirect_uri: redirectUrl,
|
||||||
client_secret: $.auth.data.clientSecret as string,
|
client_secret: $.auth.data.clientSecret,
|
||||||
code: $.auth.data.code as string,
|
code: $.auth.data.code,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
}
|
};
|
||||||
|
|
||||||
const { data: verifiedCredentials } = await $.http.post(
|
const { data: verifiedCredentials } = await $.http.post(
|
||||||
'/oauth2/token',
|
'/oauth2/token',
|
||||||
null,
|
null,
|
||||||
@@ -66,10 +42,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
|||||||
accountId,
|
accountId,
|
||||||
teamId,
|
teamId,
|
||||||
idToken,
|
idToken,
|
||||||
uid
|
uid,
|
||||||
});
|
});
|
||||||
|
|
||||||
const account = await getCurrentAccount($) as TAccount;
|
const account = await getCurrentAccount($);
|
||||||
|
|
||||||
await $.auth.set({
|
await $.auth.set({
|
||||||
accountId: account.account_id,
|
accountId: account.account_id,
|
||||||
@@ -88,10 +64,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
|||||||
referralLink: account.referral_link,
|
referralLink: account.referral_link,
|
||||||
isPaired: account.is_paired,
|
isPaired: account.is_paired,
|
||||||
accountType: {
|
accountType: {
|
||||||
".tag": account.account_type['.tag'],
|
'.tag': account.account_type['.tag'],
|
||||||
},
|
},
|
||||||
rootInfo: {
|
rootInfo: {
|
||||||
".tag": account.root_info['.tag'],
|
'.tag': account.root_info['.tag'],
|
||||||
rootNamespaceId: account.root_info.root_namespace_id,
|
rootNamespaceId: account.root_info.root_namespace_id,
|
||||||
homeNamespaceId: account.root_info.home_namespace_id,
|
homeNamespaceId: account.root_info.home_namespace_id,
|
||||||
},
|
},
|
14
packages/backend/src/apps/dropbox/common/add-auth-header.js
Normal file
14
packages/backend/src/apps/dropbox/common/add-auth-header.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
requestConfig.headers['Content-Type'] = 'application/json';
|
||||||
|
|
||||||
|
if (
|
||||||
|
!requestConfig.additionalProperties?.skipAddingAuthHeader &&
|
||||||
|
$.auth.data?.accessToken
|
||||||
|
) {
|
||||||
|
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
@@ -1,13 +0,0 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
requestConfig.headers['Content-Type'] = 'application/json';
|
|
||||||
|
|
||||||
if (!requestConfig.additionalProperties?.skipAddingAuthHeader && $.auth.data?.accessToken) {
|
|
||||||
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default addAuthHeader;
|
|
@@ -0,0 +1,6 @@
|
|||||||
|
const getCurrentAccount = async ($) => {
|
||||||
|
const response = await $.http.post('/2/users/get_current_account', null);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getCurrentAccount;
|
@@ -1,8 +0,0 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
|
||||||
|
|
||||||
const getCurrentAccount = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
|
||||||
const response = await $.http.post('/2/users/get_current_account', null);
|
|
||||||
return response.data;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getCurrentAccount;
|
|
@@ -1,7 +1,7 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Dropbox',
|
name: 'Dropbox',
|
88
packages/backend/src/apps/filter/actions/continue/index.js
Normal file
88
packages/backend/src/apps/filter/actions/continue/index.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
const isEqual = (a, b) => a === b;
|
||||||
|
const isNotEqual = (a, b) => !isEqual(a, b);
|
||||||
|
const isGreaterThan = (a, b) => Number(a) > Number(b);
|
||||||
|
const isLessThan = (a, b) => Number(a) < Number(b);
|
||||||
|
const isGreaterThanOrEqual = (a, b) => Number(a) >= Number(b);
|
||||||
|
const isLessThanOrEqual = (a, b) => Number(a) <= Number(b);
|
||||||
|
const contains = (a, b) => a.includes(b);
|
||||||
|
const doesNotContain = (a, b) => !contains(a, b);
|
||||||
|
|
||||||
|
const shouldContinue = (orGroups) => {
|
||||||
|
let atLeastOneGroupMatches = false;
|
||||||
|
|
||||||
|
for (const group of orGroups) {
|
||||||
|
let groupMatches = true;
|
||||||
|
|
||||||
|
for (const condition of group.and) {
|
||||||
|
const conditionMatches = operate(
|
||||||
|
condition.operator,
|
||||||
|
condition.key,
|
||||||
|
condition.value
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!conditionMatches) {
|
||||||
|
groupMatches = false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupMatches) {
|
||||||
|
atLeastOneGroupMatches = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return atLeastOneGroupMatches;
|
||||||
|
};
|
||||||
|
|
||||||
|
const operators = {
|
||||||
|
equal: isEqual,
|
||||||
|
not_equal: isNotEqual,
|
||||||
|
greater_than: isGreaterThan,
|
||||||
|
less_than: isLessThan,
|
||||||
|
greater_than_or_equal: isGreaterThanOrEqual,
|
||||||
|
less_than_or_equal: isLessThanOrEqual,
|
||||||
|
contains: contains,
|
||||||
|
not_contains: doesNotContain,
|
||||||
|
};
|
||||||
|
|
||||||
|
const operate = (operation, a, b) => {
|
||||||
|
return operators[operation](a, b);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Continue if conditions match',
|
||||||
|
key: 'continueIfMatches',
|
||||||
|
description: 'Let the execution continue if the conditions match',
|
||||||
|
arguments: [],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const orGroups = $.step.parameters.or;
|
||||||
|
|
||||||
|
const matchingGroups = orGroups.reduce((groups, group) => {
|
||||||
|
const matchingConditions = group.and.filter((condition) =>
|
||||||
|
operate(condition.operator, condition.key, condition.value)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingConditions.length) {
|
||||||
|
return groups.concat([{ and: matchingConditions }]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!shouldContinue(orGroups)) {
|
||||||
|
$.execution.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: {
|
||||||
|
or: matchingGroups,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,109 +0,0 @@
|
|||||||
import defineAction from '../../../../helpers/define-action';
|
|
||||||
|
|
||||||
type TGroupItem = {
|
|
||||||
key: string;
|
|
||||||
operator: keyof TOperators;
|
|
||||||
value: string;
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TGroup = Record<'and', TGroupItem[]>;
|
|
||||||
|
|
||||||
const isEqual = (a: string, b: string) => a === b;
|
|
||||||
const isNotEqual = (a: string, b: string) => !isEqual(a, b);
|
|
||||||
const isGreaterThan = (a: string, b: string) => Number(a) > Number(b);
|
|
||||||
const isLessThan = (a: string, b: string) => Number(a) < Number(b);
|
|
||||||
const isGreaterThanOrEqual = (a: string, b: string) => Number(a) >= Number(b);
|
|
||||||
const isLessThanOrEqual = (a: string, b: string) => Number(a) <= Number(b);
|
|
||||||
const contains = (a: string, b: string) => a.includes(b);
|
|
||||||
const doesNotContain = (a: string, b: string) => !contains(a, b);
|
|
||||||
|
|
||||||
const shouldContinue = (orGroups: TGroup[]) => {
|
|
||||||
let atLeastOneGroupMatches = false;
|
|
||||||
|
|
||||||
for (const group of orGroups) {
|
|
||||||
let groupMatches = true;
|
|
||||||
|
|
||||||
for (const condition of group.and) {
|
|
||||||
const conditionMatches = operate(
|
|
||||||
condition.operator,
|
|
||||||
condition.key,
|
|
||||||
condition.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!conditionMatches) {
|
|
||||||
groupMatches = false;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groupMatches) {
|
|
||||||
atLeastOneGroupMatches = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return atLeastOneGroupMatches;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TOperatorFunc = (a: string, b: string) => boolean;
|
|
||||||
|
|
||||||
type TOperators = {
|
|
||||||
equal: TOperatorFunc;
|
|
||||||
not_equal: TOperatorFunc;
|
|
||||||
greater_than: TOperatorFunc;
|
|
||||||
less_than: TOperatorFunc;
|
|
||||||
greater_than_or_equal: TOperatorFunc;
|
|
||||||
less_than_or_equal: TOperatorFunc;
|
|
||||||
contains: TOperatorFunc;
|
|
||||||
not_contains: TOperatorFunc;
|
|
||||||
};
|
|
||||||
|
|
||||||
const operators: TOperators = {
|
|
||||||
'equal': isEqual,
|
|
||||||
'not_equal': isNotEqual,
|
|
||||||
'greater_than': isGreaterThan,
|
|
||||||
'less_than': isLessThan,
|
|
||||||
'greater_than_or_equal': isGreaterThanOrEqual,
|
|
||||||
'less_than_or_equal': isLessThanOrEqual,
|
|
||||||
'contains': contains,
|
|
||||||
'not_contains': doesNotContain,
|
|
||||||
};
|
|
||||||
|
|
||||||
const operate = (operation: keyof TOperators, a: string, b: string) => {
|
|
||||||
return operators[operation](a, b);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default defineAction({
|
|
||||||
name: 'Continue if conditions match',
|
|
||||||
key: 'continueIfMatches',
|
|
||||||
description: 'Let the execution continue if the conditions match',
|
|
||||||
arguments: [],
|
|
||||||
|
|
||||||
async run($) {
|
|
||||||
const orGroups = $.step.parameters.or as TGroup[];
|
|
||||||
|
|
||||||
const matchingGroups = orGroups.reduce((groups, group) => {
|
|
||||||
const matchingConditions = group.and
|
|
||||||
.filter((condition) => operate(condition.operator, condition.key, condition.value));
|
|
||||||
|
|
||||||
if (matchingConditions.length) {
|
|
||||||
return groups.concat([{ and: matchingConditions }]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return groups;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!shouldContinue(orGroups)) {
|
|
||||||
$.execution.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$.setActionItem({
|
|
||||||
raw: {
|
|
||||||
or: matchingGroups,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
3
packages/backend/src/apps/filter/actions/index.js
Normal file
3
packages/backend/src/apps/filter/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import continueIfMatches from './continue/index.js';
|
||||||
|
|
||||||
|
export default [continueIfMatches];
|
@@ -1,3 +0,0 @@
|
|||||||
import continueIfMatches from './continue';
|
|
||||||
|
|
||||||
export default [continueIfMatches];
|
|
@@ -1,5 +1,5 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import actions from './actions';
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Filter',
|
name: 'Filter',
|
@@ -1,9 +1,8 @@
|
|||||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
|
|
||||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
export default async function generateAuthUrl($) {
|
||||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
);
|
);
|
||||||
|
|
||||||
const callbackUrl = oauthRedirectUrlField.value;
|
const callbackUrl = oauthRedirectUrlField.value;
|
@@ -1,13 +1,13 @@
|
|||||||
import generateAuthUrl from './generate-auth-url';
|
import generateAuthUrl from './generate-auth-url.js';
|
||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials.js';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: 'oAuthRedirectUrl',
|
key: 'oAuthRedirectUrl',
|
||||||
label: 'OAuth Redirect URL',
|
label: 'OAuth Redirect URL',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
value: '{WEB_APP_URL}/app/flickr/connections/add',
|
value: '{WEB_APP_URL}/app/flickr/connections/add',
|
||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'consumerKey',
|
key: 'consumerKey',
|
||||||
label: 'Consumer Key',
|
label: 'Consumer Key',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
||||||
@@ -32,7 +32,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'consumerSecret',
|
key: 'consumerSecret',
|
||||||
label: 'Consumer Secret',
|
label: 'Consumer Secret',
|
||||||
type: 'string' as const,
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
value: null,
|
value: null,
|
@@ -1,6 +1,4 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
const isStillVerified = async ($) => {
|
||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
|
||||||
const params = {
|
const params = {
|
||||||
method: 'flickr.test.login',
|
method: 'flickr.test.login',
|
||||||
format: 'json',
|
format: 'json',
|
@@ -1,7 +1,6 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
const verifyCredentials = async ($) => {
|
||||||
const response = await $.http.post(
|
const response = await $.http.post(
|
||||||
`/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`,
|
`/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`,
|
||||||
null
|
null
|
@@ -1,22 +1,14 @@
|
|||||||
import { Token } from 'oauth-1.0a';
|
import oauthClient from './oauth-client.js';
|
||||||
import { IJSONObject, TBeforeRequest } from '@automatisch/types';
|
|
||||||
import oauthClient from './oauth-client';
|
|
||||||
|
|
||||||
type RequestDataType = {
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
url: string;
|
|
||||||
method: string;
|
|
||||||
data?: IJSONObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
|
||||||
const { url, method, data, params } = requestConfig;
|
const { url, method, data, params } = requestConfig;
|
||||||
|
|
||||||
const token: Token = {
|
const token = {
|
||||||
key: $.auth.data?.accessToken as string,
|
key: $.auth.data?.accessToken,
|
||||||
secret: $.auth.data?.accessSecret as string,
|
secret: $.auth.data?.accessSecret,
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestData: RequestDataType = {
|
const requestData = {
|
||||||
url: `${requestConfig.baseURL}${url}`,
|
url: `${requestConfig.baseURL}${url}`,
|
||||||
method,
|
method,
|
||||||
};
|
};
|
@@ -1,11 +1,10 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import OAuth from 'oauth-1.0a';
|
import OAuth from 'oauth-1.0a';
|
||||||
|
|
||||||
const oauthClient = ($: IGlobalVariable) => {
|
const oauthClient = ($) => {
|
||||||
const consumerData = {
|
const consumerData = {
|
||||||
key: $.auth.data.consumerKey as string,
|
key: $.auth.data.consumerKey,
|
||||||
secret: $.auth.data.consumerSecret as string,
|
secret: $.auth.data.consumerSecret,
|
||||||
};
|
};
|
||||||
|
|
||||||
return new OAuth({
|
return new OAuth({
|
3
packages/backend/src/apps/flickr/dynamic-data/index.js
Normal file
3
packages/backend/src/apps/flickr/dynamic-data/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import listAlbums from './list-albums/index.js';
|
||||||
|
|
||||||
|
export default [listAlbums];
|
@@ -1,3 +0,0 @@
|
|||||||
import listAlbums from './list-albums';
|
|
||||||
|
|
||||||
export default [listAlbums];
|
|
@@ -1,22 +1,8 @@
|
|||||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
|
||||||
|
|
||||||
type TResponse = {
|
|
||||||
data: IJSONObject[];
|
|
||||||
error?: IJSONObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
type TPhotoset = {
|
|
||||||
id: string;
|
|
||||||
title: {
|
|
||||||
_content: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'List albums',
|
name: 'List albums',
|
||||||
key: 'listAlbums',
|
key: 'listAlbums',
|
||||||
|
|
||||||
async run($: IGlobalVariable) {
|
async run($) {
|
||||||
const params = {
|
const params = {
|
||||||
page: 1,
|
page: 1,
|
||||||
per_page: 500,
|
per_page: 500,
|
||||||
@@ -25,9 +11,10 @@ export default {
|
|||||||
format: 'json',
|
format: 'json',
|
||||||
nojsoncallback: 1,
|
nojsoncallback: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = await $.http.get('/rest', { params });
|
let response = await $.http.get('/rest', { params });
|
||||||
|
|
||||||
const aggregatedResponse: TResponse = {
|
const aggregatedResponse = {
|
||||||
data: [...response.data.photosets.photoset],
|
data: [...response.data.photosets.photoset],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,14 +29,12 @@ export default {
|
|||||||
aggregatedResponse.data.push(...response.data.photosets.photoset);
|
aggregatedResponse.data.push(...response.data.photosets.photoset);
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregatedResponse.data = aggregatedResponse.data.map(
|
aggregatedResponse.data = aggregatedResponse.data.map((photoset) => {
|
||||||
(photoset: TPhotoset) => {
|
|
||||||
return {
|
return {
|
||||||
value: photoset.id,
|
value: photoset.id,
|
||||||
name: photoset.title._content,
|
name: photoset.title._content,
|
||||||
} as IJSONObject;
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return aggregatedResponse;
|
return aggregatedResponse;
|
||||||
},
|
},
|
@@ -1,8 +1,8 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app.js';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
import auth from './auth';
|
import auth from './auth/index.js';
|
||||||
import triggers from './triggers';
|
import triggers from './triggers/index.js';
|
||||||
import dynamicData from './dynamic-data';
|
import dynamicData from './dynamic-data/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Flickr',
|
name: 'Flickr',
|
6
packages/backend/src/apps/flickr/triggers/index.js
Normal file
6
packages/backend/src/apps/flickr/triggers/index.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import newAlbums from './new-albums/index.js';
|
||||||
|
import newFavoritePhotos from './new-favorite-photos/index.js';
|
||||||
|
import newPhotos from './new-photos/index.js';
|
||||||
|
import newPhotosInAlbums from './new-photos-in-album/index.js';
|
||||||
|
|
||||||
|
export default [newAlbums, newFavoritePhotos, newPhotos, newPhotosInAlbums];
|
@@ -1,6 +0,0 @@
|
|||||||
import newAlbums from './new-albums';
|
|
||||||
import newFavoritePhotos from './new-favorite-photos';
|
|
||||||
import newPhotos from './new-photos';
|
|
||||||
import newPhotosInAlbums from './new-photos-in-album';
|
|
||||||
|
|
||||||
export default [newAlbums, newFavoritePhotos, newPhotos, newPhotosInAlbums];
|
|
@@ -1,5 +1,5 @@
|
|||||||
import defineTrigger from '../../../../helpers/define-trigger';
|
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||||
import newAlbums from './new-albums';
|
import newAlbums from './new-albums.js';
|
||||||
|
|
||||||
export default defineTrigger({
|
export default defineTrigger({
|
||||||
name: 'New albums',
|
name: 'New albums',
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user