Compare commits

..

24 Commits

Author SHA1 Message Date
Faruk AYDIN
6c7470472f fix: Update the branch for dockerfile cloud 2024-02-28 02:34:57 +01:00
Faruk AYDIN
54282ba7e0 feat: Use new API endpoint from Helix 2024-02-28 02:23:50 +01:00
Ömer Faruk Aydın
7f324abd44 Merge pull request #1669 from automatisch/helix-attemtps
fix: Add artificial delay to Helix API attempts
2024-02-27 23:49:05 +01:00
Faruk AYDIN
65a0c3b40a fix: Add artificial delay to Helix API attempts 2024-02-27 23:44:52 +01:00
Ömer Faruk Aydın
2449baac5b Merge pull request #1668 from automatisch/document-datastore
docs: Add datastore app to the integration list
2024-02-27 22:10:52 +01:00
Faruk AYDIN
0ab03e1856 docs: Add datastore app to the integration list 2024-02-27 21:44:51 +01:00
Ömer Faruk Aydın
9a3f85106c Merge pull request #1667 from automatisch/fix-helix-integration
fix: Stop asking to helix server after 50 attempts
2024-02-27 19:17:04 +01:00
Faruk AYDIN
42c495d8ab fix: Stop asking to helix server after 50 attempts 2024-02-27 19:14:19 +01:00
Ömer Faruk Aydın
58def585f1 Merge pull request #1666 from automatisch/datastore-app
feat: Implement datastore built-in app
2024-02-27 19:13:26 +01:00
Faruk AYDIN
047034d831 fix: Remove min length validation from value of datastore 2024-02-27 19:05:27 +01:00
Faruk AYDIN
bdb2f24a81 feat: Implement datastore built-in app 2024-02-27 19:01:46 +01:00
Ömer Faruk Aydın
636870a075 Merge pull request #1661 from automatisch/get-app
feat: Introduce app serializer
2024-02-26 22:32:06 +01:00
Faruk AYDIN
8981174302 feat: Introduce app serializer 2024-02-26 22:25:03 +01:00
Faruk AYDIN
dd5f05334b feat: Allow renderer to use explicitly defined serializers 2024-02-26 22:17:21 +01:00
Ömer Faruk Aydın
929b626b51 Merge pull request #1660 from automatisch/rest-get-app
feat: Implement get app API endpoint
2024-02-26 21:44:23 +01:00
Faruk AYDIN
7d5b2ec81e feat: Implement get app API endpoint 2024-02-26 17:59:48 +01:00
Ömer Faruk Aydın
f0e2d36c34 Merge pull request #1657 from automatisch/timestamp-serializer
feat: Use timestamp for serializer date objects
2024-02-26 14:36:34 +01:00
Faruk AYDIN
94f171d757 feat: Use timestamp for serializer date objects 2024-02-26 14:11:56 +01:00
Ömer Faruk Aydın
04e06db430 Merge pull request #1656 from automatisch/api-controller-tests
test: Cover not found responses for API endpoint tests
2024-02-26 13:36:48 +01:00
Faruk AYDIN
d74b215169 test: Cover bad request responses for API endpoint tests 2024-02-26 13:30:30 +01:00
Faruk AYDIN
404ea94dd2 test: Cover not found responses for API endpoint tests 2024-02-26 01:40:20 +01:00
Faruk AYDIN
4afe7c6b46 feat: Handle bad request for invalid UUID 2024-02-26 01:26:04 +01:00
Faruk AYDIN
58658c6b1a feat: Do not expose unknown error message to client 2024-02-26 01:07:31 +01:00
Faruk AYDIN
ec444317b3 feat: Catch not found error message for objection 2024-02-26 01:06:54 +01:00
49 changed files with 528 additions and 236 deletions

View File

@@ -6,7 +6,7 @@ ENV PORT 3000
RUN \ RUN \
apk --no-cache add --virtual build-dependencies python3 build-base git apk --no-cache add --virtual build-dependencies python3 build-base git
RUN git clone https://github.com/automatisch/automatisch.git RUN git clone -b helix-new-endpoint https://github.com/automatisch/automatisch.git
WORKDIR /automatisch WORKDIR /automatisch

View File

@@ -0,0 +1,27 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Get value',
key: 'getValue',
description: 'Get value from the persistent datastore.',
arguments: [
{
label: 'Key',
key: 'key',
type: 'string',
required: true,
description: 'The key of your value to get.',
variables: true,
},
],
async run($) {
const keyValuePair = await $.datastore.get({
key: $.step.parameters.key,
});
$.setActionItem({
raw: keyValuePair,
});
},
});

View File

@@ -0,0 +1,4 @@
import getValue from './get-value/index.js';
import setValue from './set-value/index.js';
export default [getValue, setValue];

View File

@@ -0,0 +1,36 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Set value',
key: 'setValue',
description: 'Set value to the persistent datastore.',
arguments: [
{
label: 'Key',
key: 'key',
type: 'string',
required: true,
description: 'The key of your value to set.',
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string',
required: true,
description: 'The value to set.',
variables: true,
},
],
async run($) {
const keyValuePair = await $.datastore.set({
key: $.step.parameters.key,
value: $.step.parameters.value,
});
$.setActionItem({
raw: keyValuePair,
});
},
});

View File

@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" width="800px" height="800px" viewBox="0 0 32 32" id="icon">
<defs>
<style>.cls-1{fill:none;}</style>
</defs>
<title>datastore</title>
<circle cx="23" cy="23" r="1"/>
<rect x="8" y="22" width="12" height="2"/>
<circle cx="23" cy="9" r="1"/>
<rect x="8" y="8" width="12" height="2"/>
<path d="M26,14a2,2,0,0,0,2-2V6a2,2,0,0,0-2-2H6A2,2,0,0,0,4,6v6a2,2,0,0,0,2,2H8v4H6a2,2,0,0,0-2,2v6a2,2,0,0,0,2,2H26a2,2,0,0,0,2-2V20a2,2,0,0,0-2-2H24V14ZM6,6H26v6H6ZM26,26H6V20H26Zm-4-8H10V14H22Z"/>
<rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32" height="32"/>
</svg>

After

Width:  |  Height:  |  Size: 704 B

View File

@@ -0,0 +1,14 @@
import defineApp from '../../helpers/define-app.js';
import actions from './actions/index.js';
export default defineApp({
name: 'Datastore',
key: 'datastore',
iconUrl: '{BASE_URL}/apps/datastore/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/datastore/connection',
supportsConnections: false,
baseUrl: '',
apiBaseUrl: '',
primaryColor: '001F52',
actions,
});

View File

@@ -1,82 +0,0 @@
import path from 'node:path';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Create a text file',
key: 'createTextFile',
description: 'Create a new text file from plain text content you specify.',
arguments: [
{
label: 'Folder',
key: 'parentFolder',
type: 'string',
required: true,
description:
'Enter the folder path that file will be saved, like /TextFiles/ or /Documents/Taxes/',
variables: true,
},
{
label: 'Folder Name',
key: 'folderName',
type: 'string',
required: true,
description:
"Enter the name for the new file. The file extension will be '.txt'.",
variables: true,
},
{
label: 'File Content',
key: 'fileContent',
type: 'string',
required: true,
description: 'Plain text content to insert into the new text file.',
variables: true,
},
{
label: 'Overwrite',
key: 'overwrite',
type: 'dropdown',
required: true,
description:
'Overwrite this file (if one of the same name exists) or not.',
variables: true,
options: [
{ label: 'False', value: false },
{ label: 'True', value: true },
],
},
],
async run($) {
const fileContent = $.step.parameters.fileContent;
const overwrite = $.step.parameters.overwrite;
const parentFolder = $.step.parameters.parentFolder;
const folderName = $.step.parameters.folderName;
const folderPath = path.join(parentFolder, folderName);
const headers = {
Authorization: `Bearer ${$.auth.data.accessToken}`,
'Content-Type': 'application/octet-stream',
'Dropbox-API-Arg': JSON.stringify({
autorename: false,
mode: overwrite ? 'overwrite' : 'add',
mute: false,
path: `${folderPath}.txt`,
strict_conflict: false,
}),
};
const response = await $.http.post(
'https://content.dropboxapi.com/2/files/upload',
fileContent,
{
headers,
additionalProperties: {
skipAddingAuthHeader: true,
},
}
);
$.setActionItem({ raw: response.data });
},
});

View File

@@ -1,5 +1,4 @@
import createFolder from './create-folder/index.js'; import createFolder from './create-folder/index.js';
import createTextFile from './create-text-file/index.js';
import renameFile from './rename-file/index.js'; import renameFile from './rename-file/index.js';
export default [createFolder, createTextFile, renameFile]; export default [createFolder, renameFile];

View File

@@ -1,10 +1,10 @@
const addAuthHeader = ($, requestConfig) => { const addAuthHeader = ($, requestConfig) => {
requestConfig.headers['Content-Type'] = 'application/json';
if ( if (
!requestConfig.additionalProperties?.skipAddingAuthHeader && !requestConfig.additionalProperties?.skipAddingAuthHeader &&
$.auth.data?.accessToken $.auth.data?.accessToken
) { ) {
requestConfig.headers['Content-Type'] = 'application/json';
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`; requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
} }

View File

@@ -2,7 +2,6 @@ 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 actions from './actions/index.js'; import actions from './actions/index.js';
import triggers from './triggers/index.js';
export default defineApp({ export default defineApp({
name: 'Dropbox', name: 'Dropbox',
@@ -16,5 +15,4 @@ export default defineApp({
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
actions, actions,
triggers,
}); });

View File

@@ -1,3 +0,0 @@
import newFolders from './new-folders/index.js';
export default [newFolders];

View File

@@ -1,61 +0,0 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'New folders',
key: 'newFolders',
pollInterval: 15,
description:
'Triggers when any new folder is added. Ensure that the number of files/folders within the monitored directory remains below 4000.',
arguments: [
{
label: 'Folder',
key: 'folderPath',
type: 'string',
required: true,
description:
'Enter the folder path that you want to follow, like /TextFiles or /Documents/Taxes.',
variables: true,
},
],
async run($) {
const folderPath = $.step.parameters.folderPath;
let endpoint = '/2/files/list_folder';
let next = false;
const params = {
path: folderPath,
recursive: false,
include_deleted: false,
include_has_explicit_shared_members: false,
include_mounted_folders: true,
limit: 2000,
include_non_downloadable_files: true,
};
do {
const { data } = await $.http.post(endpoint, params);
if (data.has_more) {
endpoint += '/continue';
params.cursor = data.cursor;
next = data.has_more;
} else {
next = false;
}
if (data.entries?.length) {
for (const entry of data.entries.reverse()) {
if (entry['.tag'] === 'folder') {
$.pushTriggerItem({
raw: entry,
meta: {
internalId: entry.id,
},
});
}
}
}
} while (next);
},
});

View File

@@ -1,4 +1,3 @@
import FormData from 'form-data';
import defineAction from '../../../../helpers/define-action.js'; import defineAction from '../../../../helpers/define-action.js';
export default defineAction({ export default defineAction({
@@ -17,34 +16,21 @@ export default defineAction({
], ],
async run($) { async run($) {
const formData = new FormData(); const response = await $.http.post('/api/v1/sessions/chat', {
formData.append('input', $.step.parameters.input); session_id: '',
formData.append('mode', 'inference'); messages: [
formData.append('type', 'text'); {
role: 'user',
const sessionResponse = await $.http.post('/api/v1/sessions', formData, { content: {
headers: { content_type: 'text',
...formData.getHeaders(), parts: [$.step.parameters.input],
}, },
},
],
}); });
const sessionId = sessionResponse.data.id;
let chatGenerated = false;
while (!chatGenerated) {
const response = await $.http.get(`/api/v1/sessions/${sessionId}`);
const message =
response.data.interactions[response.data.interactions.length - 1];
if (message.creator === 'system' && message.state === 'complete') {
$.setActionItem({ $.setActionItem({
raw: message, raw: response.data,
}); });
chatGenerated = true;
}
}
}, },
}); });

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'; import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../../app.js'; import app from '../../../../../app.js';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
import { createUser } from '../../../../../../test/factories/user.js'; import { createUser } from '../../../../../../test/factories/user.js';
@@ -31,5 +32,21 @@ describe('GET /api/v1/admin/app-auth-clients/:appAuthClientId', () => {
const expectedPayload = getAdminAppAuthClientMock(currentAppAuthClient); const expectedPayload = getAdminAppAuthClientMock(currentAppAuthClient);
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing app auth client UUID', async () => {
const notExistingAppAuthClientUUID = Crypto.randomUUID();
await request(app)
.get(`/api/v1/admin/app-auth-clients/${notExistingAppAuthClientUUID}`)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
await request(app)
.get('/api/v1/admin/app-auth-clients/invalidAppAuthClientUUID')
.set('Authorization', token)
.expect(400);
});
}); });
}); });

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'; import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../../app.js'; import app from '../../../../../app.js';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
import { createRole } from '../../../../../../test/factories/role.js'; import { createRole } from '../../../../../../test/factories/role.js';
@@ -20,7 +21,7 @@ describe('GET /api/v1/admin/roles/:roleId', () => {
token = createAuthTokenByUserId(currentUser.id); token = createAuthTokenByUserId(currentUser.id);
}); });
it('should return roles', async () => { it('should return role', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true); vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const response = await request(app) const response = await request(app)
@@ -35,4 +36,24 @@ describe('GET /api/v1/admin/roles/:roleId', () => {
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing role UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const notExistingRoleUUID = Crypto.randomUUID();
await request(app)
.get(`/api/v1/admin/roles/${notExistingRoleUUID}`)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
await request(app)
.get('/api/v1/admin/roles/invalidRoleUUID')
.set('Authorization', token)
.expect(400);
});
}); });

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'; import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../../app.js'; import app from '../../../../../app.js';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
import { createRole } from '../../../../../../test/factories/role.js'; import { createRole } from '../../../../../../test/factories/role.js';
@@ -31,4 +32,26 @@ describe('GET /api/v1/admin/saml-auth-provider/:samlAuthProviderId', () => {
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing saml auth provider UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const notExistingSamlAuthProviderUUID = Crypto.randomUUID();
await request(app)
.get(
`/api/v1/admin/saml-auth-providers/${notExistingSamlAuthProviderUUID}`
)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
await request(app)
.get('/api/v1/admin/saml-auth-providers/invalidSamlAuthProviderUUID')
.set('Authorization', token)
.expect(400);
});
}); });

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'; import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../../app.js'; import app from '../../../../../app.js';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id';
import { createUser } from '../../../../../../test/factories/user'; import { createUser } from '../../../../../../test/factories/user';
@@ -31,4 +32,24 @@ describe('GET /api/v1/admin/users/:userId', () => {
const expectedPayload = getUserMock(anotherUser, anotherUserRole); const expectedPayload = getUserMock(anotherUser, anotherUserRole);
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing user UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const notExistingUserUUID = Crypto.randomUUID();
await request(app)
.get(`/api/v1/admin/users/${notExistingUserUUID}`)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
await request(app)
.get('/api/v1/admin/users/invalidUserUUID')
.set('Authorization', token)
.expect(400);
});
}); });

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest'; import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../app.js'; import app from '../../../../app.js';
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
import { createUser } from '../../../../../test/factories/user.js'; import { createUser } from '../../../../../test/factories/user.js';
@@ -28,4 +29,20 @@ describe('GET /api/v1/app-auth-clients/:id', () => {
const expectedPayload = getAppAuthClientMock(currentAppAuthClient); const expectedPayload = getAppAuthClientMock(currentAppAuthClient);
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing app auth client ID', async () => {
const notExistingAppAuthClientUUID = Crypto.randomUUID();
await request(app)
.get(`/api/v1/app-auth-clients/${notExistingAppAuthClientUUID}`)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
await request(app)
.get('/api/v1/app-auth-clients/invalidAppAuthClientUUID')
.set('Authorization', token)
.expect(400);
});
}); });

View File

@@ -0,0 +1,8 @@
import App from '../../../../models/app.js';
import { renderObject } from '../../../../helpers/renderer.js';
export default async (request, response) => {
const app = await App.findOneByKey(request.params.appKey);
renderObject(response, app, { serializer: 'App' });
};

View File

@@ -0,0 +1,35 @@
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import App from '../../../../models/app';
import app from '../../../../app.js';
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
import { createUser } from '../../../../../test/factories/user';
import getAppMock from '../../../../../test/mocks/rest/api/v1/apps/get-app.js';
describe('GET /api/v1/apps/:appKey', () => {
let currentUser, token;
beforeEach(async () => {
currentUser = await createUser();
token = createAuthTokenByUserId(currentUser.id);
});
it('should return the app info', async () => {
const exampleApp = await App.findOneByKey('github');
const response = await request(app)
.get(`/api/v1/apps/${exampleApp.key}`)
.set('Authorization', token)
.expect(200);
const expectedPayload = getAppMock(exampleApp);
expect(response.body).toEqual(expectedPayload);
});
it('should return not found response for invalid app key', async () => {
await request(app)
.get('/api/v1/apps/invalid-app-key')
.set('Authorization', token)
.expect(404);
});
});

View File

@@ -1,5 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest'; import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../app.js'; import app from '../../../../app.js';
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
import { createUser } from '../../../../../test/factories/user'; import { createUser } from '../../../../../test/factories/user';
@@ -68,4 +69,34 @@ describe('GET /api/v1/flows/:flowId', () => {
expect(response.body).toEqual(expectedPayload); expect(response.body).toEqual(expectedPayload);
}); });
it('should return not found response for not existing flow UUID', async () => {
await createPermission({
action: 'read',
subject: 'Flow',
roleId: currentUserRole.id,
conditions: [],
});
const notExistingFlowUUID = Crypto.randomUUID();
await request(app)
.get(`/api/v1/flows/${notExistingFlowUUID}`)
.set('Authorization', token)
.expect(404);
});
it('should return bad request response for invalid UUID', async () => {
await createPermission({
action: 'read',
subject: 'Flow',
roleId: currentUserRole.id,
conditions: [],
});
await request(app)
.get('/api/v1/flows/invalidFlowUUID')
.set('Authorization', token)
.expect(400);
});
}); });

View File

@@ -0,0 +1,16 @@
export async function up(knex) {
return knex.schema.createTable('datastore', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'));
table.string('key').notNullable();
table.string('value');
table.string('scope').notNullable();
table.uuid('scope_id').notNullable();
table.index(['key', 'scope', 'scope_id']);
table.timestamps(true, true);
});
}
export async function down(knex) {
return knex.schema.dropTable('datastore');
}

View File

@@ -1,14 +1,31 @@
import logger from './logger.js'; import logger from './logger.js';
import objection from 'objection';
const { NotFoundError, DataError } = objection;
// Do not remove `next` argument as the function signature will not fit for an error handler middleware // Do not remove `next` argument as the function signature will not fit for an error handler middleware
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const errorHandler = (err, req, res, next) => { const errorHandler = (error, request, response, next) => {
if (err.message === 'Not Found') { if (error.message === 'Not Found' || error instanceof NotFoundError) {
res.status(404).end(); response.status(404).end();
} else {
logger.error(err.message + '\n' + err.stack);
res.status(err.statusCode || 500).send(err.message);
} }
if (notFoundAppError(error)) {
response.status(404).end();
}
if (error instanceof DataError) {
response.status(400).end();
}
logger.error(error.message + '\n' + error.stack);
response.status(error.statusCode || 500).end();
};
const notFoundAppError = (error) => {
return (
error.message.includes('An application with the') ||
error.message.includes("key couldn't be found.")
);
}; };
export default errorHandler; export default errorHandler;

View File

@@ -1,6 +1,7 @@
import createHttpClient from './http-client/index.js'; import createHttpClient from './http-client/index.js';
import EarlyExitError from '../errors/early-exit.js'; import EarlyExitError from '../errors/early-exit.js';
import AlreadyProcessedError from '../errors/already-processed.js'; import AlreadyProcessedError from '../errors/already-processed.js';
import Datastore from '../models/datastore.js';
const globalVariable = async (options) => { const globalVariable = async (options) => {
const { const {
@@ -88,6 +89,43 @@ const globalVariable = async (options) => {
setActionItem: (actionItem) => { setActionItem: (actionItem) => {
$.actionOutput.data = actionItem; $.actionOutput.data = actionItem;
}, },
datastore: {
get: async ({ key }) => {
const datastore = await Datastore.query().findOne({
key,
scope: 'flow',
scope_id: $.flow.id,
});
return {
key: datastore.key,
value: datastore.value,
[datastore.key]: datastore.value,
};
},
set: async ({ key, value }) => {
let datastore = await Datastore.query()
.where({ key, scope: 'flow', scope_id: $.flow.id })
.first();
if (datastore) {
await datastore.$query().patchAndFetch({ value: value });
} else {
datastore = await Datastore.query().insert({
key,
value,
scope: 'flow',
scopeId: $.flow.id,
});
}
return {
key: datastore.key,
value: datastore.value,
[datastore.key]: datastore.value,
};
},
},
}; };
if (request) { if (request) {

View File

@@ -11,7 +11,7 @@ const isArray = (object) =>
const totalCount = (object) => const totalCount = (object) =>
isPaginated(object) ? object.totalCount : isArray(object) ? object.length : 1; isPaginated(object) ? object.totalCount : isArray(object) ? object.length : 1;
const renderObject = (response, object) => { const renderObject = (response, object, options) => {
let data = isPaginated(object) ? object.records : object; let data = isPaginated(object) ? object.records : object;
const type = isPaginated(object) const type = isPaginated(object)
@@ -20,7 +20,9 @@ const renderObject = (response, object) => {
? object?.[0]?.constructor?.name || 'Object' ? object?.[0]?.constructor?.name || 'Object'
: object.constructor.name; : object.constructor.name;
const serializer = serializers[type]; const serializer = options?.serializer
? serializers[options.serializer]
: serializers[type];
if (serializer) { if (serializer) {
data = Array.isArray(data) data = Array.isArray(data)

View File

@@ -0,0 +1,24 @@
import Base from './base.js';
class Datastore extends Base {
static tableName = 'datastore';
static jsonSchema = {
type: 'object',
required: ['key', 'value', 'scope', 'scopeId'],
properties: {
id: { type: 'string', format: 'uuid' },
key: { type: 'string', minLength: 1 },
value: { type: 'string' },
scope: {
type: 'string',
enum: ['flow'],
default: 'flow',
},
scopeId: { type: 'string', format: 'uuid' },
},
};
}
export default Datastore;

View File

@@ -0,0 +1,10 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../helpers/authentication.js';
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
const router = Router();
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
export default router;

View File

@@ -8,6 +8,7 @@ import usersRouter from './api/v1/users.js';
import paymentRouter from './api/v1/payment.ee.js'; import paymentRouter from './api/v1/payment.ee.js';
import appAuthClientsRouter from './api/v1/app-auth-clients.js'; import appAuthClientsRouter from './api/v1/app-auth-clients.js';
import flowsRouter from './api/v1/flows.js'; import flowsRouter from './api/v1/flows.js';
import appsRouter from './api/v1/apps.js';
import samlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js'; import samlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
import rolesRouter from './api/v1/admin/roles.ee.js'; import rolesRouter from './api/v1/admin/roles.ee.js';
import permissionsRouter from './api/v1/admin/permissions.ee.js'; import permissionsRouter from './api/v1/admin/permissions.ee.js';
@@ -25,6 +26,7 @@ router.use('/api/v1/users', usersRouter);
router.use('/api/v1/payment', paymentRouter); router.use('/api/v1/payment', paymentRouter);
router.use('/api/v1/app-auth-clients', appAuthClientsRouter); router.use('/api/v1/app-auth-clients', appAuthClientsRouter);
router.use('/api/v1/flows', flowsRouter); router.use('/api/v1/flows', flowsRouter);
router.use('/api/v1/apps', appsRouter);
router.use('/api/v1/admin/saml-auth-providers', samlAuthProvidersRouter); router.use('/api/v1/admin/saml-auth-providers', samlAuthProvidersRouter);
router.use('/api/v1/admin/roles', rolesRouter); router.use('/api/v1/admin/roles', rolesRouter);
router.use('/api/v1/admin/permissions', permissionsRouter); router.use('/api/v1/admin/permissions', permissionsRouter);

View File

@@ -0,0 +1,12 @@
const appSerializer = (app) => {
return {
name: app.name,
key: app.key,
iconUrl: app.iconUrl,
authDocUrl: app.authDocUrl,
supportsConnections: app.supportsConnections,
primaryColor: app.primaryColor,
};
};
export default appSerializer;

View File

@@ -0,0 +1,20 @@
import { describe, it, expect } from 'vitest';
import App from '../models/app';
import appSerializer from './app';
describe('appSerializer', () => {
it('should return permission data', async () => {
const app = await App.findOneByKey('deepl');
const expectedPayload = {
name: app.name,
key: app.key,
iconUrl: app.iconUrl,
authDocUrl: app.authDocUrl,
supportsConnections: app.supportsConnections,
primaryColor: app.primaryColor,
};
expect(appSerializer(app)).toEqual(expectedPayload);
});
});

View File

@@ -5,6 +5,7 @@ import samlAuthProviderSerializer from './saml-auth-provider.ee.js';
import appAuthClientSerializer from './app-auth-client.js'; import appAuthClientSerializer from './app-auth-client.js';
import flowSerializer from './flow.js'; import flowSerializer from './flow.js';
import stepSerializer from './step.js'; import stepSerializer from './step.js';
import appSerializer from './app.js';
const serializers = { const serializers = {
User: userSerializer, User: userSerializer,
@@ -14,6 +15,7 @@ const serializers = {
AppAuthClient: appAuthClientSerializer, AppAuthClient: appAuthClientSerializer,
Flow: flowSerializer, Flow: flowSerializer,
Step: stepSerializer, Step: stepSerializer,
App: appSerializer,
}; };
export default serializers; export default serializers;

View File

@@ -5,8 +5,8 @@ const permissionSerializer = (permission) => {
action: permission.action, action: permission.action,
subject: permission.subject, subject: permission.subject,
conditions: permission.conditions, conditions: permission.conditions,
createdAt: permission.createdAt, createdAt: permission.createdAt.getTime(),
updatedAt: permission.updatedAt, updatedAt: permission.updatedAt.getTime(),
}; };
}; };

View File

@@ -16,8 +16,8 @@ describe('permissionSerializer', () => {
action: permission.action, action: permission.action,
subject: permission.subject, subject: permission.subject,
conditions: permission.conditions, conditions: permission.conditions,
createdAt: permission.createdAt, createdAt: permission.createdAt.getTime(),
updatedAt: permission.updatedAt, updatedAt: permission.updatedAt.getTime(),
}; };
expect(permissionSerializer(permission)).toEqual(expectedPayload); expect(permissionSerializer(permission)).toEqual(expectedPayload);

View File

@@ -6,8 +6,8 @@ const roleSerializer = (role) => {
name: role.name, name: role.name,
key: role.key, key: role.key,
description: role.description, description: role.description,
createdAt: role.createdAt, createdAt: role.createdAt.getTime(),
updatedAt: role.updatedAt, updatedAt: role.updatedAt.getTime(),
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
}; };

View File

@@ -29,8 +29,8 @@ describe('roleSerializer', () => {
name: role.name, name: role.name,
key: role.key, key: role.key,
description: role.description, description: role.description,
createdAt: role.createdAt, createdAt: role.createdAt.getTime(),
updatedAt: role.updatedAt, updatedAt: role.updatedAt.getTime(),
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
}; };

View File

@@ -6,8 +6,8 @@ const userSerializer = (user) => {
let userData = { let userData = {
id: user.id, id: user.id,
email: user.email, email: user.email,
createdAt: user.createdAt, createdAt: user.createdAt.getTime(),
updatedAt: user.updatedAt, updatedAt: user.updatedAt.getTime(),
fullName: user.fullName, fullName: user.fullName,
}; };

View File

@@ -31,11 +31,11 @@ describe('userSerializer', () => {
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false); vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
const expectedPayload = { const expectedPayload = {
createdAt: user.createdAt, createdAt: user.createdAt.getTime(),
email: user.email, email: user.email,
fullName: user.fullName, fullName: user.fullName,
id: user.id, id: user.id,
updatedAt: user.updatedAt, updatedAt: user.updatedAt.getTime(),
}; };
expect(userSerializer(user)).toEqual(expectedPayload); expect(userSerializer(user)).toEqual(expectedPayload);
@@ -67,7 +67,7 @@ describe('userSerializer', () => {
it('should return user data with trial expiry date', async () => { it('should return user data with trial expiry date', async () => {
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true); vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
await user.$query().patch({ await user.$query().patchAndFetch({
trialExpiryDate: DateTime.now().plus({ days: 30 }).toISODate(), trialExpiryDate: DateTime.now().plus({ days: 30 }).toISODate(),
}); });

View File

@@ -5,16 +5,16 @@ const getRoleMock = async (role, permissions) => {
name: role.name, name: role.name,
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
description: role.description, description: role.description,
createdAt: role.createdAt.toISOString(), createdAt: role.createdAt.getTime(),
updatedAt: role.updatedAt.toISOString(), updatedAt: role.updatedAt.getTime(),
permissions: permissions.map((permission) => ({ permissions: permissions.map((permission) => ({
id: permission.id, id: permission.id,
action: permission.action, action: permission.action,
conditions: permission.conditions, conditions: permission.conditions,
roleId: permission.roleId, roleId: permission.roleId,
subject: permission.subject, subject: permission.subject,
createdAt: permission.createdAt.toISOString(), createdAt: permission.createdAt.getTime(),
updatedAt: permission.updatedAt.toISOString(), updatedAt: permission.updatedAt.getTime(),
})), })),
}; };

View File

@@ -6,8 +6,8 @@ const getRolesMock = async (roles) => {
name: role.name, name: role.name,
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
description: role.description, description: role.description,
createdAt: role.createdAt.toISOString(), createdAt: role.createdAt.getTime(),
updatedAt: role.updatedAt.toISOString(), updatedAt: role.updatedAt.getTime(),
}; };
}); });

View File

@@ -1,21 +1,21 @@
const getUserMock = (currentUser, role) => { const getUserMock = (currentUser, role) => {
return { return {
data: { data: {
createdAt: currentUser.createdAt.toISOString(), createdAt: currentUser.createdAt.getTime(),
email: currentUser.email, email: currentUser.email,
fullName: currentUser.fullName, fullName: currentUser.fullName,
id: currentUser.id, id: currentUser.id,
role: { role: {
createdAt: role.createdAt.toISOString(), createdAt: role.createdAt.getTime(),
description: null, description: null,
id: role.id, id: role.id,
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
key: role.key, key: role.key,
name: role.name, name: role.name,
updatedAt: role.updatedAt.toISOString(), updatedAt: role.updatedAt.getTime(),
}, },
trialExpiryDate: currentUser.trialExpiryDate.toISOString(), trialExpiryDate: currentUser.trialExpiryDate.toISOString(),
updatedAt: currentUser.updatedAt.toISOString(), updatedAt: currentUser.updatedAt.getTime(),
}, },
meta: { meta: {
count: 1, count: 1,

View File

@@ -3,23 +3,23 @@ const getUsersMock = async (users, roles) => {
const role = roles.find((r) => r.id === user.roleId); const role = roles.find((r) => r.id === user.roleId);
return { return {
createdAt: user.createdAt.toISOString(), createdAt: user.createdAt.getTime(),
email: user.email, email: user.email,
fullName: user.fullName, fullName: user.fullName,
id: user.id, id: user.id,
role: role role: role
? { ? {
createdAt: role.createdAt.toISOString(), createdAt: role.createdAt.getTime(),
description: role.description, description: role.description,
id: role.id, id: role.id,
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
key: role.key, key: role.key,
name: role.name, name: role.name,
updatedAt: role.updatedAt.toISOString(), updatedAt: role.updatedAt.getTime(),
} }
: null, : null,
trialExpiryDate: user.trialExpiryDate.toISOString(), trialExpiryDate: user.trialExpiryDate.toISOString(),
updatedAt: user.updatedAt.toISOString(), updatedAt: user.updatedAt.getTime(),
}; };
}); });

View File

@@ -0,0 +1,21 @@
const getAppMock = (app) => {
return {
data: {
authDocUrl: app.authDocUrl,
iconUrl: app.iconUrl,
key: app.key,
name: app.name,
primaryColor: app.primaryColor,
supportsConnections: app.supportsConnections,
},
meta: {
count: 1,
currentPage: null,
isArray: false,
totalPages: null,
type: 'Object',
},
};
};
export default getAppMock;

View File

@@ -1,22 +1,22 @@
const getCurrentUserMock = (currentUser, role) => { const getCurrentUserMock = (currentUser, role) => {
return { return {
data: { data: {
createdAt: currentUser.createdAt.toISOString(), createdAt: currentUser.createdAt.getTime(),
email: currentUser.email, email: currentUser.email,
fullName: currentUser.fullName, fullName: currentUser.fullName,
id: currentUser.id, id: currentUser.id,
permissions: [], permissions: [],
role: { role: {
createdAt: role.createdAt.toISOString(), createdAt: role.createdAt.getTime(),
description: null, description: null,
id: role.id, id: role.id,
isAdmin: role.isAdmin, isAdmin: role.isAdmin,
key: role.key, key: role.key,
name: role.name, name: role.name,
updatedAt: role.updatedAt.toISOString(), updatedAt: role.updatedAt.getTime(),
}, },
trialExpiryDate: currentUser.trialExpiryDate.toISOString(), trialExpiryDate: currentUser.trialExpiryDate.toISOString(),
updatedAt: currentUser.updatedAt.toISOString(), updatedAt: currentUser.updatedAt.getTime(),
}, },
meta: { meta: {
count: 1, count: 1,

View File

@@ -41,6 +41,15 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/carbone/connection' }, { text: 'Connection', link: '/apps/carbone/connection' },
], ],
}, },
{
text: 'Datastore',
collapsible: true,
collapsed: true,
items: [
{ text: 'Actions', link: '/apps/datastore/actions' },
{ text: 'Connection', link: '/apps/datastore/connection' },
],
},
{ {
text: 'DeepL', text: 'DeepL',
collapsible: true, collapsible: true,
@@ -73,7 +82,6 @@ export default defineConfig({
collapsible: true, collapsible: true,
collapsed: true, collapsed: true,
items: [ items: [
{ text: 'Triggers', link: '/apps/dropbox/triggers' },
{ text: 'Actions', link: '/apps/dropbox/actions' }, { text: 'Actions', link: '/apps/dropbox/actions' },
{ text: 'Connection', link: '/apps/dropbox/connection' }, { text: 'Connection', link: '/apps/dropbox/connection' },
], ],

View File

@@ -0,0 +1,14 @@
---
favicon: /favicons/datastore.svg
items:
- name: Get value
desc: Get value from the persistent datastore.
- name: Set value
desc: Set value to the persistent datastore.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,3 @@
# Datastore
Datastore is a persistent key-value storage system that allows you to store and retrieve data. Currently you can use it within the scope of the flow, meaning you can store and retrieve data within the same flow.

View File

@@ -3,8 +3,6 @@ favicon: /favicons/dropbox.svg
items: items:
- name: Create a folder - name: Create a folder
desc: Creates a new folder with the given parent folder and folder name. desc: Creates a new folder with the given parent folder and folder name.
- name: Create a text file
desc: Create a new text file from plain text content you specify.
- name: Rename a file - name: Rename a file
desc: Rename a file with the given file path and new name. desc: Rename a file with the given file path and new name.
--- ---

View File

@@ -1,12 +0,0 @@
---
favicon: /favicons/dropbox.svg
items:
- name: New folders
desc: Triggers when any new folder is added. Ensure that the number of files/folders within the monitored directory remains below 4000.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" width="800px" height="800px" viewBox="0 0 32 32" id="icon">
<defs>
<style>.cls-1{fill:none;}</style>
</defs>
<title>datastore</title>
<circle cx="23" cy="23" r="1"/>
<rect x="8" y="22" width="12" height="2"/>
<circle cx="23" cy="9" r="1"/>
<rect x="8" y="8" width="12" height="2"/>
<path d="M26,14a2,2,0,0,0,2-2V6a2,2,0,0,0-2-2H6A2,2,0,0,0,4,6v6a2,2,0,0,0,2,2H8v4H6a2,2,0,0,0-2,2v6a2,2,0,0,0,2,2H26a2,2,0,0,0,2-2V20a2,2,0,0,0-2-2H24V14ZM6,6H26v6H6ZM26,26H6V20H26Zm-4-8H10V14H22Z"/>
<rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32" height="32"/>
</svg>

After

Width:  |  Height:  |  Size: 704 B