@rpcbase/server 0.545.0 → 0.547.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,11 +5,12 @@ import { createClient } from "redis";
5
5
  import { MongoClient } from "mongodb";
6
6
  import env from "@rpcbase/env";
7
7
  import { initApiClient, STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY, RtsSsrRuntimeProvider, SsrErrorFallback, SSR_ERROR_STATE_GLOBAL_KEY, serializeSsrErrorState } from "@rpcbase/client";
8
+ import { getMongoUrl } from "@rpcbase/db/mongo";
8
9
  import { posix, dirname, sep } from "path";
9
10
  import fs, { createReadStream, readFileSync } from "node:fs";
10
11
  import { createInterface } from "node:readline";
11
12
  import { AsyncLocalStorage } from "node:async_hooks";
12
- import { g as getDerivedKey, r as resolveRtsRequestTenantId, i as isRtsRequestAuthorized, b as buildRtsAbilityFromRequest, n as normalizeRtsQueryOptions, a as runRtsQuery, c as runRtsCount } from "./queryExecutor-DTEFEB5Z.js";
13
+ import { g as getDerivedKey, s as syncAuthenticatedSessionMiddleware, r as resolveRtsRequestTenantId, i as isRtsRequestAuthorized, b as buildRtsAbilityFromRequest, n as normalizeRtsQueryOptions, a as runRtsQuery, c as runRtsCount } from "./queryExecutor-Bzs0SJym.js";
13
14
  import httpProxy from "http-proxy-3";
14
15
  import fsPromises from "node:fs/promises";
15
16
  import inspector from "node:inspector";
@@ -3981,26 +3982,17 @@ process.env = {
3981
3982
  };
3982
3983
  const isProduction$1 = process.env.NODE_ENV === "production";
3983
3984
  const SESSION_MAX_AGE_S = 3600 * 24 * 60;
3984
- const getMongoUrl = (serverEnv) => {
3985
- const explicitUrl = serverEnv.MONGODB_URL || serverEnv.MONGO_URL || serverEnv.MONGODB_URI || serverEnv.DB_URL;
3986
- if (explicitUrl) {
3987
- return explicitUrl;
3985
+ const getMongoSessionUrl = (serverEnv) => {
3986
+ const appName = serverEnv.APP_NAME?.trim();
3987
+ if (!appName) {
3988
+ throw new Error("Missing APP_NAME (required to build MongoDB session store DB name)");
3988
3989
  }
3989
- if (serverEnv.DB_PORT) {
3990
- const host = serverEnv.DB_HOST ?? "localhost";
3991
- const appName = serverEnv.APP_NAME?.trim();
3992
- if (!appName) {
3993
- throw new Error("Missing APP_NAME (required to build MongoDB session store DB name)");
3994
- }
3995
- return `mongodb://${host}:${serverEnv.DB_PORT}/${appName}-sessions`;
3996
- }
3997
- return void 0;
3990
+ return getMongoUrl(serverEnv, {
3991
+ dbName: `${appName}-sessions`
3992
+ });
3998
3993
  };
3999
3994
  const createMongoSessionStore = async (serverEnv) => {
4000
- const mongoUrl = getMongoUrl(serverEnv);
4001
- if (!mongoUrl) {
4002
- throw new Error("Missing REDIS_URL and Mongo connection details (MONGODB_URL/MONGO_URL/MONGODB_URI/DB_PORT)");
4003
- }
3995
+ const mongoUrl = getMongoSessionUrl(serverEnv);
4004
3996
  console.log("Using MongoDB session store");
4005
3997
  const client2 = await MongoClient.connect(mongoUrl, {
4006
3998
  family: 4,
@@ -4074,6 +4066,9 @@ const initServer = async (app, serverEnv) => {
4074
4066
  if (!serverEnv.MASTER_KEY) {
4075
4067
  throw new Error("MASTER_KEY must be defined to derive the session secret");
4076
4068
  }
4069
+ if (!serverEnv.RB_PROXY_SHARED_SECRET?.trim()) {
4070
+ throw new Error("RB_PROXY_SHARED_SECRET must be defined");
4071
+ }
4077
4072
  const sessionSecret = getDerivedKey(serverEnv.MASTER_KEY, "express_session_key");
4078
4073
  const redisUrl = serverEnv.REDIS_URL?.trim();
4079
4074
  let store;
@@ -4102,6 +4097,7 @@ const initServer = async (app, serverEnv) => {
4102
4097
  registerDevCoverageEndpoints(app);
4103
4098
  }
4104
4099
  app.use(sessionMiddleware);
4100
+ app.use(syncAuthenticatedSessionMiddleware);
4105
4101
  return {
4106
4102
  sessionMiddleware
4107
4103
  };