@antelopejs/interface-dms 0.14.1 → 0.14.3-next.916.gd319141
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 +43 -0
- package/README.md +5 -5
- package/dist/db/models/user_invites.model.d.ts +17 -1
- package/dist/db/models/user_invites.model.js +32 -0
- package/dist/db/models/user_invites.model.js.map +1 -1
- package/dist/db/tables/user_invites.table.d.ts +10 -0
- package/dist/db/tables/user_invites.table.js +4 -0
- package/dist/db/tables/user_invites.table.js.map +1 -1
- package/dist/invite-resolution.d.ts +3 -1
- package/dist/invite-resolution.js +18 -4
- package/dist/invite-resolution.js.map +1 -1
- package/dist/invites.js +128 -35
- package/dist/invites.js.map +1 -1
- package/docs/2.auth/3.tokens-and-sessions.md +17 -13
- package/docs/3.base/6.layout.md +3 -3
- package/docs/5.html-render/1.introduction.md +3 -3
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.14.2
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.14.1...v0.14.2)
|
|
6
|
+
|
|
7
|
+
### 🚀 Enhancements
|
|
8
|
+
|
|
9
|
+
- **dms:** Fail a layer's lint on a Dms component nothing installed registers ([#1033](https://github.com/AntelopeJS/dms/pull/1033))
|
|
10
|
+
|
|
11
|
+
### 🩹 Fixes
|
|
12
|
+
|
|
13
|
+
- **dms:** Offer the MySQL driver on interface-database 0.4 ([#1029](https://github.com/AntelopeJS/dms/pull/1029))
|
|
14
|
+
- **dms:** Capture the auth middleware's toast before its first await ([#1031](https://github.com/AntelopeJS/dms/pull/1031))
|
|
15
|
+
- **dms:** Finish a dms-control watch restart of the playground ([#1035](https://github.com/AntelopeJS/dms/pull/1035))
|
|
16
|
+
- **dms:** Keep a logo the app config names in a query, a fragment or a literal-only join ([#1036](https://github.com/AntelopeJS/dms/pull/1036))
|
|
17
|
+
- **interface-dms:** Let a resend through a withdrawn fresh invite left by a failed delete, and name the invite that blocks it ([#1037](https://github.com/AntelopeJS/dms/pull/1037))
|
|
18
|
+
- **deps:** Require zod 3.25 in interface-dms and dms so a reused lock drops zod 3.24 ([#1039](https://github.com/AntelopeJS/dms/pull/1039))
|
|
19
|
+
- **interface-dms:** Hand a fresh invite whose rival retires during its withdrawal a pending invitation ([#1038](https://github.com/AntelopeJS/dms/pull/1038))
|
|
20
|
+
- **dms:** Refuse access and refresh tokens that carry no session ([#1042](https://github.com/AntelopeJS/dms/pull/1042))
|
|
21
|
+
- **dms:** Keep a logo the app config names in a percent-encoded optimizer URL ([#1041](https://github.com/AntelopeJS/dms/pull/1041))
|
|
22
|
+
- **interface-dms:** Keep a new invitation's re-read when its stray-removal retry finds the read invite cancelled ([#1045](https://github.com/AntelopeJS/dms/pull/1045))
|
|
23
|
+
- **dms:** Run the DMS component check without @antelopejs/dms-frontend, and name what a layer must install ([#1044](https://github.com/AntelopeJS/dms/pull/1044))
|
|
24
|
+
- **interface-dms:** Settle a fresh invite once as kept or withdrawn, so no caller yields to one that then withdraws ([#1046](https://github.com/AntelopeJS/dms/pull/1046))
|
|
25
|
+
- **dms:** Report a connection variable the starting environment shadows instead of writing it to .env ([#1049](https://github.com/AntelopeJS/dms/pull/1049))
|
|
26
|
+
- **dms:** Let a restart load a .env value after a builder call loaded the configuration ([#1050](https://github.com/AntelopeJS/dms/pull/1050))
|
|
27
|
+
- **deps:** Cap every @antelopejs range below the next minor ([#1051](https://github.com/AntelopeJS/dms/pull/1051))
|
|
28
|
+
|
|
29
|
+
### 📖 Documentation
|
|
30
|
+
|
|
31
|
+
- **dms:** Replace dms-ai and dms-builder with dms-assistant ([#894](https://github.com/AntelopeJS/dms/pull/894))
|
|
32
|
+
- Name the assistant dms-assistant where dms-ai was left ([#1048](https://github.com/AntelopeJS/dms/pull/1048))
|
|
33
|
+
|
|
34
|
+
### ✅ Tests
|
|
35
|
+
|
|
36
|
+
- **dms:** Restore the mail renderer and sender after each suite that captures emails ([#1030](https://github.com/AntelopeJS/dms/pull/1030))
|
|
37
|
+
- **dms:** Give the menu-access-events setup hook a timeout sized to its sign-ups ([#1032](https://github.com/AntelopeJS/dms/pull/1032))
|
|
38
|
+
- **dms:** Size the sketch rebuild test's timeout to its seventeen checks ([#1040](https://github.com/AntelopeJS/dms/pull/1040))
|
|
39
|
+
- **dms:** Keep the integration file storage off the test mongod's disk ([#1028](https://github.com/AntelopeJS/dms/pull/1028))
|
|
40
|
+
- **dms:** Move cold module and Intl setup out of two frontend-vue test bodies ([#1047](https://github.com/AntelopeJS/dms/pull/1047))
|
|
41
|
+
|
|
42
|
+
### ❤️ Contributors
|
|
43
|
+
|
|
44
|
+
- Antony Rizzitelli ([@Upd4ting](http://github.com/Upd4ting))
|
|
45
|
+
|
|
3
46
|
## v0.14.1
|
|
4
47
|
|
|
5
48
|
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.14.0...v0.14.1)
|
package/README.md
CHANGED
|
@@ -60,13 +60,13 @@ export class SalesPage extends PageController("sales", {
|
|
|
60
60
|
|
|
61
61
|
| Package | Supported | Tested with |
|
|
62
62
|
| ------------------------------------------- | ---------------- | ----------- |
|
|
63
|
-
| `@antelopejs/interface-api` | `>=0.3.0 <
|
|
64
|
-
| `@antelopejs/interface-api-util` | `>=0.
|
|
65
|
-
| `@antelopejs/interface-core` | `>=0.5.1 <
|
|
63
|
+
| `@antelopejs/interface-api` | `>=0.3.0 <0.4.0` | `0.3.2` |
|
|
64
|
+
| `@antelopejs/interface-api-util` | `>=0.3.0 <0.4.0` | `0.3.0` |
|
|
65
|
+
| `@antelopejs/interface-core` | `>=0.5.1 <0.6.0` | `0.5.1` |
|
|
66
66
|
| `@antelopejs/interface-data-api` | `>=0.8.0 <0.9.0` | `0.8.0` |
|
|
67
|
-
| `@antelopejs/interface-database` | `>=0.4.0 <0.5.0` | `0.4.
|
|
67
|
+
| `@antelopejs/interface-database` | `>=0.4.0 <0.5.0` | `0.4.1` |
|
|
68
68
|
| `@antelopejs/interface-database-decorators` | `>=0.5.2 <0.6.0` | `0.5.2` |
|
|
69
|
-
| `@antelopejs/interface-file-storage` | `>=0.1.4 <
|
|
69
|
+
| `@antelopejs/interface-file-storage` | `>=0.1.4 <0.2.0` | `0.1.4` |
|
|
70
70
|
|
|
71
71
|
<!-- antelopejs-docs-compat:end -->
|
|
72
72
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserInvite } from "../tables/user_invites.table";
|
|
1
|
+
import { type FreshInviteOutcome, UserInvite } from "../tables/user_invites.table";
|
|
2
2
|
interface InviteWithTenant {
|
|
3
3
|
invite: UserInvite;
|
|
4
4
|
tenantId: string;
|
|
@@ -40,6 +40,13 @@ export declare class UserInviteModel extends UserInviteModel_base {
|
|
|
40
40
|
* @returns The invite or undefined if not found
|
|
41
41
|
*/
|
|
42
42
|
getOtherByEmail(email: string, exceptId: string): Promise<UserInvite | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Get every invite sent to the email
|
|
45
|
+
*
|
|
46
|
+
* @param email The email the invites were sent to
|
|
47
|
+
* @returns The stored invites of the email
|
|
48
|
+
*/
|
|
49
|
+
listByEmail(email: string): Promise<UserInvite[]>;
|
|
43
50
|
/**
|
|
44
51
|
* Whether the invite is stored and is the only invite sent to its email
|
|
45
52
|
*
|
|
@@ -47,6 +54,15 @@ export declare class UserInviteModel extends UserInviteModel_base {
|
|
|
47
54
|
* @returns True when the email's invites are exactly this one
|
|
48
55
|
*/
|
|
49
56
|
isOnlyInviteOfEmail(invite: UserInvite): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Settles an invite created without a replacement as kept or withdrawn,
|
|
59
|
+
* unless it is settled already: the first outcome written stands.
|
|
60
|
+
*
|
|
61
|
+
* @param inviteId The invite to settle
|
|
62
|
+
* @param outcome The outcome to write
|
|
63
|
+
* @returns The invite's outcome after this call, or undefined when it is no longer stored
|
|
64
|
+
*/
|
|
65
|
+
settleFresh(inviteId: string, outcome: FreshInviteOutcome): Promise<FreshInviteOutcome | undefined>;
|
|
50
66
|
/**
|
|
51
67
|
* Get an invite by its token
|
|
52
68
|
*
|
|
@@ -36,6 +36,16 @@ class UserInviteModel extends (0, interface_database_decorators_1.BasicDataModel
|
|
|
36
36
|
.run()
|
|
37
37
|
.then((res) => (res ? UserInviteModel.fromDatabase(res) : undefined));
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Get every invite sent to the email
|
|
41
|
+
*
|
|
42
|
+
* @param email The email the invites were sent to
|
|
43
|
+
* @returns The stored invites of the email
|
|
44
|
+
*/
|
|
45
|
+
async listByEmail(email) {
|
|
46
|
+
const rows = await this.table.getAll((0, users_model_1.normalizeEmail)(email), "email").run();
|
|
47
|
+
return rows.flatMap((row) => UserInviteModel.fromDatabase(row) ?? []);
|
|
48
|
+
}
|
|
39
49
|
/**
|
|
40
50
|
* Whether the invite is stored and is the only invite sent to its email
|
|
41
51
|
*
|
|
@@ -48,6 +58,28 @@ class UserInviteModel extends (0, interface_database_decorators_1.BasicDataModel
|
|
|
48
58
|
.run();
|
|
49
59
|
return rows.length === 1 && rows[0]?._id === invite._id;
|
|
50
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Settles an invite created without a replacement as kept or withdrawn,
|
|
63
|
+
* unless it is settled already: the first outcome written stands.
|
|
64
|
+
*
|
|
65
|
+
* @param inviteId The invite to settle
|
|
66
|
+
* @param outcome The outcome to write
|
|
67
|
+
* @returns The invite's outcome after this call, or undefined when it is no longer stored
|
|
68
|
+
*/
|
|
69
|
+
async settleFresh(inviteId, outcome) {
|
|
70
|
+
const written = await this.table
|
|
71
|
+
.atomicMutation(inviteId, {
|
|
72
|
+
type: "update",
|
|
73
|
+
revisionField: "freshOutcome",
|
|
74
|
+
expectedRevision: { kind: "missing" },
|
|
75
|
+
nextRevision: outcome,
|
|
76
|
+
patch: {},
|
|
77
|
+
})
|
|
78
|
+
.run();
|
|
79
|
+
if (written === "applied")
|
|
80
|
+
return outcome;
|
|
81
|
+
return (await this.get(inviteId))?.freshOutcome;
|
|
82
|
+
}
|
|
51
83
|
/**
|
|
52
84
|
* Get an invite by its token
|
|
53
85
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user_invites.model.js","sourceRoot":"","sources":["../../../src/db/models/user_invites.model.ts"],"names":[],"mappings":";;;AAAA,6FAA2E;AAC3E,kEAAkE;AAClE,oEAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"user_invites.model.js","sourceRoot":"","sources":["../../../src/db/models/user_invites.model.ts"],"names":[],"mappings":";;;AAAA,6FAA2E;AAC3E,kEAAkE;AAClE,oEAAmE;AACnE,qEAIsC;AAOtC,MAAa,eAAgB,SAAQ,IAAA,8CAAc,EACjD,+BAAU,EACV,4CAAuB,CACxB;IACC;;;;;OAKG;IACH,UAAU,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,KAAK;aACd,MAAM,CAAC,IAAA,4BAAc,EAAC,KAAK,CAAC,EAAE,OAAO,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC;aACN,OAAO,CAAC,SAAS,CAAC;aAClB,GAAG,EAAE;aACL,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;OAMG;IACH,eAAe,CACb,KAAa,EACb,QAAgB;QAEhB,OAAO,IAAI,CAAC,KAAK;aACd,MAAM,CAAC,IAAA,4BAAc,EAAC,KAAK,CAAC,EAAE,OAAO,CAAC;aACtC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;aAC5C,GAAG,CAAC,CAAC,CAAC;aACN,OAA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import type { InviteExtensionPayloads } from "../../invite-extension-payloads";
|
|
3
3
|
export declare const USER_INVITES_TABLE_NAME = "user_invites";
|
|
4
|
+
/** How an invitation created without a replacement settled. */
|
|
5
|
+
export type FreshInviteOutcome = "kept" | "withdrawn";
|
|
4
6
|
export declare class UserInvite extends Table {
|
|
5
7
|
_id: string;
|
|
6
8
|
createdAt: Date;
|
|
@@ -19,6 +21,14 @@ export declare class UserInvite extends Table {
|
|
|
19
21
|
* email keep a single row.
|
|
20
22
|
*/
|
|
21
23
|
creationResolutionId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* How an invitation created without a replacement settled after it looked
|
|
26
|
+
* for another invitation of its email: `kept`, or `withdrawn` because it
|
|
27
|
+
* found one. Absent while it is undecided. Written once, through
|
|
28
|
+
* `UserInviteModel.settleFresh`, so whichever of its creator's withdrawal
|
|
29
|
+
* and another caller's adoption writes first decides.
|
|
30
|
+
*/
|
|
31
|
+
freshOutcome?: FreshInviteOutcome;
|
|
22
32
|
/**
|
|
23
33
|
* Id of the user who sent the invitation, or last resent it. `null` for an
|
|
24
34
|
* invitation created outside a signed-in request (an import, a module).
|
|
@@ -70,6 +70,10 @@ __decorate([
|
|
|
70
70
|
(0, interface_database_decorators_1.Field)("string"),
|
|
71
71
|
__metadata("design:type", String)
|
|
72
72
|
], UserInvite.prototype, "creationResolutionId", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, interface_database_decorators_1.Field)("string"),
|
|
75
|
+
__metadata("design:type", String)
|
|
76
|
+
], UserInvite.prototype, "freshOutcome", void 0);
|
|
73
77
|
__decorate([
|
|
74
78
|
(0, interface_database_decorators_1.Field)("string"),
|
|
75
79
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user_invites.table.js","sourceRoot":"","sources":["../../../src/db/tables/user_invites.table.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6FAOmD;AACnD,+CAAqD;AAErD,+CAAqC;AAExB,QAAA,u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IAAA,qCAAK,EAAC,SAAS,CAAC;;iDACc;AAIvB;IAFP,IAAA,qCAAK,EAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,qCAAK,EAAC,MAAM,CAAC;8BACK,IAAI;6CAAC;AAUhB;IAFP,IAAA,qCAAK,EAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACpD,IAAA,qCAAK,EAAC,QAAQ,CAAC;;wDACsB;AAU9B;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;gDAC0B;AAOlC;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;6CACkB;AAQ1B;IADP,IAAA,qCAAK,EAAC,KAAK,CAAC;;8CACsC;qBAvExC,UAAU;IADtB,IAAA,6CAAa,EAAC,+BAAuB,EAAE,8BAAkB,CAAC;GAC9C,UAAU,CAwEtB"}
|
|
@@ -9,7 +9,9 @@ export declare function assertInviteReady(tenantId: string, invite: UserInvite):
|
|
|
9
9
|
/**
|
|
10
10
|
* Chooses one permanent outcome; all competing lifecycle paths must use this before effects.
|
|
11
11
|
* A new replacement is refused with HTTP 409 unless its invite is the only invite of its email,
|
|
12
|
-
* so a fresh invite that lost a concurrent creation is withdrawn, never replaced.
|
|
12
|
+
* so a fresh invite that lost a concurrent creation is withdrawn, never replaced. While the
|
|
13
|
+
* invite is stored, the refusal names another invite of the email, whose cancellation lets
|
|
14
|
+
* the replacement through.
|
|
13
15
|
*/
|
|
14
16
|
export declare function decideInvite(input: ResolveInviteInput): Promise<InviteResolution>;
|
|
15
17
|
/** Replays durable effects. Contributor callbacks must deduplicate by deliveryId; failures retain the snapshot. */
|
|
@@ -4,6 +4,7 @@ exports.loadInviteForAction = loadInviteForAction;
|
|
|
4
4
|
exports.assertInviteReady = assertInviteReady;
|
|
5
5
|
exports.decideInvite = decideInvite;
|
|
6
6
|
exports.completeInviteResolution = completeInviteResolution;
|
|
7
|
+
const interface_api_1 = require("@antelopejs/interface-api");
|
|
7
8
|
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
8
9
|
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
9
10
|
const inviteResolutions_model_1 = require("./db/internal/inviteResolutions.model");
|
|
@@ -34,10 +35,24 @@ function assertSameDecision(resolution, input) {
|
|
|
34
35
|
resolution.userId === (input.userId ?? null), HTTP_CONFLICT, "Invitation already has a different terminal decision");
|
|
35
36
|
(0, interface_api_util_1.assert)((0, invite_content_1.isSameInviteContent)(resolution.replacement, input.replacement), HTTP_CONFLICT, "Invitation already has a different replacement");
|
|
36
37
|
}
|
|
38
|
+
async function assertOnlyInviteOfEmail(tenantId, invite) {
|
|
39
|
+
const invites = (0, interface_database_decorators_1.GetModel)(user_invites_model_1.UserInviteModel, tenantId);
|
|
40
|
+
if (await invites.isOnlyInviteOfEmail(invite))
|
|
41
|
+
return;
|
|
42
|
+
const stored = await invites.listByEmail(invite.email);
|
|
43
|
+
const other = stored.some((row) => row._id === invite._id)
|
|
44
|
+
? stored.find((row) => row._id !== invite._id)
|
|
45
|
+
: undefined;
|
|
46
|
+
throw new interface_api_1.HTTPResult(HTTP_CONFLICT, other
|
|
47
|
+
? `Invitation for this email was created concurrently: cancel invitation ${other._id}, created ${other.createdAt.toISOString()}, first`
|
|
48
|
+
: "Invitation for this email was created concurrently");
|
|
49
|
+
}
|
|
37
50
|
/**
|
|
38
51
|
* Chooses one permanent outcome; all competing lifecycle paths must use this before effects.
|
|
39
52
|
* A new replacement is refused with HTTP 409 unless its invite is the only invite of its email,
|
|
40
|
-
* so a fresh invite that lost a concurrent creation is withdrawn, never replaced.
|
|
53
|
+
* so a fresh invite that lost a concurrent creation is withdrawn, never replaced. While the
|
|
54
|
+
* invite is stored, the refusal names another invite of the email, whose cancellation lets
|
|
55
|
+
* the replacement through.
|
|
41
56
|
*/
|
|
42
57
|
async function decideInvite(input) {
|
|
43
58
|
await assertInviteReady(input.tenantId, input.invite);
|
|
@@ -46,9 +61,8 @@ async function decideInvite(input) {
|
|
|
46
61
|
(0, interface_api_util_1.assert)(input.reason !== "accepted" ||
|
|
47
62
|
existing ||
|
|
48
63
|
new Date(input.invite.expiresAt) > new Date(), HTTP_CONFLICT, "Invitation expired before acceptance");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(await (0, interface_database_decorators_1.GetModel)(user_invites_model_1.UserInviteModel, input.tenantId).isOnlyInviteOfEmail(input.invite)), HTTP_CONFLICT, "Invitation for this email was created concurrently");
|
|
64
|
+
if (input.replacement && !existing)
|
|
65
|
+
await assertOnlyInviteOfEmail(input.tenantId, input.invite);
|
|
52
66
|
const extensionKeys = [
|
|
53
67
|
...new Set([
|
|
54
68
|
...Object.keys(input.invite.extensions ?? {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invite-resolution.js","sourceRoot":"","sources":["../src/invite-resolution.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"invite-resolution.js","sourceRoot":"","sources":["../src/invite-resolution.ts"],"names":[],"mappings":";;AAkBA,kDAWC;AAGD,8CAaC;AA4CD,oCAwBC;AAGD,4DAOC;AA3HD,6DAAuD;AACvD,uEAAwD;AACxD,6FAAqE;AAErE,mFAA+E;AAE/E,uEAAiE;AAEjE,oEAA6E;AAC7E,qDAAuD;AACvD,oEAAgF;AAChF,oEAAwE;AACxE,8DAAgE;AAEhE,MAAM,aAAa,GAAG,GAAG,CAAC;AAG1B,wFAAwF;AACjF,KAAK,UAAU,mBAAmB,CACvC,QAAgB,EAChB,QAAgB;IAEhB,MAAM,MAAM,GAAG,MAAM,IAAA,wCAAQ,EAAC,oCAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvE,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,IAAA,wCAAQ,EAC/B,gDAAsB,EACtB,QAAQ,CACT,CAAC,YAAY,CAAC,QAAQ,EAAE,QA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F,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IACnE,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,mHAAmH;AAC5G,KAAK,UAAU,wBAAwB,CAC5C,UAA4B;IAE5B,MAAM,IAAA,oCAAmB,EAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,EAAE,MAAM,IAAA,4CAAwB,EAAC,UAAU,CAAC;QACnD,KAAK,EAAE,GAAG,EAAE,CAAC,IAAA,oDAAgC,EAAC,UAAU,CAAC;KAC1D,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/invites.js
CHANGED
|
@@ -136,28 +136,8 @@ async function createAdmittedInviteToken(options) {
|
|
|
136
136
|
const userInviteModel = (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId);
|
|
137
137
|
const existingInvite = options.replacesInvite ?? (await userInviteModel.getByEmail(email));
|
|
138
138
|
const replacement = buildInviteSnapshot(options);
|
|
139
|
-
if (existingInvite)
|
|
140
|
-
|
|
141
|
-
tenantId,
|
|
142
|
-
invite: existingInvite,
|
|
143
|
-
reason: options.replacementReason ?? "replaced",
|
|
144
|
-
replacement,
|
|
145
|
-
}).catch(async (error) => {
|
|
146
|
-
if (options.replacesInvite ||
|
|
147
|
-
!(await completeCancellationOfRead(tenantId, existingInvite)))
|
|
148
|
-
throw error;
|
|
149
|
-
return undefined;
|
|
150
|
-
});
|
|
151
|
-
if (!resolution)
|
|
152
|
-
return createAdmittedInviteToken(options);
|
|
153
|
-
await (0, invite_resolution_1.completeAdmittedInviteResolution)(resolution);
|
|
154
|
-
if (!resolution.replacement)
|
|
155
|
-
throw new Error("Replacement snapshot missing");
|
|
156
|
-
return {
|
|
157
|
-
inviteId: resolution.replacement._id,
|
|
158
|
-
token: resolution.replacement.token,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
139
|
+
if (existingInvite)
|
|
140
|
+
return replaceInvite(options, existingInvite, replacement);
|
|
161
141
|
await (0, hooks_1.ExecuteHooks)(hooks_1.Hook.INVITE_BEING_CREATED, {
|
|
162
142
|
tenantId,
|
|
163
143
|
email,
|
|
@@ -170,11 +150,18 @@ async function createAdmittedInviteToken(options) {
|
|
|
170
150
|
catch (error) {
|
|
171
151
|
if (!(0, interface_database_1.IsDuplicateKeyError)(error))
|
|
172
152
|
throw error;
|
|
173
|
-
|
|
153
|
+
const winner = await userInviteModel.getByEmail(email);
|
|
154
|
+
return yieldOrCreateAgain(options, winner && (await currentInviteOf(options, winner)), replacement);
|
|
174
155
|
}
|
|
175
156
|
const rival = await userInviteModel.getOtherByEmail(email, replacement._id);
|
|
176
|
-
if (rival)
|
|
177
|
-
|
|
157
|
+
if (rival) {
|
|
158
|
+
const outcome = await userInviteModel.settleFresh(replacement._id, "withdrawn");
|
|
159
|
+
if (outcome !== "kept")
|
|
160
|
+
return withdrawFreshInvite(options, replacement, rival);
|
|
161
|
+
const current = await currentInviteOf(options, replacement);
|
|
162
|
+
if (current?._id !== replacement._id)
|
|
163
|
+
return yieldOrCreateAgain(options, current, replacement);
|
|
164
|
+
}
|
|
178
165
|
await (0, hooks_1.ExecuteHooks)(hooks_1.Hook.INVITE_CREATED, {
|
|
179
166
|
tenantId,
|
|
180
167
|
inviteId: replacement._id,
|
|
@@ -185,14 +172,58 @@ async function createAdmittedInviteToken(options) {
|
|
|
185
172
|
});
|
|
186
173
|
return { inviteId: replacement._id, token: replacement.token };
|
|
187
174
|
}
|
|
175
|
+
async function replaceInvite(options, invite, replacement) {
|
|
176
|
+
let resolution;
|
|
177
|
+
try {
|
|
178
|
+
resolution = await (0, invite_resolution_2.decideInvite)({
|
|
179
|
+
tenantId: options.tenantId,
|
|
180
|
+
invite,
|
|
181
|
+
reason: options.replacementReason ?? "replaced",
|
|
182
|
+
replacement,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
const retry = await retryAfterRefusal(options, invite);
|
|
187
|
+
if (retry === "read the email again")
|
|
188
|
+
return createAdmittedInviteToken(options);
|
|
189
|
+
if (retry === "replace the same invite")
|
|
190
|
+
return replaceInvite(options, invite, replacement);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
await (0, invite_resolution_1.completeAdmittedInviteResolution)(resolution);
|
|
194
|
+
if (!resolution.replacement)
|
|
195
|
+
throw new Error("Replacement snapshot missing");
|
|
196
|
+
return {
|
|
197
|
+
inviteId: resolution.replacement._id,
|
|
198
|
+
token: resolution.replacement.token,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
188
201
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
202
|
+
* How the creation runs again after `decideInvite` refused to replace `read`.
|
|
203
|
+
* When a completed cancellation retired the invite a new invitation read, by
|
|
204
|
+
* the time the email's invites are listed, it reads the email again. When it removed invites a completed cancellation
|
|
205
|
+
* retired but left stored, such as a fresh invite whose withdrawal failed to
|
|
206
|
+
* delete it, it replaces `read` again with the same options, so a new
|
|
207
|
+
* invitation can still read the email again if `read` is cancelled meanwhile,
|
|
208
|
+
* and any other refusal stands.
|
|
191
209
|
*
|
|
192
|
-
* @returns
|
|
210
|
+
* @returns The retry, or undefined to keep the refusal
|
|
193
211
|
*/
|
|
194
|
-
async function
|
|
195
|
-
const
|
|
212
|
+
async function retryAfterRefusal(options, read) {
|
|
213
|
+
const { tenantId, email } = options;
|
|
214
|
+
const stored = await (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId).listByEmail(email);
|
|
215
|
+
const removed = await Promise.all(stored.map((invite) => removeIfCancelled(tenantId, invite._id)));
|
|
216
|
+
if (!options.replacesInvite && (await removeIfCancelled(tenantId, read._id)))
|
|
217
|
+
return "read the email again";
|
|
218
|
+
return removed.includes(true) ? "replace the same invite" : undefined;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Deletes the invite's row when a completed cancellation retired it.
|
|
222
|
+
*
|
|
223
|
+
* @returns Whether its decision is such a cancellation
|
|
224
|
+
*/
|
|
225
|
+
async function removeIfCancelled(tenantId, inviteId) {
|
|
226
|
+
const held = await (0, interface_database_decorators_1.GetModel)(inviteResolutions_model_1.InviteResolutionsModel, tenantId).getForInvite(tenantId, inviteId);
|
|
196
227
|
if (held?.reason !== "cancelled" || held.replacement || !held.completed)
|
|
197
228
|
return false;
|
|
198
229
|
await (0, invite_resolution_1.completeAdmittedInviteResolution)(held);
|
|
@@ -201,14 +232,76 @@ async function completeCancellationOfRead(tenantId, invite) {
|
|
|
201
232
|
/**
|
|
202
233
|
* Withdraws a fresh invite that found a rival, through its decision: a
|
|
203
234
|
* replacement decided on it first is kept instead, and its decider completes it.
|
|
235
|
+
* Otherwise it yields to the email's current invite, or runs the creation
|
|
236
|
+
* again when the email has none left.
|
|
204
237
|
*/
|
|
205
|
-
async function withdrawFreshInvite(
|
|
238
|
+
async function withdrawFreshInvite(options, fresh, rival) {
|
|
239
|
+
const { tenantId } = options;
|
|
206
240
|
const decisions = (0, interface_database_decorators_1.GetModel)(inviteResolutions_model_1.InviteResolutionsModel, tenantId);
|
|
207
241
|
const { resolution, claimed } = await decisions.withdraw(tenantId, fresh);
|
|
208
|
-
if (
|
|
209
|
-
return yieldToWinner(resolution.replacement
|
|
210
|
-
|
|
211
|
-
|
|
242
|
+
if (resolution.replacement)
|
|
243
|
+
return yieldToWinner(resolution.replacement, fresh);
|
|
244
|
+
if (claimed)
|
|
245
|
+
await (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId).delete(fresh._id);
|
|
246
|
+
return yieldOrCreateAgain(options, await currentInviteOf(options, rival), fresh);
|
|
247
|
+
}
|
|
248
|
+
/** Yields to the email's current invite, or runs the creation again when the email has none left. */
|
|
249
|
+
function yieldOrCreateAgain(options, current, lost) {
|
|
250
|
+
if (!current)
|
|
251
|
+
return createAdmittedInviteToken(options);
|
|
252
|
+
return yieldToWinner(current, lost);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The invite a withdrawn fresh invite yields to: its rival while stored, else
|
|
256
|
+
* the email's invite, or the replacement decided on it. A cancellation or an
|
|
257
|
+
* expiry decided on it is completed first, so its token is never handed out.
|
|
258
|
+
*
|
|
259
|
+
* @returns The invite, or undefined when the email has none left
|
|
260
|
+
*/
|
|
261
|
+
async function currentInviteOf(options, rival) {
|
|
262
|
+
const { tenantId, email } = options;
|
|
263
|
+
const invites = (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId);
|
|
264
|
+
const invite = (await invites.get(rival._id)) ?? (await invites.getByEmail(email));
|
|
265
|
+
if (!invite)
|
|
266
|
+
return undefined;
|
|
267
|
+
const decision = await (0, interface_database_decorators_1.GetModel)(inviteResolutions_model_1.InviteResolutionsModel, tenantId).getForInvite(tenantId, invite._id);
|
|
268
|
+
if (!decision)
|
|
269
|
+
return followUndecided(options, invite);
|
|
270
|
+
if (decision.reason === "accepted")
|
|
271
|
+
return invite;
|
|
272
|
+
if (decision.replacement)
|
|
273
|
+
return decision.replacement;
|
|
274
|
+
await (0, invite_resolution_1.completeAdmittedInviteResolution)(decision);
|
|
275
|
+
return currentInviteOf(options, invite);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The invite to yield to when `invite` has no decision. A replacement, or a
|
|
279
|
+
* fresh invite settled kept, is yielded to. A fresh invite that is the only
|
|
280
|
+
* invite of its email is settled kept here, so its creator keeps it even if it
|
|
281
|
+
* read a rival since retired. A fresh invite beside another invite yields to
|
|
282
|
+
* that one, and a fresh invite settled withdrawn has its withdrawal finished
|
|
283
|
+
* here, so no caller waits on its creator.
|
|
284
|
+
*
|
|
285
|
+
* @returns The invite, or undefined when the email has none left
|
|
286
|
+
*/
|
|
287
|
+
async function followUndecided(options, invite) {
|
|
288
|
+
const { tenantId, email } = options;
|
|
289
|
+
if (invite.creationResolutionId || invite.freshOutcome === "kept")
|
|
290
|
+
return invite;
|
|
291
|
+
const invites = (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId);
|
|
292
|
+
if (invite.freshOutcome !== "withdrawn") {
|
|
293
|
+
if (!(await invites.isOnlyInviteOfEmail(invite))) {
|
|
294
|
+
const other = await invites.getOtherByEmail(email, invite._id);
|
|
295
|
+
return currentInviteOf(options, other ?? invite);
|
|
296
|
+
}
|
|
297
|
+
if ((await invites.settleFresh(invite._id, "kept")) === "kept")
|
|
298
|
+
return invite;
|
|
299
|
+
}
|
|
300
|
+
const { resolution } = await (0, interface_database_decorators_1.GetModel)(inviteResolutions_model_1.InviteResolutionsModel, tenantId).withdraw(tenantId, invite);
|
|
301
|
+
if (resolution.replacement)
|
|
302
|
+
return resolution.replacement;
|
|
303
|
+
await invites.delete(invite._id);
|
|
304
|
+
return currentInviteOf(options, invite);
|
|
212
305
|
}
|
|
213
306
|
function yieldToWinner(winner, lost) {
|
|
214
307
|
(0, interface_api_util_1.assert)(winner && (0, invite_content_1.isSameInviteContent)(winner, lost), HTTP_CONFLICT, "Invitation for this email was created concurrently with other content");
|
package/dist/invites.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invites.js","sourceRoot":"","sources":["../src/invites.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"invites.js","sourceRoot":"","sources":["../src/invites.ts"],"names":[],"mappings":";;;;;;AA2FA,gDAmBC;AAsHD,sDAOC;AA3OD,6CAAyC;AACzC,uEAAwD;AACxD,gEAA6D;AAC7D,uEAAqE;AACrE,6FAAqE;AACrE,6BAA2E;AAC3E,mFAA+E;AAC/E,kCAAsD;AACtD,gEAAwC;AACxC,6DAAwD;AACxD,gDAA6D;AAC7D,mCAA2E;AAE3E,oEAAgF;AAChF,oEAAgF;AAChF,8DAAgE;AAChE,2DAAmD;AAEnD,qDAAgF;AAChF,kEAA2E;AAC3E,8DAAoE;AACpE,gDAG4B;AAE5B,+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M,EAAE,IAAI,CAAC,EAC3C,aAAa,EACb,uEAAuE,CACxE,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAqC;IAErC,OAAO,oBAAe,CAAC,aAAa,CAAC;QACnC,GAAG,EAAE,IAAA,wBAAU,GAAE;QACjB,SAAS,EAAE,IAAI,IAAI,EAAE;QACrB,KAAK,EAAE,IAAA,mBAAc,EAAC,OAAO,CAAC,KAAK,CAAC;QACpC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;QAClC,SAAS,EAAE,OAAO,CAAC,OAAO;QAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,sBAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,2BAAmB,EAAE,CAAC;QAC7D,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,0BAAkB,GAAG,2BAAoB,CAAC;QAC3E,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;QACpC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAI;QACtC,oBAAoB,EAAE,EAAE;KACzB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -10,8 +10,8 @@ The interface issues four kinds of token, and it records a login as a row in the
|
|
|
10
10
|
|
|
11
11
|
| Token | Generated by | Validated by | Carries |
|
|
12
12
|
| ----- | ------------ | ------------ | ------- |
|
|
13
|
-
| Access | `generateAccessToken` | The authentication decorators in [Authentication](/docs/interfaces/auth/authentication) | `id`, `tenantId`,
|
|
14
|
-
| Refresh | `generateRefreshToken` | `validateRefreshToken` | `id`, `tenantId`,
|
|
13
|
+
| Access | `generateAccessToken` | The authentication decorators in [Authentication](/docs/interfaces/auth/authentication) | `id`, `tenantId`, `sessionId`, a purpose marker |
|
|
14
|
+
| Refresh | `generateRefreshToken` | `validateRefreshToken` | `id`, `tenantId`, `sessionId`, a purpose marker |
|
|
15
15
|
| Two-factor | `generateTwoFactorToken` | `validateTwoFactorToken` | `id`, `tenantId`, a purpose marker |
|
|
16
16
|
| Tenant assignment | `generateTenantAssignmentToken` | `validateTenantAssignmentToken` | `id`, a purpose marker |
|
|
17
17
|
|
|
@@ -39,7 +39,7 @@ generateRefreshToken(
|
|
|
39
39
|
| --------- | ----------- |
|
|
40
40
|
| `tenantId` | The tenant the token is scoped to. It goes in the `tenantId` claim of the token, and the request's tenant resolution reads it back. |
|
|
41
41
|
| `user` | The `User` the token is issued for. The user's `authKey` is part of the signing secret, so rotating `authKey` invalidates every token issued to that user before. |
|
|
42
|
-
| `sessionId` | The `_id` of the `Session` row that records this login.
|
|
42
|
+
| `sessionId` | The `_id` of the `Session` row that records this login. The type marks it optional, but both functions throw when it is missing or empty. An access token is refused as soon as that row is deleted, and a token that carries no `sessionId` claim is always refused. |
|
|
43
43
|
|
|
44
44
|
Both functions return the signed `token`, and its lifetime as `expiresIn` in milliseconds. The lifetimes come from the `accessTokenLifetime` and `refreshTokenLifetime` settings of the deployment.
|
|
45
45
|
|
|
@@ -86,7 +86,7 @@ validateRefreshToken(
|
|
|
86
86
|
): Promise<{ id: string; tenantId: string; sessionId?: string }>
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
The function decodes the token, loads the user it names, and verifies the signature against that user. It also checks that the token was issued as a refresh token and carries non-empty `id` and `
|
|
89
|
+
The function decodes the token, loads the user it names, and verifies the signature against that user. It also checks that the token was issued as a refresh token and carries non-empty `id`, `tenantId` and `sessionId` claims. It throws `HTTPResult(401)` with the same message, `Invalid session token`, when the token is malformed, names no existing user, is badly signed, expired or issued for another purpose, so a forged token cannot tell whether its `id` names a user. A token naming no user is still verified, against a key no token is signed with, so the refusal takes as long either way. It returns the claims only. The caller must still confirm three things: that the session exists, that the token is its current one (`isCurrentRefreshToken`), and that the user still has access to `tenantId`.
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
92
|
import { HTTPResult } from "@antelopejs/interface-api";
|
|
@@ -112,13 +112,14 @@ export async function refresh(
|
|
|
112
112
|
const user = await userModel.get(payload.id);
|
|
113
113
|
if (!user) throw new HTTPResult(UNAUTHORIZED, "error.invalid_token");
|
|
114
114
|
|
|
115
|
-
if (payload.sessionId) {
|
|
116
|
-
|
|
117
|
-
if (!session || !isCurrentRefreshToken(session, token)) {
|
|
118
|
-
throw new HTTPResult(UNAUTHORIZED, "error.session_expired");
|
|
119
|
-
}
|
|
120
|
-
await sessionModel.update(payload.sessionId, { lastActiveAt: new Date() });
|
|
115
|
+
if (!payload.sessionId) {
|
|
116
|
+
throw new HTTPResult(UNAUTHORIZED, "error.invalid_token");
|
|
121
117
|
}
|
|
118
|
+
const session = await sessionModel.get(payload.sessionId);
|
|
119
|
+
if (!session || !isCurrentRefreshToken(session, token)) {
|
|
120
|
+
throw new HTTPResult(UNAUTHORIZED, "error.session_expired");
|
|
121
|
+
}
|
|
122
|
+
await sessionModel.update(payload.sessionId, { lastActiveAt: new Date() });
|
|
122
123
|
|
|
123
124
|
const access = await generateAccessToken(
|
|
124
125
|
payload.tenantId,
|
|
@@ -209,11 +210,12 @@ A tenant-assignment token lives fifteen minutes. `validateTenantAssignmentToken`
|
|
|
209
210
|
|
|
210
211
|
```typescript
|
|
211
212
|
import {
|
|
213
|
+
createSession,
|
|
212
214
|
generateAccessToken,
|
|
213
215
|
generateTenantAssignmentToken,
|
|
214
216
|
validateTenantAssignmentToken,
|
|
215
217
|
} from "@antelopejs/interface-dms/auth";
|
|
216
|
-
import type { User } from "@antelopejs/interface-dms/auth/db";
|
|
218
|
+
import type { SessionModel, User } from "@antelopejs/interface-dms/auth/db";
|
|
217
219
|
|
|
218
220
|
export async function offerTenantAssignment(user: User) {
|
|
219
221
|
const { token } = await generateTenantAssignmentToken(user);
|
|
@@ -221,12 +223,14 @@ export async function offerTenantAssignment(user: User) {
|
|
|
221
223
|
}
|
|
222
224
|
|
|
223
225
|
export async function completeTenantAssignment(
|
|
226
|
+
sessionModel: SessionModel,
|
|
224
227
|
assignmentToken: string,
|
|
225
228
|
tenantId: string,
|
|
226
229
|
) {
|
|
227
230
|
const { user } = await validateTenantAssignmentToken(assignmentToken);
|
|
228
231
|
// the caller attaches the user to `tenantId` before issuing real tokens
|
|
229
|
-
|
|
232
|
+
const sessionId = await createSession(sessionModel, user._id, "", "");
|
|
233
|
+
return generateAccessToken(tenantId, user, sessionId);
|
|
230
234
|
}
|
|
231
235
|
```
|
|
232
236
|
|
|
@@ -246,7 +250,7 @@ export interface JwtUserPayload {
|
|
|
246
250
|
| ----- | ---- | ----------- |
|
|
247
251
|
| `id` | `string` | The `_id` of the user the token was issued for. |
|
|
248
252
|
| `tenantId` | `string` | The tenant the token is scoped to. |
|
|
249
|
-
| `sessionId` | `string \| undefined` | The `Session` row behind the token
|
|
253
|
+
| `sessionId` | `string \| undefined` | The `Session` row behind the token. Every access and refresh token carries it. |
|
|
250
254
|
|
|
251
255
|
`TenantTokenInput`, from [Authentication](/docs/interfaces/auth/authentication), describes the same subject from the other side. It is what a validator receives: `id` and `tenantId`, plus the undecoded `rawToken`. `JwtUserPayload` is what the token itself says. The two types share `id` and `tenantId`, and neither is a subset of the other.
|
|
252
256
|
|
package/docs/3.base/6.layout.md
CHANGED
|
@@ -219,9 +219,9 @@ static preview = Placeholder({ label: "Chart goes here", height: "200px" });
|
|
|
219
219
|
```typescript fragment
|
|
220
220
|
import { CustomComponent } from "@antelopejs/interface-dms/base/custom";
|
|
221
221
|
|
|
222
|
-
static
|
|
223
|
-
name: "
|
|
224
|
-
icon: "i-ph-
|
|
222
|
+
static changes = CustomComponent("DmsAssistantChangesView").meta({
|
|
223
|
+
name: "Changes",
|
|
224
|
+
icon: "i-ph-git-diff",
|
|
225
225
|
});
|
|
226
226
|
```
|
|
227
227
|
|
|
@@ -8,7 +8,7 @@ mode: reference
|
|
|
8
8
|
|
|
9
9
|
The `html-render` domain of `@antelopejs/interface-dms` turns a named template and a props object into an HTML string. You declare a template once with `RegisterHtmlTemplate`. It records the name in a process-wide registry and returns a typed reference. Pass that reference to `GenerateHtml` to get the rendered HTML.
|
|
10
10
|
|
|
11
|
-
The backend process does not render anything itself. `GenerateHtml` sends an HTTP `POST` to the render
|
|
11
|
+
The backend process does not render anything itself. `GenerateHtml` sends an HTTP `POST` to the dashboard's `/api/html/render`, or to `htmlRender.renderEndpoint` when the DMS configures one, authenticated with a signed service token, and returns the HTML the endpoint sends back. The backend owns the template names and the props types. The markup lives with the renderer behind that endpoint.
|
|
12
12
|
|
|
13
13
|
The interface produces HTML and nothing else. Your code delivers that HTML, as a transactional email, a file or a response body.
|
|
14
14
|
|
|
@@ -148,7 +148,7 @@ export async function renderInvoice(
|
|
|
148
148
|
}
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
The call sends `{ templateName, props }` as JSON to
|
|
151
|
+
The call sends `{ templateName, props }` as JSON to the render endpoint. It carries a service token signed with `htmlRender.serviceSecret` in the `x-dms-service-token` header, and it reads the `html` field of the JSON response.
|
|
152
152
|
|
|
153
153
|
`GenerateHtml` does not look the name up in the registry before the call. It sends whatever name the reference carries. When the render endpoint does not know the name, the promise rejects. The backend runs no missing-template check of its own.
|
|
154
154
|
|
|
@@ -284,7 +284,7 @@ Types the `htmlRender` block of the DMS module configuration in `antelope.config
|
|
|
284
284
|
|
|
285
285
|
| Option | Type | Description |
|
|
286
286
|
| ------ | ---- | ----------- |
|
|
287
|
-
| `renderEndpoint` | `string` | The absolute URL `GenerateHtml` posts to. Default
|
|
287
|
+
| `renderEndpoint` | `string` | The absolute URL `GenerateHtml` posts to. Default `/api/html/render` on the dashboard's current origin: the one `ajs dms dev` serves, else the DMS's `clientBaseUrl`. |
|
|
288
288
|
| `serviceSecret` | `string` | The secret that signs the service token of each render call. Default `"dev"`. The DMS refuses a production start when the value is empty or `"dev"`. |
|
|
289
289
|
| `serviceTokenLifetime` | `number` | The lifetime of that service token, in milliseconds. The frontend render server rejects a token valid for more than five minutes. Default `300000` (five minutes). |
|
|
290
290
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-dms",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3-next.916.gd319141",
|
|
4
4
|
"description": "Public AntelopeJS interfaces of the DMS: pages, components, permissions, tenancy, auth, notifications and HTML rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -43,26 +43,26 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"randomstring": "^1.3.1",
|
|
46
|
-
"zod": "^3.
|
|
46
|
+
"zod": "^3.25.0",
|
|
47
47
|
"zod-to-json-schema": "~3.24.6"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@antelopejs/interface-api": ">=0.3.0 <
|
|
51
|
-
"@antelopejs/interface-api-util": ">=0.
|
|
52
|
-
"@antelopejs/interface-core": ">=0.5.1 <
|
|
50
|
+
"@antelopejs/interface-api": ">=0.3.0 <0.4.0",
|
|
51
|
+
"@antelopejs/interface-api-util": ">=0.3.0 <0.4.0",
|
|
52
|
+
"@antelopejs/interface-core": ">=0.5.1 <0.6.0",
|
|
53
53
|
"@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
|
|
54
54
|
"@antelopejs/interface-database": ">=0.4.0 <0.5.0",
|
|
55
55
|
"@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
|
|
56
|
-
"@antelopejs/interface-file-storage": ">=0.1.4 <
|
|
56
|
+
"@antelopejs/interface-file-storage": ">=0.1.4 <0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@antelopejs/interface-api": ">=0.3.0 <
|
|
60
|
-
"@antelopejs/interface-api-util": ">=0.3.0 <
|
|
61
|
-
"@antelopejs/interface-core": ">=0.5.1 <
|
|
59
|
+
"@antelopejs/interface-api": ">=0.3.0 <0.4.0",
|
|
60
|
+
"@antelopejs/interface-api-util": ">=0.3.0 <0.4.0",
|
|
61
|
+
"@antelopejs/interface-core": ">=0.5.1 <0.6.0",
|
|
62
62
|
"@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
|
|
63
63
|
"@antelopejs/interface-database": ">=0.4.0 <0.5.0",
|
|
64
64
|
"@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
|
|
65
|
-
"@antelopejs/interface-file-storage": ">=0.1.4 <
|
|
65
|
+
"@antelopejs/interface-file-storage": ">=0.1.4 <0.2.0",
|
|
66
66
|
"@types/node": "^24.0.0",
|
|
67
67
|
"@types/randomstring": "^1.3.0",
|
|
68
68
|
"knip": "^6.34.0",
|