Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixes #368

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,43 @@ POSTGRES_USER=my_user
POSTGRES_DB=panora_db
POSTGRES_HOST=postgres

# Each Provider is of form PROVIDER_TICKETING_SOFTWAREMODE_ATTRIBUTE
# ================================================
# Integration Providers
# ================================================
# CRM
# Hubspot
HUBSPOT_CRM_CLIENT_ID=
HUBSPOT_CRM_CLIENT_SECRET=
HUBSPOT_CRM_CLOUD_CLIENT_ID=
HUBSPOT_CRM_CLOUD_CLIENT_SECRET=
# Zoho
ZOHO_CRM_CLIENT_ID=
ZOHO_CRM_CLIENT_SECRET=
ZOHO_CRM_CLOUD_CLIENT_ID=
ZOHO_CRM_CLOUD_CLIENT_SECRET=
# Pipedrive
PIPEDRIVE_CRM_CLIENT_ID=
PIPEDRIVE_CRM_CLIENT_SECRET=
PIPEDRIVE_CRM_CLOUD_CLIENT_ID=
PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET=
# Zendesk
ZENDESK_CRM_CLIENT_ID=
ZENDESK_CRM_CLIENT_SECRET=
ZENDESK_CRM_CLOUD_CLIENT_ID=
ZENDESK_CRM_CLOUD_CLIENT_SECRET=
# Freshsales
FRESHSALES_CRM_CLIENT_ID=
FRESHSALES_CRM_CLIENT_SECRET=
FRESHSALES_CRM_CLOUD_CLIENT_ID=
FRESHSALES_CRM_CLOUD_CLIENT_SECRET=
# Attio
ATTIO_CRM_CLIENT_ID=
ATTIO_CRM_CLIENT_SECRET=
ATTIO_CRM_CLOUD_CLIENT_ID=
ATTIO_CRM_CLOUD_CLIENT_SECRET=
# ================================================
# Ticketing
# ================================================
# Zendesk
ZENDESK_TICKETING_CLIENT_ID=
ZENDESK_TICKETING_CLIENT_SECRET=
ZENDESK_TICKETING_SUBDOMAIN=
JIRA_TICKETING_CLIENT_ID=
JIRA_TICKETING_CLIENT_SECRET=
GORGIAS_TICKETING_CLIENT_ID=
GORGIAS_TICKETING_CLIENT_SECRET=
GORGIAS_TICKETING_SUBDOMAIN=
FRONT_TICKETING_CLIENT_ID=
FRONT_TICKETING_CLIENT_SECRET=
ZENDESK_TICKETING_CLOUD_CLIENT_ID=
ZENDESK_TICKETING_CLOUD_CLIENT_SECRET=
ZENDESK_TICKETING_CLOUD_SUBDOMAIN=
JIRA_TICKETING_CLOUD_CLIENT_ID=
JIRA_TICKETING_CLOUD_CLIENT_SECRET=
GORGIAS_TICKETING_CLOUD_CLIENT_ID=
GORGIAS_TICKETING_CLOUD_CLIENT_SECRET=
GORGIAS_TICKETING_CLOUD_SUBDOMAIN=
FRONT_TICKETING_CLOUD_CLIENT_ID=
FRONT_TICKETING_CLOUD_CLIENT_SECRET=

# ================================================
# Webapp settings
Expand Down
12 changes: 0 additions & 12 deletions apps/client-ts/.env.example

This file was deleted.

1 change: 0 additions & 1 deletion apps/magic-link/.env.example

This file was deleted.

48 changes: 0 additions & 48 deletions packages/api/.env.example

This file was deleted.

102 changes: 102 additions & 0 deletions packages/api/scripts/connectorUpdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

# Make the script executable
# chmod +x connectorUpdate.sh

# Run the script with (vertical) and (provider)
# ./connectorUpdate.sh crm contact

# Calculate the directory where the script resides
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BASE_DIR="$(cd "$SCRIPT_DIR" && cd ../../.. && pwd)" # Adjust the path as necessary based on your directory structure

# Function to scan directories for new services
scanDirectory() {
local dir=$1
find "$dir" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;
}

# Function to replace relative paths
replaceRelativePaths() {
local path=$1
echo "${path//..\/src\//@}"
}

# Function to generate import statements for new services
generateImportStatements() {
local basePath=$1
local objectType=$2
local serviceNames=("$@")
shift 2
local importStatements=()
for serviceName in "${serviceNames[@]}"; do
local importPath="${basePath}/${serviceName}/types"
local replacedPath=$(replaceRelativePaths "$importPath")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating declaration and assignment.

It's generally a good practice to separate the declaration of variables from their assignment when the assignment involves a function call. This can enhance readability and prevent issues where the return value might be masked by the assignment.

- local replacedPath=$(replaceRelativePaths "$importPath")
+ local replacedPath
+ replacedPath=$(replaceRelativePaths "$importPath")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
local replacedPath=$(replaceRelativePaths "$importPath")
local replacedPath
replacedPath=$(replaceRelativePaths "$importPath")

local name="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$objectType"
importStatements+=("import { ${name}Input, ${name}Output } from '${replacedPath}';")
done
printf "%s\n" "${importStatements[@]}"
}

# Function to append import statements and update type definitions
updateTargetFile() {
local file=$1
local imports=$2
local serviceNames=("$@")
shift 2

# Append import statements to the file
printf "%s\n\n" "$imports" >> "$file"

# Update type definitions
for serviceName in "${serviceNames[@]}"; do
local typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating declaration and assignment.

Similar to previous comments, separating the declaration and assignment can improve clarity and prevent potential issues in script behavior.

- local typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"
+ local typeName
+ typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
local typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"
local typeName
typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"

sed -i "/export type Original${OBJECT_TYPE}Input =/a \ | ${typeName}Input" "$file"
sed -i "/export type Original${OBJECT_TYPE}Output =/a \ | ${typeName}Output" "$file"
done
}

# Function to update mappings and module files
updateMappingsAndModules() {
local vertical=$1
local objectType=$2
local serviceDirs=("$@")
shift 2
local mappingsPath="${MAPPINGS_FILE}/${vertical}/${objectType}/types/mappingsTypes.ts"
local modulePath="${BASE_DIR}/src/${vertical}/${objectType}/${objectType}.module.ts"

# Update module and mapping files
for service in "${serviceDirs[@]}"; do
local serviceClass="${service^}Service"
if ! grep -q "$serviceClass" "$modulePath"; then
echo "import { $serviceClass } from './services/${service}';" >> "$modulePath"
fi
done
}

# Main execution block
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <vertical> <objectType>"
exit 1
fi

VERTICAL=$1
OBJECT_TYPE=$2

# Define paths based on input
TARGET_FILE="${BASE_DIR}/src/@core/utils/types/original/original${VERTICAL}.ts"
SERVICES_DIR="${BASE_DIR}/src/${VERTICAL}/${OBJECT_TYPE}/services"

# Scan for new services
newServices=($(scanDirectory "$SERVICES_DIR"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mapfile or read -a for safer command output handling.

Using mapfile or read -a is safer and more robust for handling command outputs as arrays in Bash, especially when dealing with spaces or special characters.

- newServices=($(scanDirectory "$SERVICES_DIR"))
+ mapfile -t newServices < <(scanDirectory "$SERVICES_DIR")


# Generate import statements
imports=$(generateImportStatements "$SERVICES_DIR" "$OBJECT_TYPE" "${newServices[@]}")

# Update the target file
updateTargetFile "$TARGET_FILE" "$imports" "${newServices[@]}"

# Update mappings and module files
updateMappingsAndModules "$VERTICAL" "$OBJECT_TYPE" "${newServices[@]}"

echo "Update process completed for $VERTICAL $OBJECT_TYPE."
Loading