Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OY2-26538): package action changelog #290

Merged
merged 16 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates the overarching opensearch namespace

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> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here are the opensearch core type definitions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. Any reason why the filename is _?

Copy link
Contributor Author

@pkim-gswell pkim-gswell Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially named it base.ts. But I figured that was too based.

_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";
42 changes: 42 additions & 0 deletions src/packages/shared-types/opensearch/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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;
}[];
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>;
Comment on lines +35 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both main and changelog Indices enforce the same naming convention

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 "./_";
Comment on lines +1 to +3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where namespaces get defined

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
Loading