@memberjunction/core-entities 6.1.0-edge.2 → 6.1.0-edge.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +180 -4
- package/dist/custom/MJDashboardEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJDashboardEntityExtended.js +140 -17
- package/dist/custom/MJDashboardEntityExtended.js.map +1 -1
- package/dist/engines/FileStorageEngine.d.ts.map +1 -1
- package/dist/engines/FileStorageEngine.js +1 -3
- package/dist/engines/FileStorageEngine.js.map +1 -1
- package/dist/engines/IdentityClaimEngine.d.ts +166 -0
- package/dist/engines/IdentityClaimEngine.d.ts.map +1 -0
- package/dist/engines/IdentityClaimEngine.js +140 -0
- package/dist/engines/IdentityClaimEngine.js.map +1 -0
- package/dist/engines/UserInfoEngine.d.ts.map +1 -1
- package/dist/engines/UserInfoEngine.js +13 -2
- package/dist/engines/UserInfoEngine.js.map +1 -1
- package/dist/engines/conversations.d.ts +169 -0
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +406 -3
- package/dist/engines/conversations.js.map +1 -1
- package/dist/generated/entity_subclasses.d.ts +3422 -383
- package/dist/generated/entity_subclasses.d.ts.map +1 -1
- package/dist/generated/entity_subclasses.js +5002 -1063
- package/dist/generated/entity_subclasses.js.map +1 -1
- package/dist/generated/remote_operations.d.ts +153 -2
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +144 -0
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,7 +1,183 @@
|
|
|
1
|
-
|
|
1
|
+
Business Source License 1.1
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB plc.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Blue Cypress, Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: MemberJunction.
|
|
13
|
+
The Licensed Work is (c) 2023-2026 Blue Cypress, Inc.
|
|
14
|
+
|
|
15
|
+
Additional Use Grant: Subject to the terms of this License, Licensor grants
|
|
16
|
+
you the following additional rights to make Production
|
|
17
|
+
Use of the Licensed Work.
|
|
18
|
+
|
|
19
|
+
1. Internal Use
|
|
20
|
+
|
|
21
|
+
You may make production use of the Licensed Work for
|
|
22
|
+
your own internal business or organizational operations.
|
|
23
|
+
|
|
24
|
+
2. Nonprofit Use
|
|
25
|
+
|
|
26
|
+
If you are a Nonprofit, you may make production use of
|
|
27
|
+
the Licensed Work for the operations and activities of
|
|
28
|
+
your Organizational Family.
|
|
29
|
+
|
|
30
|
+
3. MemberJunction Certified Program Use
|
|
31
|
+
|
|
32
|
+
If you are authorized by Licensor under the
|
|
33
|
+
MemberJunction Certified Program to provide professional
|
|
34
|
+
services using the Licensed Work, you may make
|
|
35
|
+
production use of the Licensed Work in providing such
|
|
36
|
+
professional services to a client, provided that:
|
|
37
|
+
|
|
38
|
+
(a) the Licensed Work is deployed in, and the applicable
|
|
39
|
+
production use occurs within, an environment owned,
|
|
40
|
+
leased, licensed, subscribed to, or otherwise controlled
|
|
41
|
+
by that client; and
|
|
42
|
+
|
|
43
|
+
(b) the production use is for that client's own internal
|
|
44
|
+
business or organizational operations or is otherwise
|
|
45
|
+
independently permitted to that client under this
|
|
46
|
+
Additional Use Grant.
|
|
47
|
+
|
|
48
|
+
4. Definitions Applicable to the Additional Use Grant
|
|
49
|
+
|
|
50
|
+
"Affiliate" means, with respect to a specified Person,
|
|
51
|
+
any other Person that directly or indirectly Controls,
|
|
52
|
+
is Controlled by, or is under common Control with such
|
|
53
|
+
specified Person.
|
|
54
|
+
|
|
55
|
+
"Control" (including the terms "Controls," "Controlled
|
|
56
|
+
by," and "under common Control with") means the direct
|
|
57
|
+
or indirect possession of the power to direct or cause
|
|
58
|
+
the direction of the management and policies of a
|
|
59
|
+
Person, whether through ownership of voting interests,
|
|
60
|
+
by contract, or otherwise.
|
|
61
|
+
|
|
62
|
+
"Organizational Family" means, with respect to a Person,
|
|
63
|
+
(a) such Person and its Affiliates, and (b) any
|
|
64
|
+
nonprofit organization, governmental entity, chapter,
|
|
65
|
+
division, local affiliate, regional affiliate, state
|
|
66
|
+
affiliate, national affiliate, or other entity that is
|
|
67
|
+
formally affiliated with such Person through governing
|
|
68
|
+
documents, a charter, bylaws, a membership agreement, or
|
|
69
|
+
another written organizational instrument, and is
|
|
70
|
+
recognized under such documents as part of the same
|
|
71
|
+
organizational structure.
|
|
72
|
+
|
|
73
|
+
"Nonprofit" means a Person recognized by the Internal
|
|
74
|
+
Revenue Service as exempt from federal income taxation
|
|
75
|
+
under Section 501(c)(3), 501(c)(4), 501(c)(5), or
|
|
76
|
+
501(c)(6) of the Internal Revenue Code, or a foreign
|
|
77
|
+
organization recognized under substantially equivalent
|
|
78
|
+
laws.
|
|
79
|
+
|
|
80
|
+
A Person claiming eligibility as a Nonprofit shall, upon
|
|
81
|
+
Licensor's reasonable request, provide documentation
|
|
82
|
+
reasonably sufficient to demonstrate that it qualifies
|
|
83
|
+
as a Nonprofit. If such Person materially misrepresents,
|
|
84
|
+
or is unable to demonstrate, its qualification as a
|
|
85
|
+
Nonprofit, the rights granted to such Person under
|
|
86
|
+
Section 2 of this Additional Use Grant shall terminate.
|
|
87
|
+
|
|
88
|
+
"MemberJunction Certified Program" means Licensor's
|
|
89
|
+
then-current program for certifying and authorizing a
|
|
90
|
+
Person to provide professional services using the
|
|
91
|
+
Licensed Work.
|
|
92
|
+
|
|
93
|
+
"Person" means any individual, corporation, limited
|
|
94
|
+
liability company, partnership, association, nonprofit
|
|
95
|
+
organization, governmental entity, or other legal or
|
|
96
|
+
organizational entity.
|
|
97
|
+
|
|
98
|
+
Change Date: Four (4) years from the date the Licensed Work is first
|
|
99
|
+
made available.
|
|
100
|
+
|
|
101
|
+
Change License: MIT License.
|
|
102
|
+
|
|
103
|
+
For information about alternative licensing arrangements for the Licensed
|
|
104
|
+
Work, please contact Blue Cypress, Inc.
|
|
105
|
+
|
|
106
|
+
-----------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
Terms
|
|
109
|
+
|
|
110
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
111
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
112
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
113
|
+
production use.
|
|
114
|
+
|
|
115
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
116
|
+
available distribution of a specific version of the Licensed Work under this
|
|
117
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
118
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
119
|
+
above terminate.
|
|
120
|
+
|
|
121
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
122
|
+
currently in effect as described in this License, you must purchase a
|
|
123
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
124
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
125
|
+
|
|
126
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
127
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
128
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
129
|
+
for each version of the Licensed Work released by Licensor.
|
|
130
|
+
|
|
131
|
+
You must conspicuously display this License on each original or modified copy
|
|
132
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
133
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
134
|
+
License apply to your use of that work.
|
|
135
|
+
|
|
136
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
137
|
+
terminate your rights under this License for the current and all other
|
|
138
|
+
versions of the Licensed Work.
|
|
139
|
+
|
|
140
|
+
This License does not grant you any right in any trademark or logo of
|
|
141
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
142
|
+
Licensor as expressly required by this License).
|
|
143
|
+
|
|
144
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
145
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
146
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
147
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
148
|
+
TITLE.
|
|
149
|
+
|
|
150
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
151
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
152
|
+
as long as you comply with the Covenants of Licensor below.
|
|
153
|
+
|
|
154
|
+
-----------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
Covenants of Licensor
|
|
157
|
+
|
|
158
|
+
In consideration of the right to use this License's text and the "Business
|
|
159
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
160
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
161
|
+
|
|
162
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
163
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
164
|
+
where "compatible" means that software provided under the Change License
|
|
165
|
+
can be included in a program with software provided under GPL Version 2.0
|
|
166
|
+
or a later version. Licensor may specify additional Change Licenses without
|
|
167
|
+
limitation.
|
|
168
|
+
|
|
169
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
170
|
+
impose any additional restriction on the right granted in this License, as
|
|
171
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
172
|
+
|
|
173
|
+
3. To specify a Change Date.
|
|
174
|
+
|
|
175
|
+
4. Not to modify this License in any other way.
|
|
176
|
+
|
|
177
|
+
-----------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
Notice
|
|
180
|
+
|
|
181
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
182
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
183
|
+
under an Open Source License, as stated in this License.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJDashboardEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJDashboardEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,mBAAmB,EAA+B,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAkD,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"MJDashboardEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJDashboardEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,mBAAmB,EAA+B,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAkD,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AA+CnE,qBACa,yBAA0B,SAAQ,iBAAiB;IACrD,SAAS,IAAI,OAAO;IA4B3B;;;;OAIG;IACa,QAAQ,IAAI,gBAAgB;IA8G5C;;;OAGG;IACmB,MAAM,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;CAiDhF"}
|
|
@@ -8,6 +8,49 @@ import { BaseEntity, LogError } from "@memberjunction/core";
|
|
|
8
8
|
import { RegisterClass, UUIDsEqual, ValidationErrorInfo } from "@memberjunction/global";
|
|
9
9
|
import { MJDashboardEntity } from "../generated/entity_subclasses.js";
|
|
10
10
|
import { DashboardEngine } from "../engines/dashboards.js";
|
|
11
|
+
/**
|
|
12
|
+
* The owner as stored in the database, ignoring any pending change to `UserID`.
|
|
13
|
+
*
|
|
14
|
+
* `BaseEntity` keeps the loaded value on the field as `OldValue`, which is what makes this
|
|
15
|
+
* answerable without a round trip. For a record that was loaded and not modified, `OldValue`
|
|
16
|
+
* and the current value agree; the two diverge exactly when someone is trying to change the
|
|
17
|
+
* owner, which is the case this exists to see through.
|
|
18
|
+
*
|
|
19
|
+
* **`OldValue` is only trustworthy when the server loaded the row itself.**
|
|
20
|
+
* `ResolverBase.UpdateRecord` takes two paths: when the entity has `TrackRecordChanges` it
|
|
21
|
+
* re-reads the record server-side, but when it does NOT, it hydrates from the client-supplied
|
|
22
|
+
* `OldValues___` — and first-set hydration writes `Value` *and* `OldValue`. On that path
|
|
23
|
+
* `OldValue` is attacker-controlled and both gates below would read whatever the caller sent.
|
|
24
|
+
* `MJ: Dashboards` ships with `TrackRecordChanges = 1`, but it is an ordinary admin-editable
|
|
25
|
+
* field — MJ has already shipped a migration disabling it on other transient entities — and
|
|
26
|
+
* `EntityInfo` declares it `boolean = null` with no coercion, so a metadata row missing the key
|
|
27
|
+
* reads falsy too. Either way this returns `null` rather than a guessable value, and the
|
|
28
|
+
* callers withhold the owner shortcut instead of trusting it.
|
|
29
|
+
*
|
|
30
|
+
* Note this is a CONSERVATIVE proxy for the real condition. `ResolverBase` re-reads when
|
|
31
|
+
* `TrackRecordChanges || !input.OldValues___`, so a caller that supplies no `OldValues___` also
|
|
32
|
+
* gets a server-loaded row and a trustworthy `OldValue` — this returns null there anyway,
|
|
33
|
+
* costing that caller the owner shortcut. That is the safe direction to be wrong in, and it
|
|
34
|
+
* only ever falls back to the pre-existing engine check. The precise fix is for `BaseEntity` to
|
|
35
|
+
* expose whether the instance was server-hydrated; until it does, this errs toward refusing to
|
|
36
|
+
* trust.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately a MODULE-LEVEL function, not a class member. A `protected` (or `private`) method
|
|
39
|
+
* makes the subclass structurally distinct from `MJDashboardEntity`, and the codebase assigns
|
|
40
|
+
* across those two types (`BaseDashboard`'s `DashboardConfig.dashboard`), so adding one breaks
|
|
41
|
+
* compilation in consumers that never touch this logic.
|
|
42
|
+
*/
|
|
43
|
+
function persistedUserID(entity) {
|
|
44
|
+
if (!entity.EntityInfo?.TrackRecordChanges) {
|
|
45
|
+
// Fail closed. Without server-side re-read there is no trustworthy persisted value
|
|
46
|
+
// here, and the alternative — falling back to `entity.UserID` — is precisely the
|
|
47
|
+
// client-supplied value the gate exists to distrust.
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const field = entity.GetFieldByName('UserID');
|
|
51
|
+
const persisted = field?.OldValue;
|
|
52
|
+
return typeof persisted === 'string' && persisted.length > 0 ? persisted : entity.UserID;
|
|
53
|
+
}
|
|
11
54
|
let MJDashboardEntityExtended = class MJDashboardEntityExtended extends MJDashboardEntity {
|
|
12
55
|
NewRecord() {
|
|
13
56
|
try {
|
|
@@ -49,26 +92,78 @@ let MJDashboardEntityExtended = class MJDashboardEntityExtended extends MJDashbo
|
|
|
49
92
|
result.Errors.push(new ValidationErrorInfo('Permission', 'You must be logged in to save a dashboard', null));
|
|
50
93
|
return result;
|
|
51
94
|
}
|
|
52
|
-
// For existing records (not new), check edit permission
|
|
95
|
+
// For existing records (not new), check edit permission.
|
|
96
|
+
//
|
|
97
|
+
// Ownership is answered from THIS ROW, not from the engine. GetDashboardPermissions reads
|
|
98
|
+
// DashboardEngine's backing array directly, so an engine that was never Config()'d is
|
|
99
|
+
// indistinguishable from "this dashboard grants you nothing" — and every caller is refused,
|
|
100
|
+
// the owner included. That is not hypothetical: any process using the default `task`
|
|
101
|
+
// startup mode defers engine pre-warm, which is why `mj sync push` failed on a dashboard
|
|
102
|
+
// whose UserID *was* the pushing user.
|
|
103
|
+
//
|
|
104
|
+
// The owner case needs no cache — the persisted `UserID` is on the record being validated.
|
|
105
|
+
// Resolving it first fixes the defect without weakening the gate: a non-owner still cannot
|
|
106
|
+
// pass on an unevaluable cache, which is the direction a permission check should fail.
|
|
107
|
+
// Validate() is synchronous and cannot await Config(), so a non-owner whose grant lives
|
|
108
|
+
// only in the engine is refused when the cache is cold — the pre-existing behaviour for
|
|
109
|
+
// that case, deliberately left as-is rather than opened up.
|
|
53
110
|
if (this.IsSaved) {
|
|
54
|
-
const
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
111
|
+
const persistedOwnerID = persistedUserID(this);
|
|
112
|
+
// NOTE — supersedes upstream's `ownsRecord` fallback (255d506404, "a dashboard's owner
|
|
113
|
+
// can save when the engine is unloaded"). That fix solved the same cold-cache problem by
|
|
114
|
+
// trusting `this.UserID` whenever `DashboardEngine.Instance.Loaded` was false — but
|
|
115
|
+
// `UserID` is client-settable on the update path, so a caller who can load a dashboard
|
|
116
|
+
// could set it to themselves and, on any process where the engine happens to be cold,
|
|
117
|
+
// be granted edit on someone else's record. Reading the PERSISTED owner fixes the cold
|
|
118
|
+
// cache the same way (the row carries the answer; no engine needed) without ever
|
|
119
|
+
// trusting a value the caller supplied.
|
|
120
|
+
// The check MUST read the persisted owner, never `this.UserID`. `UserID` is a settable
|
|
121
|
+
// field on UpdateMJDashboardInput, and ResolverBase.UpdateRecord loads the row and then
|
|
122
|
+
// applies the client's values BEFORE Save() runs Validate(). Trusting the in-memory
|
|
123
|
+
// value would let any user who can load a dashboard send
|
|
124
|
+
// `UpdateMJDashboard(ID: <someone else's>, UserID: <self>)`, satisfy the owner branch
|
|
125
|
+
// with the value they just supplied, and take ownership of the record.
|
|
126
|
+
//
|
|
127
|
+
// A NULL persisted owner means that value is not trustworthy here (see
|
|
128
|
+
// persistedUserID). It must not open the owner branch — but it must not refuse the save
|
|
129
|
+
// either. Refusing turns an auditing setting into a total outage: nobody, owner
|
|
130
|
+
// included, could update any dashboard. Instead the owner shortcut is simply withheld
|
|
131
|
+
// and the engine decides, which is exactly the behaviour before this fix existed. That
|
|
132
|
+
// is strictly no weaker than the shipped baseline while still closing the escalation.
|
|
133
|
+
if (persistedOwnerID === null || !UUIDsEqual(persistedOwnerID, currentUser.ID)) {
|
|
134
|
+
const permissions = DashboardEngine.Instance.GetDashboardPermissions(this.ID, currentUser.ID);
|
|
135
|
+
if (!permissions.CanEdit) {
|
|
136
|
+
result.Success = false;
|
|
137
|
+
result.Errors.push(new ValidationErrorInfo('Permission', 'You do not have permission to edit this dashboard', this.ID));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Reassigning ownership is an owner-only act, and separate from being able to edit.
|
|
141
|
+
// A user granted CanEdit through a share must not be able to make the dashboard theirs.
|
|
60
142
|
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
143
|
+
// ⚠️ KNOWN LIMITATION when `persistedOwnerID` is null (change tracking off). `Dirty` is
|
|
144
|
+
// `Value !== OldValue`, and on that path BOTH sides come from the client: the resolver
|
|
145
|
+
// hydrates from `OldValues___`, and first-set hydration writes `Value` *and* `OldValue`.
|
|
146
|
+
// A caller who sends `OldValues___.UserID = <self>` alongside `UserID = <self>` presents
|
|
147
|
+
// a field that is NOT dirty while the value is already theirs, so this gate does not
|
|
148
|
+
// fire and the transfer proceeds. It catches an honest client, not a hostile one.
|
|
64
149
|
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
150
|
+
// This is deliberately not "fixed" by tightening the predicate — every signal reachable
|
|
151
|
+
// from here is client-supplied on that path. The real fix is for `BaseEntity` to expose
|
|
152
|
+
// whether the instance was server-hydrated (or for this to do a provider round-trip),
|
|
153
|
+
// and `Validate()` being synchronous is what rules the round-trip out today. Until then
|
|
154
|
+
// the shipped default (`TrackRecordChanges = 1`) is what keeps this closed, and that
|
|
155
|
+
// coupling is now stated rather than assumed.
|
|
156
|
+
if (persistedOwnerID === null) {
|
|
157
|
+
const field = this.GetFieldByName('UserID');
|
|
158
|
+
if (field?.Dirty) {
|
|
159
|
+
result.Success = false;
|
|
160
|
+
result.Errors.push(new ValidationErrorInfo('UserID', 'Dashboard ownership cannot be transferred while change tracking is disabled for ' +
|
|
161
|
+
'MJ: Dashboards, because the current owner cannot be verified.', this.ID));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (!UUIDsEqual(this.UserID, persistedOwnerID) && !UUIDsEqual(persistedOwnerID, currentUser.ID)) {
|
|
70
165
|
result.Success = false;
|
|
71
|
-
result.Errors.push(new ValidationErrorInfo('
|
|
166
|
+
result.Errors.push(new ValidationErrorInfo('UserID', 'Only the owner of a dashboard can transfer its ownership', this.ID));
|
|
72
167
|
}
|
|
73
168
|
}
|
|
74
169
|
return result;
|
|
@@ -84,7 +179,35 @@ let MJDashboardEntityExtended = class MJDashboardEntityExtended extends MJDashbo
|
|
|
84
179
|
LogError('Cannot delete dashboard: User not authenticated');
|
|
85
180
|
return false;
|
|
86
181
|
}
|
|
87
|
-
//
|
|
182
|
+
// The owner is answered from the persisted row, for the same reason as in Validate():
|
|
183
|
+
// it needs no cache, and a cache that is merely stale — a dashboard created since the
|
|
184
|
+
// last Config() is absent from the backing array — otherwise refuses its own owner.
|
|
185
|
+
//
|
|
186
|
+
// A null answer means the persisted owner is not trustworthy (see persistedUserID), so
|
|
187
|
+
// this shortcut is skipped and the delete falls through to the engine. Unlike Validate(),
|
|
188
|
+
// that costs nothing here beyond a load — the engine is the authoritative source, and
|
|
189
|
+
// this path is async and can consult it.
|
|
190
|
+
const persistedOwnerID = persistedUserID(this);
|
|
191
|
+
if (persistedOwnerID !== null && UUIDsEqual(persistedOwnerID, currentUser.ID)) {
|
|
192
|
+
return super.Delete(options);
|
|
193
|
+
}
|
|
194
|
+
// Not the owner, so the grant can only come from the engine. Unlike Validate(), this path
|
|
195
|
+
// is async, so it can load the engine rather than guess.
|
|
196
|
+
//
|
|
197
|
+
// The load is GUARDED because it is the one thing here that can throw, and `Delete()` is
|
|
198
|
+
// documented to report logical failure by RETURNING FALSE, not by throwing — callers check
|
|
199
|
+
// the boolean and read `LatestResult`. Letting a Config() rejection escape would change
|
|
200
|
+
// this method's contract for every caller as a side effect of consulting the engine, and it
|
|
201
|
+
// would do so only on the cold-cache path, which is the one nobody exercises. A failure to
|
|
202
|
+
// load the permission source is a refusal to delete, which is the safe direction: it can
|
|
203
|
+
// never turn into an accidental grant.
|
|
204
|
+
try {
|
|
205
|
+
await DashboardEngine.Instance.Config(false, currentUser, this.ProviderToUse);
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
LogError(`Cannot delete dashboard ${this.ID}: loading dashboard permissions failed: ${err}`);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
88
211
|
const permissions = DashboardEngine.Instance.GetDashboardPermissions(this.ID, currentUser.ID);
|
|
89
212
|
if (!permissions.CanDelete) {
|
|
90
213
|
LogError(`User ${currentUser.ID} does not have permission to delete dashboard ${this.ID}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJDashboardEntityExtended.js","sourceRoot":"","sources":["../../src/custom/MJDashboardEntityExtended.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAA0C,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,mBAAmB,EAAoB,MAAM,wBAAwB,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"MJDashboardEntityExtended.js","sourceRoot":"","sources":["../../src/custom/MJDashboardEntityExtended.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAA0C,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,mBAAmB,EAAoB,MAAM,wBAAwB,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAS,eAAe,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AG,0BAA0B,GAAG,IAAI;CAOtF"}
|
|
@@ -74,11 +74,9 @@ export class FileStorageEngineBase extends BaseEngine {
|
|
|
74
74
|
* Consumers should filter/sort as needed (e.g., by provider.IsActive).
|
|
75
75
|
*/
|
|
76
76
|
get AccountsWithProviders() {
|
|
77
|
-
const providerMap = new Map();
|
|
78
|
-
this.Providers.forEach(p => providerMap.set(p.ID, p));
|
|
79
77
|
return this.Accounts
|
|
80
78
|
.map(account => {
|
|
81
|
-
const provider =
|
|
79
|
+
const provider = this.Providers.find(p => UUIDsEqual(p.ID, account.ProviderID));
|
|
82
80
|
if (!provider)
|
|
83
81
|
return null;
|
|
84
82
|
return { account, provider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileStorageEngine.js","sourceRoot":"","sources":["../../src/engines/FileStorageEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyD,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAWpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,qBAAsB,SAAQ,UAAiC;IAA5E;;QAUY,cAAS,GAAiC,EAAE,CAAC;QAC7C,eAAU,GAAkC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"FileStorageEngine.js","sourceRoot":"","sources":["../../src/engines/FileStorageEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyD,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAWpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,qBAAsB,SAAQ,UAAiC;IAA5E;;QAUY,cAAS,GAAiC,EAAE,CAAC;QAC7C,eAAU,GAAkC,EAAE,CAAC;IA+G3D,CAAC;IAzHG;;;;OAIG;IACI,MAAM,KAAK,QAAQ;QACtB,OAAO,KAAK,CAAC,WAAW,EAAyB,CAAC;IACtD,CAAC;IAKD;;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identity claim types,
|
|
5
|
+
* cross-system entitlement claiming, account linking, and invite verification.
|
|
6
|
+
*
|
|
7
|
+
* @module @memberjunction/core-entities/IdentityClaimEngine
|
|
8
|
+
*/
|
|
9
|
+
import { BaseEngine, IMetadataProvider, UserInfo } from "@memberjunction/core";
|
|
10
|
+
import { MJIdentityClaimTypeEntity, MJIdentityClaimEntity } from "../generated/entity_subclasses.js";
|
|
11
|
+
/**
|
|
12
|
+
* Context passed to claim driver lifecycle methods
|
|
13
|
+
*/
|
|
14
|
+
export interface ClaimContext {
|
|
15
|
+
Claim: MJIdentityClaimEntity;
|
|
16
|
+
User?: UserInfo;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Context passed when a claim is redeemed
|
|
20
|
+
*/
|
|
21
|
+
export interface ClaimRedeemContext extends ClaimContext {
|
|
22
|
+
User: UserInfo;
|
|
23
|
+
RedemptionToken?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Result returned by a claim driver's OnClaim handler
|
|
27
|
+
*/
|
|
28
|
+
export interface ClaimResult {
|
|
29
|
+
Success: boolean;
|
|
30
|
+
ErrorMessage?: string;
|
|
31
|
+
Data?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Abstract base driver for pluggable claim type behaviors.
|
|
35
|
+
* Concrete subclasses register via `@RegisterClass(BaseIdentityClaimDriver, DriverClass)`.
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class BaseIdentityClaimDriver {
|
|
38
|
+
/**
|
|
39
|
+
* Called immediately after a claim is created.
|
|
40
|
+
*/
|
|
41
|
+
abstract OnCreate(context: ClaimContext): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Called when a claim is redeemed by an authenticated user.
|
|
44
|
+
*
|
|
45
|
+
* **Idempotency Requirement**: Implementations of `OnClaim` must be safe to re-run
|
|
46
|
+
* (idempotent). If downstream provisioning fails or throws an exception, the engine
|
|
47
|
+
* automatically reverts the atomic CAS state back to 'Pending' so the customer can retry.
|
|
48
|
+
*/
|
|
49
|
+
abstract OnClaim(context: ClaimRedeemContext): Promise<ClaimResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Called when a claim is explicitly revoked.
|
|
52
|
+
*/
|
|
53
|
+
abstract OnRevoke(context: ClaimContext): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Called when a claim is found to be expired or explicitly marked expired.
|
|
56
|
+
*/
|
|
57
|
+
abstract OnExpire(context: ClaimContext): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recognized keys of `IdentityClaimType.Configuration` (a JSON column). All keys are optional;
|
|
61
|
+
* absent keys fall back to the defaults documented per key. Unrecognized keys are preserved for
|
|
62
|
+
* driver-specific configuration but ignored by the engine.
|
|
63
|
+
*/
|
|
64
|
+
export interface IdentityClaimTypeConfiguration {
|
|
65
|
+
/**
|
|
66
|
+
* When true, the email-match redemption path requires the authenticated user's IdP to have
|
|
67
|
+
* positively asserted the email as verified (`EmailVerified === true`). When false/absent,
|
|
68
|
+
* email-match is refused only when the IdP explicitly asserted `EmailVerified === false`.
|
|
69
|
+
*/
|
|
70
|
+
RequireVerifiedEmail?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When true, redemption always requires the claim's verification token — an email match alone
|
|
73
|
+
* never redeems (which also excludes the type from automatic claim-on-login). Use for
|
|
74
|
+
* high-value claim types.
|
|
75
|
+
*/
|
|
76
|
+
RequireToken?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* When false, the type is skipped by automatic claim-on-login (`AutoClaimForUser`); explicit
|
|
79
|
+
* redemption via link/token still works. Defaults to true.
|
|
80
|
+
*/
|
|
81
|
+
AutoClaim?: boolean;
|
|
82
|
+
/** Driver-specific configuration may ride alongside the engine-recognized keys. */
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parameters for creating a new Identity Claim
|
|
87
|
+
*/
|
|
88
|
+
export interface CreateClaimParams {
|
|
89
|
+
/** Name of the IdentityClaimType */
|
|
90
|
+
ClaimTypeName?: string;
|
|
91
|
+
/** ID of the IdentityClaimType (if Name is not provided) */
|
|
92
|
+
ClaimTypeID?: string;
|
|
93
|
+
/** Email address of the intended recipient/claimant */
|
|
94
|
+
NormalizedEmail: string;
|
|
95
|
+
/** Optional polymorphic target entity ID */
|
|
96
|
+
EntityID?: string | null;
|
|
97
|
+
/** Optional target record primary key ID */
|
|
98
|
+
RecordID?: string | null;
|
|
99
|
+
/** Optional payload data for driver consumption */
|
|
100
|
+
Payload?: Record<string, unknown> | null;
|
|
101
|
+
/** Lifespan in days before expiration (defaults to ClaimType.DefaultExpirationDays) */
|
|
102
|
+
ExpiresInDays?: number;
|
|
103
|
+
/** Optional linked MagicLinkInvite ID for token verification */
|
|
104
|
+
MagicLinkInviteID?: string | null;
|
|
105
|
+
/** Optional tracking metadata */
|
|
106
|
+
Metadata?: Record<string, unknown> | null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Client + server metadata cache and shared contracts for Identity Claims.
|
|
110
|
+
*
|
|
111
|
+
* This class holds only what is safe and useful in *any* host: the `IdentityClaimType` cache,
|
|
112
|
+
* type lookups, driver resolution via `ClassFactory`, and email normalization. It deliberately
|
|
113
|
+
* does **not** implement the claim lifecycle.
|
|
114
|
+
*
|
|
115
|
+
* Claim creation, redemption and revocation live exclusively on `IdentityClaimEngineServer`
|
|
116
|
+
* (`@memberjunction/core-entities-server`), which contains an instance of this class and proxies
|
|
117
|
+
* the cached members. Those operations depend on capabilities that only exist server-side:
|
|
118
|
+
* high-entropy token generation and SHA-256 hashing, a timing-safe token comparison, an atomic
|
|
119
|
+
* compare-and-swap issued as raw SQL, and email dispatch through MJ Communications. A browser
|
|
120
|
+
* copy cannot perform any of them, and a second, weaker implementation of a security-critical
|
|
121
|
+
* operation living in a package that server code also imports is a hazard rather than a
|
|
122
|
+
* convenience.
|
|
123
|
+
*
|
|
124
|
+
* Same containment split as `AIEngineBase` / `AIEngine`.
|
|
125
|
+
*/
|
|
126
|
+
export declare class IdentityClaimEngine extends BaseEngine<IdentityClaimEngine> {
|
|
127
|
+
private _claimTypes;
|
|
128
|
+
private _byName;
|
|
129
|
+
private _byId;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the singleton instance of IdentityClaimEngine
|
|
132
|
+
*/
|
|
133
|
+
static get Instance(): IdentityClaimEngine;
|
|
134
|
+
/**
|
|
135
|
+
* Configures the engine and loads cached IdentityClaimType metadata.
|
|
136
|
+
*/
|
|
137
|
+
Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* All loaded Identity Claim Types
|
|
140
|
+
*/
|
|
141
|
+
get ClaimTypes(): MJIdentityClaimTypeEntity[];
|
|
142
|
+
/**
|
|
143
|
+
* Finds a claim type by unique name (case-insensitive)
|
|
144
|
+
*/
|
|
145
|
+
GetClaimTypeByName(name: string): MJIdentityClaimTypeEntity | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Finds a claim type by unique identifier
|
|
148
|
+
*/
|
|
149
|
+
GetClaimTypeByID(id: string): MJIdentityClaimTypeEntity | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Resolves the concrete BaseIdentityClaimDriver instance for a given claim type
|
|
152
|
+
*/
|
|
153
|
+
GetDriverInstance(claimType: MJIdentityClaimTypeEntity): BaseIdentityClaimDriver | null;
|
|
154
|
+
/**
|
|
155
|
+
* Standard email normalization helper (lowercase, trimmed)
|
|
156
|
+
*/
|
|
157
|
+
NormalizeEmail(email: string): string;
|
|
158
|
+
/**
|
|
159
|
+
* Parses a claim type's `Configuration` JSON into the engine-recognized shape.
|
|
160
|
+
* Malformed or non-object JSON degrades to `{}` (the permissive defaults) rather than
|
|
161
|
+
* throwing — a bad configuration must never brick redemption outright, only tighten it
|
|
162
|
+
* when it parses.
|
|
163
|
+
*/
|
|
164
|
+
GetClaimTypeConfiguration(claimType: MJIdentityClaimTypeEntity | undefined): IdentityClaimTypeConfiguration;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=IdentityClaimEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdentityClaimEngine.d.ts","sourceRoot":"","sources":["../../src/engines/IdentityClaimEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAA4B,iBAAiB,EAAE,QAAQ,EAAsB,MAAM,sBAAsB,CAAC;AAE7H,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAElG;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,IAAI,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACpD,IAAI,EAAE,QAAQ,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,8BAAsB,uBAAuB;IACzC;;OAEG;aACa,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9D;;;;;;OAMG;aACa,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAE1E;;OAEG;aACa,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9D;;OAEG;aACa,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CACjE;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC3C;;;;OAIG;IAC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