Compare commits
5 Commits
hubspot-do
...
AUT-758
Author | SHA1 | Date | |
---|---|---|---|
![]() |
01472c1fb9 | ||
![]() |
703e434e5c | ||
![]() |
c12dacfa40 | ||
![]() |
71a404063c | ||
![]() |
8bb7b16c0e |
@@ -38,7 +38,6 @@
|
|||||||
"debug": "~2.6.9",
|
"debug": "~2.6.9",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "~4.18.2",
|
"express": "~4.18.2",
|
||||||
"express-async-handler": "^1.2.0",
|
|
||||||
"express-basic-auth": "^1.2.1",
|
"express-basic-auth": "^1.2.1",
|
||||||
"express-graphql": "^0.12.0",
|
"express-graphql": "^0.12.0",
|
||||||
"fast-xml-parser": "^4.0.11",
|
"fast-xml-parser": "^4.0.11",
|
||||||
@@ -95,7 +94,6 @@
|
|||||||
"url": "https://github.com/automatisch/automatisch/issues"
|
"url": "https://github.com/automatisch/automatisch/issues"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/utils": "^7.0.2",
|
|
||||||
"nodemon": "^2.0.13",
|
"nodemon": "^2.0.13",
|
||||||
"supertest": "^6.3.3",
|
"supertest": "^6.3.3",
|
||||||
"vitest": "^1.1.3"
|
"vitest": "^1.1.3"
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Delete document',
|
||||||
|
key: 'deleteDocument',
|
||||||
|
description: 'Deletes a document.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Document ID',
|
||||||
|
key: 'documentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const { documentId } = $.step.parameters;
|
||||||
|
|
||||||
|
await $.http.delete(`/v1/documents/${documentId}`);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: {
|
||||||
|
result: 'successful',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,27 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Find document',
|
||||||
|
key: 'findDocument',
|
||||||
|
description: 'Finds a document.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Document ID',
|
||||||
|
key: 'documentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const { documentId } = $.step.parameters;
|
||||||
|
|
||||||
|
const { data } = await $.http.get(`/v1/documents/${documentId}`);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data.document,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,241 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Generate document',
|
||||||
|
key: 'generateDocument',
|
||||||
|
description: 'Creates a new document.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Workspace',
|
||||||
|
key: 'workspaceId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listWorkspaces',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Template',
|
||||||
|
key: 'templateId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: false,
|
||||||
|
depensOn: ['parameters.workspaceId'],
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listTemplates',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.workspaceId',
|
||||||
|
value: '{parameters.workspaceId}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Use a Custom Json Structure?',
|
||||||
|
key: 'useCustomJsonStructure',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description:
|
||||||
|
'Please indicate "yes" if you would rather create a full JSON payload instead of relying on Automatisch mapping for the Document data.',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
additionalFields: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicFields',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listDocumentData',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.useCustomJsonStructure',
|
||||||
|
value: '{parameters.useCustomJsonStructure}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Add Line Items?',
|
||||||
|
key: 'addLineItems',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description:
|
||||||
|
'Choose "yes" to include information for Line Items (such as in an invoice).',
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Yes',
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'No',
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
additionalFields: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicFields',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listLineItems',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.addLineItems',
|
||||||
|
value: '{parameters.addLineItems}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Custom Filename',
|
||||||
|
key: 'customFilename',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'You have the option to define a custom filename for generated documents. If left blank, a random value will be assigned.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Meta Data',
|
||||||
|
key: 'metaData',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Extra information appended to the generated Document but not accessible within its Template.',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'metaDataKey',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Value',
|
||||||
|
key: 'metaDataValue',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const {
|
||||||
|
templateId,
|
||||||
|
useCustomJsonStructure,
|
||||||
|
customJsonPayload,
|
||||||
|
customFilename,
|
||||||
|
addLineItems,
|
||||||
|
lineItems,
|
||||||
|
documentData,
|
||||||
|
metaData,
|
||||||
|
} = $.step.parameters;
|
||||||
|
let payload = {};
|
||||||
|
let meta = {};
|
||||||
|
|
||||||
|
const documentDataObject = documentData.reduce((result, entry) => {
|
||||||
|
const key = entry.documentDataKey?.toLowerCase();
|
||||||
|
const value = entry.documentDataValue;
|
||||||
|
|
||||||
|
if (key && value) {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[entry.documentDataKey?.toLowerCase()]: entry.documentDataValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const lineItemsObject = lineItems.reduce((result, entry) => {
|
||||||
|
const key = entry.lineItemKey?.toLowerCase();
|
||||||
|
const value = entry.lineItemValue;
|
||||||
|
|
||||||
|
if (key && value) {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[entry.lineItemKey?.toLowerCase()]: entry.lineItemValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const metaDataObject = metaData.reduce((result, entry) => {
|
||||||
|
const key = entry.metaDataKey?.toLowerCase();
|
||||||
|
const value = entry.metaDataValue;
|
||||||
|
|
||||||
|
if (key && value) {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[entry.metaDataKey?.toLowerCase()]: entry.metaDataValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
if (metaDataObject) {
|
||||||
|
meta = metaDataObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customFilename) {
|
||||||
|
meta._filename = customFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useCustomJsonStructure) {
|
||||||
|
payload = JSON.parse(customJsonPayload);
|
||||||
|
} else {
|
||||||
|
payload = documentDataObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addLineItems) {
|
||||||
|
payload.lineItems = [lineItemsObject];
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
document: {
|
||||||
|
document_template_id: templateId,
|
||||||
|
meta: JSON.stringify(meta),
|
||||||
|
payload: JSON.stringify(payload),
|
||||||
|
status: 'pending',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.post('/v1/documents', body);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
5
packages/backend/src/apps/pdf-monkey/actions/index.js
Normal file
5
packages/backend/src/apps/pdf-monkey/actions/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import deleteDocument from './delete-document/index.js';
|
||||||
|
import findDocument from './find-document/index.js';
|
||||||
|
import generateDocument from './generate-document/index.js';
|
||||||
|
|
||||||
|
export default [deleteDocument, findDocument, generateDocument];
|
1487
packages/backend/src/apps/pdf-monkey/assets/favicon.svg
Normal file
1487
packages/backend/src/apps/pdf-monkey/assets/favicon.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 112 KiB |
21
packages/backend/src/apps/pdf-monkey/auth/index.js
Normal file
21
packages/backend/src/apps/pdf-monkey/auth/index.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'apiKey',
|
||||||
|
label: 'API Key',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: 'PDFMonkey API secret key of your account.',
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
verifyCredentials,
|
||||||
|
isStillVerified,
|
||||||
|
};
|
@@ -0,0 +1,8 @@
|
|||||||
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
const currentUser = await getCurrentUser($);
|
||||||
|
return !!currentUser.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
@@ -0,0 +1,15 @@
|
|||||||
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
|
const verifyCredentials = async ($) => {
|
||||||
|
const currentUser = await getCurrentUser($);
|
||||||
|
const screenName = [currentUser.desired_name, currentUser.email]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' @ ');
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
screenName,
|
||||||
|
apiKey: $.auth.data.apiKey,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyCredentials;
|
@@ -0,0 +1,9 @@
|
|||||||
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
if ($.auth.data?.apiKey) {
|
||||||
|
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
@@ -0,0 +1,8 @@
|
|||||||
|
const getCurrentUser = async ($) => {
|
||||||
|
const response = await $.http.get('/v1/current_user');
|
||||||
|
const currentUser = response.data.current_user;
|
||||||
|
|
||||||
|
return currentUser;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getCurrentUser;
|
@@ -0,0 +1,4 @@
|
|||||||
|
import listTemplates from './list-templates/index.js';
|
||||||
|
import listWorkspaces from './list-workspaces/index.js';
|
||||||
|
|
||||||
|
export default [listTemplates, listWorkspaces];
|
@@ -0,0 +1,39 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List templates',
|
||||||
|
key: 'listTemplates',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const templates = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
const workspaceId = $.step.parameters.workspaceId;
|
||||||
|
let next = false;
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
page: 'all',
|
||||||
|
'q[workspace_id]': workspaceId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!workspaceId) {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/v1/document_template_cards', params);
|
||||||
|
next = data.meta.next_page;
|
||||||
|
|
||||||
|
if (!data?.document_template_cards?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const template of data.document_template_cards) {
|
||||||
|
templates.data.push({
|
||||||
|
value: template.id,
|
||||||
|
name: template.identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} while (next);
|
||||||
|
|
||||||
|
return templates;
|
||||||
|
},
|
||||||
|
};
|
@@ -0,0 +1,29 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List workspaces',
|
||||||
|
key: 'listWorkspaces',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const workspaces = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
let next = false;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/v1/workspace_cards');
|
||||||
|
next = data.meta.next_page;
|
||||||
|
|
||||||
|
if (!data?.workspace_cards?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const workspace of data.workspace_cards) {
|
||||||
|
workspaces.data.push({
|
||||||
|
value: workspace.id,
|
||||||
|
name: workspace.identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} while (next);
|
||||||
|
|
||||||
|
return workspaces;
|
||||||
|
},
|
||||||
|
};
|
@@ -0,0 +1,4 @@
|
|||||||
|
import listDocumentData from './list-document-data/index.js';
|
||||||
|
import listLineItems from './list-line-items/index.js';
|
||||||
|
|
||||||
|
export default [listDocumentData, listLineItems];
|
@@ -0,0 +1,48 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List document data',
|
||||||
|
key: 'listDocumentData',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
if ($.step.parameters.useCustomJsonStructure) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Data for the Document (JSON Payload)',
|
||||||
|
key: 'customJsonPayload',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Use the JSON format { "firstname": "John", "lastname": "Doe" }.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Data for the Document',
|
||||||
|
key: 'documentData',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'documentDataKey',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Value',
|
||||||
|
key: 'documentDataValue',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
@@ -0,0 +1,37 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List line items',
|
||||||
|
key: 'listLineItems',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
if ($.step.parameters.addLineItems) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'Line Items',
|
||||||
|
key: 'lineItems',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Data for a single item. Available as "lineItems" in your PDFMonkey Template.',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'lineItemKey',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Value',
|
||||||
|
key: 'lineItemValue',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
24
packages/backend/src/apps/pdf-monkey/index.js
Normal file
24
packages/backend/src/apps/pdf-monkey/index.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import defineApp from '../../helpers/define-app.js';
|
||||||
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
|
import auth from './auth/index.js';
|
||||||
|
import triggers from './triggers/index.js';
|
||||||
|
import dynamicData from './dynamic-data/index.js';
|
||||||
|
import actions from './actions/index.js';
|
||||||
|
import dynamicFields from './dynamic-fields/index.js';
|
||||||
|
|
||||||
|
export default defineApp({
|
||||||
|
name: 'PDFMonkey',
|
||||||
|
key: 'pdf-monkey',
|
||||||
|
iconUrl: '{BASE_URL}/apps/pdf-monkey/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/apps/pdf-monkey/connection',
|
||||||
|
supportsConnections: true,
|
||||||
|
baseUrl: 'https://pdfmonkey.io',
|
||||||
|
apiBaseUrl: 'https://api.pdfmonkey.io/api',
|
||||||
|
primaryColor: '376794',
|
||||||
|
beforeRequest: [addAuthHeader],
|
||||||
|
auth,
|
||||||
|
triggers,
|
||||||
|
dynamicData,
|
||||||
|
actions,
|
||||||
|
dynamicFields,
|
||||||
|
});
|
@@ -0,0 +1,99 @@
|
|||||||
|
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||||
|
|
||||||
|
export default defineTrigger({
|
||||||
|
name: 'Documents Generated',
|
||||||
|
key: 'documentsGenerated',
|
||||||
|
pollInterval: 15,
|
||||||
|
description:
|
||||||
|
'Triggers upon the successful completion of document generation.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Workspace',
|
||||||
|
key: 'workspaceId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listWorkspaces',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Templates',
|
||||||
|
key: 'templateIds',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description: 'Apply this trigger exclusively for particular templates.',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Template',
|
||||||
|
key: 'templateId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: false,
|
||||||
|
depensOn: ['parameters.workspaceId'],
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listTemplates',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'parameters.workspaceId',
|
||||||
|
value: '{parameters.workspaceId}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const workspaceId = $.step.parameters.workspaceId;
|
||||||
|
const templateIds = $.step.parameters.templateIds;
|
||||||
|
const allTemplates = templateIds
|
||||||
|
.map((templateId) => templateId.templateId)
|
||||||
|
.join(',');
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
'page[size]': 100,
|
||||||
|
'q[workspace_id]': workspaceId,
|
||||||
|
'q[status]': 'success',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!templateIds.length) {
|
||||||
|
params['q[document_template_id]'] = allTemplates;
|
||||||
|
}
|
||||||
|
|
||||||
|
let next = false;
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/v1/document_cards', { params });
|
||||||
|
|
||||||
|
if (!data?.document_cards?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
next = data.meta.next_page;
|
||||||
|
|
||||||
|
for (const document of data.document_cards) {
|
||||||
|
$.pushTriggerItem({
|
||||||
|
raw: document,
|
||||||
|
meta: {
|
||||||
|
internalId: document.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} while (next);
|
||||||
|
},
|
||||||
|
});
|
3
packages/backend/src/apps/pdf-monkey/triggers/index.js
Normal file
3
packages/backend/src/apps/pdf-monkey/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import documentsGenerated from './documents-generated/index.js';
|
||||||
|
|
||||||
|
export default [documentsGenerated];
|
@@ -1,10 +0,0 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
|
||||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const appAuthClient = await AppAuthClient.query()
|
|
||||||
.findById(request.params.appAuthClientId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
|
||||||
};
|
|
@@ -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/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,6 +0,0 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
|
||||||
import permissionCatalog from '../../../../../helpers/permission-catalog.ee.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
renderObject(response, permissionCatalog);
|
|
||||||
};
|
|
@@ -1,32 +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 { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getPermissionsCatalogMock from '../../../../../../test/mocks/rest/api/v1/admin/permissions/get-permissions-catalog.ee.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/permissions/catalog', () => {
|
|
||||||
let role, currentUser, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
role = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: role.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return roles', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/admin/permissions/catalog')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getPermissionsCatalogMock();
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,16 +0,0 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
|
||||||
import Role from '../../../../../models/role.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const role = await Role.query()
|
|
||||||
.leftJoinRelated({
|
|
||||||
permissions: true,
|
|
||||||
})
|
|
||||||
.withGraphFetched({
|
|
||||||
permissions: true,
|
|
||||||
})
|
|
||||||
.findById(request.params.roleId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
renderObject(response, role);
|
|
||||||
};
|
|
@@ -1,59 +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 { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import { createPermission } from '../../../../../../test/factories/permission.js';
|
|
||||||
import getRoleMock from '../../../../../../test/mocks/rest/api/v1/admin/roles/get-role.ee.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/roles/:roleId', () => {
|
|
||||||
let role, currentUser, token, permissionOne, permissionTwo;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
role = await createRole({ key: 'admin' });
|
|
||||||
permissionOne = await createPermission({ roleId: role.id });
|
|
||||||
permissionTwo = await createPermission({ roleId: role.id });
|
|
||||||
currentUser = await createUser({ roleId: role.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return role', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/admin/roles/${role.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getRoleMock(role, [
|
|
||||||
permissionOne,
|
|
||||||
permissionTwo,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not found response for not existing role UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const notExistingRoleUUID = Crypto.randomUUID();
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get(`/api/v1/admin/roles/${notExistingRoleUUID}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/admin/roles/invalidRoleUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,8 +0,0 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
|
||||||
import Role from '../../../../../models/role.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const roles = await Role.query().orderBy('name');
|
|
||||||
|
|
||||||
renderObject(response, roles);
|
|
||||||
};
|
|
@@ -1,33 +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 { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getRolesMock from '../../../../../../test/mocks/rest/api/v1/admin/roles/get-roles.ee.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/roles', () => {
|
|
||||||
let roleOne, roleTwo, currentUser, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
roleOne = await createRole({ key: 'admin' });
|
|
||||||
roleTwo = await createRole({ key: 'user' });
|
|
||||||
currentUser = await createUser({ roleId: roleOne.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return roles', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/admin/roles')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getRolesMock([roleOne, roleTwo]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,12 +1,11 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import Crypto from 'crypto';
|
|
||||||
import app from '../../../../../app.js';
|
import app from '../../../../../app.js';
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
import { createSamlAuthProvider } from '../../../../../../test/factories/saml-auth-provider.ee.js';
|
import { createSamlAuthProvider } from '../../../../../../test/factories/saml-auth-provider.ee.js';
|
||||||
import getSamlAuthProviderMock from '../../../../../../test/mocks/rest/api/v1/admin/saml-auth-providers/get-saml-auth-provider.ee.js';
|
import getSamlAuthProviderMock from '../../../../../../test/mocks/rest/api/v1/saml-auth-providers/get-saml-auth-provider.ee.js';
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/admin/saml-auth-provider/:samlAuthProviderId', () => {
|
describe('GET /api/v1/admin/saml-auth-provider/:samlAuthProviderId', () => {
|
||||||
@@ -32,26 +31,4 @@ describe('GET /api/v1/admin/saml-auth-provider/:samlAuthProviderId', () => {
|
|||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
expect(response.body).toEqual(expectedPayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return not found response for not existing saml auth provider UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const notExistingSamlAuthProviderUUID = Crypto.randomUUID();
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get(
|
|
||||||
`/api/v1/admin/saml-auth-providers/${notExistingSamlAuthProviderUUID}`
|
|
||||||
)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/admin/saml-auth-providers/invalidSamlAuthProviderUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@@ -5,7 +5,7 @@ import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by
|
|||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
import { createSamlAuthProvider } from '../../../../../../test/factories/saml-auth-provider.ee.js';
|
import { createSamlAuthProvider } from '../../../../../../test/factories/saml-auth-provider.ee.js';
|
||||||
import getSamlAuthProvidersMock from '../../../../../../test/mocks/rest/api/v1/admin/saml-auth-providers/get-saml-auth-providers.ee.js';
|
import getSamlAuthProvidersMock from '../../../../../../test/mocks/rest/api/v1/saml-auth-providers/get-saml-auth-providers.ee.js';
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/admin/saml-auth-providers', () => {
|
describe('GET /api/v1/admin/saml-auth-providers', () => {
|
||||||
|
@@ -1,55 +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';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role';
|
|
||||||
import getUserMock from '../../../../../../test/mocks/rest/api/v1/admin/users/get-user.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/users/:userId', () => {
|
|
||||||
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
|
|
||||||
anotherUser = await createUser();
|
|
||||||
anotherUserRole = await anotherUser.$relatedQuery('role');
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return specified user info', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/admin/users/${anotherUser.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getUserMock(anotherUser, anotherUserRole);
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not found response for not existing user UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const notExistingUserUUID = Crypto.randomUUID();
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get(`/api/v1/admin/users/${notExistingUserUUID}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/admin/users/invalidUserUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,11 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
import AppAuthClient from '../../../../models/app-auth-client.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const appAuthClient = await AppAuthClient.query()
|
|
||||||
.findById(request.params.appAuthClientId)
|
|
||||||
.where({ active: true })
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
|
||||||
};
|
|
@@ -1,48 +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 getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/admin/get-app-auth-client.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/app-auth-clients/:id', () => {
|
|
||||||
let currentUser, currentAppAuthClient, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUser = await createUser();
|
|
||||||
currentAppAuthClient = await createAppAuthClient();
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/app-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/app-auth-clients/${notExistingAppAuthClientUUID}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/app-auth-clients/invalidAppAuthClientUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,8 +0,0 @@
|
|||||||
import App from '../../../../models/app.js';
|
|
||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const app = await App.findOneByKey(request.params.appKey);
|
|
||||||
|
|
||||||
renderObject(response, app, { serializer: 'App' });
|
|
||||||
};
|
|
@@ -1,35 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import App from '../../../../models/app';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
|
|
||||||
import { createUser } from '../../../../../test/factories/user';
|
|
||||||
import getAppMock from '../../../../../test/mocks/rest/api/v1/apps/get-app.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/apps/:appKey', () => {
|
|
||||||
let currentUser, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
currentUser = await createUser();
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the app info', async () => {
|
|
||||||
const exampleApp = await App.findOneByKey('github');
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/apps/${exampleApp.key}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAppMock(exampleApp);
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not found response for invalid app key', async () => {
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/apps/invalid-app-key')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,13 +0,0 @@
|
|||||||
import appConfig from '../../../../config/app.js';
|
|
||||||
import { hasValidLicense } from '../../../../helpers/license.ee.js';
|
|
||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const info = {
|
|
||||||
isCloud: appConfig.isCloud,
|
|
||||||
isMation: appConfig.isMation,
|
|
||||||
isEnterprise: await hasValidLicense(),
|
|
||||||
};
|
|
||||||
|
|
||||||
renderObject(response, info);
|
|
||||||
};
|
|
@@ -1,22 +0,0 @@
|
|||||||
import { vi, expect, describe, it } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import appConfig from '../../../../config/app.js';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
import infoMock from '../../../../../test/mocks/rest/api/v1/automatisch/info.js';
|
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/automatisch/info', () => {
|
|
||||||
it('should return Automatisch info', async () => {
|
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
|
||||||
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false);
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/automatisch/info')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = infoMock();
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,15 +0,0 @@
|
|||||||
import { getLicense } from '../../../../helpers/license.ee.js';
|
|
||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const license = await getLicense();
|
|
||||||
|
|
||||||
const computedLicense = {
|
|
||||||
id: license ? license.id : null,
|
|
||||||
name: license ? license.name : null,
|
|
||||||
expireAt: license ? license.expireAt : null,
|
|
||||||
verified: license ? true : false,
|
|
||||||
};
|
|
||||||
|
|
||||||
renderObject(response, computedLicense);
|
|
||||||
};
|
|
@@ -1,23 +0,0 @@
|
|||||||
import { vi, expect, describe, it } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
import licenseMock from '../../../../../test/mocks/rest/api/v1/automatisch/license.js';
|
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/automatisch/license', () => {
|
|
||||||
it('should return Automatisch license info', async () => {
|
|
||||||
vi.spyOn(license, 'getLicense').mockResolvedValue({
|
|
||||||
id: '123',
|
|
||||||
name: 'license-name',
|
|
||||||
expireAt: '2025-12-31T23:59:59Z',
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/automatisch/license')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = licenseMock();
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,19 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
import axios from '../../../../helpers/axios-with-proxy.js';
|
|
||||||
import logger from '../../../../helpers/logger.js';
|
|
||||||
|
|
||||||
const NOTIFICATIONS_URL =
|
|
||||||
'https://notifications.automatisch.io/notifications.json';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
let notifications = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.get(NOTIFICATIONS_URL);
|
|
||||||
notifications = response.data;
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Error fetching notifications API endpoint!', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderObject(response, notifications);
|
|
||||||
};
|
|
@@ -1,9 +0,0 @@
|
|||||||
import { describe, it } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/automatisch/notifications', () => {
|
|
||||||
it('should return Automatisch notifications', async () => {
|
|
||||||
await request(app).get('/api/v1/automatisch/notifications').expect(200);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,11 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const flow = await request.currentUser.authorizedFlows
|
|
||||||
.withGraphJoined({ steps: true })
|
|
||||||
.orderBy('steps.position', 'asc')
|
|
||||||
.findOne({ 'flows.id': request.params.flowId })
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
renderObject(response, flow);
|
|
||||||
};
|
|
@@ -1,102 +0,0 @@
|
|||||||
import { 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';
|
|
||||||
import { createUser } from '../../../../../test/factories/user';
|
|
||||||
import { createFlow } from '../../../../../test/factories/flow';
|
|
||||||
import { createStep } from '../../../../../test/factories/step';
|
|
||||||
import { createPermission } from '../../../../../test/factories/permission';
|
|
||||||
import getFlowMock from '../../../../../test/mocks/rest/api/v1/flows/get-flow';
|
|
||||||
|
|
||||||
describe('GET /api/v1/flows/:flowId', () => {
|
|
||||||
let currentUser, currentUserRole, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
currentUser = await createUser();
|
|
||||||
currentUserRole = await currentUser.$relatedQuery('role');
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the flow data of current user', async () => {
|
|
||||||
const currentUserflow = await createFlow({ userId: currentUser.id });
|
|
||||||
const triggerStep = await createStep({ flowId: currentUserflow.id });
|
|
||||||
const actionStep = await createStep({ flowId: currentUserflow.id });
|
|
||||||
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: ['isCreator'],
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/flows/${currentUserflow.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getFlowMock(currentUserflow, [
|
|
||||||
triggerStep,
|
|
||||||
actionStep,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the flow data of another user', async () => {
|
|
||||||
const anotherUser = await createUser();
|
|
||||||
const anotherUserFlow = await createFlow({ userId: anotherUser.id });
|
|
||||||
const triggerStep = await createStep({ flowId: anotherUserFlow.id });
|
|
||||||
const actionStep = await createStep({ flowId: anotherUserFlow.id });
|
|
||||||
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/flows/${anotherUserFlow.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getFlowMock(anotherUserFlow, [
|
|
||||||
triggerStep,
|
|
||||||
actionStep,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not found response for not existing flow UUID', async () => {
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const notExistingFlowUUID = Crypto.randomUUID();
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get(`/api/v1/flows/${notExistingFlowUUID}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
await createPermission({
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
conditions: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/flows/invalidFlowUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,8 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
import Billing from '../../../../helpers/billing/index.ee.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const paddleInfo = Billing.paddleInfo;
|
|
||||||
|
|
||||||
renderObject(response, paddleInfo);
|
|
||||||
};
|
|
@@ -1,33 +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 getPaddleInfoMock from '../../../../../test/mocks/rest/api/v1/payment/get-paddle-info.js';
|
|
||||||
import appConfig from '../../../../config/app.js';
|
|
||||||
import billing from '../../../../helpers/billing/index.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/payment/paddle-info', () => {
|
|
||||||
let user, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
user = await createUser();
|
|
||||||
token = createAuthTokenByUserId(user.id);
|
|
||||||
|
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
|
||||||
vi.spyOn(billing.paddleInfo, 'vendorId', 'get').mockReturnValue(
|
|
||||||
'sampleVendorId'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return payment plans', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/payment/paddle-info')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = await getPaddleInfoMock();
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,8 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
import Billing from '../../../../helpers/billing/index.ee.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const paymentPlans = Billing.paddlePlans;
|
|
||||||
|
|
||||||
renderObject(response, paymentPlans);
|
|
||||||
};
|
|
@@ -1,29 +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 getPaymentPlansMock from '../../../../../test/mocks/rest/api/v1/payment/get-plans.js';
|
|
||||||
import appConfig from '../../../../config/app.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/payment/plans', () => {
|
|
||||||
let user, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
user = await createUser();
|
|
||||||
token = createAuthTokenByUserId(user.id);
|
|
||||||
|
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return payment plans', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/payment/plans')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = await getPaymentPlansMock();
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,7 +0,0 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const invoices = await request.currentUser.getInvoices();
|
|
||||||
|
|
||||||
renderObject(response, invoices);
|
|
||||||
};
|
|
@@ -1,34 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
|
|
||||||
import { createUser } from '../../../../../test/factories/user';
|
|
||||||
import User from '../../../../models/user';
|
|
||||||
import getInvoicesMock from '../../../../../test/mocks/rest/api/v1/users/get-invoices.ee';
|
|
||||||
|
|
||||||
describe('GET /api/v1/user/invoices', () => {
|
|
||||||
let currentUser, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
currentUser = await createUser();
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return current user invoices', async () => {
|
|
||||||
const invoices = [
|
|
||||||
{ id: 1, amount: 100, description: 'Invoice 1' },
|
|
||||||
{ id: 2, amount: 200, description: 'Invoice 2' },
|
|
||||||
];
|
|
||||||
|
|
||||||
vi.spyOn(User.prototype, 'getInvoices').mockResolvedValue(invoices);
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/users/invoices')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = await getInvoicesMock(invoices);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,8 +1,11 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
import User from '../../../../../models/user.js';
|
import User from '../../../../models/user.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const user = await User.query()
|
const user = await User.query()
|
||||||
|
.leftJoinRelated({
|
||||||
|
role: true,
|
||||||
|
})
|
||||||
.withGraphFetched({
|
.withGraphFetched({
|
||||||
role: true,
|
role: true,
|
||||||
})
|
})
|
@@ -0,0 +1,36 @@
|
|||||||
|
import { 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';
|
||||||
|
import { createUser } from '../../../../../test/factories/user';
|
||||||
|
import { createPermission } from '../../../../../test/factories/permission';
|
||||||
|
import getUserMock from '../../../../../test/mocks/rest/api/v1/users/get-user';
|
||||||
|
|
||||||
|
describe('GET /api/v1/users/:userId', () => {
|
||||||
|
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
currentUser = await createUser();
|
||||||
|
anotherUser = await createUser();
|
||||||
|
currentUserRole = await currentUser.$relatedQuery('role');
|
||||||
|
anotherUserRole = await anotherUser.$relatedQuery('role');
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUserRole.id,
|
||||||
|
action: 'read',
|
||||||
|
subject: 'User',
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified user info', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/users/${anotherUser.id}`)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getUserMock(anotherUser, anotherUserRole);
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -1,9 +1,12 @@
|
|||||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
import User from '../../../../../models/user.js';
|
import User from '../../../../models/user.js';
|
||||||
import paginateRest from '../../../../../helpers/pagination-rest.js';
|
import paginateRest from '../../../../helpers/pagination-rest.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const usersQuery = User.query()
|
const usersQuery = User.query()
|
||||||
|
.leftJoinRelated({
|
||||||
|
role: true,
|
||||||
|
})
|
||||||
.withGraphFetched({
|
.withGraphFetched({
|
||||||
role: true,
|
role: true,
|
||||||
})
|
})
|
@@ -1,17 +1,26 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import app from '../../../../../app';
|
import app from '../../../../app';
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id';
|
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
|
||||||
import { createRole } from '../../../../../../test/factories/role';
|
import { createRole } from '../../../../../test/factories/role';
|
||||||
import { createUser } from '../../../../../../test/factories/user';
|
import { createPermission } from '../../../../../test/factories/permission';
|
||||||
import getUsersMock from '../../../../../../test/mocks/rest/api/v1/admin/users/get-users.js';
|
import { createUser } from '../../../../../test/factories/user';
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
import getUsersMock from '../../../../../test/mocks/rest/api/v1/users/get-users';
|
||||||
|
|
||||||
describe('GET /api/v1/admin/users', () => {
|
describe('GET /api/v1/users', () => {
|
||||||
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
currentUserRole = await createRole({
|
||||||
|
key: 'currentUser',
|
||||||
|
name: 'Current user role',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'User',
|
||||||
|
roleId: currentUserRole.id,
|
||||||
|
});
|
||||||
|
|
||||||
currentUser = await createUser({
|
currentUser = await createUser({
|
||||||
roleId: currentUserRole.id,
|
roleId: currentUserRole.id,
|
||||||
@@ -32,10 +41,8 @@ describe('GET /api/v1/admin/users', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return users data', async () => {
|
it('should return users data', async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get('/api/v1/admin/users')
|
.get('/api/v1/users')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
@@ -1,13 +1,8 @@
|
|||||||
import Step from '../../models/flow.js';
|
|
||||||
|
|
||||||
const deleteStep = async (_parent, params, context) => {
|
const deleteStep = async (_parent, params, context) => {
|
||||||
const conditions = context.currentUser.can('update', 'Flow');
|
context.currentUser.can('update', 'Flow');
|
||||||
const isCreator = conditions.isCreator;
|
|
||||||
const allSteps = Step.query();
|
|
||||||
const userSteps = context.currentUser.$relatedQuery('steps');
|
|
||||||
const baseQuery = isCreator ? userSteps : allSteps;
|
|
||||||
|
|
||||||
const step = await baseQuery
|
const step = await context.currentUser
|
||||||
|
.$relatedQuery('steps')
|
||||||
.withGraphFetched('flow')
|
.withGraphFetched('flow')
|
||||||
.findOne({
|
.findOne({
|
||||||
'steps.id': params.input.id,
|
'steps.id': params.input.id,
|
||||||
|
@@ -7,10 +7,6 @@ const authorizationList = {
|
|||||||
action: 'read',
|
action: 'read',
|
||||||
subject: 'User',
|
subject: 'User',
|
||||||
},
|
},
|
||||||
'GET /api/v1/flows/:flowId': {
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Flow',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const authorizeUser = async (request, response, next) => {
|
export const authorizeUser = async (request, response, next) => {
|
||||||
|
@@ -1,31 +1,14 @@
|
|||||||
import logger from './logger.js';
|
import logger from './logger.js';
|
||||||
import objection from 'objection';
|
|
||||||
const { NotFoundError, DataError } = objection;
|
|
||||||
|
|
||||||
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const errorHandler = (error, request, response, next) => {
|
const errorHandler = (err, req, res, next) => {
|
||||||
if (error.message === 'Not Found' || error instanceof NotFoundError) {
|
if (err.message === 'Not Found') {
|
||||||
response.status(404).end();
|
res.status(404).end();
|
||||||
|
} else {
|
||||||
|
logger.error(err.message + '\n' + err.stack);
|
||||||
|
res.status(err.statusCode || 500).send(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notFoundAppError(error)) {
|
|
||||||
response.status(404).end();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error instanceof DataError) {
|
|
||||||
response.status(400).end();
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.error(error.message + '\n' + error.stack);
|
|
||||||
response.status(error.statusCode || 500).end();
|
|
||||||
};
|
|
||||||
|
|
||||||
const notFoundAppError = (error) => {
|
|
||||||
return (
|
|
||||||
error.message.includes('An application with the') ||
|
|
||||||
error.message.includes("key couldn't be found.")
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default errorHandler;
|
export default errorHandler;
|
||||||
|
@@ -11,18 +11,15 @@ const isArray = (object) =>
|
|||||||
const totalCount = (object) =>
|
const totalCount = (object) =>
|
||||||
isPaginated(object) ? object.totalCount : isArray(object) ? object.length : 1;
|
isPaginated(object) ? object.totalCount : isArray(object) ? object.length : 1;
|
||||||
|
|
||||||
const renderObject = (response, object, options) => {
|
const renderObject = (response, object) => {
|
||||||
let data = isPaginated(object) ? object.records : object;
|
let data = isPaginated(object) ? object.records : object;
|
||||||
|
|
||||||
const type = isPaginated(object)
|
const type = isPaginated(object)
|
||||||
? object.records[0].constructor.name
|
? object.records[0].constructor.name
|
||||||
: Array.isArray(object)
|
: Array.isArray(object)
|
||||||
? object?.[0]?.constructor?.name || 'Object'
|
? object[0].constructor.name
|
||||||
: object.constructor.name;
|
: object.constructor.name;
|
||||||
|
|
||||||
const serializer = options?.serializer
|
const serializer = serializers[type];
|
||||||
? serializers[options.serializer]
|
|
||||||
: serializers[type];
|
|
||||||
|
|
||||||
if (serializer) {
|
if (serializer) {
|
||||||
data = Array.isArray(data)
|
data = Array.isArray(data)
|
||||||
|
@@ -15,7 +15,6 @@ import Role from './role.js';
|
|||||||
import Step from './step.js';
|
import Step from './step.js';
|
||||||
import Subscription from './subscription.ee.js';
|
import Subscription from './subscription.ee.js';
|
||||||
import UsageData from './usage-data.ee.js';
|
import UsageData from './usage-data.ee.js';
|
||||||
import Billing from '../helpers/billing/index.ee.js';
|
|
||||||
|
|
||||||
class User extends Base {
|
class User extends Base {
|
||||||
static tableName = 'users';
|
static tableName = 'users';
|
||||||
@@ -144,11 +143,6 @@ class User extends Base {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
get authorizedFlows() {
|
|
||||||
const conditions = this.can('read', 'Flow');
|
|
||||||
return conditions.isCreator ? this.$relatedQuery('flows') : Flow.query();
|
|
||||||
}
|
|
||||||
|
|
||||||
login(password) {
|
login(password) {
|
||||||
return bcrypt.compare(password, this.password);
|
return bcrypt.compare(password, this.password);
|
||||||
}
|
}
|
||||||
@@ -243,20 +237,6 @@ class User extends Base {
|
|||||||
return currentUsageData.consumedTaskCount < plan.quota;
|
return currentUsageData.consumedTaskCount < plan.quota;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInvoices() {
|
|
||||||
const subscription = await this.$relatedQuery('currentSubscription');
|
|
||||||
|
|
||||||
if (!subscription) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const invoices = await Billing.paddleClient.getInvoices(
|
|
||||||
Number(subscription.paddleSubscriptionId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return invoices;
|
|
||||||
}
|
|
||||||
|
|
||||||
async $beforeInsert(queryContext) {
|
async $beforeInsert(queryContext) {
|
||||||
await super.$beforeInsert(queryContext);
|
await super.$beforeInsert(queryContext);
|
||||||
|
|
||||||
|
@@ -15,17 +15,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await actionQueue.close();
|
await actionQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
actionQueue.on('error', (error) => {
|
actionQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error happened in action queue!', error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default actionQueue;
|
export default actionQueue;
|
||||||
|
@@ -15,17 +15,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await deleteUserQueue.close();
|
await deleteUserQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteUserQueue.on('error', (error) => {
|
deleteUserQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error happened in delete user queue!', error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default deleteUserQueue;
|
export default deleteUserQueue;
|
||||||
|
@@ -15,17 +15,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await emailQueue.close();
|
await emailQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
emailQueue.on('error', (error) => {
|
emailQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error happened in email queue!', error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default emailQueue;
|
export default emailQueue;
|
||||||
|
@@ -15,17 +15,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await flowQueue.close();
|
await flowQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
flowQueue.on('error', (error) => {
|
flowQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error happened in flow queue!', error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default flowQueue;
|
export default flowQueue;
|
||||||
|
@@ -18,20 +18,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await removeCancelledSubscriptionsQueue.close();
|
await removeCancelledSubscriptionsQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
removeCancelledSubscriptionsQueue.on('error', (error) => {
|
removeCancelledSubscriptionsQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(
|
|
||||||
'Error happened in remove cancelled subscriptions queue!',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
removeCancelledSubscriptionsQueue.add('remove-cancelled-subscriptions', null, {
|
removeCancelledSubscriptionsQueue.add('remove-cancelled-subscriptions', null, {
|
||||||
|
@@ -15,17 +15,11 @@ process.on('SIGTERM', async () => {
|
|||||||
await triggerQueue.close();
|
await triggerQueue.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
triggerQueue.on('error', (error) => {
|
triggerQueue.on('error', (err) => {
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
if (err.code === CONNECTION_REFUSED) {
|
||||||
logger.error(
|
logger.error('Make sure you have installed Redis and it is running.', err);
|
||||||
'Make sure you have installed Redis and it is running.',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error happened in trigger queue!', error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default triggerQueue;
|
export default triggerQueue;
|
||||||
|
@@ -1,18 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
|
||||||
import getAdminAppAuthClientsAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-client.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:appAuthClientId',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAdminAppAuthClientsAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,18 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
|
||||||
import getPermissionsCatalogAction from '../../../../controllers/api/v1/admin/permissions/get-permissions-catalog.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/catalog',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getPermissionsCatalogAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,27 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
|
||||||
import getRolesAction from '../../../../controllers/api/v1/admin/roles/get-roles.ee.js';
|
|
||||||
import getRoleAction from '../../../../controllers/api/v1/admin/roles/get-role.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getRolesAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:roleId',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getRoleAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,27 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
|
||||||
import getSamlAuthProvidersAction from '../../../../controllers/api/v1/admin/saml-auth-providers/get-saml-auth-providers.ee.js';
|
|
||||||
import getSamlAuthProviderAction from '../../../../controllers/api/v1/admin/saml-auth-providers/get-saml-auth-provider.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getSamlAuthProvidersAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:samlAuthProviderId',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getSamlAuthProviderAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,27 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
|
||||||
import getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.js';
|
|
||||||
import getUserAction from '../../../../controllers/api/v1/admin/users/get-user.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getUsersAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:userId',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getUserAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
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 getAppAuthClientAction from '../../../controllers/api/v1/app-auth-clients/get-app-auth-client.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:appAuthClientId',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppAuthClientAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,10 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,15 +1,8 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
|
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
|
||||||
import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js';
|
|
||||||
import infoAction from '../../../controllers/api/v1/automatisch/info.js';
|
|
||||||
import licenseAction from '../../../controllers/api/v1/automatisch/license.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/version', asyncHandler(versionAction));
|
router.get('/version', versionAction);
|
||||||
router.get('/notifications', asyncHandler(notificationsAction));
|
|
||||||
router.get('/info', asyncHandler(infoAction));
|
|
||||||
router.get('/license', asyncHandler(licenseAction));
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import { authorizeUser } from '../../../helpers/authorization.js';
|
|
||||||
import getFlowAction from '../../../controllers/api/v1/flows/get-flow.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:flowId',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeUser,
|
|
||||||
asyncHandler(getFlowAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -1,24 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import checkIsCloud from '../../../helpers/check-is-cloud.js';
|
|
||||||
import getPlansAction from '../../../controllers/api/v1/payment/get-plans.ee.js';
|
|
||||||
import getPaddleInfoAction from '../../../controllers/api/v1/payment/get-paddle-info.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/plans',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsCloud,
|
|
||||||
asyncHandler(getPlansAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/paddle-info',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsCloud,
|
|
||||||
asyncHandler(getPaddleInfoAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
26
packages/backend/src/routes/api/v1/saml-auth-providers.ee.js
Normal file
26
packages/backend/src/routes/api/v1/saml-auth-providers.ee.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||||
|
import { authorizeAdmin } from '../../../helpers/authorization.js';
|
||||||
|
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
||||||
|
import getSamlAuthProvidersAction from '../../../controllers/api/v1/admin/saml-auth-providers/get-saml-auth-providers.ee.js';
|
||||||
|
import getSamlAuthProviderAction from '../../../controllers/api/v1/admin/saml-auth-providers/get-saml-auth-provider.ee.js';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeAdmin,
|
||||||
|
checkIsEnterprise,
|
||||||
|
getSamlAuthProvidersAction
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:samlAuthProviderId',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeAdmin,
|
||||||
|
checkIsEnterprise,
|
||||||
|
getSamlAuthProviderAction
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
@@ -1,26 +1,22 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
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 checkIsCloud from '../../../helpers/check-is-cloud.js';
|
import checkIsCloud from '../../../helpers/check-is-cloud.js';
|
||||||
import getCurrentUserAction from '../../../controllers/api/v1/users/get-current-user.js';
|
import getCurrentUserAction from '../../../controllers/api/v1/users/get-current-user.js';
|
||||||
|
import getUserAction from '../../../controllers/api/v1/users/get-user.js';
|
||||||
|
import getUsersAction from '../../../controllers/api/v1/users/get-users.js';
|
||||||
import getUserTrialAction from '../../../controllers/api/v1/users/get-user-trial.ee.js';
|
import getUserTrialAction from '../../../controllers/api/v1/users/get-user-trial.ee.js';
|
||||||
import getInvoicesAction from '../../../controllers/api/v1/users/get-invoices.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/me', authenticateUser, asyncHandler(getCurrentUserAction));
|
router.get('/', authenticateUser, authorizeUser, getUsersAction);
|
||||||
router.get(
|
router.get('/me', authenticateUser, getCurrentUserAction);
|
||||||
'/invoices',
|
router.get('/:userId', authenticateUser, authorizeUser, getUserAction);
|
||||||
authenticateUser,
|
|
||||||
checkIsCloud,
|
|
||||||
asyncHandler(getInvoicesAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:userId/trial',
|
'/:userId/trial',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
checkIsCloud,
|
checkIsCloud,
|
||||||
asyncHandler(getUserTrialAction)
|
getUserTrialAction
|
||||||
);
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import indexAction from '../controllers/healthcheck/index.js';
|
import indexAction from '../controllers/healthcheck/index.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/', asyncHandler(indexAction));
|
router.get('/', indexAction);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -5,15 +5,7 @@ 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 usersRouter from './api/v1/users.js';
|
import usersRouter from './api/v1/users.js';
|
||||||
import paymentRouter from './api/v1/payment.ee.js';
|
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
||||||
import appAuthClientsRouter from './api/v1/app-auth-clients.js';
|
|
||||||
import flowsRouter from './api/v1/flows.js';
|
|
||||||
import appsRouter from './api/v1/apps.js';
|
|
||||||
import samlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
|
||||||
import rolesRouter from './api/v1/admin/roles.ee.js';
|
|
||||||
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
|
||||||
import adminUsersRouter from './api/v1/admin/users.ee.js';
|
|
||||||
import adminAppAuthClientsRouter from './api/v1/admin/app-auth-clients.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -23,14 +15,6 @@ 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/users', usersRouter);
|
router.use('/api/v1/users', usersRouter);
|
||||||
router.use('/api/v1/payment', paymentRouter);
|
|
||||||
router.use('/api/v1/app-auth-clients', appAuthClientsRouter);
|
|
||||||
router.use('/api/v1/flows', flowsRouter);
|
|
||||||
router.use('/api/v1/apps', appsRouter);
|
|
||||||
router.use('/api/v1/admin/saml-auth-providers', samlAuthProvidersRouter);
|
router.use('/api/v1/admin/saml-auth-providers', samlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/roles', rolesRouter);
|
|
||||||
router.use('/api/v1/admin/permissions', permissionsRouter);
|
|
||||||
router.use('/api/v1/admin/users', adminUsersRouter);
|
|
||||||
router.use('/api/v1/admin/app-auth-clients', adminAppAuthClientsRouter);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,9 +1,16 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import webhooksHandler from '../controllers/paddle/webhooks.ee.js';
|
import webhooksHandler from '../controllers/paddle/webhooks.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post('/webhooks', asyncHandler(webhooksHandler));
|
const exposeError = (handler) => async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
await handler(req, res, next);
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
router.post('/webhooks', exposeError(webhooksHandler));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
const appAuthClientSerializer = (appAuthClient) => {
|
|
||||||
return {
|
|
||||||
id: appAuthClient.id,
|
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
|
||||||
active: appAuthClient.active,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default appAuthClientSerializer;
|
|
@@ -1,22 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import { createAppAuthClient } from '../../test/factories/app-auth-client';
|
|
||||||
import appAuthClientSerializer from './app-auth-client';
|
|
||||||
|
|
||||||
describe('appAuthClient serializer', () => {
|
|
||||||
let appAuthClient;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
appAuthClient = await createAppAuthClient();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return app auth client data', async () => {
|
|
||||||
const expectedPayload = {
|
|
||||||
id: appAuthClient.id,
|
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
|
||||||
active: appAuthClient.active,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(appAuthClientSerializer(appAuthClient)).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,12 +0,0 @@
|
|||||||
const appSerializer = (app) => {
|
|
||||||
return {
|
|
||||||
name: app.name,
|
|
||||||
key: app.key,
|
|
||||||
iconUrl: app.iconUrl,
|
|
||||||
authDocUrl: app.authDocUrl,
|
|
||||||
supportsConnections: app.supportsConnections,
|
|
||||||
primaryColor: app.primaryColor,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default appSerializer;
|
|
@@ -1,20 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
|
||||||
import App from '../models/app';
|
|
||||||
import appSerializer from './app';
|
|
||||||
|
|
||||||
describe('appSerializer', () => {
|
|
||||||
it('should return permission data', async () => {
|
|
||||||
const app = await App.findOneByKey('deepl');
|
|
||||||
|
|
||||||
const expectedPayload = {
|
|
||||||
name: app.name,
|
|
||||||
key: app.key,
|
|
||||||
iconUrl: app.iconUrl,
|
|
||||||
authDocUrl: app.authDocUrl,
|
|
||||||
supportsConnections: app.supportsConnections,
|
|
||||||
primaryColor: app.primaryColor,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(appSerializer(app)).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,18 +0,0 @@
|
|||||||
import stepSerializer from './step.js';
|
|
||||||
|
|
||||||
const flowSerializer = (flow) => {
|
|
||||||
let flowData = {
|
|
||||||
id: flow.id,
|
|
||||||
name: flow.name,
|
|
||||||
active: flow.active,
|
|
||||||
status: flow.status,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (flow.steps) {
|
|
||||||
flowData.steps = flow.steps.map((step) => stepSerializer(step));
|
|
||||||
}
|
|
||||||
|
|
||||||
return flowData;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default flowSerializer;
|
|
@@ -1,44 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import { createFlow } from '../../test/factories/flow';
|
|
||||||
import flowSerializer from './flow';
|
|
||||||
import stepSerializer from './step';
|
|
||||||
import { createStep } from '../../test/factories/step';
|
|
||||||
|
|
||||||
describe('flowSerializer', () => {
|
|
||||||
let flow, stepOne, stepTwo;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
flow = await createFlow();
|
|
||||||
|
|
||||||
stepOne = await createStep({
|
|
||||||
flowId: flow.id,
|
|
||||||
type: 'trigger',
|
|
||||||
});
|
|
||||||
|
|
||||||
stepTwo = await createStep({
|
|
||||||
flowId: flow.id,
|
|
||||||
type: 'action',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return flow data', async () => {
|
|
||||||
const expectedPayload = {
|
|
||||||
id: flow.id,
|
|
||||||
name: flow.name,
|
|
||||||
active: flow.active,
|
|
||||||
status: flow.status,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(flowSerializer(flow)).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return flow data with the steps', async () => {
|
|
||||||
flow.steps = [stepOne, stepTwo];
|
|
||||||
|
|
||||||
const expectedPayload = {
|
|
||||||
steps: [stepSerializer(stepOne), stepSerializer(stepTwo)],
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(flowSerializer(flow)).toMatchObject(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -2,20 +2,12 @@ import userSerializer from './user.js';
|
|||||||
import roleSerializer from './role.js';
|
import roleSerializer from './role.js';
|
||||||
import permissionSerializer from './permission.js';
|
import permissionSerializer from './permission.js';
|
||||||
import samlAuthProviderSerializer from './saml-auth-provider.ee.js';
|
import samlAuthProviderSerializer from './saml-auth-provider.ee.js';
|
||||||
import appAuthClientSerializer from './app-auth-client.js';
|
|
||||||
import flowSerializer from './flow.js';
|
|
||||||
import stepSerializer from './step.js';
|
|
||||||
import appSerializer from './app.js';
|
|
||||||
|
|
||||||
const serializers = {
|
const serializers = {
|
||||||
User: userSerializer,
|
User: userSerializer,
|
||||||
Role: roleSerializer,
|
Role: roleSerializer,
|
||||||
Permission: permissionSerializer,
|
Permission: permissionSerializer,
|
||||||
SamlAuthProvider: samlAuthProviderSerializer,
|
SamlAuthProvider: samlAuthProviderSerializer,
|
||||||
AppAuthClient: appAuthClientSerializer,
|
|
||||||
Flow: flowSerializer,
|
|
||||||
Step: stepSerializer,
|
|
||||||
App: appSerializer,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default serializers;
|
export default serializers;
|
||||||
|
@@ -5,8 +5,8 @@ const permissionSerializer = (permission) => {
|
|||||||
action: permission.action,
|
action: permission.action,
|
||||||
subject: permission.subject,
|
subject: permission.subject,
|
||||||
conditions: permission.conditions,
|
conditions: permission.conditions,
|
||||||
createdAt: permission.createdAt.getTime(),
|
createdAt: permission.createdAt,
|
||||||
updatedAt: permission.updatedAt.getTime(),
|
updatedAt: permission.updatedAt,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,8 +16,8 @@ describe('permissionSerializer', () => {
|
|||||||
action: permission.action,
|
action: permission.action,
|
||||||
subject: permission.subject,
|
subject: permission.subject,
|
||||||
conditions: permission.conditions,
|
conditions: permission.conditions,
|
||||||
createdAt: permission.createdAt.getTime(),
|
createdAt: permission.createdAt,
|
||||||
updatedAt: permission.updatedAt.getTime(),
|
updatedAt: permission.updatedAt,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(permissionSerializer(permission)).toEqual(expectedPayload);
|
expect(permissionSerializer(permission)).toEqual(expectedPayload);
|
||||||
|
@@ -1,23 +1,13 @@
|
|||||||
import permissionSerializer from './permission.js';
|
|
||||||
|
|
||||||
const roleSerializer = (role) => {
|
const roleSerializer = (role) => {
|
||||||
let roleData = {
|
return {
|
||||||
id: role.id,
|
id: role.id,
|
||||||
name: role.name,
|
name: role.name,
|
||||||
key: role.key,
|
key: role.key,
|
||||||
description: role.description,
|
description: role.description,
|
||||||
createdAt: role.createdAt.getTime(),
|
createdAt: role.createdAt,
|
||||||
updatedAt: role.updatedAt.getTime(),
|
updatedAt: role.updatedAt,
|
||||||
isAdmin: role.isAdmin,
|
isAdmin: role.isAdmin,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (role.permissions) {
|
|
||||||
roleData.permissions = role.permissions.map((permission) =>
|
|
||||||
permissionSerializer(permission)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return roleData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default roleSerializer;
|
export default roleSerializer;
|
||||||
|
@@ -1,26 +1,12 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import { createRole } from '../../test/factories/role';
|
import { createRole } from '../../test/factories/role';
|
||||||
import roleSerializer from './role';
|
import roleSerializer from './role';
|
||||||
import permissionSerializer from './permission';
|
|
||||||
import { createPermission } from '../../test/factories/permission';
|
|
||||||
|
|
||||||
describe('roleSerializer', () => {
|
describe('roleSerializer', () => {
|
||||||
let role, permissionOne, permissionTwo;
|
let role;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
role = await createRole();
|
role = await createRole();
|
||||||
|
|
||||||
permissionOne = await createPermission({
|
|
||||||
roleId: role.id,
|
|
||||||
action: 'read',
|
|
||||||
subject: 'User',
|
|
||||||
});
|
|
||||||
|
|
||||||
permissionTwo = await createPermission({
|
|
||||||
roleId: role.id,
|
|
||||||
action: 'read',
|
|
||||||
subject: 'Role',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return role data', async () => {
|
it('should return role data', async () => {
|
||||||
@@ -29,24 +15,11 @@ describe('roleSerializer', () => {
|
|||||||
name: role.name,
|
name: role.name,
|
||||||
key: role.key,
|
key: role.key,
|
||||||
description: role.description,
|
description: role.description,
|
||||||
createdAt: role.createdAt.getTime(),
|
createdAt: role.createdAt,
|
||||||
updatedAt: role.updatedAt.getTime(),
|
updatedAt: role.updatedAt,
|
||||||
isAdmin: role.isAdmin,
|
isAdmin: role.isAdmin,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(roleSerializer(role)).toEqual(expectedPayload);
|
expect(roleSerializer(role)).toEqual(expectedPayload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return role data with the permissions', async () => {
|
|
||||||
role.permissions = [permissionOne, permissionTwo];
|
|
||||||
|
|
||||||
const expectedPayload = {
|
|
||||||
permissions: [
|
|
||||||
permissionSerializer(permissionOne),
|
|
||||||
permissionSerializer(permissionTwo),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(roleSerializer(role)).toMatchObject(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@@ -1,15 +0,0 @@
|
|||||||
const stepSerializer = (step) => {
|
|
||||||
return {
|
|
||||||
id: step.id,
|
|
||||||
type: step.type,
|
|
||||||
key: step.key,
|
|
||||||
appKey: step.appKey,
|
|
||||||
iconUrl: step.iconUrl,
|
|
||||||
webhookUrl: step.webhookUrl,
|
|
||||||
status: step.status,
|
|
||||||
position: step.position,
|
|
||||||
parameters: step.parameters,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default stepSerializer;
|
|
@@ -1,27 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import { createStep } from '../../test/factories/step';
|
|
||||||
import stepSerializer from './step';
|
|
||||||
|
|
||||||
describe('stepSerializer', () => {
|
|
||||||
let step;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
step = await createStep();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return step data', async () => {
|
|
||||||
const expectedPayload = {
|
|
||||||
id: step.id,
|
|
||||||
type: step.type,
|
|
||||||
key: step.key,
|
|
||||||
appKey: step.appKey,
|
|
||||||
iconUrl: step.iconUrl,
|
|
||||||
webhookUrl: step.webhookUrl,
|
|
||||||
status: step.status,
|
|
||||||
position: step.position,
|
|
||||||
parameters: step.parameters,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(stepSerializer(step)).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -6,9 +6,10 @@ const userSerializer = (user) => {
|
|||||||
let userData = {
|
let userData = {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
createdAt: user.createdAt.getTime(),
|
createdAt: user.createdAt,
|
||||||
updatedAt: user.updatedAt.getTime(),
|
updatedAt: user.updatedAt,
|
||||||
fullName: user.fullName,
|
fullName: user.fullName,
|
||||||
|
roleId: user.roleId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user.role) {
|
if (user.role) {
|
||||||
|
@@ -4,8 +4,6 @@ import appConfig from '../config/app';
|
|||||||
import { createUser } from '../../test/factories/user';
|
import { createUser } from '../../test/factories/user';
|
||||||
import { createPermission } from '../../test/factories/permission';
|
import { createPermission } from '../../test/factories/permission';
|
||||||
import userSerializer from './user';
|
import userSerializer from './user';
|
||||||
import roleSerializer from './role';
|
|
||||||
import permissionSerializer from './permission';
|
|
||||||
|
|
||||||
describe('userSerializer', () => {
|
describe('userSerializer', () => {
|
||||||
let user, role, permissionOne, permissionTwo;
|
let user, role, permissionOne, permissionTwo;
|
||||||
@@ -31,11 +29,12 @@ describe('userSerializer', () => {
|
|||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
||||||
|
|
||||||
const expectedPayload = {
|
const expectedPayload = {
|
||||||
createdAt: user.createdAt.getTime(),
|
createdAt: user.createdAt,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
fullName: user.fullName,
|
fullName: user.fullName,
|
||||||
id: user.id,
|
id: user.id,
|
||||||
updatedAt: user.updatedAt.getTime(),
|
roleId: user.roleId,
|
||||||
|
updatedAt: user.updatedAt,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(userSerializer(user)).toEqual(expectedPayload);
|
expect(userSerializer(user)).toEqual(expectedPayload);
|
||||||
@@ -45,7 +44,7 @@ describe('userSerializer', () => {
|
|||||||
user.role = role;
|
user.role = role;
|
||||||
|
|
||||||
const expectedPayload = {
|
const expectedPayload = {
|
||||||
role: roleSerializer(role),
|
role,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(userSerializer(user)).toMatchObject(expectedPayload);
|
expect(userSerializer(user)).toMatchObject(expectedPayload);
|
||||||
@@ -55,10 +54,7 @@ describe('userSerializer', () => {
|
|||||||
user.permissions = [permissionOne, permissionTwo];
|
user.permissions = [permissionOne, permissionTwo];
|
||||||
|
|
||||||
const expectedPayload = {
|
const expectedPayload = {
|
||||||
permissions: [
|
permissions: [permissionOne, permissionTwo],
|
||||||
permissionSerializer(permissionOne),
|
|
||||||
permissionSerializer(permissionTwo),
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(userSerializer(user)).toMatchObject(expectedPayload);
|
expect(userSerializer(user)).toMatchObject(expectedPayload);
|
||||||
@@ -67,7 +63,7 @@ describe('userSerializer', () => {
|
|||||||
it('should return user data with trial expiry date', async () => {
|
it('should return user data with trial expiry date', async () => {
|
||||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
||||||
|
|
||||||
await user.$query().patchAndFetch({
|
await user.$query().patch({
|
||||||
trialExpiryDate: DateTime.now().plus({ days: 30 }).toISODate(),
|
trialExpiryDate: DateTime.now().plus({ days: 30 }).toISODate(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,25 +0,0 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
|
||||||
import { createAppConfig } from './app-config.js';
|
|
||||||
import AppAuthClient from '../../src/models/app-auth-client';
|
|
||||||
|
|
||||||
const formattedAuthDefaults = {
|
|
||||||
oAuthRedirectUrl: faker.internet.url(),
|
|
||||||
instanceUrl: faker.internet.url(),
|
|
||||||
clientId: faker.string.uuid(),
|
|
||||||
clientSecret: faker.string.uuid(),
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createAppAuthClient = async (params = {}) => {
|
|
||||||
params.name = params?.name || faker.person.fullName();
|
|
||||||
params.id = params?.id || faker.string.uuid();
|
|
||||||
params.appConfigId = params?.appConfigId || (await createAppConfig()).id;
|
|
||||||
params.active = params?.active ?? true;
|
|
||||||
params.formattedAuthDefaults =
|
|
||||||
params?.formattedAuthDefaults || formattedAuthDefaults;
|
|
||||||
|
|
||||||
const appAuthClient = await AppAuthClient.query()
|
|
||||||
.insert(params)
|
|
||||||
.returning('*');
|
|
||||||
|
|
||||||
return appAuthClient;
|
|
||||||
};
|
|
@@ -1,13 +0,0 @@
|
|||||||
import AppConfig from '../../src/models/app-config.js';
|
|
||||||
|
|
||||||
export const createAppConfig = async (params = {}) => {
|
|
||||||
const appConfigData = {
|
|
||||||
key: params?.key || 'gitlab',
|
|
||||||
};
|
|
||||||
|
|
||||||
const appConfig = await AppConfig.query()
|
|
||||||
.insert(appConfigData)
|
|
||||||
.returning('*');
|
|
||||||
|
|
||||||
return appConfig;
|
|
||||||
};
|
|
@@ -1,19 +0,0 @@
|
|||||||
const getAdminAppAuthClientMock = (appAuthClient) => {
|
|
||||||
return {
|
|
||||||
data: {
|
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
|
||||||
id: appAuthClient.id,
|
|
||||||
active: appAuthClient.active,
|
|
||||||
},
|
|
||||||
meta: {
|
|
||||||
count: 1,
|
|
||||||
currentPage: null,
|
|
||||||
isArray: false,
|
|
||||||
totalPages: null,
|
|
||||||
type: 'AppAuthClient',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getAdminAppAuthClientMock;
|
|
@@ -1,64 +0,0 @@
|
|||||||
const getPermissionsCatalogMock = async () => {
|
|
||||||
const data = {
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
key: 'create',
|
|
||||||
label: 'Create',
|
|
||||||
subjects: ['Connection', 'Flow'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'read',
|
|
||||||
label: 'Read',
|
|
||||||
subjects: ['Connection', 'Execution', 'Flow'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'update',
|
|
||||||
label: 'Update',
|
|
||||||
subjects: ['Connection', 'Flow'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'delete',
|
|
||||||
label: 'Delete',
|
|
||||||
subjects: ['Connection', 'Flow'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'publish',
|
|
||||||
label: 'Publish',
|
|
||||||
subjects: ['Flow'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
conditions: [
|
|
||||||
{
|
|
||||||
key: 'isCreator',
|
|
||||||
label: 'Is creator',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
subjects: [
|
|
||||||
{
|
|
||||||
key: 'Connection',
|
|
||||||
label: 'Connection',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Flow',
|
|
||||||
label: 'Flow',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Execution',
|
|
||||||
label: 'Execution',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: data,
|
|
||||||
meta: {
|
|
||||||
count: 1,
|
|
||||||
currentPage: null,
|
|
||||||
isArray: false,
|
|
||||||
totalPages: null,
|
|
||||||
type: 'Object',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getPermissionsCatalogMock;
|
|
@@ -1,33 +0,0 @@
|
|||||||
const getRoleMock = async (role, permissions) => {
|
|
||||||
const data = {
|
|
||||||
id: role.id,
|
|
||||||
key: role.key,
|
|
||||||
name: role.name,
|
|
||||||
isAdmin: role.isAdmin,
|
|
||||||
description: role.description,
|
|
||||||
createdAt: role.createdAt.getTime(),
|
|
||||||
updatedAt: role.updatedAt.getTime(),
|
|
||||||
permissions: permissions.map((permission) => ({
|
|
||||||
id: permission.id,
|
|
||||||
action: permission.action,
|
|
||||||
conditions: permission.conditions,
|
|
||||||
roleId: permission.roleId,
|
|
||||||
subject: permission.subject,
|
|
||||||
createdAt: permission.createdAt.getTime(),
|
|
||||||
updatedAt: permission.updatedAt.getTime(),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: data,
|
|
||||||
meta: {
|
|
||||||
count: 1,
|
|
||||||
currentPage: null,
|
|
||||||
isArray: false,
|
|
||||||
totalPages: null,
|
|
||||||
type: 'Role',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getRoleMock;
|
|
@@ -1,26 +0,0 @@
|
|||||||
const getRolesMock = async (roles) => {
|
|
||||||
const data = roles.map((role) => {
|
|
||||||
return {
|
|
||||||
id: role.id,
|
|
||||||
key: role.key,
|
|
||||||
name: role.name,
|
|
||||||
isAdmin: role.isAdmin,
|
|
||||||
description: role.description,
|
|
||||||
createdAt: role.createdAt.getTime(),
|
|
||||||
updatedAt: role.updatedAt.getTime(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: data,
|
|
||||||
meta: {
|
|
||||||
count: data.length,
|
|
||||||
currentPage: null,
|
|
||||||
isArray: true,
|
|
||||||
totalPages: null,
|
|
||||||
type: 'Role',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getRolesMock;
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user