Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AccessReportMetricsApi } from "./access-report-metrics.api";

/**
* Request body for POST /reports/organizations/{organizationId}
*
*/
export class AccessReportCreateApi {
contentEncryptionKey?: string;
summaryData?: string;
applicationData?: string;
metrics?: AccessReportMetricsApi;
fileSize?: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
import { FileUploadType } from "@bitwarden/common/platform/enums";

import { AccessReportApi } from "./access-report.api";

/**
* Response model returned when creating a report with the Access Intelligence V2 feature flag
* enabled. Contains a presigned upload URL for the report file along with the created report.
*
* - See {@link AccessReportApi} for the nested report response model
*/
export class AccessReportFileApi extends BaseResponse {
reportFileUploadUrl: string = "";
reportResponse: AccessReportApi = new AccessReportApi();
fileUploadType: FileUploadType = FileUploadType.Direct;

constructor(data: any = null) {
super(data);
if (data == null) {
return;
}

this.reportFileUploadUrl = this.getResponseProperty("reportFileUploadUrl") ?? "";
const reportResponse = this.getResponseProperty("reportResponse");
this.reportResponse =
reportResponse != null ? new AccessReportApi(reportResponse) : new AccessReportApi();
this.fileUploadType = this.getResponseProperty("fileUploadType") ?? FileUploadType.Direct;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AccessReport } from "../domain/access-report";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { AccessReportView } from "../view/access-report.view";

import { ReportFileApi } from "./report-file.api";

/**
* Converts an AccessReport API response
*
Expand All @@ -24,6 +26,8 @@ export class AccessReportApi extends BaseResponse {
memberRegistry: string = "";
creationDate: string = "";
contentEncryptionKey: string = "";
reportFile?: ReportFileApi;
reportFileDownloadUrl?: string;

constructor(data: any = null) {
super(data);
Expand All @@ -39,6 +43,10 @@ export class AccessReportApi extends BaseResponse {
this.summary = this.getResponseProperty("summaryData");
this.memberRegistry = this.getResponseProperty("memberRegistry") ?? "";
this.contentEncryptionKey = this.getResponseProperty("contentEncryptionKey");
this.reportFileDownloadUrl = this.getResponseProperty("reportFileDownloadUrl") ?? undefined;

const reportFile = this.getResponseProperty("reportFile");
this.reportFile = reportFile != null ? new ReportFileApi(reportFile) : undefined;

// Use when individual values are encrypted
// const summary = this.getResponseProperty("summaryData");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BaseResponse } from "@bitwarden/common/models/response/base.response";

/**
* Metadata for an uploaded report file.
*/
export class ReportFileApi extends BaseResponse {
id: string | undefined;
fileName: string = "";
/** File size in bytes. Serialized as a string by the server. */
size: number = 0;
validated: boolean = false;

constructor(data: any) {
super(data);
this.id = this.getResponseProperty("id") ?? undefined;
this.fileName = this.getResponseProperty("fileName") ?? "";
this.size = Number(this.getResponseProperty("size") ?? 0);
this.validated = this.getResponseProperty("validated") ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export * from "./api/application-health.api";
export * from "./api/access-report-settings.api";
export * from "./api/access-report-summary.api";
export * from "./api/access-report-metrics.api";
export * from "./api/access-report-create.api";
export * from "./api/access-report-file.api";

// Data layer
export * from "./data/access-report.data";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Observable } from "rxjs";

import { OrganizationId, OrganizationReportId } from "@bitwarden/common/types/guid";

import {
AccessReportApi,
AccessReportCreateApi,
AccessReportFileApi,
AccessReportSummaryApi,
} from "../../models";

export abstract class AccessIntelligenceApiService {
/** GET /reports/organizations/{orgId}/latest */
abstract getLatestReport$(orgId: OrganizationId): Observable<AccessReportApi>;

/**
* POST /reports/organizations/{orgId}
*/
abstract createReport$(
orgId: OrganizationId,
request: AccessReportCreateApi,
): Observable<AccessReportFileApi>;

/**
* POST /reports/organizations/{orgId}/{reportId}/file/report-data
* Self-hosted only. Uploads report data file via multipart form data.
*/
abstract uploadReportFile$(
orgId: OrganizationId,
reportId: OrganizationReportId,
file: File,
reportFileId: string,
): Observable<void>;

/** GET /reports/organizations/{orgId}/data/summary?startDate=&endDate= */
abstract getSummaryDataByDateRange$(
orgId: OrganizationId,
startDate: Date,
endDate: Date,
): Observable<AccessReportSummaryApi[]>;

/** PATCH /reports/organizations/{orgId}/data/summary/{reportId} */
abstract updateSummaryData$(
orgId: OrganizationId,
reportId: OrganizationReportId,
summaryData: string,
metrics?: Record<string, number>,
): Observable<AccessReportApi>;

/** PATCH /reports/organizations/{orgId}/data/application/{reportId} */
abstract updateApplicationData$(
orgId: OrganizationId,
reportId: OrganizationReportId,
applicationData: string,
): Observable<AccessReportApi>;

/** GET /reports/organizations/{orgId}/{reportId}/file/renew */
abstract renewReportFileUploadLink$(
orgId: OrganizationId,
reportId: OrganizationReportId,
): Observable<AccessReportFileApi>;

/** DELETE /reports/organizations/{orgId}/{reportId} */
abstract deleteReport$(orgId: OrganizationId, reportId: OrganizationReportId): Observable<void>;
}
Loading
Loading