@terreno/api 0.31.0 → 56.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -2
- package/LICENSE +202 -21
- package/dist/api.d.ts +12 -3
- package/dist/api.js +110 -361
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +100 -1
- package/dist/betterAuth.d.ts +5 -0
- package/dist/betterAuthSetup.d.ts +1 -15
- package/dist/betterAuthSetup.js +29 -8
- package/dist/configurationPlugin.js +2 -2
- package/dist/docLoader.js +12 -9
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +29 -1
- package/dist/expressServer.js +5 -11
- package/dist/githubAuth.js +4 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -1
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +16 -1
- package/dist/openApiCompat.d.ts +10 -1
- package/dist/openApiCompat.js +115 -47
- package/dist/permissions.d.ts +27 -0
- package/dist/permissions.js +42 -1
- package/dist/plugins.d.ts +15 -3
- package/dist/plugins.js +36 -6
- package/dist/realtime/changeStreamWatcher.d.ts +100 -3
- package/dist/realtime/changeStreamWatcher.js +542 -137
- package/dist/realtime/realtimeApp.d.ts +3 -1
- package/dist/realtime/realtimeApp.js +75 -27
- package/dist/realtime/sessionRevalidation.d.ts +90 -0
- package/dist/realtime/sessionRevalidation.js +438 -0
- package/dist/realtime/socketAuth.d.ts +97 -0
- package/dist/realtime/socketAuth.js +272 -0
- package/dist/realtime/socketUser.d.ts +54 -0
- package/dist/realtime/socketUser.js +75 -5
- package/dist/realtime/types.d.ts +40 -0
- package/dist/secretProviders.d.ts +23 -0
- package/dist/secretProviders.js +9 -3
- package/dist/sync/executors.d.ts +198 -0
- package/dist/sync/executors.js +670 -0
- package/dist/sync/loadHarness.js +807 -0
- package/dist/sync/models.d.ts +216 -0
- package/dist/sync/models.js +644 -0
- package/dist/sync/mutationHandler.d.ts +97 -0
- package/dist/sync/mutationHandler.js +886 -0
- package/dist/sync/registry.d.ts +73 -0
- package/dist/sync/registry.js +223 -0
- package/dist/sync/routes.d.ts +62 -0
- package/dist/sync/routes.js +936 -0
- package/dist/sync/scripts/compactTombstones.d.ts +47 -0
- package/dist/sync/scripts/compactTombstones.js +270 -0
- package/dist/sync/serialize.d.ts +20 -0
- package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
- package/dist/sync/socketHandlers.d.ts +54 -0
- package/dist/sync/socketHandlers.js +470 -0
- package/dist/sync/streams.d.ts +85 -0
- package/dist/sync/streams.js +221 -0
- package/dist/sync/syncApp.d.ts +29 -0
- package/dist/sync/syncApp.js +44 -0
- package/dist/sync/syncBatch.d.ts +71 -0
- package/dist/sync/syncBatch.js +252 -0
- package/dist/sync/syncSeqPlugin.d.ts +8 -0
- package/dist/sync/syncSeqPlugin.js +903 -0
- package/dist/sync/types.d.ts +254 -0
- package/dist/sync/types.js +9 -0
- package/dist/terrenoApp.js +90 -27
- package/dist/tests/models.d.ts +11 -27
- package/dist/tests/models.js +3 -5
- package/dist/tests/testHelper.d.ts +3 -9
- package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
- package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
- package/package.json +10 -8
- package/src/__tests__/openApiCompat.test.ts +20 -0
- package/src/actions.test.ts +12 -19
- package/src/actions.ts +2 -2
- package/src/api.coverage.test.ts +9 -7
- package/src/api.errorPaths.test.ts +1 -47
- package/src/api.test.ts +12 -0
- package/src/api.ts +98 -317
- package/src/auth.test.ts +128 -176
- package/src/auth.ts +109 -0
- package/src/betterAuth.ts +6 -0
- package/src/betterAuthSetup.test.ts +34 -0
- package/src/betterAuthSetup.ts +27 -8
- package/src/configurationPlugin.ts +2 -2
- package/src/consentApp.test.ts +12 -12
- package/src/docLoader.ts +3 -1
- package/src/errors.ts +33 -0
- package/src/expressServer.test.ts +7 -1
- package/src/expressServer.ts +5 -11
- package/src/githubAuth.ts +3 -1
- package/src/index.ts +42 -0
- package/src/middleware.test.ts +40 -1
- package/src/middleware.ts +15 -0
- package/src/models/versionConfig.ts +1 -1
- package/src/openApiBuilder.test.ts +9 -24
- package/src/openApiCompat.ts +99 -45
- package/src/openApiValidator.test.ts +0 -41
- package/src/permissions.test.ts +75 -1
- package/src/permissions.ts +49 -0
- package/src/plugins.test.ts +54 -14
- package/src/plugins.ts +47 -9
- package/src/populate.test.ts +16 -25
- package/src/realtime/changeStreamWatcher.ts +552 -114
- package/src/realtime/realtime.test.ts +157 -239
- package/src/realtime/realtimeApp.ts +80 -19
- package/src/realtime/sessionRevalidation.test.ts +423 -0
- package/src/realtime/sessionRevalidation.ts +273 -0
- package/src/realtime/socketAuth.test.ts +355 -0
- package/src/realtime/socketAuth.ts +228 -0
- package/src/realtime/socketUser.ts +69 -0
- package/src/realtime/types.ts +40 -0
- package/src/secretProviders.test.ts +7 -1
- package/src/secretProviders.ts +15 -3
- package/src/sync/ensureSyncIndexes.test.ts +144 -0
- package/src/sync/executors.test.ts +882 -0
- package/src/sync/executors.ts +703 -0
- package/src/sync/integration.test.ts +1160 -0
- package/src/sync/loadHarness.ts +618 -0
- package/src/sync/models.ts +640 -0
- package/src/sync/mutationHandler.test.ts +1252 -0
- package/src/sync/mutationHandler.ts +850 -0
- package/src/sync/registry.ts +232 -0
- package/src/sync/routes.ts +812 -0
- package/src/sync/scripts/compactTombstones.test.ts +249 -0
- package/src/sync/scripts/compactTombstones.ts +145 -0
- package/src/sync/serialize.ts +48 -0
- package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
- package/src/sync/socketHandlers.ts +320 -0
- package/src/sync/streams.ts +188 -0
- package/src/sync/sync.test.ts +582 -0
- package/src/sync/syncApp.ts +44 -0
- package/src/sync/syncBatch.ts +219 -0
- package/src/sync/syncFrontier.test.ts +494 -0
- package/src/sync/syncPhaseC.test.ts +718 -0
- package/src/sync/syncRoutes.test.ts +865 -0
- package/src/sync/syncSeqPlugin.ts +738 -0
- package/src/sync/syncSocket.test.ts +1440 -0
- package/src/sync/types.ts +270 -0
- package/src/terrenoApp.ts +37 -17
- package/src/tests/bunSetup.ts +8 -0
- package/src/tests/models.ts +6 -8
- package/tsconfig.json +4 -4
- package/tsconfig.typedoc.json +7 -1
- package/dist/__tests__/openApiCompat.test.js +0 -317
- package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
- package/dist/__tests__/versionCheckPlugin.test.js +0 -597
- package/dist/actions.openApi.test.d.ts +0 -1
- package/dist/actions.openApi.test.js +0 -253
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -1087
- package/dist/api.arrayOperations.test.d.ts +0 -1
- package/dist/api.arrayOperations.test.js +0 -878
- package/dist/api.asyncHandler.test.d.ts +0 -1
- package/dist/api.asyncHandler.test.js +0 -236
- package/dist/api.coverage.test.d.ts +0 -1
- package/dist/api.coverage.test.js +0 -192
- package/dist/api.errorPaths.test.d.ts +0 -1
- package/dist/api.errorPaths.test.js +0 -887
- package/dist/api.errors.test.d.ts +0 -1
- package/dist/api.errors.test.js +0 -185
- package/dist/api.hooks.test.d.ts +0 -1
- package/dist/api.hooks.test.js +0 -950
- package/dist/api.query.test.d.ts +0 -1
- package/dist/api.query.test.js +0 -948
- package/dist/api.test.d.ts +0 -1
- package/dist/api.test.js +0 -2820
- package/dist/auth.compile.test.d.ts +0 -1
- package/dist/auth.compile.test.js +0 -201
- package/dist/auth.coverage.test.d.ts +0 -1
- package/dist/auth.coverage.test.js +0 -202
- package/dist/auth.test.d.ts +0 -1
- package/dist/auth.test.js +0 -2286
- package/dist/betterAuth.test.d.ts +0 -1
- package/dist/betterAuth.test.js +0 -181
- package/dist/betterAuthApp.test.d.ts +0 -1
- package/dist/betterAuthApp.test.js +0 -242
- package/dist/betterAuthSetup.test.d.ts +0 -1
- package/dist/betterAuthSetup.test.js +0 -762
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -353
- package/dist/configuration.test.d.ts +0 -1
- package/dist/configuration.test.js +0 -980
- package/dist/configurationPlugin.test.d.ts +0 -1
- package/dist/configurationPlugin.test.js +0 -827
- package/dist/consentApp.test.d.ts +0 -1
- package/dist/consentApp.test.js +0 -1411
- package/dist/docLoader.test.d.ts +0 -1
- package/dist/docLoader.test.js +0 -137
- package/dist/envConfigurationPlugin.test.d.ts +0 -1
- package/dist/envConfigurationPlugin.test.js +0 -369
- package/dist/errors.test.d.ts +0 -1
- package/dist/errors.test.js +0 -607
- package/dist/expressServer.test.d.ts +0 -1
- package/dist/expressServer.test.js +0 -1249
- package/dist/githubAuth.test.d.ts +0 -1
- package/dist/githubAuth.test.js +0 -1142
- package/dist/httpClient.test.d.ts +0 -1
- package/dist/httpClient.test.js +0 -1471
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -685
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -241
- package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
- package/dist/notifiers/googleChatNotifier.test.js +0 -298
- package/dist/notifiers/slackNotifier.test.d.ts +0 -1
- package/dist/notifiers/slackNotifier.test.js +0 -297
- package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
- package/dist/notifiers/zoomNotifier.test.js +0 -373
- package/dist/openApi.test.d.ts +0 -1
- package/dist/openApi.test.js +0 -620
- package/dist/openApiBuilder.test.d.ts +0 -1
- package/dist/openApiBuilder.test.js +0 -599
- package/dist/openApiEtag.test.d.ts +0 -1
- package/dist/openApiEtag.test.js +0 -86
- package/dist/openApiValidator.test.d.ts +0 -1
- package/dist/openApiValidator.test.js +0 -795
- package/dist/permissions.middleware.test.d.ts +0 -1
- package/dist/permissions.middleware.test.js +0 -308
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -439
- package/dist/plugins.test.d.ts +0 -1
- package/dist/plugins.test.js +0 -902
- package/dist/populate.test.d.ts +0 -1
- package/dist/populate.test.js +0 -370
- package/dist/realtime/realtime.test.d.ts +0 -10
- package/dist/realtime/realtime.test.js +0 -4213
- package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
- package/dist/realtime/realtimeAppSetup.test.js +0 -213
- package/dist/requestContext.test.d.ts +0 -1
- package/dist/requestContext.test.js +0 -412
- package/dist/scriptRunner.test.d.ts +0 -1
- package/dist/scriptRunner.test.js +0 -386
- package/dist/secretProviders.test.d.ts +0 -1
- package/dist/secretProviders.test.js +0 -726
- package/dist/syncConsents.test.d.ts +0 -1
- package/dist/syncConsents.test.js +0 -522
- package/dist/terrenoApp.test.d.ts +0 -1
- package/dist/terrenoApp.test.js +0 -489
- package/dist/tests/bunSetup.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.js +0 -37
- package/dist/tests/testEnv.d.ts +0 -0
- package/dist/tests/testEnv.js +0 -6
- package/dist/transformers.test.d.ts +0 -1
- package/dist/transformers.test.js +0 -423
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -242
- package/src/realtime/realtimeAppSetup.test.ts +0 -161
- /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
package/dist/errors.test.js
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
51
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
52
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
53
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
54
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
55
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
56
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
60
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
61
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
62
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
63
|
-
function step(op) {
|
|
64
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
65
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
66
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
67
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
68
|
-
switch (op[0]) {
|
|
69
|
-
case 0: case 1: t = op; break;
|
|
70
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
71
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
72
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
73
|
-
default:
|
|
74
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
75
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
76
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
77
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
78
|
-
if (t[2]) _.ops.pop();
|
|
79
|
-
_.trys.pop(); continue;
|
|
80
|
-
}
|
|
81
|
-
op = body.call(thisArg, _);
|
|
82
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
83
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
-
};
|
|
89
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
-
var bun_test_1 = require("bun:test");
|
|
91
|
-
var Sentry = __importStar(require("@sentry/bun"));
|
|
92
|
-
var express_1 = __importDefault(require("express"));
|
|
93
|
-
var mongoose_1 = __importStar(require("mongoose"));
|
|
94
|
-
var supertest_1 = __importDefault(require("supertest"));
|
|
95
|
-
var errors_1 = require("./errors");
|
|
96
|
-
var buildResponse = function () {
|
|
97
|
-
var res = {
|
|
98
|
-
json: (0, bun_test_1.mock)(function () { return res; }),
|
|
99
|
-
send: (0, bun_test_1.mock)(function () { return res; }),
|
|
100
|
-
status: (0, bun_test_1.mock)(function () { return res; }),
|
|
101
|
-
};
|
|
102
|
-
return res;
|
|
103
|
-
};
|
|
104
|
-
(0, bun_test_1.describe)("APIError", function () {
|
|
105
|
-
(0, bun_test_1.it)("creates an error with the provided fields", function () {
|
|
106
|
-
var error = new errors_1.APIError({
|
|
107
|
-
code: "validation-failed",
|
|
108
|
-
detail: "Email is invalid",
|
|
109
|
-
id: "abc-123",
|
|
110
|
-
links: { about: "https://example.com/help", type: "https://example.com/types/validation" },
|
|
111
|
-
meta: { requestId: "req-1" },
|
|
112
|
-
source: { header: "x-foo", parameter: "limit", pointer: "/data/email" },
|
|
113
|
-
status: 400,
|
|
114
|
-
title: "Validation failed",
|
|
115
|
-
});
|
|
116
|
-
(0, bun_test_1.expect)(error).toBeInstanceOf(Error);
|
|
117
|
-
(0, bun_test_1.expect)(error.title).toBe("Validation failed");
|
|
118
|
-
(0, bun_test_1.expect)(error.detail).toBe("Email is invalid");
|
|
119
|
-
(0, bun_test_1.expect)(error.code).toBe("validation-failed");
|
|
120
|
-
(0, bun_test_1.expect)(error.status).toBe(400);
|
|
121
|
-
(0, bun_test_1.expect)(error.id).toBe("abc-123");
|
|
122
|
-
(0, bun_test_1.expect)(error.links).toEqual({
|
|
123
|
-
about: "https://example.com/help",
|
|
124
|
-
type: "https://example.com/types/validation",
|
|
125
|
-
});
|
|
126
|
-
(0, bun_test_1.expect)(error.source).toEqual({
|
|
127
|
-
header: "x-foo",
|
|
128
|
-
parameter: "limit",
|
|
129
|
-
pointer: "/data/email",
|
|
130
|
-
});
|
|
131
|
-
(0, bun_test_1.expect)(error.meta).toEqual({ requestId: "req-1" });
|
|
132
|
-
});
|
|
133
|
-
(0, bun_test_1.it)("uses the title as the message, without detail or stacks", function () {
|
|
134
|
-
var error = new errors_1.APIError({ detail: "Something exploded", title: "Boom" });
|
|
135
|
-
(0, bun_test_1.expect)(error.message).toBe("Boom");
|
|
136
|
-
(0, bun_test_1.expect)(error.title).toBe("Boom");
|
|
137
|
-
});
|
|
138
|
-
(0, bun_test_1.it)("exposes the wrapped error as the standard cause", function () {
|
|
139
|
-
var wrapped = new Error("inner");
|
|
140
|
-
var error = new errors_1.APIError({ cause: wrapped, title: "Outer" });
|
|
141
|
-
(0, bun_test_1.expect)(error.message).toBe("Outer");
|
|
142
|
-
(0, bun_test_1.expect)(error.cause).toBe(wrapped);
|
|
143
|
-
});
|
|
144
|
-
(0, bun_test_1.it)("supports the deprecated error option as a cause alias", function () {
|
|
145
|
-
var wrapped = new Error("inner");
|
|
146
|
-
var error = new errors_1.APIError({ error: wrapped, title: "Outer" });
|
|
147
|
-
(0, bun_test_1.expect)(error.cause).toBe(wrapped);
|
|
148
|
-
(0, bun_test_1.expect)(error.error).toBe(wrapped);
|
|
149
|
-
});
|
|
150
|
-
(0, bun_test_1.it)("derives the name from the status code", function () {
|
|
151
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 400, title: "T" }).name).toBe("BadRequestError");
|
|
152
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 401, title: "T" }).name).toBe("UnauthorizedError");
|
|
153
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 403, title: "T" }).name).toBe("ForbiddenError");
|
|
154
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 404, title: "T" }).name).toBe("NotFoundError");
|
|
155
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 409, title: "T" }).name).toBe("ConflictError");
|
|
156
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 500, title: "T" }).name).toBe("InternalServerError");
|
|
157
|
-
});
|
|
158
|
-
(0, bun_test_1.it)("falls back to APIError for unmapped statuses", function () {
|
|
159
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 418, title: "T" }).name).toBe("APIError");
|
|
160
|
-
});
|
|
161
|
-
(0, bun_test_1.it)("derives the name from the code when provided", function () {
|
|
162
|
-
var error = new errors_1.APIError({ code: "update-admin-error", status: 403, title: "T" });
|
|
163
|
-
(0, bun_test_1.expect)(error.name).toBe("UpdateAdminError");
|
|
164
|
-
});
|
|
165
|
-
(0, bun_test_1.it)("keeps title in sync with message via the getter", function () {
|
|
166
|
-
var error = new errors_1.APIError({ title: "Original" });
|
|
167
|
-
error.message = "Changed";
|
|
168
|
-
(0, bun_test_1.expect)(error.title).toBe("Changed");
|
|
169
|
-
});
|
|
170
|
-
(0, bun_test_1.it)("defaults status to 500 when status is omitted", function () {
|
|
171
|
-
var error = new errors_1.APIError({ title: "No status" });
|
|
172
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
173
|
-
});
|
|
174
|
-
(0, bun_test_1.it)("forces status to 500 when below 400", function () {
|
|
175
|
-
var error = new errors_1.APIError({ status: 200, title: "Too low" });
|
|
176
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
177
|
-
});
|
|
178
|
-
(0, bun_test_1.it)("forces status to 500 when above 599", function () {
|
|
179
|
-
var error = new errors_1.APIError({ status: 600, title: "Too high" });
|
|
180
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
181
|
-
});
|
|
182
|
-
(0, bun_test_1.it)("defaults meta to an empty object when not provided", function () {
|
|
183
|
-
var error = new errors_1.APIError({ title: "No meta" });
|
|
184
|
-
(0, bun_test_1.expect)(error.meta).toEqual({});
|
|
185
|
-
});
|
|
186
|
-
(0, bun_test_1.it)("merges fields into meta", function () {
|
|
187
|
-
var _a;
|
|
188
|
-
var error = new errors_1.APIError({
|
|
189
|
-
fields: { email: "Required", name: "Required" },
|
|
190
|
-
title: "Validation",
|
|
191
|
-
});
|
|
192
|
-
(0, bun_test_1.expect)((_a = error.meta) === null || _a === void 0 ? void 0 : _a.fields).toEqual({ email: "Required", name: "Required" });
|
|
193
|
-
});
|
|
194
|
-
(0, bun_test_1.it)("respects disableExternalErrorTracking", function () {
|
|
195
|
-
var trackedError = new errors_1.APIError({ title: "Tracked" });
|
|
196
|
-
var untrackedError = new errors_1.APIError({
|
|
197
|
-
disableExternalErrorTracking: true,
|
|
198
|
-
title: "Untracked",
|
|
199
|
-
});
|
|
200
|
-
(0, bun_test_1.expect)(trackedError.disableExternalErrorTracking).toBeUndefined();
|
|
201
|
-
(0, bun_test_1.expect)(untrackedError.disableExternalErrorTracking).toBe(true);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
(0, bun_test_1.describe)("APIError subclasses", function () {
|
|
205
|
-
(0, bun_test_1.it)("sets the status and name from the subclass", function () {
|
|
206
|
-
var error = new errors_1.NotFoundError("Todo not found");
|
|
207
|
-
(0, bun_test_1.expect)(error.status).toBe(404);
|
|
208
|
-
(0, bun_test_1.expect)(error.name).toBe("NotFoundError");
|
|
209
|
-
(0, bun_test_1.expect)(error.message).toBe("Todo not found");
|
|
210
|
-
(0, bun_test_1.expect)(error).toBeInstanceOf(errors_1.APIError);
|
|
211
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(error)).toBe(true);
|
|
212
|
-
});
|
|
213
|
-
(0, bun_test_1.it)("accepts full options", function () {
|
|
214
|
-
var cause = new Error("inner");
|
|
215
|
-
var error = new errors_1.ForbiddenError({ cause: cause, detail: "Admins only", title: "Not allowed" });
|
|
216
|
-
(0, bun_test_1.expect)(error.status).toBe(403);
|
|
217
|
-
(0, bun_test_1.expect)(error.name).toBe("ForbiddenError");
|
|
218
|
-
(0, bun_test_1.expect)(error.detail).toBe("Admins only");
|
|
219
|
-
(0, bun_test_1.expect)(error.cause).toBe(cause);
|
|
220
|
-
});
|
|
221
|
-
(0, bun_test_1.it)("keeps the subclass name even when a code is provided", function () {
|
|
222
|
-
var error = new errors_1.BadRequestError({ code: "invalid-cursor", title: "Bad cursor" });
|
|
223
|
-
(0, bun_test_1.expect)(error.name).toBe("BadRequestError");
|
|
224
|
-
(0, bun_test_1.expect)(error.status).toBe(400);
|
|
225
|
-
});
|
|
226
|
-
(0, bun_test_1.it)("uses ValidationError with a 400 status", function () {
|
|
227
|
-
var _a;
|
|
228
|
-
var error = new errors_1.ValidationError({ fields: { email: "Required" }, title: "Validation failed" });
|
|
229
|
-
(0, bun_test_1.expect)(error.status).toBe(400);
|
|
230
|
-
(0, bun_test_1.expect)(error.name).toBe("ValidationError");
|
|
231
|
-
(0, bun_test_1.expect)((_a = error.meta) === null || _a === void 0 ? void 0 : _a.fields).toEqual({ email: "Required" });
|
|
232
|
-
});
|
|
233
|
-
(0, bun_test_1.it)("derives name from custom subclasses via new.target", function () {
|
|
234
|
-
var PaymentError = /** @class */ (function (_super) {
|
|
235
|
-
__extends(PaymentError, _super);
|
|
236
|
-
function PaymentError(title) {
|
|
237
|
-
return _super.call(this, { status: 402, title: title }) || this;
|
|
238
|
-
}
|
|
239
|
-
return PaymentError;
|
|
240
|
-
}(errors_1.APIError));
|
|
241
|
-
(0, bun_test_1.expect)(new PaymentError("declined").name).toBe("PaymentError");
|
|
242
|
-
});
|
|
243
|
-
(0, bun_test_1.it)("covers the remaining status subclasses", function () {
|
|
244
|
-
(0, bun_test_1.expect)(new errors_1.UnauthorizedError("U").status).toBe(401);
|
|
245
|
-
(0, bun_test_1.expect)(new errors_1.UnauthorizedError("U").name).toBe("UnauthorizedError");
|
|
246
|
-
(0, bun_test_1.expect)(new errors_1.ConflictError("C").status).toBe(409);
|
|
247
|
-
(0, bun_test_1.expect)(new errors_1.ConflictError("C").name).toBe("ConflictError");
|
|
248
|
-
(0, bun_test_1.expect)(new errors_1.InternalServerError("I").status).toBe(500);
|
|
249
|
-
(0, bun_test_1.expect)(new errors_1.InternalServerError("I").name).toBe("InternalServerError");
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
(0, bun_test_1.describe)("isAPIError", function () {
|
|
253
|
-
(0, bun_test_1.it)("returns true for an APIError instance", function () {
|
|
254
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(new errors_1.APIError({ title: "Boom" }))).toBe(true);
|
|
255
|
-
});
|
|
256
|
-
(0, bun_test_1.it)("returns false for a regular Error", function () {
|
|
257
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(new Error("nope"))).toBe(false);
|
|
258
|
-
});
|
|
259
|
-
(0, bun_test_1.it)("returns true for any error whose name is APIError (transition fallback)", function () {
|
|
260
|
-
var err = new Error("custom");
|
|
261
|
-
err.name = "APIError";
|
|
262
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(err)).toBe(true);
|
|
263
|
-
});
|
|
264
|
-
(0, bun_test_1.it)("returns true for a branded error from a duplicate package copy", function () {
|
|
265
|
-
var err = new Error("branded");
|
|
266
|
-
err.isTerrenoAPIError = true;
|
|
267
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(err)).toBe(true);
|
|
268
|
-
});
|
|
269
|
-
(0, bun_test_1.it)("returns true for subclasses", function () {
|
|
270
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(new errors_1.NotFoundError("missing"))).toBe(true);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
(0, bun_test_1.describe)("getDisableExternalErrorTracking", function () {
|
|
274
|
-
(0, bun_test_1.it)("returns the flag from an APIError", function () {
|
|
275
|
-
var error = new errors_1.APIError({ disableExternalErrorTracking: true, title: "Test" });
|
|
276
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(error)).toBe(true);
|
|
277
|
-
});
|
|
278
|
-
(0, bun_test_1.it)("returns undefined for a plain Error without the flag", function () {
|
|
279
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(new Error("plain"))).toBeUndefined();
|
|
280
|
-
});
|
|
281
|
-
(0, bun_test_1.it)("returns the flag when attached to a non-APIError object", function () {
|
|
282
|
-
var error = { disableExternalErrorTracking: false };
|
|
283
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(error)).toBe(false);
|
|
284
|
-
});
|
|
285
|
-
(0, bun_test_1.it)("returns undefined for primitives and null", function () {
|
|
286
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(null)).toBeUndefined();
|
|
287
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(undefined)).toBeUndefined();
|
|
288
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)("string")).toBeUndefined();
|
|
289
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(42)).toBeUndefined();
|
|
290
|
-
});
|
|
291
|
-
(0, bun_test_1.it)("returns undefined for an object missing the property", function () {
|
|
292
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)({ foo: "bar" })).toBeUndefined();
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
(0, bun_test_1.describe)("errorMessage", function () {
|
|
296
|
-
(0, bun_test_1.it)("returns the message from an Error instance", function () {
|
|
297
|
-
(0, bun_test_1.expect)((0, errors_1.errorMessage)(new Error("boom"))).toBe("boom");
|
|
298
|
-
});
|
|
299
|
-
(0, bun_test_1.it)("returns the string representation of a non-Error value", function () {
|
|
300
|
-
(0, bun_test_1.expect)((0, errors_1.errorMessage)("raw string")).toBe("raw string");
|
|
301
|
-
(0, bun_test_1.expect)((0, errors_1.errorMessage)(42)).toBe("42");
|
|
302
|
-
(0, bun_test_1.expect)((0, errors_1.errorMessage)(null)).toBe("null");
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
(0, bun_test_1.describe)("errorStack", function () {
|
|
306
|
-
(0, bun_test_1.it)("returns the stack trace from an Error with a stack", function () {
|
|
307
|
-
var err = new Error("fail");
|
|
308
|
-
(0, bun_test_1.expect)((0, errors_1.errorStack)(err)).toBe(err.stack);
|
|
309
|
-
});
|
|
310
|
-
(0, bun_test_1.it)("returns the string representation when error has no stack", function () {
|
|
311
|
-
var err = new Error("no-stack");
|
|
312
|
-
Object.defineProperty(err, "stack", { value: undefined });
|
|
313
|
-
(0, bun_test_1.expect)((0, errors_1.errorStack)(err)).toBe("Error: no-stack");
|
|
314
|
-
});
|
|
315
|
-
(0, bun_test_1.it)("returns the string representation of a non-Error value", function () {
|
|
316
|
-
(0, bun_test_1.expect)((0, errors_1.errorStack)("plain")).toBe("plain");
|
|
317
|
-
(0, bun_test_1.expect)((0, errors_1.errorStack)(123)).toBe("123");
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
(0, bun_test_1.describe)("getAPIErrorBody", function () {
|
|
321
|
-
(0, bun_test_1.it)("returns title and status by default", function () {
|
|
322
|
-
var error = new errors_1.APIError({ status: 404, title: "Not Found" });
|
|
323
|
-
var body = (0, errors_1.getAPIErrorBody)(error);
|
|
324
|
-
(0, bun_test_1.expect)(body).toEqual({ status: 404, title: "Not Found" });
|
|
325
|
-
});
|
|
326
|
-
(0, bun_test_1.it)("includes optional fields when set, including disableExternalErrorTracking when true", function () {
|
|
327
|
-
var error = new errors_1.APIError({
|
|
328
|
-
code: "not-found",
|
|
329
|
-
detail: "Could not find resource",
|
|
330
|
-
disableExternalErrorTracking: true,
|
|
331
|
-
id: "err-1",
|
|
332
|
-
links: { about: "https://example.com/help" },
|
|
333
|
-
source: { pointer: "/data/id" },
|
|
334
|
-
status: 404,
|
|
335
|
-
title: "Not Found",
|
|
336
|
-
});
|
|
337
|
-
var body = (0, errors_1.getAPIErrorBody)(error);
|
|
338
|
-
(0, bun_test_1.expect)(body).toEqual({
|
|
339
|
-
code: "not-found",
|
|
340
|
-
detail: "Could not find resource",
|
|
341
|
-
disableExternalErrorTracking: true,
|
|
342
|
-
id: "err-1",
|
|
343
|
-
links: { about: "https://example.com/help" },
|
|
344
|
-
source: { pointer: "/data/id" },
|
|
345
|
-
status: 404,
|
|
346
|
-
title: "Not Found",
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
(0, bun_test_1.it)("matches toJSON and excludes name, stack, and cause", function () {
|
|
350
|
-
var error = new errors_1.APIError({
|
|
351
|
-
cause: new Error("inner"),
|
|
352
|
-
detail: "d",
|
|
353
|
-
status: 404,
|
|
354
|
-
title: "Not Found",
|
|
355
|
-
});
|
|
356
|
-
var body = error.toJSON();
|
|
357
|
-
(0, bun_test_1.expect)(body).toEqual((0, errors_1.getAPIErrorBody)(error));
|
|
358
|
-
(0, bun_test_1.expect)(body.name).toBeUndefined();
|
|
359
|
-
(0, bun_test_1.expect)(body.stack).toBeUndefined();
|
|
360
|
-
(0, bun_test_1.expect)(body.cause).toBeUndefined();
|
|
361
|
-
(0, bun_test_1.expect)(body.disableExternalErrorTracking).toBeUndefined();
|
|
362
|
-
(0, bun_test_1.expect)(JSON.parse(JSON.stringify(error))).toEqual(JSON.parse(JSON.stringify(body)));
|
|
363
|
-
});
|
|
364
|
-
(0, bun_test_1.it)("exposes deprecated error getter as alias for cause", function () {
|
|
365
|
-
var cause = new Error("inner");
|
|
366
|
-
var error = new errors_1.APIError({ cause: cause, title: "Wrapped" });
|
|
367
|
-
(0, bun_test_1.expect)(error.error).toBe(cause);
|
|
368
|
-
(0, bun_test_1.expect)(error.cause).toBe(cause);
|
|
369
|
-
});
|
|
370
|
-
(0, bun_test_1.it)("prefers explicit title over message when serializing legacy instances", function () {
|
|
371
|
-
var legacy = new Error("polluted message with stack");
|
|
372
|
-
legacy.status = 404;
|
|
373
|
-
legacy.title = "Clean title";
|
|
374
|
-
var body = (0, errors_1.getAPIErrorBody)(legacy);
|
|
375
|
-
(0, bun_test_1.expect)(body.title).toBe("Clean title");
|
|
376
|
-
});
|
|
377
|
-
(0, bun_test_1.it)("truncates fractional and invalid status codes to 500", function () {
|
|
378
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 404.7, title: "x" }).status).toBe(404);
|
|
379
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: Number.NaN, title: "x" }).status).toBe(500);
|
|
380
|
-
(0, bun_test_1.expect)(new errors_1.APIError({ status: 200, title: "x" }).status).toBe(500);
|
|
381
|
-
});
|
|
382
|
-
(0, bun_test_1.it)("omits empty meta and unset optional fields", function () {
|
|
383
|
-
var error = new errors_1.APIError({ status: 400, title: "Bad" });
|
|
384
|
-
var body = (0, errors_1.getAPIErrorBody)(error);
|
|
385
|
-
(0, bun_test_1.expect)(body.meta).toBeUndefined();
|
|
386
|
-
(0, bun_test_1.expect)(body.code).toBeUndefined();
|
|
387
|
-
(0, bun_test_1.expect)(body.detail).toBeUndefined();
|
|
388
|
-
(0, bun_test_1.expect)(body.id).toBeUndefined();
|
|
389
|
-
(0, bun_test_1.expect)(body.links).toBeUndefined();
|
|
390
|
-
(0, bun_test_1.expect)(body.source).toBeUndefined();
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
(0, bun_test_1.describe)("errorsPlugin", function () {
|
|
394
|
-
(0, bun_test_1.it)("adds an apiErrors array field to the schema", function () {
|
|
395
|
-
var schema = new mongoose_1.Schema({ name: String });
|
|
396
|
-
(0, errors_1.errorsPlugin)(schema);
|
|
397
|
-
var path = schema.path("apiErrors");
|
|
398
|
-
(0, bun_test_1.expect)(path).toBeDefined();
|
|
399
|
-
});
|
|
400
|
-
(0, bun_test_1.it)("requires title on each error subdocument", function () {
|
|
401
|
-
var schema = new mongoose_1.Schema({ name: String });
|
|
402
|
-
(0, errors_1.errorsPlugin)(schema);
|
|
403
|
-
var path = schema.path("apiErrors");
|
|
404
|
-
// Inspect the embedded error schema for the title definition.
|
|
405
|
-
var embedded = path;
|
|
406
|
-
var titlePath = embedded.schema.path("title");
|
|
407
|
-
(0, bun_test_1.expect)(titlePath).toBeDefined();
|
|
408
|
-
(0, bun_test_1.expect)(titlePath.isRequired).toBe(true);
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
(0, bun_test_1.describe)("apiUnauthorizedMiddleware", function () {
|
|
412
|
-
var res;
|
|
413
|
-
var next;
|
|
414
|
-
var req = {};
|
|
415
|
-
(0, bun_test_1.beforeEach)(function () {
|
|
416
|
-
res = buildResponse();
|
|
417
|
-
next = (0, bun_test_1.mock)(function () { });
|
|
418
|
-
});
|
|
419
|
-
(0, bun_test_1.it)("returns a 401 JSON response when the message is Unauthorized", function () {
|
|
420
|
-
(0, errors_1.apiUnauthorizedMiddleware)(new Error("Unauthorized"), req, res, next);
|
|
421
|
-
(0, bun_test_1.expect)(res.status).toHaveBeenCalledWith(401);
|
|
422
|
-
(0, bun_test_1.expect)(res.json).toHaveBeenCalledWith({ status: 401, title: "Unauthorized" });
|
|
423
|
-
(0, bun_test_1.expect)(res.send).toHaveBeenCalled();
|
|
424
|
-
(0, bun_test_1.expect)(next).not.toHaveBeenCalled();
|
|
425
|
-
});
|
|
426
|
-
(0, bun_test_1.it)("forwards other errors to next", function () {
|
|
427
|
-
var err = new Error("Something else");
|
|
428
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, req, res, next);
|
|
429
|
-
(0, bun_test_1.expect)(next).toHaveBeenCalledWith(err);
|
|
430
|
-
(0, bun_test_1.expect)(res.status).not.toHaveBeenCalled();
|
|
431
|
-
});
|
|
432
|
-
(0, bun_test_1.it)("forwards an APIError titled Unauthorized so it keeps its own status", function () {
|
|
433
|
-
var err = new errors_1.ForbiddenError({
|
|
434
|
-
code: "org-membership-required",
|
|
435
|
-
detail: "You are not a member of this organization",
|
|
436
|
-
title: "Unauthorized",
|
|
437
|
-
});
|
|
438
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, req, res, next);
|
|
439
|
-
(0, bun_test_1.expect)(next).toHaveBeenCalledWith(err);
|
|
440
|
-
(0, bun_test_1.expect)(res.status).not.toHaveBeenCalled();
|
|
441
|
-
});
|
|
442
|
-
(0, bun_test_1.it)("forwards a plain APIError titled Unauthorized rather than rewriting it to a 401", function () {
|
|
443
|
-
var err = new errors_1.APIError({ status: 403, title: "Unauthorized" });
|
|
444
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, req, res, next);
|
|
445
|
-
(0, bun_test_1.expect)(next).toHaveBeenCalledWith(err);
|
|
446
|
-
(0, bun_test_1.expect)(res.status).not.toHaveBeenCalled();
|
|
447
|
-
});
|
|
448
|
-
(0, bun_test_1.it)("forwards an Error subclass whose message is Unauthorized", function () {
|
|
449
|
-
var DomainUnauthorizedError = /** @class */ (function (_super) {
|
|
450
|
-
__extends(DomainUnauthorizedError, _super);
|
|
451
|
-
function DomainUnauthorizedError() {
|
|
452
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
453
|
-
}
|
|
454
|
-
return DomainUnauthorizedError;
|
|
455
|
-
}(Error));
|
|
456
|
-
var err = new DomainUnauthorizedError("Unauthorized");
|
|
457
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, req, res, next);
|
|
458
|
-
(0, bun_test_1.expect)(next).toHaveBeenCalledWith(err);
|
|
459
|
-
(0, bun_test_1.expect)(res.status).not.toHaveBeenCalled();
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
(0, bun_test_1.describe)("apiUnauthorizedMiddleware in the terrenoApp middleware order", function () {
|
|
463
|
-
var buildApp = function () {
|
|
464
|
-
var app = (0, express_1.default)();
|
|
465
|
-
app.get("/forbidden", function (_req, _res, next) {
|
|
466
|
-
next(new errors_1.ForbiddenError({
|
|
467
|
-
code: "org-membership-required",
|
|
468
|
-
detail: "You are not a member of this organization",
|
|
469
|
-
title: "Unauthorized",
|
|
470
|
-
}));
|
|
471
|
-
});
|
|
472
|
-
app.get("/passport", function (_req, _res, next) {
|
|
473
|
-
next(new Error("Unauthorized"));
|
|
474
|
-
});
|
|
475
|
-
app.use(errors_1.apiUnauthorizedMiddleware);
|
|
476
|
-
app.use(errors_1.apiErrorMiddleware);
|
|
477
|
-
return app;
|
|
478
|
-
};
|
|
479
|
-
(0, bun_test_1.it)("keeps a 403 titled Unauthorized a 403", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
480
|
-
var res;
|
|
481
|
-
return __generator(this, function (_a) {
|
|
482
|
-
switch (_a.label) {
|
|
483
|
-
case 0: return [4 /*yield*/, (0, supertest_1.default)(buildApp()).get("/forbidden").expect(403)];
|
|
484
|
-
case 1:
|
|
485
|
-
res = _a.sent();
|
|
486
|
-
(0, bun_test_1.expect)(res.body).toEqual({
|
|
487
|
-
code: "org-membership-required",
|
|
488
|
-
detail: "You are not a member of this organization",
|
|
489
|
-
status: 403,
|
|
490
|
-
title: "Unauthorized",
|
|
491
|
-
});
|
|
492
|
-
return [2 /*return*/];
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
}); });
|
|
496
|
-
(0, bun_test_1.it)("still converts a plain Passport Unauthorized error to a 401", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
497
|
-
var res;
|
|
498
|
-
return __generator(this, function (_a) {
|
|
499
|
-
switch (_a.label) {
|
|
500
|
-
case 0: return [4 /*yield*/, (0, supertest_1.default)(buildApp()).get("/passport").expect(401)];
|
|
501
|
-
case 1:
|
|
502
|
-
res = _a.sent();
|
|
503
|
-
(0, bun_test_1.expect)(res.body).toEqual({ status: 401, title: "Unauthorized" });
|
|
504
|
-
return [2 /*return*/];
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
}); });
|
|
508
|
-
});
|
|
509
|
-
(0, bun_test_1.describe)("errorDetail", function () {
|
|
510
|
-
(0, bun_test_1.it)("combines an APIError's title and detail", function () {
|
|
511
|
-
var error = new errors_1.ConflictError({
|
|
512
|
-
code: "schedule-item-staff-conflict",
|
|
513
|
-
detail: "Conflict detected for Dr. Ada on 2026-07-31",
|
|
514
|
-
title: "Conflict detected",
|
|
515
|
-
});
|
|
516
|
-
(0, bun_test_1.expect)((0, errors_1.errorDetail)(error)).toBe("Conflict detected: Conflict detected for Dr. Ada on 2026-07-31");
|
|
517
|
-
});
|
|
518
|
-
(0, bun_test_1.it)("falls back to the title when an APIError has no detail", function () {
|
|
519
|
-
(0, bun_test_1.expect)((0, errors_1.errorDetail)(new errors_1.APIError({ title: "Conflict detected" }))).toBe("Conflict detected");
|
|
520
|
-
});
|
|
521
|
-
(0, bun_test_1.it)("returns the message for a plain Error", function () {
|
|
522
|
-
(0, bun_test_1.expect)((0, errors_1.errorDetail)(new Error("boom"))).toBe("boom");
|
|
523
|
-
});
|
|
524
|
-
(0, bun_test_1.it)("stringifies non-Error values", function () {
|
|
525
|
-
(0, bun_test_1.expect)((0, errors_1.errorDetail)("boom")).toBe("boom");
|
|
526
|
-
(0, bun_test_1.expect)((0, errors_1.errorDetail)(42)).toBe("42");
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
(0, bun_test_1.describe)("apiErrorMiddleware", function () {
|
|
530
|
-
var res;
|
|
531
|
-
var next;
|
|
532
|
-
var req = {};
|
|
533
|
-
var captureExceptionSpy = Sentry.captureException;
|
|
534
|
-
(0, bun_test_1.beforeEach)(function () {
|
|
535
|
-
var _a;
|
|
536
|
-
res = buildResponse();
|
|
537
|
-
next = (0, bun_test_1.mock)(function () { });
|
|
538
|
-
(_a = captureExceptionSpy.mockClear) === null || _a === void 0 ? void 0 : _a.call(captureExceptionSpy);
|
|
539
|
-
});
|
|
540
|
-
(0, bun_test_1.it)("responds with the APIError status and body", function () {
|
|
541
|
-
var err = new errors_1.APIError({ detail: "missing", status: 404, title: "Not Found" });
|
|
542
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
543
|
-
(0, bun_test_1.expect)(res.status).toHaveBeenCalledWith(404);
|
|
544
|
-
(0, bun_test_1.expect)(res.json).toHaveBeenCalledWith((0, errors_1.getAPIErrorBody)(err));
|
|
545
|
-
(0, bun_test_1.expect)(res.send).toHaveBeenCalled();
|
|
546
|
-
(0, bun_test_1.expect)(next).not.toHaveBeenCalled();
|
|
547
|
-
});
|
|
548
|
-
(0, bun_test_1.it)("captures the exception with Sentry by default", function () {
|
|
549
|
-
var err = new errors_1.APIError({ status: 500, title: "Boom" });
|
|
550
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
551
|
-
(0, bun_test_1.expect)(captureExceptionSpy).toHaveBeenCalledWith(err);
|
|
552
|
-
});
|
|
553
|
-
(0, bun_test_1.it)("fingerprints Sentry captures on the logical error type", function () {
|
|
554
|
-
var scope = {
|
|
555
|
-
setContext: (0, bun_test_1.mock)(function () { }),
|
|
556
|
-
setFingerprint: (0, bun_test_1.mock)(function () { }),
|
|
557
|
-
setTag: (0, bun_test_1.mock)(function () { }),
|
|
558
|
-
};
|
|
559
|
-
var withScopeSpy = (0, bun_test_1.spyOn)(Sentry, "withScope").mockImplementation((function (callback) { return callback(scope); }));
|
|
560
|
-
try {
|
|
561
|
-
var err = new errors_1.APIError({ code: "todo-sync-failed", status: 502, title: "Sync failed" });
|
|
562
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
563
|
-
(0, bun_test_1.expect)(scope.setFingerprint).toHaveBeenCalledWith([
|
|
564
|
-
"TodoSyncFailed",
|
|
565
|
-
"todo-sync-failed",
|
|
566
|
-
"502",
|
|
567
|
-
]);
|
|
568
|
-
(0, bun_test_1.expect)(scope.setTag).toHaveBeenCalledWith("http.status_code", "502");
|
|
569
|
-
(0, bun_test_1.expect)(scope.setTag).toHaveBeenCalledWith("api_error.code", "todo-sync-failed");
|
|
570
|
-
(0, bun_test_1.expect)(scope.setContext).toHaveBeenCalledWith("apiError", bun_test_1.expect.objectContaining({ status: 502, title: "Sync failed" }));
|
|
571
|
-
}
|
|
572
|
-
finally {
|
|
573
|
-
withScopeSpy.mockRestore();
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
(0, bun_test_1.it)("does not capture the exception when disableExternalErrorTracking is true", function () {
|
|
577
|
-
var err = new errors_1.APIError({
|
|
578
|
-
disableExternalErrorTracking: true,
|
|
579
|
-
status: 500,
|
|
580
|
-
title: "Quiet",
|
|
581
|
-
});
|
|
582
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
583
|
-
(0, bun_test_1.expect)(captureExceptionSpy).not.toHaveBeenCalled();
|
|
584
|
-
(0, bun_test_1.expect)(res.status).toHaveBeenCalledWith(500);
|
|
585
|
-
});
|
|
586
|
-
(0, bun_test_1.it)("forwards non-APIError errors to next", function () {
|
|
587
|
-
var err = new Error("not an api error");
|
|
588
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
589
|
-
(0, bun_test_1.expect)(next).toHaveBeenCalledWith(err);
|
|
590
|
-
(0, bun_test_1.expect)(res.status).not.toHaveBeenCalled();
|
|
591
|
-
});
|
|
592
|
-
(0, bun_test_1.it)("converts Mongoose CastError to a 400 APIError response", function () {
|
|
593
|
-
var err = new mongoose_1.default.Error.CastError("Number", "not-a-number", "general.maxUploadSizeMb");
|
|
594
|
-
(0, errors_1.apiErrorMiddleware)(err, req, res, next);
|
|
595
|
-
(0, bun_test_1.expect)(res.status).toHaveBeenCalledWith(400);
|
|
596
|
-
(0, bun_test_1.expect)(res.json).toHaveBeenCalledWith(bun_test_1.expect.objectContaining({
|
|
597
|
-
meta: bun_test_1.expect.objectContaining({
|
|
598
|
-
fields: bun_test_1.expect.objectContaining({
|
|
599
|
-
"general.maxUploadSizeMb": bun_test_1.expect.stringContaining("Expected Number"),
|
|
600
|
-
}),
|
|
601
|
-
}),
|
|
602
|
-
status: 400,
|
|
603
|
-
title: "Validation failed",
|
|
604
|
-
}));
|
|
605
|
-
(0, bun_test_1.expect)(next).not.toHaveBeenCalled();
|
|
606
|
-
});
|
|
607
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|