feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -1,4 +1,4 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Create attachment',
@@ -9,7 +9,7 @@ export default defineAction({
{
label: 'Parent ID',
key: 'parentId',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
description:
@@ -18,7 +18,7 @@ export default defineAction({
{
label: 'Name',
key: 'name',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
description: 'Name of the attached file. Maximum size is 255 characters.',
@@ -26,7 +26,7 @@ export default defineAction({
{
label: 'Body',
key: 'body',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
description: 'File data. (Max size is 25MB)',

View File

@@ -1,4 +1,4 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Execute query',
@@ -8,7 +8,7 @@ export default defineAction({
{
label: 'Query',
key: 'query',
type: 'string' as const,
type: 'string',
required: true,
description:
'Salesforce query string. For example: SELECT Id, Name FROM Account',
@@ -17,7 +17,7 @@ export default defineAction({
],
async run($) {
const query = $.step.parameters.query as string;
const query = $.step.parameters.query;
const options = {
params: {

View File

@@ -1,4 +1,4 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Find record',
@@ -8,7 +8,7 @@ export default defineAction({
{
label: 'Object',
key: 'object',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
description: 'Pick which type of object you want to search for.',
@@ -26,7 +26,7 @@ export default defineAction({
{
label: 'Field',
key: 'field',
type: 'dropdown' as const,
type: 'dropdown',
description: 'Pick which field to search by',
required: true,
variables: true,
@@ -49,7 +49,7 @@ export default defineAction({
{
label: 'Search value',
key: 'searchValue',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
},

View File

@@ -0,0 +1,5 @@
import createAttachment from './create-attachment/index.js';
import executeQuery from './execute-query/index.js';
import findRecord from './find-record/index.js';
export default [findRecord, createAttachment, executeQuery];

View File

@@ -1,5 +0,0 @@
import createAttachment from './create-attachment';
import executeQuery from './execute-query';
import findRecord from './find-record';
export default [findRecord, createAttachment, executeQuery];

View File

@@ -1,13 +1,12 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import qs from 'qs';
export default async function generateAuthUrl($: IGlobalVariable) {
export default async function generateAuthUrl($) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl'
(field) => field.key == 'oAuthRedirectUrl'
);
const redirectUri = oauthRedirectUrlField.value;
const searchParams = qs.stringify({
client_id: $.auth.data.consumerKey as string,
client_id: $.auth.data.consumerKey,
redirect_uri: redirectUri,
response_type: 'code',
});

View File

@@ -1,14 +1,14 @@
import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
import refreshToken from './refresh-token';
import generateAuthUrl from './generate-auth-url.js';
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
import refreshToken from './refresh-token.js';
export default {
fields: [
{
key: 'oAuthRedirectUrl',
label: 'OAuth Redirect URL',
type: 'string' as const,
type: 'string',
required: true,
readOnly: true,
value: '{WEB_APP_URL}/app/salesforce/connections/add',
@@ -20,7 +20,7 @@ export default {
{
key: 'oauth2Url',
label: 'Salesforce Environment',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
readOnly: false,
value: 'https://login.salesforce.com/services/oauth2',
@@ -41,7 +41,7 @@ export default {
{
key: 'consumerKey',
label: 'Consumer Key',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -52,7 +52,7 @@ export default {
{
key: 'consumerSecret',
label: 'Consumer Secret',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,

View File

@@ -0,0 +1,8 @@
import getCurrentUser from '../common/get-current-user.js';
const isStillVerified = async ($) => {
const user = await getCurrentUser($);
return !!user;
};
export default isStillVerified;

View File

@@ -1,9 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import getCurrentUser from '../common/get-current-user';
const isStillVerified = async ($: IGlobalVariable) => {
const user = await getCurrentUser($);
return !!user;
};
export default isStillVerified;

View File

@@ -1,12 +1,11 @@
import { IGlobalVariable } from '@automatisch/types';
import qs from 'querystring';
const refreshToken = async ($: IGlobalVariable) => {
const refreshToken = async ($) => {
const searchParams = qs.stringify({
grant_type: 'refresh_token',
client_id: $.auth.data.consumerKey as string,
client_secret: $.auth.data.consumerSecret as string,
refresh_token: $.auth.data.refreshToken as string,
client_id: $.auth.data.consumerKey,
client_secret: $.auth.data.consumerSecret,
refresh_token: $.auth.data.refreshToken,
});
const { data } = await $.http.post(

View File

@@ -1,8 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import getCurrentUser from '../common/get-current-user';
import getCurrentUser from '../common/get-current-user.js';
import qs from 'qs';
const verifyCredentials = async ($: IGlobalVariable) => {
const verifyCredentials = async ($) => {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field) => field.key == 'oAuthRedirectUrl'
);
@@ -10,8 +9,8 @@ const verifyCredentials = async ($: IGlobalVariable) => {
const searchParams = qs.stringify({
code: $.auth.data.code,
grant_type: 'authorization_code',
client_id: $.auth.data.consumerKey as string,
client_secret: $.auth.data.consumerSecret as string,
client_id: $.auth.data.consumerKey,
client_secret: $.auth.data.consumerSecret,
redirect_uri: redirectUri,
});
const { data } = await $.http.post(

View File

@@ -1,10 +1,8 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const addAuthHeader = ($, requestConfig) => {
const { instanceUrl, tokenType, accessToken } = $.auth.data;
if (instanceUrl) {
requestConfig.baseURL = instanceUrl as string;
requestConfig.baseURL = instanceUrl;
}
if (tokenType && accessToken) {

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
const getCurrentUser = async ($) => {
const response = await $.http.get('/services/data/v55.0/chatter/users/me');
const currentUser = response.data;

View File

@@ -0,0 +1,4 @@
import listObjects from './list-objects/index.js';
import listFields from './list-fields/index.js';
export default [listObjects, listFields];

View File

@@ -1,4 +0,0 @@
import listObjects from './list-objects';
import listFields from './list-fields';
export default [listObjects, listFields];

View File

@@ -1,26 +1,16 @@
import { IGlobalVariable } from '@automatisch/types';
type TResponse = {
fields: TField[];
};
type TField = {
name: string;
label: string;
};
export default {
name: 'List fields',
key: 'listFields',
async run($: IGlobalVariable) {
async run($) {
const { object } = $.step.parameters;
if (!object) return { data: [] };
const response = await $.http.get<TResponse>(
`/services/data/v56.0/sobjects/${object}/describe`
);
const response =
(await $.http.get) <
TResponse >
`/services/data/v56.0/sobjects/${object}/describe`;
const fields = response.data.fields.map((field) => {
return {

View File

@@ -0,0 +1,18 @@
export default {
name: 'List objects',
key: 'listObjects',
async run($) {
const response =
(await $.http.get) < TResponse > '/services/data/v56.0/sobjects';
const objects = response.data.sobjects.map((object) => {
return {
value: object.name,
name: object.label,
};
});
return { data: objects };
},
};

View File

@@ -1,30 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
type TResponse = {
sobjects: TObject[];
};
type TObject = {
name: string;
label: string;
};
export default {
name: 'List objects',
key: 'listObjects',
async run($: IGlobalVariable) {
const response = await $.http.get<TResponse>(
'/services/data/v56.0/sobjects'
);
const objects = response.data.sobjects.map((object) => {
return {
value: object.name,
name: object.label,
};
});
return { data: objects };
},
};

View File

@@ -1,9 +1,9 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import triggers from './triggers';
import actions from './actions';
import dynamicData from './dynamic-data';
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 actions from './actions/index.js';
import dynamicData from './dynamic-data/index.js';
export default defineApp({
name: 'Salesforce',

View File

@@ -0,0 +1,3 @@
import updatedFieldInRecords from './updated-field-in-records/index.js';
export default [updatedFieldInRecords];

View File

@@ -1,3 +0,0 @@
import updatedFieldInRecords from './updated-field-in-records';
export default [updatedFieldInRecords];

View File

@@ -1,5 +1,5 @@
import defineTrigger from '../../../../helpers/define-trigger';
import updatedFieldInRecords from './updated-field-in-records';
import defineTrigger from '../../../../helpers/define-trigger.js';
import updatedFieldInRecords from './updated-field-in-records.js';
export default defineTrigger({
name: 'Updated field in records',
@@ -10,7 +10,7 @@ export default defineTrigger({
{
label: 'Object',
key: 'object',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: false,
source: {
@@ -27,7 +27,7 @@ export default defineTrigger({
{
label: 'Field',
key: 'field',
type: 'dropdown' as const,
type: 'dropdown',
description: 'Track updates by this field',
required: true,
variables: false,

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable } from '@automatisch/types';
function getQuery(object: string, limit: number, offset: number) {
function getQuery(object, limit, offset) {
return `
SELECT
FIELDS(ALL)
@@ -12,10 +10,10 @@ function getQuery(object: string, limit: number, offset: number) {
`;
}
const updatedFieldInRecord = async ($: IGlobalVariable): Promise<void> => {
const updatedFieldInRecord = async ($) => {
const limit = 200;
const field = $.step.parameters.field as string;
const object = $.step.parameters.object as string;
const field = $.step.parameters.field;
const object = $.step.parameters.object;
let response;
let offset = 0;