@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 {};
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
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);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
var bun_test_1 = require("bun:test");
|
|
54
|
-
var promises_1 = require("node:fs/promises");
|
|
55
|
-
var node_net_1 = __importDefault(require("node:net"));
|
|
56
|
-
var node_os_1 = __importDefault(require("node:os"));
|
|
57
|
-
var node_path_1 = __importDefault(require("node:path"));
|
|
58
|
-
/**
|
|
59
|
-
* Regression test: auth failures must stay 401s inside `bun build --compile`
|
|
60
|
-
* binaries.
|
|
61
|
-
*
|
|
62
|
-
* passport's internal AuthenticationError calls `Error.captureStackTrace(this,
|
|
63
|
-
* arguments.callee)`. Bundling into a single-file executable puts that CJS
|
|
64
|
-
* code in strict-mode context, where touching `arguments.callee` throws a
|
|
65
|
-
* TypeError — so with `failWithError: true`, every unauthenticated request
|
|
66
|
-
* used to 500 instead of 401 (while behaving fine under plain `bun run`).
|
|
67
|
-
* authenticateMiddleware therefore must never route failures through
|
|
68
|
-
* passport's error class.
|
|
69
|
-
*
|
|
70
|
-
* This compiles a real fixture server (src/tests/fixtures/compileAuthEntry.ts)
|
|
71
|
-
* and asserts the 401 contract against the running binary.
|
|
72
|
-
*/
|
|
73
|
-
/** Grab an OS-assigned free port, then release it for the fixture binary. */
|
|
74
|
-
var findFreePort = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
77
|
-
var server = node_net_1.default.createServer();
|
|
78
|
-
server.listen(0, function () {
|
|
79
|
-
var address = server.address();
|
|
80
|
-
if (!address || typeof address === "string") {
|
|
81
|
-
server.close();
|
|
82
|
-
reject(new Error("Failed to allocate a port"));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
var port = address.port;
|
|
86
|
-
server.close(function () { return resolve(port); });
|
|
87
|
-
});
|
|
88
|
-
server.on("error", reject);
|
|
89
|
-
})];
|
|
90
|
-
});
|
|
91
|
-
}); };
|
|
92
|
-
(0, bun_test_1.describe)("authenticateMiddleware inside a bun-compiled binary", function () {
|
|
93
|
-
var tmpDir;
|
|
94
|
-
var child = null;
|
|
95
|
-
var baseUrl;
|
|
96
|
-
(0, bun_test_1.beforeAll)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var binaryPath, entryPath, build, buildExit, _a, _b, port, deadline, _c;
|
|
98
|
-
return __generator(this, function (_d) {
|
|
99
|
-
switch (_d.label) {
|
|
100
|
-
case 0: return [4 /*yield*/, (0, promises_1.mkdtemp)(node_path_1.default.join(node_os_1.default.tmpdir(), "terreno-compile-auth-"))];
|
|
101
|
-
case 1:
|
|
102
|
-
tmpDir = _d.sent();
|
|
103
|
-
binaryPath = node_path_1.default.join(tmpDir, "compile-auth-server");
|
|
104
|
-
entryPath = node_path_1.default.join(__dirname, "tests/fixtures/compileAuthEntry.ts");
|
|
105
|
-
build = Bun.spawn(["bun", "build", "--compile", entryPath, "--outfile", binaryPath], {
|
|
106
|
-
cwd: __dirname,
|
|
107
|
-
stderr: "pipe",
|
|
108
|
-
stdout: "pipe",
|
|
109
|
-
});
|
|
110
|
-
return [4 /*yield*/, build.exited];
|
|
111
|
-
case 2:
|
|
112
|
-
buildExit = _d.sent();
|
|
113
|
-
if (!(buildExit !== 0)) return [3 /*break*/, 4];
|
|
114
|
-
_a = Error.bind;
|
|
115
|
-
_b = "bun build --compile failed: ".concat;
|
|
116
|
-
return [4 /*yield*/, new Response(build.stderr).text()];
|
|
117
|
-
case 3: throw new (_a.apply(Error, [void 0, _b.apply("bun build --compile failed: ", [_d.sent()])]))();
|
|
118
|
-
case 4: return [4 /*yield*/, findFreePort()];
|
|
119
|
-
case 5:
|
|
120
|
-
port = _d.sent();
|
|
121
|
-
baseUrl = "http://127.0.0.1:".concat(port);
|
|
122
|
-
child = Bun.spawn([binaryPath], {
|
|
123
|
-
env: __assign(__assign({}, process.env), { PORT: String(port) }),
|
|
124
|
-
stderr: "inherit",
|
|
125
|
-
stdout: "inherit",
|
|
126
|
-
});
|
|
127
|
-
deadline = Date.now() + 15000;
|
|
128
|
-
_d.label = 6;
|
|
129
|
-
case 6:
|
|
130
|
-
_d.trys.push([6, 8, , 10]);
|
|
131
|
-
return [4 /*yield*/, fetch("".concat(baseUrl, "/secure"))];
|
|
132
|
-
case 7:
|
|
133
|
-
_d.sent();
|
|
134
|
-
return [3 /*break*/, 11];
|
|
135
|
-
case 8:
|
|
136
|
-
_c = _d.sent();
|
|
137
|
-
if (child.exitCode !== null) {
|
|
138
|
-
throw new Error("fixture server exited with code ".concat(child.exitCode));
|
|
139
|
-
}
|
|
140
|
-
if (Date.now() > deadline) {
|
|
141
|
-
throw new Error("fixture server never became reachable");
|
|
142
|
-
}
|
|
143
|
-
return [4 /*yield*/, Bun.sleep(100)];
|
|
144
|
-
case 9:
|
|
145
|
-
_d.sent();
|
|
146
|
-
return [3 /*break*/, 10];
|
|
147
|
-
case 10: return [3 /*break*/, 6];
|
|
148
|
-
case 11: return [2 /*return*/];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}); }, 120000);
|
|
152
|
-
(0, bun_test_1.afterAll)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (_a.label) {
|
|
155
|
-
case 0:
|
|
156
|
-
child === null || child === void 0 ? void 0 : child.kill();
|
|
157
|
-
return [4 /*yield*/, (child === null || child === void 0 ? void 0 : child.exited)];
|
|
158
|
-
case 1:
|
|
159
|
-
_a.sent();
|
|
160
|
-
return [4 /*yield*/, (0, promises_1.rm)(tmpDir, { force: true, recursive: true })];
|
|
161
|
-
case 2:
|
|
162
|
-
_a.sent();
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); });
|
|
167
|
-
(0, bun_test_1.it)("returns 401 (not 500) for a request with no token", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
-
var res, _a;
|
|
169
|
-
return __generator(this, function (_b) {
|
|
170
|
-
switch (_b.label) {
|
|
171
|
-
case 0: return [4 /*yield*/, fetch("".concat(baseUrl, "/secure"))];
|
|
172
|
-
case 1:
|
|
173
|
-
res = _b.sent();
|
|
174
|
-
(0, bun_test_1.expect)(res.status).toBe(401);
|
|
175
|
-
_a = bun_test_1.expect;
|
|
176
|
-
return [4 /*yield*/, res.json()];
|
|
177
|
-
case 2:
|
|
178
|
-
_a.apply(void 0, [_b.sent()]).toEqual({ status: 401, title: "Unauthorized" });
|
|
179
|
-
return [2 /*return*/];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}); });
|
|
183
|
-
(0, bun_test_1.it)("returns 401 (not 500) for a request with an invalid token", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
-
var res, _a;
|
|
185
|
-
return __generator(this, function (_b) {
|
|
186
|
-
switch (_b.label) {
|
|
187
|
-
case 0: return [4 /*yield*/, fetch("".concat(baseUrl, "/secure"), {
|
|
188
|
-
headers: { Authorization: "Bearer not-a-real-jwt" },
|
|
189
|
-
})];
|
|
190
|
-
case 1:
|
|
191
|
-
res = _b.sent();
|
|
192
|
-
(0, bun_test_1.expect)(res.status).toBe(401);
|
|
193
|
-
_a = bun_test_1.expect;
|
|
194
|
-
return [4 /*yield*/, res.json()];
|
|
195
|
-
case 2:
|
|
196
|
-
_a.apply(void 0, [_b.sent()]).toEqual({ status: 401, title: "Unauthorized" });
|
|
197
|
-
return [2 /*return*/];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}); });
|
|
201
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
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);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
var bun_test_1 = require("bun:test");
|
|
54
|
-
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
55
|
-
var supertest_1 = __importDefault(require("supertest"));
|
|
56
|
-
var auth_1 = require("./auth");
|
|
57
|
-
var tests_1 = require("./tests");
|
|
58
|
-
var testUserModel = tests_1.UserModel;
|
|
59
|
-
var signTokenForId = function (id) {
|
|
60
|
-
return jsonwebtoken_1.default.sign({ id: id }, process.env.TOKEN_SECRET, { issuer: process.env.TOKEN_ISSUER });
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Builds a stand-in UserModel that reuses the real passport strategy but lets each test
|
|
64
|
-
* control what `findById` resolves to.
|
|
65
|
-
*/
|
|
66
|
-
var createStubUserModel = function (overrides) {
|
|
67
|
-
return __assign({ createStrategy: function () { return testUserModel.createStrategy(); }, findById: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
68
|
-
return [2 /*return*/, null];
|
|
69
|
-
}); }); } }, overrides);
|
|
70
|
-
};
|
|
71
|
-
(0, bun_test_1.describe)("setupAuth token extraction", function () {
|
|
72
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
(0, bun_test_1.setSystemTime)();
|
|
77
|
-
return [4 /*yield*/, (0, tests_1.setupTestData)()];
|
|
78
|
-
case 1:
|
|
79
|
-
_a.sent();
|
|
80
|
-
return [2 /*return*/];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}); });
|
|
84
|
-
(0, bun_test_1.it)("reads the token from the jwt cookie when no authorization header is present", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
|
-
var app, admin, token, res;
|
|
86
|
-
return __generator(this, function (_a) {
|
|
87
|
-
switch (_a.label) {
|
|
88
|
-
case 0:
|
|
89
|
-
app = (0, tests_1.getBaseServer)();
|
|
90
|
-
return [4 /*yield*/, tests_1.UserModel.findOne({ email: "admin@example.com" })];
|
|
91
|
-
case 1:
|
|
92
|
-
admin = _a.sent();
|
|
93
|
-
token = signTokenForId(String(admin === null || admin === void 0 ? void 0 : admin._id));
|
|
94
|
-
// Emulate cookie-parser, which consumers mount before setupAuth.
|
|
95
|
-
app.use(function (req, _res, next) {
|
|
96
|
-
req.cookies = { jwt: token };
|
|
97
|
-
next();
|
|
98
|
-
});
|
|
99
|
-
(0, auth_1.setupAuth)(app, testUserModel);
|
|
100
|
-
(0, auth_1.addMeRoutes)(app, testUserModel);
|
|
101
|
-
return [4 /*yield*/, supertest_1.default.agent(app).get("/auth/me").expect(200)];
|
|
102
|
-
case 2:
|
|
103
|
-
res = _a.sent();
|
|
104
|
-
(0, bun_test_1.expect)(res.body.data.email).toBe("admin@example.com");
|
|
105
|
-
return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}); });
|
|
109
|
-
(0, bun_test_1.it)("logs the JWT setup message when not running in test mode", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
110
|
-
var app, res;
|
|
111
|
-
return __generator(this, function (_a) {
|
|
112
|
-
switch (_a.label) {
|
|
113
|
-
case 0:
|
|
114
|
-
app = (0, tests_1.getBaseServer)();
|
|
115
|
-
process.env.NODE_ENV = "development";
|
|
116
|
-
_a.label = 1;
|
|
117
|
-
case 1:
|
|
118
|
-
_a.trys.push([1, , 3, 4]);
|
|
119
|
-
(0, auth_1.setupAuth)(app, testUserModel);
|
|
120
|
-
(0, auth_1.addAuthRoutes)(app, testUserModel);
|
|
121
|
-
(0, auth_1.addMeRoutes)(app, testUserModel);
|
|
122
|
-
return [4 /*yield*/, supertest_1.default
|
|
123
|
-
.agent(app)
|
|
124
|
-
.post("/auth/login")
|
|
125
|
-
.send({ email: "admin@example.com", password: "securePassword" })
|
|
126
|
-
.expect(200)];
|
|
127
|
-
case 2:
|
|
128
|
-
res = _a.sent();
|
|
129
|
-
(0, bun_test_1.expect)(res.body.data.token).toBeDefined();
|
|
130
|
-
return [3 /*break*/, 4];
|
|
131
|
-
case 3:
|
|
132
|
-
process.env.NODE_ENV = "test";
|
|
133
|
-
return [7 /*endfinally*/];
|
|
134
|
-
case 4: return [2 /*return*/];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}); });
|
|
138
|
-
});
|
|
139
|
-
(0, bun_test_1.describe)("addMeRoutes without a resolvable user", function () {
|
|
140
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
-
return __generator(this, function (_a) {
|
|
142
|
-
switch (_a.label) {
|
|
143
|
-
case 0:
|
|
144
|
-
(0, bun_test_1.setSystemTime)();
|
|
145
|
-
return [4 /*yield*/, (0, tests_1.setupTestData)()];
|
|
146
|
-
case 1:
|
|
147
|
-
_a.sent();
|
|
148
|
-
return [2 /*return*/];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}); });
|
|
152
|
-
(0, bun_test_1.it)("returns 401 when the authenticated user has no id", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
-
var app, anonymousModel, agent;
|
|
154
|
-
return __generator(this, function (_a) {
|
|
155
|
-
switch (_a.label) {
|
|
156
|
-
case 0:
|
|
157
|
-
app = (0, tests_1.getBaseServer)();
|
|
158
|
-
anonymousModel = createStubUserModel({
|
|
159
|
-
createAnonymousUser: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
160
|
-
return [2 /*return*/, ({})];
|
|
161
|
-
}); }); },
|
|
162
|
-
});
|
|
163
|
-
(0, auth_1.setupAuth)(app, anonymousModel);
|
|
164
|
-
(0, auth_1.addMeRoutes)(app, anonymousModel);
|
|
165
|
-
agent = supertest_1.default
|
|
166
|
-
.agent(app)
|
|
167
|
-
.set("authorization", "Bearer ".concat(signTokenForId("507f1f77bcf86cd799439011")));
|
|
168
|
-
return [4 /*yield*/, agent.get("/auth/me").expect(401)];
|
|
169
|
-
case 1:
|
|
170
|
-
_a.sent();
|
|
171
|
-
return [4 /*yield*/, agent.patch("/auth/me").send({ name: "New Name" }).expect(401)];
|
|
172
|
-
case 2:
|
|
173
|
-
_a.sent();
|
|
174
|
-
return [2 /*return*/];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}); });
|
|
178
|
-
(0, bun_test_1.it)("returns 404 when the user cannot be found for the me routes", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
179
|
-
var app, admin, agent;
|
|
180
|
-
return __generator(this, function (_a) {
|
|
181
|
-
switch (_a.label) {
|
|
182
|
-
case 0:
|
|
183
|
-
app = (0, tests_1.getBaseServer)();
|
|
184
|
-
return [4 /*yield*/, tests_1.UserModel.findOne({ email: "admin@example.com" })];
|
|
185
|
-
case 1:
|
|
186
|
-
admin = _a.sent();
|
|
187
|
-
(0, auth_1.setupAuth)(app, testUserModel);
|
|
188
|
-
(0, auth_1.addMeRoutes)(app, createStubUserModel({}));
|
|
189
|
-
agent = supertest_1.default
|
|
190
|
-
.agent(app)
|
|
191
|
-
.set("authorization", "Bearer ".concat(signTokenForId(String(admin === null || admin === void 0 ? void 0 : admin._id))));
|
|
192
|
-
return [4 /*yield*/, agent.get("/auth/me").expect(404)];
|
|
193
|
-
case 2:
|
|
194
|
-
_a.sent();
|
|
195
|
-
return [4 /*yield*/, agent.patch("/auth/me").send({ name: "New Name" }).expect(404)];
|
|
196
|
-
case 3:
|
|
197
|
-
_a.sent();
|
|
198
|
-
return [2 /*return*/];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}); });
|
|
202
|
-
});
|
package/dist/auth.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|