@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/api.errors.test.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
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);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
// noExplicitAny: test mock typing
|
|
43
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
44
|
-
var bun_test_1 = require("bun:test");
|
|
45
|
-
var mongoose_1 = __importDefault(require("mongoose"));
|
|
46
|
-
var errors_1 = require("./errors");
|
|
47
|
-
(0, bun_test_1.describe)("errors module", function () {
|
|
48
|
-
(0, bun_test_1.describe)("APIError", function () {
|
|
49
|
-
(0, bun_test_1.it)("sets default status to 500 when not provided", function () {
|
|
50
|
-
var error = new errors_1.APIError({ title: "Test error" });
|
|
51
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
52
|
-
});
|
|
53
|
-
(0, bun_test_1.it)("sets status to 500 for invalid status codes below 400", function () {
|
|
54
|
-
var error = new errors_1.APIError({ status: 200, title: "Test error" });
|
|
55
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
56
|
-
});
|
|
57
|
-
(0, bun_test_1.it)("sets status to 500 for invalid status codes above 599", function () {
|
|
58
|
-
var error = new errors_1.APIError({ status: 600, title: "Test error" });
|
|
59
|
-
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
60
|
-
});
|
|
61
|
-
(0, bun_test_1.it)("exposes a wrapped error as the cause, keeping the message stable", function () {
|
|
62
|
-
var originalError = new Error("Original error");
|
|
63
|
-
var apiError = new errors_1.APIError({
|
|
64
|
-
error: originalError,
|
|
65
|
-
title: "Wrapped error",
|
|
66
|
-
});
|
|
67
|
-
(0, bun_test_1.expect)(apiError.message).toBe("Wrapped error");
|
|
68
|
-
(0, bun_test_1.expect)(apiError.cause).toBe(originalError);
|
|
69
|
-
});
|
|
70
|
-
(0, bun_test_1.it)("keeps detail out of the message", function () {
|
|
71
|
-
var error = new errors_1.APIError({
|
|
72
|
-
detail: "More details here",
|
|
73
|
-
title: "Test error",
|
|
74
|
-
});
|
|
75
|
-
(0, bun_test_1.expect)(error.message).toBe("Test error");
|
|
76
|
-
(0, bun_test_1.expect)(error.detail).toBe("More details here");
|
|
77
|
-
});
|
|
78
|
-
(0, bun_test_1.it)("sets fields in meta when provided", function () {
|
|
79
|
-
var _a;
|
|
80
|
-
var error = new errors_1.APIError({
|
|
81
|
-
fields: { email: "Invalid email format" },
|
|
82
|
-
title: "Validation error",
|
|
83
|
-
});
|
|
84
|
-
(0, bun_test_1.expect)((_a = error.meta) === null || _a === void 0 ? void 0 : _a.fields).toEqual({ email: "Invalid email format" });
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
(0, bun_test_1.describe)("errorsPlugin", function () {
|
|
88
|
-
(0, bun_test_1.it)("adds apiErrors field to schema", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
-
var testSchema;
|
|
90
|
-
return __generator(this, function (_a) {
|
|
91
|
-
testSchema = new mongoose_1.default.Schema({ name: String });
|
|
92
|
-
(0, errors_1.errorsPlugin)(testSchema);
|
|
93
|
-
(0, bun_test_1.expect)(testSchema.path("apiErrors")).toBeDefined();
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
});
|
|
96
|
-
}); });
|
|
97
|
-
});
|
|
98
|
-
(0, bun_test_1.describe)("isAPIError", function () {
|
|
99
|
-
(0, bun_test_1.it)("returns true for APIError instances", function () {
|
|
100
|
-
var error = new errors_1.APIError({ title: "Test" });
|
|
101
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(error)).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
(0, bun_test_1.it)("returns false for regular Error instances", function () {
|
|
104
|
-
var error = new Error("Test");
|
|
105
|
-
(0, bun_test_1.expect)((0, errors_1.isAPIError)(error)).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
(0, bun_test_1.describe)("getDisableExternalErrorTracking", function () {
|
|
109
|
-
(0, bun_test_1.it)("returns undefined for non-objects", function () {
|
|
110
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(null)).toBeUndefined();
|
|
111
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)("string")).toBeUndefined();
|
|
112
|
-
});
|
|
113
|
-
(0, bun_test_1.it)("returns value from APIError", function () {
|
|
114
|
-
var error = new errors_1.APIError({ disableExternalErrorTracking: true, title: "Test" });
|
|
115
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(error)).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
(0, bun_test_1.it)("returns value from plain object with property", function () {
|
|
118
|
-
var obj = { disableExternalErrorTracking: true };
|
|
119
|
-
(0, bun_test_1.expect)((0, errors_1.getDisableExternalErrorTracking)(obj)).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
(0, bun_test_1.describe)("getAPIErrorBody", function () {
|
|
123
|
-
(0, bun_test_1.it)("includes all non-undefined fields", function () {
|
|
124
|
-
var error = new errors_1.APIError({
|
|
125
|
-
code: "TEST_CODE",
|
|
126
|
-
detail: "Test detail",
|
|
127
|
-
id: "error-123",
|
|
128
|
-
links: { about: "http://example.com" },
|
|
129
|
-
meta: { extra: "data" },
|
|
130
|
-
source: { parameter: "id" },
|
|
131
|
-
status: 400,
|
|
132
|
-
title: "Test error",
|
|
133
|
-
});
|
|
134
|
-
var body = (0, errors_1.getAPIErrorBody)(error);
|
|
135
|
-
(0, bun_test_1.expect)(body.title).toBe("Test error");
|
|
136
|
-
(0, bun_test_1.expect)(body.status).toBe(400);
|
|
137
|
-
(0, bun_test_1.expect)(body.code).toBe("TEST_CODE");
|
|
138
|
-
(0, bun_test_1.expect)(body.detail).toBe("Test detail");
|
|
139
|
-
(0, bun_test_1.expect)(body.id).toBe("error-123");
|
|
140
|
-
(0, bun_test_1.expect)(body.links).toEqual({ about: "http://example.com" });
|
|
141
|
-
(0, bun_test_1.expect)(body.source).toEqual({ parameter: "id" });
|
|
142
|
-
(0, bun_test_1.expect)(body.meta).toEqual({ extra: "data" });
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
(0, bun_test_1.describe)("apiUnauthorizedMiddleware", function () {
|
|
146
|
-
(0, bun_test_1.it)("returns 401 for Unauthorized errors", function () {
|
|
147
|
-
var err = new Error("Unauthorized");
|
|
148
|
-
var res = {
|
|
149
|
-
json: function (data) {
|
|
150
|
-
this.body = data;
|
|
151
|
-
return this;
|
|
152
|
-
},
|
|
153
|
-
send: function () {
|
|
154
|
-
return this;
|
|
155
|
-
},
|
|
156
|
-
status: function (code) {
|
|
157
|
-
this.statusCode = code;
|
|
158
|
-
return this;
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
var next = function () { };
|
|
162
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, {}, res, next);
|
|
163
|
-
(0, bun_test_1.expect)(res.statusCode).toBe(401);
|
|
164
|
-
(0, bun_test_1.expect)(res.body.title).toBe("Unauthorized");
|
|
165
|
-
});
|
|
166
|
-
(0, bun_test_1.it)("calls next for non-Unauthorized errors", function () {
|
|
167
|
-
var err = new Error("Some other error");
|
|
168
|
-
var nextCalled = false;
|
|
169
|
-
var next = function () {
|
|
170
|
-
nextCalled = true;
|
|
171
|
-
};
|
|
172
|
-
(0, errors_1.apiUnauthorizedMiddleware)(err, {}, {}, next);
|
|
173
|
-
(0, bun_test_1.expect)(nextCalled).toBe(true);
|
|
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
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
package/dist/api.hooks.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|