@adaptic/backend-legacy 0.0.45 → 0.0.46
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/ABTest.cjs +19 -18
- package/Account.cjs +19 -18
- package/AccountLinkingRequest.cjs +19 -18
- package/Action.cjs +19 -18
- package/Alert.cjs +19 -18
- package/Allocation.cjs +19 -18
- package/AlpacaAccount.cjs +19 -18
- package/AnalyticsConfiguration.cjs +19 -18
- package/AnalyticsSnapshot.cjs +19 -18
- package/Asset.cjs +19 -18
- package/Authenticator.cjs +19 -18
- package/Configuration.cjs +19 -18
- package/ConflictEvent.cjs +19 -18
- package/ConnectionHealthSnapshot.cjs +19 -18
- package/Customer.cjs +19 -18
- package/DeadLetterMessage.cjs +19 -18
- package/EconomicEvent.cjs +19 -18
- package/Event.cjs +19 -18
- package/EventSnapshot.cjs +19 -18
- package/FeatureImportanceAnalysis.cjs +19 -18
- package/InstitutionalFlowSignal.cjs +19 -18
- package/InstitutionalHolding.cjs +19 -18
- package/InstitutionalSentimentAlerts.cjs +19 -18
- package/InstitutionalSentimentErrors.cjs +19 -18
- package/InstitutionalSentimentHistory.cjs +19 -18
- package/InstitutionalSentimentMetrics.cjs +19 -18
- package/InviteToken.cjs +19 -18
- package/LinkedProvider.cjs +19 -18
- package/MLTrainingData.cjs +19 -18
- package/MarketSentiment.cjs +19 -18
- package/ModelArtifact.cjs +19 -18
- package/ModelVersion.cjs +19 -18
- package/ModelVersionArtifact.cjs +19 -18
- package/NewsArticle.cjs +19 -18
- package/NewsArticleAssetSentiment.cjs +19 -18
- package/OptionsContract.cjs +19 -18
- package/OptionsGreeksHistory.cjs +19 -18
- package/OptionsPosition.cjs +19 -18
- package/OptionsTradeExecution.cjs +19 -18
- package/PortfolioGreeksHistory.cjs +19 -18
- package/ScheduledOptionOrder.cjs +19 -18
- package/Session.cjs +19 -18
- package/SignalGeneratorMetrics.cjs +19 -18
- package/SignalLineage.cjs +19 -18
- package/SignalOutcome.cjs +19 -18
- package/SignalPriorityQueue.cjs +19 -18
- package/SyncEvent.cjs +19 -18
- package/SystemAlert.cjs +19 -18
- package/Trade.cjs +19 -18
- package/TradeAuditEvent.cjs +19 -18
- package/TradeExecutionHistory.cjs +19 -18
- package/User.cjs +19 -18
- package/VerificationToken.cjs +19 -18
- package/WaitlistEntry.cjs +19 -18
- package/client.cjs +11 -10
- package/esm/ABTest.d.ts.map +1 -1
- package/esm/ABTest.js.map +1 -1
- package/esm/ABTest.mjs +19 -18
- package/esm/Account.d.ts.map +1 -1
- package/esm/Account.js.map +1 -1
- package/esm/Account.mjs +19 -18
- package/esm/AccountLinkingRequest.d.ts.map +1 -1
- package/esm/AccountLinkingRequest.js.map +1 -1
- package/esm/AccountLinkingRequest.mjs +19 -18
- package/esm/Action.d.ts.map +1 -1
- package/esm/Action.js.map +1 -1
- package/esm/Action.mjs +19 -18
- package/esm/Alert.d.ts.map +1 -1
- package/esm/Alert.js.map +1 -1
- package/esm/Alert.mjs +19 -18
- package/esm/Allocation.d.ts.map +1 -1
- package/esm/Allocation.js.map +1 -1
- package/esm/Allocation.mjs +19 -18
- package/esm/AlpacaAccount.d.ts.map +1 -1
- package/esm/AlpacaAccount.js.map +1 -1
- package/esm/AlpacaAccount.mjs +19 -18
- package/esm/AnalyticsConfiguration.d.ts.map +1 -1
- package/esm/AnalyticsConfiguration.js.map +1 -1
- package/esm/AnalyticsConfiguration.mjs +19 -18
- package/esm/AnalyticsSnapshot.d.ts.map +1 -1
- package/esm/AnalyticsSnapshot.js.map +1 -1
- package/esm/AnalyticsSnapshot.mjs +19 -18
- package/esm/Asset.d.ts.map +1 -1
- package/esm/Asset.js.map +1 -1
- package/esm/Asset.mjs +19 -18
- package/esm/Authenticator.d.ts.map +1 -1
- package/esm/Authenticator.js.map +1 -1
- package/esm/Authenticator.mjs +19 -18
- package/esm/Configuration.d.ts.map +1 -1
- package/esm/Configuration.js.map +1 -1
- package/esm/Configuration.mjs +19 -18
- package/esm/ConflictEvent.d.ts.map +1 -1
- package/esm/ConflictEvent.js.map +1 -1
- package/esm/ConflictEvent.mjs +19 -18
- package/esm/ConnectionHealthSnapshot.d.ts.map +1 -1
- package/esm/ConnectionHealthSnapshot.js.map +1 -1
- package/esm/ConnectionHealthSnapshot.mjs +19 -18
- package/esm/Customer.d.ts.map +1 -1
- package/esm/Customer.js.map +1 -1
- package/esm/Customer.mjs +19 -18
- package/esm/DeadLetterMessage.d.ts.map +1 -1
- package/esm/DeadLetterMessage.js.map +1 -1
- package/esm/DeadLetterMessage.mjs +19 -18
- package/esm/EconomicEvent.d.ts.map +1 -1
- package/esm/EconomicEvent.js.map +1 -1
- package/esm/EconomicEvent.mjs +19 -18
- package/esm/Event.d.ts.map +1 -1
- package/esm/Event.js.map +1 -1
- package/esm/Event.mjs +19 -18
- package/esm/EventSnapshot.d.ts.map +1 -1
- package/esm/EventSnapshot.js.map +1 -1
- package/esm/EventSnapshot.mjs +19 -18
- package/esm/FeatureImportanceAnalysis.d.ts.map +1 -1
- package/esm/FeatureImportanceAnalysis.js.map +1 -1
- package/esm/FeatureImportanceAnalysis.mjs +19 -18
- package/esm/InstitutionalFlowSignal.d.ts.map +1 -1
- package/esm/InstitutionalFlowSignal.js.map +1 -1
- package/esm/InstitutionalFlowSignal.mjs +19 -18
- package/esm/InstitutionalHolding.d.ts.map +1 -1
- package/esm/InstitutionalHolding.js.map +1 -1
- package/esm/InstitutionalHolding.mjs +19 -18
- package/esm/InstitutionalSentimentAlerts.d.ts.map +1 -1
- package/esm/InstitutionalSentimentAlerts.js.map +1 -1
- package/esm/InstitutionalSentimentAlerts.mjs +19 -18
- package/esm/InstitutionalSentimentErrors.d.ts.map +1 -1
- package/esm/InstitutionalSentimentErrors.js.map +1 -1
- package/esm/InstitutionalSentimentErrors.mjs +19 -18
- package/esm/InstitutionalSentimentHistory.d.ts.map +1 -1
- package/esm/InstitutionalSentimentHistory.js.map +1 -1
- package/esm/InstitutionalSentimentHistory.mjs +19 -18
- package/esm/InstitutionalSentimentMetrics.d.ts.map +1 -1
- package/esm/InstitutionalSentimentMetrics.js.map +1 -1
- package/esm/InstitutionalSentimentMetrics.mjs +19 -18
- package/esm/InviteToken.d.ts.map +1 -1
- package/esm/InviteToken.js.map +1 -1
- package/esm/InviteToken.mjs +19 -18
- package/esm/LinkedProvider.d.ts.map +1 -1
- package/esm/LinkedProvider.js.map +1 -1
- package/esm/LinkedProvider.mjs +19 -18
- package/esm/MLTrainingData.d.ts.map +1 -1
- package/esm/MLTrainingData.js.map +1 -1
- package/esm/MLTrainingData.mjs +19 -18
- package/esm/MarketSentiment.d.ts.map +1 -1
- package/esm/MarketSentiment.js.map +1 -1
- package/esm/MarketSentiment.mjs +19 -18
- package/esm/ModelArtifact.d.ts.map +1 -1
- package/esm/ModelArtifact.js.map +1 -1
- package/esm/ModelArtifact.mjs +19 -18
- package/esm/ModelVersion.d.ts.map +1 -1
- package/esm/ModelVersion.js.map +1 -1
- package/esm/ModelVersion.mjs +19 -18
- package/esm/ModelVersionArtifact.d.ts.map +1 -1
- package/esm/ModelVersionArtifact.js.map +1 -1
- package/esm/ModelVersionArtifact.mjs +19 -18
- package/esm/NewsArticle.d.ts.map +1 -1
- package/esm/NewsArticle.js.map +1 -1
- package/esm/NewsArticle.mjs +19 -18
- package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
- package/esm/NewsArticleAssetSentiment.js.map +1 -1
- package/esm/NewsArticleAssetSentiment.mjs +19 -18
- package/esm/OptionsContract.d.ts.map +1 -1
- package/esm/OptionsContract.js.map +1 -1
- package/esm/OptionsContract.mjs +19 -18
- package/esm/OptionsGreeksHistory.d.ts.map +1 -1
- package/esm/OptionsGreeksHistory.js.map +1 -1
- package/esm/OptionsGreeksHistory.mjs +19 -18
- package/esm/OptionsPosition.d.ts.map +1 -1
- package/esm/OptionsPosition.js.map +1 -1
- package/esm/OptionsPosition.mjs +19 -18
- package/esm/OptionsTradeExecution.d.ts.map +1 -1
- package/esm/OptionsTradeExecution.js.map +1 -1
- package/esm/OptionsTradeExecution.mjs +19 -18
- package/esm/PortfolioGreeksHistory.d.ts.map +1 -1
- package/esm/PortfolioGreeksHistory.js.map +1 -1
- package/esm/PortfolioGreeksHistory.mjs +19 -18
- package/esm/ScheduledOptionOrder.d.ts.map +1 -1
- package/esm/ScheduledOptionOrder.js.map +1 -1
- package/esm/ScheduledOptionOrder.mjs +19 -18
- package/esm/Session.d.ts.map +1 -1
- package/esm/Session.js.map +1 -1
- package/esm/Session.mjs +19 -18
- package/esm/SignalGeneratorMetrics.d.ts.map +1 -1
- package/esm/SignalGeneratorMetrics.js.map +1 -1
- package/esm/SignalGeneratorMetrics.mjs +19 -18
- package/esm/SignalLineage.d.ts.map +1 -1
- package/esm/SignalLineage.js.map +1 -1
- package/esm/SignalLineage.mjs +19 -18
- package/esm/SignalOutcome.d.ts.map +1 -1
- package/esm/SignalOutcome.js.map +1 -1
- package/esm/SignalOutcome.mjs +19 -18
- package/esm/SignalPriorityQueue.d.ts.map +1 -1
- package/esm/SignalPriorityQueue.js.map +1 -1
- package/esm/SignalPriorityQueue.mjs +19 -18
- package/esm/SyncEvent.d.ts.map +1 -1
- package/esm/SyncEvent.js.map +1 -1
- package/esm/SyncEvent.mjs +19 -18
- package/esm/SystemAlert.d.ts.map +1 -1
- package/esm/SystemAlert.js.map +1 -1
- package/esm/SystemAlert.mjs +19 -18
- package/esm/Trade.d.ts.map +1 -1
- package/esm/Trade.js.map +1 -1
- package/esm/Trade.mjs +19 -18
- package/esm/TradeAuditEvent.d.ts.map +1 -1
- package/esm/TradeAuditEvent.js.map +1 -1
- package/esm/TradeAuditEvent.mjs +19 -18
- package/esm/TradeExecutionHistory.d.ts.map +1 -1
- package/esm/TradeExecutionHistory.js.map +1 -1
- package/esm/TradeExecutionHistory.mjs +19 -18
- package/esm/User.d.ts.map +1 -1
- package/esm/User.js.map +1 -1
- package/esm/User.mjs +19 -18
- package/esm/VerificationToken.d.ts.map +1 -1
- package/esm/VerificationToken.js.map +1 -1
- package/esm/VerificationToken.mjs +19 -18
- package/esm/WaitlistEntry.d.ts.map +1 -1
- package/esm/WaitlistEntry.js.map +1 -1
- package/esm/WaitlistEntry.mjs +19 -18
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js.map +1 -1
- package/esm/client.mjs +11 -10
- package/esm/config/jwtConfig.d.ts.map +1 -1
- package/esm/config/jwtConfig.js.map +1 -1
- package/esm/config/jwtConfig.mjs +5 -4
- package/esm/getToken.d.ts.map +1 -1
- package/esm/getToken.js.map +1 -1
- package/esm/getToken.mjs +3 -2
- package/esm/health.d.ts +16 -0
- package/esm/health.d.ts.map +1 -0
- package/esm/health.js.map +1 -0
- package/esm/health.mjs +74 -0
- package/esm/middleware/auth.d.ts.map +1 -1
- package/esm/middleware/auth.js.map +1 -1
- package/esm/middleware/auth.mjs +3 -2
- package/esm/plugins/error-sanitizer.d.ts.map +1 -1
- package/esm/plugins/error-sanitizer.js.map +1 -1
- package/esm/plugins/error-sanitizer.mjs +6 -5
- package/esm/plugins/query-depth-limiter.d.ts.map +1 -1
- package/esm/plugins/query-depth-limiter.js.map +1 -1
- package/esm/plugins/query-depth-limiter.mjs +2 -2
- package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts +7 -1
- package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts.map +1 -1
- package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
- package/esm/scripts/migrate-openai-model-enum.js.map +1 -1
- package/esm/scripts/migrate-openai-model-enum.mjs +11 -10
- package/esm/scripts/set-default-openai-model.js.map +1 -1
- package/esm/scripts/set-default-openai-model.mjs +7 -6
- package/esm/utils/logger.d.ts +9 -0
- package/esm/utils/logger.d.ts.map +1 -0
- package/esm/utils/logger.js.map +1 -0
- package/esm/utils/logger.mjs +28 -0
- package/esm/utils.d.ts +12 -1
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js.map +1 -1
- package/esm/utils.mjs +20 -7
- package/getToken.cjs +3 -2
- package/health.cjs +80 -0
- package/health.d.ts +16 -0
- package/package.json +1 -1
- package/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts +7 -1
- package/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts.map +1 -1
- package/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
- package/server.cjs +35 -39
- package/utils.cjs +20 -7
- package/utils.d.ts +12 -1
package/server.cjs
CHANGED
|
@@ -22,12 +22,14 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
22
22
|
const auth_1 = require("./middleware/auth.cjs");
|
|
23
23
|
const jwtConfig_1 = require("./config/jwtConfig.cjs");
|
|
24
24
|
const prismaClient_1 = __importDefault(require("./prismaClient.cjs"));
|
|
25
|
+
const health_1 = require("./health.cjs");
|
|
25
26
|
const child_process_1 = require("child_process");
|
|
27
|
+
const logger_1 = require("./utils/logger.cjs");
|
|
26
28
|
let dbUnreachableCount = 0;
|
|
27
29
|
let lastRestartAttempt = 0;
|
|
28
30
|
async function restartDatabase() {
|
|
29
31
|
return new Promise((resolve, reject) => {
|
|
30
|
-
|
|
32
|
+
logger_1.logger.info('Attempting to redeploy the Railway Postgres service in production');
|
|
31
33
|
// Check for both types of tokens
|
|
32
34
|
const projectToken = process.env.RAILWAY_TOKEN;
|
|
33
35
|
const apiToken = process.env.RAILWAY_API_TOKEN;
|
|
@@ -41,12 +43,10 @@ async function restartDatabase() {
|
|
|
41
43
|
shell: '/bin/sh'
|
|
42
44
|
}, (error, stdout, stderr) => {
|
|
43
45
|
if (error) {
|
|
44
|
-
|
|
45
|
-
console.error('Command output:', stdout);
|
|
46
|
-
console.error('Command errors:', stderr);
|
|
46
|
+
logger_1.logger.error('Failed to redeploy DB via Railway CLI', { error: String(error), stdout, stderr });
|
|
47
47
|
return reject(error);
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
logger_1.logger.info('Railway deployment output', { stdout });
|
|
50
50
|
resolve();
|
|
51
51
|
});
|
|
52
52
|
});
|
|
@@ -65,12 +65,12 @@ const startServer = async () => {
|
|
|
65
65
|
plugins: [(0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({ httpServer })],
|
|
66
66
|
formatError: (err) => {
|
|
67
67
|
var _a;
|
|
68
|
-
|
|
68
|
+
logger_1.logger.error('GraphQL Error', { graphqlError: err });
|
|
69
69
|
// Check if this error is due to unreachable DB
|
|
70
70
|
const message = err.message || '';
|
|
71
71
|
if (message.includes("Can't reach database server")) {
|
|
72
72
|
dbUnreachableCount += 1;
|
|
73
|
-
|
|
73
|
+
logger_1.logger.warn('Database unreachable', { dbUnreachableCount });
|
|
74
74
|
// If we've hit 3 (for example) attempts
|
|
75
75
|
if (dbUnreachableCount >= 3) {
|
|
76
76
|
const now = Date.now();
|
|
@@ -78,22 +78,22 @@ const startServer = async () => {
|
|
|
78
78
|
if (now - lastRestartAttempt > 5 * 60 * 1000) {
|
|
79
79
|
lastRestartAttempt = now;
|
|
80
80
|
try {
|
|
81
|
-
restartDatabase();
|
|
81
|
+
void restartDatabase();
|
|
82
82
|
// Reset the counter after attempting a restart
|
|
83
83
|
dbUnreachableCount = 0;
|
|
84
84
|
}
|
|
85
85
|
catch (restartError) {
|
|
86
|
-
|
|
86
|
+
logger_1.logger.error('Error trying to restart DB', { restartError: String(restartError) });
|
|
87
87
|
// If the restart fails, we can try again after a delay
|
|
88
88
|
const backoffTime = Math.min(30000, 1000 * Math.pow(2, dbUnreachableCount - 3)); // Exponential backoff with a max of 30 seconds
|
|
89
|
-
|
|
89
|
+
logger_1.logger.info('Waiting before next restart attempt', { backoffSeconds: backoffTime / 1000 });
|
|
90
90
|
setTimeout(() => {
|
|
91
91
|
restartDatabase()
|
|
92
92
|
.then(() => {
|
|
93
93
|
dbUnreachableCount = 0; // Reset the counter after a successful restart
|
|
94
94
|
})
|
|
95
95
|
.catch((restartError) => {
|
|
96
|
-
|
|
96
|
+
logger_1.logger.error('Error trying to restart DB', { restartError: String(restartError) });
|
|
97
97
|
// We do not reset the counter here if the restart fails,
|
|
98
98
|
// so it can try again next time.
|
|
99
99
|
});
|
|
@@ -119,6 +119,8 @@ const startServer = async () => {
|
|
|
119
119
|
},
|
|
120
120
|
});
|
|
121
121
|
await server.start();
|
|
122
|
+
// Health check endpoint - mounted before Apollo middleware so it's not behind GraphQL or auth
|
|
123
|
+
app.use((0, health_1.createHealthRouter)());
|
|
122
124
|
// Configure CORS with allowed origins
|
|
123
125
|
const allowedOrigins = (process.env.ALLOWED_ORIGINS || 'http://localhost:3000,http://localhost:3001').split(',').map(o => o.trim());
|
|
124
126
|
const corsOptions = {
|
|
@@ -142,7 +144,7 @@ const startServer = async () => {
|
|
|
142
144
|
context: async ({ req }) => {
|
|
143
145
|
// Ensure we're using the global prisma instance and never disconnecting it between requests
|
|
144
146
|
if (!global.prisma) {
|
|
145
|
-
|
|
147
|
+
logger_1.logger.warn('Prisma client not found in global scope, reinitializing');
|
|
146
148
|
global.prisma = prismaClient_1.default;
|
|
147
149
|
}
|
|
148
150
|
// Extract token from Authorization header
|
|
@@ -163,7 +165,7 @@ const startServer = async () => {
|
|
|
163
165
|
if (tokenParts.length !== 3) {
|
|
164
166
|
// Log only once per unique malformed token to avoid log spam
|
|
165
167
|
const tokenPreview = token.length > 20 ? `${token.substring(0, 20)}...` : token;
|
|
166
|
-
|
|
168
|
+
logger_1.logger.warn('Received malformed token (not a valid JWT format)', { tokenPreview });
|
|
167
169
|
// Continue without authentication - don't fail the request
|
|
168
170
|
return { prisma: global.prisma, req, authError: 'Malformed token: expected JWT format (header.payload.signature)' };
|
|
169
171
|
}
|
|
@@ -181,7 +183,7 @@ const startServer = async () => {
|
|
|
181
183
|
catch (e) {
|
|
182
184
|
// Only log verification failures at warn level with minimal info
|
|
183
185
|
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
184
|
-
|
|
186
|
+
logger_1.logger.warn('JWT verification failed', { errorMessage });
|
|
185
187
|
return { prisma: global.prisma, req, authError: 'Invalid token' };
|
|
186
188
|
}
|
|
187
189
|
}
|
|
@@ -190,12 +192,12 @@ const startServer = async () => {
|
|
|
190
192
|
},
|
|
191
193
|
}));
|
|
192
194
|
// Custom error handling middleware for express
|
|
193
|
-
app.use((err, req, res,
|
|
194
|
-
|
|
195
|
+
app.use((err, req, res, _next) => {
|
|
196
|
+
logger_1.logger.error('Express error', { error: err.message, stack: err.stack });
|
|
195
197
|
res.status(500).json({ error: 'An internal server error occurred' });
|
|
196
198
|
});
|
|
197
199
|
app.use((req, res, next) => {
|
|
198
|
-
|
|
200
|
+
logger_1.logger.debug('Incoming request', { method: req.method, url: req.url });
|
|
199
201
|
next();
|
|
200
202
|
});
|
|
201
203
|
const wsServer = new ws_1.WebSocketServer({
|
|
@@ -204,11 +206,11 @@ const startServer = async () => {
|
|
|
204
206
|
});
|
|
205
207
|
(0, ws_2.useServer)({
|
|
206
208
|
schema,
|
|
207
|
-
context: async (ctx,
|
|
209
|
+
context: async (ctx, _msg, _args) => {
|
|
208
210
|
var _a;
|
|
209
211
|
// Ensure we're using the global prisma instance for WebSocket connections too
|
|
210
212
|
if (!global.prisma) {
|
|
211
|
-
|
|
213
|
+
logger_1.logger.warn('Prisma client not found in global scope for WebSocket context, reinitializing');
|
|
212
214
|
global.prisma = prismaClient_1.default;
|
|
213
215
|
}
|
|
214
216
|
const authHeader = ((_a = ctx.connectionParams) === null || _a === void 0 ? void 0 : _a.authorization) || '';
|
|
@@ -218,7 +220,7 @@ const startServer = async () => {
|
|
|
218
220
|
// Check if token is a Google OAuth token (starts with ya29.)
|
|
219
221
|
if (token.startsWith('ya29.')) {
|
|
220
222
|
// For Google OAuth tokens, we should validate differently or pass them through
|
|
221
|
-
|
|
223
|
+
logger_1.logger.info('Detected Google OAuth token in WebSocket, skipping JWT verification');
|
|
222
224
|
user = { provider: 'google', token };
|
|
223
225
|
}
|
|
224
226
|
else {
|
|
@@ -235,7 +237,7 @@ const startServer = async () => {
|
|
|
235
237
|
}
|
|
236
238
|
catch (e) {
|
|
237
239
|
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
238
|
-
|
|
240
|
+
logger_1.logger.warn('WebSocket JWT verification failed', { errorMessage });
|
|
239
241
|
return { prisma: global.prisma, authError: 'Invalid token' };
|
|
240
242
|
}
|
|
241
243
|
}
|
|
@@ -245,50 +247,44 @@ const startServer = async () => {
|
|
|
245
247
|
}, wsServer);
|
|
246
248
|
const PORT = process.env.PORT || 4000;
|
|
247
249
|
httpServer.listen(PORT, () => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
+
logger_1.logger.info('Server ready', { graphql: `http://localhost:${PORT}/graphql`, health: `http://localhost:${PORT}/health` });
|
|
251
|
+
logger_1.logger.info('Subscriptions ready', { endpoint: `ws://localhost:${PORT}/subscriptions` });
|
|
250
252
|
});
|
|
251
253
|
};
|
|
252
254
|
startServer().catch((error) => {
|
|
253
|
-
|
|
255
|
+
logger_1.logger.error('Error starting the server', { error: error instanceof Error ? error.message : String(error) });
|
|
254
256
|
process.exit(1);
|
|
255
257
|
});
|
|
256
|
-
process.on('unhandledRejection', (reason,
|
|
257
|
-
|
|
258
|
+
process.on('unhandledRejection', (reason, _promise) => {
|
|
259
|
+
logger_1.logger.error('Unhandled Rejection', { reason: reason instanceof Error ? reason.message : String(reason) });
|
|
258
260
|
});
|
|
259
261
|
process.on('uncaughtException', (error) => {
|
|
260
|
-
|
|
262
|
+
logger_1.logger.error('Uncaught Exception', { error: error.message, stack: error.stack });
|
|
261
263
|
});
|
|
262
264
|
// Only disconnect Prisma when the process is truly shutting down
|
|
263
265
|
process.on('SIGINT', async () => {
|
|
264
266
|
var _a;
|
|
265
|
-
|
|
267
|
+
logger_1.logger.info('Gracefully shutting down and closing database connections');
|
|
266
268
|
try {
|
|
267
269
|
await ((_a = global.prisma) === null || _a === void 0 ? void 0 : _a.$disconnect());
|
|
268
|
-
|
|
270
|
+
logger_1.logger.info('Database connections closed successfully');
|
|
269
271
|
}
|
|
270
272
|
catch (e) {
|
|
271
|
-
|
|
273
|
+
logger_1.logger.error('Error disconnecting from database', { error: e instanceof Error ? e.message : String(e) });
|
|
272
274
|
}
|
|
273
275
|
process.exit(0);
|
|
274
276
|
});
|
|
275
277
|
// Also handle SIGTERM for containerized environments
|
|
276
278
|
process.on('SIGTERM', async () => {
|
|
277
279
|
var _a;
|
|
278
|
-
|
|
280
|
+
logger_1.logger.info('Received SIGTERM, gracefully shutting down');
|
|
279
281
|
try {
|
|
280
282
|
await ((_a = global.prisma) === null || _a === void 0 ? void 0 : _a.$disconnect());
|
|
281
|
-
|
|
283
|
+
logger_1.logger.info('Database connections closed successfully');
|
|
282
284
|
}
|
|
283
285
|
catch (e) {
|
|
284
|
-
|
|
286
|
+
logger_1.logger.error('Error disconnecting from database', { error: e instanceof Error ? e.message : String(e) });
|
|
285
287
|
}
|
|
286
288
|
process.exit(0);
|
|
287
289
|
});
|
|
288
|
-
// // run restartDatabase() function
|
|
289
|
-
// restartDatabase().then(() => {
|
|
290
|
-
// console.log('Database restarted successfully');
|
|
291
|
-
// }).catch((error) => {
|
|
292
|
-
// console.error('Error restarting database:', error);
|
|
293
|
-
// });
|
|
294
290
|
//# sourceMappingURL=server.js.map
|
package/utils.cjs
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeUndefinedProps = removeUndefinedProps;
|
|
4
|
+
/**
|
|
5
|
+
* Recursively removes undefined and null properties from an object or array.
|
|
6
|
+
*
|
|
7
|
+
* This utility is called by generated CRUD functions to clean GraphQL variables
|
|
8
|
+
* before passing them to Apollo Client. The input objects contain Prisma-typed
|
|
9
|
+
* fields (Date, Decimal, bigint, JsonValue, nested relations, etc.) which cannot
|
|
10
|
+
* be enumerated exhaustively. The return value is used as Apollo OperationVariables.
|
|
11
|
+
*
|
|
12
|
+
* We use Record<string, unknown> for the parameter to accept all generated Prisma
|
|
13
|
+
* input shapes without needing to enumerate every possible field type.
|
|
14
|
+
*/
|
|
4
15
|
function removeUndefinedProps(obj) {
|
|
5
16
|
if (Array.isArray(obj)) {
|
|
6
17
|
return obj
|
|
@@ -9,15 +20,17 @@ function removeUndefinedProps(obj) {
|
|
|
9
20
|
item !== null &&
|
|
10
21
|
(typeof item !== 'object' || Object.keys(item).length > 0));
|
|
11
22
|
}
|
|
12
|
-
else if (typeof obj === 'object' && obj !== null) {
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
else if (typeof obj === 'object' && obj !== null && !(obj instanceof Date)) {
|
|
24
|
+
const record = obj;
|
|
25
|
+
return Object.keys(record).reduce((acc, key) => {
|
|
26
|
+
const value = record[key];
|
|
15
27
|
if (value !== undefined && value !== null) {
|
|
16
28
|
let cleanedValue;
|
|
17
|
-
if (key === 'where' && typeof value === 'object' && value !== null) {
|
|
18
|
-
|
|
29
|
+
if (key === 'where' && typeof value === 'object' && value !== null && !(value instanceof Date)) {
|
|
30
|
+
const whereObj = value;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(whereObj, 'id') && whereObj.id !== undefined) {
|
|
19
32
|
// Retain only the 'id' field within 'where'
|
|
20
|
-
cleanedValue = { id: removeUndefinedProps(
|
|
33
|
+
cleanedValue = { id: removeUndefinedProps(whereObj.id) };
|
|
21
34
|
}
|
|
22
35
|
else {
|
|
23
36
|
// Process 'where' object normally if 'id' is undefined or doesn't exist
|
|
@@ -30,7 +43,7 @@ function removeUndefinedProps(obj) {
|
|
|
30
43
|
}
|
|
31
44
|
if (cleanedValue !== undefined &&
|
|
32
45
|
cleanedValue !== null &&
|
|
33
|
-
(typeof cleanedValue !== 'object' || Object.keys(cleanedValue).length > 0)) {
|
|
46
|
+
(typeof cleanedValue !== 'object' || cleanedValue instanceof Date || Object.keys(cleanedValue).length > 0)) {
|
|
34
47
|
acc[key] = cleanedValue;
|
|
35
48
|
}
|
|
36
49
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Recursively removes undefined and null properties from an object or array.
|
|
3
|
+
*
|
|
4
|
+
* This utility is called by generated CRUD functions to clean GraphQL variables
|
|
5
|
+
* before passing them to Apollo Client. The input objects contain Prisma-typed
|
|
6
|
+
* fields (Date, Decimal, bigint, JsonValue, nested relations, etc.) which cannot
|
|
7
|
+
* be enumerated exhaustively. The return value is used as Apollo OperationVariables.
|
|
8
|
+
*
|
|
9
|
+
* We use Record<string, unknown> for the parameter to accept all generated Prisma
|
|
10
|
+
* input shapes without needing to enumerate every possible field type.
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeUndefinedProps(obj: Record<string, unknown> | Record<string, unknown>[] | unknown): Record<string, unknown> | undefined;
|
|
2
13
|
//# sourceMappingURL=utils.d.ts.map
|