@terreno/api 0.25.0 → 0.26.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/.ai/guidelines/core.md +1 -0
- package/README.md +4 -3
- package/dist/__tests__/versionCheckPlugin.test.js +15 -0
- package/dist/betterAuthApp.test.js +1 -2
- package/dist/expressServer.js +6 -6
- package/dist/expressServer.test.js +22 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +28 -3
- package/dist/openApi.test.js +51 -0
- package/dist/tests/fixtures/compileAuthEntry.js +1 -1
- package/package.json +2 -2
- package/src/__tests__/versionCheckPlugin.test.ts +9 -0
- package/src/betterAuthApp.test.ts +3 -3
- package/src/expressServer.test.ts +12 -0
- package/src/expressServer.ts +1 -1
- package/src/index.ts +40 -2
- package/src/openApi.test.ts +53 -0
- package/src/tests/fixtures/compileAuthEntry.ts +1 -1
- package/dist/notifiers/index.d.ts +0 -3
- package/dist/notifiers/index.js +0 -19
- package/dist/realtime/index.d.ts +0 -6
- package/dist/realtime/index.js +0 -27
- package/src/notifiers/index.ts +0 -3
- package/src/realtime/index.ts +0 -34
package/.ai/guidelines/core.md
CHANGED
|
@@ -69,3 +69,4 @@ router.get("/yourRoute/:id", [
|
|
|
69
69
|
- Define statics/methods by direct assignment: `schema.methods = {bar() {}}`
|
|
70
70
|
- All model types live in `src/types/models/`
|
|
71
71
|
- In routes: `req.user` is `UserDocument | undefined`
|
|
72
|
+
- **No barrel imports** — import from concrete files (e.g. `../models/user`), not `../models` index barrels. See `docs/explanation/no-barrel-imports.md`.
|
package/README.md
CHANGED
|
@@ -35,14 +35,15 @@ import {Schema} from "mongoose";
|
|
|
35
35
|
import {DateOnly} from "@terreno/api";
|
|
36
36
|
|
|
37
37
|
// Register DateOnly type before any models are loaded
|
|
38
|
-
|
|
38
|
+
const schemaTypes = Schema.Types as typeof Schema.Types & {DateOnly: typeof DateOnly};
|
|
39
|
+
schemaTypes.DateOnly = DateOnly;
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
Then you can use it in your schemas:
|
|
42
43
|
|
|
43
44
|
```typescript
|
|
44
45
|
const eventSchema = new Schema({
|
|
45
|
-
eventDate: {type:
|
|
46
|
+
eventDate: {type: schemaTypes.DateOnly},
|
|
46
47
|
});
|
|
47
48
|
```
|
|
48
49
|
|
|
@@ -237,7 +238,7 @@ Sentry.init({
|
|
|
237
238
|
integrations: [
|
|
238
239
|
// Only profile integration needs to be added, the rest are defaults and are already added,
|
|
239
240
|
// including Express, mongoose, HTTP, etc.
|
|
240
|
-
nodeProfilingIntegration()
|
|
241
|
+
nodeProfilingIntegration(),
|
|
241
242
|
],
|
|
242
243
|
// Debug can be helpful for figuruing out why something isn't working.
|
|
243
244
|
// debug: true,
|
|
@@ -67,6 +67,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
67
|
};
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
69
|
var bun_test_1 = require("bun:test");
|
|
70
|
+
var chai_1 = require("chai");
|
|
70
71
|
var supertest_1 = __importDefault(require("supertest"));
|
|
71
72
|
var versionConfig_1 = require("../models/versionConfig");
|
|
72
73
|
var terrenoApp_1 = require("../terrenoApp");
|
|
@@ -151,6 +152,20 @@ var typedUserModel = tests_1.UserModel;
|
|
|
151
152
|
}
|
|
152
153
|
});
|
|
153
154
|
}); });
|
|
155
|
+
(0, bun_test_1.it)("returns ok when version is provided more than once", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
+
var res;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0: return [4 /*yield*/, app.get("/version-check?platform=mobile&version=1&version=2")];
|
|
160
|
+
case 1:
|
|
161
|
+
res = _a.sent();
|
|
162
|
+
chai_1.assert.equal(res.status, 200);
|
|
163
|
+
chai_1.assert.equal(res.body.status, "ok");
|
|
164
|
+
chai_1.assert.notProperty(res.body, "pollingIntervalMs");
|
|
165
|
+
return [2 /*return*/];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}); });
|
|
154
169
|
(0, bun_test_1.it)("returns ok when client version >= warning and required (web)", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
155
170
|
var res;
|
|
156
171
|
return __generator(this, function (_a) {
|
|
@@ -83,7 +83,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
83
83
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
84
84
|
};
|
|
85
85
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
87
86
|
var bun_test_1 = require("bun:test");
|
|
88
87
|
var express_1 = __importDefault(require("express"));
|
|
89
88
|
var mongodb_memory_server_1 = require("mongodb-memory-server");
|
|
@@ -91,7 +90,6 @@ var mongoose_1 = __importStar(require("mongoose"));
|
|
|
91
90
|
var betterAuthApp_1 = require("./betterAuthApp");
|
|
92
91
|
var conn;
|
|
93
92
|
var mongod;
|
|
94
|
-
var TestUser;
|
|
95
93
|
var testUserSchema = new mongoose_1.Schema({
|
|
96
94
|
admin: { default: false, type: Boolean },
|
|
97
95
|
betterAuthId: { type: String },
|
|
@@ -99,6 +97,7 @@ var testUserSchema = new mongoose_1.Schema({
|
|
|
99
97
|
name: { type: String },
|
|
100
98
|
oauthProvider: { type: String },
|
|
101
99
|
});
|
|
100
|
+
var TestUser;
|
|
102
101
|
var setup = (function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
103
102
|
return __generator(this, function (_a) {
|
|
104
103
|
switch (_a.label) {
|
package/dist/expressServer.js
CHANGED
|
@@ -105,7 +105,7 @@ 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
107
|
var logger_1 = require("./logger");
|
|
108
|
-
var
|
|
108
|
+
var slackNotifier_1 = require("./notifiers/slackNotifier");
|
|
109
109
|
var SLOW_READ_MAX = 200;
|
|
110
110
|
var SLOW_WRITE_MAX = 500;
|
|
111
111
|
var IS_JEST = process.env.JEST_WORKER_ID !== undefined;
|
|
@@ -246,7 +246,7 @@ var wrapScript = function (func_1) {
|
|
|
246
246
|
case 0:
|
|
247
247
|
name = (_a = require.main) === null || _a === void 0 ? void 0 : _a.filename.split("/").slice(-1)[0].replace(".ts", "");
|
|
248
248
|
logger_1.logger.info("Running script ".concat(name));
|
|
249
|
-
return [4 /*yield*/, (0,
|
|
249
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Running script ".concat(name), {
|
|
250
250
|
slackChannel: options.slackChannel,
|
|
251
251
|
})];
|
|
252
252
|
case 1:
|
|
@@ -260,7 +260,7 @@ var wrapScript = function (func_1) {
|
|
|
260
260
|
switch (_a.label) {
|
|
261
261
|
case 0:
|
|
262
262
|
msg = "Script ".concat(name, " is taking a while, currently ").concat(warnTime_1 / 1000, " seconds");
|
|
263
|
-
return [4 /*yield*/, (0,
|
|
263
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)(msg)];
|
|
264
264
|
case 1:
|
|
265
265
|
_a.sent();
|
|
266
266
|
logger_1.logger.warn(msg);
|
|
@@ -274,7 +274,7 @@ var wrapScript = function (func_1) {
|
|
|
274
274
|
switch (_a.label) {
|
|
275
275
|
case 0:
|
|
276
276
|
msg = "Script ".concat(name, " took too long, exiting");
|
|
277
|
-
return [4 /*yield*/, (0,
|
|
277
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)(msg)];
|
|
278
278
|
case 1:
|
|
279
279
|
_a.sent();
|
|
280
280
|
logger_1.logger.error(msg);
|
|
@@ -304,7 +304,7 @@ var wrapScript = function (func_1) {
|
|
|
304
304
|
error_1 = _d.sent();
|
|
305
305
|
Sentry.captureException(error_1);
|
|
306
306
|
logger_1.logger.error("Error running script ".concat(name, ": ").concat(error_1, "\n").concat(error_1.stack));
|
|
307
|
-
return [4 /*yield*/, (0,
|
|
307
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Error running script ".concat(name, ": ").concat(error_1, "\n").concat(error_1.stack))];
|
|
308
308
|
case 7:
|
|
309
309
|
_d.sent();
|
|
310
310
|
return [4 /*yield*/, Sentry.flush()];
|
|
@@ -312,7 +312,7 @@ var wrapScript = function (func_1) {
|
|
|
312
312
|
_d.sent();
|
|
313
313
|
process.exit(1);
|
|
314
314
|
return [3 /*break*/, 9];
|
|
315
|
-
case 9: return [4 /*yield*/, (0,
|
|
315
|
+
case 9: return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Success running script ".concat(name, ": ").concat(result))];
|
|
316
316
|
case 10:
|
|
317
317
|
_d.sent();
|
|
318
318
|
process.exit(0);
|
|
@@ -1201,6 +1201,28 @@ var typedUserModel = tests_1.UserModel;
|
|
|
1201
1201
|
}
|
|
1202
1202
|
});
|
|
1203
1203
|
}); });
|
|
1204
|
+
(0, bun_test_1.it)("terminate timeout callback reports the timeout and exits with code 2", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1205
|
+
var func, closeTimer, runCloseTimer;
|
|
1206
|
+
return __generator(this, function (_a) {
|
|
1207
|
+
switch (_a.label) {
|
|
1208
|
+
case 0:
|
|
1209
|
+
func = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1210
|
+
return [2 /*return*/, "ok"];
|
|
1211
|
+
}); }); };
|
|
1212
|
+
return [4 /*yield*/, (0, bun_test_1.expect)((0, expressServer_1.wrapScript)(func, { terminateTimeout: 100 })).rejects.toThrow("__EXIT__")];
|
|
1213
|
+
case 1:
|
|
1214
|
+
_a.sent();
|
|
1215
|
+
closeTimer = timerCallbacks.find(function (t) { return t.delay === 100000; });
|
|
1216
|
+
(0, bun_test_1.expect)(closeTimer).toBeDefined();
|
|
1217
|
+
runCloseTimer = closeTimer === null || closeTimer === void 0 ? void 0 : closeTimer.callback;
|
|
1218
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(runCloseTimer()).rejects.toThrow("__EXIT__")];
|
|
1219
|
+
case 2:
|
|
1220
|
+
_a.sent();
|
|
1221
|
+
(0, bun_test_1.expect)(process.exit).toHaveBeenCalledWith(2);
|
|
1222
|
+
return [2 /*return*/];
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
}); });
|
|
1204
1226
|
});
|
|
1205
1227
|
(0, bun_test_1.describe)("TerrenoApp error handling", function () {
|
|
1206
1228
|
var originalEnv = process.env;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export * from "./middleware";
|
|
|
18
18
|
export * from "./models/consentForm";
|
|
19
19
|
export * from "./models/consentResponse";
|
|
20
20
|
export * from "./models/versionConfig";
|
|
21
|
-
export * from "./notifiers";
|
|
21
|
+
export * from "./notifiers/googleChatNotifier";
|
|
22
|
+
export * from "./notifiers/slackNotifier";
|
|
23
|
+
export * from "./notifiers/zoomNotifier";
|
|
22
24
|
export * from "./openApiBuilder";
|
|
23
25
|
export * from "./openApiCompat";
|
|
24
26
|
export * from "./openApiEtag";
|
|
@@ -26,7 +28,12 @@ export * from "./openApiValidator";
|
|
|
26
28
|
export * from "./permissions";
|
|
27
29
|
export * from "./plugins";
|
|
28
30
|
export * from "./populate";
|
|
29
|
-
export
|
|
31
|
+
export { startChangeStreamWatcher, stopChangeStreamWatcher, } from "./realtime/changeStreamWatcher";
|
|
32
|
+
export { matchesQuery } from "./realtime/queryMatcher";
|
|
33
|
+
export { addQuerySubscription, clearQueryStore, computeQueryId, getQuerySubscriptionsForCollection, removeAllSocketQueries, removeQuerySubscription, } from "./realtime/queryStore";
|
|
34
|
+
export { installRealtimeSocketHandlers, MAX_DOCUMENT_SUBSCRIPTIONS, MAX_MODEL_SUBSCRIPTIONS, MAX_QUERY_SUBSCRIPTIONS, RealtimeApp, type RealtimeSocketLike, } from "./realtime/realtimeApp";
|
|
35
|
+
export { clearRealtimeRegistry, findRegistryEntryByCollection, findRegistryEntryByRoutePath, getRealtimeRegistry, type RealtimeRegistryEntry, registerRealtime, } from "./realtime/registry";
|
|
36
|
+
export type { ChangeStreamConfig, DocumentSubscription, QuerySubscription, RealtimeAppOptions, RealtimeConfig, RealtimeEvent, } from "./realtime/types";
|
|
30
37
|
export * from "./requestContext";
|
|
31
38
|
export * from "./scriptRunner";
|
|
32
39
|
export * from "./secretProviders";
|
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 = void 0;
|
|
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;
|
|
18
18
|
__exportStar(require("./actions"), exports);
|
|
19
19
|
__exportStar(require("./api"), exports);
|
|
20
20
|
__exportStar(require("./auth"), exports);
|
|
@@ -35,7 +35,9 @@ __exportStar(require("./middleware"), exports);
|
|
|
35
35
|
__exportStar(require("./models/consentForm"), exports);
|
|
36
36
|
__exportStar(require("./models/consentResponse"), exports);
|
|
37
37
|
__exportStar(require("./models/versionConfig"), exports);
|
|
38
|
-
__exportStar(require("./notifiers"), exports);
|
|
38
|
+
__exportStar(require("./notifiers/googleChatNotifier"), exports);
|
|
39
|
+
__exportStar(require("./notifiers/slackNotifier"), exports);
|
|
40
|
+
__exportStar(require("./notifiers/zoomNotifier"), exports);
|
|
39
41
|
__exportStar(require("./openApiBuilder"), exports);
|
|
40
42
|
__exportStar(require("./openApiCompat"), exports);
|
|
41
43
|
__exportStar(require("./openApiEtag"), exports);
|
|
@@ -43,7 +45,30 @@ __exportStar(require("./openApiValidator"), exports);
|
|
|
43
45
|
__exportStar(require("./permissions"), exports);
|
|
44
46
|
__exportStar(require("./plugins"), exports);
|
|
45
47
|
__exportStar(require("./populate"), exports);
|
|
46
|
-
|
|
48
|
+
var changeStreamWatcher_1 = require("./realtime/changeStreamWatcher");
|
|
49
|
+
Object.defineProperty(exports, "startChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.startChangeStreamWatcher; } });
|
|
50
|
+
Object.defineProperty(exports, "stopChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.stopChangeStreamWatcher; } });
|
|
51
|
+
var queryMatcher_1 = require("./realtime/queryMatcher");
|
|
52
|
+
Object.defineProperty(exports, "matchesQuery", { enumerable: true, get: function () { return queryMatcher_1.matchesQuery; } });
|
|
53
|
+
var queryStore_1 = require("./realtime/queryStore");
|
|
54
|
+
Object.defineProperty(exports, "addQuerySubscription", { enumerable: true, get: function () { return queryStore_1.addQuerySubscription; } });
|
|
55
|
+
Object.defineProperty(exports, "clearQueryStore", { enumerable: true, get: function () { return queryStore_1.clearQueryStore; } });
|
|
56
|
+
Object.defineProperty(exports, "computeQueryId", { enumerable: true, get: function () { return queryStore_1.computeQueryId; } });
|
|
57
|
+
Object.defineProperty(exports, "getQuerySubscriptionsForCollection", { enumerable: true, get: function () { return queryStore_1.getQuerySubscriptionsForCollection; } });
|
|
58
|
+
Object.defineProperty(exports, "removeAllSocketQueries", { enumerable: true, get: function () { return queryStore_1.removeAllSocketQueries; } });
|
|
59
|
+
Object.defineProperty(exports, "removeQuerySubscription", { enumerable: true, get: function () { return queryStore_1.removeQuerySubscription; } });
|
|
60
|
+
var realtimeApp_1 = require("./realtime/realtimeApp");
|
|
61
|
+
Object.defineProperty(exports, "installRealtimeSocketHandlers", { enumerable: true, get: function () { return realtimeApp_1.installRealtimeSocketHandlers; } });
|
|
62
|
+
Object.defineProperty(exports, "MAX_DOCUMENT_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_DOCUMENT_SUBSCRIPTIONS; } });
|
|
63
|
+
Object.defineProperty(exports, "MAX_MODEL_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_MODEL_SUBSCRIPTIONS; } });
|
|
64
|
+
Object.defineProperty(exports, "MAX_QUERY_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_QUERY_SUBSCRIPTIONS; } });
|
|
65
|
+
Object.defineProperty(exports, "RealtimeApp", { enumerable: true, get: function () { return realtimeApp_1.RealtimeApp; } });
|
|
66
|
+
var registry_1 = require("./realtime/registry");
|
|
67
|
+
Object.defineProperty(exports, "clearRealtimeRegistry", { enumerable: true, get: function () { return registry_1.clearRealtimeRegistry; } });
|
|
68
|
+
Object.defineProperty(exports, "findRegistryEntryByCollection", { enumerable: true, get: function () { return registry_1.findRegistryEntryByCollection; } });
|
|
69
|
+
Object.defineProperty(exports, "findRegistryEntryByRoutePath", { enumerable: true, get: function () { return registry_1.findRegistryEntryByRoutePath; } });
|
|
70
|
+
Object.defineProperty(exports, "getRealtimeRegistry", { enumerable: true, get: function () { return registry_1.getRealtimeRegistry; } });
|
|
71
|
+
Object.defineProperty(exports, "registerRealtime", { enumerable: true, get: function () { return registry_1.registerRealtime; } });
|
|
47
72
|
__exportStar(require("./requestContext"), exports);
|
|
48
73
|
__exportStar(require("./scriptRunner"), exports);
|
|
49
74
|
__exportStar(require("./secretProviders"), exports);
|
package/dist/openApi.test.js
CHANGED
|
@@ -293,6 +293,57 @@ function addRoutes(router, options) {
|
|
|
293
293
|
});
|
|
294
294
|
}); });
|
|
295
295
|
});
|
|
296
|
+
function addRoutesStringQuery(router, options) {
|
|
297
|
+
router.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, __assign(__assign({}, options), { allowAnonymous: true, permissions: {
|
|
298
|
+
create: [permissions_1.Permissions.IsAny],
|
|
299
|
+
delete: [permissions_1.Permissions.IsAny],
|
|
300
|
+
list: [permissions_1.Permissions.IsAny],
|
|
301
|
+
read: [permissions_1.Permissions.IsAny],
|
|
302
|
+
update: [permissions_1.Permissions.IsAny],
|
|
303
|
+
}, queryFields: ["name"] })));
|
|
304
|
+
}
|
|
305
|
+
(0, bun_test_1.describe)("openApi string query fields", function () {
|
|
306
|
+
var server;
|
|
307
|
+
var app;
|
|
308
|
+
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
|
|
311
|
+
process.env.ENABLE_SWAGGER = "true";
|
|
312
|
+
app = new terrenoApp_1.TerrenoApp({
|
|
313
|
+
configureApp: addRoutesStringQuery,
|
|
314
|
+
skipListen: true,
|
|
315
|
+
userModel: tests_1.UserModel,
|
|
316
|
+
}).build();
|
|
317
|
+
return [2 /*return*/];
|
|
318
|
+
});
|
|
319
|
+
}); });
|
|
320
|
+
(0, bun_test_1.it)("builds an $in array query param for non-numeric query fields", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
321
|
+
var res, nameQuery;
|
|
322
|
+
return __generator(this, function (_a) {
|
|
323
|
+
switch (_a.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
server = (0, supertest_1.default)(app);
|
|
326
|
+
return [4 /*yield*/, server.get("/openapi.json").expect(200)];
|
|
327
|
+
case 1:
|
|
328
|
+
res = _a.sent();
|
|
329
|
+
nameQuery = res.body.paths["/food/"].get.parameters.find(function (p) { return p.name === "name"; });
|
|
330
|
+
// Non-number/non-datetime fields support equality and $in array matching.
|
|
331
|
+
(0, bun_test_1.expect)(nameQuery.schema).toEqual({
|
|
332
|
+
oneOf: [
|
|
333
|
+
{ description: "The name of the food", type: "string" },
|
|
334
|
+
{
|
|
335
|
+
properties: {
|
|
336
|
+
$in: { items: { type: "string" }, type: "array" },
|
|
337
|
+
},
|
|
338
|
+
type: "object",
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
});
|
|
342
|
+
return [2 /*return*/];
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}); });
|
|
346
|
+
});
|
|
296
347
|
function addRoutesPopulate(router, options) {
|
|
297
348
|
var _a;
|
|
298
349
|
(_a = options === null || options === void 0 ? void 0 : options.openApi) === null || _a === void 0 ? void 0 : _a.component("schemas", "LimitedUser", {
|
|
@@ -26,7 +26,7 @@ app.get("/secure", (0, auth_1.authenticateMiddleware)(), function (_req, res) {
|
|
|
26
26
|
});
|
|
27
27
|
app.use(errors_1.apiUnauthorizedMiddleware);
|
|
28
28
|
app.use(errors_1.apiErrorMiddleware);
|
|
29
|
-
// Terreno's fallthrough
|
|
29
|
+
// Terreno's fallthrough turns requests reaching here into a 500. The
|
|
30
30
|
// regression turns auth failures into exactly this kind of error.
|
|
31
31
|
app.use(function (err, _req, res, _next) {
|
|
32
32
|
res.status(500).json({ status: 500, title: "Fallthrough error: ".concat(err.message) });
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"@asteasolutions/zod-to-openapi": "^8.5.0",
|
|
8
8
|
"@sentry/bun": "^10.39.0",
|
|
9
9
|
"@sentry/profiling-node": "^10.25.0",
|
|
10
|
-
"@terreno/test": "0.
|
|
10
|
+
"@terreno/test": "0.26.0",
|
|
11
11
|
"@types/qs": "^6.14.0",
|
|
12
12
|
"ajv": "8.18.0",
|
|
13
13
|
"ajv-formats": "^3.0.1",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"updateSnapshot": "bun test --update-snapshots"
|
|
124
124
|
},
|
|
125
125
|
"types": "dist/index.d.ts",
|
|
126
|
-
"version": "0.
|
|
126
|
+
"version": "0.26.0"
|
|
127
127
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
2
3
|
import supertest from "supertest";
|
|
3
4
|
import type {UserModel as UserModelType} from "../auth";
|
|
4
5
|
import {VersionConfig} from "../models/versionConfig";
|
|
@@ -55,6 +56,14 @@ describe("VersionCheckPlugin", () => {
|
|
|
55
56
|
expect(res.body).toEqual(expect.objectContaining({status: "ok"}));
|
|
56
57
|
});
|
|
57
58
|
|
|
59
|
+
it("returns ok when version is provided more than once", async () => {
|
|
60
|
+
const res = await app.get("/version-check?platform=mobile&version=1&version=2");
|
|
61
|
+
|
|
62
|
+
assert.equal(res.status, 200);
|
|
63
|
+
assert.equal(res.body.status, "ok");
|
|
64
|
+
assert.notProperty(res.body, "pollingIntervalMs");
|
|
65
|
+
});
|
|
66
|
+
|
|
58
67
|
it("returns ok when client version >= warning and required (web)", async () => {
|
|
59
68
|
await VersionConfig.create({
|
|
60
69
|
webRequiredVersion: 50,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {afterAll, afterEach, describe, expect, it} from "bun:test";
|
|
3
2
|
import express from "express";
|
|
4
3
|
import {MongoMemoryServer} from "mongodb-memory-server";
|
|
@@ -9,7 +8,6 @@ import {BetterAuthApp} from "./betterAuthApp";
|
|
|
9
8
|
|
|
10
9
|
let conn: mongoose.Connection;
|
|
11
10
|
let mongod: MongoMemoryServer;
|
|
12
|
-
let TestUser: any;
|
|
13
11
|
|
|
14
12
|
const testUserSchema = new Schema({
|
|
15
13
|
admin: {default: false, type: Boolean},
|
|
@@ -19,6 +17,8 @@ const testUserSchema = new Schema({
|
|
|
19
17
|
oauthProvider: {type: String},
|
|
20
18
|
});
|
|
21
19
|
|
|
20
|
+
let TestUser: mongoose.Model<mongoose.InferSchemaType<typeof testUserSchema>>;
|
|
21
|
+
|
|
22
22
|
const setup = (async () => {
|
|
23
23
|
mongod = await MongoMemoryServer.create();
|
|
24
24
|
conn = mongoose.createConnection(mongod.getUri());
|
|
@@ -78,7 +78,7 @@ describe("BetterAuthApp", () => {
|
|
|
78
78
|
|
|
79
79
|
const plugin = new BetterAuthApp({
|
|
80
80
|
config: makeConfig(),
|
|
81
|
-
userModel: TestUser as UserModel,
|
|
81
|
+
userModel: TestUser as unknown as UserModel,
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
expect(() => plugin.register(app)).not.toThrow();
|
|
@@ -951,6 +951,18 @@ describe("expressServer", () => {
|
|
|
951
951
|
expect(warnTimer).toBeDefined();
|
|
952
952
|
expect(closeTimer).toBeDefined();
|
|
953
953
|
});
|
|
954
|
+
|
|
955
|
+
it("terminate timeout callback reports the timeout and exits with code 2", async () => {
|
|
956
|
+
const func = async () => "ok";
|
|
957
|
+
await expect(wrapScript(func, {terminateTimeout: 100})).rejects.toThrow("__EXIT__");
|
|
958
|
+
|
|
959
|
+
const closeTimer = timerCallbacks.find((t) => t.delay === 100000);
|
|
960
|
+
expect(closeTimer).toBeDefined();
|
|
961
|
+
|
|
962
|
+
const runCloseTimer = closeTimer?.callback as unknown as () => Promise<void>;
|
|
963
|
+
await expect(runCloseTimer()).rejects.toThrow("__EXIT__");
|
|
964
|
+
expect(process.exit).toHaveBeenCalledWith(2);
|
|
965
|
+
});
|
|
954
966
|
});
|
|
955
967
|
|
|
956
968
|
describe("TerrenoApp error handling", () => {
|
package/src/expressServer.ts
CHANGED
|
@@ -8,7 +8,7 @@ import onFinished from "on-finished";
|
|
|
8
8
|
import passport from "passport";
|
|
9
9
|
import type {ModelRouterOptions} from "./api";
|
|
10
10
|
import {type LoggingOptions, logger} from "./logger";
|
|
11
|
-
import {sendToSlack} from "./notifiers";
|
|
11
|
+
import {sendToSlack} from "./notifiers/slackNotifier";
|
|
12
12
|
|
|
13
13
|
const SLOW_READ_MAX = 200;
|
|
14
14
|
const SLOW_WRITE_MAX = 500;
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,9 @@ export * from "./middleware";
|
|
|
18
18
|
export * from "./models/consentForm";
|
|
19
19
|
export * from "./models/consentResponse";
|
|
20
20
|
export * from "./models/versionConfig";
|
|
21
|
-
export * from "./notifiers";
|
|
21
|
+
export * from "./notifiers/googleChatNotifier";
|
|
22
|
+
export * from "./notifiers/slackNotifier";
|
|
23
|
+
export * from "./notifiers/zoomNotifier";
|
|
22
24
|
export * from "./openApiBuilder";
|
|
23
25
|
export * from "./openApiCompat";
|
|
24
26
|
export * from "./openApiEtag";
|
|
@@ -26,7 +28,43 @@ export * from "./openApiValidator";
|
|
|
26
28
|
export * from "./permissions";
|
|
27
29
|
export * from "./plugins";
|
|
28
30
|
export * from "./populate";
|
|
29
|
-
export
|
|
31
|
+
export {
|
|
32
|
+
startChangeStreamWatcher,
|
|
33
|
+
stopChangeStreamWatcher,
|
|
34
|
+
} from "./realtime/changeStreamWatcher";
|
|
35
|
+
export {matchesQuery} from "./realtime/queryMatcher";
|
|
36
|
+
export {
|
|
37
|
+
addQuerySubscription,
|
|
38
|
+
clearQueryStore,
|
|
39
|
+
computeQueryId,
|
|
40
|
+
getQuerySubscriptionsForCollection,
|
|
41
|
+
removeAllSocketQueries,
|
|
42
|
+
removeQuerySubscription,
|
|
43
|
+
} from "./realtime/queryStore";
|
|
44
|
+
export {
|
|
45
|
+
installRealtimeSocketHandlers,
|
|
46
|
+
MAX_DOCUMENT_SUBSCRIPTIONS,
|
|
47
|
+
MAX_MODEL_SUBSCRIPTIONS,
|
|
48
|
+
MAX_QUERY_SUBSCRIPTIONS,
|
|
49
|
+
RealtimeApp,
|
|
50
|
+
type RealtimeSocketLike,
|
|
51
|
+
} from "./realtime/realtimeApp";
|
|
52
|
+
export {
|
|
53
|
+
clearRealtimeRegistry,
|
|
54
|
+
findRegistryEntryByCollection,
|
|
55
|
+
findRegistryEntryByRoutePath,
|
|
56
|
+
getRealtimeRegistry,
|
|
57
|
+
type RealtimeRegistryEntry,
|
|
58
|
+
registerRealtime,
|
|
59
|
+
} from "./realtime/registry";
|
|
60
|
+
export type {
|
|
61
|
+
ChangeStreamConfig,
|
|
62
|
+
DocumentSubscription,
|
|
63
|
+
QuerySubscription,
|
|
64
|
+
RealtimeAppOptions,
|
|
65
|
+
RealtimeConfig,
|
|
66
|
+
RealtimeEvent,
|
|
67
|
+
} from "./realtime/types";
|
|
30
68
|
export * from "./requestContext";
|
|
31
69
|
export * from "./scriptRunner";
|
|
32
70
|
export * from "./secretProviders";
|
package/src/openApi.test.ts
CHANGED
|
@@ -186,6 +186,59 @@ describe("openApi", () => {
|
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
+
function addRoutesStringQuery(router: Router, options?: Partial<ModelRouterOptions<any>>): void {
|
|
190
|
+
router.use(
|
|
191
|
+
"/food",
|
|
192
|
+
modelRouter(FoodModel as any, {
|
|
193
|
+
...options,
|
|
194
|
+
allowAnonymous: true,
|
|
195
|
+
permissions: {
|
|
196
|
+
create: [Permissions.IsAny],
|
|
197
|
+
delete: [Permissions.IsAny],
|
|
198
|
+
list: [Permissions.IsAny],
|
|
199
|
+
read: [Permissions.IsAny],
|
|
200
|
+
update: [Permissions.IsAny],
|
|
201
|
+
},
|
|
202
|
+
queryFields: ["name"],
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
describe("openApi string query fields", () => {
|
|
208
|
+
let server: TestAgent;
|
|
209
|
+
let app: express.Application;
|
|
210
|
+
|
|
211
|
+
beforeEach(async () => {
|
|
212
|
+
process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
|
|
213
|
+
process.env.ENABLE_SWAGGER = "true";
|
|
214
|
+
|
|
215
|
+
app = new TerrenoApp({
|
|
216
|
+
configureApp: addRoutesStringQuery,
|
|
217
|
+
skipListen: true,
|
|
218
|
+
userModel: UserModel as any,
|
|
219
|
+
}).build();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("builds an $in array query param for non-numeric query fields", async () => {
|
|
223
|
+
server = supertest(app);
|
|
224
|
+
const res = await server.get("/openapi.json").expect(200);
|
|
225
|
+
const nameQuery = res.body.paths["/food/"].get.parameters.find((p) => p.name === "name");
|
|
226
|
+
|
|
227
|
+
// Non-number/non-datetime fields support equality and $in array matching.
|
|
228
|
+
expect(nameQuery.schema).toEqual({
|
|
229
|
+
oneOf: [
|
|
230
|
+
{description: "The name of the food", type: "string"},
|
|
231
|
+
{
|
|
232
|
+
properties: {
|
|
233
|
+
$in: {items: {type: "string"}, type: "array"},
|
|
234
|
+
},
|
|
235
|
+
type: "object",
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
189
242
|
function addRoutesPopulate(router: Router, options?: Partial<ModelRouterOptions<any>>): void {
|
|
190
243
|
options?.openApi?.component("schemas", "LimitedUser", {
|
|
191
244
|
properties: {
|
|
@@ -31,7 +31,7 @@ app.get("/secure", authenticateMiddleware(), (_req, res) => {
|
|
|
31
31
|
|
|
32
32
|
app.use(apiUnauthorizedMiddleware);
|
|
33
33
|
app.use(apiErrorMiddleware);
|
|
34
|
-
// Terreno's fallthrough
|
|
34
|
+
// Terreno's fallthrough turns requests reaching here into a 500. The
|
|
35
35
|
// regression turns auth failures into exactly this kind of error.
|
|
36
36
|
app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
|
37
37
|
res.status(500).json({status: 500, title: `Fallthrough error: ${err.message}`});
|
package/dist/notifiers/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./googleChatNotifier"), exports);
|
|
18
|
-
__exportStar(require("./slackNotifier"), exports);
|
|
19
|
-
__exportStar(require("./zoomNotifier"), exports);
|
package/dist/realtime/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { startChangeStreamWatcher, stopChangeStreamWatcher } from "./changeStreamWatcher";
|
|
2
|
-
export { matchesQuery } from "./queryMatcher";
|
|
3
|
-
export { addQuerySubscription, clearQueryStore, computeQueryId, getQuerySubscriptionsForCollection, removeAllSocketQueries, removeQuerySubscription, } from "./queryStore";
|
|
4
|
-
export { installRealtimeSocketHandlers, MAX_DOCUMENT_SUBSCRIPTIONS, MAX_MODEL_SUBSCRIPTIONS, MAX_QUERY_SUBSCRIPTIONS, RealtimeApp, type RealtimeSocketLike, } from "./realtimeApp";
|
|
5
|
-
export { clearRealtimeRegistry, findRegistryEntryByCollection, findRegistryEntryByRoutePath, getRealtimeRegistry, type RealtimeRegistryEntry, registerRealtime, } from "./registry";
|
|
6
|
-
export type { ChangeStreamConfig, DocumentSubscription, QuerySubscription, RealtimeAppOptions, RealtimeConfig, RealtimeEvent, } from "./types";
|
package/dist/realtime/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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;
|
|
4
|
-
var changeStreamWatcher_1 = require("./changeStreamWatcher");
|
|
5
|
-
Object.defineProperty(exports, "startChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.startChangeStreamWatcher; } });
|
|
6
|
-
Object.defineProperty(exports, "stopChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.stopChangeStreamWatcher; } });
|
|
7
|
-
var queryMatcher_1 = require("./queryMatcher");
|
|
8
|
-
Object.defineProperty(exports, "matchesQuery", { enumerable: true, get: function () { return queryMatcher_1.matchesQuery; } });
|
|
9
|
-
var queryStore_1 = require("./queryStore");
|
|
10
|
-
Object.defineProperty(exports, "addQuerySubscription", { enumerable: true, get: function () { return queryStore_1.addQuerySubscription; } });
|
|
11
|
-
Object.defineProperty(exports, "clearQueryStore", { enumerable: true, get: function () { return queryStore_1.clearQueryStore; } });
|
|
12
|
-
Object.defineProperty(exports, "computeQueryId", { enumerable: true, get: function () { return queryStore_1.computeQueryId; } });
|
|
13
|
-
Object.defineProperty(exports, "getQuerySubscriptionsForCollection", { enumerable: true, get: function () { return queryStore_1.getQuerySubscriptionsForCollection; } });
|
|
14
|
-
Object.defineProperty(exports, "removeAllSocketQueries", { enumerable: true, get: function () { return queryStore_1.removeAllSocketQueries; } });
|
|
15
|
-
Object.defineProperty(exports, "removeQuerySubscription", { enumerable: true, get: function () { return queryStore_1.removeQuerySubscription; } });
|
|
16
|
-
var realtimeApp_1 = require("./realtimeApp");
|
|
17
|
-
Object.defineProperty(exports, "installRealtimeSocketHandlers", { enumerable: true, get: function () { return realtimeApp_1.installRealtimeSocketHandlers; } });
|
|
18
|
-
Object.defineProperty(exports, "MAX_DOCUMENT_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_DOCUMENT_SUBSCRIPTIONS; } });
|
|
19
|
-
Object.defineProperty(exports, "MAX_MODEL_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_MODEL_SUBSCRIPTIONS; } });
|
|
20
|
-
Object.defineProperty(exports, "MAX_QUERY_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_QUERY_SUBSCRIPTIONS; } });
|
|
21
|
-
Object.defineProperty(exports, "RealtimeApp", { enumerable: true, get: function () { return realtimeApp_1.RealtimeApp; } });
|
|
22
|
-
var registry_1 = require("./registry");
|
|
23
|
-
Object.defineProperty(exports, "clearRealtimeRegistry", { enumerable: true, get: function () { return registry_1.clearRealtimeRegistry; } });
|
|
24
|
-
Object.defineProperty(exports, "findRegistryEntryByCollection", { enumerable: true, get: function () { return registry_1.findRegistryEntryByCollection; } });
|
|
25
|
-
Object.defineProperty(exports, "findRegistryEntryByRoutePath", { enumerable: true, get: function () { return registry_1.findRegistryEntryByRoutePath; } });
|
|
26
|
-
Object.defineProperty(exports, "getRealtimeRegistry", { enumerable: true, get: function () { return registry_1.getRealtimeRegistry; } });
|
|
27
|
-
Object.defineProperty(exports, "registerRealtime", { enumerable: true, get: function () { return registry_1.registerRealtime; } });
|
package/src/notifiers/index.ts
DELETED
package/src/realtime/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export {startChangeStreamWatcher, stopChangeStreamWatcher} from "./changeStreamWatcher";
|
|
2
|
-
export {matchesQuery} from "./queryMatcher";
|
|
3
|
-
export {
|
|
4
|
-
addQuerySubscription,
|
|
5
|
-
clearQueryStore,
|
|
6
|
-
computeQueryId,
|
|
7
|
-
getQuerySubscriptionsForCollection,
|
|
8
|
-
removeAllSocketQueries,
|
|
9
|
-
removeQuerySubscription,
|
|
10
|
-
} from "./queryStore";
|
|
11
|
-
export {
|
|
12
|
-
installRealtimeSocketHandlers,
|
|
13
|
-
MAX_DOCUMENT_SUBSCRIPTIONS,
|
|
14
|
-
MAX_MODEL_SUBSCRIPTIONS,
|
|
15
|
-
MAX_QUERY_SUBSCRIPTIONS,
|
|
16
|
-
RealtimeApp,
|
|
17
|
-
type RealtimeSocketLike,
|
|
18
|
-
} from "./realtimeApp";
|
|
19
|
-
export {
|
|
20
|
-
clearRealtimeRegistry,
|
|
21
|
-
findRegistryEntryByCollection,
|
|
22
|
-
findRegistryEntryByRoutePath,
|
|
23
|
-
getRealtimeRegistry,
|
|
24
|
-
type RealtimeRegistryEntry,
|
|
25
|
-
registerRealtime,
|
|
26
|
-
} from "./registry";
|
|
27
|
-
export type {
|
|
28
|
-
ChangeStreamConfig,
|
|
29
|
-
DocumentSubscription,
|
|
30
|
-
QuerySubscription,
|
|
31
|
-
RealtimeAppOptions,
|
|
32
|
-
RealtimeConfig,
|
|
33
|
-
RealtimeEvent,
|
|
34
|
-
} from "./types";
|