Skip to content

Commit 89dc471

Browse files
committed
Merge branch 'main' into fmenezes/autoGenerateApiClient
2 parents 365f457 + 8ca583a commit 89dc471

36 files changed

+305
-504
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
coverage
33
package-lock.json
44
tests/tmp
5+
src/common/atlas/openapi.d.ts

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"singleQuote": false,
66
"printWidth": 120,
77
"overrides": [
8+
{
9+
"files": "*.ts",
10+
"options": {
11+
"insertPragma": false,
12+
"proseWrap": "preserve"
13+
}
14+
},
815
{
916
"files": "*.json",
1017
"options": {

eslint.config.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,32 @@ import globals from "globals";
44
import tseslint from "typescript-eslint";
55
import eslintConfigPrettier from "eslint-config-prettier/flat";
66

7+
const files = ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.test.ts", "eslint.config.js", "jest.config.js"];
8+
79
export default defineConfig([
8-
{ files: ["src/**/*.ts"], plugins: { js }, extends: ["js/recommended"] },
9-
{ files: ["src/**/*.ts"], languageOptions: { globals: globals.node } },
10-
tseslint.configs.recommended,
10+
{ files, plugins: { js }, extends: ["js/recommended"] },
11+
{ files, languageOptions: { globals: globals.node } },
12+
tseslint.configs.recommendedTypeChecked,
13+
{
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: import.meta.dirname,
18+
},
19+
},
20+
},
21+
{
22+
files,
23+
rules: {
24+
"@typescript-eslint/switch-exhaustiveness-check": "error",
25+
"@typescript-eslint/no-non-null-assertion": "error",
26+
},
27+
},
28+
// Ignore features specific to TypeScript resolved rules
29+
tseslint.config({
30+
// TODO: Configure tests and scripts to work with this.
31+
ignores: ["eslint.config.js", "jest.config.js", "tests/**/*.ts", "scripts/**/*.ts"],
32+
}),
33+
globalIgnores(["node_modules", "dist", "src/common/atlas/openapi.d.ts"]),
1134
eslintConfigPrettier,
12-
globalIgnores(["node_modules", "dist"]),
1335
]);

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
"prepare": "npm run build",
2020
"build:clean": "rm -rf dist",
2121
"build:compile": "tsc",
22-
"build:addshebang": "echo '#!/usr/bin/env node' > dist/index2.js && cat dist/index.js >> dist/index2.js && mv dist/index2.js dist/index.js",
2322
"build:chmod": "chmod +x dist/index.js",
24-
"build": "npm run build:clean && npm run build:compile && npm run build:addshebang && npm run build:chmod",
23+
"build": "npm run build:clean && npm run build:compile && npm run build:chmod",
2524
"inspect": "npm run build && mcp-inspector -- dist/index.js",
2625
"prettier": "prettier",
2726
"check": "npm run build && npm run check:lint && npm run check:format",
@@ -38,6 +37,7 @@
3837
"@modelcontextprotocol/inspector": "^0.8.2",
3938
"@modelcontextprotocol/sdk": "^1.8.0",
4039
"@redocly/cli": "^1.34.2",
40+
"@types/express": "^5.0.1",
4141
"@types/jest": "^29.5.14",
4242
"@types/node": "^22.14.0",
4343
"@types/simple-oauth2": "^5.0.7",
@@ -60,7 +60,6 @@
6060
"dependencies": {
6161
"@mongodb-js/devtools-connect": "^3.7.2",
6262
"@mongosh/service-provider-node-driver": "^3.6.0",
63-
"@types/express": "^5.0.1",
6463
"bson": "^6.10.3",
6564
"mongodb": "^6.15.0",
6665
"mongodb-log-writer": "^2.4.1",

src/common/atlas/apiClient.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,29 @@ export class ApiClient {
3535
return this.accessToken?.token.access_token as string | undefined;
3636
};
3737

38-
private authMiddleware = (apiClient: ApiClient): Middleware => ({
39-
async onRequest({ request, schemaPath }) {
38+
private authMiddleware: Middleware = {
39+
onRequest: async ({ request, schemaPath }) => {
4040
if (schemaPath.startsWith("/api/private/unauth") || schemaPath.startsWith("/api/oauth")) {
4141
return undefined;
4242
}
4343

4444
try {
45-
const accessToken = await apiClient.getAccessToken();
45+
const accessToken = await this.getAccessToken();
4646
request.headers.set("Authorization", `Bearer ${accessToken}`);
4747
return request;
4848
} catch {
4949
// ignore not availble tokens, API will return 401
5050
}
5151
},
52-
});
53-
private errorMiddleware = (): Middleware => ({
52+
};
53+
54+
private readonly errorMiddleware: Middleware = {
5455
async onResponse({ response }) {
5556
if (!response.ok) {
5657
throw await ApiClientError.fromResponse(response);
5758
}
5859
},
59-
});
60+
};
6061

6162
constructor(options?: ApiClientOptions) {
6263
this.options = {
@@ -85,12 +86,14 @@ export class ApiClient {
8586
tokenPath: "/api/oauth/token",
8687
},
8788
});
88-
this.client.use(this.authMiddleware(this));
89+
this.client.use(this.authMiddleware);
8990
}
90-
this.client.use(this.errorMiddleware());
91+
this.client.use(this.errorMiddleware);
9192
}
9293

93-
async getIpInfo() {
94+
public async getIpInfo(): Promise<{
95+
currentIpv4Address: string;
96+
}> {
9497
const accessToken = await this.getAccessToken();
9598

9699
const endpoint = "api/private/ipinfo";
@@ -108,10 +111,9 @@ export class ApiClient {
108111
throw await ApiClientError.fromResponse(response);
109112
}
110113

111-
const responseBody = await response.json();
112-
return responseBody as {
114+
return (await response.json()) as Promise<{
113115
currentIpv4Address: string;
114-
};
116+
}>;
115117
}
116118

117119
// DO NOT EDIT. This is auto-generated code.

src/common/atlas/apiClientError.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export class ApiClientError extends Error {
77
this.response = response;
88
}
99

10-
static async fromResponse(response: Response, message: string = `error calling Atlas API`): Promise<ApiClientError> {
10+
static async fromResponse(
11+
response: Response,
12+
message: string = `error calling Atlas API`
13+
): Promise<ApiClientError> {
1114
try {
1215
const text = await response.text();
1316
return new ApiClientError(`${message}: [${response.status} ${response.statusText}] ${text}`, response);

0 commit comments

Comments
 (0)