Deep Wiki
Deep Wiki generates rich, developer-grade documentation for any function, class, module, or system in your codebase. It doesn't just describe what code does it explains when and why to use it, what
Last updated
Use OrderService.create() when creating an order from a user-facing flow (checkout,
subscription renewal, admin order entry). Don't use it for programmatic test data
setup use OrderFactory from tests/support/factories.ts instead, which skips
payment processing and email sending.Best results: call recalculateTotals() after any mutation to the order's line items.
If you're making multiple mutations, batch them and call recalculateTotals() once at
the end — it's expensive and doesn't need to run after each change.Edge cases:
- If quantity is 0, the item is removed from the order rather than kept with a zero quantity.
- If all items are removed, the order is cancelled automatically, not left as an empty order.
- Applying a discount code that's already applied is a no-op, not an error.Input: @SessionManager.refresh "Generate a Deep Wiki entry."
Output:
## SessionManager.refresh(sessionId: string, userId: number): Promise<Session>
### Overview
Refreshes an existing session, extending its TTL and returning the updated Session
object. Called automatically by the auth middleware on authenticated requests.
### When to use it
Use this when you need to explicitly extend a session outside of a normal request
cycle — for example, during a long-running background job initiated by a user action.
Don't call this directly in request handlers; the middleware handles it automatically
for all authenticated routes.
### Parameters
- sessionId — the session token string from the user's cookie or Authorization header.
Must be a valid session that exists in Redis. Throws SessionNotFoundError if absent.
- userId — the ID of the user the session belongs to. Used to verify the session
belongs to the correct user before refreshing. Throws SessionMismatchError if it
doesn't match.
### Returns
The updated Session object with the new expiresAt timestamp.
### Throws
- SessionNotFoundError — the sessionId doesn't exist in Redis (expired or never existed)
- SessionMismatchError — the session exists but belongs to a different userId
- StorageError — Redis is unavailable
### Best-case usage notes
The TTL on refresh is controlled by SESSION_TTL_SECONDS in config/auth.ts.
If you need to refresh with a non-standard TTL (e.g., "remember me" sessions),
use SessionManager.refreshWithTTL() instead.
### Known edge cases
- Calling refresh on a session that expires within the next 5 seconds may result in
a SessionNotFoundError, because Redis may have already evicted it by the time the
write completes.
- If Redis is in readonly mode during a failover, refresh will throw StorageError
but the auth middleware will still allow the request to proceed (fail-open behavior).
### Related
- SessionManager.create() — creates a new session
- SessionManager.invalidate() — terminates a session
- AuthMiddleware.verify() — the main caller in request flows@src/services/ "Generate a Deep Wiki overview of the services layer."