@adaptic/backend-legacy 0.0.53 → 0.0.54
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/README.md +47 -35
- package/apollo-client.client.d.ts +7 -7
- package/apollo-client.server.d.ts +7 -7
- package/client.cjs +27 -16
- package/client.d.ts +10 -10
- package/esm/apollo-client.client.d.ts +7 -7
- package/esm/apollo-client.client.mjs +6 -6
- package/esm/apollo-client.server.d.ts +7 -7
- package/esm/apollo-client.server.mjs +6 -6
- package/esm/client.d.ts +10 -10
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js.map +1 -1
- package/esm/client.mjs +27 -16
- package/esm/config/jwtConfig.d.ts.map +1 -1
- package/esm/config/jwtConfig.js.map +1 -1
- package/esm/config/metrics.d.ts.map +1 -1
- package/esm/config/metrics.js.map +1 -1
- package/esm/config/metrics.mjs +6 -2
- package/esm/config/persisted-queries.d.ts.map +1 -1
- package/esm/config/persisted-queries.js.map +1 -1
- package/esm/config/persisted-queries.mjs +3 -1
- package/esm/config/tracing.d.ts.map +1 -1
- package/esm/config/tracing.js.map +1 -1
- package/esm/config/tracing.mjs +5 -3
- package/esm/getToken.d.ts +1 -1
- package/esm/getToken.d.ts.map +1 -1
- package/esm/getToken.js.map +1 -1
- package/esm/getToken.mjs +25 -12
- package/esm/middleware/audit-logger.d.ts +1 -1
- package/esm/middleware/audit-logger.d.ts.map +1 -1
- package/esm/middleware/audit-logger.js.map +1 -1
- package/esm/middleware/audit-logger.mjs +8 -4
- package/esm/middleware/auth.d.ts +1 -1
- package/esm/middleware/auth.d.ts.map +1 -1
- package/esm/middleware/auth.js.map +1 -1
- package/esm/middleware/auth.mjs +7 -5
- package/esm/middleware/graphql-validation-plugin.d.ts.map +1 -1
- package/esm/middleware/graphql-validation-plugin.js.map +1 -1
- package/esm/middleware/index.d.ts +1 -1
- package/esm/middleware/index.d.ts.map +1 -1
- package/esm/middleware/index.js.map +1 -1
- package/esm/middleware/index.mjs +1 -1
- package/esm/middleware/query-complexity.d.ts.map +1 -1
- package/esm/middleware/query-complexity.js.map +1 -1
- package/esm/middleware/query-complexity.mjs +3 -1
- package/esm/middleware/rate-limiter.d.ts.map +1 -1
- package/esm/middleware/rate-limiter.js.map +1 -1
- package/esm/middleware/rate-limiter.mjs +6 -2
- package/esm/middleware/soft-delete.d.ts.map +1 -1
- package/esm/middleware/soft-delete.js.map +1 -1
- package/esm/middleware/soft-delete.mjs +8 -2
- package/esm/middleware/validation-examples.d.ts.map +1 -1
- package/esm/middleware/validation-examples.js.map +1 -1
- package/esm/middleware/validation-examples.mjs +2 -1
- 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 +1 -3
- package/esm/plugins/integration-example.d.ts.map +1 -1
- package/esm/plugins/integration-example.js.map +1 -1
- 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 +3 -1
- package/esm/prismaClient.d.ts +1 -1
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +2 -2
- package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
- package/esm/resolvers/custom/OptionsGreeksHistoryCustomResolver.mjs +2 -2
- package/esm/resolvers/custom/OptionsGreeksHistorySystemSummary.js.map +1 -1
- package/esm/resolvers/custom/OptionsGreeksHistorySystemSummary.mjs +4 -4
- package/esm/scripts/migrate-openai-model-enum.js.map +1 -1
- package/esm/utils/logger.d.ts.map +1 -1
- package/esm/utils/logger.js.map +1 -1
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js.map +1 -1
- package/esm/utils.mjs +22 -9
- package/esm/validators/allocation-validator.d.ts.map +1 -1
- package/esm/validators/allocation-validator.js.map +1 -1
- package/esm/validators/allocation-validator.mjs +6 -6
- package/getToken.cjs +24 -12
- package/getToken.d.ts +1 -1
- package/package.json +1 -1
- package/prismaClient.d.ts +1 -1
- package/resolvers/custom/OptionsGreeksHistoryCustomResolver.cjs +2 -2
- package/resolvers/custom/OptionsGreeksHistoryCustomResolver.js.map +1 -1
- package/resolvers/custom/OptionsGreeksHistorySystemSummary.cjs +4 -4
- package/resolvers/custom/OptionsGreeksHistorySystemSummary.js.map +1 -1
- package/server.cjs +58 -19
- package/utils.cjs +22 -9
package/getToken.cjs
CHANGED
|
@@ -56,14 +56,17 @@ function generateUUID() {
|
|
|
56
56
|
return crypto.randomUUID();
|
|
57
57
|
}
|
|
58
58
|
// Fallback for older Node.js versions
|
|
59
|
-
return (1e7 + -1e3 + -4e3 + -8e3 + -1e11)
|
|
59
|
+
return (1e7 + -1e3 + -4e3 + -8e3 + -1e11)
|
|
60
|
+
.toString()
|
|
61
|
+
.replace(/[018]/g, (c) => (parseInt(c, 16) ^
|
|
60
62
|
(crypto.randomBytes(1)[0] & (15 >> (parseInt(c, 16) / 4)))).toString(16));
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
65
|
* Base64 URL Encode
|
|
64
66
|
*/
|
|
65
67
|
function base64UrlEncode(buffer) {
|
|
66
|
-
return buffer
|
|
68
|
+
return buffer
|
|
69
|
+
.toString('base64')
|
|
67
70
|
.replace(/=/g, '')
|
|
68
71
|
.replace(/\+/g, '-')
|
|
69
72
|
.replace(/\//g, '_');
|
|
@@ -85,7 +88,7 @@ function base64UrlDecode(str) {
|
|
|
85
88
|
async function encryptJWT(payload, encryptionKey) {
|
|
86
89
|
const header = {
|
|
87
90
|
alg: 'dir',
|
|
88
|
-
enc: 'A256GCM'
|
|
91
|
+
enc: 'A256GCM',
|
|
89
92
|
};
|
|
90
93
|
const iv = crypto.randomBytes(12); // 96-bit nonce for GCM
|
|
91
94
|
const cipher = crypto.createCipheriv('aes-256-gcm', encryptionKey, iv);
|
|
@@ -97,7 +100,7 @@ async function encryptJWT(payload, encryptionKey) {
|
|
|
97
100
|
'', // Encrypted Key (empty for 'dir')
|
|
98
101
|
base64UrlEncode(iv), // IV
|
|
99
102
|
base64UrlEncode(ciphertext), // Ciphertext
|
|
100
|
-
base64UrlEncode(authTag) // Authentication Tag
|
|
103
|
+
base64UrlEncode(authTag), // Authentication Tag
|
|
101
104
|
].join('.');
|
|
102
105
|
return jwe;
|
|
103
106
|
}
|
|
@@ -109,7 +112,7 @@ async function decryptJWT(jwe, encryptionKey) {
|
|
|
109
112
|
if (parts.length !== 5) {
|
|
110
113
|
throw new Error('Invalid JWE format');
|
|
111
114
|
}
|
|
112
|
-
const [encodedHeader, encryptedKey, encodedIV, encodedCiphertext, encodedAuthTag] = parts;
|
|
115
|
+
const [encodedHeader, encryptedKey, encodedIV, encodedCiphertext, encodedAuthTag,] = parts;
|
|
113
116
|
if (encryptedKey !== '') {
|
|
114
117
|
throw new Error('Encrypted Key must be empty for "dir" algorithm');
|
|
115
118
|
}
|
|
@@ -137,7 +140,9 @@ async function decryptJWT(jwe, encryptionKey) {
|
|
|
137
140
|
*/
|
|
138
141
|
async function getDerivedEncryptionKey(keyMaterial, salt) {
|
|
139
142
|
return new Promise((resolve, reject) => {
|
|
140
|
-
const ikm = typeof keyMaterial === 'string'
|
|
143
|
+
const ikm = typeof keyMaterial === 'string'
|
|
144
|
+
? buffer_1.Buffer.from(keyMaterial, 'utf8')
|
|
145
|
+
: keyMaterial;
|
|
141
146
|
const saltBuffer = buffer_1.Buffer.from(salt, 'utf8');
|
|
142
147
|
const info = buffer_1.Buffer.from(`NextAuth.js Generated Encryption Key${salt ? ` (${salt})` : ''}`, 'utf8');
|
|
143
148
|
crypto.hkdf('sha256', ikm, saltBuffer, info, 32, (err, derivedKey) => {
|
|
@@ -160,7 +165,7 @@ async function encode(params) {
|
|
|
160
165
|
...token,
|
|
161
166
|
iat: now(),
|
|
162
167
|
exp: now() + maxAge,
|
|
163
|
-
jti: generateUUID()
|
|
168
|
+
jti: generateUUID(),
|
|
164
169
|
};
|
|
165
170
|
return await encryptJWT(payload, encryptionSecret);
|
|
166
171
|
}
|
|
@@ -199,14 +204,16 @@ class SessionStore {
|
|
|
199
204
|
}
|
|
200
205
|
parseCookie(cookies, headers = {}) {
|
|
201
206
|
// If cookies are provided as an object
|
|
202
|
-
if (typeof cookies === 'object' &&
|
|
207
|
+
if (typeof cookies === 'object' &&
|
|
208
|
+
cookies !== null &&
|
|
209
|
+
!Array.isArray(cookies)) {
|
|
203
210
|
const cookieObj = cookies;
|
|
204
211
|
return cookieObj[this.name] || null;
|
|
205
212
|
}
|
|
206
213
|
// If cookies are provided as a string
|
|
207
214
|
if (typeof cookies === 'string') {
|
|
208
215
|
const parsedCookies = {};
|
|
209
|
-
cookies.split(';').forEach(cookie => {
|
|
216
|
+
cookies.split(';').forEach((cookie) => {
|
|
210
217
|
const [key, ...val] = cookie.trim().split('=');
|
|
211
218
|
parsedCookies[key] = val.join('=');
|
|
212
219
|
});
|
|
@@ -215,7 +222,7 @@ class SessionStore {
|
|
|
215
222
|
// Fallback: Try to parse from headers
|
|
216
223
|
if (headers && headers.cookie && typeof headers.cookie === 'string') {
|
|
217
224
|
const parsedCookies = {};
|
|
218
|
-
headers.cookie.split(';').forEach(cookie => {
|
|
225
|
+
headers.cookie.split(';').forEach((cookie) => {
|
|
219
226
|
const [key, ...val] = cookie.trim().split('=');
|
|
220
227
|
parsedCookies[key] = decodeURIComponent(val.join('='));
|
|
221
228
|
});
|
|
@@ -229,14 +236,19 @@ class SessionStore {
|
|
|
229
236
|
*/
|
|
230
237
|
async function getToken(params) {
|
|
231
238
|
var _a, _b;
|
|
232
|
-
const { req, secureCookie = ((_b = (_a = process.env.NEXTAUTH_URL) === null || _a === void 0 ? void 0 : _a.startsWith('https://')) !== null && _b !== void 0 ? _b : false) ||
|
|
239
|
+
const { req, secureCookie = ((_b = (_a = process.env.NEXTAUTH_URL) === null || _a === void 0 ? void 0 : _a.startsWith('https://')) !== null && _b !== void 0 ? _b : false) ||
|
|
240
|
+
!!process.env.VERCEL, cookieName = secureCookie
|
|
241
|
+
? '__Secure-next-auth.session-token'
|
|
242
|
+
: 'next-auth.session-token', raw = false, decode: _decode = decode, logger = defaultLogger, secret = jwtConfig_1.jwtSecret, salt = process.env.JWT_SALT || '', } = params;
|
|
233
243
|
if (!req)
|
|
234
244
|
throw new Error('Must pass `req` to JWT getToken()');
|
|
235
245
|
const sessionStore = new SessionStore({ name: cookieName, options: { secure: secureCookie } }, req, logger);
|
|
236
246
|
let token = sessionStore.value;
|
|
237
247
|
// Check Authorization header for Bearer token
|
|
238
248
|
const authorizationHeader = req.headers && req.headers['authorization'];
|
|
239
|
-
if (!token &&
|
|
249
|
+
if (!token &&
|
|
250
|
+
typeof authorizationHeader === 'string' &&
|
|
251
|
+
authorizationHeader.startsWith('Bearer ')) {
|
|
240
252
|
const urlEncodedToken = authorizationHeader.split(' ')[1];
|
|
241
253
|
token = decodeURIComponent(urlEncodedToken);
|
|
242
254
|
logger.info('Token found in Authorization header');
|
package/getToken.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptic/backend-legacy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
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/prismaClient.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ let OptionsGreeksHistoryCustomResolver = class OptionsGreeksHistoryCustomResolve
|
|
|
98
98
|
};
|
|
99
99
|
exports.OptionsGreeksHistoryCustomResolver = OptionsGreeksHistoryCustomResolver;
|
|
100
100
|
__decorate([
|
|
101
|
-
TypeGraphQL.Query(_returns => OptionsGreeksHistorySystemSummary_1.OptionsGreeksHistorySystemSummary, {
|
|
101
|
+
TypeGraphQL.Query((_returns) => OptionsGreeksHistorySystemSummary_1.OptionsGreeksHistorySystemSummary, {
|
|
102
102
|
nullable: false,
|
|
103
103
|
description: 'Get system-wide summary statistics for Greeks history data',
|
|
104
104
|
}),
|
|
@@ -108,6 +108,6 @@ __decorate([
|
|
|
108
108
|
__metadata("design:returntype", Promise)
|
|
109
109
|
], OptionsGreeksHistoryCustomResolver.prototype, "optionsGreeksHistorySystemSummary", null);
|
|
110
110
|
exports.OptionsGreeksHistoryCustomResolver = OptionsGreeksHistoryCustomResolver = __decorate([
|
|
111
|
-
TypeGraphQL.Resolver(_of => PortfolioGreeksHistory_1.PortfolioGreeksHistory)
|
|
111
|
+
TypeGraphQL.Resolver((_of) => PortfolioGreeksHistory_1.PortfolioGreeksHistory)
|
|
112
112
|
], OptionsGreeksHistoryCustomResolver);
|
|
113
113
|
//# sourceMappingURL=OptionsGreeksHistoryCustomResolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionsGreeksHistoryCustomResolver.js","sourceRoot":"","sources":["../../../src/resolvers/custom/OptionsGreeksHistoryCustomResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4C;AAE5C,6GAA0G;AAC1G,2FAAwF;AACxF,wEAAkF;AAOlF;;;;GAIG;AAEI,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAC7C;;;OAGG;IAKG,AAAN,KAAK,CAAC,iCAAiC,CAClB,GAAmB;QAEtC,MAAM,MAAM,GAAG,IAAA,8BAAoB,EAAC,GAAG,CAAC,CAAC;QAEzC,4BAA4B;QAC5B,yBAAyB;QACzB,SAAS;QACT,kDAAkD;QAClD,iCAAiC;QACjC,uCAAuC;QACvC,sCAAsC;QACtC,gCAAgC;QAChC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACtD,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAAC;gBACtC,IAAI,EAAE;oBACJ,SAAS,EAAE,IAAI;iBAChB;gBACD,IAAI,EAAE;oBACJ,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;YACF,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE;SACtC,CAAC,CAAC;QAEH,iDAAiD;QACjD,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACnE,EAAE,EAAE,CAAC,WAAW,CAAC;YACjB,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF,CAAC,CAAC;QAEH,OAAO;YACL,aAAa,EAAE,gBAAgB,CAAC,MAAM;YACtC,cAAc,EAAE,UAAU;YAC1B,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,SAAS;YAC9C,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,SAAS;SAC/C,CAAC;IACJ,CAAC;CACF,CAAA;AAjDY,gFAAkC;AASvC;IAJL,WAAW,CAAC,KAAK,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"OptionsGreeksHistoryCustomResolver.js","sourceRoot":"","sources":["../../../src/resolvers/custom/OptionsGreeksHistoryCustomResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4C;AAE5C,6GAA0G;AAC1G,2FAAwF;AACxF,wEAAkF;AAOlF;;;;GAIG;AAEI,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAC7C;;;OAGG;IAKG,AAAN,KAAK,CAAC,iCAAiC,CAClB,GAAmB;QAEtC,MAAM,MAAM,GAAG,IAAA,8BAAoB,EAAC,GAAG,CAAC,CAAC;QAEzC,4BAA4B;QAC5B,yBAAyB;QACzB,SAAS;QACT,kDAAkD;QAClD,iCAAiC;QACjC,uCAAuC;QACvC,sCAAsC;QACtC,gCAAgC;QAChC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACtD,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAAC;gBACtC,IAAI,EAAE;oBACJ,SAAS,EAAE,IAAI;iBAChB;gBACD,IAAI,EAAE;oBACJ,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;YACF,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE;SACtC,CAAC,CAAC;QAEH,iDAAiD;QACjD,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACnE,EAAE,EAAE,CAAC,WAAW,CAAC;YACjB,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI;aAChB;SACF,CAAC,CAAC;QAEH,OAAO;YACL,aAAa,EAAE,gBAAgB,CAAC,MAAM;YACtC,cAAc,EAAE,UAAU;YAC1B,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,SAAS;YAC9C,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,SAAS;SAC/C,CAAC;IACJ,CAAC;CACF,CAAA;AAjDY,gFAAkC;AASvC;IAJL,WAAW,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,qEAAiC,EAAE;QAClE,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,4DAA4D;KAC1E,CAAC;IAEC,WAAA,WAAW,CAAC,GAAG,EAAE,CAAA;;;;2FAsCnB;6CAhDU,kCAAkC;IAD9C,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,+CAAsB,CAAC;GACzC,kCAAkC,CAiD9C"}
|
|
@@ -51,28 +51,28 @@ let OptionsGreeksHistorySystemSummary = class OptionsGreeksHistorySystemSummary
|
|
|
51
51
|
};
|
|
52
52
|
exports.OptionsGreeksHistorySystemSummary = OptionsGreeksHistorySystemSummary;
|
|
53
53
|
__decorate([
|
|
54
|
-
TypeGraphQL.Field(_type => TypeGraphQL.Int, {
|
|
54
|
+
TypeGraphQL.Field((_type) => TypeGraphQL.Int, {
|
|
55
55
|
nullable: false,
|
|
56
56
|
description: 'Total number of unique accounts with Greeks history',
|
|
57
57
|
}),
|
|
58
58
|
__metadata("design:type", Number)
|
|
59
59
|
], OptionsGreeksHistorySystemSummary.prototype, "totalAccounts", void 0);
|
|
60
60
|
__decorate([
|
|
61
|
-
TypeGraphQL.Field(_type => TypeGraphQL.Int, {
|
|
61
|
+
TypeGraphQL.Field((_type) => TypeGraphQL.Int, {
|
|
62
62
|
nullable: false,
|
|
63
63
|
description: 'Total number of Greeks snapshots across all accounts',
|
|
64
64
|
}),
|
|
65
65
|
__metadata("design:type", Number)
|
|
66
66
|
], OptionsGreeksHistorySystemSummary.prototype, "totalSnapshots", void 0);
|
|
67
67
|
__decorate([
|
|
68
|
-
TypeGraphQL.Field(_type => Date, {
|
|
68
|
+
TypeGraphQL.Field((_type) => Date, {
|
|
69
69
|
nullable: true,
|
|
70
70
|
description: 'Timestamp of the oldest Greeks snapshot in the system',
|
|
71
71
|
}),
|
|
72
72
|
__metadata("design:type", Object)
|
|
73
73
|
], OptionsGreeksHistorySystemSummary.prototype, "oldestSnapshot", void 0);
|
|
74
74
|
__decorate([
|
|
75
|
-
TypeGraphQL.Field(_type => Date, {
|
|
75
|
+
TypeGraphQL.Field((_type) => Date, {
|
|
76
76
|
nullable: true,
|
|
77
77
|
description: 'Timestamp of the newest Greeks snapshot in the system',
|
|
78
78
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionsGreeksHistorySystemSummary.js","sourceRoot":"","sources":["../../../src/resolvers/custom/OptionsGreeksHistorySystemSummary.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4C;AAE5C;;GAEG;AAEI,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;CAwB7C,CAAA;AAxBY,8EAAiC;AAK5C;IAJC,WAAW,CAAC,KAAK,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"OptionsGreeksHistorySystemSummary.js","sourceRoot":"","sources":["../../../src/resolvers/custom/OptionsGreeksHistorySystemSummary.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4C;AAE5C;;GAEG;AAEI,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;CAwB7C,CAAA;AAxBY,8EAAiC;AAK5C;IAJC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;QAC7C,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,qDAAqD;KACnE,CAAC;;wEACqB;AAMvB;IAJC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;QAC7C,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,sDAAsD;KACpE,CAAC;;yEACsB;AAMxB;IAJC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE;QAClC,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,uDAAuD;KACrE,CAAC;;yEAC2B;AAM7B;IAJC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE;QAClC,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,uDAAuD;KACrE,CAAC;;yEAC2B;4CAvBlB,iCAAiC;IAD7C,WAAW,CAAC,UAAU,CAAC,mCAAmC,EAAE,EAAE,CAAC;GACnD,iCAAiC,CAwB7C"}
|
package/server.cjs
CHANGED
|
@@ -41,10 +41,14 @@ async function restartDatabase() {
|
|
|
41
41
|
const deployCommand = `RAILWAY_TOKEN=${projectToken || ''} RAILWAY_API_TOKEN=${apiToken || ''} railway redeploy --service Postgres -y`;
|
|
42
42
|
(0, child_process_1.exec)(deployCommand, {
|
|
43
43
|
env: process.env,
|
|
44
|
-
shell: '/bin/sh'
|
|
44
|
+
shell: '/bin/sh',
|
|
45
45
|
}, (error, stdout, stderr) => {
|
|
46
46
|
if (error) {
|
|
47
|
-
logger_1.logger.error('Failed to redeploy DB via Railway CLI', {
|
|
47
|
+
logger_1.logger.error('Failed to redeploy DB via Railway CLI', {
|
|
48
|
+
error: String(error),
|
|
49
|
+
stdout,
|
|
50
|
+
stderr,
|
|
51
|
+
});
|
|
48
52
|
return reject(error);
|
|
49
53
|
}
|
|
50
54
|
logger_1.logger.info('Railway deployment output', { stdout });
|
|
@@ -87,17 +91,23 @@ const startServer = async () => {
|
|
|
87
91
|
dbUnreachableCount = 0;
|
|
88
92
|
}
|
|
89
93
|
catch (restartError) {
|
|
90
|
-
logger_1.logger.error('Error trying to restart DB', {
|
|
94
|
+
logger_1.logger.error('Error trying to restart DB', {
|
|
95
|
+
restartError: String(restartError),
|
|
96
|
+
});
|
|
91
97
|
// If the restart fails, we can try again after a delay
|
|
92
98
|
const backoffTime = Math.min(30000, 1000 * Math.pow(2, dbUnreachableCount - 3)); // Exponential backoff with a max of 30 seconds
|
|
93
|
-
logger_1.logger.info('Waiting before next restart attempt', {
|
|
99
|
+
logger_1.logger.info('Waiting before next restart attempt', {
|
|
100
|
+
backoffSeconds: backoffTime / 1000,
|
|
101
|
+
});
|
|
94
102
|
setTimeout(() => {
|
|
95
103
|
restartDatabase()
|
|
96
104
|
.then(() => {
|
|
97
105
|
dbUnreachableCount = 0; // Reset the counter after a successful restart
|
|
98
106
|
})
|
|
99
107
|
.catch((restartError) => {
|
|
100
|
-
logger_1.logger.error('Error trying to restart DB', {
|
|
108
|
+
logger_1.logger.error('Error trying to restart DB', {
|
|
109
|
+
restartError: String(restartError),
|
|
110
|
+
});
|
|
101
111
|
// We do not reset the counter here if the restart fails,
|
|
102
112
|
// so it can try again next time.
|
|
103
113
|
});
|
|
@@ -126,7 +136,7 @@ const startServer = async () => {
|
|
|
126
136
|
// Health check endpoint - mounted before Apollo middleware so it's not behind GraphQL or auth
|
|
127
137
|
app.use((0, health_1.createHealthRouter)());
|
|
128
138
|
// Configure CORS with allowed origins
|
|
129
|
-
const defaultOrigins = ['http://localhost:3000', 'http://localhost:3001', 'https://adaptic.ai', 'https://api.adaptic.ai'];
|
|
139
|
+
const defaultOrigins = ['http://localhost:3000', 'http://localhost:3001', 'http://localhost:4000', 'https://adaptic.ai', 'https://api.adaptic.ai'];
|
|
130
140
|
const envOrigins = process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(',').map(o => o.trim()) : [];
|
|
131
141
|
const allowedOrigins = [...new Set([...defaultOrigins, ...envOrigins])];
|
|
132
142
|
const corsOptions = {
|
|
@@ -156,7 +166,9 @@ const startServer = async () => {
|
|
|
156
166
|
// Extract token from Authorization header
|
|
157
167
|
const authHeader = req.headers.authorization || '';
|
|
158
168
|
// Only try to verify token if it's in proper Bearer format
|
|
159
|
-
const token = authHeader.startsWith('Bearer ')
|
|
169
|
+
const token = authHeader.startsWith('Bearer ')
|
|
170
|
+
? authHeader.split(' ')[1]
|
|
171
|
+
: '';
|
|
160
172
|
let user = null;
|
|
161
173
|
if (token) {
|
|
162
174
|
// Check if token is a Google OAuth token (starts with ya29.)
|
|
@@ -171,9 +183,15 @@ const startServer = async () => {
|
|
|
171
183
|
if (tokenParts.length !== 3) {
|
|
172
184
|
// Log only once per unique malformed token to avoid log spam
|
|
173
185
|
const tokenPreview = token.length > 20 ? `${token.substring(0, 20)}...` : token;
|
|
174
|
-
logger_1.logger.warn('Received malformed token (not a valid JWT format)', {
|
|
186
|
+
logger_1.logger.warn('Received malformed token (not a valid JWT format)', {
|
|
187
|
+
tokenPreview,
|
|
188
|
+
});
|
|
175
189
|
// Continue without authentication - don't fail the request
|
|
176
|
-
return {
|
|
190
|
+
return {
|
|
191
|
+
prisma: global.prisma,
|
|
192
|
+
req,
|
|
193
|
+
authError: 'Malformed token: expected JWT format (header.payload.signature)',
|
|
194
|
+
};
|
|
177
195
|
}
|
|
178
196
|
// For regular JWT tokens, verify using the centralized secret
|
|
179
197
|
try {
|
|
@@ -219,8 +237,11 @@ const startServer = async () => {
|
|
|
219
237
|
logger_1.logger.warn('Prisma client not found in global scope for WebSocket context, reinitializing');
|
|
220
238
|
global.prisma = prismaClient_1.default;
|
|
221
239
|
}
|
|
222
|
-
const authHeader = ((_a = ctx.connectionParams) === null || _a === void 0 ? void 0 : _a.authorization) ||
|
|
223
|
-
|
|
240
|
+
const authHeader = ((_a = ctx.connectionParams) === null || _a === void 0 ? void 0 : _a.authorization) ||
|
|
241
|
+
'';
|
|
242
|
+
const token = authHeader.startsWith('Bearer ')
|
|
243
|
+
? authHeader.split(' ')[1]
|
|
244
|
+
: '';
|
|
224
245
|
let user = null;
|
|
225
246
|
if (token) {
|
|
226
247
|
// Check if token is a Google OAuth token (starts with ya29.)
|
|
@@ -243,7 +264,9 @@ const startServer = async () => {
|
|
|
243
264
|
}
|
|
244
265
|
catch (e) {
|
|
245
266
|
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
246
|
-
logger_1.logger.warn('WebSocket JWT verification failed', {
|
|
267
|
+
logger_1.logger.warn('WebSocket JWT verification failed', {
|
|
268
|
+
errorMessage,
|
|
269
|
+
});
|
|
247
270
|
return { prisma: global.prisma, authError: 'Invalid token' };
|
|
248
271
|
}
|
|
249
272
|
}
|
|
@@ -253,19 +276,31 @@ const startServer = async () => {
|
|
|
253
276
|
}, wsServer);
|
|
254
277
|
const PORT = process.env.PORT || 4000;
|
|
255
278
|
httpServer.listen(PORT, () => {
|
|
256
|
-
logger_1.logger.info('Server ready', {
|
|
257
|
-
|
|
279
|
+
logger_1.logger.info('Server ready', {
|
|
280
|
+
graphql: `http://localhost:${PORT}/graphql`,
|
|
281
|
+
health: `http://localhost:${PORT}/health`,
|
|
282
|
+
});
|
|
283
|
+
logger_1.logger.info('Subscriptions ready', {
|
|
284
|
+
endpoint: `ws://localhost:${PORT}/subscriptions`,
|
|
285
|
+
});
|
|
258
286
|
});
|
|
259
287
|
};
|
|
260
288
|
startServer().catch((error) => {
|
|
261
|
-
logger_1.logger.error('Error starting the server', {
|
|
289
|
+
logger_1.logger.error('Error starting the server', {
|
|
290
|
+
error: error instanceof Error ? error.message : String(error),
|
|
291
|
+
});
|
|
262
292
|
process.exit(1);
|
|
263
293
|
});
|
|
264
294
|
process.on('unhandledRejection', (reason, _promise) => {
|
|
265
|
-
logger_1.logger.error('Unhandled Rejection', {
|
|
295
|
+
logger_1.logger.error('Unhandled Rejection', {
|
|
296
|
+
reason: reason instanceof Error ? reason.message : String(reason),
|
|
297
|
+
});
|
|
266
298
|
});
|
|
267
299
|
process.on('uncaughtException', (error) => {
|
|
268
|
-
logger_1.logger.error('Uncaught Exception', {
|
|
300
|
+
logger_1.logger.error('Uncaught Exception', {
|
|
301
|
+
error: error.message,
|
|
302
|
+
stack: error.stack,
|
|
303
|
+
});
|
|
269
304
|
});
|
|
270
305
|
// Only disconnect Prisma when the process is truly shutting down
|
|
271
306
|
process.on('SIGINT', async () => {
|
|
@@ -276,7 +311,9 @@ process.on('SIGINT', async () => {
|
|
|
276
311
|
logger_1.logger.info('Database connections closed successfully');
|
|
277
312
|
}
|
|
278
313
|
catch (e) {
|
|
279
|
-
logger_1.logger.error('Error disconnecting from database', {
|
|
314
|
+
logger_1.logger.error('Error disconnecting from database', {
|
|
315
|
+
error: e instanceof Error ? e.message : String(e),
|
|
316
|
+
});
|
|
280
317
|
}
|
|
281
318
|
process.exit(0);
|
|
282
319
|
});
|
|
@@ -289,7 +326,9 @@ process.on('SIGTERM', async () => {
|
|
|
289
326
|
logger_1.logger.info('Database connections closed successfully');
|
|
290
327
|
}
|
|
291
328
|
catch (e) {
|
|
292
|
-
logger_1.logger.error('Error disconnecting from database', {
|
|
329
|
+
logger_1.logger.error('Error disconnecting from database', {
|
|
330
|
+
error: e instanceof Error ? e.message : String(e),
|
|
331
|
+
});
|
|
293
332
|
}
|
|
294
333
|
process.exit(0);
|
|
295
334
|
});
|
package/utils.cjs
CHANGED
|
@@ -15,22 +15,31 @@ exports.removeUndefinedProps = removeUndefinedProps;
|
|
|
15
15
|
function removeUndefinedProps(obj) {
|
|
16
16
|
if (Array.isArray(obj)) {
|
|
17
17
|
return obj
|
|
18
|
-
.map(item => removeUndefinedProps(item))
|
|
19
|
-
.filter(item => item !== undefined &&
|
|
18
|
+
.map((item) => removeUndefinedProps(item))
|
|
19
|
+
.filter((item) => item !== undefined &&
|
|
20
20
|
item !== null &&
|
|
21
|
-
(typeof item !== 'object' ||
|
|
21
|
+
(typeof item !== 'object' ||
|
|
22
|
+
Object.keys(item).length > 0));
|
|
22
23
|
}
|
|
23
|
-
else if (typeof obj === 'object' &&
|
|
24
|
+
else if (typeof obj === 'object' &&
|
|
25
|
+
obj !== null &&
|
|
26
|
+
!(obj instanceof Date)) {
|
|
24
27
|
const record = obj;
|
|
25
28
|
return Object.keys(record).reduce((acc, key) => {
|
|
26
29
|
const value = record[key];
|
|
27
30
|
if (value !== undefined && value !== null) {
|
|
28
31
|
let cleanedValue;
|
|
29
|
-
if (key === 'where' &&
|
|
32
|
+
if (key === 'where' &&
|
|
33
|
+
typeof value === 'object' &&
|
|
34
|
+
value !== null &&
|
|
35
|
+
!(value instanceof Date)) {
|
|
30
36
|
const whereObj = value;
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(whereObj, 'id') &&
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(whereObj, 'id') &&
|
|
38
|
+
whereObj.id !== undefined) {
|
|
32
39
|
// Retain only the 'id' field within 'where'
|
|
33
|
-
cleanedValue = {
|
|
40
|
+
cleanedValue = {
|
|
41
|
+
id: removeUndefinedProps(whereObj.id),
|
|
42
|
+
};
|
|
34
43
|
}
|
|
35
44
|
else {
|
|
36
45
|
// Process 'where' object normally if 'id' is undefined or doesn't exist
|
|
@@ -43,13 +52,17 @@ function removeUndefinedProps(obj) {
|
|
|
43
52
|
}
|
|
44
53
|
if (cleanedValue !== undefined &&
|
|
45
54
|
cleanedValue !== null &&
|
|
46
|
-
(typeof cleanedValue !== 'object' ||
|
|
55
|
+
(typeof cleanedValue !== 'object' ||
|
|
56
|
+
cleanedValue instanceof Date ||
|
|
57
|
+
Object.keys(cleanedValue).length > 0)) {
|
|
47
58
|
acc[key] = cleanedValue;
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
61
|
return acc;
|
|
51
62
|
}, {});
|
|
52
63
|
}
|
|
53
|
-
return obj !== undefined && obj !== null
|
|
64
|
+
return obj !== undefined && obj !== null
|
|
65
|
+
? obj
|
|
66
|
+
: undefined;
|
|
54
67
|
}
|
|
55
68
|
//# sourceMappingURL=utils.js.map
|