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

refactor: better define the api bounderies of the module #32

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b973057
refactor: better define the api bounderies of the module
drazisil Jul 26, 2024
1d8ecbe
refactor: Add customerId property to User model and AuthLogin service
drazisil Jul 26, 2024
c592226
refactor: Add customerId property to User model and AuthLogin service
drazisil Jul 26, 2024
eb1d377
feat: add config lib
drazisil Jul 26, 2024
8ef3e2e
refactor: remove unneeded complexity
drazisil Jul 26, 2024
73809f8
refactor: Remove unused script for injecting token
drazisil Jul 26, 2024
2b5d438
test: add comment explaining why 200 is the expected response code fo…
drazisil Jul 26, 2024
fcbc2c2
refactor: Remove nx.json from .gitignore
drazisil Jul 26, 2024
135028b
refactor: Add unit tests for extractCredentials and validateCredentia…
drazisil Jul 27, 2024
015bf0f
refactor: Add .github/codecov.yml for component management
drazisil Jul 27, 2024
2967c17
refactor: Update CI workflow to distribute test runs and upload cover…
drazisil Jul 27, 2024
289d76d
refactor: Update .github/codecov.yml for comment layout and visibility
drazisil Jul 27, 2024
0c6443e
refactor: Update .github/codecov.yml to show project coverage
drazisil Jul 27, 2024
7c5b372
refactor: Update log.debug statement in processWebRequests
drazisil Jul 27, 2024
7622867
refactor: Simplify processWebRequests error handling
drazisil Jul 27, 2024
3a5f229
fix(ci): change with to env
drazisil Jul 31, 2024
f7acc94
Drazisil/issue39 (#40)
drazisil Aug 1, 2024
5117f9b
Create pipeline to run full tests on main and development branches (#43)
drazisil Aug 1, 2024
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
34 changes: 34 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
component_management:
default_rules:
statuses:
- type: project
target: auto
- type: patch
target: auto
individual_components:
- component_id: server
name: Server
paths:
- "apps/server/src/**"
- component_id: config
name: Config
paths:
- libs/config/src/**
- component_id: web
name: Web
paths:
- libs/web/src/**
- component_id: utils
name: Utils
paths:
- libs/util/src/**
- component_id: all_tests
name: All Tests
paths:
- "apps/*/test/**"
- "libs/*/test/**"

Comment on lines +1 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Verify the specified paths for components.

The following paths do not exist in the codebase and need to be verified:

  • apps/*/test
  • libs/*/test

Please ensure these paths are correct or update the configuration accordingly.

Analysis chain

Verify the specified paths for components.

Ensure that the specified paths for the components exist in the codebase.


Let's re-verify the existence of the specified paths using the correct fd command with the --full-path option.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of specified paths in the Codecov configuration.

# Search for the existence of the specified paths. Expect: All specified paths should exist.
fd --type d 'apps/server/src' && fd --type d 'libs/config/src' && fd --type d 'libs/web/src' && fd --type d 'libs/util/src' && fd --type d 'apps/*/test' && fd --type d 'libs/*/test'

Length of output: 395


Script:

#!/bin/bash
# Description: Verify the existence of specified paths in the Codecov configuration using the correct fd command.

# Search for the existence of the specified paths. Expect: All specified paths should exist.
fd --type d --full-path 'apps/server/src' && fd --type d --full-path 'libs/config/src' && fd --type d --full-path 'libs/web/src' && fd --type d --full-path 'libs/util/src' && fd --type d --full-path 'apps/*/test' && fd --type d --full-path 'libs/*/test'

Length of output: 374

comment:
layout: diff, flags, components, files, header, footer
hide_project_coverage: false
show_carryforward_flags: true
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ permissions:
actions: read
contents: read


jobs:
main:
runs-on: ubuntu-22.04
Expand All @@ -25,8 +24,9 @@ jobs:
# Run this command as early as possible, before dependencies are installed
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
# Connect your workspace by running "nx connect" and uncomment this
# - run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build"

- run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build"
env:
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
# Cache node_modules
- uses: actions/setup-node@v3
with:
Expand All @@ -35,19 +35,21 @@ jobs:

- run: pnpm install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

env:
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: pnpm exec nx-cloud record -- echo Hello World
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
- run: make test
env:
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
run: make codecov
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ node_modules
coverage
*.xml

# tell Git to ignore/stop ignoring this file
#$ git update-index --assume-unchanged <file-to-ignore>
#$ git update-index --no-assume-unchanged <file-to-ignore>
# Credit: https://web.archive.org/web/20240726013834/https://practicalgit.com/blog/make-git-ignore-local-changes-to-tracked-files.html
nx.json
.env
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
test:
./scripts/inject-token.sh
pnpm exec nx affected -t lint build test
pnpm exec nx affected -t lint test build

@PHONY: test
codecov_install:
pip install codecov-cli

codecov: codecov_install
codecovcli --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n Server -F Server -f apps/server/coverage/lcov.info
codecovcli --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n Config -F Config -f libs/config/coverage/lcov.info
codecovcli --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n Utils -F Utils -f libs/utils/coverage/lcov.info
drazisil marked this conversation as resolved.
Show resolved Hide resolved
codecovcli --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n Web -F Web -f libs/web/coverage/lcov.info

codecov_local:
codecovcli --verbose upload-process --fail-on-error -n Server -F Server -f apps/server/coverage/lcov.info
codecovcli --verbose upload-process --fail-on-error -n Config -F Config -f libs/config/coverage/lcov.info
codecovcli --verbose upload-process --fail-on-error -n Utils -F Utils -f libs/utils/coverage/lcov.info
Comment on lines +16 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure coverage files exist for local uploads.

The specified coverage files for local uploads do not exist:

  • apps/server/coverage/lcov.info
  • libs/config/coverage/lcov.info
  • libs/utils/coverage/lcov.info
  • libs/web/coverage/lcov.info

Please verify the presence of these files or ensure they are generated correctly.

Analysis chain

Ensure coverage files exist for local uploads.

Verify that the specified coverage files exist for all components in local uploads.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the coverage files specified in the `codecov_local` target exist.

# Test: Check for the existence of the coverage files. Expect: All specified coverage files should exist.
fd --type f 'apps/server/coverage/lcov.info' && fd --type f 'libs/config/coverage/lcov.info' && fd --type f 'libs/utils/coverage/lcov.info' && fd --type f 'libs/web/coverage/lcov.info'

Length of output: 175


Script:

#!/bin/bash
# Description: Verify that the coverage files specified in the `codecov_local` target exist.

# Check for the existence of each coverage file and provide detailed output.
echo "Checking apps/server/coverage/lcov.info"
fd --type f 'apps/server/coverage/lcov.info' || echo "File not found: apps/server/coverage/lcov.info"

echo "Checking libs/config/coverage/lcov.info"
fd --type f 'libs/config/coverage/lcov.info' || echo "File not found: libs/config/coverage/lcov.info"

echo "Checking libs/utils/coverage/lcov.info"
fd --type f 'libs/utils/coverage/lcov.info' || echo "File not found: libs/utils/coverage/lcov.info"

echo "Checking libs/web/coverage/lcov.info"
fd --type f 'libs/web/coverage/lcov.info' || echo "File not found: libs/web/coverage/lcov.info"

Length of output: 523

codecovcli --verbose upload-process --fail-on-error -n Web -F Web -f libs/web/coverage/lcov.info


@PHONY: test codecov_install codecov
2 changes: 2 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NX_CLOUD_AUTH_TOKEN=
SENTRY_DSN=
7 changes: 5 additions & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "tsc --build --verbose",
"check-types": "tsc --noEmit",
"lint": "eslint src",
"start": "node dist/src/index.js",
"prestart": "nx run @rusty/server:build",
"start": "node --env-file .env dist/src/index.js",
drazisil marked this conversation as resolved.
Show resolved Hide resolved
"test": "vitest",
"dev": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' --watch src/index.ts"
},
Expand All @@ -30,6 +31,8 @@
},
"dependencies": {
"@rusty/util": "workspace:*",
"@rusty/web": "workspace:*"
"@rusty/web": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0"
}
}
4 changes: 2 additions & 2 deletions apps/server/src/ServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { WrappedServer } from "./WrappedServer.js";
import { exit } from "node:process";
import { log } from "@rusty/util";
import { handleWebRequests } from "@rusty/web";
import { processWebRequests } from "@rusty/web";

Check warning on line 7 in apps/server/src/ServerController.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/ServerController.ts#L7

Added line #L7 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure handleWebRequests is completely removed from the codebase.

The import processWebRequests has been correctly added and used, but handleWebRequests is still present in libs/web/src/index.ts. Please remove all occurrences of handleWebRequests.

  • libs/web/src/index.ts: log.debug("web.handleWebRequests");
Analysis chain

Verify the usage of the new import and ensure the old import is removed.

The processWebRequests import replaces handleWebRequests. Ensure that the new import is used correctly and that the old import is completely removed from the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurances of `processWebRequests`.
rg --type python -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurances of `handleWebRequests`.
rg --type python -A 5 $'handleWebRequests'

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurrences of `processWebRequests`.
rg --type typescript -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurrences of `handleWebRequests`.
rg --type typescript -A 5 $'handleWebRequests'

Length of output: 162


Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurrences of `processWebRequests`.
rg -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurrences of `handleWebRequests`.
rg -A 5 $'handleWebRequests'

Length of output: 1781

Tools
GitHub Check: codecov/patch

[warning] 7-7: apps/server/src/ServerController.ts#L7
Added line #L7 was not covered by tests

import { headersToRecords } from "./headersToRecords.js";

/**
Expand All @@ -16,7 +16,7 @@
req: import("node:http").IncomingMessage,
res: import("node:http").ServerResponse
) {
const response = await handleWebRequests({
const response = await processWebRequests({

Check warning on line 19 in apps/server/src/ServerController.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/ServerController.ts#L19

Added line #L19 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
headers: headersToRecords(req.headers),
remoteAddress: req.socket.remoteAddress || "",
method: req.method || "",
Expand Down
27 changes: 25 additions & 2 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
// IMPORTANT: Make sure to import `instrument.js` at the top of your file.
// If you're using ECMAScript Modules (ESM) syntax, use `import "./instrument.js";`
void import ("./instrument.js");

Check warning on line 3 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L3

Added line #L3 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved

// All other imports below
import * as Sentry from "@sentry/node";

Check warning on line 6 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L6

Added line #L6 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
import { ServerController } from "./ServerController.js";

const serverController = new ServerController();
void serverController.start();
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
Sentry.captureException(reason as Error);
process.exit(1);
})

Check warning on line 13 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L9-L13

Added lines #L9 - L13 were not covered by tests
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Consider adding tests for unhandled promise rejections.

The addition of global error handling for unhandled promise rejections enhances the robustness of the application by logging and capturing errors with Sentry.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 9-13: apps/server/src/index.ts#L9-L13
Added lines #L9 - L13 were not covered by tests


process.on("uncaughtException", (error) => {
console.error("Uncaught Exception thrown", error);
Sentry.captureException(error);
process.exit(1);
})

Check warning on line 19 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L15-L19

Added lines #L15 - L19 were not covered by tests
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Consider adding tests for uncaught exceptions.

The addition of global error handling for uncaught exceptions enhances the robustness of the application by logging and capturing errors with Sentry.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 15-19: apps/server/src/index.ts#L15-L19
Added lines #L15 - L19 were not covered by tests


function main() {
const serverController = new ServerController();
void serverController.start();
}

Check warning on line 24 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L21-L24

Added lines #L21 - L24 were not covered by tests
Comment on lines +21 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! Consider adding tests for the main function.

Encapsulating the server startup logic within a main function improves the organization of the code and provides a clear entry point for the application.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 21-24: apps/server/src/index.ts#L21-L24
Added lines #L21 - L24 were not covered by tests


main();

Check warning on line 26 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L26

Added line #L26 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for the invocation of the main function.

The invocation of the main function is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 26-26: apps/server/src/index.ts#L26
Added line #L26 was not covered by tests


18 changes: 18 additions & 0 deletions apps/server/src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Import with `import * as Sentry from "@sentry/node"` if you are using ESM
drazisil marked this conversation as resolved.
Show resolved Hide resolved
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

Check warning on line 3 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L2-L3

Added lines #L2 - L3 were not covered by tests

if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
console.error("No SENTRY_DSN provided");
process.exit(1);
}

Check warning on line 8 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L5-L8

Added lines #L5 - L8 were not covered by tests
Comment on lines +5 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve DSN validation.

The current DSN validation only checks for undefined or empty values. Consider using a more robust validation method to ensure the DSN is a valid URL.

- if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
+ const isValidUrl = (url) => {
+   try {
+     new URL(url);
+     return true;
+   } catch (_) {
+     return false;
+   }
+ };
+ 
+ if (!isValidUrl(process.env.SENTRY_DSN)) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
console.error("No SENTRY_DSN provided");
process.exit(1);
}
const isValidUrl = (url) => {
try {
new URL(url);
return true;
} catch (_) {
return false;
}
};
if (!isValidUrl(process.env.SENTRY_DSN)) {
console.error("No SENTRY_DSN provided");
process.exit(1);
}
Tools
GitHub Check: codecov/patch

[warning] 5-8: apps/server/src/instrument.ts#L5-L8
Added lines #L5 - L8 were not covered by tests


Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [nodeProfilingIntegration()],

Check warning on line 12 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L10-L12

Added lines #L10 - L12 were not covered by tests
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions

Check warning on line 14 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L14

Added line #L14 was not covered by tests

// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
});

Check warning on line 18 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions libs/config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ["eslint.config.js", "vitest.config.js", "**/*.d.ts"],
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/coverage/*", "**/dist/*"],
}
);
1 change: 1 addition & 0 deletions libs/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getServerURL } from "./src/index.js";
42 changes: 42 additions & 0 deletions libs/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@rusty/config",
"version": "1.0.0",
"private": true,
"type": "module",
"imports": {
"#internal": "./dist/src/index.js"
},
"exports": {
".": "./dist/index.js"
},
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "eslint src"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"pino": "9.3.1"
}
}
4 changes: 4 additions & 0 deletions libs/config/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function getServerURL(): string {
const serverURL = process.env.SERVER_URL ?? "https://rusty-motors.com";
return serverURL;
}

Check warning on line 4 in libs/config/src/config.ts

View check run for this annotation

Codecov / codecov/patch

libs/config/src/config.ts#L2-L4

Added lines #L2 - L4 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions libs/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getServerURL } from "./config.js";
24 changes: 24 additions & 0 deletions libs/config/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type rawHttpRequestData = {
headers: Record<string, string>;
remoteAddress: string;
method: string;
url: string;
};

export type parsedHttpRequestData = {
headers: Record<string, string>;
remoteAddress: string;
method: string;
pathname: string;
searchParams: URLSearchParams;
};
export type RequestResponse = {
statusCode: number;
body: string;
headers: Record<string, string>;
};

export type User = {
username: string;
password: string;
};
13 changes: 13 additions & 0 deletions libs/config/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from "vitest";
import { getServerURL } from "@rusty/config";

describe("config", () => {
it("should have a default serverURL if SERVER_URL environment variable is not set", () => {
expect(getServerURL()).toBe("https://rusty-motors.com");
});

it("should use the SERVER_URL environment variable if set", () => {
process.env.SERVER_URL = "https://example.com";
expect(getServerURL()).toBe("https://example.com");
});
});
11 changes: 11 additions & 0 deletions libs/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declarationDir": "./dist",
"composite": true
},
"include": ["index.ts", "src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist"],
"references": [{ "path": "../util" }]
}
20 changes: 20 additions & 0 deletions libs/config/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
all: true,
exclude: [
"dist/**",
"eslint.config.js",
"vitest.config.js"
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
2 changes: 2 additions & 0 deletions libs/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"vitest": "^2.0.4"
},
"dependencies": {
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"pino": "9.3.1"
}
}
5 changes: 4 additions & 1 deletion libs/web/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { handleWebRequests } from "./src/index.js";
/**
* External exports for the web library
*/
export { processWebRequests } from "./src/processors/processWebRequests.js";
6 changes: 6 additions & 0 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.0",
"private": true,
"type": "module",
"imports": {
"#internal": "./dist/src/index.js"
},
"exports": {
".": "./dist/index.js"
},
Expand Down Expand Up @@ -32,6 +35,9 @@
},
"dependencies": {
"@rusty/util": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"@rusty/config": "workspace:*",
"pino": "9.3.1",
"sequelize": "6.37.3",
"sqlite3": "5.1.7"
Expand Down
Loading