@adaptic/backend-legacy 0.0.983 → 0.0.985

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/esm/health.d.ts CHANGED
@@ -1,16 +1,19 @@
1
1
  import { Router } from 'express';
2
2
  /**
3
- * Creates an Express router with a GET /health endpoint.
3
+ * Creates an Express router with health-probe endpoints.
4
4
  *
5
- * The endpoint returns HTTP 200 when healthy (database reachable)
6
- * and HTTP 503 when degraded (database unreachable).
5
+ * - `GET /livez` — Process-only liveness check. Always returns HTTP 200 with
6
+ * `{ status, service, version, uptime }`. Safe for Cloud Run / Kubernetes
7
+ * liveness probes since it never touches the database.
8
+ * - `GET /readyz` — Readiness check. Returns HTTP 200 only when the database
9
+ * is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
10
+ * startup probes and load-balancer readiness.
11
+ * - `GET /health` — Full health snapshot including memory usage and database
12
+ * status. Returns 503 when the database is unreachable. Kept for
13
+ * backward compatibility with existing Railway/uptime checks.
7
14
  *
8
- * Response includes: service name, version, uptime in seconds,
9
- * memory usage (RSS, heap used, heap total in MB), database status,
10
- * and an ISO 8601 timestamp.
11
- *
12
- * This endpoint should be mounted before auth middleware so it
13
- * remains accessible without authentication.
15
+ * All endpoints should be mounted before auth middleware so they remain
16
+ * accessible without authentication.
14
17
  */
15
18
  export declare function createHealthRouter(): Router;
16
19
  //# sourceMappingURL=health.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAuDpD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CA4B3C"}
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAuDpD;;;;;;;;;;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AI,CAAC;YACnD,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;gBAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;gBACxD,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;aAC3D;YACD,QAAQ,EAAE,cAAc;SACzB,CAAC;QAEF,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/esm/health.mjs CHANGED
@@ -35,20 +35,43 @@ async function checkDatabase() {
35
35
  }
36
36
  }
37
37
  /**
38
- * Creates an Express router with a GET /health endpoint.
38
+ * Creates an Express router with health-probe endpoints.
39
39
  *
40
- * The endpoint returns HTTP 200 when healthy (database reachable)
41
- * and HTTP 503 when degraded (database unreachable).
40
+ * - `GET /livez` — Process-only liveness check. Always returns HTTP 200 with
41
+ * `{ status, service, version, uptime }`. Safe for Cloud Run / Kubernetes
42
+ * liveness probes since it never touches the database.
43
+ * - `GET /readyz` — Readiness check. Returns HTTP 200 only when the database
44
+ * is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
45
+ * startup probes and load-balancer readiness.
46
+ * - `GET /health` — Full health snapshot including memory usage and database
47
+ * status. Returns 503 when the database is unreachable. Kept for
48
+ * backward compatibility with existing Railway/uptime checks.
42
49
  *
43
- * Response includes: service name, version, uptime in seconds,
44
- * memory usage (RSS, heap used, heap total in MB), database status,
45
- * and an ISO 8601 timestamp.
46
- *
47
- * This endpoint should be mounted before auth middleware so it
48
- * remains accessible without authentication.
50
+ * All endpoints should be mounted before auth middleware so they remain
51
+ * accessible without authentication.
49
52
  */
50
53
  export function createHealthRouter() {
51
54
  const router = Router();
55
+ router.get('/livez', (_req, res) => {
56
+ res.status(200).json({
57
+ status: 'ok',
58
+ service: SERVICE_NAME,
59
+ version: PACKAGE_VERSION,
60
+ timestamp: new Date().toISOString(),
61
+ uptime: Math.floor((Date.now() - startedAt) / 1000),
62
+ });
63
+ });
64
+ router.get('/readyz', async (_req, res) => {
65
+ const databaseStatus = await checkDatabase();
66
+ const isReady = databaseStatus === 'connected';
67
+ res.status(isReady ? 200 : 503).json({
68
+ status: isReady ? 'ready' : 'not-ready',
69
+ service: SERVICE_NAME,
70
+ version: PACKAGE_VERSION,
71
+ database: databaseStatus,
72
+ timestamp: new Date().toISOString(),
73
+ });
74
+ });
52
75
  router.get('/health', async (_req, res) => {
53
76
  const databaseStatus = await checkDatabase();
54
77
  const isHealthy = databaseStatus === 'connected';
package/health.cjs CHANGED
@@ -41,20 +41,43 @@ async function checkDatabase() {
41
41
  }
42
42
  }
43
43
  /**
44
- * Creates an Express router with a GET /health endpoint.
44
+ * Creates an Express router with health-probe endpoints.
45
45
  *
46
- * The endpoint returns HTTP 200 when healthy (database reachable)
47
- * and HTTP 503 when degraded (database unreachable).
46
+ * - `GET /livez` — Process-only liveness check. Always returns HTTP 200 with
47
+ * `{ status, service, version, uptime }`. Safe for Cloud Run / Kubernetes
48
+ * liveness probes since it never touches the database.
49
+ * - `GET /readyz` — Readiness check. Returns HTTP 200 only when the database
50
+ * is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
51
+ * startup probes and load-balancer readiness.
52
+ * - `GET /health` — Full health snapshot including memory usage and database
53
+ * status. Returns 503 when the database is unreachable. Kept for
54
+ * backward compatibility with existing Railway/uptime checks.
48
55
  *
49
- * Response includes: service name, version, uptime in seconds,
50
- * memory usage (RSS, heap used, heap total in MB), database status,
51
- * and an ISO 8601 timestamp.
52
- *
53
- * This endpoint should be mounted before auth middleware so it
54
- * remains accessible without authentication.
56
+ * All endpoints should be mounted before auth middleware so they remain
57
+ * accessible without authentication.
55
58
  */
56
59
  function createHealthRouter() {
57
60
  const router = (0, express_1.Router)();
61
+ router.get('/livez', (_req, res) => {
62
+ res.status(200).json({
63
+ status: 'ok',
64
+ service: SERVICE_NAME,
65
+ version: PACKAGE_VERSION,
66
+ timestamp: new Date().toISOString(),
67
+ uptime: Math.floor((Date.now() - startedAt) / 1000),
68
+ });
69
+ });
70
+ router.get('/readyz', async (_req, res) => {
71
+ const databaseStatus = await checkDatabase();
72
+ const isReady = databaseStatus === 'connected';
73
+ res.status(isReady ? 200 : 503).json({
74
+ status: isReady ? 'ready' : 'not-ready',
75
+ service: SERVICE_NAME,
76
+ version: PACKAGE_VERSION,
77
+ database: databaseStatus,
78
+ timestamp: new Date().toISOString(),
79
+ });
80
+ });
58
81
  router.get('/health', async (_req, res) => {
59
82
  const databaseStatus = await checkDatabase();
60
83
  const isHealthy = databaseStatus === 'connected';
package/health.d.ts CHANGED
@@ -1,16 +1,19 @@
1
1
  import { Router } from 'express';
2
2
  /**
3
- * Creates an Express router with a GET /health endpoint.
3
+ * Creates an Express router with health-probe endpoints.
4
4
  *
5
- * The endpoint returns HTTP 200 when healthy (database reachable)
6
- * and HTTP 503 when degraded (database unreachable).
5
+ * - `GET /livez` — Process-only liveness check. Always returns HTTP 200 with
6
+ * `{ status, service, version, uptime }`. Safe for Cloud Run / Kubernetes
7
+ * liveness probes since it never touches the database.
8
+ * - `GET /readyz` — Readiness check. Returns HTTP 200 only when the database
9
+ * is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
10
+ * startup probes and load-balancer readiness.
11
+ * - `GET /health` — Full health snapshot including memory usage and database
12
+ * status. Returns 503 when the database is unreachable. Kept for
13
+ * backward compatibility with existing Railway/uptime checks.
7
14
  *
8
- * Response includes: service name, version, uptime in seconds,
9
- * memory usage (RSS, heap used, heap total in MB), database status,
10
- * and an ISO 8601 timestamp.
11
- *
12
- * This endpoint should be mounted before auth middleware so it
13
- * remains accessible without authentication.
15
+ * All endpoints should be mounted before auth middleware so they remain
16
+ * accessible without authentication.
14
17
  */
15
18
  export declare function createHealthRouter(): Router;
16
19
  //# sourceMappingURL=health.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptic/backend-legacy",
3
- "version": "0.0.983",
3
+ "version": "0.0.985",
4
4
  "description": "Backend executable CRUD functions with dynamic variables construction, and type definitions for the Adaptic AI platform.",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",
package/server.cjs CHANGED
@@ -57,7 +57,6 @@ const audit_logger_1 = require("./middleware/audit-logger.cjs");
57
57
  const http_status_mapper_1 = require("./plugins/http-status-mapper.cjs");
58
58
  const prismaClient_1 = __importStar(require("./prismaClient.cjs"));
59
59
  const health_1 = require("./health.cjs");
60
- const child_process_1 = require("child_process");
61
60
  const logger_1 = require("./utils/logger.cjs");
62
61
  const tracing_1 = require("./config/tracing.cjs");
63
62
  const token_verifier_1 = require("./auth/token-verifier.cjs");
@@ -91,36 +90,6 @@ function principalToUser(principal) {
91
90
  };
92
91
  }
93
92
  }
94
- let dbUnreachableCount = 0;
95
- let lastRestartAttempt = 0;
96
- async function restartDatabase() {
97
- return new Promise((resolve, reject) => {
98
- logger_1.logger.info('Attempting to redeploy the Railway Postgres service in production');
99
- // Check for both types of tokens
100
- const projectToken = process.env.RAILWAY_TOKEN;
101
- const apiToken = process.env.RAILWAY_API_TOKEN;
102
- if (!projectToken && !apiToken) {
103
- return reject(new Error('Neither RAILWAY_TOKEN nor RAILWAY_API_TOKEN found in environment variables'));
104
- }
105
- // Simplified command based on Railway CLI documentation
106
- const deployCommand = `RAILWAY_TOKEN=${projectToken || ''} RAILWAY_API_TOKEN=${apiToken || ''} railway redeploy --service Postgres -y`;
107
- (0, child_process_1.exec)(deployCommand, {
108
- env: process.env,
109
- shell: '/bin/sh',
110
- }, (error, stdout, stderr) => {
111
- if (error) {
112
- logger_1.logger.error('Failed to redeploy DB via Railway CLI', {
113
- error: String(error),
114
- stdout,
115
- stderr,
116
- });
117
- return reject(error);
118
- }
119
- logger_1.logger.info('Railway deployment output', { stdout });
120
- resolve();
121
- });
122
- });
123
- }
124
93
  const startServer = async () => {
125
94
  // Boot-time invariant: in production, `GOOGLE_OAUTH_CLIENT_IDS` must be set.
126
95
  // Without it, no Google ID token can be safely verified — and the verifier
@@ -136,7 +105,7 @@ const startServer = async () => {
136
105
  app.use('/api', (req, res, next) => (0, auth_1.authMiddleware)(req, res, next));
137
106
  const server = new server_1.ApolloServer({
138
107
  schema,
139
- introspection: true,
108
+ introspection: process.env.NODE_ENV !== 'production',
140
109
  plugins: [
141
110
  (0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({ httpServer }),
142
111
  (0, audit_logger_1.createAuditLogPlugin)(),
@@ -167,29 +136,8 @@ const startServer = async () => {
167
136
  else {
168
137
  logger_1.logger.error('GraphQL Error', { graphqlError: err });
169
138
  }
170
- // Check if this error is due to unreachable DB
171
139
  if (message.includes("Can't reach database server")) {
172
- dbUnreachableCount += 1;
173
- logger_1.logger.warn('Database unreachable', { dbUnreachableCount });
174
- // If we've hit 3 (for example) attempts
175
- if (dbUnreachableCount >= 3) {
176
- const now = Date.now();
177
- if (now - lastRestartAttempt > 5 * 60 * 1000) {
178
- lastRestartAttempt = now;
179
- dbUnreachableCount = 0;
180
- restartDatabase().catch((restartError) => {
181
- logger_1.logger.error('Error trying to restart DB', {
182
- restartError: String(restartError),
183
- });
184
- });
185
- }
186
- }
187
- }
188
- else {
189
- // If the error is not a DB unreachable error, we might want
190
- // to reset the counter or leave it as is. Generally, if we see
191
- // a successful query or a different error, we might reset:
192
- dbUnreachableCount = 0;
140
+ logger_1.logger.warn('Database unreachable', { graphqlError: err });
193
141
  }
194
142
  // Surface the verifier's `reason` enum on UNAUTHENTICATED responses so
195
143
  // operators (and the web app's network tab) can diagnose auth failures