Skip to content

Commit

Permalink
Revert "Support for different clusters (#468)" (#477)
Browse files Browse the repository at this point in the history
This reverts commit 4a41317.
  • Loading branch information
ashwin1111 authored Jan 29, 2024
1 parent 0089b61 commit 469b653
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 77 deletions.
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fi
for f in /usr/share/nginx/html/*
do
echo "Substituting Environment variables and other stuff in $f ...";
sed -i $SED_EXTRA_ARGS "s?{{CLUSTER_DOMAIN_API_URL}}?${CLUSTER_DOMAIN_API_URL}?g" $f;
sed -i $SED_EXTRA_ARGS "s?{{API_URL}}?${API_URL}?g" $f;
sed -i $SED_EXTRA_ARGS "s?{{QBD_API_URL}}?${QBD_API_URL}?g" $f;
sed -i $SED_EXTRA_ARGS "s?{{SI_API_URL}}?${SI_API_URL}?g" $f;
sed -i $SED_EXTRA_ARGS "s?{{SAGE300_API_URL}}?${SAGE300_API_URL}?g" $f;
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const environment = {
sage300_api_url: `${process.env.SAGE300_API_URL ? process.env.SAGE300_API_URL : '{{SAGE300_API_URL}}'}`,
business_central_api_url: `${process.env.BUSINESS_CENTRAL_API_URL ? process.env.BUSINESS_CENTRAL_API_URL : '{{BUSINESS_CENTRAL_API_URL}}'}`,
qbo_api_url: `${process.env.QBO_API_URL ? process.env.QBO_API_URL : '{{QBO_API_URL}}'}`,
cluster_domain_api_url: `${process.env.CLUSTER_DOMAIN_API_URL ? process.env.CLUSTER_DOMAIN_API_URL : '{{CLUSTER_DOMAIN_API_URL}}'}`,
api_url: `${process.env.API_URL ? process.env.API_URL : '{{API_URL}}'}`,
fyle_app_url: `${process.env.FYLE_APP_URL ? process.env.FYLE_APP_URL : '{{FYLE_APP_URL}}'}`,
sentry_dsn: `${process.env.SENTRY_DSN ? process.env.SENTRY_DSN : '{{SENTRY_DSN}}'}`,
sentry_env: `${process.env.SENTRY_ENV ? process.env.SENTRY_ENV : '{{SENTRY_ENV}}'}`,
Expand Down
73 changes: 33 additions & 40 deletions src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { BusinessCentralAuthService } from 'src/app/core/services/business-centr
import { QboAuthService } from 'src/app/core/services/qbo/qbo-core/qbo-auth.service';
import { HelperService } from 'src/app/core/services/common/helper.service';
import { AppUrl } from 'src/app/core/models/enum/enum.model';
import { ClusterDomainWithToken } from 'src/app/core/models/misc/token.model';
import { StorageService } from 'src/app/core/services/common/storage.service';

@Component({
selector: 'app-login',
Expand All @@ -23,16 +21,15 @@ export class LoginComponent implements OnInit {

constructor(
private authService: AuthService,
private businessCentralAuthService: BusinessCentralAuthService,
private helperService: HelperService,
private qboAuthService: QboAuthService,
private qbdAuthService: QbdAuthService,
private route: ActivatedRoute,
private router: Router,
private sage300AuthService: Sage300AuthService,
private userService: UserService,
private qbdAuthService: QbdAuthService,
private siAuthService : SiAuthService,
private storageService: StorageService,
private userService: UserService
private sage300AuthService: Sage300AuthService,
private businessCentralAuthService: BusinessCentralAuthService,
private qboAuthService: QboAuthService
) { }

private redirect(redirectUri: string | undefined): void {
Expand All @@ -44,42 +41,38 @@ export class LoginComponent implements OnInit {
}

private saveUserProfileAndNavigate(code: string, redirectUri: string | undefined): void {
this.helperService.setBaseApiURL(AppUrl.INTEGRATION);
this.authService.getClusterDomainByCode(code).subscribe((clusterDomainWithToken: ClusterDomainWithToken) => {
this.storageService.set('cluster-domain', clusterDomainWithToken.cluster_domain);
this.authService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe(response => {
const user: MinimalUser = {
'email': response.user.email,
'access_token': response.access_token,
'refresh_token': response.refresh_token,
'full_name': response.user.full_name,
'user_id': response.user.user_id,
'org_id': response.user.org_id,
'org_name': response.user.org_name
};
this.userService.storeUserProfile(user);
this.authService.login(code).subscribe(response => {
const user: MinimalUser = {
'email': response.user.email,
'access_token': response.access_token,
'refresh_token': response.refresh_token,
'full_name': response.user.full_name,
'user_id': response.user.user_id,
'org_id': response.user.org_id,
'org_name': response.user.org_name
};
this.userService.storeUserProfile(user);

this.helperService.setBaseApiURL(AppUrl.QBD);
this.qbdAuthService.qbdLogin(clusterDomainWithToken.tokens.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.QBD);
this.qbdAuthService.qbdLogin(user.refresh_token).subscribe();

this.helperService.setBaseApiURL(AppUrl.SAGE300);
this.sage300AuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.SAGE300);
this.sage300AuthService.loginWithRefreshToken(user.refresh_token).subscribe();

this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
this.businessCentralAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
this.businessCentralAuthService.loginWithRefreshToken(user.refresh_token).subscribe();

// Only local dev needs this, login happens via postMessage for prod/staging through webapp
if (!environment.production) {
this.userService.storeUserProfile(user);
this.helperService.setBaseApiURL(AppUrl.QBO);
this.qboAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.INTACCT);
this.siAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
this.redirect(redirectUri);
} else {
this.redirect(redirectUri);
}
});
// Only local dev needs this, login happens via postMessage for prod/staging through webapp
if (!environment.production) {
this.userService.storeUserProfile(user);
this.helperService.setBaseApiURL(AppUrl.QBO);
this.qboAuthService.loginWithRefreshToken(user.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.INTACCT);
this.siAuthService.loginWithRefreshToken(user.refresh_token).subscribe();
this.redirect(redirectUri);
} else {
this.redirect(redirectUri);
}
});
}

Expand Down
5 changes: 0 additions & 5 deletions src/app/core/models/misc/token.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ export type Token = {
token_type: string;
user: User;
}

export type ClusterDomainWithToken = {
cluster_domain: string;
tokens: Token;
}
3 changes: 2 additions & 1 deletion src/app/core/services/common/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular
import { Injectable } from '@angular/core';
import { catchError, Observable } from 'rxjs';
import { throwError } from 'rxjs';
import { environment } from 'src/environments/environment';

let API_BASE_URL: string;
let API_BASE_URL = environment.api_url;

const httpOptions = {
headers: new HttpHeaders({
Expand Down
12 changes: 1 addition & 11 deletions src/app/core/services/common/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { MinimalUser } from '../../models/db/user.model';
import { ClusterDomainWithToken, Token } from '../../models/misc/token.model';
import { Token } from '../../models/misc/token.model';
import { UserService } from '../misc/user.service';
import { ApiService } from './api.service';
import { StorageService } from './storage.service';
import { environment } from 'src/environments/environment';

@Injectable({
providedIn: 'root'
Expand All @@ -26,14 +25,6 @@ export class AuthService {
return this.apiService.post('/auth/login/', { code: code });
}

getClusterDomainByCode(code: string): Observable<ClusterDomainWithToken> {
return this.apiService.post('/auth/cluster_domain/', { code });
}

loginWithRefreshToken(refreshToken: string): Observable<Token> {
return this.apiService.post('/auth/login_with_refresh_token/', { refresh_token: refreshToken });
}

getAccessToken(): string | null {
const user: MinimalUser | null = this.userService.getUserProfile();

Expand Down Expand Up @@ -64,7 +55,6 @@ export class AuthService {

logout(): void {
this.storageService.remove('user');
this.storageService.remove('cluster-domain');
}

checkLoginStatusAndLogout(): void {
Expand Down
20 changes: 7 additions & 13 deletions src/app/core/services/common/helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ExportModuleRule, ExportSettingValidatorRule } from '../../models/sage3
import { TitleCasePipe } from '@angular/common';
import { SnakeCaseToSpaceCasePipe } from 'src/app/shared/pipes/snake-case-to-space-case.pipe';
import { SkipExportValidatorRule, skipExportValidator } from '../../models/common/advanced-settings.model';
import { StorageService } from './storage.service';

@Injectable({
providedIn: 'root'
Expand All @@ -19,15 +18,10 @@ export class HelperService {
@Output() oauthCallbackUrl: EventEmitter<string> = new EventEmitter();

constructor(
private apiService: ApiService,
private router: Router,
private storageService: StorageService
private apiService: ApiService
) {}

private get apiBaseUrl(): string {
return this.storageService.get('cluster-domain') || environment.cluster_domain_api_url;
}

setBaseApiURL(appUrl: string| void): void {
const urlSplit = this.router.url.split('/');
let module: AppUrl;
Expand All @@ -41,15 +35,15 @@ export class HelperService {
}

const apiUrlMap: AppUrlMap = {
[AppUrl.INTACCT]: environment.production ? `${this.apiBaseUrl}/intacct-api/api` : environment.si_api_url,
[AppUrl.INTACCT]: environment.si_api_url,
[AppUrl.QBD]: environment.qbd_api_url,
[AppUrl.TRAVELPERK]: `${this.apiBaseUrl}/${environment.production ? 'integrations-api/': ''}api`,
[AppUrl.BAMBOO_HR]: `${this.apiBaseUrl}/${environment.production ? 'integrations-api/': ''}api`,
[AppUrl.GUSTO]: `${this.apiBaseUrl}/${environment.production ? 'integrations-api/': ''}api`,
[AppUrl.TRAVELPERK]: environment.api_url,
[AppUrl.BAMBOO_HR]: environment.api_url,
[AppUrl.GUSTO]: environment.api_url,
[AppUrl.SAGE300]: environment.sage300_api_url,
[AppUrl.INTEGRATION]: `${this.apiBaseUrl}/${environment.production ? 'integrations-api/': ''}api`,
[AppUrl.INTEGRATION]: environment.api_url,
[AppUrl.BUSINESS_CENTRAL]: environment.business_central_api_url,
[AppUrl.QBO]: environment.production ? `${this.apiBaseUrl}/quickbooks-api/api` : environment.qbo_api_url
[AppUrl.QBO]: environment.qbo_api_url
};

const apiUrl = apiUrlMap[module] ?? apiUrlMap.integration;
Expand Down
6 changes: 3 additions & 3 deletions src/app/integrations/landing/landing.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<svg-icon-sprite *ngIf="!exposeIntacctNewApp" src="open-in-new-tab" width="16px" height="16px" class="landing--accounting-app-open"></svg-icon-sprite>
</span>
</div>
<div *ngIf="!isINCluster" class="landing--accounting-app tw-mr-20-px tw-mt-20-px" (click)="openInAppIntegration(InAppIntegration.BUSINESS_CENTRAL)">
<div class="landing--accounting-app tw-mr-20-px tw-mt-20-px" (click)="openInAppIntegration(InAppIntegration.BUSINESS_CENTRAL)">
<img src="assets/logos/BusinessCentral-logo.svg" class="tw-mt-[-20px]" width="50px" height="60px" />
<span class="landing--accounting-app-name">
Dynamics 365 Business Central
Expand All @@ -68,12 +68,12 @@
<svg-icon-sprite *ngIf="!exposeOnlyQBOApp" src="open-in-new-tab" width="16px" height="16px" class="landing--accounting-app-open"></svg-icon-sprite>
</span>
</div>
<div *ngIf="!isINCluster" class="landing--accounting-app tw-mr-20-px tw-mt-20-px" (click)="openInAppIntegration(InAppIntegration.SAGE300)">
<!-- <div class="landing--accounting-app tw-mr-20-px tw-mt-20-px" (click)="openInAppIntegration(InAppIntegration.SAGE300)">
<img src="assets/logos/sage300-logo.svg" width="110px" height="60px" />
<span class="landing--accounting-app-name">
Sage 300 CRE
</span>
</div>
</div> -->
</div>
<div *ngIf="!exposeOnlyQBOApp" class="landing--accounting-app" (click)="openAccountingIntegrationApp(AccountingIntegrationApp.XERO)">
<img src="assets/logos/xero-logo.png" class="tw-mt-[-20px]" width="50px" height="60px" />
Expand Down
2 changes: 0 additions & 2 deletions src/app/integrations/landing/landing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export class LandingComponent implements OnInit {

readonly brandingConfig = brandingConfig;

readonly isINCluster = this.storageService.get('cluster-domain').includes('in1');

constructor(
private eventsService: EventsService,
private qboAuthService: QboAuthService,
Expand Down

0 comments on commit 469b653

Please sign in to comment.