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 contact',
@@ -8,28 +8,28 @@ export default defineAction({
{
label: 'Company name',
key: 'company',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
{
label: 'Email',
key: 'email',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
{
label: 'First name',
key: 'firstName',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
{
label: 'Last name',
key: 'lastName',
type: 'string' as const,
type: 'string',
required: false,
description: 'Last name',
variables: true,
@@ -37,34 +37,34 @@ export default defineAction({
{
label: 'Phone',
key: 'phone',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
{
label: 'Website URL',
key: 'website',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
{
label: 'Owner ID',
key: 'hubspotOwnerId',
type: 'string' as const,
type: 'string',
required: false,
variables: true,
},
],
async run($) {
const company = $.step.parameters.company as string;
const email = $.step.parameters.email as string;
const firstName = $.step.parameters.firstName as string;
const lastName = $.step.parameters.lastName as string;
const phone = $.step.parameters.phone as string;
const website = $.step.parameters.website as string;
const hubspotOwnerId = $.step.parameters.hubspotOwnerId as string;
const company = $.step.parameters.company;
const email = $.step.parameters.email;
const firstName = $.step.parameters.firstName;
const lastName = $.step.parameters.lastName;
const phone = $.step.parameters.phone;
const website = $.step.parameters.website;
const hubspotOwnerId = $.step.parameters.hubspotOwnerId;
const response = await $.http.post(`crm/v3/objects/contacts`, {
properties: {

View File

@@ -0,0 +1,3 @@
import createContact from './create-contact/index.js';
export default [createContact];

View File

@@ -1,3 +0,0 @@
import createContact from './create-contact';
export default [ createContact ];

View File

@@ -0,0 +1,19 @@
import { URLSearchParams } from 'url';
import scopes from '../common/scopes.js';
export default async function generateAuthUrl($) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field) => field.key == 'oAuthRedirectUrl'
);
const callbackUrl = oauthRedirectUrlField.value;
const searchParams = new URLSearchParams({
client_id: $.auth.data.clientId,
redirect_uri: callbackUrl,
scope: scopes.join(' '),
});
const url = `https://app.hubspot.com/oauth/authorize?${searchParams.toString()}`;
await $.auth.set({ url });
}

View File

@@ -1,20 +0,0 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
import scopes from '../common/scopes';
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl'
);
const callbackUrl = oauthRedirectUrlField.value as string;
const searchParams = new URLSearchParams({
client_id: $.auth.data.clientId as string,
redirect_uri: callbackUrl,
scope: scopes.join(' '),
});
const url = `https://app.hubspot.com/oauth/authorize?${searchParams.toString()}`;
await $.auth.set({ url });
}

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/hubspot/connections/add',
@@ -20,7 +20,7 @@ export default {
{
key: 'clientId',
label: 'Client ID',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -31,7 +31,7 @@ export default {
{
key: 'clientSecret',
label: 'Client Secret',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,

View File

@@ -0,0 +1,9 @@
import getAccessTokenInfo from '../common/get-access-token-info.js';
const isStillVerified = async ($) => {
await getAccessTokenInfo($);
return true;
};
export default isStillVerified;

View File

@@ -1,10 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import getAccessTokenInfo from '../common/get-access-token-info';
const isStillVerified = async ($: IGlobalVariable) => {
await getAccessTokenInfo($);
return true;
};
export default isStillVerified;

View File

@@ -1,19 +1,18 @@
import { IGlobalVariable, IField } from '@automatisch/types';
import { URLSearchParams } from 'url';
const refreshToken = async ($: IGlobalVariable) => {
const refreshToken = async ($) => {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl'
(field) => field.key == 'oAuthRedirectUrl'
);
const callbackUrl = oauthRedirectUrlField.value as string;
const callbackUrl = oauthRedirectUrlField.value;
const params = new URLSearchParams({
grant_type: 'refresh_token',
client_id: $.auth.data.clientId as string,
client_secret: $.auth.data.clientSecret as string,
client_id: $.auth.data.clientId,
client_secret: $.auth.data.clientSecret,
redirect_uri: callbackUrl,
refresh_token: $.auth.data.refreshToken as string,
refresh_token: $.auth.data.refreshToken,
});
const { data } = await $.http.post('/oauth/v1/token', params.toString());

View File

@@ -1,18 +1,17 @@
import { IGlobalVariable, IField } from '@automatisch/types';
import { URLSearchParams } from 'url';
import getAccessTokenInfo from '../common/get-access-token-info';
import getAccessTokenInfo from '../common/get-access-token-info.js';
const verifyCredentials = async ($: IGlobalVariable) => {
const verifyCredentials = async ($) => {
const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl'
(field) => field.key == 'oAuthRedirectUrl'
);
const callbackUrl = oauthRedirectUrlField.value as string;
const callbackUrl = oauthRedirectUrlField.value;
const params = new URLSearchParams({
grant_type: 'authorization_code',
client_id: $.auth.data.clientId as string,
client_secret: $.auth.data.clientSecret as string,
client_id: $.auth.data.clientId,
client_secret: $.auth.data.clientSecret,
redirect_uri: callbackUrl,
code: $.auth.data.code as string,
code: $.auth.data.code,
});
const { data: verifiedCredentials } = await $.http.post(

View File

@@ -1,7 +1,6 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if (requestConfig.additionalProperties?.skipAddingAuthHeader) return requestConfig;
const addAuthHeader = ($, requestConfig) => {
if (requestConfig.additionalProperties?.skipAddingAuthHeader)
return requestConfig;
if ($.auth.data?.accessToken) {
const authorizationHeader = `Bearer ${$.auth.data.accessToken}`;

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
const getAccessTokenInfo = async ($: IGlobalVariable): Promise<IJSONObject> => {
const getAccessTokenInfo = async ($) => {
const response = await $.http.get(
`/oauth/v1/access-tokens/${$.auth.data.accessToken}`
);

View File

@@ -1,7 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import actions from './actions';
import auth from './auth';
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import actions from './actions/index.js';
import auth from './auth/index.js';
export default defineApp({
name: 'HubSpot',