Skip to content

Commit

Permalink
Update node dependencies Scripting 2024-12-19 (#276)
Browse files Browse the repository at this point in the history
* PewRL fixes and updates (#274)

* Endpoint modal initially open w/o useEffect, removed devkey option

* Clear URL button added

* Clear URL button, query params, request body

* Replaced console.error with log()

* Update node dependencies 2024-12-19 (#275)

* Added back in the ec2-metadata-service call to getInstanceId

* Updated version and dependencies

- Updated lockfile to latest
- Updated Mocha to v11

* Updated Next.js to 15.1

* Fixed timeout issue in unit tests by only calling metadata service in AWS

---------

Co-authored-by: blonde-mike <[email protected]>
  • Loading branch information
tkmcmaster and blonde-mike authored Dec 19, 2024
1 parent 714334d commit 3c18cae
Show file tree
Hide file tree
Showing 14 changed files with 2,326 additions and 1,724 deletions.
4 changes: 2 additions & 2 deletions agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-agent",
"version": "3.3.4",
"version": "3.3.5",
"description": "Agent Service for running pewpew tests",
"main": "dist/src/app.js",
"scripts": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"axios": "~1.7.0",
"chai": "^4.3.7",
"eslint": "^9.15.0",
"mocha": "^10.2.0",
"mocha": "^11.0.0",
"nyc": "^17.0.0",
"typescript": "^5.3.0"
}
Expand Down
5 changes: 3 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-common",
"version": "3.3.4",
"version": "3.3.5",
"description": "Common Code for the PewPewController and PewPewAgent",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.363.0",
"@aws-sdk/client-sqs": "^3.363.0",
"@aws-sdk/ec2-metadata-service": "^3.363.0",
"@aws-sdk/lib-storage": "^3.363.0",
"bunyan": "~1.8.0",
"rimraf": "^5.0.0"
Expand All @@ -55,7 +56,7 @@
"dotenv": "^16.0.0",
"dotenv-flow": "^4.0.1",
"eslint": "^9.15.0",
"mocha": "^10.2.0",
"mocha": "^11.0.0",
"nyc": "^17.0.0",
"typescript": "^5.3.0"
}
Expand Down
24 changes: 24 additions & 0 deletions common/src/util/ec2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { LogLevel, log } from "./log";
import { IS_RUNNING_IN_AWS } from "./util";
import { MetadataService } from "@aws-sdk/ec2-metadata-service";
import { exec as _exec } from "child_process";
import { promisify } from "util";
import { readFile } from "fs/promises";
Expand All @@ -8,7 +10,29 @@ export const INSTANCE_ID_FILE = "/var/lib/cloud/data/instance-id";
export const INSTANCE_ID_REGEX = /^i-[0-9a-z]+$/;
export const INSTANCE_FILE_REGEX = /^instance-id:\s*(i-[0-9a-z]+)$/;
export const INSTANCE_ID_COMMAND = "ec2-metadata --instance-id";

// Putting back code removed by https://github.com/fs-eng/ppaas-common/commit/397d38e31ebafa9551dec8d9a2082140e8d949ae#diff-b0083bb9a17262c7a014463e8dee3fd0489cad8cb220d19531f295b9592826a0L14
// AWS SDK V3 finally supports the MetadataService
const metadata: MetadataService = new MetadataService({
// host: "169.254.169.254"
});

export async function getInstanceId (): Promise<string> {
// Our current mocks do not support the metadata service. bypass when not in AWS so we don't timeout on integration and unit tests
if (IS_RUNNING_IN_AWS) {
try {
// curl http://169.254.169.254/latest/meta-data/instance-id -> "i-0cfd3309705a3ce79"
const instanceId: string = await metadata.request("/latest/meta-data/instance-id", {});
log("getInstanceId MetadataService /latest/meta-data/instance-id: " + instanceId, LogLevel.WARN, instanceId);
if (!INSTANCE_ID_REGEX.test(instanceId)) {
log(`InstanceId did not match regex [${instanceId}]`, LogLevel.WARN, { match: instanceId?.match(INSTANCE_ID_REGEX), INSTANCE_ID_REGEX });
throw new Error("InstanceId did not match regex");
}
return instanceId;
} catch (error: unknown) {
log("Could not load instanceId metadata", LogLevel.WARN, error);
}
}
// Try to load from file first
// $ cat /var/lib/cloud/data/instance-id -> "i-0cfd3309705a3ce79"
try {
Expand Down
1 change: 1 addition & 0 deletions common/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CONTROLLER_APPLICATION_PREFIX: string = CONTROLLER_APPLICATION_NAME
export const SYSTEM_NAME: string = process.env.SYSTEM_NAME || "unittests";
export const CONTROLLER_ENV = process.env.CONTROLLER_ENV;
export const AGENT_ENV = process.env.AGENT_ENV;
export const IS_RUNNING_IN_AWS: boolean = process.env.APPLICATION_NAME !== undefined && process.env.SYSTEM_NAME !== undefined;

export const PEWPEW_BINARY_FOLDER: string = "pewpew";
export const PEWPEW_VERSION_LATEST: string = "latest";
Expand Down
2 changes: 1 addition & 1 deletion controller/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
10 changes: 5 additions & 5 deletions controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-controller",
"version": "3.3.4",
"version": "3.3.5",
"description": "Controller Service for running pewpew tests",
"private": true,
"scripts": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"formidable": "~3.5.0",
"js-cookie": "^3.0.5",
"js-yaml": "^4.1.0",
"next": "~15.0.3",
"next": "~15.1.0",
"next-cookies": "^2.0.3",
"openid-client": "~5.7.0",
"rc-progress": "^4.0.0",
Expand All @@ -84,7 +84,7 @@
"@aws-sdk/util-stream-node": "^3.363.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@next/eslint-plugin-next": "~15.0.3",
"@next/eslint-plugin-next": "~15.1.0",
"@storybook/addon-actions": "~8.4.0",
"@storybook/addon-links": "~8.4.0",
"@storybook/nextjs": "~8.4.0",
Expand Down Expand Up @@ -115,13 +115,13 @@
"dotenv-flow": "^4.0.1",
"esbuild": ">=0.17",
"eslint": "^9.15.0",
"eslint-config-next": "~15.0.3",
"eslint-config-next": "~15.1.0",
"form-data": "^4.0.0",
"glob-parent": "^6.0.2",
"immer": "^10.0.2",
"jsdom": ">=23.0.0",
"jsdom-global": "^3.0.2",
"mocha": "^10.2.0",
"mocha": "^11.0.0",
"nyc": "^17.0.0",
"postcss": "^8.4.24",
"set-value": "^4.1.0",
Expand Down
6 changes: 4 additions & 2 deletions guide/results-viewer-react/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ interface ModalProps {
children?: React.ReactNode;
isReady?: boolean;
scrollable?: boolean;
initialDisplay?: boolean;
}

export interface ModalObject {
Expand Down Expand Up @@ -136,9 +137,10 @@ export const Modal = forwardRef(({
submitText = "submit",
children,
isReady,
scrollable
scrollable,
initialDisplay = false
}: ModalProps, ref: Ref<ModalObject>) => {
const [display, setDisplay] = useState(false);
const [display, setDisplay] = useState(initialDisplay);
let windowOffset: number = 0;

useImperativeHandle(ref, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { PewPewHeader, PewPewQueryParam } from "../../util/yamlwriter";
import { PewPewQueryParamStringType } from ".";
import React from "react";

export interface QueryParamsViewProps {
id: string;
queryParamList: PewPewQueryParam[];
removeParam: (param: PewPewQueryParam) => void;
changeParam: (paramIndex: number, type: PewPewQueryParamStringType, value: string) => void;
addParam: () => void;
}

function QueryParamsView ({ id, queryParamList, removeParam, changeParam, addParam }: QueryParamsViewProps): JSX.Element {
const styles: Record<string, React.CSSProperties> = {
headersDisplay: {
marginTop: "10px",
maxHeight: "300px",
overflow: "auto"
},
gridContainer: {
display: "grid",
gap: "10px"
},
gridHeader: {
display: "grid",
gridTemplateColumns: "auto 1fr 2fr",
gap: "10px",
fontWeight: "bold",
height: "20px"
},
gridRows: {
display: "grid",
gridTemplateColumns: "auto 1fr 2fr",
gap: "10px",
alignItems: "stretch"
},
input: {
boxSizing: "border-box"
},
button: {
boxSizing: "border-box",
whiteSpace: "nowrap"
}
};
return (
<React.Fragment>
<div style={styles.headersDisplay}>
<div style={styles.gridContainer}>
<div style={styles.gridHeader}>
<span><button name={id} onClick={() => addParam()}>+</button></span>
<span>Name</span>
<span>Value</span>
</div>
{queryParamList.length === 0 && <span>No Query Params yet, click "+" to create one</span>}
{queryParamList.map((param: PewPewHeader, index: number) => (
<div key={index} style={styles.gridRows}>
<button style={styles.button} onClick={() => removeParam(param)}>X</button>
<input style={styles.input} id={`urlHeaderKey@${index}`} name={id} value={param.name} onChange={(event) => changeParam(index, "name", event.target.value)} />
<input style={styles.input} id={`urlHeaderValue@${index}`} name={id} value={param.value} onChange={(event) => changeParam(index, "value", event.target.value)} />
</div>
))}
</div>
</div>
</React.Fragment>
);
}

export default QueryParamsView;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { LogLevel, log } from "../../util/log";
import React from "react";

export interface RequestBodyViewProps {
requestBody: object | undefined;
updateRequestBody: (newRequestBody: object) => void;
}

function RequestBodyView ({ requestBody, updateRequestBody }: RequestBodyViewProps): JSX.Element {
const [requestBodyInEdit, setRequestBodyInEdit] = React.useState<string>(JSON.stringify(requestBody, null, 2).replace(/\\n/g, "\n").replace(/^"|"$/g, ""));

const requestBodyDisplayStyle: React.CSSProperties = {
fontFamily: "monospace",
width: "100%",
height: "270px",
overflow: "auto",
border: "1px solid #ccc",
padding: "10px",
backgroundColor: "#2e3438",
resize: "none",
tabSize: 2,
boxSizing: "border-box"
};

const handleEditorInput = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const newRequestBody = event.target.value;
setRequestBodyInEdit(newRequestBody);
try {
updateRequestBody(JSON.parse(newRequestBody));
} catch (error) {
log("Invalid JSON", LogLevel.WARN, error);
}
};

return (
<React.Fragment>
<textarea
value={requestBodyInEdit}
onChange={handleEditorInput}
style={requestBodyDisplayStyle}
/>
</React.Fragment>
);
}

export default RequestBodyView;
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import HeadersView, { HeadersViewProps } from "./HeadersView";
import QueryParamsView, { QueryParamsViewProps } from "./QueryParamsView";
import RequestBodyView, { RequestBodyViewProps } from "./RequestBodyView";
import ResponseView, { ResponseViewProps } from "./ResponseView";
import React from "react";
import { TabType } from ".";

interface RequestDetailsTabsProps extends HeadersViewProps, ResponseViewProps {
interface RequestDetailsTabsProps extends HeadersViewProps, ResponseViewProps, QueryParamsViewProps, RequestBodyViewProps {
activeTab: TabType;
handleChangeTab: (tab: TabType) => void;
}

function RequestDetailsTabs ({ id, headersList, removeHeader, changeHeader, addHeader, response, error, activeTab, handleChangeTab }: RequestDetailsTabsProps): JSX.Element {
const tabs: TabType[] = ["Headers", "Response"];
function RequestDetailsTabs ({
id,
headersList,
removeHeader,
changeHeader,
addHeader,
queryParamList,
removeParam,
changeParam,
addParam,
response,
error,
activeTab,
handleChangeTab,
requestBody,
updateRequestBody
}: RequestDetailsTabsProps): JSX.Element {
const tabs: TabType[] = ["Headers", "Query Params", "Request Body", "Response"];

return (
<div>
Expand All @@ -33,6 +51,8 @@ interface RequestDetailsTabsProps extends HeadersViewProps, ResponseViewProps {
<div role="tabpanel" id={`tabpanel-${activeTab}`} aria-labelledby={`tab-${activeTab}`}>
{activeTab === "Headers" && <HeadersView id={id} headersList={headersList} removeHeader={removeHeader} changeHeader={changeHeader} addHeader={addHeader} />}
{activeTab === "Response" && <ResponseView response={response} error={error} />}
{activeTab === "Query Params" && <QueryParamsView id={id} queryParamList={queryParamList} removeParam={removeParam} changeParam={changeParam} addParam={addParam} />}
{activeTab === "Request Body" && <RequestBodyView requestBody={requestBody} updateRequestBody={updateRequestBody} />}
</div>
</div>
);
Expand Down
Loading

0 comments on commit 3c18cae

Please sign in to comment.