@antelopejs/interface-dms 0.14.0 → 0.14.2
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 +78 -0
- package/README.md +4 -4
- package/dist/db/internal/inviteResolutions.model.d.ts +13 -0
- package/dist/db/internal/inviteResolutions.model.js +38 -0
- package/dist/db/internal/inviteResolutions.model.js.map +1 -1
- 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/internal/invite-resolution.js +5 -2
- package/dist/internal/invite-resolution.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 +142 -18
- 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/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
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
|
+
|
|
46
|
+
## v0.14.1
|
|
47
|
+
|
|
48
|
+
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.14.0...v0.14.1)
|
|
49
|
+
|
|
50
|
+
### 🩹 Fixes
|
|
51
|
+
|
|
52
|
+
- **dms:** Restrict credential files to their owner on Windows ([#1008](https://github.com/AntelopeJS/dms/pull/1008))
|
|
53
|
+
- **dms:** Keep a logo file the app config builds with +, concat or join ([#1024](https://github.com/AntelopeJS/dms/pull/1024))
|
|
54
|
+
- **interface-dms:** Keep one pending invite when a cancel, accept or expiry lands during a fresh invite's withdrawal ([#1021](https://github.com/AntelopeJS/dms/pull/1021))
|
|
55
|
+
- **dms:** Install a scaffolded module outside the project's pnpm workspace ([#1022](https://github.com/AntelopeJS/dms/pull/1022))
|
|
56
|
+
- **dms:** Check preview_blocks sketches with the mockup compiler's sanitizer and publish it as @antelopejs/dms/sketch ([#1009](https://github.com/AntelopeJS/dms/pull/1009))
|
|
57
|
+
|
|
58
|
+
### 📖 Documentation
|
|
59
|
+
|
|
60
|
+
- **interface-dms-builder:** Say when a second catalog provider needs exportPriority or a pin ([#1026](https://github.com/AntelopeJS/dms/pull/1026))
|
|
61
|
+
|
|
62
|
+
### 🏡 Chore
|
|
63
|
+
|
|
64
|
+
- **release:** @antelopejs/interface-dms-builder v0.5.1 ([77d48d67](https://github.com/AntelopeJS/dms/commit/77d48d67))
|
|
65
|
+
- **release:** @antelopejs/dms v0.20.0 ([b540c6be](https://github.com/AntelopeJS/dms/commit/b540c6be))
|
|
66
|
+
|
|
67
|
+
### ✅ Tests
|
|
68
|
+
|
|
69
|
+
- **dms:** Let the invite host take any zod 3.x and spawn npm through its Windows shim ([#1023](https://github.com/AntelopeJS/dms/pull/1023))
|
|
70
|
+
- **dms:** Load TableView in the table runtime setup, not the first test ([#1025](https://github.com/AntelopeJS/dms/pull/1025))
|
|
71
|
+
- **dms:** Acknowledge test MongoDB writes on apply so Windows integration runs stop stalling ([#1027](https://github.com/AntelopeJS/dms/pull/1027))
|
|
72
|
+
|
|
73
|
+
### 🤖 CI
|
|
74
|
+
|
|
75
|
+
- Run the CI on Windows in parallel with Linux ([#906](https://github.com/AntelopeJS/dms/pull/906))
|
|
76
|
+
|
|
77
|
+
### ❤️ Contributors
|
|
78
|
+
|
|
79
|
+
- Antony Rizzitelli ([@Upd4ting](http://github.com/Upd4ting))
|
|
80
|
+
|
|
3
81
|
## v0.14.0
|
|
4
82
|
|
|
5
83
|
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.13.3...v0.14.0)
|
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
67
|
| `@antelopejs/interface-database` | `>=0.4.0 <0.5.0` | `0.4.0` |
|
|
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,5 @@
|
|
|
1
1
|
import { type InviteMembershipPhase, InviteResolution } from "../tables/inviteResolutions.table";
|
|
2
|
+
import type { UserInvite } from "../tables/user_invites.table";
|
|
2
3
|
import type { InviteDecision } from "../models/inviteResolutions.model";
|
|
3
4
|
declare const InviteResolutionsModel_base: {
|
|
4
5
|
new (database: import("@antelopejs/interface-database").SchemaInstance<any>): {
|
|
@@ -36,6 +37,18 @@ export declare class InviteResolutionsModel extends InviteResolutionsModel_base
|
|
|
36
37
|
getForToken(token: string): Promise<InviteResolution | undefined>;
|
|
37
38
|
/** Reads the canonical decision even after a lost insert acknowledgement. */
|
|
38
39
|
decide(input: InviteDecision): Promise<InviteResolution>;
|
|
40
|
+
/**
|
|
41
|
+
* Claims the decision of a fresh invite that lost its email to a rival, so
|
|
42
|
+
* no replacement can be decided on it once it is withdrawn. The claim is
|
|
43
|
+
* stored completed: a withdrawn invite was never announced, so no hook
|
|
44
|
+
* reports its removal.
|
|
45
|
+
*
|
|
46
|
+
* @returns The invite's decision, and whether this call recorded it
|
|
47
|
+
*/
|
|
48
|
+
withdraw(tenantId: string, invite: UserInvite): Promise<{
|
|
49
|
+
resolution: InviteResolution;
|
|
50
|
+
claimed: boolean;
|
|
51
|
+
}>;
|
|
39
52
|
/** Advances a membership stage only against the exact observed revision. */
|
|
40
53
|
advanceMembership(resolution: InviteResolution, membershipPhase: InviteMembershipPhase, field?: "membershipPhase" | "replacementPhase"): Promise<boolean>;
|
|
41
54
|
}
|
|
@@ -67,6 +67,44 @@ class InviteResolutionsModel extends (0, interface_database_decorators_1.BasicDa
|
|
|
67
67
|
}
|
|
68
68
|
return resolution;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Claims the decision of a fresh invite that lost its email to a rival, so
|
|
72
|
+
* no replacement can be decided on it once it is withdrawn. The claim is
|
|
73
|
+
* stored completed: a withdrawn invite was never announced, so no hook
|
|
74
|
+
* reports its removal.
|
|
75
|
+
*
|
|
76
|
+
* @returns The invite's decision, and whether this call recorded it
|
|
77
|
+
*/
|
|
78
|
+
async withdraw(tenantId, invite) {
|
|
79
|
+
const id = decisionId(tenantId, invite._id);
|
|
80
|
+
const revision = (0, node_crypto_1.randomUUID)();
|
|
81
|
+
let insertError;
|
|
82
|
+
try {
|
|
83
|
+
await this.insert({
|
|
84
|
+
tenantId,
|
|
85
|
+
invite,
|
|
86
|
+
inviteToken: invite.token,
|
|
87
|
+
reason: "cancelled",
|
|
88
|
+
extensionKeys: [],
|
|
89
|
+
_id: id,
|
|
90
|
+
userId: null,
|
|
91
|
+
replacement: null,
|
|
92
|
+
revision,
|
|
93
|
+
membershipPhase: "pending",
|
|
94
|
+
replacementPhase: "pending",
|
|
95
|
+
completed: true,
|
|
96
|
+
decidedAt: new Date(),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
insertError = error;
|
|
101
|
+
}
|
|
102
|
+
const resolution = await this.get(id);
|
|
103
|
+
if (!resolution) {
|
|
104
|
+
throw insertError ?? new Error("Invite withdrawal was not persisted");
|
|
105
|
+
}
|
|
106
|
+
return { resolution, claimed: resolution.revision === revision };
|
|
107
|
+
}
|
|
70
108
|
/** Advances a membership stage only against the exact observed revision. */
|
|
71
109
|
async advanceMembership(resolution, membershipPhase, field = "membershipPhase") {
|
|
72
110
|
const nextRevision = (0, node_crypto_1.randomUUID)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inviteResolutions.model.js","sourceRoot":"","sources":["../../../src/db/internal/inviteResolutions.model.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,6FAA2E;AAC3E,+EAG2C;
|
|
1
|
+
{"version":3,"file":"inviteResolutions.model.js","sourceRoot":"","sources":["../../../src/db/internal/inviteResolutions.model.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,6FAA2E;AAC3E,+EAG2C;AAE3C,+CAA2D;AAG3D,SAAS,UAAU,CAAC,QAAgB,EAAE,QAAgB;IACpD,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC;SACxB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,IAAA,8CAAc,EACxD,0CAAgB,EAChB,wCAA0B,CAC3B;IACC,4EAA4E;IAC5E,KAAK,CAAC,YAAY,CAChB,QAAgB,EAChB,QAAgB;QAEhB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,KAAa;QAC7B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK;aACzB,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;aAC5B,GAAG,CAAC,CAAC,CAAC;aACN,OAAO,CAAC,SAAS,CAAC;aAClB,G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,MAAM,IAAI,CAAC,KAAK;aAC7B,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE;YAC9B,IAAI,EAAE,QAAQ;YACd,aAAa,EAAE,UAAU;YACzB,gBAAgB,EAAE,UAAU,CAAC,QAAQ;YACrC,YAAY;YACZ,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE;SACpC,CAAC;aACD,GAAG,EAAE,CAAC;QACT,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACvC,IAAI,OAAO,KAAK,aAAa;YAAE,OAAO,KAAK,CAAC;QAC5C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,OAAO,EAAE,QAAQ,KAAK,YAAY;YAAE,OAAO,IAAI,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,CAAC;CACF;AAhID,wDAgIC"}
|
|
@@ -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,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,EAAE,IAAA,6BAAc,EAAC,GAAG,CAAC,EAAE,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,KAAa;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;IAC1D,CAAC;CACF;AApID,0CAoIC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Table } from "@antelopejs/interface-database-decorators";
|
|
2
2
|
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,uBAAuB,GAAG,cAAc,CAAC;AACtD,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;
|
|
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,uBAAuB,GAAG,cAAc,CAAC;AACtD,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAMnD,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,qCAAK;CAwEpC,CAAA;AAxEY,gCAAU;AAEb;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;uCACI;AAKZ;IAHP,IAAA,qCAAK,EAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,4CAAY,GAAE;IACd,IAAA,qCAAK,EAAC,MAAM,CAAC;8BACK,IAAI;6CAAC;AAKhB;IAHP,IAAA,qCAAK,EAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACpD,IAAA,qCAAK,EAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,qCAAK,EAAC,QAAQ,CAAC;;yCACM;AAGd;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;6CACiB;AAGzB;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;4CACgB;AAIxB;IAFP,IAAA,qCAAK,EAAC,CAAC,QAAQ,CAAC,CAAC;IACjB,IAAA,wCAAQ,EAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,kBAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;6CACb;AAGpB;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;4CACS;AAIjB;IAFP,IAAA,qCAAK,EAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,qCAAK,EAAC,QAAQ,CAAC;;yCACM;AAGd;IADP,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"}
|
|
@@ -30,8 +30,11 @@ async function completeAdmittedInviteResolution(resolution) {
|
|
|
30
30
|
const current = await model.get(resolution._id);
|
|
31
31
|
if (!current)
|
|
32
32
|
throw new Error("Invite decision disappeared");
|
|
33
|
-
|
|
33
|
+
const invites = (0, interface_database_decorators_1.GetModel)(user_invites_model_1.UserInviteModel, current.tenantId);
|
|
34
|
+
if (current.completed) {
|
|
35
|
+
await invites.delete(current.invite._id);
|
|
34
36
|
return;
|
|
37
|
+
}
|
|
35
38
|
requireExtensions(current);
|
|
36
39
|
if (current.reason === "accepted")
|
|
37
40
|
await deliverAcceptance(current);
|
|
@@ -44,7 +47,7 @@ async function completeAdmittedInviteResolution(resolution) {
|
|
|
44
47
|
deliveryId: current._id,
|
|
45
48
|
});
|
|
46
49
|
await (0, invite_replacement_1.ensureInviteReplacement)(current);
|
|
47
|
-
await
|
|
50
|
+
await invites.delete(current.invite._id);
|
|
48
51
|
await model.update(current._id, { completed: true });
|
|
49
52
|
}
|
|
50
53
|
//# sourceMappingURL=invite-resolution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invite-resolution.js","sourceRoot":"","sources":["../../src/internal/invite-resolution.ts"],"names":[],"mappings":";;AAmCA,
|
|
1
|
+
{"version":3,"file":"invite-resolution.js","sourceRoot":"","sources":["../../src/internal/invite-resolution.ts"],"names":[],"mappings":";;AAmCA,4EAwBC;AA3DD,6FAAqE;AACrE,oFAAgF;AAEhF,wEAAkE;AAClE,oCAA8C;AAC9C,qEAA8E;AAC9E,qEAAiF;AACjF,2DAA6D;AAC7D,6DAA+D;AAE/D,SAAS,iBAAiB,CAAC,UAA4B;IACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,IAAA,+BAAoB,GAAE,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CACzD,CAAC;IACF,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,IAAI,OAAO,CAAC,MAAM;QAChB,MAAM,IAAI,KAAK,CAAC,sCAAsC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,UAA4B;IAC3D,MAAM,MAAM,GAAG,MAAM,IAAA,0CAAsB,EAAC,UAAU,CAAC,CAAC;IACxD,MAAM,IAAA,k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,CAAC,UAAU;QACrC,UAAU,EAAE,OAAO,CAAC,GAAG;KACxB,CAAC,CAAC;IACH,MAAM,IAAA,4CAAuB,EAAC,OAAO,CAAC,CAAC;IACvC,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -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,QAAQ,CAAC,CAAC;IACnC,OAAO,UAAU,EAAE,MAAM,CAAC;AAC5B,CAAC;AAED,0EAA0E;AACnE,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,MAAkB;IAElB,IAAI,CAAC,MAAM,CAAC,oBAAoB;QAAE,OAAO;IACzC,MAAM,MAAM,GAAG,MAAM,IAAA,wCAAQ,EAAC,gDAAsB,EAAE,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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
|
@@ -12,6 +12,7 @@ const logging_1 = require("@antelopejs/interface-core/logging");
|
|
|
12
12
|
const interface_database_1 = require("@antelopejs/interface-database");
|
|
13
13
|
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
14
14
|
const db_1 = require("./db");
|
|
15
|
+
const inviteResolutions_model_1 = require("./db/internal/inviteResolutions.model");
|
|
15
16
|
const db_2 = require("./auth/db");
|
|
16
17
|
const randomstring_1 = __importDefault(require("randomstring"));
|
|
17
18
|
const fire_and_forget_1 = require("./utils/fire-and-forget");
|
|
@@ -135,21 +136,8 @@ async function createAdmittedInviteToken(options) {
|
|
|
135
136
|
const userInviteModel = (0, interface_database_decorators_1.GetModel)(db_1.UserInviteModel, tenantId);
|
|
136
137
|
const existingInvite = options.replacesInvite ?? (await userInviteModel.getByEmail(email));
|
|
137
138
|
const replacement = buildInviteSnapshot(options);
|
|
138
|
-
if (existingInvite)
|
|
139
|
-
|
|
140
|
-
tenantId,
|
|
141
|
-
invite: existingInvite,
|
|
142
|
-
reason: options.replacementReason ?? "replaced",
|
|
143
|
-
replacement,
|
|
144
|
-
});
|
|
145
|
-
await (0, invite_resolution_1.completeAdmittedInviteResolution)(resolution);
|
|
146
|
-
if (!resolution.replacement)
|
|
147
|
-
throw new Error("Replacement snapshot missing");
|
|
148
|
-
return {
|
|
149
|
-
inviteId: resolution.replacement._id,
|
|
150
|
-
token: resolution.replacement.token,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
139
|
+
if (existingInvite)
|
|
140
|
+
return replaceInvite(options, existingInvite, replacement);
|
|
153
141
|
await (0, hooks_1.ExecuteHooks)(hooks_1.Hook.INVITE_BEING_CREATED, {
|
|
154
142
|
tenantId,
|
|
155
143
|
email,
|
|
@@ -162,12 +150,17 @@ async function createAdmittedInviteToken(options) {
|
|
|
162
150
|
catch (error) {
|
|
163
151
|
if (!(0, interface_database_1.IsDuplicateKeyError)(error))
|
|
164
152
|
throw error;
|
|
165
|
-
|
|
153
|
+
const winner = await userInviteModel.getByEmail(email);
|
|
154
|
+
return yieldOrCreateAgain(options, winner && (await currentInviteOf(options, winner)), replacement);
|
|
166
155
|
}
|
|
167
156
|
const rival = await userInviteModel.getOtherByEmail(email, replacement._id);
|
|
168
157
|
if (rival) {
|
|
169
|
-
await userInviteModel.
|
|
170
|
-
|
|
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);
|
|
171
164
|
}
|
|
172
165
|
await (0, hooks_1.ExecuteHooks)(hooks_1.Hook.INVITE_CREATED, {
|
|
173
166
|
tenantId,
|
|
@@ -179,6 +172,137 @@ async function createAdmittedInviteToken(options) {
|
|
|
179
172
|
});
|
|
180
173
|
return { inviteId: replacement._id, token: replacement.token };
|
|
181
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
|
+
}
|
|
201
|
+
/**
|
|
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.
|
|
209
|
+
*
|
|
210
|
+
* @returns The retry, or undefined to keep the refusal
|
|
211
|
+
*/
|
|
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);
|
|
227
|
+
if (held?.reason !== "cancelled" || held.replacement || !held.completed)
|
|
228
|
+
return false;
|
|
229
|
+
await (0, invite_resolution_1.completeAdmittedInviteResolution)(held);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Withdraws a fresh invite that found a rival, through its decision: a
|
|
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.
|
|
237
|
+
*/
|
|
238
|
+
async function withdrawFreshInvite(options, fresh, rival) {
|
|
239
|
+
const { tenantId } = options;
|
|
240
|
+
const decisions = (0, interface_database_decorators_1.GetModel)(inviteResolutions_model_1.InviteResolutionsModel, tenantId);
|
|
241
|
+
const { resolution, claimed } = await decisions.withdraw(tenantId, fresh);
|
|
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);
|
|
305
|
+
}
|
|
182
306
|
function yieldToWinner(winner, lost) {
|
|
183
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");
|
|
184
308
|
return { inviteId: winner._id, token: winner.token };
|
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,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAEd,QAAA,mBAAmB,GAAG,EAAE,CAAC;AACzB,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,aAAa,GAAG,GAAG,CAAC;AA6C1B;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,kBAAkB,CACtC,OAAkC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,oCAAmB,EAAC,OAAO,CAAC,Q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AAS,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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-dms",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
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",
|