Skip to content

Commit

Permalink
Merge pull request #290 from Enterprise-CMCS/bruce
Browse files Browse the repository at this point in the history
feat(OY2-26538): package action changelog
  • Loading branch information
pkim-gswell authored Jan 10, 2024
2 parents b0b261c + 6243d62 commit 8c53dd8
Show file tree
Hide file tree
Showing 64 changed files with 813 additions and 329 deletions.
14 changes: 7 additions & 7 deletions src/libs/opensearch-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as aws4 from "aws4";
import axios from "axios";
import { aws4Interceptor } from "aws4-axios";
import { STSClient, AssumeRoleCommand } from "@aws-sdk/client-sts";
import { OsIndex } from "shared-types";
import { opensearch } from "shared-types";
let client: Client;

export async function getClient(host: string) {
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function updateData(host: string, indexObject: any) {

export async function bulkUpdateData(
host: string,
index: OsIndex,
index: opensearch.Index,
arrayOfDocuments: any
) {
client = client || (await getClient(host));
Expand All @@ -60,7 +60,7 @@ export async function bulkUpdateData(
console.log(response);
}

export async function deleteIndex(host: string, index: OsIndex) {
export async function deleteIndex(host: string, index: opensearch.Index) {
client = client || (await getClient(host));
var response = await client.indices.delete({ index });
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export async function mapRole(
}
}

export async function search(host: string, index: OsIndex, query: any) {
export async function search(host: string, index: opensearch.Index, query: any) {
client = client || (await getClient(host));
try {
const response = await client.search({
Expand All @@ -124,7 +124,7 @@ export async function search(host: string, index: OsIndex, query: any) {
}
}

export async function getItem(host: string, index: OsIndex, id: string) {
export async function getItem(host: string, index: opensearch.Index, id: string) {
client = client || (await getClient(host));
try {
const response = await client.get({ id, index });
Expand All @@ -135,7 +135,7 @@ export async function getItem(host: string, index: OsIndex, id: string) {
}

// check it exists - then create
export async function createIndex(host: string, index: OsIndex) {
export async function createIndex(host: string, index: opensearch.Index) {
client = client || (await getClient(host));
try {
const exists = await client.indices.exists({ index });
Expand All @@ -150,7 +150,7 @@ export async function createIndex(host: string, index: OsIndex) {

export async function updateFieldMapping(
host: string,
index: OsIndex,
index: opensearch.Index,
properties: object
) {
client = client || (await getClient(host));
Expand Down
2 changes: 1 addition & 1 deletion src/packages/shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from "./errors";
export * from "./seatool";
export * from "./onemac";
export * from "./onemacLegacy";
export * from "./opensearch";
export * as opensearch from "./opensearch";
export * from "./uploads";
export * from "./actions";
export * from "./attachments";
Expand Down
110 changes: 0 additions & 110 deletions src/packages/shared-types/opensearch.ts

This file was deleted.

82 changes: 82 additions & 0 deletions src/packages/shared-types/opensearch/_.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
export type Hit<T> = {
_index: string;
_id: string;
_score: number;
_source: T;
sort: Array<number>;
};
export type Hits<T> = {
hits: Hit<T>[];
max_score: number;
total: { value: number; relation: "eq" };
};

export type Response<T> = {
_shards: {
total: number;
failed: number;
successful: number;
skipped: number;
};
hits: Hits<T>;
total: {
value: number;
};
max_score: number | null;
took: number;
timed_out: boolean;
aggregations?: AggResult;
};

export type FilterType =
| "term"
| "terms"
| "match"
| "range"
| "search"
| "global_search"
| "exists";

export type RangeValue = { gte?: string; lte?: string };
export type FilterValue = string | string[] | number | boolean | RangeValue;

export type Filterable<_FIELD> = {
type: FilterType;
label?: string;
component?: string;
field: _FIELD;
value: FilterValue;
prefix: "must" | "must_not" | "should" | "filter";
};

export type QueryState<_FIELD> = {
sort: { field: _FIELD; order: "asc" | "desc" };
pagination: { number: number; size: number };
filters: Filterable<_FIELD>[];
search?: string;
};

export type AggQuery<_FIELD> = {
name: string;
type: FilterType;
field: _FIELD;
size: number;
};

export type AggBucket = { key: string; doc_count: number };

export type AggResult = Record<
string,
{
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: AggBucket[];
}
>;

export type ExportHeaderOptions<TData> = {
transform: (data: TData) => string;
name: string;
};

export type Index = "main" | "seatool" | "changelog";
43 changes: 43 additions & 0 deletions src/packages/shared-types/opensearch/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Response as Res,
Hit,
Filterable as FIL,
QueryState,
AggQuery,
} from "./_";

export type Document = {
actionType: string;
additionalInformation: string;
attachments?: {
bucket: string;
filename: string;
key: string;
title: string;
uploadDate: number;
}[];
timestamp: string;
authority: string;
id: string;
origin: string;
packageId: string;
proposedEffectiveDate: number;
raiWithdrawEnabled: boolean;
rais: any;
requestedDate: number;
responseDate: number;
state: string;
submitterEmail: string;
submitterName: string;
withdrawnDate: number;
};

export type Response = Res<Document>;
export type ItemResult = Hit<Document> & {
found: boolean;
};

export type Field = keyof Document | `${keyof Document}.keyword`;
export type Filterable = FIL<Field>;
export type State = QueryState<Field>;
export type Aggs = AggQuery<Field>;
3 changes: 3 additions & 0 deletions src/packages/shared-types/opensearch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * as changelog from "./changelog";
export * as main from "./main";
export * from "./_";
38 changes: 38 additions & 0 deletions src/packages/shared-types/opensearch/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
SeaToolTransform,
OnemacTransform,
OnemacLegacyTransform,
RaiIssueTransform,
RaiResponseTransform,
RaiWithdrawTransform,
WithdrawPackageTransform,
ToggleWithdrawRaiEnabledTransform,
} from "..";

import {
Response as Res,
Hit,
Filterable as FIL,
QueryState,
AggQuery,
} from "./_";
import { ItemResult as Changelog } from "./changelog";

export type Document = OnemacTransform &
OnemacLegacyTransform &
SeaToolTransform &
RaiIssueTransform &
RaiResponseTransform &
RaiWithdrawTransform &
WithdrawPackageTransform &
ToggleWithdrawRaiEnabledTransform & { changelog?: Changelog[] };

export type Response = Res<Document>;
export type ItemResult = Hit<Document> & {
found: boolean;
};

export type Field = keyof Document | `${keyof Document}.keyword`;
export type Filterable = FIL<Field>;
export type State = QueryState<Field>;
export type Aggs = AggQuery<Field>;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
CognitoUserAttributes,
OsMainSourceItem,
PlanType,
opensearch
} from "../../shared-types";
import rules from "./rules";
import { PackageCheck } from "../packageCheck";

export const getAvailableActions = (
user: CognitoUserAttributes,
result: OsMainSourceItem
result: opensearch.main.Document
) => {
const checks = PackageCheck(result);
return checks.planTypeIs([PlanType.MED_SPA])
Expand Down
4 changes: 2 additions & 2 deletions src/packages/shared-utils/packageCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OsMainSourceItem, PlanType, SEATOOL_STATUS } from "../shared-types";
import { opensearch, PlanType, SEATOOL_STATUS } from "../shared-types";
import { getLatestRai } from "./rai-helper";

const secondClockStatuses = [
Expand All @@ -24,7 +24,7 @@ export const PackageCheck = ({
rais,
raiWithdrawEnabled,
planType,
}: OsMainSourceItem) => {
}: opensearch.main.Document) => {
const latestRai = getLatestRai(rais);
const planChecks = {
isSpa: checkPlan(planType, [PlanType.MED_SPA, PlanType.CHIP_SPA]),
Expand Down
Loading

0 comments on commit 8c53dd8

Please sign in to comment.