Skip to content

Commit

Permalink
Cluster domain changes (#501)
Browse files Browse the repository at this point in the history
* Cluster domain changes

* sage comment

* Remove qbd intacct services (#476)

* Fix build

* add dep

* hide sage and dynamics

* remove qbd and intacct services

* fix lint
  • Loading branch information
ashwin1111 authored Feb 2, 2024
1 parent 3f3ee8c commit bc09fc5
Show file tree
Hide file tree
Showing 32 changed files with 126 additions and 565 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?{{API_URL}}?${API_URL}?g" $f;
sed -i $SED_EXTRA_ARGS "s?{{CLUSTER_DOMAIN_API_URL}}?${CLUSTER_DOMAIN_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}}'}`,
api_url: `${process.env.API_URL ? process.env.API_URL : '{{API_URL}}'}`,
cluster_domain_api_url: `${process.env.CLUSTER_DOMAIN_API_URL ? process.env.CLUSTER_DOMAIN_API_URL : '{{CLUSTER_DOMAIN_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: 40 additions & 33 deletions src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 @@ -21,15 +23,16 @@ 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 userService: UserService,
private qbdAuthService: QbdAuthService,
private siAuthService : SiAuthService,
private sage300AuthService: Sage300AuthService,
private businessCentralAuthService: BusinessCentralAuthService,
private qboAuthService: QboAuthService
private siAuthService : SiAuthService,
private storageService: StorageService,
private userService: UserService
) { }

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

private saveUserProfileAndNavigate(code: string, redirectUri: string | undefined): void {
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.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.helperService.setBaseApiURL(AppUrl.QBD);
this.qbdAuthService.qbdLogin(user.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.QBD);
this.qbdAuthService.qbdLogin(clusterDomainWithToken.tokens.refresh_token).subscribe();

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

this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
this.businessCentralAuthService.loginWithRefreshToken(user.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
this.businessCentralAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.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(user.refresh_token).subscribe();
this.helperService.setBaseApiURL(AppUrl.INTACCT);
this.siAuthService.loginWithRefreshToken(user.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(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);
}
});
});
}

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

export type ClusterDomainWithToken = {
cluster_domain: string;
tokens: Token;
}
3 changes: 1 addition & 2 deletions src/app/core/services/common/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ 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 = environment.api_url;
let API_BASE_URL: string;

const httpOptions = {
headers: new HttpHeaders({
Expand Down
12 changes: 11 additions & 1 deletion src/app/core/services/common/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { MinimalUser } from '../../models/db/user.model';
import { Token } from '../../models/misc/token.model';
import { ClusterDomainWithToken, 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 @@ -25,6 +26,14 @@ 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 @@ -55,6 +64,7 @@ export class AuthService {

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

checkLoginStatusAndLogout(): void {
Expand Down
18 changes: 12 additions & 6 deletions src/app/core/services/common/helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -18,10 +19,15 @@ export class HelperService {
@Output() oauthCallbackUrl: EventEmitter<string> = new EventEmitter();

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

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 @@ -35,14 +41,14 @@ export class HelperService {
}

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

const apiUrl = apiUrlMap[module] ?? apiUrlMap.integration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { QBDAdvancedSettingsGet, QBDAdvancedSettingsPost } from 'src/app/core/models/qbd/qbd-configuration/advanced-setting.model';
import { QbdApiService } from '../qbd-core/qbd-api.service';
import { QbdWorkspaceService } from '../qbd-core/qbd-workspace.service';
import { ApiService } from '../../common/api.service';

@Injectable({
providedIn: 'root'
})
export class QbdAdvancedSettingService {

constructor(
private apiService: QbdApiService,
private apiService: ApiService,
private workspaceService: QbdWorkspaceService
) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { QBDExportSettingGet, QBDExportSettingPost } from 'src/app/core/models/qbd/qbd-configuration/export-setting.model';
import { QbdApiService } from '../qbd-core/qbd-api.service';
import { QbdWorkspaceService } from '../qbd-core/qbd-workspace.service';
import { ApiService } from '../../common/api.service';

@Injectable({
providedIn: 'root'
})
export class QbdExportSettingService {

constructor(
private apiService: QbdApiService,
private apiService: ApiService,
private workspaceService: QbdWorkspaceService
) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { QBDFieldMappingGet, QBDFieldMappingPost } from 'src/app/core/models/qbd/qbd-configuration/field-mapping.model';
import { QbdApiService } from '../qbd-core/qbd-api.service';
import { QbdWorkspaceService } from '../qbd-core/qbd-workspace.service';
import { ApiService } from '../../common/api.service';

@Injectable({
providedIn: 'root'
})
export class QbdFieldMappingService {

constructor(
private apiService: QbdApiService,
private apiService: ApiService,
private workspaceService: QbdWorkspaceService
) { }

Expand Down
Loading

0 comments on commit bc09fc5

Please sign in to comment.