Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
465dc8ba38 |
@@ -6,7 +6,8 @@
|
|||||||
"start": "lerna run --stream --parallel --scope=@*/{web,backend} dev",
|
"start": "lerna run --stream --parallel --scope=@*/{web,backend} dev",
|
||||||
"start:web": "lerna run --stream --scope=@*/web dev",
|
"start:web": "lerna run --stream --scope=@*/web dev",
|
||||||
"start:backend": "lerna run --stream --scope=@*/backend dev",
|
"start:backend": "lerna run --stream --scope=@*/backend dev",
|
||||||
"lint": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend} lint",
|
"lint": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend,cli} lint",
|
||||||
|
"build:watch": "lerna run --no-bail --stream --parallel --scope=@*/{web,backend,cli} build:watch",
|
||||||
"build:docs": "cd ./packages/docs && yarn install && yarn build"
|
"build:docs": "cd ./packages/docs && yarn install && yarn build"
|
||||||
},
|
},
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
|
||||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
|
||||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="200.000000pt" height="200.000000pt" viewBox="0 0 200.000000 200.000000"
|
|
||||||
preserveAspectRatio="xMidYMid meet">
|
|
||||||
|
|
||||||
<g transform="translate(0.000000,200.000000) scale(0.100000,-0.100000)"
|
|
||||||
fill="#000" stroke="none">
|
|
||||||
<path d="M0 1000 l0 -1000 1000 0 1000 0 0 1000 0 1000 -1000 0 -1000 0 0
|
|
||||||
-1000z m1162 460 c14 -11 113 -184 232 -408 228 -429 231 -439 175 -486 -35
|
|
||||||
-30 -30 -29 -140 -15 -89 12 -123 25 -152 56 -9 11 -72 147 -140 304 -113 263
|
|
||||||
-124 284 -149 287 -14 2 -29 10 -32 17 -8 21 67 214 94 242 28 29 78 30 112 3z
|
|
||||||
m-340 -148 c10 -10 72 -175 139 -367 114 -325 121 -351 108 -374 -8 -14 -27
|
|
||||||
-32 -41 -41 -25 -13 -34 -12 -126 18 -55 18 -111 43 -125 56 -19 17 -40 67
|
|
||||||
-76 182 -36 112 -58 164 -73 176 l-22 16 27 99 c63 224 66 232 95 248 31 17
|
|
||||||
69 12 94 -13z m-314 -219 c16 -15 26 -59 56 -243 42 -262 43 -285 17 -300 -11
|
|
||||||
-5 -24 -10 -30 -10 -19 0 -140 114 -150 141 -7 20 -4 76 10 191 10 90 19 171
|
|
||||||
19 181 0 18 33 57 49 57 5 0 18 -8 29 -17z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1,33 +0,0 @@
|
|||||||
import verifyCredentials from './verify-credentials.js';
|
|
||||||
import isStillVerified from './is-still-verified.js';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
key: 'screenName',
|
|
||||||
label: 'Screen Name',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
readOnly: false,
|
|
||||||
value: null,
|
|
||||||
placeholder: null,
|
|
||||||
description:
|
|
||||||
'Screen name of your connection to be used on Automatisch UI.',
|
|
||||||
clickToCopy: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'apiKey',
|
|
||||||
label: 'API Key',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
readOnly: false,
|
|
||||||
value: null,
|
|
||||||
placeholder: null,
|
|
||||||
description: 'Better Stack API key of your account.',
|
|
||||||
clickToCopy: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
verifyCredentials,
|
|
||||||
isStillVerified,
|
|
||||||
};
|
|
@@ -1,8 +0,0 @@
|
|||||||
import verifyCredentials from './verify-credentials.js';
|
|
||||||
|
|
||||||
const isStillVerified = async ($) => {
|
|
||||||
await verifyCredentials($);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isStillVerified;
|
|
@@ -1,10 +0,0 @@
|
|||||||
const verifyCredentials = async ($) => {
|
|
||||||
await $.http.get('/v2/metadata');
|
|
||||||
|
|
||||||
await $.auth.set({
|
|
||||||
screenName: $.auth.data.screenName,
|
|
||||||
apiKey: $.auth.data.apiKey,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default verifyCredentials;
|
|
@@ -1,9 +0,0 @@
|
|||||||
const addAuthHeader = ($, requestConfig) => {
|
|
||||||
if ($.auth.data?.apiKey) {
|
|
||||||
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default addAuthHeader;
|
|
@@ -1,16 +0,0 @@
|
|||||||
import defineApp from '../../helpers/define-app.js';
|
|
||||||
import addAuthHeader from './common/add-auth-header.js';
|
|
||||||
import auth from './auth/index.js';
|
|
||||||
|
|
||||||
export default defineApp({
|
|
||||||
name: 'Better Stack',
|
|
||||||
key: 'better-stack',
|
|
||||||
iconUrl: '{BASE_URL}/apps/better-stack/assets/favicon.svg',
|
|
||||||
authDocUrl: 'https://automatisch.io/docs/apps/better-stack/connection',
|
|
||||||
supportsConnections: true,
|
|
||||||
baseUrl: 'https://betterstack.com',
|
|
||||||
apiBaseUrl: 'https://uptime.betterstack.com/api',
|
|
||||||
primaryColor: '000000',
|
|
||||||
beforeRequest: [addAuthHeader],
|
|
||||||
auth,
|
|
||||||
});
|
|
@@ -1,5 +1,11 @@
|
|||||||
import createDatabaseItem from './create-database-item/index.js';
|
import createDatabaseItem from './create-database-item/index.js';
|
||||||
import createPage from './create-page/index.js';
|
import createPage from './create-page/index.js';
|
||||||
import findDatabaseItem from './find-database-item/index.js';
|
import findDatabaseItem from './find-database-item/index.js';
|
||||||
|
import updateDatabaseItem from './update-database-item/index.js';
|
||||||
|
|
||||||
export default [createDatabaseItem, createPage, findDatabaseItem];
|
export default [
|
||||||
|
createDatabaseItem,
|
||||||
|
createPage,
|
||||||
|
findDatabaseItem,
|
||||||
|
updateDatabaseItem,
|
||||||
|
];
|
||||||
|
@@ -0,0 +1,157 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Update database item',
|
||||||
|
key: 'updateDatabaseItem',
|
||||||
|
description: 'Updates a database item.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Database',
|
||||||
|
key: 'databaseId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listDatabases',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Item',
|
||||||
|
key: 'itemId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
dependsOn: ['parameters.databaseId'],
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listDatabaseItems',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.databaseId',
|
||||||
|
value: '{parameters.databaseId}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Name',
|
||||||
|
key: 'name',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'This field has a 2000 character limit. Any characters beyond 2000 will not be included.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Tags',
|
||||||
|
key: 'tags',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Tag',
|
||||||
|
key: 'tag',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
dependsOn: ['parameters.databaseId'],
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listTags',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.databaseId',
|
||||||
|
value: '{parameters.databaseId}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Content',
|
||||||
|
key: 'content',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'You can choose to add extra text to the database item, with a limit of up to 2000 characters if desired.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const itemId = $.step.parameters.itemId;
|
||||||
|
const name = $.step.parameters.name;
|
||||||
|
const truncatedName = name.slice(0, 2000);
|
||||||
|
const content = $.step.parameters.content;
|
||||||
|
const truncatedContent = content.slice(0, 2000);
|
||||||
|
const tags = $.step.parameters.tags;
|
||||||
|
const formattedTags = tags
|
||||||
|
.filter((tag) => tag.tag !== '')
|
||||||
|
.map((tag) => tag.tag);
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
properties: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (truncatedName) {
|
||||||
|
body.properties.Name = {
|
||||||
|
title: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: truncatedName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formattedTags?.length) {
|
||||||
|
body.properties.Tags = {
|
||||||
|
multi_select: formattedTags.map((tag) => ({ name: tag })),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (truncatedContent) {
|
||||||
|
const response = await $.http.get(`/v1/blocks/${itemId}/children`);
|
||||||
|
const firstBlockId = response.data.results[0].id;
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
paragraph: {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: {
|
||||||
|
content: truncatedContent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
await $.http.patch(`/v1/blocks/${firstBlockId}`, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await $.http.patch(`/v1/pages/${itemId}`, body);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,4 +1,6 @@
|
|||||||
|
import listDatabaseItems from './list-database-items/index.js';
|
||||||
import listDatabases from './list-databases/index.js';
|
import listDatabases from './list-databases/index.js';
|
||||||
import listParentPages from './list-parent-pages/index.js';
|
import listParentPages from './list-parent-pages/index.js';
|
||||||
|
import listTags from './list-tags/index.js';
|
||||||
|
|
||||||
export default [listDatabases, listParentPages];
|
export default [listDatabaseItems, listDatabases, listParentPages, listTags];
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List database items',
|
||||||
|
key: 'listDatabaseItems',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const databases = {
|
||||||
|
data: [],
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
const payload = {
|
||||||
|
start_cursor: undefined,
|
||||||
|
};
|
||||||
|
const databaseId = $.step.parameters.databaseId;
|
||||||
|
|
||||||
|
if (!databaseId) {
|
||||||
|
return databases;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
const response = await $.http.post(
|
||||||
|
`/v1/databases/${databaseId}/query`,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
payload.start_cursor = response.data.next_cursor;
|
||||||
|
|
||||||
|
for (const database of response.data.results) {
|
||||||
|
databases.data.push({
|
||||||
|
value: database.id,
|
||||||
|
name:
|
||||||
|
database.properties.Name?.title?.[0]?.plain_text || 'Untitled Page',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} while (payload.start_cursor);
|
||||||
|
|
||||||
|
return databases;
|
||||||
|
},
|
||||||
|
};
|
@@ -22,7 +22,7 @@ export default {
|
|||||||
for (const database of response.data.results) {
|
for (const database of response.data.results) {
|
||||||
databases.data.push({
|
databases.data.push({
|
||||||
value: database.id,
|
value: database.id,
|
||||||
name: database.title[0].plain_text,
|
name: database.title?.[0]?.plain_text || 'Untitled Database',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (payload.start_cursor);
|
} while (payload.start_cursor);
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List tags',
|
||||||
|
key: 'listTags',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const tags = {
|
||||||
|
data: [],
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
const databaseId = $.step.parameters.databaseId;
|
||||||
|
let allTags;
|
||||||
|
|
||||||
|
if (!databaseId) {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await $.http.get(`/v1/databases/${databaseId}`);
|
||||||
|
const tagsExist =
|
||||||
|
response.data.properties.Tags.multi_select.options.length !== 0;
|
||||||
|
|
||||||
|
if (tagsExist) {
|
||||||
|
allTags = response.data.properties.Tags.multi_select.options.map(
|
||||||
|
(tag) => tag.name
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const tag of allTags) {
|
||||||
|
tags.data.push({
|
||||||
|
value: tag,
|
||||||
|
name: tag,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
},
|
||||||
|
};
|
@@ -6,6 +6,31 @@ import { createRole } from '../../../test/factories/role';
|
|||||||
import { createUser } from '../../../test/factories/user';
|
import { createUser } from '../../../test/factories/user';
|
||||||
|
|
||||||
describe('graphQL getCurrentUser query', () => {
|
describe('graphQL getCurrentUser query', () => {
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const invalidUserToken = 'invalid-token';
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getCurrentUser {
|
||||||
|
id
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidUserToken)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
let role, currentUser, token, requestObject;
|
let role, currentUser, token, requestObject;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -76,4 +101,5 @@ describe('graphQL getCurrentUser query', () => {
|
|||||||
'Cannot query field "password" on type "User".'
|
'Cannot query field "password" on type "User".'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -40,7 +40,23 @@ describe('graphQL getExecutions query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
describe('and without correct permissions', () => {
|
const invalidToken = 'invalid-token';
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const userWithoutPermissions = await createUser();
|
const userWithoutPermissions = await createUser();
|
||||||
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
@@ -469,4 +485,5 @@ describe('graphQL getExecutions query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -40,6 +40,23 @@ describe('graphQL getFlow query', () => {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const invalidToken = 'invalid-token';
|
||||||
|
const flow = await createFlow();
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query: query(flow.id) })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
describe('and without permissions', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const userWithoutPermissions = await createUser();
|
const userWithoutPermissions = await createUser();
|
||||||
@@ -128,7 +145,9 @@ describe('graphQL getFlow query', () => {
|
|||||||
{
|
{
|
||||||
appKey: actionStep.appKey,
|
appKey: actionStep.appKey,
|
||||||
connection: {
|
connection: {
|
||||||
createdAt: actionConnection.createdAt.getTime().toString(),
|
createdAt: actionConnection.createdAt
|
||||||
|
.getTime()
|
||||||
|
.toString(),
|
||||||
id: actionConnection.id,
|
id: actionConnection.id,
|
||||||
verified: actionConnection.verified,
|
verified: actionConnection.verified,
|
||||||
},
|
},
|
||||||
@@ -215,7 +234,9 @@ describe('graphQL getFlow query', () => {
|
|||||||
{
|
{
|
||||||
appKey: actionStep.appKey,
|
appKey: actionStep.appKey,
|
||||||
connection: {
|
connection: {
|
||||||
createdAt: actionConnection.createdAt.getTime().toString(),
|
createdAt: actionConnection.createdAt
|
||||||
|
.getTime()
|
||||||
|
.toString(),
|
||||||
id: actionConnection.id,
|
id: actionConnection.id,
|
||||||
verified: actionConnection.verified,
|
verified: actionConnection.verified,
|
||||||
},
|
},
|
||||||
@@ -237,4 +258,5 @@ describe('graphQL getFlow query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -17,6 +17,7 @@ describe('graphQL getRole query', () => {
|
|||||||
userWithoutPermissions,
|
userWithoutPermissions,
|
||||||
tokenWithPermissions,
|
tokenWithPermissions,
|
||||||
tokenWithoutPermissions,
|
tokenWithoutPermissions,
|
||||||
|
invalidToken,
|
||||||
permissionOne,
|
permissionOne,
|
||||||
permissionTwo;
|
permissionTwo;
|
||||||
|
|
||||||
@@ -73,8 +74,24 @@ describe('graphQL getRole query', () => {
|
|||||||
tokenWithoutPermissions = createAuthTokenByUserId(
|
tokenWithoutPermissions = createAuthTokenByUserId(
|
||||||
userWithoutPermissions.id
|
userWithoutPermissions.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
invalidToken = 'invalid-token';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query: queryWithValidRole })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
describe('and with valid license', () => {
|
describe('and with valid license', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
@@ -161,4 +178,5 @@ describe('graphQL getRole query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,8 @@ describe('graphQL getRoles query', () => {
|
|||||||
userWithPermissions,
|
userWithPermissions,
|
||||||
userWithoutPermissions,
|
userWithoutPermissions,
|
||||||
tokenWithPermissions,
|
tokenWithPermissions,
|
||||||
tokenWithoutPermissions;
|
tokenWithoutPermissions,
|
||||||
|
invalidToken;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUserRole = await createRole({ name: 'Current user role' });
|
currentUserRole = await createRole({ name: 'Current user role' });
|
||||||
@@ -52,8 +53,24 @@ describe('graphQL getRoles query', () => {
|
|||||||
tokenWithoutPermissions = createAuthTokenByUserId(
|
tokenWithoutPermissions = createAuthTokenByUserId(
|
||||||
userWithoutPermissions.id
|
userWithoutPermissions.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
invalidToken = 'invalid-token';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
describe('and with valid license', () => {
|
describe('and with valid license', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
@@ -131,4 +148,5 @@ describe('graphQL getRoles query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -16,6 +16,22 @@ describe('graphQL getTrialStatus query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const invalidToken = 'invalid-token';
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
let user, userToken;
|
let user, userToken;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -97,4 +113,5 @@ describe('graphQL getTrialStatus query', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -8,6 +8,31 @@ import { createPermission } from '../../../test/factories/permission';
|
|||||||
import { createUser } from '../../../test/factories/user';
|
import { createUser } from '../../../test/factories/user';
|
||||||
|
|
||||||
describe('graphQL getUser query', () => {
|
describe('graphQL getUser query', () => {
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const invalidUserId = '123123123';
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getUser(id: "${invalidUserId}") {
|
||||||
|
id
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', 'invalid-token')
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
describe('and without permissions', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const userWithoutPermissions = await createUser();
|
const userWithoutPermissions = await createUser();
|
||||||
@@ -59,7 +84,9 @@ describe('graphQL getUser query', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
requestObject = request(app).post('/graphql').set('Authorization', token);
|
requestObject = request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return user data for a valid user id', async () => {
|
it('should return user data for a valid user id', async () => {
|
||||||
@@ -143,4 +170,5 @@ describe('graphQL getUser query', () => {
|
|||||||
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
expect(response.body.errors[0].message).toEqual('NotFoundError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -30,6 +30,20 @@ describe('graphQL getUsers query', () => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', 'invalid-token')
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
describe('and without permissions', () => {
|
describe('and without permissions', () => {
|
||||||
it('should throw not authorized error', async () => {
|
it('should throw not authorized error', async () => {
|
||||||
const userWithoutPermissions = await createUser();
|
const userWithoutPermissions = await createUser();
|
||||||
@@ -72,7 +86,9 @@ describe('graphQL getUsers query', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
requestObject = request(app).post('/graphql').set('Authorization', token);
|
requestObject = request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return users data', async () => {
|
it('should return users data', async () => {
|
||||||
@@ -145,4 +161,5 @@ describe('graphQL getUsers query', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -3,7 +3,7 @@ import jwt from 'jsonwebtoken';
|
|||||||
import appConfig from '../config/app.js';
|
import appConfig from '../config/app.js';
|
||||||
import User from '../models/user.js';
|
import User from '../models/user.js';
|
||||||
|
|
||||||
export const isAuthenticated = async (_parent, _args, req) => {
|
const isAuthenticated = rule()(async (_parent, _args, req) => {
|
||||||
const token = req.headers['authorization'];
|
const token = req.headers['authorization'];
|
||||||
|
|
||||||
if (token == null) return false;
|
if (token == null) return false;
|
||||||
@@ -26,13 +26,12 @@ export const isAuthenticated = async (_parent, _args, req) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const isAuthenticatedRule = rule()(isAuthenticated);
|
const authentication = shield(
|
||||||
|
{
|
||||||
export const authenticationRules = {
|
|
||||||
Query: {
|
Query: {
|
||||||
'*': isAuthenticatedRule,
|
'*': isAuthenticated,
|
||||||
getAutomatischInfo: allow,
|
getAutomatischInfo: allow,
|
||||||
getConfig: allow,
|
getConfig: allow,
|
||||||
getNotifications: allow,
|
getNotifications: allow,
|
||||||
@@ -40,18 +39,16 @@ export const authenticationRules = {
|
|||||||
listSamlAuthProviders: allow,
|
listSamlAuthProviders: allow,
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
'*': isAuthenticatedRule,
|
'*': isAuthenticated,
|
||||||
forgotPassword: allow,
|
forgotPassword: allow,
|
||||||
login: allow,
|
login: allow,
|
||||||
registerUser: allow,
|
registerUser: allow,
|
||||||
resetPassword: allow,
|
resetPassword: allow,
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
{
|
||||||
const authenticationOptions = {
|
|
||||||
allowExternalErrors: true,
|
allowExternalErrors: true,
|
||||||
};
|
}
|
||||||
|
);
|
||||||
const authentication = shield(authenticationRules, authenticationOptions);
|
|
||||||
|
|
||||||
export default authentication;
|
export default authentication;
|
||||||
|
@@ -1,78 +0,0 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest';
|
|
||||||
import { allow } from 'graphql-shield';
|
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import User from '../models/user.js';
|
|
||||||
import { isAuthenticated, authenticationRules } from './authentication.js';
|
|
||||||
|
|
||||||
vi.mock('jsonwebtoken');
|
|
||||||
vi.mock('../models/user.js');
|
|
||||||
|
|
||||||
describe('isAuthenticated', () => {
|
|
||||||
it('should return false if no token is provided', async () => {
|
|
||||||
const req = { headers: {} };
|
|
||||||
expect(await isAuthenticated(null, null, req)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if token is invalid', async () => {
|
|
||||||
jwt.verify.mockImplementation(() => {
|
|
||||||
throw new Error('invalid token');
|
|
||||||
});
|
|
||||||
|
|
||||||
const req = { headers: { authorization: 'invalidToken' } };
|
|
||||||
expect(await isAuthenticated(null, null, req)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if token is valid', async () => {
|
|
||||||
jwt.verify.mockReturnValue({ userId: '123' });
|
|
||||||
|
|
||||||
User.query.mockReturnValue({
|
|
||||||
findById: vi.fn().mockReturnValue({
|
|
||||||
leftJoinRelated: vi.fn().mockReturnThis(),
|
|
||||||
withGraphFetched: vi
|
|
||||||
.fn()
|
|
||||||
.mockResolvedValue({ id: '123', role: {}, permissions: {} }),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const req = { headers: { authorization: 'validToken' } };
|
|
||||||
expect(await isAuthenticated(null, null, req)).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('authentication rules', () => {
|
|
||||||
const getQueryAndMutationNames = (rules) => {
|
|
||||||
const queries = Object.keys(rules.Query || {});
|
|
||||||
const mutations = Object.keys(rules.Mutation || {});
|
|
||||||
return { queries, mutations };
|
|
||||||
};
|
|
||||||
|
|
||||||
const { queries, mutations } = getQueryAndMutationNames(authenticationRules);
|
|
||||||
|
|
||||||
describe('for queries', () => {
|
|
||||||
queries.forEach((query) => {
|
|
||||||
it(`should apply correct rule for query: ${query}`, () => {
|
|
||||||
const ruleApplied = authenticationRules.Query[query];
|
|
||||||
|
|
||||||
if (query === '*') {
|
|
||||||
expect(ruleApplied.func).toBe(isAuthenticated);
|
|
||||||
} else {
|
|
||||||
expect(ruleApplied).toEqual(allow);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('for mutations', () => {
|
|
||||||
mutations.forEach((mutation) => {
|
|
||||||
it(`should apply correct rule for mutation: ${mutation}`, () => {
|
|
||||||
const ruleApplied = authenticationRules.Mutation[mutation];
|
|
||||||
|
|
||||||
if (mutation === '*') {
|
|
||||||
expect(ruleApplied.func).toBe(isAuthenticated);
|
|
||||||
} else {
|
|
||||||
expect(ruleApplied).toBe(allow);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -32,14 +32,6 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
sidebar: {
|
sidebar: {
|
||||||
'/apps/': [
|
'/apps/': [
|
||||||
{
|
|
||||||
text: 'Better Stack',
|
|
||||||
collapsible: true,
|
|
||||||
collapsed: true,
|
|
||||||
items: [
|
|
||||||
{ text: 'Connection', link: '/apps/better-stack/connection' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text: 'Carbone',
|
text: 'Carbone',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
@@ -313,7 +305,7 @@ export default defineConfig({
|
|||||||
collapsed: true,
|
collapsed: true,
|
||||||
items: [
|
items: [
|
||||||
{ text: 'Actions', link: '/apps/removebg/actions' },
|
{ text: 'Actions', link: '/apps/removebg/actions' },
|
||||||
{ text: 'Connection', link: '/apps/removebg/connection' },
|
{ text: 'Connection', link: '/apps/removebg/connection' }
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
# Better Stack
|
|
||||||
|
|
||||||
:::info
|
|
||||||
This page explains the steps you need to follow to set up the Better Stack
|
|
||||||
connection in Automatisch. If any of the steps are outdated, please let us know!
|
|
||||||
:::
|
|
||||||
|
|
||||||
1. Login to your Better Stack account: [https://betterstack.com/](https://betterstack.com/).
|
|
||||||
2. Click on the team name bottom left and select **Manage Teams** option.
|
|
||||||
3. Click on the three dots icon of your team and select **manage** option.
|
|
||||||
4. Click on the **API tokens** tab.
|
|
||||||
5. Copy the token next to **Direct API tokens** to the `API Key` field on Automatisch.
|
|
||||||
6. Fill the screen name on Automatisch.
|
|
||||||
7. Now, you can start using the Better Stack connection with Automatisch.
|
|
@@ -7,6 +7,8 @@ items:
|
|||||||
desc: Creates a page inside a parent page.
|
desc: Creates a page inside a parent page.
|
||||||
- name: Find database item
|
- name: Find database item
|
||||||
desc: Searches for an item in a database by property.
|
desc: Searches for an item in a database by property.
|
||||||
|
- name: Update database item
|
||||||
|
desc: Updates a database item.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
|
||||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
|
||||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="200.000000pt" height="200.000000pt" viewBox="0 0 200.000000 200.000000"
|
|
||||||
preserveAspectRatio="xMidYMid meet">
|
|
||||||
|
|
||||||
<g transform="translate(0.000000,200.000000) scale(0.100000,-0.100000)"
|
|
||||||
fill="#000000" stroke="none">
|
|
||||||
<path d="M0 1000 l0 -1000 1000 0 1000 0 0 1000 0 1000 -1000 0 -1000 0 0
|
|
||||||
-1000z m1162 460 c14 -11 113 -184 232 -408 228 -429 231 -439 175 -486 -35
|
|
||||||
-30 -30 -29 -140 -15 -89 12 -123 25 -152 56 -9 11 -72 147 -140 304 -113 263
|
|
||||||
-124 284 -149 287 -14 2 -29 10 -32 17 -8 21 67 214 94 242 28 29 78 30 112 3z
|
|
||||||
m-340 -148 c10 -10 72 -175 139 -367 114 -325 121 -351 108 -374 -8 -14 -27
|
|
||||||
-32 -41 -41 -25 -13 -34 -12 -126 18 -55 18 -111 43 -125 56 -19 17 -40 67
|
|
||||||
-76 182 -36 112 -58 164 -73 176 l-22 16 27 99 c63 224 66 232 95 248 31 17
|
|
||||||
69 12 94 -13z m-314 -219 c16 -15 26 -59 56 -243 42 -262 43 -285 17 -300 -11
|
|
||||||
-5 -24 -10 -30 -10 -19 0 -140 114 -150 141 -7 20 -4 76 10 191 10 90 19 171
|
|
||||||
19 181 0 18 33 57 49 57 5 0 18 -8 29 -17z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user