Skip to content

Commit 136ad40

Browse files
committed
feat: add attachment count to notes list and enhance monitoring
- Add attachmentCount field to GET /api/notes response for efficient UI rendering - Create NoteWithAttachmentCount type for improved type safety - Integrate New Relic APM monitoring for observability - Increase free tier note limit from 100 to 1000 notes
1 parent f10271c commit 136ad40

File tree

8 files changed

+1182
-13
lines changed

8 files changed

+1182
-13
lines changed

newrelic.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict'
2+
3+
/**
4+
* New Relic agent configuration.
5+
*/
6+
exports.config = {
7+
app_name: [process.env.NEW_RELIC_APP_NAME || 'Typelets API'],
8+
license_key: process.env.NEW_RELIC_LICENSE_KEY || '',
9+
logging: {
10+
level: process.env.NEW_RELIC_LOG_LEVEL || 'info',
11+
filepath: 'stdout'
12+
},
13+
application_logging: {
14+
forwarding: {
15+
enabled: true
16+
}
17+
},
18+
allow_all_headers: true,
19+
attributes: {
20+
exclude: [
21+
'request.headers.cookie',
22+
'request.headers.authorization',
23+
'request.headers.proxyAuthorization',
24+
'request.headers.setCookie*',
25+
'request.headers.x*',
26+
'response.headers.cookie',
27+
'response.headers.authorization',
28+
'response.headers.proxyAuthorization',
29+
'response.headers.setCookie*',
30+
'response.headers.x*'
31+
]
32+
}
33+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"hono": "^4.8.3",
4848
"postgres": "^3.4.7",
4949
"ws": "^8.18.3",
50-
"zod": "^3.25.67"
50+
"zod": "^3.25.67",
51+
"newrelic": "latest"
5152
},
5253
"devDependencies": {
5354
"@semantic-release/changelog": "^6.0.3",
@@ -76,4 +77,4 @@
7677
"pnpm": ">=9.15.0"
7778
},
7879
"packageManager": "pnpm@9.15.0"
79-
}
80+
}

pnpm-lock.yaml

Lines changed: 1124 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/middleware/usage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { HTTPException } from "hono/http-exception";
88

99
export const checkNoteLimits = async (c: Context, next: Next) => {
1010
const userId = c.get("userId");
11-
12-
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 100;
11+
12+
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 1000;
1313

1414
const { db, notes } = await import("../db");
1515
const { eq, and, count, isNull, or } = await import("drizzle-orm");
@@ -99,9 +99,9 @@ export const checkStorageLimits = (expectedFileSizeBytes: number) => {
9999
*/
100100
export const checkUsageLimits = async (c: Context, next: Next) => {
101101
const userId = c.get("userId");
102-
102+
103103
const FREE_TIER_STORAGE_GB = process.env.FREE_TIER_STORAGE_GB ? parseFloat(process.env.FREE_TIER_STORAGE_GB) : 1;
104-
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 100;
104+
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 1000;
105105

106106
const { db, fileAttachments, notes } = await import("../db");
107107
const { eq, and, sum, count, isNull, or } = await import("drizzle-orm");

src/routes/notes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ notesRouter.get("/", zValidator("query", notesQuerySchema), async (c) => {
6868
offset,
6969
with: {
7070
folder: true,
71+
attachments: true,
7172
},
7273
});
7374

75+
// Add attachmentCount to each note and remove full attachments array
76+
const notesWithAttachmentCount = userNotes.map(note => ({
77+
...note,
78+
attachmentCount: note.attachments.length,
79+
attachments: undefined,
80+
}));
81+
7482
return c.json({
75-
notes: userNotes,
83+
notes: notesWithAttachmentCount,
7684
pagination: {
7785
page: query.page,
7886
limit: query.limit,

src/routes/users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ usersRouter.get("/me", async (c) => {
1212
}
1313

1414
const FREE_TIER_STORAGE_GB = process.env.FREE_TIER_STORAGE_GB ? parseFloat(process.env.FREE_TIER_STORAGE_GB) : 1;
15-
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 100;
15+
const FREE_TIER_NOTE_LIMIT = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 1000;
1616

1717
const { db, fileAttachments, notes } = await import("../db");
1818
const { eq, and, sum, count, isNull, or } = await import("drizzle-orm");

src/server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/// <reference lib="dom" />
1+
require('newrelic');
22

3-
// Load environment variables
43
import "dotenv-flow/config";
54

65
const isDevelopment = process.env.NODE_ENV === 'development';
@@ -268,7 +267,7 @@ app.notFound((c) => {
268267
const port = Number(process.env.PORT) || 3000;
269268

270269
const freeStorageGB = process.env.FREE_TIER_STORAGE_GB ? parseFloat(process.env.FREE_TIER_STORAGE_GB) : 1;
271-
const freeNoteLimit = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 100;
270+
const freeNoteLimit = process.env.FREE_TIER_NOTE_LIMIT ? parseInt(process.env.FREE_TIER_NOTE_LIMIT) : 1000;
272271

273272

274273
logger.info("Typelets API server starting", {

src/types/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export interface UserUpdateData {
4646
lastName?: string | null;
4747
}
4848

49+
// Note with attachment count for list responses
50+
export type NoteWithAttachmentCount = Omit<Note, 'attachments'> & {
51+
attachmentCount: number;
52+
folder?: Folder | null;
53+
};
54+
4955
export type {
5056
User,
5157
UserInsert,

0 commit comments

Comments
 (0)