@terreno/api 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/dist/actions.js +17 -8
- package/dist/actions.test.js +8 -3
- package/dist/api.arrayOperations.test.js +16 -8
- package/dist/api.coverage.test.js +2 -1
- package/dist/api.errorPaths.test.js +522 -1
- package/dist/api.errors.test.js +9 -0
- package/dist/api.js +137 -170
- package/dist/api.query.test.js +20 -8
- package/dist/api.test.js +12 -6
- package/dist/auth.coverage.test.d.ts +1 -0
- package/dist/auth.coverage.test.js +202 -0
- package/dist/auth.test.js +159 -0
- package/dist/docLoader.js +5 -1
- package/dist/envConfigurationPlugin.d.ts +1 -1
- package/dist/envConfigurationPlugin.js +0 -2
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +24 -2
- package/dist/errors.test.js +137 -0
- package/dist/httpClient.js +5 -1
- package/dist/plugins.d.ts +4 -4
- package/dist/plugins.js +51 -9
- package/dist/plugins.test.js +61 -17
- package/dist/realtime/registry.d.ts +3 -2
- package/package.json +2 -2
- package/src/actions.test.ts +8 -3
- package/src/actions.ts +19 -10
- package/src/api.arrayOperations.test.ts +16 -8
- package/src/api.coverage.test.ts +2 -1
- package/src/api.errorPaths.test.ts +313 -3
- package/src/api.errors.test.ts +12 -0
- package/src/api.query.test.ts +20 -8
- package/src/api.test.ts +12 -6
- package/src/api.ts +141 -161
- package/src/auth.coverage.test.ts +101 -0
- package/src/auth.test.ts +125 -2
- package/src/docLoader.ts +6 -2
- package/src/envConfigurationPlugin.ts +2 -6
- package/src/errors.test.ts +106 -1
- package/src/errors.ts +25 -1
- package/src/httpClient.ts +6 -2
- package/src/plugins.test.ts +45 -9
- package/src/plugins.ts +72 -35
- package/src/realtime/changeStreamWatcher.ts +8 -1
- package/src/realtime/registry.ts +3 -4
|
@@ -79,6 +79,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
79
79
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
+
var __values = (this && this.__values) || function(o) {
|
|
83
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
84
|
+
if (m) return m.call(o);
|
|
85
|
+
if (o && typeof o.length === "number") return {
|
|
86
|
+
next: function () {
|
|
87
|
+
if (o && i >= o.length) o = void 0;
|
|
88
|
+
return { value: o && o[i++], done: !o };
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
92
|
+
};
|
|
82
93
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
83
94
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
84
95
|
};
|
|
@@ -90,6 +101,7 @@ var mongoose_1 = __importDefault(require("mongoose"));
|
|
|
90
101
|
var supertest_1 = __importDefault(require("supertest"));
|
|
91
102
|
var api_1 = require("./api");
|
|
92
103
|
var auth_1 = require("./auth");
|
|
104
|
+
var errors_1 = require("./errors");
|
|
93
105
|
var permissions_1 = require("./permissions");
|
|
94
106
|
var tests_1 = require("./tests");
|
|
95
107
|
var authUserModel = tests_1.UserModel;
|
|
@@ -253,7 +265,7 @@ var anyPermissions = {
|
|
|
253
265
|
}
|
|
254
266
|
});
|
|
255
267
|
}); });
|
|
256
|
-
(0, bun_test_1.it)("
|
|
268
|
+
(0, bun_test_1.it)("converts Mongoose save failures during array operations into field errors", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
257
269
|
var food, res;
|
|
258
270
|
return __generator(this, function (_a) {
|
|
259
271
|
switch (_a.label) {
|
|
@@ -271,10 +283,519 @@ var anyPermissions = {
|
|
|
271
283
|
.send({ eatenBy: "not-an-object-id" })
|
|
272
284
|
.expect(400)];
|
|
273
285
|
case 2:
|
|
286
|
+
res = _a.sent();
|
|
287
|
+
chai_1.assert.equal(res.body.title, "Validation failed");
|
|
288
|
+
chai_1.assert.include(res.body.meta.fields["eatenBy.0"], "ObjectId");
|
|
289
|
+
return [2 /*return*/];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}); });
|
|
293
|
+
(0, bun_test_1.it)("wraps non-Mongoose save failures during array operations", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
294
|
+
var food, saveSpy, res;
|
|
295
|
+
return __generator(this, function (_a) {
|
|
296
|
+
switch (_a.label) {
|
|
297
|
+
case 0:
|
|
298
|
+
mountFood();
|
|
299
|
+
return [4 /*yield*/, tests_1.FoodModel.create({
|
|
300
|
+
calories: 1,
|
|
301
|
+
name: "Unsavable",
|
|
302
|
+
ownerId: new mongoose_1.default.Types.ObjectId(),
|
|
303
|
+
})];
|
|
304
|
+
case 1:
|
|
305
|
+
food = _a.sent();
|
|
306
|
+
saveSpy = (0, bun_test_1.spyOn)(tests_1.FoodModel.prototype, "save").mockImplementation(function () {
|
|
307
|
+
throw new Error("save exploded");
|
|
308
|
+
});
|
|
309
|
+
_a.label = 2;
|
|
310
|
+
case 2:
|
|
311
|
+
_a.trys.push([2, , 4, 5]);
|
|
312
|
+
return [4 /*yield*/, server.post("/food/".concat(food._id, "/tags")).send({ tags: "vegetable" }).expect(400)];
|
|
313
|
+
case 3:
|
|
274
314
|
res = _a.sent();
|
|
275
315
|
chai_1.assert.include(res.body.title, "PATCH Pre Update error");
|
|
316
|
+
chai_1.assert.include(res.body.detail, "save exploded");
|
|
317
|
+
return [3 /*break*/, 5];
|
|
318
|
+
case 4:
|
|
319
|
+
saveSpy.mockRestore();
|
|
320
|
+
return [7 /*endfinally*/];
|
|
321
|
+
case 5: return [2 /*return*/];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}); });
|
|
325
|
+
});
|
|
326
|
+
// A domain error of the shape consumers throw: stable title, kebab-case code, per-occurrence
|
|
327
|
+
// detail, and structured meta the client renders.
|
|
328
|
+
var staffConflictError = function (code) {
|
|
329
|
+
return new errors_1.ConflictError({
|
|
330
|
+
code: code,
|
|
331
|
+
detail: "Conflict detected for Dr. Ada on 2026-07-31",
|
|
332
|
+
meta: { date: "2026-07-31", staff: "Dr. Ada" },
|
|
333
|
+
title: "Conflict detected",
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
var assertStaffConflict = function (body, code) {
|
|
337
|
+
chai_1.assert.equal(body.status, 409);
|
|
338
|
+
chai_1.assert.equal(body.title, "Conflict detected");
|
|
339
|
+
chai_1.assert.equal(body.detail, "Conflict detected for Dr. Ada on 2026-07-31");
|
|
340
|
+
chai_1.assert.equal(body.code, code);
|
|
341
|
+
chai_1.assert.deepEqual(body.meta, { date: "2026-07-31", staff: "Dr. Ada" });
|
|
342
|
+
};
|
|
343
|
+
var guardedSchema = new mongoose_1.default.Schema({
|
|
344
|
+
name: { description: "The name", type: String },
|
|
345
|
+
tags: { description: "Tags for the document", type: [String] },
|
|
346
|
+
}, { strict: "throw" });
|
|
347
|
+
// Stands in for a consumer model that validates in document middleware.
|
|
348
|
+
guardedSchema.pre("save", function () {
|
|
349
|
+
var _a, _b;
|
|
350
|
+
if (this.name === "Conflict" || ((_a = this.tags) === null || _a === void 0 ? void 0 : _a.includes("conflict"))) {
|
|
351
|
+
throw staffConflictError("schedule-item-staff-conflict");
|
|
352
|
+
}
|
|
353
|
+
if (this.name === "Boom" || ((_b = this.tags) === null || _b === void 0 ? void 0 : _b.includes("boom"))) {
|
|
354
|
+
throw new Error("save exploded");
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
var GuardedModel = mongoose_1.default.model("PassthroughGuarded", guardedSchema);
|
|
358
|
+
(0, bun_test_1.describe)("modelRouter APIError passthrough", function () {
|
|
359
|
+
var app;
|
|
360
|
+
var server;
|
|
361
|
+
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
362
|
+
return __generator(this, function (_a) {
|
|
363
|
+
switch (_a.label) {
|
|
364
|
+
case 0: return [4 /*yield*/, (0, tests_1.setupDb)()];
|
|
365
|
+
case 1:
|
|
366
|
+
_a.sent();
|
|
367
|
+
return [4 /*yield*/, GuardedModel.deleteMany({})];
|
|
368
|
+
case 2:
|
|
369
|
+
_a.sent();
|
|
370
|
+
app = (0, tests_1.getBaseServer)();
|
|
371
|
+
(0, auth_1.setupAuth)(app, authUserModel);
|
|
372
|
+
(0, auth_1.addAuthRoutes)(app, authUserModel);
|
|
276
373
|
return [2 /*return*/];
|
|
277
374
|
}
|
|
278
375
|
});
|
|
279
376
|
}); });
|
|
377
|
+
var mountGuarded = function (options) {
|
|
378
|
+
if (options === void 0) { options = {}; }
|
|
379
|
+
app.use("/guarded", (0, api_1.modelRouter)(GuardedModel, __assign({ allowAnonymous: true, permissions: anyPermissions }, options)));
|
|
380
|
+
server = (0, supertest_1.default)(app);
|
|
381
|
+
};
|
|
382
|
+
(0, bun_test_1.describe)("Mongoose document middleware", function () {
|
|
383
|
+
(0, bun_test_1.it)("keeps an APIError from pre(save) intact through POST /", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
384
|
+
var res;
|
|
385
|
+
return __generator(this, function (_a) {
|
|
386
|
+
switch (_a.label) {
|
|
387
|
+
case 0:
|
|
388
|
+
mountGuarded();
|
|
389
|
+
return [4 /*yield*/, server.post("/guarded").send({ name: "Conflict" }).expect(409)];
|
|
390
|
+
case 1:
|
|
391
|
+
res = _a.sent();
|
|
392
|
+
assertStaffConflict(res.body, "schedule-item-staff-conflict");
|
|
393
|
+
return [2 /*return*/];
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}); });
|
|
397
|
+
(0, bun_test_1.it)("wraps a non-APIError from pre(save) on POST /", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
398
|
+
var res;
|
|
399
|
+
return __generator(this, function (_a) {
|
|
400
|
+
switch (_a.label) {
|
|
401
|
+
case 0:
|
|
402
|
+
mountGuarded();
|
|
403
|
+
return [4 /*yield*/, server.post("/guarded").send({ name: "Boom" }).expect(400)];
|
|
404
|
+
case 1:
|
|
405
|
+
res = _a.sent();
|
|
406
|
+
chai_1.assert.equal(res.body.title, "Create error");
|
|
407
|
+
chai_1.assert.equal(res.body.code, "create-error");
|
|
408
|
+
chai_1.assert.include(res.body.detail, "save exploded");
|
|
409
|
+
return [2 /*return*/];
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}); });
|
|
413
|
+
(0, bun_test_1.it)("keeps an APIError from pre(save) intact through PATCH /:id", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
414
|
+
var doc, res;
|
|
415
|
+
return __generator(this, function (_a) {
|
|
416
|
+
switch (_a.label) {
|
|
417
|
+
case 0:
|
|
418
|
+
mountGuarded();
|
|
419
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
420
|
+
case 1:
|
|
421
|
+
doc = _a.sent();
|
|
422
|
+
return [4 /*yield*/, server.patch("/guarded/".concat(doc._id)).send({ name: "Conflict" }).expect(409)];
|
|
423
|
+
case 2:
|
|
424
|
+
res = _a.sent();
|
|
425
|
+
assertStaffConflict(res.body, "schedule-item-staff-conflict");
|
|
426
|
+
return [2 /*return*/];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}); });
|
|
430
|
+
(0, bun_test_1.it)("wraps a non-APIError from pre(save) on PATCH /:id", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
431
|
+
var doc, res;
|
|
432
|
+
return __generator(this, function (_a) {
|
|
433
|
+
switch (_a.label) {
|
|
434
|
+
case 0:
|
|
435
|
+
mountGuarded();
|
|
436
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
437
|
+
case 1:
|
|
438
|
+
doc = _a.sent();
|
|
439
|
+
return [4 /*yield*/, server.patch("/guarded/".concat(doc._id)).send({ name: "Boom" }).expect(400)];
|
|
440
|
+
case 2:
|
|
441
|
+
res = _a.sent();
|
|
442
|
+
chai_1.assert.equal(res.body.title, "preUpdate hook save error");
|
|
443
|
+
chai_1.assert.include(res.body.detail, "save exploded");
|
|
444
|
+
return [2 /*return*/];
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}); });
|
|
448
|
+
(0, bun_test_1.it)("keeps an APIError from pre(save) intact through an array operation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
449
|
+
var doc, res;
|
|
450
|
+
return __generator(this, function (_a) {
|
|
451
|
+
switch (_a.label) {
|
|
452
|
+
case 0:
|
|
453
|
+
mountGuarded();
|
|
454
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
455
|
+
case 1:
|
|
456
|
+
doc = _a.sent();
|
|
457
|
+
return [4 /*yield*/, server
|
|
458
|
+
.post("/guarded/".concat(doc._id, "/tags"))
|
|
459
|
+
.send({ tags: "conflict" })
|
|
460
|
+
.expect(409)];
|
|
461
|
+
case 2:
|
|
462
|
+
res = _a.sent();
|
|
463
|
+
assertStaffConflict(res.body, "schedule-item-staff-conflict");
|
|
464
|
+
return [2 /*return*/];
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}); });
|
|
468
|
+
(0, bun_test_1.it)("surfaces Mongoose validation errors from create as per-field errors", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
469
|
+
var res;
|
|
470
|
+
return __generator(this, function (_a) {
|
|
471
|
+
switch (_a.label) {
|
|
472
|
+
case 0:
|
|
473
|
+
app.use("/required", (0, api_1.modelRouter)(tests_1.RequiredModel, { allowAnonymous: true, permissions: anyPermissions }));
|
|
474
|
+
server = (0, supertest_1.default)(app);
|
|
475
|
+
return [4 /*yield*/, server.post("/required").send({ about: "no name here" }).expect(400)];
|
|
476
|
+
case 1:
|
|
477
|
+
res = _a.sent();
|
|
478
|
+
chai_1.assert.equal(res.body.title, "Validation failed");
|
|
479
|
+
chai_1.assert.include(res.body.meta.fields.name, "required");
|
|
480
|
+
chai_1.assert.isTrue(res.body.disableExternalErrorTracking);
|
|
481
|
+
return [2 /*return*/];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}); });
|
|
485
|
+
});
|
|
486
|
+
(0, bun_test_1.describe)("hooks", function () {
|
|
487
|
+
(0, bun_test_1.it)("keeps an APIError from queryFilter intact", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
488
|
+
var res;
|
|
489
|
+
return __generator(this, function (_a) {
|
|
490
|
+
switch (_a.label) {
|
|
491
|
+
case 0:
|
|
492
|
+
mountGuarded({
|
|
493
|
+
queryFilter: function () {
|
|
494
|
+
throw staffConflictError("query-filter-conflict");
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
return [4 /*yield*/, server.get("/guarded").expect(409)];
|
|
498
|
+
case 1:
|
|
499
|
+
res = _a.sent();
|
|
500
|
+
assertStaffConflict(res.body, "query-filter-conflict");
|
|
501
|
+
return [2 /*return*/];
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}); });
|
|
505
|
+
(0, bun_test_1.it)("wraps a non-APIError from queryFilter with the caught error's message", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
506
|
+
var res;
|
|
507
|
+
return __generator(this, function (_a) {
|
|
508
|
+
switch (_a.label) {
|
|
509
|
+
case 0:
|
|
510
|
+
mountGuarded({
|
|
511
|
+
queryFilter: function () {
|
|
512
|
+
throw new Error("filter exploded");
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
return [4 /*yield*/, server.get("/guarded").expect(400)];
|
|
516
|
+
case 1:
|
|
517
|
+
res = _a.sent();
|
|
518
|
+
chai_1.assert.equal(res.body.title, "Query filter error");
|
|
519
|
+
// Previously String(error), which prefixed the class name.
|
|
520
|
+
chai_1.assert.equal(res.body.detail, "filter exploded");
|
|
521
|
+
return [2 /*return*/];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}); });
|
|
525
|
+
(0, bun_test_1.it)("wraps a thrown non-Error from queryFilter", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
526
|
+
var res;
|
|
527
|
+
return __generator(this, function (_a) {
|
|
528
|
+
switch (_a.label) {
|
|
529
|
+
case 0:
|
|
530
|
+
mountGuarded({
|
|
531
|
+
queryFilter: function () {
|
|
532
|
+
throw "filter string";
|
|
533
|
+
},
|
|
534
|
+
});
|
|
535
|
+
return [4 /*yield*/, server.get("/guarded").expect(400)];
|
|
536
|
+
case 1:
|
|
537
|
+
res = _a.sent();
|
|
538
|
+
chai_1.assert.equal(res.body.title, "Query filter error");
|
|
539
|
+
chai_1.assert.equal(res.body.detail, "filter string");
|
|
540
|
+
return [2 /*return*/];
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}); });
|
|
544
|
+
(0, bun_test_1.it)("keeps an APIError from responseHandler intact for every method", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
545
|
+
var doc, _a, _b, request, res, e_1_1;
|
|
546
|
+
var e_1, _c;
|
|
547
|
+
return __generator(this, function (_d) {
|
|
548
|
+
switch (_d.label) {
|
|
549
|
+
case 0:
|
|
550
|
+
mountGuarded({
|
|
551
|
+
responseHandler: function () {
|
|
552
|
+
throw staffConflictError("response-handler-conflict");
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
556
|
+
case 1:
|
|
557
|
+
doc = _d.sent();
|
|
558
|
+
_d.label = 2;
|
|
559
|
+
case 2:
|
|
560
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
561
|
+
_a = __values([
|
|
562
|
+
server.post("/guarded").send({ name: "Another" }),
|
|
563
|
+
server.get("/guarded"),
|
|
564
|
+
server.get("/guarded/".concat(doc._id)),
|
|
565
|
+
server.patch("/guarded/".concat(doc._id)).send({ name: "Renamed" }),
|
|
566
|
+
]), _b = _a.next();
|
|
567
|
+
_d.label = 3;
|
|
568
|
+
case 3:
|
|
569
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
570
|
+
request = _b.value;
|
|
571
|
+
return [4 /*yield*/, request.expect(409)];
|
|
572
|
+
case 4:
|
|
573
|
+
res = _d.sent();
|
|
574
|
+
assertStaffConflict(res.body, "response-handler-conflict");
|
|
575
|
+
_d.label = 5;
|
|
576
|
+
case 5:
|
|
577
|
+
_b = _a.next();
|
|
578
|
+
return [3 /*break*/, 3];
|
|
579
|
+
case 6: return [3 /*break*/, 9];
|
|
580
|
+
case 7:
|
|
581
|
+
e_1_1 = _d.sent();
|
|
582
|
+
e_1 = { error: e_1_1 };
|
|
583
|
+
return [3 /*break*/, 9];
|
|
584
|
+
case 8:
|
|
585
|
+
try {
|
|
586
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
587
|
+
}
|
|
588
|
+
finally { if (e_1) throw e_1.error; }
|
|
589
|
+
return [7 /*endfinally*/];
|
|
590
|
+
case 9: return [2 /*return*/];
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}); });
|
|
594
|
+
(0, bun_test_1.it)("wraps a non-APIError from responseHandler", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
595
|
+
var res;
|
|
596
|
+
return __generator(this, function (_a) {
|
|
597
|
+
switch (_a.label) {
|
|
598
|
+
case 0:
|
|
599
|
+
mountGuarded({
|
|
600
|
+
responseHandler: function () {
|
|
601
|
+
throw new Error("serialize exploded");
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
return [4 /*yield*/, server.get("/guarded").expect(500)];
|
|
605
|
+
case 1:
|
|
606
|
+
res = _a.sent();
|
|
607
|
+
chai_1.assert.equal(res.body.title, "responseHandler error");
|
|
608
|
+
chai_1.assert.include(res.body.detail, "serialize exploded");
|
|
609
|
+
return [2 /*return*/];
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}); });
|
|
613
|
+
(0, bun_test_1.it)("keeps an APIError from postCreate intact", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
614
|
+
var res;
|
|
615
|
+
return __generator(this, function (_a) {
|
|
616
|
+
switch (_a.label) {
|
|
617
|
+
case 0:
|
|
618
|
+
mountGuarded({
|
|
619
|
+
postCreate: function () {
|
|
620
|
+
throw staffConflictError("post-create-conflict");
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
return [4 /*yield*/, server.post("/guarded").send({ name: "Fine" }).expect(409)];
|
|
624
|
+
case 1:
|
|
625
|
+
res = _a.sent();
|
|
626
|
+
assertStaffConflict(res.body, "post-create-conflict");
|
|
627
|
+
return [2 /*return*/];
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}); });
|
|
631
|
+
(0, bun_test_1.it)("wraps a non-APIError from postCreate", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
632
|
+
var res;
|
|
633
|
+
return __generator(this, function (_a) {
|
|
634
|
+
switch (_a.label) {
|
|
635
|
+
case 0:
|
|
636
|
+
mountGuarded({
|
|
637
|
+
postCreate: function () {
|
|
638
|
+
throw new Error("postCreate exploded");
|
|
639
|
+
},
|
|
640
|
+
});
|
|
641
|
+
return [4 /*yield*/, server.post("/guarded").send({ name: "Fine" }).expect(400)];
|
|
642
|
+
case 1:
|
|
643
|
+
res = _a.sent();
|
|
644
|
+
chai_1.assert.equal(res.body.title, "postCreate hook error");
|
|
645
|
+
chai_1.assert.include(res.body.detail, "postCreate exploded");
|
|
646
|
+
return [2 /*return*/];
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
}); });
|
|
650
|
+
(0, bun_test_1.it)("keeps an APIError from postUpdate intact", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
651
|
+
var doc, res;
|
|
652
|
+
return __generator(this, function (_a) {
|
|
653
|
+
switch (_a.label) {
|
|
654
|
+
case 0:
|
|
655
|
+
mountGuarded({
|
|
656
|
+
postUpdate: function () {
|
|
657
|
+
throw staffConflictError("post-update-conflict");
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
661
|
+
case 1:
|
|
662
|
+
doc = _a.sent();
|
|
663
|
+
return [4 /*yield*/, server.patch("/guarded/".concat(doc._id)).send({ name: "Renamed" }).expect(409)];
|
|
664
|
+
case 2:
|
|
665
|
+
res = _a.sent();
|
|
666
|
+
assertStaffConflict(res.body, "post-update-conflict");
|
|
667
|
+
return [2 /*return*/];
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
}); });
|
|
671
|
+
(0, bun_test_1.it)("wraps a non-APIError from postUpdate", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
672
|
+
var doc, res;
|
|
673
|
+
return __generator(this, function (_a) {
|
|
674
|
+
switch (_a.label) {
|
|
675
|
+
case 0:
|
|
676
|
+
mountGuarded({
|
|
677
|
+
postUpdate: function () {
|
|
678
|
+
throw new Error("postUpdate exploded");
|
|
679
|
+
},
|
|
680
|
+
});
|
|
681
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
682
|
+
case 1:
|
|
683
|
+
doc = _a.sent();
|
|
684
|
+
return [4 /*yield*/, server.patch("/guarded/".concat(doc._id)).send({ name: "Renamed" }).expect(400)];
|
|
685
|
+
case 2:
|
|
686
|
+
res = _a.sent();
|
|
687
|
+
chai_1.assert.equal(res.body.title, "postUpdate hook error");
|
|
688
|
+
chai_1.assert.include(res.body.detail, "postUpdate exploded");
|
|
689
|
+
return [2 /*return*/];
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
}); });
|
|
693
|
+
(0, bun_test_1.it)("keeps an APIError from postDelete intact", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
694
|
+
var doc, res;
|
|
695
|
+
return __generator(this, function (_a) {
|
|
696
|
+
switch (_a.label) {
|
|
697
|
+
case 0:
|
|
698
|
+
mountGuarded({
|
|
699
|
+
postDelete: function () {
|
|
700
|
+
throw staffConflictError("post-delete-conflict");
|
|
701
|
+
},
|
|
702
|
+
});
|
|
703
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
704
|
+
case 1:
|
|
705
|
+
doc = _a.sent();
|
|
706
|
+
return [4 /*yield*/, server.delete("/guarded/".concat(doc._id)).expect(409)];
|
|
707
|
+
case 2:
|
|
708
|
+
res = _a.sent();
|
|
709
|
+
assertStaffConflict(res.body, "post-delete-conflict");
|
|
710
|
+
return [2 /*return*/];
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
}); });
|
|
714
|
+
(0, bun_test_1.it)("wraps a non-APIError from postDelete", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
715
|
+
var doc, res;
|
|
716
|
+
return __generator(this, function (_a) {
|
|
717
|
+
switch (_a.label) {
|
|
718
|
+
case 0:
|
|
719
|
+
mountGuarded({
|
|
720
|
+
postDelete: function () {
|
|
721
|
+
throw new Error("postDelete exploded");
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
725
|
+
case 1:
|
|
726
|
+
doc = _a.sent();
|
|
727
|
+
return [4 /*yield*/, server.delete("/guarded/".concat(doc._id)).expect(400)];
|
|
728
|
+
case 2:
|
|
729
|
+
res = _a.sent();
|
|
730
|
+
chai_1.assert.equal(res.body.title, "postDelete hook error");
|
|
731
|
+
chai_1.assert.include(res.body.detail, "postDelete exploded");
|
|
732
|
+
return [2 /*return*/];
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
}); });
|
|
736
|
+
(0, bun_test_1.it)("keeps an APIError from preUpdate intact during an array operation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
737
|
+
var doc, res;
|
|
738
|
+
return __generator(this, function (_a) {
|
|
739
|
+
switch (_a.label) {
|
|
740
|
+
case 0:
|
|
741
|
+
mountGuarded({
|
|
742
|
+
preUpdate: function () {
|
|
743
|
+
throw staffConflictError("array-pre-update-conflict");
|
|
744
|
+
},
|
|
745
|
+
});
|
|
746
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
747
|
+
case 1:
|
|
748
|
+
doc = _a.sent();
|
|
749
|
+
return [4 /*yield*/, server.post("/guarded/".concat(doc._id, "/tags")).send({ tags: "healthy" }).expect(409)];
|
|
750
|
+
case 2:
|
|
751
|
+
res = _a.sent();
|
|
752
|
+
assertStaffConflict(res.body, "array-pre-update-conflict");
|
|
753
|
+
return [2 /*return*/];
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}); });
|
|
757
|
+
(0, bun_test_1.it)("keeps an APIError from postUpdate intact during an array operation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
758
|
+
var doc, res;
|
|
759
|
+
return __generator(this, function (_a) {
|
|
760
|
+
switch (_a.label) {
|
|
761
|
+
case 0:
|
|
762
|
+
mountGuarded({
|
|
763
|
+
postUpdate: function () {
|
|
764
|
+
throw staffConflictError("array-post-update-conflict");
|
|
765
|
+
},
|
|
766
|
+
});
|
|
767
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
768
|
+
case 1:
|
|
769
|
+
doc = _a.sent();
|
|
770
|
+
return [4 /*yield*/, server.post("/guarded/".concat(doc._id, "/tags")).send({ tags: "healthy" }).expect(409)];
|
|
771
|
+
case 2:
|
|
772
|
+
res = _a.sent();
|
|
773
|
+
assertStaffConflict(res.body, "array-post-update-conflict");
|
|
774
|
+
return [2 /*return*/];
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}); });
|
|
778
|
+
(0, bun_test_1.it)("wraps a non-APIError from preUpdate during an array operation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
779
|
+
var doc, res;
|
|
780
|
+
return __generator(this, function (_a) {
|
|
781
|
+
switch (_a.label) {
|
|
782
|
+
case 0:
|
|
783
|
+
mountGuarded({
|
|
784
|
+
preUpdate: function () {
|
|
785
|
+
throw new Error("array preUpdate exploded");
|
|
786
|
+
},
|
|
787
|
+
});
|
|
788
|
+
return [4 /*yield*/, GuardedModel.create({ name: "Fine", tags: [] })];
|
|
789
|
+
case 1:
|
|
790
|
+
doc = _a.sent();
|
|
791
|
+
return [4 /*yield*/, server.post("/guarded/".concat(doc._id, "/tags")).send({ tags: "healthy" }).expect(400)];
|
|
792
|
+
case 2:
|
|
793
|
+
res = _a.sent();
|
|
794
|
+
chai_1.assert.equal(res.body.title, "preUpdate hook error");
|
|
795
|
+
chai_1.assert.include(res.body.detail, "array preUpdate exploded");
|
|
796
|
+
return [2 /*return*/];
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}); });
|
|
800
|
+
});
|
|
280
801
|
});
|
package/dist/api.errors.test.js
CHANGED
|
@@ -172,5 +172,14 @@ var errors_1 = require("./errors");
|
|
|
172
172
|
(0, errors_1.apiUnauthorizedMiddleware)(err, {}, {}, next);
|
|
173
173
|
(0, bun_test_1.expect)(nextCalled).toBe(true);
|
|
174
174
|
});
|
|
175
|
+
(0, bun_test_1.it)("calls next for an APIError whose title is Unauthorized", function () {
|
|
176
|
+
var err = new errors_1.APIError({ code: "not-a-member", status: 403, title: "Unauthorized" });
|
|
177
|
+
var nextArg;
|
|
178
|
+
var next = function (error) {
|
|
179
|
+
nextArg = error;
|
|
180
|
+
};
|
|
181
|
+
(0, errors_1.apiUnauthorizedMiddleware)(err, {}, {}, next);
|
|
182
|
+
(0, bun_test_1.expect)(nextArg).toBe(err);
|
|
183
|
+
});
|
|
175
184
|
});
|
|
176
185
|
});
|