@terreno/api 0.26.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/dist/__tests__/openApiCompat.test.js +8 -2
- 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/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.test.js +1 -0
- package/dist/githubAuth.js +2 -0
- package/dist/githubAuth.test.js +1 -0
- package/dist/logger.test.js +107 -0
- package/dist/openApi.test.js +1 -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/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/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/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 +1 -0
- package/src/expressServer.ts +4 -2
- package/src/githubAuth.test.ts +1 -0
- package/src/githubAuth.ts +2 -0
- package/src/logger.test.ts +78 -0
- package/src/openApi.test.ts +1 -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/models.ts +1 -0
- package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +4 -1
- package/tsconfig.json +3 -3
- /package/{types.d.ts → src/types.d.ts} +0 -0
package/dist/api.js
CHANGED
|
@@ -142,6 +142,7 @@ var registry_1 = require("./realtime/registry");
|
|
|
142
142
|
var transformers_1 = require("./transformers");
|
|
143
143
|
var utils_1 = require("./utils");
|
|
144
144
|
var addPopulateToQuery = function (
|
|
145
|
+
// noExplicitAny: mongoose Query type parameters vary widely across populated/unpopulated documents — caller passes concrete types
|
|
145
146
|
// biome-ignore lint/suspicious/noExplicitAny: mongoose Query type parameters vary widely across populated/unpopulated documents — caller passes concrete types
|
|
146
147
|
builtQuery, populatePaths) {
|
|
147
148
|
var e_1, _a;
|
|
@@ -1054,194 +1055,186 @@ function _buildModelRouter(model, options) {
|
|
|
1054
1055
|
}
|
|
1055
1056
|
});
|
|
1056
1057
|
}); }));
|
|
1057
|
-
function
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1058
|
+
var arrayOperation = function (req, res, operation) { return __awaiter(_this, void 0, void 0, function () {
|
|
1059
|
+
var doc, prevDoc, field, itemId, array, index, body, error_17, error_18, error_19;
|
|
1060
|
+
var _a;
|
|
1061
|
+
var _b, _c;
|
|
1062
|
+
return __generator(this, function (_d) {
|
|
1063
|
+
switch (_d.label) {
|
|
1064
|
+
case 0: return [4 /*yield*/, (0, permissions_1.checkPermissions)("update", options.permissions.update, req.user)];
|
|
1065
|
+
case 1:
|
|
1066
|
+
// TODO Combine array operations and .patch(), as they are very similar.
|
|
1067
|
+
if (!(_d.sent())) {
|
|
1068
|
+
throw new errors_1.APIError({
|
|
1069
|
+
status: 405,
|
|
1070
|
+
title: "Access to PATCH on ".concat(model.modelName, " denied for ").concat((_b = req.user) === null || _b === void 0 ? void 0 : _b.id),
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
return [4 /*yield*/, model.findById(req.params.id)];
|
|
1074
|
+
case 2:
|
|
1075
|
+
doc = _d.sent();
|
|
1076
|
+
prevDoc = (0, cloneDeep_1.default)(doc);
|
|
1077
|
+
if (!doc) {
|
|
1078
|
+
throw new errors_1.APIError({
|
|
1079
|
+
status: 404,
|
|
1080
|
+
title: "Could not find document to PATCH: ".concat(req.params.id),
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
return [4 /*yield*/, (0, permissions_1.checkPermissions)("update", options.permissions.update, req.user, doc)];
|
|
1084
|
+
case 3:
|
|
1085
|
+
if (!(_d.sent())) {
|
|
1086
|
+
throw new errors_1.APIError({
|
|
1087
|
+
status: 403,
|
|
1088
|
+
title: "Patch not allowed for user ".concat((_c = req.user) === null || _c === void 0 ? void 0 : _c.id, " on doc ").concat(doc._id),
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
field = req.params.field;
|
|
1092
|
+
itemId = req.params.itemId;
|
|
1093
|
+
// We apply the operation *before* the hooks. As far as the callers are concerned, this should
|
|
1094
|
+
// be like PATCHing the field and replacing the whole thing.
|
|
1095
|
+
if (operation !== "DELETE" && req.body[field] === undefined) {
|
|
1096
|
+
throw new errors_1.APIError({
|
|
1097
|
+
status: 400,
|
|
1098
|
+
title: "Malformed body, array operations should have a single, top level key, got: ".concat(Object.keys(req.body).join(",")),
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
array = __spreadArray([], __read(doc[field]), false);
|
|
1102
|
+
if (operation === "POST") {
|
|
1103
|
+
array.push(req.body[field]);
|
|
1104
|
+
}
|
|
1105
|
+
else if (operation === "PATCH" || operation === "DELETE") {
|
|
1106
|
+
index = void 0;
|
|
1107
|
+
if ((0, utils_1.isValidObjectId)(itemId)) {
|
|
1108
|
+
index = array.findIndex(function (x) { return (x === null || x === void 0 ? void 0 : x.id) === itemId; });
|
|
1082
1109
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
if (!(_d.sent())) {
|
|
1086
|
-
throw new errors_1.APIError({
|
|
1087
|
-
status: 403,
|
|
1088
|
-
title: "Patch not allowed for user ".concat((_c = req.user) === null || _c === void 0 ? void 0 : _c.id, " on doc ").concat(doc._id),
|
|
1089
|
-
});
|
|
1110
|
+
else {
|
|
1111
|
+
index = array.indexOf(itemId);
|
|
1090
1112
|
}
|
|
1091
|
-
|
|
1092
|
-
itemId = req.params.itemId;
|
|
1093
|
-
// We apply the operation *before* the hooks. As far as the callers are concerned, this should
|
|
1094
|
-
// be like PATCHing the field and replacing the whole thing.
|
|
1095
|
-
if (operation !== "DELETE" && req.body[field] === undefined) {
|
|
1113
|
+
if (index === -1) {
|
|
1096
1114
|
throw new errors_1.APIError({
|
|
1097
|
-
status:
|
|
1098
|
-
title: "
|
|
1115
|
+
status: 404,
|
|
1116
|
+
title: "Could not find ".concat(field, "/").concat(itemId),
|
|
1099
1117
|
});
|
|
1100
1118
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1119
|
+
// For PATCHing an item by ID, we need to merge the objects so we don't override the _id or
|
|
1120
|
+
// other parts of the subdocument.
|
|
1121
|
+
if (operation === "PATCH" && (0, utils_1.isValidObjectId)(itemId)) {
|
|
1122
|
+
Object.assign(array[index], req.body[field]);
|
|
1104
1123
|
}
|
|
1105
|
-
else if (operation === "PATCH"
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
index = array.findIndex(function (x) { return (x === null || x === void 0 ? void 0 : x.id) === itemId; });
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
index = array.indexOf(itemId);
|
|
1112
|
-
}
|
|
1113
|
-
if (index === -1) {
|
|
1114
|
-
throw new errors_1.APIError({
|
|
1115
|
-
status: 404,
|
|
1116
|
-
title: "Could not find ".concat(field, "/").concat(itemId),
|
|
1117
|
-
});
|
|
1118
|
-
}
|
|
1119
|
-
// For PATCHing an item by ID, we need to merge the objects so we don't override the _id or
|
|
1120
|
-
// other parts of the subdocument.
|
|
1121
|
-
if (operation === "PATCH" && (0, utils_1.isValidObjectId)(itemId)) {
|
|
1122
|
-
Object.assign(array[index], req.body[field]);
|
|
1123
|
-
}
|
|
1124
|
-
else if (operation === "PATCH") {
|
|
1125
|
-
// For PATCHing a string array, we can replace the whole object.
|
|
1126
|
-
array[index] = req.body[field];
|
|
1127
|
-
}
|
|
1128
|
-
else {
|
|
1129
|
-
array.splice(index, 1);
|
|
1130
|
-
}
|
|
1124
|
+
else if (operation === "PATCH") {
|
|
1125
|
+
// For PATCHing a string array, we can replace the whole object.
|
|
1126
|
+
array[index] = req.body[field];
|
|
1131
1127
|
}
|
|
1132
1128
|
else {
|
|
1133
|
-
|
|
1134
|
-
status: 400,
|
|
1135
|
-
title: "Invalid array operation: ".concat(operation),
|
|
1136
|
-
});
|
|
1129
|
+
array.splice(index, 1);
|
|
1137
1130
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
body = (0, transformers_1.transform)(options, body, "update", req.user);
|
|
1141
|
-
}
|
|
1142
|
-
catch (error) {
|
|
1143
|
-
if ((0, errors_1.isAPIError)(error)) {
|
|
1144
|
-
throw error;
|
|
1145
|
-
}
|
|
1146
|
-
throw new errors_1.APIError({
|
|
1147
|
-
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
1148
|
-
error: error,
|
|
1149
|
-
status: 403,
|
|
1150
|
-
title: (0, errors_1.errorMessage)(error),
|
|
1151
|
-
});
|
|
1152
|
-
}
|
|
1153
|
-
if (!options.preUpdate) return [3 /*break*/, 8];
|
|
1154
|
-
_d.label = 4;
|
|
1155
|
-
case 4:
|
|
1156
|
-
_d.trys.push([4, 6, , 7]);
|
|
1157
|
-
return [4 /*yield*/, options.preUpdate(body, req)];
|
|
1158
|
-
case 5:
|
|
1159
|
-
body = _d.sent();
|
|
1160
|
-
return [3 /*break*/, 7];
|
|
1161
|
-
case 6:
|
|
1162
|
-
error_17 = _d.sent();
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1163
1133
|
throw new errors_1.APIError({
|
|
1164
|
-
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_17),
|
|
1165
|
-
error: error_17,
|
|
1166
1134
|
status: 400,
|
|
1167
|
-
title: "
|
|
1135
|
+
title: "Invalid array operation: ".concat(operation),
|
|
1168
1136
|
});
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
if (body === null) {
|
|
1178
|
-
throw new errors_1.APIError({
|
|
1179
|
-
detail: "preUpdate hook on ".concat(req.params.id, " returned null"),
|
|
1180
|
-
status: 403,
|
|
1181
|
-
title: "Update not allowed",
|
|
1182
|
-
});
|
|
1137
|
+
}
|
|
1138
|
+
body = (_a = {}, _a[field] = array, _a);
|
|
1139
|
+
try {
|
|
1140
|
+
body = (0, transformers_1.transform)(options, body, "update", req.user);
|
|
1141
|
+
}
|
|
1142
|
+
catch (error) {
|
|
1143
|
+
if ((0, errors_1.isAPIError)(error)) {
|
|
1144
|
+
throw error;
|
|
1183
1145
|
}
|
|
1184
|
-
_d.label = 8;
|
|
1185
|
-
case 8:
|
|
1186
|
-
_d.trys.push([8, 10, , 11]);
|
|
1187
|
-
Object.assign(doc, body);
|
|
1188
|
-
return [4 /*yield*/, doc.save()];
|
|
1189
|
-
case 9:
|
|
1190
|
-
_d.sent();
|
|
1191
|
-
return [3 /*break*/, 11];
|
|
1192
|
-
case 10:
|
|
1193
|
-
error_18 = _d.sent();
|
|
1194
1146
|
throw new errors_1.APIError({
|
|
1195
|
-
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(
|
|
1196
|
-
error:
|
|
1197
|
-
status:
|
|
1198
|
-
title:
|
|
1147
|
+
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
1148
|
+
error: error,
|
|
1149
|
+
status: 403,
|
|
1150
|
+
title: (0, errors_1.errorMessage)(error),
|
|
1199
1151
|
});
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1152
|
+
}
|
|
1153
|
+
if (!options.preUpdate) return [3 /*break*/, 8];
|
|
1154
|
+
_d.label = 4;
|
|
1155
|
+
case 4:
|
|
1156
|
+
_d.trys.push([4, 6, , 7]);
|
|
1157
|
+
return [4 /*yield*/, options.preUpdate(body, req)];
|
|
1158
|
+
case 5:
|
|
1159
|
+
body = _d.sent();
|
|
1160
|
+
return [3 /*break*/, 7];
|
|
1161
|
+
case 6:
|
|
1162
|
+
error_17 = _d.sent();
|
|
1163
|
+
throw new errors_1.APIError({
|
|
1164
|
+
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_17),
|
|
1165
|
+
error: error_17,
|
|
1166
|
+
status: 400,
|
|
1167
|
+
title: "preUpdate hook error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_17)),
|
|
1168
|
+
});
|
|
1169
|
+
case 7:
|
|
1170
|
+
if (body === undefined) {
|
|
1211
1171
|
throw new errors_1.APIError({
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
title: "PATCH Post Update error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_19)),
|
|
1172
|
+
detail: "A body must be returned from preUpdate",
|
|
1173
|
+
status: 403,
|
|
1174
|
+
title: "Update not allowed",
|
|
1216
1175
|
});
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1176
|
+
}
|
|
1177
|
+
if (body === null) {
|
|
1178
|
+
throw new errors_1.APIError({
|
|
1179
|
+
detail: "preUpdate hook on ".concat(req.params.id, " returned null"),
|
|
1180
|
+
status: 403,
|
|
1181
|
+
title: "Update not allowed",
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
_d.label = 8;
|
|
1185
|
+
case 8:
|
|
1186
|
+
_d.trys.push([8, 10, , 11]);
|
|
1187
|
+
Object.assign(doc, body);
|
|
1188
|
+
return [4 /*yield*/, doc.save()];
|
|
1189
|
+
case 9:
|
|
1190
|
+
_d.sent();
|
|
1191
|
+
return [3 /*break*/, 11];
|
|
1192
|
+
case 10:
|
|
1193
|
+
error_18 = _d.sent();
|
|
1194
|
+
throw new errors_1.APIError({
|
|
1195
|
+
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_18),
|
|
1196
|
+
error: error_18,
|
|
1197
|
+
status: 400,
|
|
1198
|
+
title: "PATCH Pre Update error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_18)),
|
|
1199
|
+
});
|
|
1200
|
+
case 11:
|
|
1201
|
+
if (!options.postUpdate) return [3 /*break*/, 15];
|
|
1202
|
+
_d.label = 12;
|
|
1203
|
+
case 12:
|
|
1204
|
+
_d.trys.push([12, 14, , 15]);
|
|
1205
|
+
return [4 /*yield*/, options.postUpdate(doc, body, req, prevDoc)];
|
|
1206
|
+
case 13:
|
|
1207
|
+
_d.sent();
|
|
1208
|
+
return [3 /*break*/, 15];
|
|
1209
|
+
case 14:
|
|
1210
|
+
error_19 = _d.sent();
|
|
1211
|
+
throw new errors_1.APIError({
|
|
1212
|
+
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_19),
|
|
1213
|
+
error: error_19,
|
|
1214
|
+
status: 400,
|
|
1215
|
+
title: "PATCH Post Update error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_19)),
|
|
1216
|
+
});
|
|
1217
|
+
case 15: return [2 /*return*/, res.json({
|
|
1218
|
+
data: (0, transformers_1.serialize)(req, options, doc),
|
|
1219
|
+
})];
|
|
1220
|
+
}
|
|
1222
1221
|
});
|
|
1223
|
-
}
|
|
1224
|
-
function
|
|
1225
|
-
return
|
|
1226
|
-
return
|
|
1227
|
-
return [2 /*return*/, arrayOperation(req, res, "POST")];
|
|
1228
|
-
});
|
|
1222
|
+
}); };
|
|
1223
|
+
var arrayPost = function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
1224
|
+
return __generator(this, function (_a) {
|
|
1225
|
+
return [2 /*return*/, arrayOperation(req, res, "POST")];
|
|
1229
1226
|
});
|
|
1230
|
-
}
|
|
1231
|
-
function
|
|
1232
|
-
return
|
|
1233
|
-
return
|
|
1234
|
-
return [2 /*return*/, arrayOperation(req, res, "PATCH")];
|
|
1235
|
-
});
|
|
1227
|
+
}); };
|
|
1228
|
+
var arrayPatch = function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
1229
|
+
return __generator(this, function (_a) {
|
|
1230
|
+
return [2 /*return*/, arrayOperation(req, res, "PATCH")];
|
|
1236
1231
|
});
|
|
1237
|
-
}
|
|
1238
|
-
function
|
|
1239
|
-
return
|
|
1240
|
-
return
|
|
1241
|
-
return [2 /*return*/, arrayOperation(req, res, "DELETE")];
|
|
1242
|
-
});
|
|
1232
|
+
}); };
|
|
1233
|
+
var arrayDelete = function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
1234
|
+
return __generator(this, function (_a) {
|
|
1235
|
+
return [2 /*return*/, arrayOperation(req, res, "DELETE")];
|
|
1243
1236
|
});
|
|
1244
|
-
}
|
|
1237
|
+
}); };
|
|
1245
1238
|
// Set up routes for managing array fields. Check if there any array fields to add this for.
|
|
1246
1239
|
if (Object.values(model.schema.paths).find(function (config) { return config.instance === "Array"; })) {
|
|
1247
1240
|
router.post("/:id/:field", (0, auth_1.authenticateMiddleware)(options.allowAnonymous), (0, exports.asyncHandler)(arrayPost));
|
package/dist/api.query.test.js
CHANGED
|
@@ -88,6 +88,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
88
88
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
89
|
};
|
|
90
90
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
+
// noExplicitAny: test mock typing
|
|
91
92
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
92
93
|
var bun_test_1 = require("bun:test");
|
|
93
94
|
var Sentry = __importStar(require("@sentry/bun"));
|
package/dist/api.test.js
CHANGED
|
@@ -88,6 +88,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
88
88
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
89
|
};
|
|
90
90
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
+
// noExplicitAny: test mock typing
|
|
91
92
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
92
93
|
// biome-ignore-all lint/suspicious/noImplicitAnyLet: test mock typing
|
|
93
94
|
var bun_test_1 = require("bun:test");
|
package/dist/auth.js
CHANGED
|
@@ -419,6 +419,7 @@ var setupAuth = function (app, userModel) {
|
|
|
419
419
|
});
|
|
420
420
|
}); };
|
|
421
421
|
app.use(decodeJWTMiddleware);
|
|
422
|
+
// noExplicitAny: express 5 type for urlencoded doesn't match RequestHandler
|
|
422
423
|
// biome-ignore lint/suspicious/noExplicitAny: express 5 type for urlencoded doesn't match RequestHandler
|
|
423
424
|
app.use(express_1.default.urlencoded({ extended: false }));
|
|
424
425
|
};
|
package/dist/auth.test.js
CHANGED
|
@@ -99,6 +99,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
99
99
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
100
100
|
};
|
|
101
101
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
102
|
+
// noExplicitAny: test mock typing
|
|
102
103
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
103
104
|
var bun_test_1 = require("bun:test");
|
|
104
105
|
var supertest_1 = __importDefault(require("supertest"));
|
|
@@ -2003,3 +2004,124 @@ var decodeTokenPayload = function (token) {
|
|
|
2003
2004
|
});
|
|
2004
2005
|
}); });
|
|
2005
2006
|
});
|
|
2007
|
+
(0, bun_test_1.describe)("signupUser postCreate failures", function () {
|
|
2008
|
+
(0, bun_test_1.it)("wraps and rethrows errors thrown by user.postCreate", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2009
|
+
var saveCalled, failingUser, fakeModel;
|
|
2010
|
+
return __generator(this, function (_a) {
|
|
2011
|
+
switch (_a.label) {
|
|
2012
|
+
case 0:
|
|
2013
|
+
saveCalled = false;
|
|
2014
|
+
failingUser = {
|
|
2015
|
+
postCreate: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2016
|
+
return __generator(this, function (_a) {
|
|
2017
|
+
throw new Error("postCreate failed");
|
|
2018
|
+
});
|
|
2019
|
+
}); },
|
|
2020
|
+
save: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2021
|
+
return __generator(this, function (_a) {
|
|
2022
|
+
saveCalled = true;
|
|
2023
|
+
return [2 /*return*/];
|
|
2024
|
+
});
|
|
2025
|
+
}); },
|
|
2026
|
+
};
|
|
2027
|
+
fakeModel = {
|
|
2028
|
+
register: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2029
|
+
return [2 /*return*/, failingUser];
|
|
2030
|
+
}); }); },
|
|
2031
|
+
};
|
|
2032
|
+
return [4 /*yield*/, (0, bun_test_1.expect)((0, auth_1.signupUser)(fakeModel, "new@example.com", "password123")).rejects.toThrow("postCreate failed")];
|
|
2033
|
+
case 1:
|
|
2034
|
+
_a.sent();
|
|
2035
|
+
(0, bun_test_1.expect)(saveCalled).toBe(false);
|
|
2036
|
+
return [2 /*return*/];
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
}); });
|
|
2040
|
+
});
|
|
2041
|
+
(0, bun_test_1.describe)("auth error paths when the user lookup fails", function () {
|
|
2042
|
+
var app;
|
|
2043
|
+
var agent;
|
|
2044
|
+
var admin;
|
|
2045
|
+
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2046
|
+
var testData;
|
|
2047
|
+
return __generator(this, function (_a) {
|
|
2048
|
+
switch (_a.label) {
|
|
2049
|
+
case 0:
|
|
2050
|
+
(0, bun_test_1.setSystemTime)();
|
|
2051
|
+
return [4 /*yield*/, (0, tests_1.setupTestData)()];
|
|
2052
|
+
case 1:
|
|
2053
|
+
testData = _a.sent();
|
|
2054
|
+
admin = testData.users.admin;
|
|
2055
|
+
app = new terrenoApp_1.TerrenoApp({
|
|
2056
|
+
configureApp: function () { },
|
|
2057
|
+
skipListen: true,
|
|
2058
|
+
userModel: tests_1.UserModel,
|
|
2059
|
+
}).build();
|
|
2060
|
+
agent = supertest_1.default.agent(app);
|
|
2061
|
+
return [2 /*return*/];
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
}); });
|
|
2065
|
+
(0, bun_test_1.afterEach)(function () {
|
|
2066
|
+
(0, bun_test_1.setSystemTime)();
|
|
2067
|
+
});
|
|
2068
|
+
(0, bun_test_1.it)("responds with an error when userModel.findById throws during authentication", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2069
|
+
var jwtLib, token, findSpy, res;
|
|
2070
|
+
return __generator(this, function (_a) {
|
|
2071
|
+
switch (_a.label) {
|
|
2072
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("jsonwebtoken")); })];
|
|
2073
|
+
case 1:
|
|
2074
|
+
jwtLib = (_a.sent()).default;
|
|
2075
|
+
token = jwtLib.sign({ id: admin._id.toString() }, process.env.TOKEN_SECRET, {
|
|
2076
|
+
issuer: process.env.TOKEN_ISSUER,
|
|
2077
|
+
});
|
|
2078
|
+
findSpy = (0, bun_test_1.spyOn)(tests_1.UserModel, "findById").mockImplementation(function () {
|
|
2079
|
+
throw new Error("database unavailable");
|
|
2080
|
+
});
|
|
2081
|
+
_a.label = 2;
|
|
2082
|
+
case 2:
|
|
2083
|
+
_a.trys.push([2, , 4, 5]);
|
|
2084
|
+
return [4 /*yield*/, agent.get("/auth/me").set("authorization", "Bearer ".concat(token))];
|
|
2085
|
+
case 3:
|
|
2086
|
+
res = _a.sent();
|
|
2087
|
+
(0, bun_test_1.expect)(res.status).toBeGreaterThanOrEqual(400);
|
|
2088
|
+
return [3 /*break*/, 5];
|
|
2089
|
+
case 4:
|
|
2090
|
+
findSpy.mockRestore();
|
|
2091
|
+
return [7 /*endfinally*/];
|
|
2092
|
+
case 5: return [2 /*return*/];
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
2095
|
+
}); });
|
|
2096
|
+
(0, bun_test_1.it)("calls next(err) when the local login strategy errors", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2097
|
+
var authSpy, errApp, errAgent, res;
|
|
2098
|
+
return __generator(this, function (_a) {
|
|
2099
|
+
switch (_a.label) {
|
|
2100
|
+
case 0:
|
|
2101
|
+
authSpy = (0, bun_test_1.spyOn)(tests_1.UserModel, "authenticate").mockReturnValue(function (_username, _password, done) {
|
|
2102
|
+
done(new Error("strategy failure"));
|
|
2103
|
+
});
|
|
2104
|
+
_a.label = 1;
|
|
2105
|
+
case 1:
|
|
2106
|
+
_a.trys.push([1, , 3, 4]);
|
|
2107
|
+
errApp = new terrenoApp_1.TerrenoApp({
|
|
2108
|
+
configureApp: function () { },
|
|
2109
|
+
skipListen: true,
|
|
2110
|
+
userModel: tests_1.UserModel,
|
|
2111
|
+
}).build();
|
|
2112
|
+
errAgent = supertest_1.default.agent(errApp);
|
|
2113
|
+
return [4 /*yield*/, errAgent
|
|
2114
|
+
.post("/auth/login")
|
|
2115
|
+
.send({ email: "notAdmin@example.com", password: "password" })];
|
|
2116
|
+
case 2:
|
|
2117
|
+
res = _a.sent();
|
|
2118
|
+
(0, bun_test_1.expect)(res.status).toBeGreaterThanOrEqual(400);
|
|
2119
|
+
return [3 /*break*/, 4];
|
|
2120
|
+
case 3:
|
|
2121
|
+
authSpy.mockRestore();
|
|
2122
|
+
return [7 /*endfinally*/];
|
|
2123
|
+
case 4: return [2 /*return*/];
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
}); });
|
|
2127
|
+
});
|
package/dist/betterAuthSetup.js
CHANGED
|
@@ -191,6 +191,7 @@ var createBetterAuthSessionMiddleware = function (auth, userModel) {
|
|
|
191
191
|
};
|
|
192
192
|
exports.createBetterAuthSessionMiddleware = createBetterAuthSessionMiddleware;
|
|
193
193
|
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider
|
|
194
|
+
// noExplicitAny: return is a consumer-defined user document; tests inspect varied fields
|
|
194
195
|
// biome-ignore lint/suspicious/noExplicitAny: return is a consumer-defined user document; tests inspect varied fields
|
|
195
196
|
) { return __awaiter(void 0, void 0, void 0, function () {
|
|
196
197
|
var existingUser, userByEmail, useAsId, newUser, error_2;
|
|
@@ -83,6 +83,7 @@ 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
|
+
// noExplicitAny: test mock typing
|
|
86
87
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
87
88
|
var bun_test_1 = require("bun:test");
|
|
88
89
|
var express_1 = __importDefault(require("express"));
|
|
@@ -83,6 +83,7 @@ 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
|
+
// noExplicitAny: test mock typing
|
|
86
87
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
87
88
|
var bun_test_1 = require("bun:test");
|
|
88
89
|
var mongoose_1 = __importStar(require("mongoose"));
|
package/dist/configurationApp.js
CHANGED
|
@@ -441,6 +441,7 @@ var ConfigurationApp = /** @class */ (function () {
|
|
|
441
441
|
* Top-level fields with subschemas become sections.
|
|
442
442
|
* Top-level scalar fields go into a "General" section.
|
|
443
443
|
*/
|
|
444
|
+
// noExplicitAny: Model<any> required for invariance with consumer-supplied configuration models
|
|
444
445
|
// biome-ignore lint/suspicious/noExplicitAny: Model<any> required for invariance with consumer-supplied configuration models
|
|
445
446
|
ConfigurationApp.prototype.buildMetadata = function (_model, schema) {
|
|
446
447
|
var _this = this;
|