@proteinjs/user-server 1.24.2 → 1.24.4
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 +22 -0
- package/dist/src/routes/devLogin.d.ts +9 -5
- package/dist/src/routes/devLogin.d.ts.map +1 -1
- package/dist/src/routes/devLogin.js +30 -22
- package/dist/src/routes/devLogin.js.map +1 -1
- package/dist/test/DevLogin.test.js +75 -0
- package/dist/test/DevLogin.test.js.map +1 -1
- package/dist/test/PublicDeclarationSurface.test.js +75 -7
- package/dist/test/PublicDeclarationSurface.test.js.map +1 -1
- package/package.json +3 -3
- package/src/routes/devLogin.ts +34 -20
- package/test/DevLogin.test.ts +40 -0
- package/test/PublicDeclarationSurface.test.ts +93 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.24.4](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.3...@proteinjs/user-server@1.24.4) (2026-10-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **dev-login:** an existing account signs in as it stands; the door creates only a missing one ([fbdd545](https://github.com/proteinjs/user/commit/fbdd545aaddc89d23aaf2a31cdcc3a916b6a3d74))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.24.3](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.2...@proteinjs/user-server@1.24.3) (2026-10-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **user-server:** the public declarations resolve their types from the declared dependencies ([e42e2c7](https://github.com/proteinjs/user/commit/e42e2c7db7c8e09b6992490f0ed54bae30560156))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [1.24.2](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.1...@proteinjs/user-server@1.24.2) (2026-10-03)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -18,11 +18,15 @@ import { Route } from '@proteinjs/server-api';
|
|
|
18
18
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
19
19
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
22
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
23
|
+
* involved). A missing account is created through the normal signup creation path
|
|
24
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
25
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
26
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
27
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
28
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
29
|
+
* real account from the start.
|
|
26
30
|
*
|
|
27
31
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
28
32
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAiB9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,QAAQ,EAAE,KA+EtB,CAAC"}
|
|
@@ -37,7 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.devLogin = void 0;
|
|
40
|
+
var db_1 = require("@proteinjs/db");
|
|
40
41
|
var logger_1 = require("@proteinjs/logger");
|
|
42
|
+
var user_1 = require("@proteinjs/user");
|
|
41
43
|
var util_node_1 = require("@proteinjs/util-node");
|
|
42
44
|
var util_1 = require("@proteinjs/util");
|
|
43
45
|
var establishSession_1 = require("../authentication/establishSession");
|
|
@@ -67,11 +69,15 @@ var emailDomain = function (address) { return address.slice(address.lastIndexOf(
|
|
|
67
69
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
68
70
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
69
71
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
73
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
74
|
+
* involved). A missing account is created through the normal signup creation path
|
|
75
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
76
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
77
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
78
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
79
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
80
|
+
* real account from the start.
|
|
75
81
|
*
|
|
76
82
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
77
83
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -127,9 +133,13 @@ exports.devLogin = {
|
|
|
127
133
|
}
|
|
128
134
|
email = email.toLowerCase();
|
|
129
135
|
digests = new util_node_1.RequestDigests();
|
|
130
|
-
|
|
136
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.User, { email: email })];
|
|
131
137
|
case 1:
|
|
132
|
-
_d.
|
|
138
|
+
if (!_d.sent()) return [3 /*break*/, 2];
|
|
139
|
+
creation = 'exists';
|
|
140
|
+
return [3 /*break*/, 5];
|
|
141
|
+
case 2:
|
|
142
|
+
_d.trys.push([2, 4, , 5]);
|
|
133
143
|
return [4 /*yield*/, new Signup_1.Signup().createAccount({
|
|
134
144
|
name: email.slice(0, email.indexOf('@')),
|
|
135
145
|
email: email,
|
|
@@ -137,41 +147,39 @@ exports.devLogin = {
|
|
|
137
147
|
emailVerified: false,
|
|
138
148
|
invitedBy: null,
|
|
139
149
|
})];
|
|
140
|
-
case 2:
|
|
141
|
-
creation = _d.sent();
|
|
142
|
-
return [3 /*break*/, 4];
|
|
143
150
|
case 3:
|
|
151
|
+
creation = _d.sent();
|
|
152
|
+
return [3 /*break*/, 5];
|
|
153
|
+
case 4:
|
|
144
154
|
error_1 = _d.sent();
|
|
145
|
-
// createAccount refuses in plain words (an address a machine-account declaration owns); the
|
|
146
|
-
// dev door answers the way its other refusals do — the words, no session, no row.
|
|
147
155
|
response
|
|
148
156
|
.status(400)
|
|
149
157
|
.send("/dev/login: ".concat(error_1 instanceof Error ? error_1.message : 'the account could not be created'));
|
|
150
158
|
return [2 /*return*/];
|
|
151
|
-
case
|
|
159
|
+
case 5:
|
|
152
160
|
if (creation === 'created') {
|
|
153
161
|
logger.info({ message: 'Dev auto-login created missing test account', obj: { account: digests.account(email) } });
|
|
154
162
|
}
|
|
155
163
|
bootstrapEmail = ((_c = process.env.DEV_BOOTSTRAP_ADMIN_EMAIL) !== null && _c !== void 0 ? _c : '').trim().toLowerCase();
|
|
156
|
-
if (!(bootstrapEmail && email === bootstrapEmail)) return [3 /*break*/,
|
|
164
|
+
if (!(bootstrapEmail && email === bootstrapEmail)) return [3 /*break*/, 7];
|
|
157
165
|
return [4 /*yield*/, new Roles_1.Roles().bootstrapAdmin(email)];
|
|
158
|
-
case
|
|
166
|
+
case 6:
|
|
159
167
|
outcome = _d.sent();
|
|
160
168
|
logger.info({ message: "Dev bootstrap admin door: ".concat(outcome), obj: { account: digests.account(email) } });
|
|
161
|
-
_d.label =
|
|
162
|
-
case
|
|
169
|
+
_d.label = 7;
|
|
170
|
+
case 7:
|
|
163
171
|
bootstrapRoles = DevBootstrapRoles_1.DevBootstrapRoles.rolesFor(email);
|
|
164
|
-
if (!(bootstrapRoles.length > 0)) return [3 /*break*/,
|
|
172
|
+
if (!(bootstrapRoles.length > 0)) return [3 /*break*/, 9];
|
|
165
173
|
return [4 /*yield*/, new Roles_1.Roles().bootstrapRoles(email, bootstrapRoles)];
|
|
166
|
-
case
|
|
174
|
+
case 8:
|
|
167
175
|
outcome = _d.sent();
|
|
168
176
|
logger.info({ message: DevBootstrapRoles_1.DevBootstrapRoles.markerLine(email, outcome) });
|
|
169
|
-
_d.label =
|
|
170
|
-
case
|
|
177
|
+
_d.label = 9;
|
|
178
|
+
case 9:
|
|
171
179
|
// establishSession commits the session row before the redirect — the redirected GET / must
|
|
172
180
|
// never read the store ahead of the write (observed: first /dev/login load landed on /login).
|
|
173
181
|
return [4 /*yield*/, (0, establishSession_1.establishSession)(request, email)];
|
|
174
|
-
case
|
|
182
|
+
case 10:
|
|
175
183
|
// establishSession commits the session row before the redirect — the redirected GET / must
|
|
176
184
|
// never read the store ahead of the write (observed: first /dev/login load landed on /login).
|
|
177
185
|
_d.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devLogin.js","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA2C;AAC3C,k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;oBAAjE,OAAO,GAAG,SAAuD;oBACvE,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qCAAiB,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;;;gBAGzE,2FAA2F;gBAC3F,8FAA8F;gBAC9F,qBAAM,IAAA,mCAAgB,EAAC,OAAO,EAAE,KAAK,CAAC,EAAA;;oBAFtC,2FAA2F;oBAC3F,8FAA8F;oBAC9F,SAAsC,CAAC;oBACvC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,oCAAoC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;oBACzG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;;;;SACxB;CACF,CAAC"}
|
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -258,6 +269,70 @@ describe('devLogin route', function () {
|
|
|
258
269
|
}
|
|
259
270
|
});
|
|
260
271
|
}); });
|
|
272
|
+
it('establishes a session for a declared machine account whose row the boot sync made — the door creates nothing, the account signs in as it stands', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
273
|
+
var SyncedMachineAccount, declaration, repo, outcome, row;
|
|
274
|
+
var _a;
|
|
275
|
+
return __generator(this, function (_b) {
|
|
276
|
+
switch (_b.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
SyncedMachineAccount = /** @class */ (function (_super) {
|
|
279
|
+
__extends(SyncedMachineAccount, _super);
|
|
280
|
+
// The dev door exists so automated dev-loop testing can self-serve a session for any account of
|
|
281
|
+
// the build — a declared machine account's included, once the boot sync has created its row. The
|
|
282
|
+
// door never CREATES one (the case above); an existing row is signed in like any other account's.
|
|
283
|
+
function SyncedMachineAccount() {
|
|
284
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
285
|
+
_this.id = 'synced-machine';
|
|
286
|
+
_this.email = 'synced.machine@test.local';
|
|
287
|
+
_this.accountName = 'Synced machine';
|
|
288
|
+
_this.roles = [];
|
|
289
|
+
_this.secretName = 'synced-machine-secret';
|
|
290
|
+
return _this;
|
|
291
|
+
}
|
|
292
|
+
return SyncedMachineAccount;
|
|
293
|
+
}(user_1.MachineAccount));
|
|
294
|
+
declaration = new SyncedMachineAccount();
|
|
295
|
+
repo = reflection_1.SourceRepository.get();
|
|
296
|
+
repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'] = [
|
|
297
|
+
{
|
|
298
|
+
qualifiedName: '@proteinjs/user-server-test/SyncedMachineAccount',
|
|
299
|
+
packageName: '@test/declarer',
|
|
300
|
+
object: declaration,
|
|
301
|
+
},
|
|
302
|
+
];
|
|
303
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
304
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().insert(user_1.tables.User, __assign(__assign({}, declaration.record), { isLoadedFromSource: true }))];
|
|
305
|
+
case 1:
|
|
306
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
307
|
+
_b.sent();
|
|
308
|
+
_b.label = 2;
|
|
309
|
+
case 2:
|
|
310
|
+
_b.trys.push([2, , 5, 7]);
|
|
311
|
+
return [4 /*yield*/, (0, devLoginHarness_1.invokeDevLogin)({ email: declaration.email })];
|
|
312
|
+
case 3:
|
|
313
|
+
outcome = _b.sent();
|
|
314
|
+
expect(outcome.status).toBeUndefined();
|
|
315
|
+
expect(outcome.redirect).toBe('/');
|
|
316
|
+
expect(outcome.loggedInAs).toBe(declaration.email);
|
|
317
|
+
expect(outcome.sessionRegenerated).toBe(true);
|
|
318
|
+
expect(outcome.sessionSaved).toBe(true);
|
|
319
|
+
return [4 /*yield*/, getUserRow(declaration.email)];
|
|
320
|
+
case 4:
|
|
321
|
+
row = _b.sent();
|
|
322
|
+
expect(row === null || row === void 0 ? void 0 : row.machine).toBe(true);
|
|
323
|
+
expect(row === null || row === void 0 ? void 0 : row.isLoadedFromSource).toBe(true);
|
|
324
|
+
expect((_a = row === null || row === void 0 ? void 0 : row.password) !== null && _a !== void 0 ? _a : null).toBeNull();
|
|
325
|
+
return [3 /*break*/, 7];
|
|
326
|
+
case 5:
|
|
327
|
+
delete repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'];
|
|
328
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().delete(user_1.tables.User, { email: declaration.email })];
|
|
329
|
+
case 6:
|
|
330
|
+
_b.sent();
|
|
331
|
+
return [7 /*endfinally*/];
|
|
332
|
+
case 7: return [2 /*return*/];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}); });
|
|
261
336
|
it('rejects a malformed same-domain ?email with 400 — no session, no stray account', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
262
337
|
var malformed, outcome, _a;
|
|
263
338
|
return __generator(this, function (_b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DevLogin.test.js","sourceRoot":"","sources":["../../test/DevLogin.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":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M,IAAA,gCAAc,EAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAAA;;oBAA9D,OAAO,GAAG,SAAoD;oBAEpE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACjC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;oBAC3C,KAAA,MAAM,CAAA;oBAAC,qBAAM,UAAU,CAAC,mBAAmB,CAAC,EAAA;;oBAA5C,kBAAO,SAAqC,EAAC,CAAC,aAAa,EAAE,CAAC;;;;SAC/D,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -37,12 +37,38 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
37
37
|
PublicDeclarationSurface.prototype.packageNames = function () {
|
|
38
38
|
return Array.from(new Set(this.imports.map(function (entry) { return entry.packageName; }))).sort();
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Where a specifier's declarations come from in this package's own tree — the resolution a
|
|
42
|
+
* consumer's compiler repeats from its own node_modules — or undefined when no declaration file
|
|
43
|
+
* answers it (a JavaScript-only package with no `@types` twin installed resolves to its `.js`).
|
|
44
|
+
*/
|
|
45
|
+
PublicDeclarationSurface.prototype.providerOf = function (entry) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
var from = path_1.default.resolve(this.packageDir, entry.file);
|
|
48
|
+
var specifier = entry.via === 'reference types' ? "@types/".concat(entry.specifier) : entry.specifier;
|
|
49
|
+
var resolvedModule = typescript_1.default.resolveModuleName(specifier, from, { moduleResolution: typescript_1.default.ModuleResolutionKind.Node10 }, typescript_1.default.sys).resolvedModule;
|
|
50
|
+
if (!resolvedModule || !PublicDeclarationSurface.DECLARATION_EXTENSIONS.has(resolvedModule.extension)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
var file = path_1.default.relative(this.packageDir, resolvedModule.resolvedFileName);
|
|
54
|
+
var packageName = (_b = (_a = resolvedModule.packageId) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : PublicDeclarationSurface.packageUnderNodeModules(file);
|
|
55
|
+
return packageName ? { packageName: packageName, file: file } : undefined;
|
|
56
|
+
};
|
|
40
57
|
/** `@scope/name/sub` -> `@scope/name`; `name/sub` -> `name`; `node:fs` -> `fs`. */
|
|
41
58
|
PublicDeclarationSurface.packageNameOf = function (specifier) {
|
|
42
59
|
var bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
|
|
43
60
|
var parts = bare.split('/');
|
|
44
61
|
return bare.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
45
62
|
};
|
|
63
|
+
/** The package a resolved file belongs to, read from its path's last `node_modules/` segment. */
|
|
64
|
+
PublicDeclarationSurface.packageUnderNodeModules = function (file) {
|
|
65
|
+
var segments = file.split(path_1.default.sep);
|
|
66
|
+
var at = segments.lastIndexOf('node_modules');
|
|
67
|
+
if (at < 0 || at + 1 >= segments.length) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return segments[at + 1].startsWith('@') ? segments.slice(at + 1, at + 3).join('/') : segments[at + 1];
|
|
71
|
+
};
|
|
46
72
|
PublicDeclarationSurface.prototype.walk = function (file) {
|
|
47
73
|
var _this = this;
|
|
48
74
|
if (this.seen.has(file)) {
|
|
@@ -60,7 +86,7 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
60
86
|
}
|
|
61
87
|
for (var _b = 0, _c = source.typeReferenceDirectives; _b < _c.length; _b++) {
|
|
62
88
|
var reference = _c[_b];
|
|
63
|
-
this.record(file, reference.fileName, 'reference types');
|
|
89
|
+
this.record(file, reference.fileName, 'reference types', true);
|
|
64
90
|
}
|
|
65
91
|
var visit = function (node) {
|
|
66
92
|
var specifier = _this.specifierOf(node);
|
|
@@ -69,7 +95,7 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
69
95
|
_this.walk(_this.declarationFileFor(file, specifier.text));
|
|
70
96
|
}
|
|
71
97
|
else {
|
|
72
|
-
_this.record(file, specifier.text, specifier.via);
|
|
98
|
+
_this.record(file, specifier.text, specifier.via, specifier.bindings);
|
|
73
99
|
}
|
|
74
100
|
}
|
|
75
101
|
typescript_1.default.forEachChild(node, visit);
|
|
@@ -77,25 +103,29 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
77
103
|
visit(source);
|
|
78
104
|
};
|
|
79
105
|
PublicDeclarationSurface.prototype.specifierOf = function (node) {
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
106
|
+
if (typescript_1.default.isImportDeclaration(node) && typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
107
|
+
return { text: node.moduleSpecifier.text, via: 'import', bindings: node.importClause !== undefined };
|
|
108
|
+
}
|
|
109
|
+
if (typescript_1.default.isExportDeclaration(node) && node.moduleSpecifier && typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
110
|
+
return { text: node.moduleSpecifier.text, via: 'import', bindings: true };
|
|
82
111
|
}
|
|
83
112
|
if (typescript_1.default.isImportEqualsDeclaration(node) && typescript_1.default.isExternalModuleReference(node.moduleReference)) {
|
|
84
113
|
var expression = node.moduleReference.expression;
|
|
85
|
-
return typescript_1.default.isStringLiteral(expression) ? { text: expression.text, via: 'import' } : undefined;
|
|
114
|
+
return typescript_1.default.isStringLiteral(expression) ? { text: expression.text, via: 'import', bindings: true } : undefined;
|
|
86
115
|
}
|
|
87
116
|
if (typescript_1.default.isImportTypeNode(node) && typescript_1.default.isLiteralTypeNode(node.argument)) {
|
|
88
117
|
var literal = node.argument.literal;
|
|
89
|
-
return typescript_1.default.isStringLiteral(literal) ? { text: literal.text, via: 'import()' } : undefined;
|
|
118
|
+
return typescript_1.default.isStringLiteral(literal) ? { text: literal.text, via: 'import()', bindings: true } : undefined;
|
|
90
119
|
}
|
|
91
120
|
return undefined;
|
|
92
121
|
};
|
|
93
|
-
PublicDeclarationSurface.prototype.record = function (file, specifier, via) {
|
|
122
|
+
PublicDeclarationSurface.prototype.record = function (file, specifier, via, bindings) {
|
|
94
123
|
this.imports.push({
|
|
95
124
|
specifier: specifier,
|
|
96
125
|
packageName: PublicDeclarationSurface.packageNameOf(specifier),
|
|
97
126
|
file: path_1.default.relative(this.packageDir, file),
|
|
98
127
|
via: via,
|
|
128
|
+
bindings: bindings,
|
|
99
129
|
});
|
|
100
130
|
};
|
|
101
131
|
/** A relative specifier's declaration file: `x.d.ts`, else `x/index.d.ts`; a `.d.ts` path as is. */
|
|
@@ -111,6 +141,15 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
111
141
|
}
|
|
112
142
|
return found;
|
|
113
143
|
};
|
|
144
|
+
PublicDeclarationSurface.DECLARATION_EXTENSIONS = new Set([
|
|
145
|
+
'.d.ts',
|
|
146
|
+
'.ts',
|
|
147
|
+
'.tsx',
|
|
148
|
+
'.d.mts',
|
|
149
|
+
'.mts',
|
|
150
|
+
'.d.cts',
|
|
151
|
+
'.cts',
|
|
152
|
+
]);
|
|
114
153
|
return PublicDeclarationSurface;
|
|
115
154
|
}());
|
|
116
155
|
/**
|
|
@@ -120,6 +159,13 @@ var PublicDeclarationSurface = /** @class */ (function () {
|
|
|
120
159
|
* same types whether its copy is installed from the registry (devDependencies absent) or linked
|
|
121
160
|
* from a checkout (devDependencies present), and the same whether or not a transitive package
|
|
122
161
|
* happens to hoist beside it.
|
|
162
|
+
*
|
|
163
|
+
* Two clauses, because a specifier and its declarations can come from different packages: the
|
|
164
|
+
* specifier's own package must be declared (the runtime import resolves for the consumer), AND the
|
|
165
|
+
* package whose declaration file answers it must be declared — a dependency that ships no
|
|
166
|
+
* declarations of its own (nodemailer) is typed by its `@types` twin, which is then part of the
|
|
167
|
+
* public surface and belongs beside it in `dependencies`, never in `devDependencies`. Node's
|
|
168
|
+
* builtins and the `node` types that declare them are the consumer's own environment.
|
|
123
169
|
*/
|
|
124
170
|
describe('the public declaration surface resolves against the declared dependencies alone', function () {
|
|
125
171
|
var _a, _b;
|
|
@@ -139,11 +185,15 @@ describe('the public declaration surface resolves against the declared dependenc
|
|
|
139
185
|
return builtins.has(entry.packageName) || (entry.via === 'reference types' && entry.packageName === 'node');
|
|
140
186
|
};
|
|
141
187
|
it('reads the whole surface from the types entry (the control: the walk sees files and their imports)', function () {
|
|
188
|
+
var _a;
|
|
142
189
|
var relativeFiles = surface.files.map(function (file) { return path_1.default.relative(PACKAGE_DIR, file); });
|
|
143
190
|
expect(relativeFiles).toContain(path_1.default.normalize('dist/index.d.ts'));
|
|
144
191
|
expect(relativeFiles).toContain(path_1.default.normalize('dist/src/emails/AccountDeletionEmailConfigs.d.ts'));
|
|
145
192
|
expect(relativeFiles.length).toBeGreaterThanOrEqual(10);
|
|
146
193
|
expect(surface.packageNames()).toEqual(expect.arrayContaining(['@proteinjs/reflection', '@proteinjs/user', 'moment']));
|
|
194
|
+
// The resolver half of the control: a package that ships its own declarations answers for itself.
|
|
195
|
+
var reflection = surface.imports.find(function (entry) { return entry.packageName === '@proteinjs/reflection'; });
|
|
196
|
+
expect(reflection && ((_a = surface.providerOf(reflection)) === null || _a === void 0 ? void 0 : _a.packageName)).toBe('@proteinjs/reflection');
|
|
147
197
|
});
|
|
148
198
|
it('names no package outside dependencies / peerDependencies / node builtins', function () {
|
|
149
199
|
var undeclared = surface.imports
|
|
@@ -153,5 +203,23 @@ describe('the public declaration surface resolves against the declared dependenc
|
|
|
153
203
|
});
|
|
154
204
|
expect(undeclared).toEqual([]);
|
|
155
205
|
});
|
|
206
|
+
it('resolves every declaration it names from a declared package (a dependency typed by its @types twin declares the twin too)', function () {
|
|
207
|
+
var untyped = surface.imports
|
|
208
|
+
.filter(function (entry) { return !isBuiltin(entry) && entry.bindings; })
|
|
209
|
+
.map(function (entry) {
|
|
210
|
+
var provider = surface.providerOf(entry);
|
|
211
|
+
if (!provider) {
|
|
212
|
+
return ["".concat(entry.file, " names '").concat(entry.specifier, "' (").concat(entry.via, ") \u2014 no declaration file resolves for it")];
|
|
213
|
+
}
|
|
214
|
+
if (declared.has(provider.packageName)) {
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
return [
|
|
218
|
+
"".concat(entry.file, " names '").concat(entry.specifier, "' (").concat(entry.via, ") \u2014 its declarations come from ").concat(provider.packageName, " (").concat(provider.file, "), which is not in dependencies or peerDependencies"),
|
|
219
|
+
];
|
|
220
|
+
})
|
|
221
|
+
.reduce(function (all, lines) { return all.concat(lines); }, []);
|
|
222
|
+
expect(untyped).toEqual([]);
|
|
223
|
+
});
|
|
156
224
|
});
|
|
157
225
|
//# sourceMappingURL=PublicDeclarationSurface.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublicDeclarationSurface.test.js","sourceRoot":"","sources":["../../test/PublicDeclarationSurface.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,0CAAoB;AACpB,8CAAwB;AACxB,iCAAwC;AACxC,0DAA4B;AAE5B,IAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"PublicDeclarationSurface.test.js","sourceRoot":"","sources":["../../test/PublicDeclarationSurface.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,0CAAoB;AACpB,8CAAwB;AACxB,iCAAwC;AACxC,0DAA4B;AAE5B,IAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AA8BlD;;;;;;;GAOG;AACH;IAKE,kCACU,UAAkB,EAC1B,UAAkB;QADV,eAAU,GAAV,UAAU,CAAQ;QALnB,UAAK,GAAa,EAAE,CAAC;QACrB,YAAO,GAAwB,EAAE,CAAC;QACnC,SAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAM/B,IAAI,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,4EAA4E;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CAAC,GAAG,iDAAkC,QAAQ,CAAC,WAAW,eAAK,QAAQ,CAAC,IAAI,wDAAqD;aACpL,CAAC;QACJ,CAAC,CAAC;aACD,MAAM,CAAC,UAAC,GAAG,EAAE,KAAK,IAAK,OAAA,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAjB,CAAiB,EAAE,EAAc,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-server",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.4",
|
|
4
4
|
"description": "User server components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@proteinjs/user": "^1.23.1",
|
|
34
34
|
"@proteinjs/util": "^1.6.1",
|
|
35
35
|
"@proteinjs/util-node": "^1.11.1",
|
|
36
|
+
"@types/express-session": "1.17.0",
|
|
36
37
|
"argon2": "^0.45.1",
|
|
37
38
|
"crypto-js": "4.0.0",
|
|
38
39
|
"express-session": "1.17.1",
|
|
@@ -44,7 +45,6 @@
|
|
|
44
45
|
"@proteinjs/db-driver-spanner": "^1.32.1",
|
|
45
46
|
"@proteinjs/reflection-build": "^2.0.1",
|
|
46
47
|
"@types/crypto-js": "4.0.1",
|
|
47
|
-
"@types/express-session": "1.17.0",
|
|
48
48
|
"@types/jest": "29.5.5",
|
|
49
49
|
"@types/node": "14.0.13",
|
|
50
50
|
"@types/nodemailer": "6.4.15",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
},
|
|
62
62
|
"main": "./dist/generated/index.js",
|
|
63
63
|
"types": "./dist/generated/index.d.ts",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "f836a4e03906bc67aaab4d2b81b7b2579a931e55"
|
|
65
65
|
}
|
package/src/routes/devLogin.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Route } from '@proteinjs/server-api';
|
|
2
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
2
3
|
import { Logger } from '@proteinjs/logger';
|
|
4
|
+
import { tables } from '@proteinjs/user';
|
|
3
5
|
import { RequestDigests } from '@proteinjs/util-node';
|
|
4
6
|
import { emailRegex } from '@proteinjs/util';
|
|
5
7
|
import { establishSession } from '../authentication/establishSession';
|
|
@@ -32,11 +34,15 @@ const emailDomain = (address: string) => address.slice(address.lastIndexOf('@')
|
|
|
32
34
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
33
35
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
34
36
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
38
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
39
|
+
* involved). A missing account is created through the normal signup creation path
|
|
40
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
41
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
42
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
43
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
44
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
45
|
+
* real account from the start.
|
|
40
46
|
*
|
|
41
47
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
42
48
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -91,22 +97,30 @@ export const devLogin: Route = {
|
|
|
91
97
|
email = email.toLowerCase();
|
|
92
98
|
const digests = new RequestDigests();
|
|
93
99
|
|
|
100
|
+
// An EXISTING account signs in as it stands — a person's row, or a machine account's row the boot
|
|
101
|
+
// sync made from its declaration (this door exists so automated dev-loop testing can self-serve a
|
|
102
|
+
// session for any account of the build). The door CREATES only a missing account, and never one
|
|
103
|
+
// under an address a declaration owns: createAccount refuses that in words (a row the sync does
|
|
104
|
+
// not own would make it refuse the declaration), and the door answers the way its other refusals
|
|
105
|
+
// do — the words, no session, no row.
|
|
94
106
|
let creation: 'created' | 'exists';
|
|
95
|
-
|
|
96
|
-
creation =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
if (await getDbAsSystem().get(tables.User, { email })) {
|
|
108
|
+
creation = 'exists';
|
|
109
|
+
} else {
|
|
110
|
+
try {
|
|
111
|
+
creation = await new Signup().createAccount({
|
|
112
|
+
name: email.slice(0, email.indexOf('@')),
|
|
113
|
+
email,
|
|
114
|
+
password: 'test',
|
|
115
|
+
emailVerified: false, // same shape an inviteless signup produces
|
|
116
|
+
invitedBy: null,
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
response
|
|
120
|
+
.status(400)
|
|
121
|
+
.send(`/dev/login: ${error instanceof Error ? error.message : 'the account could not be created'}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
110
124
|
}
|
|
111
125
|
if (creation === 'created') {
|
|
112
126
|
logger.info({ message: 'Dev auto-login created missing test account', obj: { account: digests.account(email) } });
|
package/test/DevLogin.test.ts
CHANGED
|
@@ -141,6 +141,46 @@ describe('devLogin route', () => {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
+
it('establishes a session for a declared machine account whose row the boot sync made — the door creates nothing, the account signs in as it stands', async () => {
|
|
145
|
+
// The dev door exists so automated dev-loop testing can self-serve a session for any account of
|
|
146
|
+
// the build — a declared machine account's included, once the boot sync has created its row. The
|
|
147
|
+
// door never CREATES one (the case above); an existing row is signed in like any other account's.
|
|
148
|
+
class SyncedMachineAccount extends MachineAccount {
|
|
149
|
+
id = 'synced-machine';
|
|
150
|
+
email = 'synced.machine@test.local';
|
|
151
|
+
accountName = 'Synced machine';
|
|
152
|
+
roles = [];
|
|
153
|
+
secretName = 'synced-machine-secret';
|
|
154
|
+
}
|
|
155
|
+
const declaration = new SyncedMachineAccount();
|
|
156
|
+
const repo = SourceRepository.get() as unknown as { namedObjectCache: Record<string, unknown[]> };
|
|
157
|
+
repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'] = [
|
|
158
|
+
{
|
|
159
|
+
qualifiedName: '@proteinjs/user-server-test/SyncedMachineAccount',
|
|
160
|
+
packageName: '@test/declarer',
|
|
161
|
+
object: declaration,
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
165
|
+
await getDbAsSystem().insert(tables.User, { ...declaration.record, isLoadedFromSource: true } as never);
|
|
166
|
+
try {
|
|
167
|
+
const outcome = await invokeDevLogin({ email: declaration.email });
|
|
168
|
+
|
|
169
|
+
expect(outcome.status).toBeUndefined();
|
|
170
|
+
expect(outcome.redirect).toBe('/');
|
|
171
|
+
expect(outcome.loggedInAs).toBe(declaration.email);
|
|
172
|
+
expect(outcome.sessionRegenerated).toBe(true);
|
|
173
|
+
expect(outcome.sessionSaved).toBe(true);
|
|
174
|
+
const row = await getUserRow(declaration.email);
|
|
175
|
+
expect(row?.machine).toBe(true);
|
|
176
|
+
expect(row?.isLoadedFromSource).toBe(true);
|
|
177
|
+
expect(row?.password ?? null).toBeNull();
|
|
178
|
+
} finally {
|
|
179
|
+
delete repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'];
|
|
180
|
+
await getDbAsSystem().delete(tables.User, { email: declaration.email });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
144
184
|
it('rejects a malformed same-domain ?email with 400 — no session, no stray account', async () => {
|
|
145
185
|
// The observed shape: an unencoded `+` in the query decodes to a space, so
|
|
146
186
|
// `?email=brent+shareproof-a@...` arrived as `brent shareproof-a@...` and minted a stray
|
|
@@ -21,6 +21,16 @@ type DeclarationImport = {
|
|
|
21
21
|
file: string;
|
|
22
22
|
/** How it is named: an import / export clause, an `import('x')` type, or a `/// <reference types>`. */
|
|
23
23
|
via: 'import' | 'import()' | 'reference types';
|
|
24
|
+
/** False for a bindingless `import 'x'` — a side effect a consumer's compiler needs no declarations for. */
|
|
25
|
+
bindings: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The package whose declaration file answers a specifier in this tree, by TypeScript's own resolver. */
|
|
29
|
+
type DeclarationProvider = {
|
|
30
|
+
/** `@types/name`, or the package itself when it ships its own declarations. */
|
|
31
|
+
packageName: string;
|
|
32
|
+
/** The declaration file resolved, relative to the package. */
|
|
33
|
+
file: string;
|
|
24
34
|
};
|
|
25
35
|
|
|
26
36
|
/**
|
|
@@ -48,6 +58,28 @@ class PublicDeclarationSurface {
|
|
|
48
58
|
return Array.from(new Set(this.imports.map((entry) => entry.packageName))).sort();
|
|
49
59
|
}
|
|
50
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Where a specifier's declarations come from in this package's own tree — the resolution a
|
|
63
|
+
* consumer's compiler repeats from its own node_modules — or undefined when no declaration file
|
|
64
|
+
* answers it (a JavaScript-only package with no `@types` twin installed resolves to its `.js`).
|
|
65
|
+
*/
|
|
66
|
+
providerOf(entry: DeclarationImport): DeclarationProvider | undefined {
|
|
67
|
+
const from = path.resolve(this.packageDir, entry.file);
|
|
68
|
+
const specifier = entry.via === 'reference types' ? `@types/${entry.specifier}` : entry.specifier;
|
|
69
|
+
const { resolvedModule } = ts.resolveModuleName(
|
|
70
|
+
specifier,
|
|
71
|
+
from,
|
|
72
|
+
{ moduleResolution: ts.ModuleResolutionKind.Node10 },
|
|
73
|
+
ts.sys
|
|
74
|
+
);
|
|
75
|
+
if (!resolvedModule || !PublicDeclarationSurface.DECLARATION_EXTENSIONS.has(resolvedModule.extension)) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const file = path.relative(this.packageDir, resolvedModule.resolvedFileName);
|
|
79
|
+
const packageName = resolvedModule.packageId?.name ?? PublicDeclarationSurface.packageUnderNodeModules(file);
|
|
80
|
+
return packageName ? { packageName, file } : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
51
83
|
/** `@scope/name/sub` -> `@scope/name`; `name/sub` -> `name`; `node:fs` -> `fs`. */
|
|
52
84
|
static packageNameOf(specifier: string): string {
|
|
53
85
|
const bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
|
|
@@ -55,6 +87,26 @@ class PublicDeclarationSurface {
|
|
|
55
87
|
return bare.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
56
88
|
}
|
|
57
89
|
|
|
90
|
+
private static readonly DECLARATION_EXTENSIONS = new Set<string>([
|
|
91
|
+
'.d.ts',
|
|
92
|
+
'.ts',
|
|
93
|
+
'.tsx',
|
|
94
|
+
'.d.mts',
|
|
95
|
+
'.mts',
|
|
96
|
+
'.d.cts',
|
|
97
|
+
'.cts',
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
/** The package a resolved file belongs to, read from its path's last `node_modules/` segment. */
|
|
101
|
+
private static packageUnderNodeModules(file: string): string | undefined {
|
|
102
|
+
const segments = file.split(path.sep);
|
|
103
|
+
const at = segments.lastIndexOf('node_modules');
|
|
104
|
+
if (at < 0 || at + 1 >= segments.length) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
return segments[at + 1].startsWith('@') ? segments.slice(at + 1, at + 3).join('/') : segments[at + 1];
|
|
108
|
+
}
|
|
109
|
+
|
|
58
110
|
private walk(file: string) {
|
|
59
111
|
if (this.seen.has(file)) {
|
|
60
112
|
return;
|
|
@@ -69,7 +121,7 @@ class PublicDeclarationSurface {
|
|
|
69
121
|
this.walk(this.declarationFileFor(file, reference.fileName));
|
|
70
122
|
}
|
|
71
123
|
for (const reference of source.typeReferenceDirectives) {
|
|
72
|
-
this.record(file, reference.fileName, 'reference types');
|
|
124
|
+
this.record(file, reference.fileName, 'reference types', true);
|
|
73
125
|
}
|
|
74
126
|
const visit = (node: ts.Node) => {
|
|
75
127
|
const specifier = this.specifierOf(node);
|
|
@@ -77,7 +129,7 @@ class PublicDeclarationSurface {
|
|
|
77
129
|
if (specifier.text.startsWith('.')) {
|
|
78
130
|
this.walk(this.declarationFileFor(file, specifier.text));
|
|
79
131
|
} else {
|
|
80
|
-
this.record(file, specifier.text, specifier.via);
|
|
132
|
+
this.record(file, specifier.text, specifier.via, specifier.bindings);
|
|
81
133
|
}
|
|
82
134
|
}
|
|
83
135
|
ts.forEachChild(node, visit);
|
|
@@ -85,27 +137,31 @@ class PublicDeclarationSurface {
|
|
|
85
137
|
visit(source);
|
|
86
138
|
}
|
|
87
139
|
|
|
88
|
-
private specifierOf(node: ts.Node): { text: string; via: DeclarationImport['via'] } | undefined {
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
140
|
+
private specifierOf(node: ts.Node): { text: string; via: DeclarationImport['via']; bindings: boolean } | undefined {
|
|
141
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
142
|
+
return { text: node.moduleSpecifier.text, via: 'import', bindings: node.importClause !== undefined };
|
|
143
|
+
}
|
|
144
|
+
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
145
|
+
return { text: node.moduleSpecifier.text, via: 'import', bindings: true };
|
|
91
146
|
}
|
|
92
147
|
if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
|
|
93
148
|
const { expression } = node.moduleReference;
|
|
94
|
-
return ts.isStringLiteral(expression) ? { text: expression.text, via: 'import' } : undefined;
|
|
149
|
+
return ts.isStringLiteral(expression) ? { text: expression.text, via: 'import', bindings: true } : undefined;
|
|
95
150
|
}
|
|
96
151
|
if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument)) {
|
|
97
152
|
const { literal } = node.argument;
|
|
98
|
-
return ts.isStringLiteral(literal) ? { text: literal.text, via: 'import()' } : undefined;
|
|
153
|
+
return ts.isStringLiteral(literal) ? { text: literal.text, via: 'import()', bindings: true } : undefined;
|
|
99
154
|
}
|
|
100
155
|
return undefined;
|
|
101
156
|
}
|
|
102
157
|
|
|
103
|
-
private record(file: string, specifier: string, via: DeclarationImport['via']) {
|
|
158
|
+
private record(file: string, specifier: string, via: DeclarationImport['via'], bindings: boolean) {
|
|
104
159
|
this.imports.push({
|
|
105
160
|
specifier,
|
|
106
161
|
packageName: PublicDeclarationSurface.packageNameOf(specifier),
|
|
107
162
|
file: path.relative(this.packageDir, file),
|
|
108
163
|
via,
|
|
164
|
+
bindings,
|
|
109
165
|
});
|
|
110
166
|
}
|
|
111
167
|
|
|
@@ -132,6 +188,13 @@ class PublicDeclarationSurface {
|
|
|
132
188
|
* same types whether its copy is installed from the registry (devDependencies absent) or linked
|
|
133
189
|
* from a checkout (devDependencies present), and the same whether or not a transitive package
|
|
134
190
|
* happens to hoist beside it.
|
|
191
|
+
*
|
|
192
|
+
* Two clauses, because a specifier and its declarations can come from different packages: the
|
|
193
|
+
* specifier's own package must be declared (the runtime import resolves for the consumer), AND the
|
|
194
|
+
* package whose declaration file answers it must be declared — a dependency that ships no
|
|
195
|
+
* declarations of its own (nodemailer) is typed by its `@types` twin, which is then part of the
|
|
196
|
+
* public surface and belongs beside it in `dependencies`, never in `devDependencies`. Node's
|
|
197
|
+
* builtins and the `node` types that declare them are the consumer's own environment.
|
|
135
198
|
*/
|
|
136
199
|
describe('the public declaration surface resolves against the declared dependencies alone', () => {
|
|
137
200
|
const manifest = JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, 'package.json'), 'utf8')) as PackageManifest;
|
|
@@ -161,6 +224,9 @@ describe('the public declaration surface resolves against the declared dependenc
|
|
|
161
224
|
expect(surface.packageNames()).toEqual(
|
|
162
225
|
expect.arrayContaining(['@proteinjs/reflection', '@proteinjs/user', 'moment'])
|
|
163
226
|
);
|
|
227
|
+
// The resolver half of the control: a package that ships its own declarations answers for itself.
|
|
228
|
+
const reflection = surface.imports.find((entry) => entry.packageName === '@proteinjs/reflection');
|
|
229
|
+
expect(reflection && surface.providerOf(reflection)?.packageName).toBe('@proteinjs/reflection');
|
|
164
230
|
});
|
|
165
231
|
|
|
166
232
|
it('names no package outside dependencies / peerDependencies / node builtins', () => {
|
|
@@ -172,4 +238,23 @@ describe('the public declaration surface resolves against the declared dependenc
|
|
|
172
238
|
);
|
|
173
239
|
expect(undeclared).toEqual([]);
|
|
174
240
|
});
|
|
241
|
+
|
|
242
|
+
it('resolves every declaration it names from a declared package (a dependency typed by its @types twin declares the twin too)', () => {
|
|
243
|
+
const untyped = surface.imports
|
|
244
|
+
.filter((entry) => !isBuiltin(entry) && entry.bindings)
|
|
245
|
+
.map((entry) => {
|
|
246
|
+
const provider = surface.providerOf(entry);
|
|
247
|
+
if (!provider) {
|
|
248
|
+
return [`${entry.file} names '${entry.specifier}' (${entry.via}) — no declaration file resolves for it`];
|
|
249
|
+
}
|
|
250
|
+
if (declared.has(provider.packageName)) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
return [
|
|
254
|
+
`${entry.file} names '${entry.specifier}' (${entry.via}) — its declarations come from ${provider.packageName} (${provider.file}), which is not in dependencies or peerDependencies`,
|
|
255
|
+
];
|
|
256
|
+
})
|
|
257
|
+
.reduce((all, lines) => all.concat(lines), [] as string[]);
|
|
258
|
+
expect(untyped).toEqual([]);
|
|
259
|
+
});
|
|
175
260
|
});
|