@terreno/api 0.25.0 → 0.27.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__/openApiCompat.test.js +8 -2
- package/dist/__tests__/versionCheckPlugin.test.js +15 -0
- package/dist/actions.openApi.test.js +1 -0
- package/dist/actions.test.js +1 -0
- package/dist/api.arrayOperations.test.js +1 -0
- package/dist/api.coverage.test.d.ts +1 -0
- package/dist/api.coverage.test.js +191 -0
- package/dist/api.errorPaths.test.d.ts +1 -0
- package/dist/api.errorPaths.test.js +278 -0
- package/dist/api.errors.test.js +1 -0
- package/dist/api.hooks.test.js +1 -0
- package/dist/api.js +160 -167
- package/dist/api.query.test.js +1 -0
- package/dist/api.test.js +1 -0
- package/dist/auth.js +1 -0
- package/dist/auth.test.js +122 -0
- package/dist/betterAuthApp.test.js +1 -2
- package/dist/betterAuthSetup.js +1 -0
- package/dist/betterAuthSetup.test.js +1 -0
- package/dist/configuration.test.js +1 -0
- package/dist/configurationApp.js +1 -0
- package/dist/configurationPlugin.test.js +80 -0
- package/dist/consentApp.test.js +1 -0
- package/dist/docLoader.js +1 -3
- package/dist/envConfigurationPlugin.js +1 -0
- package/dist/example.js +3 -2
- package/dist/expressServer.js +6 -6
- package/dist/expressServer.test.js +23 -0
- package/dist/githubAuth.js +2 -0
- package/dist/githubAuth.test.js +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +28 -3
- package/dist/logger.test.js +107 -0
- package/dist/openApi.test.js +52 -0
- package/dist/openApiBuilder.js +2 -1
- package/dist/openApiBuilder.test.js +3 -2
- package/dist/openApiValidator.js +1 -0
- package/dist/openApiValidator.test.js +41 -0
- package/dist/permissions.middleware.test.js +1 -0
- package/dist/permissions.test.js +1 -0
- package/dist/plugins.js +8 -0
- package/dist/plugins.test.js +1 -0
- package/dist/populate.js +4 -2
- package/dist/populate.test.js +1 -0
- package/dist/realtime/realtime.test.js +13 -3
- package/dist/realtime/types.d.ts +1 -1
- package/dist/requestContext.test.js +28 -0
- package/dist/terrenoApp.js +1 -0
- package/dist/tests/createTestData.js +11 -6
- package/dist/tests/fixtures/compileAuthEntry.js +1 -1
- package/dist/tests/models.js +1 -0
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +3 -1
- package/package.json +7 -7
- package/src/__tests__/openApiCompat.test.ts +8 -2
- package/src/__tests__/versionCheckPlugin.test.ts +9 -0
- package/src/actions.openApi.test.ts +1 -0
- package/src/actions.test.ts +1 -0
- package/src/api.arrayOperations.test.ts +1 -0
- package/src/api.coverage.test.ts +121 -0
- package/src/api.errorPaths.test.ts +171 -0
- package/src/api.errors.test.ts +1 -0
- package/src/api.hooks.test.ts +1 -0
- package/src/api.query.test.ts +1 -0
- package/src/api.test.ts +1 -0
- package/src/api.ts +13 -9
- package/src/auth.test.ts +91 -2
- package/src/auth.ts +6 -0
- package/src/betterAuthApp.test.ts +3 -3
- package/src/betterAuthSetup.test.ts +1 -0
- package/src/betterAuthSetup.ts +3 -0
- package/src/configuration.test.ts +1 -0
- package/src/configurationApp.ts +2 -0
- package/src/configurationPlugin.test.ts +46 -1
- package/src/consentApp.test.ts +1 -0
- package/src/docLoader.ts +1 -2
- package/src/envConfigurationPlugin.ts +2 -0
- package/src/example.ts +3 -2
- package/src/expressServer.test.ts +13 -0
- package/src/expressServer.ts +5 -3
- package/src/githubAuth.test.ts +1 -0
- package/src/githubAuth.ts +2 -0
- package/src/index.ts +40 -2
- package/src/logger.test.ts +78 -0
- package/src/openApi.test.ts +54 -0
- package/src/openApiBuilder.test.ts +7 -6
- package/src/openApiBuilder.ts +2 -1
- package/src/openApiValidator.test.ts +64 -0
- package/src/openApiValidator.ts +1 -0
- package/src/permissions.middleware.test.ts +1 -0
- package/src/permissions.test.ts +1 -0
- package/src/plugins.test.ts +1 -0
- package/src/plugins.ts +9 -0
- package/src/populate.test.ts +1 -0
- package/src/populate.ts +4 -2
- package/src/realtime/realtime.test.ts +13 -3
- package/src/realtime/realtimeApp.ts +1 -0
- package/src/realtime/registry.ts +1 -0
- package/src/realtime/types.ts +1 -2
- package/src/requestContext.test.ts +32 -0
- package/src/terrenoApp.ts +1 -0
- package/src/tests/createTestData.ts +11 -6
- package/src/tests/fixtures/compileAuthEntry.ts +1 -1
- package/src/tests/models.ts +1 -0
- package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +4 -1
- package/tsconfig.json +3 -3
- 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/{types.d.ts → src/types.d.ts} +0 -0
package/dist/permissions.test.js
CHANGED
|
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
// noExplicitAny: test mock typing
|
|
42
43
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
43
44
|
var bun_test_1 = require("bun:test");
|
|
44
45
|
var supertest_1 = __importDefault(require("supertest"));
|
package/dist/plugins.js
CHANGED
|
@@ -99,6 +99,7 @@ exports.DateOnly = exports.upsertPlugin = exports.findExactlyOne = exports.findO
|
|
|
99
99
|
var luxon_1 = require("luxon");
|
|
100
100
|
var mongoose_1 = __importStar(require("mongoose"));
|
|
101
101
|
var errors_1 = require("./errors");
|
|
102
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
102
103
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
103
104
|
var baseUserPlugin = function (schema) {
|
|
104
105
|
schema.add({
|
|
@@ -107,6 +108,7 @@ var baseUserPlugin = function (schema) {
|
|
|
107
108
|
schema.add({ email: { description: "The user's email address", index: true, type: String } });
|
|
108
109
|
};
|
|
109
110
|
exports.baseUserPlugin = baseUserPlugin;
|
|
111
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
110
112
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
111
113
|
var isDeletedPlugin = function (schema, defaultValue) {
|
|
112
114
|
if (defaultValue === void 0) { defaultValue = false; }
|
|
@@ -119,6 +121,7 @@ var isDeletedPlugin = function (schema, defaultValue) {
|
|
|
119
121
|
type: Boolean,
|
|
120
122
|
},
|
|
121
123
|
});
|
|
124
|
+
// noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
|
|
122
125
|
// biome-ignore lint/suspicious/noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
|
|
123
126
|
var applyDeleteFilter = function (q) {
|
|
124
127
|
var query = q.getQuery();
|
|
@@ -135,6 +138,7 @@ var isDeletedPlugin = function (schema, defaultValue) {
|
|
|
135
138
|
};
|
|
136
139
|
exports.isDeletedPlugin = isDeletedPlugin;
|
|
137
140
|
var isDisabledPlugin = function (
|
|
141
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
138
142
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
139
143
|
schema, defaultValue) {
|
|
140
144
|
if (defaultValue === void 0) { defaultValue = false; }
|
|
@@ -148,6 +152,7 @@ schema, defaultValue) {
|
|
|
148
152
|
});
|
|
149
153
|
};
|
|
150
154
|
exports.isDisabledPlugin = isDisabledPlugin;
|
|
155
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
151
156
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
152
157
|
var createdUpdatedPlugin = function (schema) {
|
|
153
158
|
schema.add({
|
|
@@ -274,6 +279,7 @@ exports.findExactlyOne = findExactlyOne;
|
|
|
274
279
|
* match the conditions to prevent ambiguous updates.
|
|
275
280
|
* @param schema Mongoose Schema
|
|
276
281
|
*/
|
|
282
|
+
// noExplicitAny: Schema generics with unknown collide with mongoose's loose this-binding on schema.statics
|
|
277
283
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics with unknown collide with mongoose's loose this-binding on schema.statics
|
|
278
284
|
var upsertPlugin = function (schema) {
|
|
279
285
|
schema.statics.upsert = function (conditions, update) {
|
|
@@ -322,6 +328,7 @@ var DateOnly = /** @class */ (function (_super) {
|
|
|
322
328
|
// When using $gt, $gte, $lt, $lte, etc, we need to cast the value to a Date
|
|
323
329
|
DateOnly.prototype.castForQuery = function ($conditional, val, context) {
|
|
324
330
|
if ($conditional == null) {
|
|
331
|
+
// noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
|
|
325
332
|
// biome-ignore lint/suspicious/noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
|
|
326
333
|
return this.applySetters(val, context);
|
|
327
334
|
}
|
|
@@ -363,5 +370,6 @@ var DateOnly = /** @class */ (function (_super) {
|
|
|
363
370
|
}(mongoose_1.SchemaType));
|
|
364
371
|
exports.DateOnly = DateOnly;
|
|
365
372
|
// Register DateOnly with Mongoose's Schema.Types
|
|
373
|
+
// noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
|
|
366
374
|
// biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
|
|
367
375
|
mongoose_1.default.Schema.Types.DateOnly = DateOnly;
|
package/dist/plugins.test.js
CHANGED
|
@@ -55,6 +55,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
56
56
|
};
|
|
57
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
// noExplicitAny: test mock typing
|
|
58
59
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
59
60
|
var bun_test_1 = require("bun:test");
|
|
60
61
|
var mongoose_1 = require("mongoose");
|
package/dist/populate.js
CHANGED
|
@@ -158,7 +158,8 @@ var fixMixedFields = function (schema, properties) {
|
|
|
158
158
|
};
|
|
159
159
|
exports.fixMixedFields = fixMixedFields;
|
|
160
160
|
var getOpenApiSpecForModel = function (
|
|
161
|
-
//
|
|
161
|
+
// noExplicitAny: Mongoose Model param uses deep internal APIs (schema.path().options.ref, schema.virtuals, schema.childSchemas, db.model) that are not exposed in public type definitions
|
|
162
|
+
// biome-ignore lint/suspicious/noExplicitAny: Mongoose Model param uses deep internal APIs (schema.path().options.ref, schema.virtuals, schema.childSchemas, db.model) that are not exposed in public type definitions
|
|
162
163
|
model, _a) {
|
|
163
164
|
var e_2, _b, _c, e_3, _d, e_4, _e, e_5, _f;
|
|
164
165
|
var _g, _h, _j, _k;
|
|
@@ -304,7 +305,8 @@ var unpopulate = function (doc, path) {
|
|
|
304
305
|
}
|
|
305
306
|
var pathParts = path.split(".");
|
|
306
307
|
// Recursive because we need to support nested paths.
|
|
307
|
-
//
|
|
308
|
+
// noExplicitAny: recursive document traversal uses bracket-notation indexing on arbitrary nested document shapes that Mongoose Document types do not expose
|
|
309
|
+
// biome-ignore lint/suspicious/noExplicitAny: recursive document traversal uses bracket-notation indexing on arbitrary nested document shapes that Mongoose Document types do not expose
|
|
308
310
|
var recursiveUnpopulate = function (current, parts) {
|
|
309
311
|
var e_6, _a;
|
|
310
312
|
var _b;
|
package/dist/populate.test.js
CHANGED
|
@@ -69,6 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
|
+
// noExplicitAny: test mock typing
|
|
72
73
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
73
74
|
var bun_test_1 = require("bun:test");
|
|
74
75
|
var mongoose_1 = __importStar(require("mongoose"));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// noExplicitAny: test mocks use dynamic shapes for registry entries and documents
|
|
2
3
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mocks use dynamic shapes for registry entries and documents
|
|
3
4
|
/**
|
|
4
5
|
* Tests for the realtime module's pure functions and classes:
|
|
@@ -1114,7 +1115,10 @@ var createMockSocket = function (decodedToken) {
|
|
|
1114
1115
|
_a.sent();
|
|
1115
1116
|
subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
|
|
1116
1117
|
(0, bun_test_1.expect)(subscribed).toBeDefined();
|
|
1117
|
-
|
|
1118
|
+
if (!subscribed) {
|
|
1119
|
+
throw new Error("Expected a query subscription event");
|
|
1120
|
+
}
|
|
1121
|
+
(0, bun_test_1.expect)(subscribed.payload.queryId).toContain("user1");
|
|
1118
1122
|
return [2 /*return*/];
|
|
1119
1123
|
}
|
|
1120
1124
|
});
|
|
@@ -1135,7 +1139,10 @@ var createMockSocket = function (decodedToken) {
|
|
|
1135
1139
|
_a.sent();
|
|
1136
1140
|
subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
|
|
1137
1141
|
(0, bun_test_1.expect)(subscribed).toBeDefined();
|
|
1138
|
-
|
|
1142
|
+
if (!subscribed) {
|
|
1143
|
+
throw new Error("Expected a query subscription event");
|
|
1144
|
+
}
|
|
1145
|
+
(0, bun_test_1.expect)(subscribed.payload.queryId).not.toContain("admin1");
|
|
1139
1146
|
return [2 /*return*/];
|
|
1140
1147
|
}
|
|
1141
1148
|
});
|
|
@@ -1438,7 +1445,10 @@ var createMockSocket = function (decodedToken) {
|
|
|
1438
1445
|
_a.sent();
|
|
1439
1446
|
subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
|
|
1440
1447
|
(0, bun_test_1.expect)(subscribed).toBeDefined();
|
|
1441
|
-
|
|
1448
|
+
if (!subscribed) {
|
|
1449
|
+
throw new Error("Expected a query subscription event");
|
|
1450
|
+
}
|
|
1451
|
+
queryId = subscribed.payload.queryId;
|
|
1442
1452
|
(0, bun_test_1.expect)(socket.rooms.has("query:".concat(queryId))).toBe(true);
|
|
1443
1453
|
(0, bun_test_1.expect)((0, queryStore_1.getQuerySubscriptionsForCollection)("broadcasts").length).toBe(1);
|
|
1444
1454
|
return [4 /*yield*/, socket.trigger("unsubscribe:query", { queryId: queryId })];
|
package/dist/realtime/types.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface RealtimeEvent {
|
|
|
30
30
|
/** Document ID */
|
|
31
31
|
id: string;
|
|
32
32
|
/** Serialized document data (omitted for hard deletes) */
|
|
33
|
-
data?:
|
|
33
|
+
data?: unknown;
|
|
34
34
|
/** Fields that were updated (for update events from change streams) */
|
|
35
35
|
updatedFields?: string[];
|
|
36
36
|
/** Epoch milliseconds when the event was generated */
|
|
@@ -355,6 +355,34 @@ var requestContext_1 = require("./requestContext");
|
|
|
355
355
|
});
|
|
356
356
|
(0, bun_test_1.expect)(ctx.traceId).toBeUndefined();
|
|
357
357
|
});
|
|
358
|
+
(0, bun_test_1.it)("returns undefined trace when google cloud trace context has empty trace id", function () {
|
|
359
|
+
var ctx = (0, requestContext_1.getRequestContextFromAttributes)({
|
|
360
|
+
"x-cloud-trace-context": "/1;o=1",
|
|
361
|
+
"x-request-id": "r7",
|
|
362
|
+
});
|
|
363
|
+
(0, bun_test_1.expect)(ctx.traceId).toBeUndefined();
|
|
364
|
+
(0, bun_test_1.expect)(ctx.spanId).toBeUndefined();
|
|
365
|
+
(0, bun_test_1.expect)(ctx.requestId).toBe("r7");
|
|
366
|
+
});
|
|
367
|
+
(0, bun_test_1.it)("reads the first value when a request header arrives as an array", function () {
|
|
368
|
+
var headers = {
|
|
369
|
+
"x-cloud-trace-context": ["arrtrace/7;o=1", "ignored/9;o=0"],
|
|
370
|
+
};
|
|
371
|
+
var req = {
|
|
372
|
+
header: function (name) { return headers[name.toLowerCase()]; },
|
|
373
|
+
user: undefined,
|
|
374
|
+
};
|
|
375
|
+
var res = {
|
|
376
|
+
setHeader: function () { },
|
|
377
|
+
};
|
|
378
|
+
var captured;
|
|
379
|
+
(0, requestContext_1.requestContextMiddleware)(req, res, function () {
|
|
380
|
+
var ctx = (0, requestContext_1.getCurrentRequestContext)();
|
|
381
|
+
captured = { spanId: ctx === null || ctx === void 0 ? void 0 : ctx.spanId, traceId: ctx === null || ctx === void 0 ? void 0 : ctx.traceId };
|
|
382
|
+
});
|
|
383
|
+
(0, bun_test_1.expect)(captured === null || captured === void 0 ? void 0 : captured.traceId).toBe("arrtrace");
|
|
384
|
+
(0, bun_test_1.expect)(captured === null || captured === void 0 ? void 0 : captured.spanId).toBe("7");
|
|
385
|
+
});
|
|
358
386
|
(0, bun_test_1.it)("adds job id to logger context", function () {
|
|
359
387
|
var output = "";
|
|
360
388
|
var stream = new node_stream_1.Writable({
|
package/dist/terrenoApp.js
CHANGED
|
@@ -218,6 +218,7 @@ var TerrenoApp = /** @class */ (function () {
|
|
|
218
218
|
* ```
|
|
219
219
|
*/
|
|
220
220
|
TerrenoApp.prototype.configure = function (
|
|
221
|
+
// noExplicitAny: Model<any> required for invariance — consumers pass arbitrary configuration models
|
|
221
222
|
// biome-ignore lint/suspicious/noExplicitAny: Model<any> required for invariance — consumers pass arbitrary configuration models
|
|
222
223
|
model, options) {
|
|
223
224
|
this.configurationApp = new configurationApp_1.ConfigurationApp(__assign({ model: model }, options));
|
|
@@ -53,6 +53,8 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
exports.loadTestDataFromDocuments = exports.toCachedTestData = exports.createTestData = exports.createRequiredFixtures = exports.createStandardFoods = exports.createTestUsers = exports.clearTestCollections = void 0;
|
|
56
|
+
var luxon_1 = require("luxon");
|
|
57
|
+
var errors_1 = require("../errors");
|
|
56
58
|
var logger_1 = require("../logger");
|
|
57
59
|
var models_1 = require("./models");
|
|
58
60
|
var setPassword = function (user, password) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -116,12 +118,12 @@ var createStandardFoods = function (users) { return __awaiter(void 0, void 0, vo
|
|
|
116
118
|
models_1.FoodModel.create({
|
|
117
119
|
calories: 1,
|
|
118
120
|
categories: [{ name: "Vegetables", show: true }],
|
|
119
|
-
created:
|
|
121
|
+
created: luxon_1.DateTime.fromISO("2021-12-03T00:00:20.000Z").toJSDate(),
|
|
120
122
|
eatenBy: [admin._id],
|
|
121
123
|
expiration: "2026-12-31",
|
|
122
124
|
hidden: false,
|
|
123
125
|
lastEatenWith: {
|
|
124
|
-
dressing:
|
|
126
|
+
dressing: luxon_1.DateTime.fromISO("2021-12-03T19:00:30.000Z").toJSDate(),
|
|
125
127
|
},
|
|
126
128
|
likesIds: [
|
|
127
129
|
{ likes: true, userId: admin._id },
|
|
@@ -138,7 +140,7 @@ var createStandardFoods = function (users) { return __awaiter(void 0, void 0, vo
|
|
|
138
140
|
}),
|
|
139
141
|
models_1.FoodModel.create({
|
|
140
142
|
calories: 100,
|
|
141
|
-
created:
|
|
143
|
+
created: luxon_1.DateTime.fromISO("2021-12-03T00:00:30.000Z").toJSDate(),
|
|
142
144
|
expiration: "2026-12-31",
|
|
143
145
|
hidden: true,
|
|
144
146
|
likesIds: [{ likes: true, userId: admin._id }],
|
|
@@ -149,7 +151,7 @@ var createStandardFoods = function (users) { return __awaiter(void 0, void 0, vo
|
|
|
149
151
|
}),
|
|
150
152
|
models_1.FoodModel.create({
|
|
151
153
|
calories: 100,
|
|
152
|
-
created:
|
|
154
|
+
created: luxon_1.DateTime.fromISO("2021-12-03T00:00:00.000Z").toJSDate(),
|
|
153
155
|
eatenBy: [admin._id, notAdmin._id],
|
|
154
156
|
expiration: "2026-12-31",
|
|
155
157
|
hidden: false,
|
|
@@ -161,7 +163,7 @@ var createStandardFoods = function (users) { return __awaiter(void 0, void 0, vo
|
|
|
161
163
|
}),
|
|
162
164
|
models_1.FoodModel.create({
|
|
163
165
|
calories: 800,
|
|
164
|
-
created:
|
|
166
|
+
created: luxon_1.DateTime.fromISO("2022-01-01T00:00:00.000Z").toJSDate(),
|
|
165
167
|
expiration: "2026-12-31",
|
|
166
168
|
hidden: false,
|
|
167
169
|
likesIds: [{ likes: true, userId: adminOther._id }],
|
|
@@ -259,7 +261,10 @@ var loadTestDataFromDocuments = function (cached) { return __awaiter(void 0, voi
|
|
|
259
261
|
!pizza ||
|
|
260
262
|
!sample ||
|
|
261
263
|
!withAbout) {
|
|
262
|
-
throw new
|
|
264
|
+
throw new errors_1.APIError({
|
|
265
|
+
status: 500,
|
|
266
|
+
title: "[createTestData] Cached test data references missing documents",
|
|
267
|
+
});
|
|
263
268
|
}
|
|
264
269
|
return [2 /*return*/, {
|
|
265
270
|
foods: { apple: apple, carrots: carrots, pizza: pizza, spinach: spinach },
|
|
@@ -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/dist/tests/models.js
CHANGED
|
@@ -101,6 +101,7 @@ var foodSchema = new mongoose_1.Schema({
|
|
|
101
101
|
type: mongoose_1.Schema.Types.ObjectId,
|
|
102
102
|
},
|
|
103
103
|
],
|
|
104
|
+
// noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
|
|
104
105
|
// biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
|
|
105
106
|
expiration: { description: "Expiration date of the food", type: plugins_1.DateOnly },
|
|
106
107
|
hidden: {
|
|
@@ -70,7 +70,7 @@ module.exports = function generateDocument(baseDocument, router, basePath) {
|
|
|
70
70
|
}
|
|
71
71
|
operation.parameters = params_1.filter(function (p) { return typeof p.name === 'string' && p.name; });
|
|
72
72
|
try {
|
|
73
|
-
path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)')
|
|
73
|
+
path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'), { encode: function (value) { return value; } })(keys_1);
|
|
74
74
|
}
|
|
75
75
|
catch (_e) {
|
|
76
76
|
// Express 5 stores path params in matchers instead of layer.keys, so keys
|
|
@@ -78,6 +78,8 @@ module.exports = function generateDocument(baseDocument, router, basePath) {
|
|
|
78
78
|
path = path.replace(/:([a-zA-Z0-9_]+)/g, '{$1}');
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
// Normalize any percent-encoded path parameters to OpenAPI syntax.
|
|
82
|
+
path = path.replace(/%7B/gi, '{').replace(/%7D/gi, '}');
|
|
81
83
|
doc.paths[path] = doc.paths[path] || {};
|
|
82
84
|
doc.paths[path][layer.method] = operation;
|
|
83
85
|
setSchema(layer.handle, operation);
|
package/package.json
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
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.27.0",
|
|
11
11
|
"@types/qs": "^6.14.0",
|
|
12
|
-
"ajv": "8.
|
|
12
|
+
"ajv": "8.20.0",
|
|
13
13
|
"ajv-formats": "^3.0.1",
|
|
14
14
|
"ajv-keywords": "^5.1.0",
|
|
15
15
|
"http-errors": "^2.0.0",
|
|
16
|
-
"path-to-regexp": "^
|
|
16
|
+
"path-to-regexp": "^8.4.2",
|
|
17
17
|
"router": "^2.2.0",
|
|
18
|
-
"serve-static": "^
|
|
18
|
+
"serve-static": "^2.2.1",
|
|
19
19
|
"swagger-parser": "^10.0.3",
|
|
20
20
|
"swagger-ui-dist": "^5.11.8",
|
|
21
21
|
"yaml": "^2.4.0",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"express": "^5.2.1",
|
|
28
28
|
"generaterr": "^1.5.0",
|
|
29
29
|
"jsonwebtoken": "^9.0.2",
|
|
30
|
-
"lodash": "^4.
|
|
30
|
+
"lodash": "^4.18.1",
|
|
31
31
|
"luxon": "^3.7.2",
|
|
32
32
|
"mongoose-to-swagger": "^1.4.0",
|
|
33
33
|
"ms": "^2.1.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/supertest": "^7.2.0",
|
|
67
67
|
"mongodb-memory-server": "^11.0.1",
|
|
68
68
|
"mongoose": "8.23.0",
|
|
69
|
-
"sinon": "^
|
|
69
|
+
"sinon": "^22.0.0",
|
|
70
70
|
"supertest": "^7.2.2",
|
|
71
71
|
"typedoc": "^0.28.17",
|
|
72
72
|
"typescript": "~5.9.2",
|
|
@@ -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.27.0"
|
|
127
127
|
}
|
|
@@ -203,7 +203,10 @@ describe("openApiCompat", () => {
|
|
|
203
203
|
const routeLayer = findLayer(stack, (layer) => layer.route?.path === "/items/:itemId");
|
|
204
204
|
expect(routeLayer).toBeDefined();
|
|
205
205
|
expect(routeLayer?.regexp).toBeInstanceOf(RegExp);
|
|
206
|
-
|
|
206
|
+
if (!(routeLayer?.regexp instanceof RegExp)) {
|
|
207
|
+
throw new Error("Expected the item route layer to have a regexp");
|
|
208
|
+
}
|
|
209
|
+
expect(routeLayer.regexp.test("/items/123")).toBe(true);
|
|
207
210
|
expect(routeLayer?.keys).toEqual([{name: "itemId", optional: false}]);
|
|
208
211
|
|
|
209
212
|
const res = await supertest(app).get("/items/123").expect(200);
|
|
@@ -275,7 +278,10 @@ describe("openApiCompat", () => {
|
|
|
275
278
|
const widgetLayer = findLayer(stack, (layer) => layer.route?.path === "/widgets/:widgetId");
|
|
276
279
|
expect(widgetLayer).toBeDefined();
|
|
277
280
|
expect(widgetLayer?.regexp).toBeInstanceOf(RegExp);
|
|
278
|
-
|
|
281
|
+
if (!(widgetLayer?.regexp instanceof RegExp)) {
|
|
282
|
+
throw new Error("Expected the widget route layer to have a regexp");
|
|
283
|
+
}
|
|
284
|
+
expect(widgetLayer.regexp.test("/widgets/42")).toBe(true);
|
|
279
285
|
expect(widgetLayer?.keys).toEqual([{name: "widgetId", optional: false}]);
|
|
280
286
|
});
|
|
281
287
|
|
|
@@ -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,
|
package/src/actions.test.ts
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
|
+
import {beforeEach, describe, expect, it} from "bun:test";
|
|
4
|
+
import type express from "express";
|
|
5
|
+
import mongoose from "mongoose";
|
|
6
|
+
import supertest from "supertest";
|
|
7
|
+
import type TestAgent from "supertest/lib/agent";
|
|
8
|
+
|
|
9
|
+
import {modelRouter} from "./api";
|
|
10
|
+
import {addAuthRoutes, setupAuth} from "./auth";
|
|
11
|
+
import {Permissions} from "./permissions";
|
|
12
|
+
import {type Food, FoodModel, getBaseServer, setupDb, UserModel} from "./tests";
|
|
13
|
+
|
|
14
|
+
// A model without the isDeleted plugin so deletes call doc.deleteOne(). The
|
|
15
|
+
// document delete hook throws to exercise the hard-delete error branch.
|
|
16
|
+
const explosiveSchema = new mongoose.Schema<{name: string}>({
|
|
17
|
+
name: {description: "The name of the item", type: String},
|
|
18
|
+
});
|
|
19
|
+
explosiveSchema.pre("deleteOne", {document: true, query: false}, () => {
|
|
20
|
+
throw new Error("deleteOne exploded");
|
|
21
|
+
});
|
|
22
|
+
const ExplosiveModel = mongoose.model<{name: string}>("ExplosiveCoverage", explosiveSchema);
|
|
23
|
+
|
|
24
|
+
describe("modelRouter error path coverage", () => {
|
|
25
|
+
let server: TestAgent;
|
|
26
|
+
let app: express.Application;
|
|
27
|
+
let admin: any;
|
|
28
|
+
let apple: Food;
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
[admin] = await setupDb();
|
|
32
|
+
|
|
33
|
+
apple = await FoodModel.create({
|
|
34
|
+
calories: 100,
|
|
35
|
+
categories: [
|
|
36
|
+
{name: "Fruit", show: true},
|
|
37
|
+
{name: "Popular", show: false},
|
|
38
|
+
],
|
|
39
|
+
created: new Date("2021-12-03T00:00:30.000Z"),
|
|
40
|
+
hidden: false,
|
|
41
|
+
name: "Apple",
|
|
42
|
+
ownerId: admin._id,
|
|
43
|
+
tags: ["healthy", "cheap"],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
app = getBaseServer();
|
|
47
|
+
setupAuth(app, UserModel as any);
|
|
48
|
+
addAuthRoutes(app, UserModel as any);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns 400 when an array operation transformer throws a non-APIError", async () => {
|
|
52
|
+
app.use(
|
|
53
|
+
"/food",
|
|
54
|
+
modelRouter(FoodModel, {
|
|
55
|
+
allowAnonymous: true,
|
|
56
|
+
permissions: {
|
|
57
|
+
create: [Permissions.IsAny],
|
|
58
|
+
delete: [Permissions.IsAny],
|
|
59
|
+
list: [Permissions.IsAny],
|
|
60
|
+
read: [Permissions.IsAny],
|
|
61
|
+
update: [Permissions.IsAny],
|
|
62
|
+
},
|
|
63
|
+
transformer: {
|
|
64
|
+
transform: () => {
|
|
65
|
+
throw new Error("array transform boom");
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
server = supertest(app);
|
|
71
|
+
|
|
72
|
+
const res = await server.post(`/food/${apple._id}/tags`).send({tags: "organic"}).expect(403);
|
|
73
|
+
expect(res.body.title).toContain("array transform boom");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns 400 when saving an array operation fails validation", async () => {
|
|
77
|
+
app.use(
|
|
78
|
+
"/food",
|
|
79
|
+
modelRouter(FoodModel, {
|
|
80
|
+
allowAnonymous: true,
|
|
81
|
+
permissions: {
|
|
82
|
+
create: [Permissions.IsAny],
|
|
83
|
+
delete: [Permissions.IsAny],
|
|
84
|
+
list: [Permissions.IsAny],
|
|
85
|
+
read: [Permissions.IsAny],
|
|
86
|
+
update: [Permissions.IsAny],
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
server = supertest(app);
|
|
91
|
+
|
|
92
|
+
// eatenBy is an ObjectId array; pushing a non-ObjectId value fails the
|
|
93
|
+
// cast when the document is saved.
|
|
94
|
+
const res = await server
|
|
95
|
+
.post(`/food/${apple._id}/eatenBy`)
|
|
96
|
+
.send({eatenBy: "not-an-object-id"})
|
|
97
|
+
.expect(400);
|
|
98
|
+
expect(res.body.title).toContain("PATCH Pre Update error");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("returns 400 when a hard delete (no isDeleted plugin) fails", async () => {
|
|
102
|
+
const doc = await ExplosiveModel.create({name: "boom"});
|
|
103
|
+
app.use(
|
|
104
|
+
"/explosive",
|
|
105
|
+
modelRouter(ExplosiveModel as any, {
|
|
106
|
+
allowAnonymous: true,
|
|
107
|
+
permissions: {
|
|
108
|
+
create: [Permissions.IsAny],
|
|
109
|
+
delete: [Permissions.IsAny],
|
|
110
|
+
list: [Permissions.IsAny],
|
|
111
|
+
read: [Permissions.IsAny],
|
|
112
|
+
update: [Permissions.IsAny],
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
server = supertest(app);
|
|
117
|
+
|
|
118
|
+
const res = await server.delete(`/explosive/${doc._id}`).expect(400);
|
|
119
|
+
expect(res.body.title).toContain("deleteOne exploded");
|
|
120
|
+
});
|
|
121
|
+
});
|