@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.
Files changed (264) hide show
  1. package/ABTest.cjs +19 -18
  2. package/Account.cjs +19 -18
  3. package/AccountLinkingRequest.cjs +19 -18
  4. package/Action.cjs +19 -18
  5. package/Alert.cjs +19 -18
  6. package/Allocation.cjs +19 -18
  7. package/AlpacaAccount.cjs +19 -18
  8. package/AnalyticsConfiguration.cjs +19 -18
  9. package/AnalyticsSnapshot.cjs +19 -18
  10. package/Asset.cjs +19 -18
  11. package/Authenticator.cjs +19 -18
  12. package/Configuration.cjs +19 -18
  13. package/ConflictEvent.cjs +19 -18
  14. package/ConnectionHealthSnapshot.cjs +19 -18
  15. package/Customer.cjs +19 -18
  16. package/DeadLetterMessage.cjs +19 -18
  17. package/EconomicEvent.cjs +19 -18
  18. package/Event.cjs +19 -18
  19. package/EventSnapshot.cjs +19 -18
  20. package/FeatureImportanceAnalysis.cjs +19 -18
  21. package/InstitutionalFlowSignal.cjs +19 -18
  22. package/InstitutionalHolding.cjs +19 -18
  23. package/InstitutionalSentimentAlerts.cjs +19 -18
  24. package/InstitutionalSentimentErrors.cjs +19 -18
  25. package/InstitutionalSentimentHistory.cjs +19 -18
  26. package/InstitutionalSentimentMetrics.cjs +19 -18
  27. package/InviteToken.cjs +19 -18
  28. package/LinkedProvider.cjs +19 -18
  29. package/MLTrainingData.cjs +19 -18
  30. package/MarketSentiment.cjs +19 -18
  31. package/ModelArtifact.cjs +19 -18
  32. package/ModelVersion.cjs +19 -18
  33. package/ModelVersionArtifact.cjs +19 -18
  34. package/NewsArticle.cjs +19 -18
  35. package/NewsArticleAssetSentiment.cjs +19 -18
  36. package/OptionsContract.cjs +19 -18
  37. package/OptionsGreeksHistory.cjs +19 -18
  38. package/OptionsPosition.cjs +19 -18
  39. package/OptionsTradeExecution.cjs +19 -18
  40. package/PortfolioGreeksHistory.cjs +19 -18
  41. package/ScheduledOptionOrder.cjs +19 -18
  42. package/Session.cjs +19 -18
  43. package/SignalGeneratorMetrics.cjs +19 -18
  44. package/SignalLineage.cjs +19 -18
  45. package/SignalOutcome.cjs +19 -18
  46. package/SignalPriorityQueue.cjs +19 -18
  47. package/SyncEvent.cjs +19 -18
  48. package/SystemAlert.cjs +19 -18
  49. package/Trade.cjs +19 -18
  50. package/TradeAuditEvent.cjs +19 -18
  51. package/TradeExecutionHistory.cjs +19 -18
  52. package/User.cjs +19 -18
  53. package/VerificationToken.cjs +19 -18
  54. package/WaitlistEntry.cjs +19 -18
  55. package/client.cjs +11 -10
  56. package/esm/ABTest.d.ts.map +1 -1
  57. package/esm/ABTest.js.map +1 -1
  58. package/esm/ABTest.mjs +19 -18
  59. package/esm/Account.d.ts.map +1 -1
  60. package/esm/Account.js.map +1 -1
  61. package/esm/Account.mjs +19 -18
  62. package/esm/AccountLinkingRequest.d.ts.map +1 -1
  63. package/esm/AccountLinkingRequest.js.map +1 -1
  64. package/esm/AccountLinkingRequest.mjs +19 -18
  65. package/esm/Action.d.ts.map +1 -1
  66. package/esm/Action.js.map +1 -1
  67. package/esm/Action.mjs +19 -18
  68. package/esm/Alert.d.ts.map +1 -1
  69. package/esm/Alert.js.map +1 -1
  70. package/esm/Alert.mjs +19 -18
  71. package/esm/Allocation.d.ts.map +1 -1
  72. package/esm/Allocation.js.map +1 -1
  73. package/esm/Allocation.mjs +19 -18
  74. package/esm/AlpacaAccount.d.ts.map +1 -1
  75. package/esm/AlpacaAccount.js.map +1 -1
  76. package/esm/AlpacaAccount.mjs +19 -18
  77. package/esm/AnalyticsConfiguration.d.ts.map +1 -1
  78. package/esm/AnalyticsConfiguration.js.map +1 -1
  79. package/esm/AnalyticsConfiguration.mjs +19 -18
  80. package/esm/AnalyticsSnapshot.d.ts.map +1 -1
  81. package/esm/AnalyticsSnapshot.js.map +1 -1
  82. package/esm/AnalyticsSnapshot.mjs +19 -18
  83. package/esm/Asset.d.ts.map +1 -1
  84. package/esm/Asset.js.map +1 -1
  85. package/esm/Asset.mjs +19 -18
  86. package/esm/Authenticator.d.ts.map +1 -1
  87. package/esm/Authenticator.js.map +1 -1
  88. package/esm/Authenticator.mjs +19 -18
  89. package/esm/Configuration.d.ts.map +1 -1
  90. package/esm/Configuration.js.map +1 -1
  91. package/esm/Configuration.mjs +19 -18
  92. package/esm/ConflictEvent.d.ts.map +1 -1
  93. package/esm/ConflictEvent.js.map +1 -1
  94. package/esm/ConflictEvent.mjs +19 -18
  95. package/esm/ConnectionHealthSnapshot.d.ts.map +1 -1
  96. package/esm/ConnectionHealthSnapshot.js.map +1 -1
  97. package/esm/ConnectionHealthSnapshot.mjs +19 -18
  98. package/esm/Customer.d.ts.map +1 -1
  99. package/esm/Customer.js.map +1 -1
  100. package/esm/Customer.mjs +19 -18
  101. package/esm/DeadLetterMessage.d.ts.map +1 -1
  102. package/esm/DeadLetterMessage.js.map +1 -1
  103. package/esm/DeadLetterMessage.mjs +19 -18
  104. package/esm/EconomicEvent.d.ts.map +1 -1
  105. package/esm/EconomicEvent.js.map +1 -1
  106. package/esm/EconomicEvent.mjs +19 -18
  107. package/esm/Event.d.ts.map +1 -1
  108. package/esm/Event.js.map +1 -1
  109. package/esm/Event.mjs +19 -18
  110. package/esm/EventSnapshot.d.ts.map +1 -1
  111. package/esm/EventSnapshot.js.map +1 -1
  112. package/esm/EventSnapshot.mjs +19 -18
  113. package/esm/FeatureImportanceAnalysis.d.ts.map +1 -1
  114. package/esm/FeatureImportanceAnalysis.js.map +1 -1
  115. package/esm/FeatureImportanceAnalysis.mjs +19 -18
  116. package/esm/InstitutionalFlowSignal.d.ts.map +1 -1
  117. package/esm/InstitutionalFlowSignal.js.map +1 -1
  118. package/esm/InstitutionalFlowSignal.mjs +19 -18
  119. package/esm/InstitutionalHolding.d.ts.map +1 -1
  120. package/esm/InstitutionalHolding.js.map +1 -1
  121. package/esm/InstitutionalHolding.mjs +19 -18
  122. package/esm/InstitutionalSentimentAlerts.d.ts.map +1 -1
  123. package/esm/InstitutionalSentimentAlerts.js.map +1 -1
  124. package/esm/InstitutionalSentimentAlerts.mjs +19 -18
  125. package/esm/InstitutionalSentimentErrors.d.ts.map +1 -1
  126. package/esm/InstitutionalSentimentErrors.js.map +1 -1
  127. package/esm/InstitutionalSentimentErrors.mjs +19 -18
  128. package/esm/InstitutionalSentimentHistory.d.ts.map +1 -1
  129. package/esm/InstitutionalSentimentHistory.js.map +1 -1
  130. package/esm/InstitutionalSentimentHistory.mjs +19 -18
  131. package/esm/InstitutionalSentimentMetrics.d.ts.map +1 -1
  132. package/esm/InstitutionalSentimentMetrics.js.map +1 -1
  133. package/esm/InstitutionalSentimentMetrics.mjs +19 -18
  134. package/esm/InviteToken.d.ts.map +1 -1
  135. package/esm/InviteToken.js.map +1 -1
  136. package/esm/InviteToken.mjs +19 -18
  137. package/esm/LinkedProvider.d.ts.map +1 -1
  138. package/esm/LinkedProvider.js.map +1 -1
  139. package/esm/LinkedProvider.mjs +19 -18
  140. package/esm/MLTrainingData.d.ts.map +1 -1
  141. package/esm/MLTrainingData.js.map +1 -1
  142. package/esm/MLTrainingData.mjs +19 -18
  143. package/esm/MarketSentiment.d.ts.map +1 -1
  144. package/esm/MarketSentiment.js.map +1 -1
  145. package/esm/MarketSentiment.mjs +19 -18
  146. package/esm/ModelArtifact.d.ts.map +1 -1
  147. package/esm/ModelArtifact.js.map +1 -1
  148. package/esm/ModelArtifact.mjs +19 -18
  149. package/esm/ModelVersion.d.ts.map +1 -1
  150. package/esm/ModelVersion.js.map +1 -1
  151. package/esm/ModelVersion.mjs +19 -18
  152. package/esm/ModelVersionArtifact.d.ts.map +1 -1
  153. package/esm/ModelVersionArtifact.js.map +1 -1
  154. package/esm/ModelVersionArtifact.mjs +19 -18
  155. package/esm/NewsArticle.d.ts.map +1 -1
  156. package/esm/NewsArticle.js.map +1 -1
  157. package/esm/NewsArticle.mjs +19 -18
  158. package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
  159. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  160. package/esm/NewsArticleAssetSentiment.mjs +19 -18
  161. package/esm/OptionsContract.d.ts.map +1 -1
  162. package/esm/OptionsContract.js.map +1 -1
  163. package/esm/OptionsContract.mjs +19 -18
  164. package/esm/OptionsGreeksHistory.d.ts.map +1 -1
  165. package/esm/OptionsGreeksHistory.js.map +1 -1
  166. package/esm/OptionsGreeksHistory.mjs +19 -18
  167. package/esm/OptionsPosition.d.ts.map +1 -1
  168. package/esm/OptionsPosition.js.map +1 -1
  169. package/esm/OptionsPosition.mjs +19 -18
  170. package/esm/OptionsTradeExecution.d.ts.map +1 -1
  171. package/esm/OptionsTradeExecution.js.map +1 -1
  172. package/esm/OptionsTradeExecution.mjs +19 -18
  173. package/esm/PortfolioGreeksHistory.d.ts.map +1 -1
  174. package/esm/PortfolioGreeksHistory.js.map +1 -1
  175. package/esm/PortfolioGreeksHistory.mjs +19 -18
  176. package/esm/ScheduledOptionOrder.d.ts.map +1 -1
  177. package/esm/ScheduledOptionOrder.js.map +1 -1
  178. package/esm/ScheduledOptionOrder.mjs +19 -18
  179. package/esm/Session.d.ts.map +1 -1
  180. package/esm/Session.js.map +1 -1
  181. package/esm/Session.mjs +19 -18
  182. package/esm/SignalGeneratorMetrics.d.ts.map +1 -1
  183. package/esm/SignalGeneratorMetrics.js.map +1 -1
  184. package/esm/SignalGeneratorMetrics.mjs +19 -18
  185. package/esm/SignalLineage.d.ts.map +1 -1
  186. package/esm/SignalLineage.js.map +1 -1
  187. package/esm/SignalLineage.mjs +19 -18
  188. package/esm/SignalOutcome.d.ts.map +1 -1
  189. package/esm/SignalOutcome.js.map +1 -1
  190. package/esm/SignalOutcome.mjs +19 -18
  191. package/esm/SignalPriorityQueue.d.ts.map +1 -1
  192. package/esm/SignalPriorityQueue.js.map +1 -1
  193. package/esm/SignalPriorityQueue.mjs +19 -18
  194. package/esm/SyncEvent.d.ts.map +1 -1
  195. package/esm/SyncEvent.js.map +1 -1
  196. package/esm/SyncEvent.mjs +19 -18
  197. package/esm/SystemAlert.d.ts.map +1 -1
  198. package/esm/SystemAlert.js.map +1 -1
  199. package/esm/SystemAlert.mjs +19 -18
  200. package/esm/Trade.d.ts.map +1 -1
  201. package/esm/Trade.js.map +1 -1
  202. package/esm/Trade.mjs +19 -18
  203. package/esm/TradeAuditEvent.d.ts.map +1 -1
  204. package/esm/TradeAuditEvent.js.map +1 -1
  205. package/esm/TradeAuditEvent.mjs +19 -18
  206. package/esm/TradeExecutionHistory.d.ts.map +1 -1
  207. package/esm/TradeExecutionHistory.js.map +1 -1
  208. package/esm/TradeExecutionHistory.mjs +19 -18
  209. package/esm/User.d.ts.map +1 -1
  210. package/esm/User.js.map +1 -1
  211. package/esm/User.mjs +19 -18
  212. package/esm/VerificationToken.d.ts.map +1 -1
  213. package/esm/VerificationToken.js.map +1 -1
  214. package/esm/VerificationToken.mjs +19 -18
  215. package/esm/WaitlistEntry.d.ts.map +1 -1
  216. package/esm/WaitlistEntry.js.map +1 -1
  217. package/esm/WaitlistEntry.mjs +19 -18
  218. package/esm/client.d.ts.map +1 -1
  219. package/esm/client.js.map +1 -1
  220. package/esm/client.mjs +11 -10
  221. package/esm/config/jwtConfig.d.ts.map +1 -1
  222. package/esm/config/jwtConfig.js.map +1 -1
  223. package/esm/config/jwtConfig.mjs +5 -4
  224. package/esm/getToken.d.ts.map +1 -1
  225. package/esm/getToken.js.map +1 -1
  226. package/esm/getToken.mjs +3 -2
  227. package/esm/health.d.ts +16 -0
  228. package/esm/health.d.ts.map +1 -0
  229. package/esm/health.js.map +1 -0
  230. package/esm/health.mjs +74 -0
  231. package/esm/middleware/auth.d.ts.map +1 -1
  232. package/esm/middleware/auth.js.map +1 -1
  233. package/esm/middleware/auth.mjs +3 -2
  234. package/esm/plugins/error-sanitizer.d.ts.map +1 -1
  235. package/esm/plugins/error-sanitizer.js.map +1 -1
  236. package/esm/plugins/error-sanitizer.mjs +6 -5
  237. package/esm/plugins/query-depth-limiter.d.ts.map +1 -1
  238. package/esm/plugins/query-depth-limiter.js.map +1 -1
  239. package/esm/plugins/query-depth-limiter.mjs +2 -2
  240. package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts +7 -1
  241. package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts.map +1 -1
  242. package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
  243. package/esm/scripts/migrate-openai-model-enum.js.map +1 -1
  244. package/esm/scripts/migrate-openai-model-enum.mjs +11 -10
  245. package/esm/scripts/set-default-openai-model.js.map +1 -1
  246. package/esm/scripts/set-default-openai-model.mjs +7 -6
  247. package/esm/utils/logger.d.ts +9 -0
  248. package/esm/utils/logger.d.ts.map +1 -0
  249. package/esm/utils/logger.js.map +1 -0
  250. package/esm/utils/logger.mjs +28 -0
  251. package/esm/utils.d.ts +12 -1
  252. package/esm/utils.d.ts.map +1 -1
  253. package/esm/utils.js.map +1 -1
  254. package/esm/utils.mjs +20 -7
  255. package/getToken.cjs +3 -2
  256. package/health.cjs +80 -0
  257. package/health.d.ts +16 -0
  258. package/package.json +1 -1
  259. package/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts +7 -1
  260. package/resolvers/custom/OptionsGreeksHistoryCustomResolver.d.ts.map +1 -1
  261. package/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
  262. package/server.cjs +35 -39
  263. package/utils.cjs +20 -7
  264. 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
- console.log("Attempting to redeploy the Railway Postgres service in production...");
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
- console.error('Failed to redeploy DB via Railway CLI:', error);
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
- console.log('Railway deployment output:', stdout);
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
- console.error('GraphQL Error:', JSON.stringify(err, null, 2));
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
- console.log(`DB unreachable count: ${dbUnreachableCount}`);
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
- console.error('Error trying to restart DB:', restartError);
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
- console.log(`Waiting for ${backoffTime / 1000} seconds before next restart attempt...`);
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
- console.error('Error trying to restart DB:', restartError);
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
- console.warn('Prisma client not found in global scope, reinitializing');
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
- console.warn(`[Auth] Received malformed token (not a valid JWT format): ${tokenPreview}`);
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
- console.warn(`[Auth] JWT verification failed: ${errorMessage}`);
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, next) => {
194
- console.error('Express error:', err);
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
- console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
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, msg, args) => {
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
- console.warn('Prisma client not found in global scope for WebSocket context, reinitializing');
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
- console.log('Detected Google OAuth token in WebSocket, skipping JWT verification');
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
- console.warn(`[Auth] WebSocket JWT verification failed: ${errorMessage}`);
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
- console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`);
249
- console.log(`🚀 Subscriptions ready at ws://localhost:${PORT}/subscriptions`);
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
- console.error('Error starting the server', error);
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, promise) => {
257
- console.error('Unhandled Rejection at:', promise, 'reason:', reason);
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
- console.error('Uncaught Exception:', error);
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
- console.log('Gracefully shutting down and closing database connections...');
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
- console.log('Database connections closed successfully');
270
+ logger_1.logger.info('Database connections closed successfully');
269
271
  }
270
272
  catch (e) {
271
- console.error('Error disconnecting from database:', e);
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
- console.log('Received SIGTERM, gracefully shutting down...');
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
- console.log('Database connections closed successfully');
283
+ logger_1.logger.info('Database connections closed successfully');
282
284
  }
283
285
  catch (e) {
284
- console.error('Error disconnecting from database:', e);
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
- return Object.keys(obj).reduce((acc, key) => {
14
- let value = obj[key];
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
- if (value.hasOwnProperty('id') && value.id !== undefined) {
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(value.id) };
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
- export declare function removeUndefinedProps(obj: any): any;
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