@terreno/api 0.31.0 → 56.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -2
- package/LICENSE +202 -21
- package/dist/api.d.ts +12 -3
- package/dist/api.js +110 -361
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +100 -1
- package/dist/betterAuth.d.ts +5 -0
- package/dist/betterAuthSetup.d.ts +1 -15
- package/dist/betterAuthSetup.js +29 -8
- package/dist/configurationPlugin.js +2 -2
- package/dist/docLoader.js +12 -9
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +29 -1
- package/dist/expressServer.js +5 -11
- package/dist/githubAuth.js +4 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -1
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +16 -1
- package/dist/openApiCompat.d.ts +10 -1
- package/dist/openApiCompat.js +115 -47
- package/dist/permissions.d.ts +27 -0
- package/dist/permissions.js +42 -1
- package/dist/plugins.d.ts +15 -3
- package/dist/plugins.js +36 -6
- package/dist/realtime/changeStreamWatcher.d.ts +100 -3
- package/dist/realtime/changeStreamWatcher.js +542 -137
- package/dist/realtime/realtimeApp.d.ts +3 -1
- package/dist/realtime/realtimeApp.js +75 -27
- package/dist/realtime/sessionRevalidation.d.ts +90 -0
- package/dist/realtime/sessionRevalidation.js +438 -0
- package/dist/realtime/socketAuth.d.ts +97 -0
- package/dist/realtime/socketAuth.js +272 -0
- package/dist/realtime/socketUser.d.ts +54 -0
- package/dist/realtime/socketUser.js +75 -5
- package/dist/realtime/types.d.ts +40 -0
- package/dist/secretProviders.d.ts +23 -0
- package/dist/secretProviders.js +9 -3
- package/dist/sync/executors.d.ts +198 -0
- package/dist/sync/executors.js +670 -0
- package/dist/sync/loadHarness.js +807 -0
- package/dist/sync/models.d.ts +216 -0
- package/dist/sync/models.js +644 -0
- package/dist/sync/mutationHandler.d.ts +97 -0
- package/dist/sync/mutationHandler.js +886 -0
- package/dist/sync/registry.d.ts +73 -0
- package/dist/sync/registry.js +223 -0
- package/dist/sync/routes.d.ts +62 -0
- package/dist/sync/routes.js +936 -0
- package/dist/sync/scripts/compactTombstones.d.ts +47 -0
- package/dist/sync/scripts/compactTombstones.js +270 -0
- package/dist/sync/serialize.d.ts +20 -0
- package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
- package/dist/sync/socketHandlers.d.ts +54 -0
- package/dist/sync/socketHandlers.js +470 -0
- package/dist/sync/streams.d.ts +85 -0
- package/dist/sync/streams.js +221 -0
- package/dist/sync/syncApp.d.ts +29 -0
- package/dist/sync/syncApp.js +44 -0
- package/dist/sync/syncBatch.d.ts +71 -0
- package/dist/sync/syncBatch.js +252 -0
- package/dist/sync/syncSeqPlugin.d.ts +8 -0
- package/dist/sync/syncSeqPlugin.js +903 -0
- package/dist/sync/types.d.ts +254 -0
- package/dist/sync/types.js +9 -0
- package/dist/terrenoApp.js +90 -27
- package/dist/tests/models.d.ts +11 -27
- package/dist/tests/models.js +3 -5
- package/dist/tests/testHelper.d.ts +3 -9
- package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
- package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
- package/package.json +10 -8
- package/src/__tests__/openApiCompat.test.ts +20 -0
- package/src/actions.test.ts +12 -19
- package/src/actions.ts +2 -2
- package/src/api.coverage.test.ts +9 -7
- package/src/api.errorPaths.test.ts +1 -47
- package/src/api.test.ts +12 -0
- package/src/api.ts +98 -317
- package/src/auth.test.ts +128 -176
- package/src/auth.ts +109 -0
- package/src/betterAuth.ts +6 -0
- package/src/betterAuthSetup.test.ts +34 -0
- package/src/betterAuthSetup.ts +27 -8
- package/src/configurationPlugin.ts +2 -2
- package/src/consentApp.test.ts +12 -12
- package/src/docLoader.ts +3 -1
- package/src/errors.ts +33 -0
- package/src/expressServer.test.ts +7 -1
- package/src/expressServer.ts +5 -11
- package/src/githubAuth.ts +3 -1
- package/src/index.ts +42 -0
- package/src/middleware.test.ts +40 -1
- package/src/middleware.ts +15 -0
- package/src/models/versionConfig.ts +1 -1
- package/src/openApiBuilder.test.ts +9 -24
- package/src/openApiCompat.ts +99 -45
- package/src/openApiValidator.test.ts +0 -41
- package/src/permissions.test.ts +75 -1
- package/src/permissions.ts +49 -0
- package/src/plugins.test.ts +54 -14
- package/src/plugins.ts +47 -9
- package/src/populate.test.ts +16 -25
- package/src/realtime/changeStreamWatcher.ts +552 -114
- package/src/realtime/realtime.test.ts +157 -239
- package/src/realtime/realtimeApp.ts +80 -19
- package/src/realtime/sessionRevalidation.test.ts +423 -0
- package/src/realtime/sessionRevalidation.ts +273 -0
- package/src/realtime/socketAuth.test.ts +355 -0
- package/src/realtime/socketAuth.ts +228 -0
- package/src/realtime/socketUser.ts +69 -0
- package/src/realtime/types.ts +40 -0
- package/src/secretProviders.test.ts +7 -1
- package/src/secretProviders.ts +15 -3
- package/src/sync/ensureSyncIndexes.test.ts +144 -0
- package/src/sync/executors.test.ts +882 -0
- package/src/sync/executors.ts +703 -0
- package/src/sync/integration.test.ts +1160 -0
- package/src/sync/loadHarness.ts +618 -0
- package/src/sync/models.ts +640 -0
- package/src/sync/mutationHandler.test.ts +1252 -0
- package/src/sync/mutationHandler.ts +850 -0
- package/src/sync/registry.ts +232 -0
- package/src/sync/routes.ts +812 -0
- package/src/sync/scripts/compactTombstones.test.ts +249 -0
- package/src/sync/scripts/compactTombstones.ts +145 -0
- package/src/sync/serialize.ts +48 -0
- package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
- package/src/sync/socketHandlers.ts +320 -0
- package/src/sync/streams.ts +188 -0
- package/src/sync/sync.test.ts +582 -0
- package/src/sync/syncApp.ts +44 -0
- package/src/sync/syncBatch.ts +219 -0
- package/src/sync/syncFrontier.test.ts +494 -0
- package/src/sync/syncPhaseC.test.ts +718 -0
- package/src/sync/syncRoutes.test.ts +865 -0
- package/src/sync/syncSeqPlugin.ts +738 -0
- package/src/sync/syncSocket.test.ts +1440 -0
- package/src/sync/types.ts +270 -0
- package/src/terrenoApp.ts +37 -17
- package/src/tests/bunSetup.ts +8 -0
- package/src/tests/models.ts +6 -8
- package/tsconfig.json +4 -4
- package/tsconfig.typedoc.json +7 -1
- package/dist/__tests__/openApiCompat.test.js +0 -317
- package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
- package/dist/__tests__/versionCheckPlugin.test.js +0 -597
- package/dist/actions.openApi.test.d.ts +0 -1
- package/dist/actions.openApi.test.js +0 -253
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -1087
- package/dist/api.arrayOperations.test.d.ts +0 -1
- package/dist/api.arrayOperations.test.js +0 -878
- package/dist/api.asyncHandler.test.d.ts +0 -1
- package/dist/api.asyncHandler.test.js +0 -236
- package/dist/api.coverage.test.d.ts +0 -1
- package/dist/api.coverage.test.js +0 -192
- package/dist/api.errorPaths.test.d.ts +0 -1
- package/dist/api.errorPaths.test.js +0 -887
- package/dist/api.errors.test.d.ts +0 -1
- package/dist/api.errors.test.js +0 -185
- package/dist/api.hooks.test.d.ts +0 -1
- package/dist/api.hooks.test.js +0 -950
- package/dist/api.query.test.d.ts +0 -1
- package/dist/api.query.test.js +0 -948
- package/dist/api.test.d.ts +0 -1
- package/dist/api.test.js +0 -2820
- package/dist/auth.compile.test.d.ts +0 -1
- package/dist/auth.compile.test.js +0 -201
- package/dist/auth.coverage.test.d.ts +0 -1
- package/dist/auth.coverage.test.js +0 -202
- package/dist/auth.test.d.ts +0 -1
- package/dist/auth.test.js +0 -2286
- package/dist/betterAuth.test.d.ts +0 -1
- package/dist/betterAuth.test.js +0 -181
- package/dist/betterAuthApp.test.d.ts +0 -1
- package/dist/betterAuthApp.test.js +0 -242
- package/dist/betterAuthSetup.test.d.ts +0 -1
- package/dist/betterAuthSetup.test.js +0 -762
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -353
- package/dist/configuration.test.d.ts +0 -1
- package/dist/configuration.test.js +0 -980
- package/dist/configurationPlugin.test.d.ts +0 -1
- package/dist/configurationPlugin.test.js +0 -827
- package/dist/consentApp.test.d.ts +0 -1
- package/dist/consentApp.test.js +0 -1411
- package/dist/docLoader.test.d.ts +0 -1
- package/dist/docLoader.test.js +0 -137
- package/dist/envConfigurationPlugin.test.d.ts +0 -1
- package/dist/envConfigurationPlugin.test.js +0 -369
- package/dist/errors.test.d.ts +0 -1
- package/dist/errors.test.js +0 -607
- package/dist/expressServer.test.d.ts +0 -1
- package/dist/expressServer.test.js +0 -1249
- package/dist/githubAuth.test.d.ts +0 -1
- package/dist/githubAuth.test.js +0 -1142
- package/dist/httpClient.test.d.ts +0 -1
- package/dist/httpClient.test.js +0 -1471
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -685
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -241
- package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
- package/dist/notifiers/googleChatNotifier.test.js +0 -298
- package/dist/notifiers/slackNotifier.test.d.ts +0 -1
- package/dist/notifiers/slackNotifier.test.js +0 -297
- package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
- package/dist/notifiers/zoomNotifier.test.js +0 -373
- package/dist/openApi.test.d.ts +0 -1
- package/dist/openApi.test.js +0 -620
- package/dist/openApiBuilder.test.d.ts +0 -1
- package/dist/openApiBuilder.test.js +0 -599
- package/dist/openApiEtag.test.d.ts +0 -1
- package/dist/openApiEtag.test.js +0 -86
- package/dist/openApiValidator.test.d.ts +0 -1
- package/dist/openApiValidator.test.js +0 -795
- package/dist/permissions.middleware.test.d.ts +0 -1
- package/dist/permissions.middleware.test.js +0 -308
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -439
- package/dist/plugins.test.d.ts +0 -1
- package/dist/plugins.test.js +0 -902
- package/dist/populate.test.d.ts +0 -1
- package/dist/populate.test.js +0 -370
- package/dist/realtime/realtime.test.d.ts +0 -10
- package/dist/realtime/realtime.test.js +0 -4213
- package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
- package/dist/realtime/realtimeAppSetup.test.js +0 -213
- package/dist/requestContext.test.d.ts +0 -1
- package/dist/requestContext.test.js +0 -412
- package/dist/scriptRunner.test.d.ts +0 -1
- package/dist/scriptRunner.test.js +0 -386
- package/dist/secretProviders.test.d.ts +0 -1
- package/dist/secretProviders.test.js +0 -726
- package/dist/syncConsents.test.d.ts +0 -1
- package/dist/syncConsents.test.js +0 -522
- package/dist/terrenoApp.test.d.ts +0 -1
- package/dist/terrenoApp.test.js +0 -489
- package/dist/tests/bunSetup.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.js +0 -37
- package/dist/tests/testEnv.d.ts +0 -0
- package/dist/tests/testEnv.js +0 -6
- package/dist/transformers.test.d.ts +0 -1
- package/dist/transformers.test.js +0 -423
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -242
- package/src/realtime/realtimeAppSetup.test.ts +0 -161
- /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
package/dist/auth.d.ts
CHANGED
|
@@ -24,6 +24,32 @@ export interface GenerateTokensOptions {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const authenticateMiddleware: (anonymous?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => any;
|
|
26
26
|
export declare const signupUser: (userModel: UserModel, email: string, password: string, body?: Record<string, unknown>) => Promise<any>;
|
|
27
|
+
/** A user document exposing passport-local-mongoose's `setPassword`. */
|
|
28
|
+
export interface HasSetPassword {
|
|
29
|
+
_id?: unknown;
|
|
30
|
+
id?: string;
|
|
31
|
+
setPassword: (password: string, callback?: (error?: unknown) => void) => Promise<unknown> | unknown;
|
|
32
|
+
}
|
|
33
|
+
/** Upper bound on password length accepted by {@link setPasswordForUser} (D5). */
|
|
34
|
+
export declare const MAX_PASSWORD_LENGTH = 256;
|
|
35
|
+
/** Optional audit context for {@link setPasswordForUser} — never includes the password itself. */
|
|
36
|
+
export interface SetPasswordAuditContext {
|
|
37
|
+
/** The admin performing the change, when set via an admin-only route. */
|
|
38
|
+
adminId?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets a password on a passport-local-mongoose user document, returning a Promise regardless of
|
|
42
|
+
* whether the installed version of `setPassword` is callback- or promise-based. Newer versions
|
|
43
|
+
* return a promise while older ones only invoke the callback; this helper normalizes both and
|
|
44
|
+
* rejects after `timeoutMs` (default 15s) if neither settles. Call `user.save()` afterwards to
|
|
45
|
+
* persist the new hash/salt.
|
|
46
|
+
*
|
|
47
|
+
* Rejects synchronously (before touching `setPassword`) when `password` exceeds
|
|
48
|
+
* {@link MAX_PASSWORD_LENGTH} characters. When `audit.adminId` is provided (an admin-initiated
|
|
49
|
+
* password change), logs a `logger.info` audit line with the admin id, target user id, and
|
|
50
|
+
* timestamp — NEVER the password itself.
|
|
51
|
+
*/
|
|
52
|
+
export declare const setPasswordForUser: (user: HasSetPassword, password: string, timeoutMs?: number, audit?: SetPasswordAuditContext) => Promise<void>;
|
|
27
53
|
/**
|
|
28
54
|
* Generates both an access token (JWT) and a refresh token for a given user.
|
|
29
55
|
*
|
package/dist/auth.js
CHANGED
|
@@ -86,7 +86,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
86
86
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
87
|
};
|
|
88
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
-
exports.addMeRoutes = exports.addAuthRoutes = exports.setupAuth = exports.generateTokens = exports.signupUser = exports.authenticateMiddleware = void 0;
|
|
89
|
+
exports.addMeRoutes = exports.addAuthRoutes = exports.setupAuth = exports.generateTokens = exports.setPasswordForUser = exports.MAX_PASSWORD_LENGTH = exports.signupUser = exports.authenticateMiddleware = void 0;
|
|
90
90
|
var node_crypto_1 = require("node:crypto");
|
|
91
91
|
var express_1 = __importDefault(require("express"));
|
|
92
92
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
@@ -170,6 +170,92 @@ var signupUser = function (userModel, email, password, body) { return __awaiter(
|
|
|
170
170
|
});
|
|
171
171
|
}); };
|
|
172
172
|
exports.signupUser = signupUser;
|
|
173
|
+
/** Upper bound on password length accepted by {@link setPasswordForUser} (D5). */
|
|
174
|
+
exports.MAX_PASSWORD_LENGTH = 256;
|
|
175
|
+
/**
|
|
176
|
+
* Sets a password on a passport-local-mongoose user document, returning a Promise regardless of
|
|
177
|
+
* whether the installed version of `setPassword` is callback- or promise-based. Newer versions
|
|
178
|
+
* return a promise while older ones only invoke the callback; this helper normalizes both and
|
|
179
|
+
* rejects after `timeoutMs` (default 15s) if neither settles. Call `user.save()` afterwards to
|
|
180
|
+
* persist the new hash/salt.
|
|
181
|
+
*
|
|
182
|
+
* Rejects synchronously (before touching `setPassword`) when `password` exceeds
|
|
183
|
+
* {@link MAX_PASSWORD_LENGTH} characters. When `audit.adminId` is provided (an admin-initiated
|
|
184
|
+
* password change), logs a `logger.info` audit line with the admin id, target user id, and
|
|
185
|
+
* timestamp — NEVER the password itself.
|
|
186
|
+
*/
|
|
187
|
+
var setPasswordForUser = function (user_1, password_1) {
|
|
188
|
+
var args_1 = [];
|
|
189
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
190
|
+
args_1[_i - 2] = arguments[_i];
|
|
191
|
+
}
|
|
192
|
+
return __awaiter(void 0, __spreadArray([user_1, password_1], __read(args_1), false), void 0, function (user, password, timeoutMs, audit) {
|
|
193
|
+
var targetUserId;
|
|
194
|
+
var _a, _b;
|
|
195
|
+
if (timeoutMs === void 0) { timeoutMs = 15000; }
|
|
196
|
+
return __generator(this, function (_c) {
|
|
197
|
+
switch (_c.label) {
|
|
198
|
+
case 0:
|
|
199
|
+
if (password.length > exports.MAX_PASSWORD_LENGTH) {
|
|
200
|
+
throw new errors_1.APIError({
|
|
201
|
+
status: 400,
|
|
202
|
+
title: "Password must be at most ".concat(exports.MAX_PASSWORD_LENGTH, " characters"),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if ((audit === null || audit === void 0 ? void 0 : audit.adminId) !== undefined) {
|
|
206
|
+
targetUserId = (_b = (_a = user._id) !== null && _a !== void 0 ? _a : user.id) !== null && _b !== void 0 ? _b : "unknown";
|
|
207
|
+
logger_1.logger.info("[auth] Admin ".concat(String(audit.adminId), " set password for user ").concat(String(targetUserId), " ") +
|
|
208
|
+
"at ".concat(luxon_1.DateTime.now().toISO()));
|
|
209
|
+
}
|
|
210
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
211
|
+
var isSettled = false;
|
|
212
|
+
var timeout = setTimeout(function () {
|
|
213
|
+
if (isSettled) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
isSettled = true;
|
|
217
|
+
reject(new Error("Timed out while setting password"));
|
|
218
|
+
}, timeoutMs);
|
|
219
|
+
var resolveOnce = function () {
|
|
220
|
+
if (isSettled) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
isSettled = true;
|
|
224
|
+
clearTimeout(timeout);
|
|
225
|
+
resolve();
|
|
226
|
+
};
|
|
227
|
+
var rejectOnce = function (error) {
|
|
228
|
+
if (isSettled) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
isSettled = true;
|
|
232
|
+
clearTimeout(timeout);
|
|
233
|
+
reject(error);
|
|
234
|
+
};
|
|
235
|
+
try {
|
|
236
|
+
var maybePromise = user.setPassword(password, function (error) {
|
|
237
|
+
if (error) {
|
|
238
|
+
rejectOnce(error);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
resolveOnce();
|
|
242
|
+
});
|
|
243
|
+
if (maybePromise && typeof maybePromise.then === "function") {
|
|
244
|
+
maybePromise.then(resolveOnce).catch(rejectOnce);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
rejectOnce(error);
|
|
249
|
+
}
|
|
250
|
+
})];
|
|
251
|
+
case 1:
|
|
252
|
+
_c.sent();
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
exports.setPasswordForUser = setPasswordForUser;
|
|
173
259
|
/**
|
|
174
260
|
* Generates both an access token (JWT) and a refresh token for a given user.
|
|
175
261
|
*
|
|
@@ -381,6 +467,19 @@ var setupAuth = function (app, userModel) {
|
|
|
381
467
|
});
|
|
382
468
|
}
|
|
383
469
|
catch (error) {
|
|
470
|
+
// A bearer token that is not a JWT at all (e.g. a Better Auth opaque session
|
|
471
|
+
// token) is not ours to reject — fall through so a later auth layer (Better
|
|
472
|
+
// Auth session middleware) or the route's own permissions can handle it.
|
|
473
|
+
// Detect this by decoding the token's header/payload structure (D1) rather
|
|
474
|
+
// than counting dot-delimited segments: an opaque token can coincidentally
|
|
475
|
+
// contain exactly two dots, and a malformed-but-JWT-shaped string can fail
|
|
476
|
+
// this same check for the wrong reason — `jwt.decode` parses the actual
|
|
477
|
+
// base64url JSON structure of each segment, which dot-counting cannot.
|
|
478
|
+
// Genuine JWTs that fail verification (malformed/expired) still return 401 so the
|
|
479
|
+
// client's token-refresh flow is preserved.
|
|
480
|
+
if (jsonwebtoken_1.default.decode(token, { complete: true }) === null) {
|
|
481
|
+
return [2 /*return*/, next()];
|
|
482
|
+
}
|
|
384
483
|
userText = ((_c = req.user) === null || _c === void 0 ? void 0 : _c._id) ? " for user ".concat(req.user._id, " ") : "";
|
|
385
484
|
expiredAt = error && typeof error === "object" && "expiredAt" in error
|
|
386
485
|
? error.expiredAt
|
package/dist/betterAuth.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ export interface BetterAuthConfig {
|
|
|
36
36
|
* Include your app's deep link schemes (e.g., "terreno://", "exp://").
|
|
37
37
|
*/
|
|
38
38
|
trustedOrigins?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Allow credential cookies when the frontend and API are hosted on different sites.
|
|
41
|
+
* Enables `SameSite=None; Secure` cookie attributes. Keep disabled for local HTTP.
|
|
42
|
+
*/
|
|
43
|
+
crossDomainCookies?: boolean;
|
|
39
44
|
/**
|
|
40
45
|
* Base path for Better Auth routes.
|
|
41
46
|
* @default "/api/auth"
|
|
@@ -32,20 +32,7 @@ export declare const createBetterAuth: (options: CreateBetterAuthOptions) => Bet
|
|
|
32
32
|
* and populates req.user with the application User model.
|
|
33
33
|
*/
|
|
34
34
|
export declare const createBetterAuthSessionMiddleware: (auth: BetterAuthInstance, userModel?: UserModel) => (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
35
|
-
|
|
36
|
-
* Syncs a Better Auth user to the application User model.
|
|
37
|
-
* Creates or updates the user as needed.
|
|
38
|
-
*/
|
|
39
|
-
interface MutableUserDoc {
|
|
40
|
-
admin?: boolean;
|
|
41
|
-
email?: string;
|
|
42
|
-
name?: string;
|
|
43
|
-
betterAuthId?: string;
|
|
44
|
-
oauthProvider?: string | null;
|
|
45
|
-
id?: string;
|
|
46
|
-
save: () => Promise<unknown>;
|
|
47
|
-
}
|
|
48
|
-
export declare const syncBetterAuthUser: (userModel: UserModel, betterAuthUser: BetterAuthUser, oauthProvider?: string) => Promise<MutableUserDoc>;
|
|
35
|
+
export declare const syncBetterAuthUser: (userModel: UserModel, betterAuthUser: BetterAuthUser, oauthProvider?: string) => Promise<any>;
|
|
49
36
|
/**
|
|
50
37
|
* Mounts Better Auth routes on the Express app.
|
|
51
38
|
*/
|
|
@@ -70,4 +57,3 @@ export declare const getBetterAuthSession: (req: Request) => BetterAuthSessionDa
|
|
|
70
57
|
* Checks if the request has a valid Better Auth session.
|
|
71
58
|
*/
|
|
72
59
|
export declare const hasBetterAuthSession: (req: Request) => boolean;
|
|
73
|
-
export {};
|
package/dist/betterAuthSetup.js
CHANGED
|
@@ -60,10 +60,11 @@ exports.hasBetterAuthSession = exports.getBetterAuthSession = exports.setupBette
|
|
|
60
60
|
var better_auth_1 = require("better-auth");
|
|
61
61
|
var mongodb_1 = require("better-auth/adapters/mongodb");
|
|
62
62
|
var node_1 = require("better-auth/node");
|
|
63
|
+
var plugins_1 = require("better-auth/plugins");
|
|
63
64
|
var mongoose_1 = __importDefault(require("mongoose"));
|
|
64
65
|
var errors_1 = require("./errors");
|
|
65
66
|
var logger_1 = require("./logger");
|
|
66
|
-
var
|
|
67
|
+
var plugins_2 = require("./plugins");
|
|
67
68
|
var requestContext_1 = require("./requestContext");
|
|
68
69
|
/**
|
|
69
70
|
* Creates a Better Auth instance with MongoDB adapter.
|
|
@@ -106,12 +107,27 @@ var createBetterAuth = function (options) {
|
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
var auth = (0, better_auth_1.betterAuth)({
|
|
110
|
+
advanced: config.crossDomainCookies
|
|
111
|
+
? {
|
|
112
|
+
defaultCookieAttributes: {
|
|
113
|
+
httpOnly: true,
|
|
114
|
+
sameSite: "none",
|
|
115
|
+
secure: true,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
: undefined,
|
|
109
119
|
basePath: basePath,
|
|
110
120
|
baseURL: baseURL,
|
|
111
121
|
database: (0, mongodb_1.mongodbAdapter)(mongoClient.db()),
|
|
112
122
|
emailAndPassword: {
|
|
113
123
|
enabled: true,
|
|
114
124
|
},
|
|
125
|
+
// The bearer plugin lets clients authenticate with `Authorization: Bearer <sessionToken>`
|
|
126
|
+
// instead of the signed session cookie. Required for cross-origin/native clients and for
|
|
127
|
+
// websocket handshakes (RealtimeApp's Better Auth socket validator forwards the handshake
|
|
128
|
+
// token as a bearer header) — without it, a raw session token cannot be validated and
|
|
129
|
+
// socket auth silently fails (the sync client shows perpetually "offline").
|
|
130
|
+
plugins: [(0, plugins_1.bearer)()],
|
|
115
131
|
secret: secret,
|
|
116
132
|
session: {
|
|
117
133
|
cookieCache: {
|
|
@@ -122,6 +138,9 @@ var createBetterAuth = function (options) {
|
|
|
122
138
|
socialProviders: Object.keys(socialProviders).length > 0 ? socialProviders : undefined,
|
|
123
139
|
trustedOrigins: (_b = config.trustedOrigins) !== null && _b !== void 0 ? _b : [],
|
|
124
140
|
});
|
|
141
|
+
// Cast through unknown: enabling the bearer plugin narrows betterAuth()'s inferred
|
|
142
|
+
// return type to a plugin-specific tuple that no longer matches the plugin-agnostic
|
|
143
|
+
// BetterAuthInstance alias, though the runtime instance is a valid better-auth instance.
|
|
125
144
|
return auth;
|
|
126
145
|
};
|
|
127
146
|
exports.createBetterAuth = createBetterAuth;
|
|
@@ -145,7 +164,7 @@ var createBetterAuthSessionMiddleware = function (auth, userModel) {
|
|
|
145
164
|
betterAuthUser = session.user;
|
|
146
165
|
reqWithSession = req;
|
|
147
166
|
if (!userModel) return [3 /*break*/, 6];
|
|
148
|
-
return [4 /*yield*/, (0,
|
|
167
|
+
return [4 /*yield*/, (0, plugins_2.findOneOrNoneFor)(userModel, {
|
|
149
168
|
betterAuthId: betterAuthUser.id,
|
|
150
169
|
})];
|
|
151
170
|
case 2:
|
|
@@ -190,13 +209,16 @@ var createBetterAuthSessionMiddleware = function (auth, userModel) {
|
|
|
190
209
|
}); };
|
|
191
210
|
};
|
|
192
211
|
exports.createBetterAuthSessionMiddleware = createBetterAuthSessionMiddleware;
|
|
193
|
-
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider
|
|
194
|
-
|
|
212
|
+
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider
|
|
213
|
+
// noExplicitAny: return is a consumer-defined user document; tests inspect varied fields
|
|
214
|
+
// biome-ignore lint/suspicious/noExplicitAny: return is a consumer-defined user document; tests inspect varied fields
|
|
215
|
+
) { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
+
var existingUser, userByEmail, useAsId, newUser, error_2;
|
|
195
217
|
return __generator(this, function (_a) {
|
|
196
218
|
switch (_a.label) {
|
|
197
219
|
case 0:
|
|
198
220
|
_a.trys.push([0, 8, , 9]);
|
|
199
|
-
return [4 /*yield*/, (0,
|
|
221
|
+
return [4 /*yield*/, (0, plugins_2.findOneOrNoneFor)(userModel, {
|
|
200
222
|
betterAuthId: betterAuthUser.id,
|
|
201
223
|
})];
|
|
202
224
|
case 1:
|
|
@@ -211,7 +233,7 @@ var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { r
|
|
|
211
233
|
case 2:
|
|
212
234
|
_a.sent();
|
|
213
235
|
return [2 /*return*/, existingUser];
|
|
214
|
-
case 3: return [4 /*yield*/, (0,
|
|
236
|
+
case 3: return [4 /*yield*/, (0, plugins_2.findOneOrNoneFor)(userModel, {
|
|
215
237
|
email: betterAuthUser.email,
|
|
216
238
|
})];
|
|
217
239
|
case 4:
|
|
@@ -228,8 +250,7 @@ var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { r
|
|
|
228
250
|
return [2 /*return*/, userByEmail];
|
|
229
251
|
case 6:
|
|
230
252
|
useAsId = mongoose_1.default.isValidObjectId(betterAuthUser.id) ? { _id: betterAuthUser.id } : {};
|
|
231
|
-
|
|
232
|
-
newUser = new UserDocumentConstructor(__assign(__assign({}, useAsId), { admin: false, betterAuthId: betterAuthUser.id, email: betterAuthUser.email, name: betterAuthUser.name || betterAuthUser.email.split("@")[0], oauthProvider: oauthProvider || null }));
|
|
253
|
+
newUser = new userModel(__assign(__assign({}, useAsId), { admin: false, betterAuthId: betterAuthUser.id, email: betterAuthUser.email, name: betterAuthUser.name || betterAuthUser.email.split("@")[0], oauthProvider: oauthProvider || null }));
|
|
233
254
|
return [4 /*yield*/, newUser.save()];
|
|
234
255
|
case 7:
|
|
235
256
|
_a.sent();
|
|
@@ -314,7 +314,7 @@ var configurationPlugin = function (schema, options) {
|
|
|
314
314
|
if (Object.keys(setFields).length === 0) {
|
|
315
315
|
return [2 /*return*/, this.getConfig()];
|
|
316
316
|
}
|
|
317
|
-
return [4 /*yield*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, {
|
|
317
|
+
return [4 /*yield*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, { new: true, runValidators: true })];
|
|
318
318
|
case 1:
|
|
319
319
|
updated = _e.sent();
|
|
320
320
|
if (updated) {
|
|
@@ -327,7 +327,7 @@ var configurationPlugin = function (schema, options) {
|
|
|
327
327
|
// No singleton yet — create one (with subdocument defaults applied), then
|
|
328
328
|
// apply the patch.
|
|
329
329
|
_e.sent();
|
|
330
|
-
return [2 /*return*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, {
|
|
330
|
+
return [2 /*return*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, { new: true, runValidators: true }).orFail()];
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
333
|
});
|
package/dist/docLoader.js
CHANGED
|
@@ -48,21 +48,22 @@ var errors_1 = require("./errors");
|
|
|
48
48
|
* Matches permission middleware behavior including soft-delete metadata.
|
|
49
49
|
*/
|
|
50
50
|
var loadDocOr404 = function (model, id, populatePaths) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
-
var builtQuery, populatedQuery, data, error_1, hiddenDoc, notFoundDetail, reason;
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
var builtQuery, populatedQuery, data, error_1, idSchemaType, hiddenId, hiddenDoc, notFoundDetail, reason;
|
|
52
|
+
var _a;
|
|
53
|
+
return __generator(this, function (_b) {
|
|
54
|
+
switch (_b.label) {
|
|
54
55
|
case 0:
|
|
55
56
|
builtQuery = model.findById(id);
|
|
56
57
|
populatedQuery = (0, api_1.addPopulateToQuery)(builtQuery, populatePaths);
|
|
57
|
-
|
|
58
|
+
_b.label = 1;
|
|
58
59
|
case 1:
|
|
59
|
-
|
|
60
|
+
_b.trys.push([1, 3, , 4]);
|
|
60
61
|
return [4 /*yield*/, populatedQuery.exec()];
|
|
61
62
|
case 2:
|
|
62
|
-
data = (
|
|
63
|
+
data = (_b.sent());
|
|
63
64
|
return [3 /*break*/, 4];
|
|
64
65
|
case 3:
|
|
65
|
-
error_1 =
|
|
66
|
+
error_1 = _b.sent();
|
|
66
67
|
if ((0, errors_1.isAPIError)(error_1)) {
|
|
67
68
|
throw error_1;
|
|
68
69
|
}
|
|
@@ -76,11 +77,13 @@ var loadDocOr404 = function (model, id, populatePaths) { return __awaiter(void 0
|
|
|
76
77
|
});
|
|
77
78
|
case 4:
|
|
78
79
|
if (!!data) return [3 /*break*/, 6];
|
|
80
|
+
idSchemaType = (_a = model.schema) === null || _a === void 0 ? void 0 : _a.path("_id");
|
|
81
|
+
hiddenId = (idSchemaType === null || idSchemaType === void 0 ? void 0 : idSchemaType.instance) === "String" ? id : new mongoose_1.default.Types.ObjectId(id);
|
|
79
82
|
return [4 /*yield*/, model.collection.findOne({
|
|
80
|
-
_id:
|
|
83
|
+
_id: hiddenId,
|
|
81
84
|
})];
|
|
82
85
|
case 5:
|
|
83
|
-
hiddenDoc =
|
|
86
|
+
hiddenDoc = _b.sent();
|
|
84
87
|
notFoundDetail = "Document ".concat(id, " not found for model ").concat(model.modelName);
|
|
85
88
|
if (!hiddenDoc) {
|
|
86
89
|
throw new errors_1.NotFoundError({
|
package/dist/errors.d.ts
CHANGED
|
@@ -159,6 +159,19 @@ export declare const apiUnauthorizedMiddleware: (err: Error, _req: Request, res:
|
|
|
159
159
|
* Converts Mongoose validation/cast errors into client-friendly APIErrors.
|
|
160
160
|
*/
|
|
161
161
|
export declare const mongooseErrorToAPIError: (err: Error) => APIError | null;
|
|
162
|
+
/**
|
|
163
|
+
* Picks the error to throw for something caught in a hook, transformer, or Mongoose middleware.
|
|
164
|
+
* An `APIError` is passed through untouched so its status, code, detail, and meta reach the client;
|
|
165
|
+
* anything else is wrapped in the given framework error. `wrapper` may override any field,
|
|
166
|
+
* including `detail`, which defaults to the caught error's text.
|
|
167
|
+
*/
|
|
168
|
+
export declare const passthroughOrWrap: (error: unknown, wrapper: APIErrorOptions) => APIError;
|
|
169
|
+
/**
|
|
170
|
+
* `passthroughOrWrap` for write paths (`model.create`, `doc.save`). Mongoose validation and cast
|
|
171
|
+
* errors are converted first so their per-field messages survive as `meta.fields` instead of being
|
|
172
|
+
* flattened into the wrapper's `detail`.
|
|
173
|
+
*/
|
|
174
|
+
export declare const passthroughOrWrapWrite: (error: unknown, wrapper: APIErrorOptions) => APIError;
|
|
162
175
|
export declare const apiErrorMiddleware: (err: Error, _req: Request, res: Response, next: NextFunction) => void;
|
|
163
176
|
/**
|
|
164
177
|
* Final Express error handler for unexpected errors. Always returns JSON so
|
package/dist/errors.js
CHANGED
|
@@ -86,7 +86,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
86
86
|
return ar;
|
|
87
87
|
};
|
|
88
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
-
exports.apiFallthroughErrorMiddleware = exports.apiErrorMiddleware = exports.mongooseErrorToAPIError = exports.apiUnauthorizedMiddleware = exports.getAPIErrorBody = exports.getDisableExternalErrorTracking = exports.errorStack = exports.errorDetail = exports.errorMessage = exports.isAPIError = exports.errorsPlugin = exports.InternalServerError = exports.ValidationError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.APIError = void 0;
|
|
89
|
+
exports.apiFallthroughErrorMiddleware = exports.apiErrorMiddleware = exports.passthroughOrWrapWrite = exports.passthroughOrWrap = exports.mongooseErrorToAPIError = exports.apiUnauthorizedMiddleware = exports.getAPIErrorBody = exports.getDisableExternalErrorTracking = exports.errorStack = exports.errorDetail = exports.errorMessage = exports.isAPIError = exports.errorsPlugin = exports.InternalServerError = exports.ValidationError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.APIError = void 0;
|
|
90
90
|
// https://jsonapi.org/format/#errors
|
|
91
91
|
var Sentry = __importStar(require("@sentry/bun"));
|
|
92
92
|
var mongoose_1 = __importStar(require("mongoose"));
|
|
@@ -494,6 +494,34 @@ var mongooseErrorToAPIError = function (err) {
|
|
|
494
494
|
return null;
|
|
495
495
|
};
|
|
496
496
|
exports.mongooseErrorToAPIError = mongooseErrorToAPIError;
|
|
497
|
+
/**
|
|
498
|
+
* Picks the error to throw for something caught in a hook, transformer, or Mongoose middleware.
|
|
499
|
+
* An `APIError` is passed through untouched so its status, code, detail, and meta reach the client;
|
|
500
|
+
* anything else is wrapped in the given framework error. `wrapper` may override any field,
|
|
501
|
+
* including `detail`, which defaults to the caught error's text.
|
|
502
|
+
*/
|
|
503
|
+
var passthroughOrWrap = function (error, wrapper) {
|
|
504
|
+
if ((0, exports.isAPIError)(error)) {
|
|
505
|
+
return error;
|
|
506
|
+
}
|
|
507
|
+
return new APIError(__assign({ cause: error, detail: (0, exports.errorDetail)(error), disableExternalErrorTracking: (0, exports.getDisableExternalErrorTracking)(error) }, wrapper));
|
|
508
|
+
};
|
|
509
|
+
exports.passthroughOrWrap = passthroughOrWrap;
|
|
510
|
+
/**
|
|
511
|
+
* `passthroughOrWrap` for write paths (`model.create`, `doc.save`). Mongoose validation and cast
|
|
512
|
+
* errors are converted first so their per-field messages survive as `meta.fields` instead of being
|
|
513
|
+
* flattened into the wrapper's `detail`.
|
|
514
|
+
*/
|
|
515
|
+
var passthroughOrWrapWrite = function (error, wrapper) {
|
|
516
|
+
if (!(0, exports.isAPIError)(error) && error instanceof Error) {
|
|
517
|
+
var converted = (0, exports.mongooseErrorToAPIError)(error);
|
|
518
|
+
if (converted) {
|
|
519
|
+
return converted;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return (0, exports.passthroughOrWrap)(error, wrapper);
|
|
523
|
+
};
|
|
524
|
+
exports.passthroughOrWrapWrite = passthroughOrWrapWrite;
|
|
497
525
|
// Logs the error (warn for 4xx client errors, error for 5xx server errors) and captures it with
|
|
498
526
|
// Sentry unless external tracking is disabled. Fingerprints on the logical error type
|
|
499
527
|
// (name + code/title + status) so unrelated errors constructed at the same framework lines don't
|
package/dist/expressServer.js
CHANGED
|
@@ -104,7 +104,6 @@ var express_1 = __importDefault(require("express"));
|
|
|
104
104
|
var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
105
105
|
var on_finished_1 = __importDefault(require("on-finished"));
|
|
106
106
|
var passport_1 = __importDefault(require("passport"));
|
|
107
|
-
var errors_1 = require("./errors");
|
|
108
107
|
var logger_1 = require("./logger");
|
|
109
108
|
var slackNotifier_1 = require("./notifiers/slackNotifier");
|
|
110
109
|
var SLOW_READ_MAX = 200;
|
|
@@ -112,16 +111,16 @@ var SLOW_WRITE_MAX = 500;
|
|
|
112
111
|
var IS_JEST = process.env.JEST_WORKER_ID !== undefined;
|
|
113
112
|
var setupEnvironment = function () {
|
|
114
113
|
if (!process.env.TOKEN_ISSUER) {
|
|
115
|
-
throw new
|
|
114
|
+
throw new Error("TOKEN_ISSUER must be set in env.");
|
|
116
115
|
}
|
|
117
116
|
if (!process.env.TOKEN_SECRET) {
|
|
118
|
-
throw new
|
|
117
|
+
throw new Error("TOKEN_SECRET must be set.");
|
|
119
118
|
}
|
|
120
119
|
if (!process.env.REFRESH_TOKEN_SECRET) {
|
|
121
|
-
throw new
|
|
120
|
+
throw new Error("REFRESH_TOKEN_SECRET must be set.");
|
|
122
121
|
}
|
|
123
122
|
if (!process.env.SESSION_SECRET) {
|
|
124
|
-
throw new
|
|
123
|
+
throw new Error("SESSION_SECRET must be set.");
|
|
125
124
|
}
|
|
126
125
|
if (!process.env.TOKEN_EXPIRES_IN && !IS_JEST) {
|
|
127
126
|
logger_1.logger.warn("TOKEN_EXPIRES_IN is not set so using default.");
|
|
@@ -229,12 +228,7 @@ var cronjob = function (name, schedule, callback) {
|
|
|
229
228
|
new cron_1.default.CronJob(cronSchedule, callback, null, true, "America/Chicago");
|
|
230
229
|
}
|
|
231
230
|
catch (error) {
|
|
232
|
-
throw new
|
|
233
|
-
cause: error,
|
|
234
|
-
detail: "Failed to create cronjob ".concat(name, " with schedule ").concat(cronSchedule, ": ").concat(error),
|
|
235
|
-
status: 500,
|
|
236
|
-
title: "Failed to create cronjob",
|
|
237
|
-
});
|
|
231
|
+
throw new Error("Failed to create cronjob: ".concat(error));
|
|
238
232
|
}
|
|
239
233
|
};
|
|
240
234
|
exports.cronjob = cronjob;
|
package/dist/githubAuth.js
CHANGED
|
@@ -82,7 +82,10 @@ exports.githubUserPlugin = githubUserPlugin;
|
|
|
82
82
|
var setupGitHubAuth = function (_app, userModel, githubOptions) {
|
|
83
83
|
var _a;
|
|
84
84
|
var scope = (_a = githubOptions.scope) !== null && _a !== void 0 ? _a : ["user:email"];
|
|
85
|
-
passport_1.default.use("github",
|
|
85
|
+
passport_1.default.use("github",
|
|
86
|
+
// noExplicitAny: passport-github2's typed constructor overloads don't match passReqToCallback variant
|
|
87
|
+
// biome-ignore lint/suspicious/noExplicitAny: passport-github2's typed constructor overloads don't match passReqToCallback variant
|
|
88
|
+
new passport_github2_1.Strategy({
|
|
86
89
|
callbackURL: githubOptions.callbackURL,
|
|
87
90
|
clientID: githubOptions.clientId,
|
|
88
91
|
clientSecret: githubOptions.clientSecret,
|
package/dist/index.d.ts
CHANGED
|
@@ -28,15 +28,31 @@ export * from "./openApiValidator";
|
|
|
28
28
|
export * from "./permissions";
|
|
29
29
|
export * from "./plugins";
|
|
30
30
|
export * from "./populate";
|
|
31
|
-
export { startChangeStreamWatcher, stopChangeStreamWatcher, } from "./realtime/changeStreamWatcher";
|
|
31
|
+
export { type AuthorizedEmitEntry, emitPayloadToAuthorizedRoom, emitSyncDeltaForChange, startChangeStreamWatcher, stopChangeStreamWatcher, } from "./realtime/changeStreamWatcher";
|
|
32
32
|
export { matchesQuery } from "./realtime/queryMatcher";
|
|
33
33
|
export { addQuerySubscription, clearQueryStore, computeQueryId, getQuerySubscriptionsForCollection, removeAllSocketQueries, removeQuerySubscription, } from "./realtime/queryStore";
|
|
34
34
|
export { installRealtimeSocketHandlers, MAX_DOCUMENT_SUBSCRIPTIONS, MAX_MODEL_SUBSCRIPTIONS, MAX_QUERY_SUBSCRIPTIONS, RealtimeApp, type RealtimeSocketLike, } from "./realtime/realtimeApp";
|
|
35
35
|
export { clearRealtimeRegistry, findRegistryEntryByCollection, findRegistryEntryByRoutePath, getRealtimeRegistry, type RealtimeRegistryEntry, registerRealtime, } from "./realtime/registry";
|
|
36
|
+
export { DEFAULT_SESSION_REVALIDATION_INTERVAL_MS, loadFullUserForSocket, type RevalidatableSocket, type RevalidationOutcome, reresolveSyncRoomsForSocket, revalidateSocketSession, runSessionRevalidationSweep, type SessionRevalidationHandle, type SessionRevalidationOptions, startSessionRevalidationSweep, } from "./realtime/sessionRevalidation";
|
|
37
|
+
export { type AuthenticatableSocket, type BetterAuthSocketOptions, createBetterAuthValidator, createLegacyJwtValidator, createSocketAuthMiddleware, type SocketAuthValidator, } from "./realtime/socketAuth";
|
|
38
|
+
export { type DecodedRealtimeToken, getSocketUser, type SocketDataBag, type SocketWithDecodedToken, } from "./realtime/socketUser";
|
|
36
39
|
export type { ChangeStreamConfig, DocumentSubscription, QuerySubscription, RealtimeAppOptions, RealtimeConfig, RealtimeEvent, } from "./realtime/types";
|
|
37
40
|
export * from "./requestContext";
|
|
38
41
|
export * from "./scriptRunner";
|
|
39
42
|
export * from "./secretProviders";
|
|
43
|
+
export * from "./sync/executors";
|
|
44
|
+
export * from "./sync/models";
|
|
45
|
+
export * from "./sync/mutationHandler";
|
|
46
|
+
export * from "./sync/registry";
|
|
47
|
+
export * from "./sync/routes";
|
|
48
|
+
export * from "./sync/scripts/compactTombstones";
|
|
49
|
+
export * from "./sync/serialize";
|
|
50
|
+
export * from "./sync/socketHandlers";
|
|
51
|
+
export * from "./sync/streams";
|
|
52
|
+
export * from "./sync/syncApp";
|
|
53
|
+
export * from "./sync/syncBatch";
|
|
54
|
+
export * from "./sync/syncSeqPlugin";
|
|
55
|
+
export * from "./sync/types";
|
|
40
56
|
export * from "./syncConsents";
|
|
41
57
|
export * from "./terrenoApp";
|
|
42
58
|
export * from "./terrenoPlugin";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.z = exports.registerRealtime = exports.getRealtimeRegistry = exports.findRegistryEntryByRoutePath = exports.findRegistryEntryByCollection = exports.clearRealtimeRegistry = exports.RealtimeApp = exports.MAX_QUERY_SUBSCRIPTIONS = exports.MAX_MODEL_SUBSCRIPTIONS = exports.MAX_DOCUMENT_SUBSCRIPTIONS = exports.installRealtimeSocketHandlers = exports.removeQuerySubscription = exports.removeAllSocketQueries = exports.getQuerySubscriptionsForCollection = exports.computeQueryId = exports.clearQueryStore = exports.addQuerySubscription = exports.matchesQuery = exports.stopChangeStreamWatcher = exports.startChangeStreamWatcher = void 0;
|
|
17
|
+
exports.z = exports.getSocketUser = exports.createSocketAuthMiddleware = exports.createLegacyJwtValidator = exports.createBetterAuthValidator = exports.startSessionRevalidationSweep = exports.runSessionRevalidationSweep = exports.revalidateSocketSession = exports.reresolveSyncRoomsForSocket = exports.loadFullUserForSocket = exports.DEFAULT_SESSION_REVALIDATION_INTERVAL_MS = exports.registerRealtime = exports.getRealtimeRegistry = exports.findRegistryEntryByRoutePath = exports.findRegistryEntryByCollection = exports.clearRealtimeRegistry = exports.RealtimeApp = exports.MAX_QUERY_SUBSCRIPTIONS = exports.MAX_MODEL_SUBSCRIPTIONS = exports.MAX_DOCUMENT_SUBSCRIPTIONS = exports.installRealtimeSocketHandlers = exports.removeQuerySubscription = exports.removeAllSocketQueries = exports.getQuerySubscriptionsForCollection = exports.computeQueryId = exports.clearQueryStore = exports.addQuerySubscription = exports.matchesQuery = exports.stopChangeStreamWatcher = exports.startChangeStreamWatcher = exports.emitSyncDeltaForChange = exports.emitPayloadToAuthorizedRoom = void 0;
|
|
18
18
|
__exportStar(require("./actions"), exports);
|
|
19
19
|
__exportStar(require("./api"), exports);
|
|
20
20
|
__exportStar(require("./auth"), exports);
|
|
@@ -46,6 +46,8 @@ __exportStar(require("./permissions"), exports);
|
|
|
46
46
|
__exportStar(require("./plugins"), exports);
|
|
47
47
|
__exportStar(require("./populate"), exports);
|
|
48
48
|
var changeStreamWatcher_1 = require("./realtime/changeStreamWatcher");
|
|
49
|
+
Object.defineProperty(exports, "emitPayloadToAuthorizedRoom", { enumerable: true, get: function () { return changeStreamWatcher_1.emitPayloadToAuthorizedRoom; } });
|
|
50
|
+
Object.defineProperty(exports, "emitSyncDeltaForChange", { enumerable: true, get: function () { return changeStreamWatcher_1.emitSyncDeltaForChange; } });
|
|
49
51
|
Object.defineProperty(exports, "startChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.startChangeStreamWatcher; } });
|
|
50
52
|
Object.defineProperty(exports, "stopChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.stopChangeStreamWatcher; } });
|
|
51
53
|
var queryMatcher_1 = require("./realtime/queryMatcher");
|
|
@@ -69,9 +71,35 @@ Object.defineProperty(exports, "findRegistryEntryByCollection", { enumerable: tr
|
|
|
69
71
|
Object.defineProperty(exports, "findRegistryEntryByRoutePath", { enumerable: true, get: function () { return registry_1.findRegistryEntryByRoutePath; } });
|
|
70
72
|
Object.defineProperty(exports, "getRealtimeRegistry", { enumerable: true, get: function () { return registry_1.getRealtimeRegistry; } });
|
|
71
73
|
Object.defineProperty(exports, "registerRealtime", { enumerable: true, get: function () { return registry_1.registerRealtime; } });
|
|
74
|
+
var sessionRevalidation_1 = require("./realtime/sessionRevalidation");
|
|
75
|
+
Object.defineProperty(exports, "DEFAULT_SESSION_REVALIDATION_INTERVAL_MS", { enumerable: true, get: function () { return sessionRevalidation_1.DEFAULT_SESSION_REVALIDATION_INTERVAL_MS; } });
|
|
76
|
+
Object.defineProperty(exports, "loadFullUserForSocket", { enumerable: true, get: function () { return sessionRevalidation_1.loadFullUserForSocket; } });
|
|
77
|
+
Object.defineProperty(exports, "reresolveSyncRoomsForSocket", { enumerable: true, get: function () { return sessionRevalidation_1.reresolveSyncRoomsForSocket; } });
|
|
78
|
+
Object.defineProperty(exports, "revalidateSocketSession", { enumerable: true, get: function () { return sessionRevalidation_1.revalidateSocketSession; } });
|
|
79
|
+
Object.defineProperty(exports, "runSessionRevalidationSweep", { enumerable: true, get: function () { return sessionRevalidation_1.runSessionRevalidationSweep; } });
|
|
80
|
+
Object.defineProperty(exports, "startSessionRevalidationSweep", { enumerable: true, get: function () { return sessionRevalidation_1.startSessionRevalidationSweep; } });
|
|
81
|
+
var socketAuth_1 = require("./realtime/socketAuth");
|
|
82
|
+
Object.defineProperty(exports, "createBetterAuthValidator", { enumerable: true, get: function () { return socketAuth_1.createBetterAuthValidator; } });
|
|
83
|
+
Object.defineProperty(exports, "createLegacyJwtValidator", { enumerable: true, get: function () { return socketAuth_1.createLegacyJwtValidator; } });
|
|
84
|
+
Object.defineProperty(exports, "createSocketAuthMiddleware", { enumerable: true, get: function () { return socketAuth_1.createSocketAuthMiddleware; } });
|
|
85
|
+
var socketUser_1 = require("./realtime/socketUser");
|
|
86
|
+
Object.defineProperty(exports, "getSocketUser", { enumerable: true, get: function () { return socketUser_1.getSocketUser; } });
|
|
72
87
|
__exportStar(require("./requestContext"), exports);
|
|
73
88
|
__exportStar(require("./scriptRunner"), exports);
|
|
74
89
|
__exportStar(require("./secretProviders"), exports);
|
|
90
|
+
__exportStar(require("./sync/executors"), exports);
|
|
91
|
+
__exportStar(require("./sync/models"), exports);
|
|
92
|
+
__exportStar(require("./sync/mutationHandler"), exports);
|
|
93
|
+
__exportStar(require("./sync/registry"), exports);
|
|
94
|
+
__exportStar(require("./sync/routes"), exports);
|
|
95
|
+
__exportStar(require("./sync/scripts/compactTombstones"), exports);
|
|
96
|
+
__exportStar(require("./sync/serialize"), exports);
|
|
97
|
+
__exportStar(require("./sync/socketHandlers"), exports);
|
|
98
|
+
__exportStar(require("./sync/streams"), exports);
|
|
99
|
+
__exportStar(require("./sync/syncApp"), exports);
|
|
100
|
+
__exportStar(require("./sync/syncBatch"), exports);
|
|
101
|
+
__exportStar(require("./sync/syncSeqPlugin"), exports);
|
|
102
|
+
__exportStar(require("./sync/types"), exports);
|
|
75
103
|
__exportStar(require("./syncConsents"), exports);
|
|
76
104
|
__exportStar(require("./terrenoApp"), exports);
|
|
77
105
|
__exportStar(require("./terrenoPlugin"), exports);
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
+
/**
|
|
3
|
+
* Express middleware that rejects the request with a 403 unless the authenticated user is an admin
|
|
4
|
+
* (`req.user.admin === true`). Run it after {@link authenticateMiddleware} so `req.user` is
|
|
5
|
+
* populated, e.g. `[authenticateMiddleware(), requireAdminMiddleware]`. Use this for admin-only
|
|
6
|
+
* custom routes instead of hand-rolling an inline admin guard.
|
|
7
|
+
*/
|
|
8
|
+
export declare const requireAdminMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
|
|
2
9
|
/**
|
|
3
10
|
* Express middleware that captures the app version from the request header
|
|
4
11
|
* and adds it as a tag to the current Sentry scope.
|
package/dist/middleware.js
CHANGED
|
@@ -44,9 +44,24 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
44
44
|
};
|
|
45
45
|
})();
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.jsonResponseRequestIdMiddleware = exports.sentryAppVersionMiddleware = void 0;
|
|
47
|
+
exports.jsonResponseRequestIdMiddleware = exports.sentryAppVersionMiddleware = exports.requireAdminMiddleware = void 0;
|
|
48
48
|
var Sentry = __importStar(require("@sentry/bun"));
|
|
49
|
+
var errors_1 = require("./errors");
|
|
49
50
|
var requestContext_1 = require("./requestContext");
|
|
51
|
+
/**
|
|
52
|
+
* Express middleware that rejects the request with a 403 unless the authenticated user is an admin
|
|
53
|
+
* (`req.user.admin === true`). Run it after {@link authenticateMiddleware} so `req.user` is
|
|
54
|
+
* populated, e.g. `[authenticateMiddleware(), requireAdminMiddleware]`. Use this for admin-only
|
|
55
|
+
* custom routes instead of hand-rolling an inline admin guard.
|
|
56
|
+
*/
|
|
57
|
+
var requireAdminMiddleware = function (req, _res, next) {
|
|
58
|
+
var user = req.user;
|
|
59
|
+
if (!(user === null || user === void 0 ? void 0 : user.admin)) {
|
|
60
|
+
throw new errors_1.APIError({ status: 403, title: "Admin access required" });
|
|
61
|
+
}
|
|
62
|
+
next();
|
|
63
|
+
};
|
|
64
|
+
exports.requireAdminMiddleware = requireAdminMiddleware;
|
|
50
65
|
/**
|
|
51
66
|
* Express middleware that captures the app version from the request header
|
|
52
67
|
* and adds it as a tag to the current Sentry scope.
|
package/dist/openApiCompat.d.ts
CHANGED
|
@@ -8,7 +8,16 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @see https://github.com/wesleytodd/express-openapi/issues/70
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
11
|
+
import { type Application, type NextFunction, type Request, type Response } from "express";
|
|
12
|
+
/**
|
|
13
|
+
* Patches `express.Router().use` so nested mounts (e.g. `router.use("/gpt/histories", ...)`)
|
|
14
|
+
* record `__openApiMountPath` the same way `app.use` does. Without this, nested
|
|
15
|
+
* modelRouter OpenAPI paths are omitted from `/openapi.json`.
|
|
16
|
+
*
|
|
17
|
+
* Express 5's Router puts `use` a few prototypes up from the instance, so we walk
|
|
18
|
+
* the chain until we find the own `use` descriptor.
|
|
19
|
+
*/
|
|
20
|
+
export declare const patchExpressRouterUse: () => void;
|
|
12
21
|
/**
|
|
13
22
|
* Wraps an Express app's `use` method to record the mount path on each
|
|
14
23
|
* layer added to the router stack. This runs at setup time so that
|