Skip to content

Commit

Permalink
Remove ember-ajax and use ember-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
SmitGala committed Dec 30, 2024
1 parent cae4957 commit 077935f
Show file tree
Hide file tree
Showing 88 changed files with 888 additions and 680 deletions.
8 changes: 2 additions & 6 deletions app/adapters/file-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ModelSchema } from 'ember-data';
import commondrf from './commondrf';
import Store, { Snapshot } from '@ember-data/store';
import ModelRegistry from 'ember-data/types/registries/model';
import NetworkService from 'irene/services/network';
import { inject as service } from '@ember/service';
import { FileReportScanType } from 'irene/models/file-report';

interface FileReportQuery {
Expand All @@ -18,8 +16,6 @@ enum REPORT_TYPE_ENDPOINT {
}

export default class FileReport extends commondrf {
@service declare network: NetworkService;

filesBaseUrl = this.buildURLFromBase(`${this.namespace_v2}/files`);
reportsBaseUrl = this.buildURLFromBase(`${this.namespace_v2}/reports`);

Expand Down Expand Up @@ -54,11 +50,11 @@ export default class FileReport extends commondrf {
const reportTypeEndpoint = REPORT_TYPE_ENDPOINT[type];
const url = `${this.reportsBaseUrl}/${reportId}/${reportTypeEndpoint}`;

const response = await this.network.request(url, {
const response = await this.ajax(url, 'GET', {
headers: this.headers,
});

return response.json() as { url?: string };
return response as { url?: string };
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/authenticators/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import RouterService from '@ember/routing/router-service';
import ENV from 'irene/config/environment';
import OidcService from 'irene/services/oidc';
import FreshdeskService from 'irene/services/freshdesk';
import type IreneAjaxService from 'irene/services/ajax';

export interface LoginSuccessDataProps {
token: string;
Expand Down Expand Up @@ -35,7 +36,7 @@ export const processData = (data: LoginSuccessDataProps) => {
};

export default class BaseAuthenticator extends Base {
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service declare session: any;
@service declare router: RouterService;
@service('notifications') declare notify: NotificationService;
Expand Down
2 changes: 1 addition & 1 deletion app/authenticators/irene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IreneAuthenticator extends BaseAuthenticator {

const url = ENV['ember-simple-auth']['loginEndPoint'];

return this.ajax.post(url, { data }).then((data: LoginSuccessDataProps) => {
return this.ajax.post<LoginSuccessDataProps>(url, { data }).then((data) => {
this.restoreLastTransition(data.user_id);

return processData(data);
Expand Down
36 changes: 19 additions & 17 deletions app/authenticators/saml2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ import BaseAuthenticator, { LoginSuccessDataProps, processData } from './base';
export default class Saml2Auth extends BaseAuthenticator {
authenticate(ssotoken: string) {
return new Promise((resolve, reject) => {
const url = ENV['endpoints']['saml2Login'];
const url = ENV['endpoints']['saml2Login'] as string;

this.ajax.post(url, { data: { token: ssotoken } }).then(
(data: LoginSuccessDataProps) => {
this.restoreLastTransition(data.user_id);
this.ajax
.post<LoginSuccessDataProps>(url, { data: { token: ssotoken } })
.then(
(data) => {
this.restoreLastTransition(data.user_id);

data = processData(data);
resolve(data);
},
(error: AjaxError) => {
let msg = 'Login failed';
data = processData(data);
resolve(data);
},
(error: AjaxError) => {
let msg = 'Login failed';

if (error.payload.message) {
msg = 'Login failed: ' + error.payload.message;
}
if (error.payload.message) {
msg = 'Login failed: ' + error.payload.message;
}

this.notify.error(msg);
this.router.transitionTo('login');
this.notify.error(msg);
this.router.transitionTo('login');

return reject(msg);
}
);
return reject(msg);
}
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import IntlService from 'ember-intl/services/intl';
import ENV from 'irene/config/environment';

import PersonaltokenModel from 'irene/models/personaltoken';
import type IreneAjaxService from 'irene/services/ajax';

export interface AccountSettingsDeveloperSettingsPersonaltokenListDeleteTokenSignature {
Args: {
Expand All @@ -17,7 +18,7 @@ export interface AccountSettingsDeveloperSettingsPersonaltokenListDeleteTokenSig

export default class AccountSettingsDeveloperSettingsPersonaltokenListDeleteTokenComponent extends Component<AccountSettingsDeveloperSettingsPersonaltokenListDeleteTokenSignature> {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service('notifications') declare notify: NotificationService;

@tracked showRevokePersonalTokenConfirmBox = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { task } from 'ember-concurrency';
import { query } from 'ember-data-resources';

import PersonaltokenModel from 'irene/models/personaltoken';
import type IreneAjaxService from 'irene/services/ajax';

export default class AccountSettingsDeveloperSettingsPersonaltokenListComponent extends Component {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service declare store: Store;
@service('notifications') declare notify: NotificationService;

Expand Down Expand Up @@ -78,7 +79,7 @@ export default class AccountSettingsDeveloperSettingsPersonaltokenListComponent
name: this.tokenName,
};

await this.ajax.post(ENV.endpoints['personaltokens'], {
await this.ajax.post(ENV.endpoints['personaltokens'] as string, {
data,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type Store from '@ember-data/store';
import ENV from 'irene/config/environment';
import parseError from 'irene/utils/parse-error';
import type DatetimeService from 'irene/services/datetime';
import type IreneAjaxService from 'irene/services/ajax';

const localeStrings = {
en: 'English',
Expand All @@ -19,7 +20,7 @@ type LocaleKeys = keyof typeof localeStrings;

export default class AccountSettingsGeneralSelectLanguageComponent extends Component {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service declare datetime: DatetimeService;
@service declare session: any;
@service declare store: Store;
Expand Down Expand Up @@ -65,7 +66,7 @@ export default class AccountSettingsGeneralSelectLanguageComponent extends Compo
};

try {
await this.ajax.post(ENV.endpoints['lang'], { data });
await this.ajax.post(ENV.endpoints['lang'] as string, { data });

if (!this.isDestroyed) {
window.location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ import ENUMS from 'irene/enums';
import MeService from 'irene/services/me';
import MfaModel from 'irene/models/mfa';
import UserModel from 'irene/models/user';
import type IreneAjaxService from 'irene/services/ajax';

type MfaConfirmEventData = { cancel: boolean; otp?: string };

type TokenData = {
token: string;
secret: string;
};

export default class AccountSettingsSecurityMultiFactorAuthComponent extends Component.extend(
Evented
) {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service('notifications') declare notify: NotificationService;
@service declare me: MeService;
@service declare store: Store;
Expand Down Expand Up @@ -169,7 +175,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
});

getMFAEnableEmailToken = task(async () => {
return await this.ajax.post(this.mfaEndpoint, {
return await this.ajax.post<TokenData>(this.mfaEndpoint, {
data: {
method: ENUMS.MFA_METHOD.HOTP,
},
Expand Down Expand Up @@ -302,7 +308,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
});

getMFAEnableAppToken = task(async () => {
return await this.ajax.post(this.mfaEndpoint, {
return await this.ajax.post<TokenData>(this.mfaEndpoint, {
data: {
method: ENUMS.MFA_METHOD.TOTP,
},
Expand Down Expand Up @@ -448,7 +454,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com

verifySwitchToEmailAppOTP = task(async (otp) => {
try {
return await this.ajax.post(this.mfaEndpoint, {
return await this.ajax.post<TokenData>(this.mfaEndpoint, {
data: {
method: ENUMS.MFA_METHOD.HOTP,
otp: otp || '',
Expand Down Expand Up @@ -517,7 +523,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
appOTPNotConfirmed = !(tokenData || {}).token;
} while (appOTPNotConfirmed);

debug('SwitchTOEmail: App OTP Token Data ' + tokenData.token);
debug('SwitchTOEmail: App OTP Token Data ' + tokenData?.token);

while (true) {
debug('SwitchTOEmail: In Email OTP Loop');
Expand All @@ -529,7 +535,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com

const confirmed = await this.verifySwitchToEmailEmailOTP.perform(
emailOTPData.otp,
tokenData.token
tokenData?.token
);

if (confirmed) {
Expand Down Expand Up @@ -672,7 +678,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
}

try {
return await this.ajax.post(this.mfaEndpoint, {
return await this.ajax.post<TokenData>(this.mfaEndpoint, {
data: {
method: ENUMS.MFA_METHOD.TOTP,
otp: otp,
Expand Down Expand Up @@ -733,7 +739,7 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
}

let emailOTPNotConfirmed;
let tokenData;
let tokenData: TokenData;

await this.staInitialEmail.perform();

Expand All @@ -745,7 +751,9 @@ export default class AccountSettingsSecurityMultiFactorAuthComponent extends Com
return;
}

tokenData = await this.staVerifyEmailOTP.perform(emailOTPData.otp);
tokenData = (await this.staVerifyEmailOTP.perform(
emailOTPData.otp
)) as TokenData;

emailOTPNotConfirmed = !(tokenData || {}).token;
} while (emailOTPNotConfirmed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Changeset } from 'ember-changeset';

import ENV from 'irene/config/environment';
import triggerAnalytics from 'irene/utils/trigger-analytics';
import type IreneAjaxService from 'irene/services/ajax';

type ChangesetBufferProps = BufferedChangeset & {
old_password: string;
Expand All @@ -29,7 +30,7 @@ const ChangeValidator = {

export default class AccountSettingsSecurityPasswordChangeComponent extends Component {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service('rollbar') declare logger: any;
@service declare router: RouterService;
@service('notifications') declare notify: NotificationService;
Expand Down Expand Up @@ -63,7 +64,7 @@ export default class AccountSettingsSecurityPasswordChangeComponent extends Comp
};

try {
await this.ajax.post(this.changePasswordURL, {
await this.ajax.post(String(this.changePasswordURL), {
data,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type RiskOverrideCriteria = { label: string; value: string };

export default class AnalysisRiskOverrideEditDrawerOverrideFormComponent extends Component<AnalysisRiskOverrideEditDrawerOverrideFormSignature> {
@service declare intl: IntlService;
@service declare ajax: any;
@service('notifications') declare notify: NotificationService;

@tracked showOverrideSuccess = false;
Expand Down
3 changes: 2 additions & 1 deletion app/components/api-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import triggerAnalytics from 'irene/utils/trigger-analytics';
import ApiScanOptionsModel from 'irene/models/api-scan-options';
import { task } from 'ember-concurrency';
import { action } from '@ember/object';
import type IreneAjaxService from 'irene/services/ajax';

const isRegexFailed = function (url: string) {
const reg =
Expand All @@ -29,7 +30,7 @@ export interface ApiFilterSignature {

export default class ApiFilterComponent extends Component<ApiFilterSignature> {
@service declare intl: IntlService;
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service declare store: Store;
@service('notifications') declare notify: NotificationService;

Expand Down
3 changes: 2 additions & 1 deletion app/components/app-monitoring/version-table/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import parseError from 'irene/utils/parse-error';
import SubmissionModel from 'irene/models/submission';
import RealtimeService from 'irene/services/realtime';
import ENUMS from 'irene/enums';
import type IreneAjaxService from 'irene/services/ajax';

dayjs.extend(advancedFormat);

Expand All @@ -27,7 +28,7 @@ interface AppMonitoringVersionTableActionsSignature {
}

export default class AppMonitoringVersionTableActionsComponent extends Component<AppMonitoringVersionTableActionsSignature> {
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service('notifications') declare notify: NotificationService;
@service declare store: Store;
@service declare intl: IntlService;
Expand Down
1 change: 0 additions & 1 deletion app/components/appknox-wrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface AppknoxWrapperSignature {
}

export default class AppknoxWrapperComponent extends Component<AppknoxWrapperSignature> {
@service declare ajax: any;
@service declare session: any;
@service declare me: MeService;
@service declare intl: IntlService;
Expand Down
11 changes: 9 additions & 2 deletions app/components/attachment-detail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@ import { inject as service } from '@ember/service';
import ENV from 'irene/config/environment';
import AttachmentModel from 'irene/models/attachment';
import { task } from 'ember-concurrency';
import type IreneAjaxService from 'irene/services/ajax';

export interface AttachmentDetailSignature {
Args: {
attachment: AttachmentModel;
};
}

interface DownloadResponse {
data: {
url: string;
};
}

export default class AttachmentDetailComponent extends Component<AttachmentDetailSignature> {
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service('notifications') declare notify: NotificationService;
@service('browser/window') declare window: Window;

downloadAttachment = task({ drop: true }, async () => {
const url = ENV.host + this.args.attachment.downloadUrl;

try {
const result = await this.ajax.request(url);
const result = await this.ajax.request<DownloadResponse>(url);

this.window.open(result.data.url);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { inject as service } from '@ember/service';
import type IntlService from 'ember-intl/services/intl';

import parseError from 'irene/utils/parse-error';
import type IreneAjaxService from 'irene/services/ajax';

export default class DyanmicscanAutomationUpsellingFeatureComponent extends Component {
@service declare ajax: any;
@service declare ajax: IreneAjaxService;
@service declare intl: IntlService;
@service('notifications') declare notify: NotificationService;
@service('browser/window') declare window: Window;
Expand Down
Loading

0 comments on commit 077935f

Please sign in to comment.