Compare commits
31 Commits
AUT-860
...
static-can
Author | SHA1 | Date | |
---|---|---|---|
![]() |
62b656add1 | ||
![]() |
40636119fb | ||
![]() |
beb3b2cf45 | ||
![]() |
c2375ed3d4 | ||
![]() |
4942cf8dae | ||
![]() |
8f444eafa7 | ||
![]() |
2484a0e631 | ||
![]() |
d3747ad050 | ||
![]() |
bb68a75636 | ||
![]() |
98131d633e | ||
![]() |
e8193e0e17 | ||
![]() |
74b7dd8f34 | ||
![]() |
4f500e2d04 | ||
![]() |
b53ddca8ce | ||
![]() |
70f30034ab | ||
![]() |
fcd83909f7 | ||
![]() |
eadb472af9 | ||
![]() |
600316577e | ||
![]() |
9aa48c20e4 | ||
![]() |
1b5d3beeca | ||
![]() |
00115d313e | ||
![]() |
190f1a205f | ||
![]() |
8ab6f0c3fe | ||
![]() |
13eea263c0 | ||
![]() |
b52b40962e | ||
![]() |
7d1fa2e40c | ||
![]() |
93b2098829 | ||
![]() |
a2acdc6b12 | ||
![]() |
38b2c1e30f | ||
![]() |
e07f579f3c | ||
![]() |
df3297b6ca |
@@ -31,7 +31,6 @@
|
|||||||
"accounting": "^0.4.1",
|
"accounting": "^0.4.1",
|
||||||
"ajv-formats": "^2.1.1",
|
"ajv-formats": "^2.1.1",
|
||||||
"axios": "1.6.0",
|
"axios": "1.6.0",
|
||||||
"basic-ftp": "^5.0.5",
|
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"bullmq": "^3.0.0",
|
"bullmq": "^3.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 109.36" style="enable-background:new 0 0 122.88 109.36" xml:space="preserve"><g><path d="M14.69,16.44h3.56V8.63c0-1.09,0.88-1.97,1.97-1.97h3.5V1.97C23.72,0.88,24.6,0,25.69,0h31.92c1.09,0,1.97,0.88,1.97,1.97 v4.69h43.05c1.09,0,1.97,0.88,1.97,1.97v7.82h3.59c1.09,0,1.97,0.88,1.97,1.97c0,0.14-0.01,0.28-0.04,0.42l-6.88,50.59 c-0.22,1.65-0.95,3.18-2.05,4.29c-1.1,1.1-2.54,1.78-4.25,1.78H70.95v5.86h2.12c1.54,0,2.8,1.26,2.8,2.8v5.06h10.44 c1.25,0,2.32,0.83,2.67,1.97h26.1c3.73,0,6.14,2.07,7.2,4.71c0.4,1,0.6,2.08,0.6,3.14c0,1.06-0.2,2.14-0.6,3.14 c-1.06,2.64-3.47,4.71-7.2,4.71H89.09c-0.15,1.4-1.35,2.49-2.78,2.49H72.63H38.8c-1.44,0-2.63-1.1-2.78-2.49H7.8 c-3.73,0-6.14-2.07-7.2-4.71c-0.4-1-0.6-2.08-0.6-3.14c0-1.06,0.2-2.14,0.6-3.14c1.06-2.64,3.47-4.71,7.2-4.71h28.32 c0.36-1.14,1.42-1.97,2.67-1.97h8.74v-5.06c0-1.54,1.26-2.8,2.8-2.8h1.69v-5.86H24.38c-1.71,0-3.19-0.69-4.3-1.79 c-1.11-1.11-1.83-2.66-2.01-4.33l-5.33-50.74c-0.11-1.08,0.67-2.04,1.75-2.15C14.56,16.45,14.63,16.45,14.69,16.44L14.69,16.44 L14.69,16.44L14.69,16.44z M31.38,34.43h16.29v4.58H38v3.72h8.26v4.3H38v8.71h-6.61V34.43L31.38,34.43z M50.08,34.43H70.1v5.27 h-6.72v16.05h-6.59V39.7h-6.71V34.43L50.08,34.43z M73.41,34.43h10.95c2.38,0,4.17,0.57,5.35,1.7c1.19,1.14,1.78,2.75,1.78,4.84 c0,2.15-0.65,3.84-1.94,5.05c-1.3,1.21-3.27,1.82-5.93,1.82h-3.6v7.91h-6.61V34.43L73.41,34.43z M80.03,43.52h1.61 c1.27,0,2.16-0.22,2.68-0.66c0.51-0.44,0.77-1,0.77-1.69c0-0.67-0.22-1.24-0.67-1.7c-0.44-0.47-1.28-0.7-2.51-0.7h-1.88V43.52 L80.03,43.52z M56.38,81.34h10.21v-5.79H56.38V81.34L56.38,81.34z M89.11,94.88v8.27h25.97c1.97,0,3.22-1.04,3.76-2.37 c0.22-0.54,0.33-1.15,0.33-1.76s-0.11-1.22-0.33-1.76c-0.54-1.33-1.79-2.37-3.76-2.37H89.11L89.11,94.88z M36,103.15v-8.27H7.8 c-1.97,0-3.22,1.04-3.76,2.37c-0.22,0.54-0.33,1.15-0.33,1.76s0.11,1.22,0.33,1.76c0.54,1.33,1.79,2.37,3.76,2.37H36L36,103.15z M20.23,20.38h-3.35l5.1,48.57c0.08,0.78,0.39,1.47,0.87,1.95c0.4,0.4,0.92,0.64,1.53,0.64h72.54c0.59,0,1.1-0.24,1.48-0.62 c0.49-0.49,0.82-1.22,0.93-2.03l6.6-48.51L20.23,20.38L20.23,20.38L20.23,20.38z M22.19,10.6v5.83l78.46-0.83v-5H57.61 c-1.09,0-1.97-0.88-1.97-1.97V3.94H27.66v4.69c0,1.09-0.88,1.97-1.97,1.97L22.19,10.6L22.19,10.6L22.19,10.6z"/></g></svg>
|
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -1,91 +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: 'host',
|
|
||||||
label: 'Host',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
readOnly: false,
|
|
||||||
value: null,
|
|
||||||
placeholder: null,
|
|
||||||
description: 'The host information Automatisch will connect to.',
|
|
||||||
docUrl: 'https://automatisch.io/docs/ftp#host',
|
|
||||||
clickToCopy: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'username',
|
|
||||||
label: 'Email/Username',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
readOnly: false,
|
|
||||||
value: null,
|
|
||||||
placeholder: null,
|
|
||||||
description: 'Your FTP login credentials.',
|
|
||||||
docUrl: 'https://automatisch.io/docs/ftp#username',
|
|
||||||
clickToCopy: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'password',
|
|
||||||
label: 'Password',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
readOnly: false,
|
|
||||||
value: null,
|
|
||||||
placeholder: null,
|
|
||||||
description: null,
|
|
||||||
docUrl: 'https://automatisch.io/docs/ftp#password',
|
|
||||||
clickToCopy: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'secure',
|
|
||||||
label: 'Secure',
|
|
||||||
type: 'dropdown',
|
|
||||||
required: false,
|
|
||||||
readOnly: false,
|
|
||||||
value: false,
|
|
||||||
placeholder: null,
|
|
||||||
description: null,
|
|
||||||
docUrl: 'https://automatisch.io/docs/ftp#secure',
|
|
||||||
clickToCopy: false,
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
label: 'Yes',
|
|
||||||
value: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'No',
|
|
||||||
value: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'port',
|
|
||||||
label: 'Port',
|
|
||||||
type: 'string',
|
|
||||||
required: false,
|
|
||||||
readOnly: false,
|
|
||||||
value: '21',
|
|
||||||
placeholder: null,
|
|
||||||
description: null,
|
|
||||||
docUrl: 'https://automatisch.io/docs/ftp#port',
|
|
||||||
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,19 +0,0 @@
|
|||||||
import { Client } from 'basic-ftp';
|
|
||||||
|
|
||||||
const verifyCredentials = async ($) => {
|
|
||||||
const client = new Client();
|
|
||||||
client.ftp.verbose = true;
|
|
||||||
|
|
||||||
await client.access({
|
|
||||||
host: $.auth.data.host,
|
|
||||||
user: $.auth.data.username,
|
|
||||||
password: $.auth.data.password,
|
|
||||||
secure: $.auth.data.secure,
|
|
||||||
});
|
|
||||||
|
|
||||||
await $.auth.set({
|
|
||||||
screenName: $.auth.data.screenName,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default verifyCredentials;
|
|
@@ -1,14 +0,0 @@
|
|||||||
import defineApp from '../../helpers/define-app.js';
|
|
||||||
import auth from './auth/index.js';
|
|
||||||
|
|
||||||
export default defineApp({
|
|
||||||
name: 'FTP',
|
|
||||||
key: 'ftp',
|
|
||||||
iconUrl: '{BASE_URL}/apps/ftp/assets/favicon.svg',
|
|
||||||
authDocUrl: 'https://automatisch.io/docs/apps/ftp/connection',
|
|
||||||
supportsConnections: true,
|
|
||||||
baseUrl: '',
|
|
||||||
apiBaseUrl: '',
|
|
||||||
primaryColor: '000000',
|
|
||||||
auth,
|
|
||||||
});
|
|
@@ -0,0 +1,13 @@
|
|||||||
|
import User from '../../../../models/user.js';
|
||||||
|
import { renderObject, renderError } from '../../../../helpers/renderer.js';
|
||||||
|
|
||||||
|
export default async (request, response) => {
|
||||||
|
const { email, password } = request.body;
|
||||||
|
const token = await User.authenticate(email, password);
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
return renderObject(response, { token });
|
||||||
|
}
|
||||||
|
|
||||||
|
renderError(response, [{ general: ['Incorrect email or password.'] }]);
|
||||||
|
};
|
@@ -0,0 +1,39 @@
|
|||||||
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../../../app.js';
|
||||||
|
import { createUser } from '../../../../../test/factories/user';
|
||||||
|
|
||||||
|
describe('POST /api/v1/access-tokens', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createUser({
|
||||||
|
email: 'user@automatisch.io',
|
||||||
|
password: 'password',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the token data with correct credentials', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/api/v1/access-tokens')
|
||||||
|
.send({
|
||||||
|
email: 'user@automatisch.io',
|
||||||
|
password: 'password',
|
||||||
|
})
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.data.token.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return error with incorrect credentials', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/api/v1/access-tokens')
|
||||||
|
.send({
|
||||||
|
email: 'incorrect@email.com',
|
||||||
|
password: 'incorrectpassword',
|
||||||
|
})
|
||||||
|
.expect(422);
|
||||||
|
|
||||||
|
expect(response.body.errors.general).toEqual([
|
||||||
|
'Incorrect email or password.',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
@@ -1,52 +0,0 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import Crypto from 'crypto';
|
|
||||||
import app from '../../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getAdminAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/app-auth-clients/get-app-auth-client.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/app-auth-clients/:appAuthClientId', () => {
|
|
||||||
let currentUser, currentUserRole, currentAppAuthClient, token;
|
|
||||||
|
|
||||||
describe('with valid license key', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
currentAppAuthClient = await createAppAuthClient();
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/admin/app-auth-clients/${currentAppAuthClient.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAdminAppAuthClientMock(currentAppAuthClient);
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,41 +0,0 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getAdminAppAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/app-auth-clients/get-app-auth-clients.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/app-auth-clients', () => {
|
|
||||||
let currentUser, currentUserRole, token;
|
|
||||||
|
|
||||||
describe('with valid license key', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return app auth clients', async () => {
|
|
||||||
const appAuthClientOne = await createAppAuthClient();
|
|
||||||
const appAuthClientTwo = await createAppAuthClient();
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/admin/app-auth-clients')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAdminAppAuthClientsMock([
|
|
||||||
appAuthClientTwo,
|
|
||||||
appAuthClientOne,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -4,6 +4,7 @@ import AppAuthClient from '../../../../../models/app-auth-client.js';
|
|||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClient = await AppAuthClient.query()
|
const appAuthClient = await AppAuthClient.query()
|
||||||
.findById(request.params.appAuthClientId)
|
.findById(request.params.appAuthClientId)
|
||||||
|
.where({ app_key: request.params.appKey })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
renderObject(response, appAuthClient);
|
@@ -0,0 +1,55 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import Crypto from 'crypto';
|
||||||
|
import app from '../../../../../app.js';
|
||||||
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
|
import getAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-client.js';
|
||||||
|
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||||
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||||
|
let currentUser, adminRole, currentAppAuthClient, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
adminRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: adminRole.id });
|
||||||
|
|
||||||
|
currentAppAuthClient = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified app auth client', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/admin/apps/deepl/auth-clients/${currentAppAuthClient.id}`)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAppAuthClientMock(currentAppAuthClient);
|
||||||
|
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/admin/apps/deepl/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/apps/deepl/auth-clients/invalidAppAuthClientUUID')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
});
|
@@ -2,10 +2,9 @@ import { renderObject } from '../../../../../helpers/renderer.js';
|
|||||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClients = await AppAuthClient.query().orderBy(
|
const appAuthClients = await AppAuthClient.query()
|
||||||
'created_at',
|
.where({ app_key: request.params.appKey })
|
||||||
'desc'
|
.orderBy('created_at', 'desc');
|
||||||
);
|
|
||||||
|
|
||||||
renderObject(response, appAuthClients);
|
renderObject(response, appAuthClients);
|
||||||
};
|
};
|
@@ -0,0 +1,44 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../../../../app.js';
|
||||||
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
|
import getAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-clients.js';
|
||||||
|
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||||
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||||
|
let currentUser, adminRole, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
adminRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: adminRole.id });
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified app auth client info', async () => {
|
||||||
|
const appAuthClientOne = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const appAuthClientTwo = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/v1/admin/apps/deepl/auth-clients')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAuthClientsMock([
|
||||||
|
appAuthClientTwo,
|
||||||
|
appAuthClientOne,
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -4,7 +4,7 @@ import AppAuthClient from '../../../../models/app-auth-client.js';
|
|||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClient = await AppAuthClient.query()
|
const appAuthClient = await AppAuthClient.query()
|
||||||
.findById(request.params.appAuthClientId)
|
.findById(request.params.appAuthClientId)
|
||||||
.where({ active: true })
|
.where({ app_key: request.params.appKey, active: true })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
renderObject(response, appAuthClient);
|
@@ -4,25 +4,27 @@ 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';
|
||||||
import getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/app-auth-clients/get-app-auth-client.js';
|
import getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-client.js';
|
||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app-auth-clients/:id', () => {
|
describe('GET /api/v1/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||||
let currentUser, currentAppAuthClient, token;
|
let currentUser, currentAppAuthClient, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
currentUser = await createUser();
|
currentUser = await createUser();
|
||||||
currentAppAuthClient = await createAppAuthClient();
|
currentAppAuthClient = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
it('should return specified app auth client', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get(`/api/v1/app-auth-clients/${currentAppAuthClient.id}`)
|
.get(`/api/v1/apps/deepl/auth-clients/${currentAppAuthClient.id}`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
@@ -34,14 +36,14 @@ describe('GET /api/v1/app-auth-clients/:id', () => {
|
|||||||
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.get(`/api/v1/app-auth-clients/${notExistingAppAuthClientUUID}`)
|
.get(`/api/v1/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
it('should return bad request response for invalid UUID', async () => {
|
||||||
await request(app)
|
await request(app)
|
||||||
.get('/api/v1/app-auth-clients/invalidAppAuthClientUUID')
|
.get('/api/v1/apps/deepl/auth-clients/invalidAppAuthClientUUID')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
@@ -3,7 +3,7 @@ import AppAuthClient from '../../../../models/app-auth-client.js';
|
|||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClients = await AppAuthClient.query()
|
const appAuthClients = await AppAuthClient.query()
|
||||||
.where({ active: true })
|
.where({ app_key: request.params.appKey, active: true })
|
||||||
.orderBy('created_at', 'desc');
|
.orderBy('created_at', 'desc');
|
||||||
|
|
||||||
renderObject(response, appAuthClients);
|
renderObject(response, appAuthClients);
|
@@ -3,11 +3,11 @@ import request from 'supertest';
|
|||||||
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';
|
||||||
import getAppAuthClientsMock from '../../../../../test/mocks/rest/api/v1/app-auth-clients/get-app-auth-clients.js';
|
import getAuthClientsMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-clients.js';
|
||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app-auth-clients', () => {
|
describe('GET /api/v1/apps/:appKey/auth-clients', () => {
|
||||||
let currentUser, token;
|
let currentUser, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -19,15 +19,20 @@ describe('GET /api/v1/app-auth-clients', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
it('should return specified app auth client info', async () => {
|
||||||
const appAuthClientOne = await createAppAuthClient();
|
const appAuthClientOne = await createAppAuthClient({
|
||||||
const appAuthClientTwo = await createAppAuthClient();
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const appAuthClientTwo = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get('/api/v1/app-auth-clients')
|
.get('/api/v1/apps/deepl/auth-clients')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
const expectedPayload = getAppAuthClientsMock([
|
const expectedPayload = getAuthClientsMock([
|
||||||
appAuthClientTwo,
|
appAuthClientTwo,
|
||||||
appAuthClientOne,
|
appAuthClientOne,
|
||||||
]);
|
]);
|
@@ -3,11 +3,11 @@ import request from 'supertest';
|
|||||||
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';
|
||||||
import getAppConfigMock from '../../../../../test/mocks/rest/api/v1/app-configs/get-app-config.js';
|
import getAppConfigMock from '../../../../../test/mocks/rest/api/v1/apps/get-config.js';
|
||||||
import { createAppConfig } from '../../../../../test/factories/app-config.js';
|
import { createAppConfig } from '../../../../../test/factories/app-config.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app-configs/:appKey', () => {
|
describe('GET /api/v1/apps/:appKey/config', () => {
|
||||||
let currentUser, appConfig, token;
|
let currentUser, appConfig, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -27,7 +27,7 @@ describe('GET /api/v1/app-configs/:appKey', () => {
|
|||||||
|
|
||||||
it('should return specified app config info', async () => {
|
it('should return specified app config info', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get(`/api/v1/app-configs/${appConfig.key}`)
|
.get(`/api/v1/apps/${appConfig.key}/config`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ describe('GET /api/v1/app-configs/:appKey', () => {
|
|||||||
|
|
||||||
it('should return not found response for not existing app key', async () => {
|
it('should return not found response for not existing app key', async () => {
|
||||||
await request(app)
|
await request(app)
|
||||||
.get('/api/v1/app-configs/not-existing-app-key')
|
.get('/api/v1/apps/not-existing-app-key/config')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.dropColumn('app_key');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
const appAuthClients = await knex('app_auth_clients').select('*');
|
||||||
|
|
||||||
|
for (const appAuthClient of appAuthClients) {
|
||||||
|
const appConfig = await knex('app_configs')
|
||||||
|
.where('id', appAuthClient.app_config_id)
|
||||||
|
.first();
|
||||||
|
|
||||||
|
await knex('app_auth_clients')
|
||||||
|
.where('id', appAuthClient.id)
|
||||||
|
.update({ app_key: appConfig.key });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down() {
|
||||||
|
// void
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.dropColumn('app_config_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table
|
||||||
|
.uuid('app_config_id')
|
||||||
|
.notNullable()
|
||||||
|
.references('id')
|
||||||
|
.inTable('app_configs');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key').notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key').nullable().alter();
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.boolean('can_connect').defaultTo(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.dropColumn('can_connect');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.boolean('can_custom_connect').defaultTo(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.dropColumn('can_custom_connect');
|
||||||
|
});
|
||||||
|
}
|
@@ -1,40 +0,0 @@
|
|||||||
import App from '../../models/app.js';
|
|
||||||
import Step from '../../models/step.js';
|
|
||||||
import globalVariable from '../../helpers/global-variable.js';
|
|
||||||
|
|
||||||
const getDynamicFields = async (_parent, params, context) => {
|
|
||||||
const conditions = context.currentUser.can('update', 'Flow');
|
|
||||||
const userSteps = context.currentUser.$relatedQuery('steps');
|
|
||||||
const allSteps = Step.query();
|
|
||||||
const stepBaseQuery = conditions.isCreator ? userSteps : allSteps;
|
|
||||||
|
|
||||||
const step = await stepBaseQuery
|
|
||||||
.clone()
|
|
||||||
.withGraphFetched({
|
|
||||||
connection: true,
|
|
||||||
flow: true,
|
|
||||||
})
|
|
||||||
.findById(params.stepId);
|
|
||||||
|
|
||||||
if (!step) return null;
|
|
||||||
|
|
||||||
const connection = step.connection;
|
|
||||||
|
|
||||||
if (!step.appKey) return null;
|
|
||||||
|
|
||||||
const app = await App.findOneByKey(step.appKey);
|
|
||||||
const $ = await globalVariable({ connection, app, flow: step.flow, step });
|
|
||||||
|
|
||||||
const command = app.dynamicFields.find((data) => data.key === params.key);
|
|
||||||
|
|
||||||
for (const parameterKey in params.parameters) {
|
|
||||||
const parameterValue = params.parameters[parameterKey];
|
|
||||||
$.step.parameters[parameterKey] = parameterValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const additionalFields = (await command.run($)) || [];
|
|
||||||
|
|
||||||
return additionalFields;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getDynamicFields;
|
|
@@ -4,7 +4,6 @@ import getAppAuthClients from './queries/get-app-auth-clients.ee.js';
|
|||||||
import getBillingAndUsage from './queries/get-billing-and-usage.ee.js';
|
import getBillingAndUsage from './queries/get-billing-and-usage.ee.js';
|
||||||
import getConnectedApps from './queries/get-connected-apps.js';
|
import getConnectedApps from './queries/get-connected-apps.js';
|
||||||
import getDynamicData from './queries/get-dynamic-data.js';
|
import getDynamicData from './queries/get-dynamic-data.js';
|
||||||
import getDynamicFields from './queries/get-dynamic-fields.js';
|
|
||||||
import getFlow from './queries/get-flow.js';
|
import getFlow from './queries/get-flow.js';
|
||||||
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
||||||
import testConnection from './queries/test-connection.js';
|
import testConnection from './queries/test-connection.js';
|
||||||
@@ -16,7 +15,6 @@ const queryResolvers = {
|
|||||||
getBillingAndUsage,
|
getBillingAndUsage,
|
||||||
getConnectedApps,
|
getConnectedApps,
|
||||||
getDynamicData,
|
getDynamicData,
|
||||||
getDynamicFields,
|
|
||||||
getFlow,
|
getFlow,
|
||||||
getStepWithTestExecutions,
|
getStepWithTestExecutions,
|
||||||
testConnection,
|
testConnection,
|
||||||
|
@@ -11,11 +11,6 @@ type Query {
|
|||||||
key: String!
|
key: String!
|
||||||
parameters: JSONObject
|
parameters: JSONObject
|
||||||
): JSONObject
|
): JSONObject
|
||||||
getDynamicFields(
|
|
||||||
stepId: String!
|
|
||||||
key: String!
|
|
||||||
parameters: JSONObject
|
|
||||||
): [SubstepArgument]
|
|
||||||
getBillingAndUsage: GetBillingAndUsage
|
getBillingAndUsage: GetBillingAndUsage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ const stream = {
|
|||||||
const registerGraphQLToken = () => {
|
const registerGraphQLToken = () => {
|
||||||
morgan.token('graphql-query', (req) => {
|
morgan.token('graphql-query', (req) => {
|
||||||
if (req.body.query) {
|
if (req.body.query) {
|
||||||
return `GraphQL ${req.body.query}`;
|
return `\n GraphQL ${req.body.query}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -17,7 +17,7 @@ const registerGraphQLToken = () => {
|
|||||||
registerGraphQLToken();
|
registerGraphQLToken();
|
||||||
|
|
||||||
const morganMiddleware = morgan(
|
const morganMiddleware = morgan(
|
||||||
':method :url :status :res[content-length] - :response-time ms\n:graphql-query',
|
':method :url :status :res[content-length] - :response-time ms :graphql-query',
|
||||||
{ stream }
|
{ stream }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -44,4 +44,22 @@ const renderObject = (response, object, options) => {
|
|||||||
return response.json(computedPayload);
|
return response.json(computedPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { renderObject };
|
const renderError = (response, errors, status, type) => {
|
||||||
|
const errorStatus = status || 422;
|
||||||
|
const errorType = type || 'ValidationError';
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
errors: errors.reduce((acc, error) => {
|
||||||
|
const key = Object.keys(error)[0];
|
||||||
|
acc[key] = error[key];
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
|
meta: {
|
||||||
|
type: errorType,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return response.status(errorStatus).send(payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { renderObject, renderError };
|
||||||
|
@@ -9,11 +9,11 @@ class AppAuthClient extends Base {
|
|||||||
|
|
||||||
static jsonSchema = {
|
static jsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['name', 'appConfigId', 'formattedAuthDefaults'],
|
required: ['name', 'appKey', 'formattedAuthDefaults'],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
id: { type: 'string', format: 'uuid' },
|
id: { type: 'string', format: 'uuid' },
|
||||||
appConfigId: { type: 'string', format: 'uuid' },
|
appKey: { type: 'string' },
|
||||||
active: { type: 'boolean' },
|
active: { type: 'boolean' },
|
||||||
authDefaults: { type: ['string', 'null'] },
|
authDefaults: { type: ['string', 'null'] },
|
||||||
formattedAuthDefaults: { type: 'object' },
|
formattedAuthDefaults: { type: 'object' },
|
||||||
@@ -22,17 +22,6 @@ class AppAuthClient extends Base {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static relationMappings = () => ({
|
|
||||||
appConfig: {
|
|
||||||
relation: Base.BelongsToOneRelation,
|
|
||||||
modelClass: AppConfig,
|
|
||||||
join: {
|
|
||||||
from: 'app_auth_clients.app_config_id',
|
|
||||||
to: 'app_configs.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
encryptData() {
|
encryptData() {
|
||||||
if (!this.eligibleForEncryption()) return;
|
if (!this.eligibleForEncryption()) return;
|
||||||
|
|
||||||
@@ -71,6 +60,21 @@ class AppAuthClient extends Base {
|
|||||||
this.encryptData();
|
this.encryptData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async assignCanConnectForAppConfig() {
|
||||||
|
const appConfig = await AppConfig.query().findOne({ key: this.appKey });
|
||||||
|
await appConfig?.$query()?.patch({});
|
||||||
|
}
|
||||||
|
|
||||||
|
async $afterInsert(queryContext) {
|
||||||
|
await super.$afterInsert(queryContext);
|
||||||
|
await this.assignCanConnectForAppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
async $afterUpdate(opt, queryContext) {
|
||||||
|
await super.$afterUpdate(opt, queryContext);
|
||||||
|
await this.assignCanConnectForAppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
async $afterFind() {
|
async $afterFind() {
|
||||||
this.decryptData();
|
this.decryptData();
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import App from './app.js';
|
import App from './app.js';
|
||||||
import Base from './base.js';
|
|
||||||
import AppAuthClient from './app-auth-client.js';
|
import AppAuthClient from './app-auth-client.js';
|
||||||
|
import Base from './base.js';
|
||||||
|
|
||||||
class AppConfig extends Base {
|
class AppConfig extends Base {
|
||||||
static tableName = 'app_configs';
|
static tableName = 'app_configs';
|
||||||
@@ -15,45 +15,56 @@ class AppConfig extends Base {
|
|||||||
allowCustomConnection: { type: 'boolean', default: false },
|
allowCustomConnection: { type: 'boolean', default: false },
|
||||||
shared: { type: 'boolean', default: false },
|
shared: { type: 'boolean', default: false },
|
||||||
disabled: { type: 'boolean', default: false },
|
disabled: { type: 'boolean', default: false },
|
||||||
|
canConnect: { type: 'boolean', default: false },
|
||||||
|
canCustomConnect: { type: 'boolean', default: false },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static get virtualAttributes() {
|
|
||||||
return ['canConnect', 'canCustomConnect'];
|
|
||||||
}
|
|
||||||
|
|
||||||
static relationMappings = () => ({
|
|
||||||
appAuthClients: {
|
|
||||||
relation: Base.HasManyRelation,
|
|
||||||
modelClass: AppAuthClient,
|
|
||||||
join: {
|
|
||||||
from: 'app_configs.id',
|
|
||||||
to: 'app_auth_clients.app_config_id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
get canCustomConnect() {
|
|
||||||
return !this.disabled && this.allowCustomConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
get canConnect() {
|
|
||||||
const hasSomeActiveAppAuthClients = !!this.appAuthClients?.some(
|
|
||||||
(appAuthClient) => appAuthClient.active
|
|
||||||
);
|
|
||||||
const shared = this.shared;
|
|
||||||
const active = this.disabled === false;
|
|
||||||
|
|
||||||
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
|
||||||
|
|
||||||
return conditions.every(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getApp() {
|
async getApp() {
|
||||||
if (!this.key) return null;
|
if (!this.key) return null;
|
||||||
|
|
||||||
return await App.findOneByKey(this.key);
|
return await App.findOneByKey(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hasActiveAppAuthClients() {
|
||||||
|
const appAuthClients = await AppAuthClient.query().where({
|
||||||
|
appKey: this.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasSomeActiveAppAuthClients = !!appAuthClients?.some(
|
||||||
|
(appAuthClient) => appAuthClient.active
|
||||||
|
);
|
||||||
|
|
||||||
|
return hasSomeActiveAppAuthClients;
|
||||||
|
}
|
||||||
|
|
||||||
|
async assignCanConnect() {
|
||||||
|
const shared = this.shared;
|
||||||
|
const active = this.disabled === false;
|
||||||
|
const hasSomeActiveAppAuthClients = await this.hasActiveAppAuthClients();
|
||||||
|
|
||||||
|
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
||||||
|
const canConnect = conditions.every(Boolean);
|
||||||
|
|
||||||
|
this.canConnect = canConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
async assignCanCustomConnect() {
|
||||||
|
const canCustomConnect = !this.disabled && this.allowCustomConnection;
|
||||||
|
this.canCustomConnect = canCustomConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
async $beforeInsert(queryContext) {
|
||||||
|
await super.$beforeInsert(queryContext);
|
||||||
|
await this.assignCanConnect();
|
||||||
|
await this.assignCanCustomConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
async $beforeUpdate(opt, queryContext) {
|
||||||
|
await super.$beforeUpdate(opt, queryContext);
|
||||||
|
await this.assignCanConnect();
|
||||||
|
await this.assignCanCustomConnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AppConfig;
|
export default AppConfig;
|
||||||
|
@@ -5,6 +5,7 @@ import crypto from 'node:crypto';
|
|||||||
import appConfig from '../config/app.js';
|
import appConfig from '../config/app.js';
|
||||||
import { hasValidLicense } from '../helpers/license.ee.js';
|
import { hasValidLicense } from '../helpers/license.ee.js';
|
||||||
import userAbility from '../helpers/user-ability.js';
|
import userAbility from '../helpers/user-ability.js';
|
||||||
|
import createAuthTokenByUserId from '../helpers/create-auth-token-by-user-id.js';
|
||||||
import Base from './base.js';
|
import Base from './base.js';
|
||||||
import Connection from './connection.js';
|
import Connection from './connection.js';
|
||||||
import Execution from './execution.js';
|
import Execution from './execution.js';
|
||||||
@@ -161,6 +162,17 @@ class User extends Base {
|
|||||||
: Execution.query();
|
: Execution.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async authenticate(email, password) {
|
||||||
|
const user = await User.query().findOne({
|
||||||
|
email: email?.toLowerCase() || null,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (user && (await user.login(password))) {
|
||||||
|
const token = createAuthTokenByUserId(user.id);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
login(password) {
|
login(password) {
|
||||||
return bcrypt.compare(password, this.password);
|
return bcrypt.compare(password, this.password);
|
||||||
}
|
}
|
||||||
|
9
packages/backend/src/routes/api/v1/access-tokens.js
Normal file
9
packages/backend/src/routes/api/v1/access-tokens.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import asyncHandler from 'express-async-handler';
|
||||||
|
import createAccessTokenAction from '../../../controllers/api/v1/access-tokens/create-access-token.js';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.post('/', asyncHandler(createAccessTokenAction));
|
||||||
|
|
||||||
|
export default router;
|
@@ -3,25 +3,25 @@ import asyncHandler from 'express-async-handler';
|
|||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../../helpers/authentication.js';
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
||||||
import getAdminAppAuthClientsAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-clients.ee.js';
|
import getAuthClientsAction from '../../../../controllers/api/v1/admin/apps/get-auth-clients.ee.js';
|
||||||
import getAdminAppAuthClientAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-client.ee.js';
|
import getAuthClientAction from '../../../../controllers/api/v1/admin/apps/get-auth-client.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/:appKey/auth-clients',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
authorizeAdmin,
|
authorizeAdmin,
|
||||||
checkIsEnterprise,
|
checkIsEnterprise,
|
||||||
asyncHandler(getAdminAppAuthClientsAction)
|
asyncHandler(getAuthClientsAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:appAuthClientId',
|
'/:appKey/auth-clients/:appAuthClientId',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
authorizeAdmin,
|
authorizeAdmin,
|
||||||
checkIsEnterprise,
|
checkIsEnterprise,
|
||||||
asyncHandler(getAdminAppAuthClientAction)
|
asyncHandler(getAuthClientAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
@@ -1,24 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
|
||||||
import getAppAuthClientAction from '../../../controllers/api/v1/app-auth-clients/get-app-auth-client.js';
|
|
||||||
import getAppAuthClientsAction from '../../../controllers/api/v1/app-auth-clients/get-app-auth-clients.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppAuthClientsAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:appAuthClientId',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppAuthClientAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,16 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
|
||||||
import getAppConfigAction from '../../../controllers/api/v1/app-configs/get-app-config.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:appKey',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppConfigAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -2,9 +2,13 @@ import { Router } from 'express';
|
|||||||
import asyncHandler from 'express-async-handler';
|
import asyncHandler from 'express-async-handler';
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||||
import { authorizeUser } from '../../../helpers/authorization.js';
|
import { authorizeUser } from '../../../helpers/authorization.js';
|
||||||
|
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
||||||
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
||||||
import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js';
|
import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js';
|
||||||
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
||||||
|
import getConfigAction from '../../../controllers/api/v1/apps/get-config.ee.js';
|
||||||
|
import getAuthClientsAction from '../../../controllers/api/v1/apps/get-auth-clients.ee.js';
|
||||||
|
import getAuthClientAction from '../../../controllers/api/v1/apps/get-auth-client.ee.js';
|
||||||
import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js';
|
import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js';
|
||||||
import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js';
|
import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js';
|
||||||
import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js';
|
import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js';
|
||||||
@@ -17,6 +21,27 @@ router.get('/', authenticateUser, asyncHandler(getAppsAction));
|
|||||||
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
|
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
|
||||||
router.get('/:appKey/auth', authenticateUser, asyncHandler(getAuthAction));
|
router.get('/:appKey/auth', authenticateUser, asyncHandler(getAuthAction));
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/config',
|
||||||
|
authenticateUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getConfigAction)
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients',
|
||||||
|
authenticateUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getAuthClientsAction)
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients/:appAuthClientId',
|
||||||
|
authenticateUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getAuthClientAction)
|
||||||
|
);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:appKey/triggers',
|
'/:appKey/triggers',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
|
@@ -4,21 +4,20 @@ import webhooksRouter from './webhooks.js';
|
|||||||
import paddleRouter from './paddle.ee.js';
|
import paddleRouter from './paddle.ee.js';
|
||||||
import healthcheckRouter from './healthcheck.js';
|
import healthcheckRouter from './healthcheck.js';
|
||||||
import automatischRouter from './api/v1/automatisch.js';
|
import automatischRouter from './api/v1/automatisch.js';
|
||||||
|
import accessTokensRouter from './api/v1/access-tokens.js';
|
||||||
import usersRouter from './api/v1/users.js';
|
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 appConfigsRouter from './api/v1/app-configs.ee.js';
|
|
||||||
import flowsRouter from './api/v1/flows.js';
|
import flowsRouter from './api/v1/flows.js';
|
||||||
import stepsRouter from './api/v1/steps.js';
|
import stepsRouter from './api/v1/steps.js';
|
||||||
import appsRouter from './api/v1/apps.js';
|
import appsRouter from './api/v1/apps.js';
|
||||||
import connectionsRouter from './api/v1/connections.js';
|
import connectionsRouter from './api/v1/connections.js';
|
||||||
import executionsRouter from './api/v1/executions.js';
|
import executionsRouter from './api/v1/executions.js';
|
||||||
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
||||||
|
import adminAppsRouter from './api/v1/admin/apps.ee.js';
|
||||||
import adminSamlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
import adminSamlAuthProvidersRouter 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';
|
||||||
import adminUsersRouter from './api/v1/admin/users.ee.js';
|
import adminUsersRouter from './api/v1/admin/users.ee.js';
|
||||||
import adminAppAuthClientsRouter from './api/v1/admin/app-auth-clients.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -27,20 +26,19 @@ router.use('/webhooks', webhooksRouter);
|
|||||||
router.use('/paddle', paddleRouter);
|
router.use('/paddle', paddleRouter);
|
||||||
router.use('/healthcheck', healthcheckRouter);
|
router.use('/healthcheck', healthcheckRouter);
|
||||||
router.use('/api/v1/automatisch', automatischRouter);
|
router.use('/api/v1/automatisch', automatischRouter);
|
||||||
|
router.use('/api/v1/access-tokens', accessTokensRouter);
|
||||||
router.use('/api/v1/users', usersRouter);
|
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-configs', appConfigsRouter);
|
|
||||||
router.use('/api/v1/flows', flowsRouter);
|
|
||||||
router.use('/api/v1/steps', stepsRouter);
|
|
||||||
router.use('/api/v1/apps', appsRouter);
|
router.use('/api/v1/apps', appsRouter);
|
||||||
router.use('/api/v1/connections', connectionsRouter);
|
router.use('/api/v1/connections', connectionsRouter);
|
||||||
|
router.use('/api/v1/flows', flowsRouter);
|
||||||
|
router.use('/api/v1/steps', stepsRouter);
|
||||||
router.use('/api/v1/executions', executionsRouter);
|
router.use('/api/v1/executions', executionsRouter);
|
||||||
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
router.use('/api/v1/admin/apps', adminAppsRouter);
|
||||||
|
router.use('/api/v1/admin/users', adminUsersRouter);
|
||||||
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);
|
||||||
router.use('/api/v1/admin/users', adminUsersRouter);
|
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/app-auth-clients', adminAppAuthClientsRouter);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { createAppConfig } from './app-config.js';
|
|
||||||
import AppAuthClient from '../../src/models/app-auth-client';
|
import AppAuthClient from '../../src/models/app-auth-client';
|
||||||
|
|
||||||
const formattedAuthDefaults = {
|
const formattedAuthDefaults = {
|
||||||
@@ -12,7 +11,7 @@ const formattedAuthDefaults = {
|
|||||||
export const createAppAuthClient = async (params = {}) => {
|
export const createAppAuthClient = async (params = {}) => {
|
||||||
params.name = params?.name || faker.person.fullName();
|
params.name = params?.name || faker.person.fullName();
|
||||||
params.id = params?.id || faker.string.uuid();
|
params.id = params?.id || faker.string.uuid();
|
||||||
params.appConfigId = params?.appConfigId || (await createAppConfig()).id;
|
params.appKey = params?.appKey || 'deepl';
|
||||||
params.active = params?.active ?? true;
|
params.active = params?.active ?? true;
|
||||||
params.formattedAuthDefaults =
|
params.formattedAuthDefaults =
|
||||||
params?.formattedAuthDefaults || formattedAuthDefaults;
|
params?.formattedAuthDefaults || formattedAuthDefaults;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
||||||
return {
|
return {
|
||||||
data: appAuthClients.map((appAuthClient) => ({
|
data: appAuthClients.map((appAuthClient) => ({
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
@@ -1,9 +1,9 @@
|
|||||||
const getAdminAppAuthClientMock = (appAuthClient) => {
|
const getAppAuthClientMock = (appAuthClient) => {
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
|
appConfigId: appAuthClient.appConfigId,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
@@ -16,4 +16,4 @@ const getAdminAppAuthClientMock = (appAuthClient) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getAdminAppAuthClientMock;
|
export default getAppAuthClientMock;
|
@@ -1,7 +1,6 @@
|
|||||||
const getAppAuthClientsMock = (appAuthClients) => {
|
const getAppAuthClientsMock = (appAuthClients) => {
|
||||||
return {
|
return {
|
||||||
data: appAuthClients.map((appAuthClient) => ({
|
data: appAuthClients.map((appAuthClient) => ({
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
@@ -113,12 +113,6 @@ export default defineConfig({
|
|||||||
{ text: 'Connection', link: '/apps/formatter/connection' },
|
{ text: 'Connection', link: '/apps/formatter/connection' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
text: 'FTP',
|
|
||||||
collapsible: true,
|
|
||||||
collapsed: true,
|
|
||||||
items: [{ text: 'Connection', link: '/apps/ftp/connection' }],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text: 'Ghost',
|
text: 'Ghost',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
# FTP
|
|
||||||
|
|
||||||
:::info
|
|
||||||
This page explains the steps you need to follow to set up the FTP connection in Automatisch. If any of the steps are outdated, please let us know!
|
|
||||||
:::
|
|
||||||
|
|
||||||
FTP, which stands for File Transfer Protocol, is a standard network protocol used for the transfer of computer files between a client and server on a computer network. t's commonly used to download files from a server or upload files to a server.. You need to provide the following information from Automatisch by using FTP connection.
|
|
||||||
|
|
||||||
1. Write any screen name to be displayed in Automatisch.
|
|
||||||
1. Fill host address field with the FTP host address.
|
|
||||||
1. Fill username field with the FTP username.
|
|
||||||
1. Fill password field with the FTP password.
|
|
||||||
1. Select the Secure field.
|
|
||||||
1. Fill port field with the FTP port. Default is 21.
|
|
||||||
1. Click **Submit** button on Automatisch.
|
|
||||||
1. Now, you can start using the FTP connection with Automatisch.
|
|
@@ -1 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 109.36" style="enable-background:new 0 0 122.88 109.36" xml:space="preserve"><g><path d="M14.69,16.44h3.56V8.63c0-1.09,0.88-1.97,1.97-1.97h3.5V1.97C23.72,0.88,24.6,0,25.69,0h31.92c1.09,0,1.97,0.88,1.97,1.97 v4.69h43.05c1.09,0,1.97,0.88,1.97,1.97v7.82h3.59c1.09,0,1.97,0.88,1.97,1.97c0,0.14-0.01,0.28-0.04,0.42l-6.88,50.59 c-0.22,1.65-0.95,3.18-2.05,4.29c-1.1,1.1-2.54,1.78-4.25,1.78H70.95v5.86h2.12c1.54,0,2.8,1.26,2.8,2.8v5.06h10.44 c1.25,0,2.32,0.83,2.67,1.97h26.1c3.73,0,6.14,2.07,7.2,4.71c0.4,1,0.6,2.08,0.6,3.14c0,1.06-0.2,2.14-0.6,3.14 c-1.06,2.64-3.47,4.71-7.2,4.71H89.09c-0.15,1.4-1.35,2.49-2.78,2.49H72.63H38.8c-1.44,0-2.63-1.1-2.78-2.49H7.8 c-3.73,0-6.14-2.07-7.2-4.71c-0.4-1-0.6-2.08-0.6-3.14c0-1.06,0.2-2.14,0.6-3.14c1.06-2.64,3.47-4.71,7.2-4.71h28.32 c0.36-1.14,1.42-1.97,2.67-1.97h8.74v-5.06c0-1.54,1.26-2.8,2.8-2.8h1.69v-5.86H24.38c-1.71,0-3.19-0.69-4.3-1.79 c-1.11-1.11-1.83-2.66-2.01-4.33l-5.33-50.74c-0.11-1.08,0.67-2.04,1.75-2.15C14.56,16.45,14.63,16.45,14.69,16.44L14.69,16.44 L14.69,16.44L14.69,16.44z M31.38,34.43h16.29v4.58H38v3.72h8.26v4.3H38v8.71h-6.61V34.43L31.38,34.43z M50.08,34.43H70.1v5.27 h-6.72v16.05h-6.59V39.7h-6.71V34.43L50.08,34.43z M73.41,34.43h10.95c2.38,0,4.17,0.57,5.35,1.7c1.19,1.14,1.78,2.75,1.78,4.84 c0,2.15-0.65,3.84-1.94,5.05c-1.3,1.21-3.27,1.82-5.93,1.82h-3.6v7.91h-6.61V34.43L73.41,34.43z M80.03,43.52h1.61 c1.27,0,2.16-0.22,2.68-0.66c0.51-0.44,0.77-1,0.77-1.69c0-0.67-0.22-1.24-0.67-1.7c-0.44-0.47-1.28-0.7-2.51-0.7h-1.88V43.52 L80.03,43.52z M56.38,81.34h10.21v-5.79H56.38V81.34L56.38,81.34z M89.11,94.88v8.27h25.97c1.97,0,3.22-1.04,3.76-2.37 c0.22-0.54,0.33-1.15,0.33-1.76s-0.11-1.22-0.33-1.76c-0.54-1.33-1.79-2.37-3.76-2.37H89.11L89.11,94.88z M36,103.15v-8.27H7.8 c-1.97,0-3.22,1.04-3.76,2.37c-0.22,0.54-0.33,1.15-0.33,1.76s0.11,1.22,0.33,1.76c0.54,1.33,1.79,2.37,3.76,2.37H36L36,103.15z M20.23,20.38h-3.35l5.1,48.57c0.08,0.78,0.39,1.47,0.87,1.95c0.4,0.4,0.92,0.64,1.53,0.64h72.54c0.59,0,1.1-0.24,1.48-0.62 c0.49-0.49,0.82-1.22,0.93-2.03l6.6-48.51L20.23,20.38L20.23,20.38L20.23,20.38z M22.19,10.6v5.83l78.46-0.83v-5H57.61 c-1.09,0-1.97-0.88-1.97-1.97V3.94H27.66v4.69c0,1.09-0.88,1.97-1.97,1.97L22.19,10.6L22.19,10.6L22.19,10.6z"/></g></svg>
|
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -1,6 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import MuiTextField from '@mui/material/TextField';
|
import MuiTextField from '@mui/material/TextField';
|
||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
|
|
||||||
import useDynamicFields from 'hooks/useDynamicFields';
|
import useDynamicFields from 'hooks/useDynamicFields';
|
||||||
import useDynamicData from 'hooks/useDynamicData';
|
import useDynamicData from 'hooks/useDynamicData';
|
||||||
import PowerInput from 'components/PowerInput';
|
import PowerInput from 'components/PowerInput';
|
||||||
@@ -8,8 +9,10 @@ import TextField from 'components/TextField';
|
|||||||
import ControlledAutocomplete from 'components/ControlledAutocomplete';
|
import ControlledAutocomplete from 'components/ControlledAutocomplete';
|
||||||
import ControlledCustomAutocomplete from 'components/ControlledCustomAutocomplete';
|
import ControlledCustomAutocomplete from 'components/ControlledCustomAutocomplete';
|
||||||
import DynamicField from 'components/DynamicField';
|
import DynamicField from 'components/DynamicField';
|
||||||
|
|
||||||
const optionGenerator = (options) =>
|
const optionGenerator = (options) =>
|
||||||
options?.map(({ name, value }) => ({ label: name, value: value }));
|
options?.map(({ name, value }) => ({ label: name, value: value }));
|
||||||
|
|
||||||
export default function InputCreator(props) {
|
export default function InputCreator(props) {
|
||||||
const {
|
const {
|
||||||
onChange,
|
onChange,
|
||||||
@@ -31,9 +34,12 @@ export default function InputCreator(props) {
|
|||||||
type,
|
type,
|
||||||
} = schema;
|
} = schema;
|
||||||
const { data, loading } = useDynamicData(stepId, schema);
|
const { data, loading } = useDynamicData(stepId, schema);
|
||||||
const { data: additionalFields, loading: additionalFieldsLoading } =
|
const { data: additionalFieldsData, isLoading: isDynamicFieldsLoading } =
|
||||||
useDynamicFields(stepId, schema);
|
useDynamicFields(stepId, schema);
|
||||||
|
const additionalFields = additionalFieldsData?.data;
|
||||||
|
|
||||||
const computedName = namePrefix ? `${namePrefix}.${name}` : name;
|
const computedName = namePrefix ? `${namePrefix}.${name}` : name;
|
||||||
|
|
||||||
if (type === 'dynamic') {
|
if (type === 'dynamic') {
|
||||||
return (
|
return (
|
||||||
<DynamicField
|
<DynamicField
|
||||||
@@ -50,8 +56,10 @@ export default function InputCreator(props) {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'dropdown') {
|
if (type === 'dropdown') {
|
||||||
const preparedOptions = schema.options || optionGenerator(data);
|
const preparedOptions = schema.options || optionGenerator(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{!schema.variables && (
|
{!schema.variables && (
|
||||||
@@ -63,7 +71,9 @@ export default function InputCreator(props) {
|
|||||||
disablePortal
|
disablePortal
|
||||||
disableClearable={required}
|
disableClearable={required}
|
||||||
options={preparedOptions}
|
options={preparedOptions}
|
||||||
renderInput={(params) => <MuiTextField {...params} label={label} required={required}/>}
|
renderInput={(params) => (
|
||||||
|
<MuiTextField {...params} label={label} required={required} />
|
||||||
|
)}
|
||||||
defaultValue={value}
|
defaultValue={value}
|
||||||
description={description}
|
description={description}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
@@ -93,7 +103,7 @@ export default function InputCreator(props) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{additionalFieldsLoading && !additionalFields?.length && (
|
{isDynamicFieldsLoading && !additionalFields?.length && (
|
||||||
<div>
|
<div>
|
||||||
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
|
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
|
||||||
</div>
|
</div>
|
||||||
@@ -113,6 +123,7 @@ export default function InputCreator(props) {
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'string') {
|
if (type === 'string') {
|
||||||
if (schema.variables) {
|
if (schema.variables) {
|
||||||
return (
|
return (
|
||||||
@@ -127,7 +138,7 @@ export default function InputCreator(props) {
|
|||||||
shouldUnregister={shouldUnregister}
|
shouldUnregister={shouldUnregister}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{additionalFieldsLoading && !additionalFields?.length && (
|
{isDynamicFieldsLoading && !additionalFields?.length && (
|
||||||
<div>
|
<div>
|
||||||
<CircularProgress
|
<CircularProgress
|
||||||
sx={{ display: 'block', margin: '20px auto' }}
|
sx={{ display: 'block', margin: '20px auto' }}
|
||||||
@@ -149,6 +160,7 @@ export default function InputCreator(props) {
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -168,7 +180,7 @@ export default function InputCreator(props) {
|
|||||||
shouldUnregister={shouldUnregister}
|
shouldUnregister={shouldUnregister}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{additionalFieldsLoading && !additionalFields?.length && (
|
{isDynamicFieldsLoading && !additionalFields?.length && (
|
||||||
<div>
|
<div>
|
||||||
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
|
<CircularProgress sx={{ display: 'block', margin: '20px auto' }} />
|
||||||
</div>
|
</div>
|
||||||
|
@@ -5,7 +5,7 @@ export default function useAppConfig(appKey) {
|
|||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['appConfig', appKey],
|
queryKey: ['appConfig', appKey],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
const { data } = await api.get(`/v1/app-configs/${appKey}`, {
|
const { data } = await api.get(`/v1/apps/${appKey}/config`, {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,27 +1,35 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useLazyQuery } from '@apollo/client';
|
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
import set from 'lodash/set';
|
import set from 'lodash/set';
|
||||||
import isEqual from 'lodash/isEqual';
|
import isEqual from 'lodash/isEqual';
|
||||||
import { GET_DYNAMIC_FIELDS } from 'graphql/queries/get-dynamic-fields';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import api from 'helpers/api';
|
||||||
|
|
||||||
const variableRegExp = /({.*?})/;
|
const variableRegExp = /({.*?})/;
|
||||||
// TODO: extract this function to a separate file
|
// TODO: extract this function to a separate file
|
||||||
function computeArguments(args, getValues) {
|
function computeArguments(args, getValues) {
|
||||||
const initialValue = {};
|
const initialValue = {};
|
||||||
|
|
||||||
return args.reduce((result, { name, value }) => {
|
return args.reduce((result, { name, value }) => {
|
||||||
const isVariable = variableRegExp.test(value);
|
const isVariable = variableRegExp.test(value);
|
||||||
|
|
||||||
if (isVariable) {
|
if (isVariable) {
|
||||||
const sanitizedFieldPath = value.replace(/{|}/g, '');
|
const sanitizedFieldPath = value.replace(/{|}/g, '');
|
||||||
const computedValue = getValues(sanitizedFieldPath);
|
const computedValue = getValues(sanitizedFieldPath);
|
||||||
|
|
||||||
if (computedValue === undefined || computedValue === '')
|
if (computedValue === undefined || computedValue === '')
|
||||||
throw new Error(`The ${sanitizedFieldPath} field is required.`);
|
throw new Error(`The ${sanitizedFieldPath} field is required.`);
|
||||||
|
|
||||||
set(result, name, computedValue);
|
set(result, name, computedValue);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(result, name, value);
|
set(result, name, value);
|
||||||
return result;
|
return result;
|
||||||
}, initialValue);
|
}, initialValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the dynamic fields for the given step.
|
* Fetch the dynamic fields for the given step.
|
||||||
* This hook must be within a react-hook-form context.
|
* This hook must be within a react-hook-form context.
|
||||||
@@ -31,10 +39,9 @@ function computeArguments(args, getValues) {
|
|||||||
*/
|
*/
|
||||||
function useDynamicFields(stepId, schema) {
|
function useDynamicFields(stepId, schema) {
|
||||||
const lastComputedVariables = React.useRef({});
|
const lastComputedVariables = React.useRef({});
|
||||||
const [getDynamicFields, { called, data, loading }] =
|
|
||||||
useLazyQuery(GET_DYNAMIC_FIELDS);
|
|
||||||
const { getValues } = useFormContext();
|
const { getValues } = useFormContext();
|
||||||
const formValues = getValues();
|
const formValues = getValues();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return `null` when even a field is missing value.
|
* Return `null` when even a field is missing value.
|
||||||
*
|
*
|
||||||
@@ -58,31 +65,28 @@ function useDynamicFields(stepId, schema) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
/**
|
/**
|
||||||
* `formValues` is to trigger recomputation when form is updated.
|
* `formValues` is to trigger recomputation when form is updated.
|
||||||
* `getValues` is for convenience as it supports paths for fields like `getValues('foo.bar.baz')`.
|
* `getValues` is for convenience as it supports paths for fields like `getValues('foo.bar.baz')`.
|
||||||
*/
|
*/
|
||||||
}, [schema, formValues, getValues]);
|
}, [schema, formValues, getValues]);
|
||||||
React.useEffect(() => {
|
|
||||||
if (
|
const query = useQuery({
|
||||||
schema.type === 'dropdown' &&
|
queryKey: ['dynamicFields', stepId, computedVariables],
|
||||||
stepId &&
|
queryFn: async () => {
|
||||||
schema.additionalFields &&
|
const { data } = await api.post(`/v1/steps/${stepId}/dynamic-fields`, {
|
||||||
computedVariables
|
dynamicFieldsKey: computedVariables.key,
|
||||||
) {
|
parameters: computedVariables.parameters,
|
||||||
getDynamicFields({
|
|
||||||
variables: {
|
|
||||||
stepId,
|
|
||||||
...computedVariables,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}, [getDynamicFields, stepId, schema, computedVariables]);
|
return data;
|
||||||
return {
|
},
|
||||||
called,
|
enabled: !!stepId && !!computedVariables,
|
||||||
data: data?.getDynamicFields,
|
});
|
||||||
loading,
|
|
||||||
};
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useDynamicFields;
|
export default useDynamicFields;
|
||||||
|
@@ -79,7 +79,7 @@ export default function useUserTrial() {
|
|||||||
[checkoutCompleted, hasTrial, setIsPolling],
|
[checkoutCompleted, hasTrial, setIsPolling],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isUserTrialLoading || !userTrial) return null;
|
if (isUserTrialLoading || !hasTrial) return null;
|
||||||
|
|
||||||
const expireAt = DateTime.fromISO(userTrial?.expireAt).startOf('day');
|
const expireAt = DateTime.fromISO(userTrial?.expireAt).startOf('day');
|
||||||
|
|
||||||
|
@@ -5471,11 +5471,6 @@ basic-auth@^2.0.1, basic-auth@~2.0.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
safe-buffer "5.1.2"
|
safe-buffer "5.1.2"
|
||||||
|
|
||||||
basic-ftp@^5.0.5:
|
|
||||||
version "5.0.5"
|
|
||||||
resolved "https://registry.yarnpkg.com/basic-ftp/-/basic-ftp-5.0.5.tgz#14a474f5fffecca1f4f406f1c26b18f800225ac0"
|
|
||||||
integrity sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg==
|
|
||||||
|
|
||||||
batch@0.6.1:
|
batch@0.6.1:
|
||||||
version "0.6.1"
|
version "0.6.1"
|
||||||
resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz"
|
resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz"
|
||||||
|
Reference in New Issue
Block a user