@tearleads/client-sdk 0.1.16 → 0.1.18
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/client/index.d.ts +1 -1
- package/client/index.js.map +1 -1
- package/client/organizations/currentPrincipalMutations.js +96 -0
- package/client/organizations/currentPrincipalMutations.js.map +1 -0
- package/client/organizations/index.d.ts +1 -1
- package/client/organizations/index.js +4 -3
- package/client/organizations/index.js.map +1 -1
- package/client/organizations/organizationGroupHistory.js +44 -0
- package/client/organizations/organizationGroupHistory.js.map +1 -0
- package/client/organizations/organizationGroupNameHydration.js +7 -1
- package/client/organizations/organizationGroupNameHydration.js.map +1 -1
- package/client/organizations/organizationGroupPresentation.d.ts +1 -0
- package/client/organizations/organizationGroupPresentation.js +16 -2
- package/client/organizations/organizationGroupPresentation.js.map +1 -1
- package/client/organizations/organizationReadModels.d.ts +1 -1
- package/client/organizations/organizationReadModels.js +11 -1
- package/client/organizations/organizationReadModels.js.map +1 -1
- package/client/organizations/organizationsTypes.d.ts +8 -5
- package/client/organizations/organizationsTypes.js.map +1 -1
- package/client/organizations/principalContainerMutations.js +2 -0
- package/client/organizations/principalContainerMutations.js.map +1 -1
- package/client/organizations/principalMutations.d.ts +4 -308
- package/client/organizations/principalMutations.js +165 -87
- package/client/organizations/principalMutations.js.map +1 -1
- package/client/principalMutationApi.d.ts +1 -1
- package/client/principalMutationApi.js +5 -13
- package/client/principalMutationApi.js.map +1 -1
- package/client/principalMutationDispatch.js +54 -0
- package/client/principalMutationDispatch.js.map +1 -0
- package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +2 -2
- package/data/persistence/principalCurrentAcknowledgementPersistence.js +21 -14
- package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
- package/data/principals/currentPolicyReferenceResolver.js +2 -0
- package/data/principals/currentPolicyReferenceResolver.js.map +1 -0
- package/data/principals/principalHistoryScopeProtection.js +23 -0
- package/data/principals/principalHistoryScopeProtection.js.map +1 -0
- package/data/principals/principalMutationJournal.d.ts +2 -5
- package/data/principals/principalMutationJournal.js +3 -20
- package/data/principals/principalMutationJournal.js.map +1 -1
- package/data/principals/principalMutationJournalShape.d.ts +26 -0
- package/data/principals/principalMutationJournalShape.js +46 -0
- package/data/principals/principalMutationJournalShape.js.map +1 -0
- package/data/principals/principalPolicyAdminSigners.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +267 -3
- package/internal/api-client/ApiClient.js +11 -29
- package/internal/api-client/ApiClient.js.map +1 -1
- package/internal/api-client/principalPolicyRequests.d.ts +266 -1
- package/internal/api-client/principalPolicyRequests.js +43 -1
- package/internal/api-client/principalPolicyRequests.js.map +1 -1
- package/internal/crypto/index.d.ts +1 -1
- package/internal/crypto/index.js +1 -1
- package/internal/crypto/index.js.map +1 -1
- package/internal/crypto/keying/index.d.ts +1 -0
- package/internal/crypto/keying/index.js +1 -0
- package/internal/crypto/keying/index.js.map +1 -1
- package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.d.ts +8 -0
- package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js +46 -0
- package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js.map +1 -0
- package/internal/validators/operation/organizations.d.ts +54 -0
- package/internal/validators/operation/organizations.js +19 -4
- package/internal/validators/operation/organizations.js.map +1 -1
- package/package.json +1 -1
- package/workflows/containers/child/carriedDescendantRekeys.js +9 -1
- package/workflows/containers/child/carriedDescendantRekeys.js.map +1 -1
- package/workflows/containers/child/replacementPrincipalPolicyReferences.js +19 -0
- package/workflows/containers/child/replacementPrincipalPolicyReferences.js.map +1 -0
- package/workflows/organizations/commitCurrentGroupPolicyMutation.js +72 -0
- package/workflows/organizations/commitCurrentGroupPolicyMutation.js.map +1 -0
- package/workflows/organizations/createCurrentOrganizationGroup.js +85 -0
- package/workflows/organizations/createCurrentOrganizationGroup.js.map +1 -0
- package/workflows/organizations/currentGroupMetadataAuthority.js +24 -3
- package/workflows/organizations/currentGroupMetadataAuthority.js.map +1 -1
- package/workflows/organizations/currentGroupMutationReferences.js +35 -0
- package/workflows/organizations/currentGroupMutationReferences.js.map +1 -0
- package/workflows/organizations/currentGroupPolicyMutationContext.js +79 -0
- package/workflows/organizations/currentGroupPolicyMutationContext.js.map +1 -0
- package/workflows/organizations/currentOrganizationGroupNames.js +5 -1
- package/workflows/organizations/currentOrganizationGroupNames.js.map +1 -1
- package/workflows/organizations/currentOrganizationMutationAuthority.js +16 -0
- package/workflows/organizations/currentOrganizationMutationAuthority.js.map +1 -0
- package/workflows/organizations/currentOrganizationMutationRetention.js +53 -0
- package/workflows/organizations/currentOrganizationMutationRetention.js.map +1 -0
- package/workflows/organizations/currentPrincipalMutationLease.js +38 -0
- package/workflows/organizations/currentPrincipalMutationLease.js.map +1 -0
- package/workflows/organizations/deleteCurrentOrganizationGroup.js +35 -0
- package/workflows/organizations/deleteCurrentOrganizationGroup.js.map +1 -0
- package/workflows/organizations/deleteOrganizationGroup.d.ts +1 -0
- package/workflows/organizations/deleteOrganizationGroup.js +10 -0
- package/workflows/organizations/deleteOrganizationGroup.js.map +1 -1
- package/workflows/organizations/groupCreation.d.ts +1 -0
- package/workflows/organizations/groupCreation.js +8 -0
- package/workflows/organizations/groupCreation.js.map +1 -1
- package/workflows/organizations/groupMembershipName.d.ts +1 -1
- package/workflows/organizations/groupMembershipName.js.map +1 -1
- package/workflows/organizations/groupMetadataRuntime.js +14 -9
- package/workflows/organizations/groupMetadataRuntime.js.map +1 -1
- package/workflows/organizations/groupNameUniqueness.js +1 -1
- package/workflows/organizations/groupNameUniqueness.js.map +1 -1
- package/workflows/organizations/groupPolicyHistoryPage.js +31 -0
- package/workflows/organizations/groupPolicyHistoryPage.js.map +1 -0
- package/workflows/organizations/groupPolicyMutationAcknowledgement.js +1 -0
- package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +1 -1
- package/workflows/organizations/groupPolicyMutationContext.d.ts +18 -0
- package/workflows/organizations/groupPolicyMutationContext.js +1 -1
- package/workflows/organizations/groupPolicyMutationContext.js.map +1 -1
- package/workflows/organizations/index.d.ts +1 -0
- package/workflows/organizations/index.js.map +1 -1
- package/workflows/organizations/initialPrincipalCurrentPublication.js +83 -0
- package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -0
- package/workflows/organizations/organizationGroupDirectory.js +6 -0
- package/workflows/organizations/organizationGroupDirectory.js.map +1 -1
- package/workflows/organizations/organizationGroupNames.js.map +1 -1
- package/workflows/organizations/policyHistoryTypes.d.ts +2 -0
- package/workflows/organizations/policyHistoryTypes.js.map +1 -1
- package/workflows/organizations/principalContainerRematerialization.js +12 -2
- package/workflows/organizations/principalContainerRematerialization.js.map +1 -1
- package/workflows/organizations/principalContainerRematerializationPlanning.js +1 -0
- package/workflows/organizations/principalContainerRematerializationPlanning.js.map +1 -1
- package/workflows/organizations/principalContainerRematerializationTargets.js.map +1 -1
- package/workflows/organizations/principalMutationJournalSession.d.ts +3 -3
- package/workflows/organizations/principalMutationJournalSession.js +2 -2
- package/workflows/organizations/principalMutationJournalSession.js.map +1 -1
- package/workflows/organizations/principalMutationReceipt.js +13 -12
- package/workflows/organizations/principalMutationReceipt.js.map +1 -1
- package/workflows/organizations/principalOperationReceipt.d.ts +5 -0
- package/workflows/organizations/principalOperationReceipt.js +36 -0
- package/workflows/organizations/principalOperationReceipt.js.map +1 -0
- package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +2 -0
- package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +5 -1
- package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -1
- package/workflows/organizations/runtimeCurrentGroupMutation.js +85 -0
- package/workflows/organizations/runtimeCurrentGroupMutation.js.map +1 -0
- package/workflows/organizations/runtimeCurrentOrganizationMutation.js +48 -0
- package/workflows/organizations/runtimeCurrentOrganizationMutation.js.map +1 -0
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.d.ts +11 -0
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.js +120 -0
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +1 -0
- package/workflows/principals/principalHistoryRecoveryReferences.js +8 -0
- package/workflows/principals/principalHistoryRecoveryReferences.js.map +1 -1
- package/workflows/principals/principalRecoveryDirectory.js +3 -8
- package/workflows/principals/principalRecoveryDirectory.js.map +1 -1
- package/workflows/principals/principalRecoveryLocalPreference.js +3 -2
- package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -1
- package/workflows/principals/recoverCurrentOrganizationPolicy.js.map +1 -1
- package/workflows/principals/recoverPrincipalHistoryPage.js +30 -0
- package/workflows/principals/recoverPrincipalHistoryPage.js.map +1 -0
- package/workflows/principals/recoverPrincipalPolicyHistory.d.ts +2 -0
- package/workflows/principals/recoverPrincipalPolicyHistory.js +14 -2
- package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
- package/workflows/principals/recoverScopedPrincipalPolicyHistory.d.ts +6 -0
- package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +31 -19
- package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
- package/workflows/principals/runtimePolicyRecovery.js +25 -4
- package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
- package/workflows/principals/runtimePolicyWarmer.js +2 -2
- package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { runWithSecurityIncidentReporting } from "../../data/keyingProjectionVerification/error.js";
|
|
2
2
|
import { addOrganizationGroupUser, createOrganizationGroup, deleteOrganizationGroup, removeOrganizationGroupUser, revokeOrganizationContainerGrant, rotateOrganizationGroupForAccessSetShrink, } from "../../workflows/organizations/index.js";
|
|
3
|
+
import { createCurrentOrganizationGroup } from "../../workflows/organizations/createCurrentOrganizationGroup.js";
|
|
4
|
+
import { createSelectedCurrentGroupMetadataContainerVerifier } from "../../workflows/organizations/currentGroupMetadataAuthority.js";
|
|
5
|
+
import { deleteCurrentOrganizationGroup } from "../../workflows/organizations/deleteCurrentOrganizationGroup.js";
|
|
3
6
|
import { createRuntimeGroupMetadataAccess } from "../../workflows/organizations/groupMetadataRuntime.js";
|
|
7
|
+
import { createRuntimeCurrentOrganizationMutation } from "../../workflows/organizations/runtimeCurrentOrganizationMutation.js";
|
|
4
8
|
import { createRuntimePrincipalPolicyWarmer } from "../../workflows/principals/runtimePolicyWarmer.js";
|
|
9
|
+
import { createCurrentPrincipalMutation } from "./currentPrincipalMutations.js";
|
|
5
10
|
import { syncOrganizationMetadataProfile } from "./organizationMetadataProfileSync.js";
|
|
6
11
|
import { preparePrincipalContainerMutations } from "./principalContainerMutations.js";
|
|
7
12
|
function requireSigningContext(runtime) {
|
|
@@ -33,30 +38,44 @@ export async function addUserToOrganizationGroup(input) {
|
|
|
33
38
|
organizationId: signingContext.organizationId,
|
|
34
39
|
}, async () => {
|
|
35
40
|
let memberGroupId = null;
|
|
36
|
-
const
|
|
37
|
-
apiClient: input.runtime.apiClient,
|
|
38
|
-
beforePolicyCommit: (_head, authority) => {
|
|
39
|
-
memberGroupId = authority.memberGroupId;
|
|
40
|
-
},
|
|
41
|
-
currentUserSecretKey: requireEncapsulationKeyPair(input.runtime)
|
|
42
|
-
.secretKey,
|
|
43
|
-
execSql: input.runtime.infra.execSql,
|
|
44
|
-
expectedGroupName: input.expectedGroupName,
|
|
45
|
-
readEncryptedName: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, input.stillCurrent).readName,
|
|
46
|
-
groupId: input.groupId,
|
|
47
|
-
prepareContainerMutations: ({ currentPolicy, nextPolicy }) => preparePrincipalContainerMutations({
|
|
48
|
-
currentPolicy,
|
|
49
|
-
groupId: input.groupId,
|
|
50
|
-
nextPolicy,
|
|
51
|
-
organizationId: signingContext.organizationId,
|
|
52
|
-
runtime: input.runtime,
|
|
53
|
-
stillCurrent: input.stillCurrent,
|
|
54
|
-
}),
|
|
55
|
-
reportSecurityIncident: input.runtime.util.reportSecurityIncident,
|
|
56
|
-
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
57
|
-
targetUserId: input.targetUserId,
|
|
41
|
+
const mutateCurrent = createCurrentPrincipalMutation({
|
|
58
42
|
...signingContext,
|
|
43
|
+
runtime: input.runtime,
|
|
44
|
+
stillCurrent: input.stillCurrent,
|
|
59
45
|
});
|
|
46
|
+
const current = mutateCurrent
|
|
47
|
+
? await mutateCurrent(input.groupId, {
|
|
48
|
+
kind: "add",
|
|
49
|
+
expectedGroupName: input.expectedGroupName,
|
|
50
|
+
targetUserId: input.targetUserId,
|
|
51
|
+
})
|
|
52
|
+
: undefined;
|
|
53
|
+
memberGroupId = current?.memberGroupId ?? null;
|
|
54
|
+
const bundle = current?.response ??
|
|
55
|
+
(await addOrganizationGroupUser({
|
|
56
|
+
apiClient: input.runtime.apiClient,
|
|
57
|
+
beforePolicyCommit: (_head, authority) => {
|
|
58
|
+
memberGroupId = authority.memberGroupId;
|
|
59
|
+
},
|
|
60
|
+
currentUserSecretKey: requireEncapsulationKeyPair(input.runtime)
|
|
61
|
+
.secretKey,
|
|
62
|
+
execSql: input.runtime.infra.execSql,
|
|
63
|
+
expectedGroupName: input.expectedGroupName,
|
|
64
|
+
readEncryptedName: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, input.stillCurrent).readName,
|
|
65
|
+
groupId: input.groupId,
|
|
66
|
+
prepareContainerMutations: ({ currentPolicy, nextPolicy }) => preparePrincipalContainerMutations({
|
|
67
|
+
currentPolicy,
|
|
68
|
+
groupId: input.groupId,
|
|
69
|
+
nextPolicy,
|
|
70
|
+
organizationId: signingContext.organizationId,
|
|
71
|
+
runtime: input.runtime,
|
|
72
|
+
stillCurrent: input.stillCurrent,
|
|
73
|
+
}),
|
|
74
|
+
reportSecurityIncident: input.runtime.util.reportSecurityIncident,
|
|
75
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
76
|
+
targetUserId: input.targetUserId,
|
|
77
|
+
...signingContext,
|
|
78
|
+
}));
|
|
60
79
|
if (input.groupId === memberGroupId) {
|
|
61
80
|
await syncOrganizationMetadataProfile({
|
|
62
81
|
containerContents: input.containerContents,
|
|
@@ -75,16 +94,37 @@ export function createGroupForOrganization(input) {
|
|
|
75
94
|
objectKind: "principal",
|
|
76
95
|
operation: "group.create",
|
|
77
96
|
organizationId: signingContext.organizationId,
|
|
78
|
-
}, () =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
}, () => {
|
|
98
|
+
const creatorEncapsulationKeyPair = requireEncapsulationKeyPair(input.runtime);
|
|
99
|
+
const mutate = createRuntimeCurrentOrganizationMutation(input.runtime);
|
|
100
|
+
if (mutate)
|
|
101
|
+
return mutate({ ...signingContext, stillCurrent: input.stillCurrent }, (context) => createCurrentOrganizationGroup({
|
|
102
|
+
...signingContext,
|
|
103
|
+
context,
|
|
104
|
+
apiClient: input.runtime.apiClient,
|
|
105
|
+
creatorEncapsulationKeyPair,
|
|
106
|
+
execSql: input.runtime.infra.execSql,
|
|
107
|
+
name: input.name,
|
|
108
|
+
metadataAccess: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, context.stillCurrent, createSelectedCurrentGroupMetadataContainerVerifier({
|
|
109
|
+
authority: context,
|
|
110
|
+
organizationId: signingContext.organizationId,
|
|
111
|
+
stillCurrent: context.stillCurrent,
|
|
112
|
+
})),
|
|
113
|
+
reportSecurityIncident: input.runtime.util.reportSecurityIncident,
|
|
114
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
115
|
+
}));
|
|
116
|
+
return createOrganizationGroup({
|
|
117
|
+
stillCurrent: input.stillCurrent,
|
|
118
|
+
apiClient: input.runtime.apiClient,
|
|
119
|
+
creatorEncapsulationKeyPair,
|
|
120
|
+
execSql: input.runtime.infra.execSql,
|
|
121
|
+
name: input.name,
|
|
122
|
+
metadataAccess: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, input.stillCurrent),
|
|
123
|
+
reportSecurityIncident: input.runtime.util.reportSecurityIncident,
|
|
124
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
125
|
+
...signingContext,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
88
128
|
}
|
|
89
129
|
export function deleteGroupForOrganization(input) {
|
|
90
130
|
const signingContext = requireSigningContext(input.runtime);
|
|
@@ -93,13 +133,25 @@ export function deleteGroupForOrganization(input) {
|
|
|
93
133
|
objectKind: "principal",
|
|
94
134
|
operation: "group.delete",
|
|
95
135
|
organizationId: signingContext.organizationId,
|
|
96
|
-
}, () =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
136
|
+
}, () => {
|
|
137
|
+
const mutate = createRuntimeCurrentOrganizationMutation(input.runtime);
|
|
138
|
+
if (mutate)
|
|
139
|
+
return mutate({ ...signingContext, stillCurrent: input.stillCurrent }, (context) => deleteCurrentOrganizationGroup({
|
|
140
|
+
...signingContext,
|
|
141
|
+
context,
|
|
142
|
+
groupId: input.groupId,
|
|
143
|
+
apiClient: input.runtime.apiClient,
|
|
144
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
145
|
+
}));
|
|
146
|
+
return deleteOrganizationGroup({
|
|
147
|
+
stillCurrent: input.stillCurrent,
|
|
148
|
+
apiClient: input.runtime.apiClient,
|
|
149
|
+
execSql: input.runtime.infra.execSql,
|
|
150
|
+
groupId: input.groupId,
|
|
151
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
152
|
+
...signingContext,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
103
155
|
}
|
|
104
156
|
export async function removeUserFromOrganizationGroup(input) {
|
|
105
157
|
const signingContext = requireSigningContext(input.runtime);
|
|
@@ -110,27 +162,41 @@ export async function removeUserFromOrganizationGroup(input) {
|
|
|
110
162
|
organizationId: signingContext.organizationId,
|
|
111
163
|
}, async () => {
|
|
112
164
|
let memberGroupId = null;
|
|
113
|
-
const
|
|
114
|
-
apiClient: input.runtime.apiClient,
|
|
115
|
-
beforePolicyCommit: (_head, authority) => {
|
|
116
|
-
memberGroupId = authority.memberGroupId;
|
|
117
|
-
},
|
|
118
|
-
execSql: input.runtime.infra.execSql,
|
|
119
|
-
expectedGroupName: input.expectedGroupName,
|
|
120
|
-
readEncryptedName: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, input.stillCurrent).readName,
|
|
121
|
-
groupId: input.groupId,
|
|
122
|
-
prepareContainerMutations: ({ currentPolicy, nextPolicy }) => preparePrincipalContainerMutations({
|
|
123
|
-
currentPolicy,
|
|
124
|
-
groupId: input.groupId,
|
|
125
|
-
nextPolicy,
|
|
126
|
-
organizationId: signingContext.organizationId,
|
|
127
|
-
runtime: input.runtime,
|
|
128
|
-
stillCurrent: input.stillCurrent,
|
|
129
|
-
}),
|
|
130
|
-
removedUserId: input.removedUserId,
|
|
131
|
-
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
165
|
+
const mutateCurrent = createCurrentPrincipalMutation({
|
|
132
166
|
...signingContext,
|
|
167
|
+
runtime: input.runtime,
|
|
168
|
+
stillCurrent: input.stillCurrent,
|
|
133
169
|
});
|
|
170
|
+
const current = mutateCurrent
|
|
171
|
+
? await mutateCurrent(input.groupId, {
|
|
172
|
+
kind: "remove",
|
|
173
|
+
expectedGroupName: input.expectedGroupName,
|
|
174
|
+
removedUserId: input.removedUserId,
|
|
175
|
+
})
|
|
176
|
+
: undefined;
|
|
177
|
+
memberGroupId = current?.memberGroupId ?? null;
|
|
178
|
+
const bundle = current?.response ??
|
|
179
|
+
(await removeOrganizationGroupUser({
|
|
180
|
+
apiClient: input.runtime.apiClient,
|
|
181
|
+
beforePolicyCommit: (_head, authority) => {
|
|
182
|
+
memberGroupId = authority.memberGroupId;
|
|
183
|
+
},
|
|
184
|
+
execSql: input.runtime.infra.execSql,
|
|
185
|
+
expectedGroupName: input.expectedGroupName,
|
|
186
|
+
readEncryptedName: createRuntimeGroupMetadataAccess(input.runtime, signingContext.organizationId, input.stillCurrent).readName,
|
|
187
|
+
groupId: input.groupId,
|
|
188
|
+
prepareContainerMutations: ({ currentPolicy, nextPolicy }) => preparePrincipalContainerMutations({
|
|
189
|
+
currentPolicy,
|
|
190
|
+
groupId: input.groupId,
|
|
191
|
+
nextPolicy,
|
|
192
|
+
organizationId: signingContext.organizationId,
|
|
193
|
+
runtime: input.runtime,
|
|
194
|
+
stillCurrent: input.stillCurrent,
|
|
195
|
+
}),
|
|
196
|
+
removedUserId: input.removedUserId,
|
|
197
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
198
|
+
...signingContext,
|
|
199
|
+
}));
|
|
134
200
|
if (input.groupId === memberGroupId) {
|
|
135
201
|
await syncOrganizationMetadataProfile({
|
|
136
202
|
containerContents: input.containerContents,
|
|
@@ -154,39 +220,51 @@ export async function revokeOrganizationGrant(input) {
|
|
|
154
220
|
operation: "principal.grant.revoke",
|
|
155
221
|
organizationId: signingContext.organizationId,
|
|
156
222
|
}, async () => {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
223
|
+
const mutateCurrent = createCurrentPrincipalMutation({
|
|
224
|
+
...signingContext,
|
|
225
|
+
runtime: input.runtime,
|
|
226
|
+
stillCurrent: input.stillCurrent,
|
|
227
|
+
});
|
|
228
|
+
const current = input.subjectType === "group" && mutateCurrent
|
|
229
|
+
? await mutateCurrent(input.subjectId, {
|
|
230
|
+
kind: "revoke",
|
|
162
231
|
revokedContainerId: input.containerId,
|
|
163
|
-
|
|
164
|
-
|
|
232
|
+
})
|
|
233
|
+
: undefined;
|
|
234
|
+
const response = current?.response ??
|
|
235
|
+
(input.subjectType === "group"
|
|
236
|
+
? await rotateOrganizationGroupForAccessSetShrink({
|
|
237
|
+
apiClient: input.runtime.apiClient,
|
|
238
|
+
execSql: input.runtime.infra.execSql,
|
|
165
239
|
groupId: input.subjectId,
|
|
166
|
-
nextPolicy,
|
|
167
|
-
organizationId: signingContext.organizationId,
|
|
168
240
|
revokedContainerId: input.containerId,
|
|
169
|
-
|
|
241
|
+
prepareContainerMutations: ({ currentPolicy, nextPolicy }) => preparePrincipalContainerMutations({
|
|
242
|
+
currentPolicy,
|
|
243
|
+
groupId: input.subjectId,
|
|
244
|
+
nextPolicy,
|
|
245
|
+
organizationId: signingContext.organizationId,
|
|
246
|
+
revokedContainerId: input.containerId,
|
|
247
|
+
runtime: input.runtime,
|
|
248
|
+
stillCurrent: input.stillCurrent,
|
|
249
|
+
}),
|
|
250
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
251
|
+
...signingContext,
|
|
252
|
+
})
|
|
253
|
+
: await revokeOrganizationContainerGrant({
|
|
170
254
|
stillCurrent: input.stillCurrent,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
subjectType: input.subjectType,
|
|
185
|
-
},
|
|
186
|
-
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
187
|
-
warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(input.runtime),
|
|
188
|
-
...signingContext,
|
|
189
|
-
});
|
|
255
|
+
reportSecurityIncident: input.runtime.util.reportSecurityIncident,
|
|
256
|
+
apiClient: input.runtime.apiClient,
|
|
257
|
+
containerId: input.containerId,
|
|
258
|
+
encapsulationKeyPair,
|
|
259
|
+
execSql: input.runtime.infra.execSql,
|
|
260
|
+
revokedSubject: {
|
|
261
|
+
subjectId: input.subjectId,
|
|
262
|
+
subjectType: input.subjectType,
|
|
263
|
+
},
|
|
264
|
+
resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,
|
|
265
|
+
warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(input.runtime),
|
|
266
|
+
...signingContext,
|
|
267
|
+
}));
|
|
190
268
|
await input.readModelCoordinator.reconcileAfterMutation(signingContext.organizationId);
|
|
191
269
|
return response;
|
|
192
270
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalMutations.js","sourceRoot":"","sources":["principalMutations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,gCAAgC,EAChC,yCAAyC,GAC1C,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,gCAAgC,EAAE,MAAM,oDAAoD,CAAC;AACtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAGpG,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AAgCnF,SAAS,qBAAqB,CAC5B,OAAqC;IAErC,IACE,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc;QAC5B,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM;QACpB,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB;QAClC,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAC9B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc;QAC3C,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM;QACjC,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB;QACrD,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc;KAC9C,CAAC;AACJ,CAAC;A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,OAAO;oBACtB,YAAY,EAAE,KAAK,CAAC,YAAY;iBACjC,CAAC;gBACJ,0BAA0B,EACxB,KAAK,CAAC,OAAO,CAAC,0BAA0B;gBAC1C,GAAG,cAAc;aAClB,CAAC;YACJ,CAAC,CAAC,MAAM,gCAAgC,CAAC;gBACrC,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB;gBACjE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;gBAClC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,oBAAoB;gBACpB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;gBACpC,cAAc,EAAE;oBACd,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;iBAC/B;gBACD,0BAA0B,EACxB,KAAK,CAAC,OAAO,CAAC,0BAA0B;gBAC1C,+BAA+B,EAC7B,kCAAkC,CAAC,KAAK,CAAC,OAAO,CAAC;gBACnD,GAAG,cAAc;aAClB,CAAC,CAAC;QACT,MAAM,KAAK,CAAC,oBAAoB,CAAC,sBAAsB,CACrD,cAAc,CAAC,cAAc,CAC9B,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ContainerGrantSubjectType } from \"@tearleads/crypto\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n addOrganizationGroupUser,\n createOrganizationGroup,\n deleteOrganizationGroup,\n removeOrganizationGroupUser,\n revokeOrganizationContainerGrant,\n rotateOrganizationGroupForAccessSetShrink,\n} from \"../../workflows/organizations\";\nimport { createRuntimeGroupMetadataAccess } from \"../../workflows/organizations/groupMetadataRuntime\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalWorkflowRuntimeInput } from \"../workflowRuntime\";\nimport { syncOrganizationMetadataProfile } from \"./organizationMetadataProfileSync\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModels\";\nimport { preparePrincipalContainerMutations } from \"./principalContainerMutations\";\n\nexport interface OrganizationGrantRef {\n containerId: string;\n subjectId: string;\n subjectType: ContainerGrantSubjectType;\n}\n\nexport interface OrganizationGroupUserMutationInput {\n groupId: string;\n expectedGroupName: string;\n}\n\nexport interface AddOrganizationGroupUserInput\n extends OrganizationGroupUserMutationInput {\n targetUserId: string;\n}\n\nexport interface RemoveOrganizationGroupUserInput\n extends OrganizationGroupUserMutationInput {\n removedUserId: string;\n}\n\ninterface OrganizationSigningContext {\n organizationId: string;\n signerUserId: string;\n signingFingerprint: string;\n signingKeyPair: NonNullable<\n InternalWorkflowRuntimeInput[\"crypto\"][\"signingKeyPair\"]\n >;\n}\n\nfunction requireSigningContext(\n runtime: InternalWorkflowRuntimeInput,\n): OrganizationSigningContext {\n if (\n !runtime.auth.organizationId ||\n !runtime.auth.userId ||\n !runtime.crypto.signingFingerprint ||\n !runtime.crypto.signingKeyPair\n ) {\n throw new Error(\"Organization signing context is unavailable\");\n }\n\n return {\n organizationId: runtime.auth.organizationId,\n signerUserId: runtime.auth.userId,\n signingFingerprint: runtime.crypto.signingFingerprint,\n signingKeyPair: runtime.crypto.signingKeyPair,\n };\n}\n\nfunction requireEncapsulationKeyPair(\n runtime: InternalWorkflowRuntimeInput,\n): NonNullable<InternalWorkflowRuntimeInput[\"crypto\"][\"encapsulationKeyPair\"]> {\n if (!runtime.crypto.encapsulationKeyPair) {\n throw new Error(\"Organization encryption context is unavailable\");\n }\n\n return runtime.crypto.encapsulationKeyPair;\n}\n\ninterface PrincipalMutationRuntime {\n readonly stillCurrent: () => boolean;\n readonly containerContents: ContainerContents;\n readonly readModelCoordinator: OrganizationReadModelCoordinator;\n readonly runtime: InternalWorkflowRuntimeInput;\n}\n\nexport async function addUserToOrganizationGroup(\n input: PrincipalMutationRuntime & AddOrganizationGroupUserInput,\n) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.member.add\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n let memberGroupId: string | null = null;\n const bundle = await addOrganizationGroupUser({\n apiClient: input.runtime.apiClient,\n beforePolicyCommit: (_head, authority) => {\n memberGroupId = authority.memberGroupId;\n },\n currentUserSecretKey: requireEncapsulationKeyPair(input.runtime)\n .secretKey,\n execSql: input.runtime.infra.execSql,\n expectedGroupName: input.expectedGroupName,\n readEncryptedName: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n input.stillCurrent,\n ).readName,\n groupId: input.groupId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.groupId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n targetUserId: input.targetUserId,\n ...signingContext,\n });\n if (input.groupId === memberGroupId) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return bundle;\n },\n );\n}\n\nexport function createGroupForOrganization(input: {\n readonly name: string;\n readonly runtime: InternalWorkflowRuntimeInput;\n}) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: signingContext.organizationId,\n objectKind: \"principal\",\n operation: \"group.create\",\n organizationId: signingContext.organizationId,\n },\n () =>\n createOrganizationGroup({\n apiClient: input.runtime.apiClient,\n creatorEncapsulationKeyPair: requireEncapsulationKeyPair(input.runtime),\n execSql: input.runtime.infra.execSql,\n name: input.name,\n metadataAccess: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n ),\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n }),\n );\n}\n\nexport function deleteGroupForOrganization(input: {\n readonly groupId: string;\n readonly runtime: InternalWorkflowRuntimeInput;\n}) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.delete\",\n organizationId: signingContext.organizationId,\n },\n () =>\n deleteOrganizationGroup({\n apiClient: input.runtime.apiClient,\n execSql: input.runtime.infra.execSql,\n groupId: input.groupId,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n }),\n );\n}\n\nexport async function removeUserFromOrganizationGroup(\n input: PrincipalMutationRuntime & RemoveOrganizationGroupUserInput,\n) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.member.remove\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n let memberGroupId: string | null = null;\n const bundle = await removeOrganizationGroupUser({\n apiClient: input.runtime.apiClient,\n beforePolicyCommit: (_head, authority) => {\n memberGroupId = authority.memberGroupId;\n },\n execSql: input.runtime.infra.execSql,\n expectedGroupName: input.expectedGroupName,\n readEncryptedName: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n input.stillCurrent,\n ).readName,\n groupId: input.groupId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.groupId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n removedUserId: input.removedUserId,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n });\n if (input.groupId === memberGroupId) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return bundle;\n },\n );\n}\n\nexport async function revokeOrganizationGrant(\n input: PrincipalMutationRuntime & OrganizationGrantRef,\n) {\n const signingContext = requireSigningContext(input.runtime);\n const encapsulationKeyPair = requireEncapsulationKeyPair(input.runtime);\n if (input.runtime.infra.dbStatus !== \"ready\") {\n throw new Error(\"Organization local database is unavailable\");\n }\n\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.subjectId,\n objectKind: \"principal\",\n operation: \"principal.grant.revoke\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n const response =\n input.subjectType === \"group\"\n ? await rotateOrganizationGroupForAccessSetShrink({\n apiClient: input.runtime.apiClient,\n execSql: input.runtime.infra.execSql,\n groupId: input.subjectId,\n revokedContainerId: input.containerId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.subjectId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n revokedContainerId: input.containerId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n })\n : await revokeOrganizationContainerGrant({\n stillCurrent: input.stillCurrent,\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n apiClient: input.runtime.apiClient,\n containerId: input.containerId,\n encapsulationKeyPair,\n execSql: input.runtime.infra.execSql,\n revokedSubject: {\n subjectId: input.subjectId,\n subjectType: input.subjectType,\n },\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n warmReferencedPrincipalPolicies:\n createRuntimePrincipalPolicyWarmer(input.runtime),\n ...signingContext,\n });\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return response;\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"principalMutations.js","sourceRoot":"","sources":["principalMutations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,gCAAgC,EAChC,yCAAyC,GAC1C,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,8BAA8B,EAAE,MAAM,8DAA8D,CAAC;AAC9G,OAAO,EAAE,mDAAmD,EAAE,MAAM,6DAA6D,CAAC;AAClI,OAAO,EAAE,8BAA8B,EAAE,MAAM,8DAA8D,CAAC;AAC9G,OAAO,EAAE,gCAAgC,EAAE,MAAM,oDAAoD,CAAC;AACtG,OAAO,EAAE,wCAAwC,EAAE,MAAM,kEAAkE,CAAC;AAC5H,OAAO,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAGpG,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AAgCnF,SAAS,qBAAqB,CAC5B,OAAqC;IAErC,IACE,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc;QAC5B,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM;QACpB,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB;QAClC,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAC9B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc;QAC3C,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM;QACj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C;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ContainerGrantSubjectType } from \"@tearleads/crypto\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n addOrganizationGroupUser,\n createOrganizationGroup,\n deleteOrganizationGroup,\n removeOrganizationGroupUser,\n revokeOrganizationContainerGrant,\n rotateOrganizationGroupForAccessSetShrink,\n} from \"../../workflows/organizations\";\nimport { createCurrentOrganizationGroup } from \"../../workflows/organizations/createCurrentOrganizationGroup\";\nimport { createSelectedCurrentGroupMetadataContainerVerifier } from \"../../workflows/organizations/currentGroupMetadataAuthority\";\nimport { deleteCurrentOrganizationGroup } from \"../../workflows/organizations/deleteCurrentOrganizationGroup\";\nimport { createRuntimeGroupMetadataAccess } from \"../../workflows/organizations/groupMetadataRuntime\";\nimport { createRuntimeCurrentOrganizationMutation } from \"../../workflows/organizations/runtimeCurrentOrganizationMutation\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalWorkflowRuntimeInput } from \"../workflowRuntime\";\nimport { createCurrentPrincipalMutation } from \"./currentPrincipalMutations\";\nimport { syncOrganizationMetadataProfile } from \"./organizationMetadataProfileSync\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModels\";\nimport { preparePrincipalContainerMutations } from \"./principalContainerMutations\";\n\nexport interface OrganizationGrantRef {\n containerId: string;\n subjectId: string;\n subjectType: ContainerGrantSubjectType;\n}\n\nexport interface OrganizationGroupUserMutationInput {\n groupId: string;\n expectedGroupName: string;\n}\n\nexport interface AddOrganizationGroupUserInput\n extends OrganizationGroupUserMutationInput {\n targetUserId: string;\n}\n\nexport interface RemoveOrganizationGroupUserInput\n extends OrganizationGroupUserMutationInput {\n removedUserId: string;\n}\n\ninterface OrganizationSigningContext {\n organizationId: string;\n signerUserId: string;\n signingFingerprint: string;\n signingKeyPair: NonNullable<\n InternalWorkflowRuntimeInput[\"crypto\"][\"signingKeyPair\"]\n >;\n}\n\nfunction requireSigningContext(\n runtime: InternalWorkflowRuntimeInput,\n): OrganizationSigningContext {\n if (\n !runtime.auth.organizationId ||\n !runtime.auth.userId ||\n !runtime.crypto.signingFingerprint ||\n !runtime.crypto.signingKeyPair\n ) {\n throw new Error(\"Organization signing context is unavailable\");\n }\n\n return {\n organizationId: runtime.auth.organizationId,\n signerUserId: runtime.auth.userId,\n signingFingerprint: runtime.crypto.signingFingerprint,\n signingKeyPair: runtime.crypto.signingKeyPair,\n };\n}\n\nfunction requireEncapsulationKeyPair(\n runtime: InternalWorkflowRuntimeInput,\n): NonNullable<InternalWorkflowRuntimeInput[\"crypto\"][\"encapsulationKeyPair\"]> {\n if (!runtime.crypto.encapsulationKeyPair) {\n throw new Error(\"Organization encryption context is unavailable\");\n }\n\n return runtime.crypto.encapsulationKeyPair;\n}\n\ninterface PrincipalMutationRuntime {\n readonly stillCurrent: () => boolean;\n readonly containerContents: ContainerContents;\n readonly readModelCoordinator: OrganizationReadModelCoordinator;\n readonly runtime: InternalWorkflowRuntimeInput;\n}\n\nexport async function addUserToOrganizationGroup(\n input: PrincipalMutationRuntime & AddOrganizationGroupUserInput,\n) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.member.add\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n let memberGroupId: string | null = null;\n const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n const current = mutateCurrent\n ? await mutateCurrent(input.groupId, {\n kind: \"add\",\n expectedGroupName: input.expectedGroupName,\n targetUserId: input.targetUserId,\n })\n : undefined;\n memberGroupId = current?.memberGroupId ?? null;\n const bundle =\n current?.response ??\n (await addOrganizationGroupUser({\n apiClient: input.runtime.apiClient,\n beforePolicyCommit: (_head, authority) => {\n memberGroupId = authority.memberGroupId;\n },\n currentUserSecretKey: requireEncapsulationKeyPair(input.runtime)\n .secretKey,\n execSql: input.runtime.infra.execSql,\n expectedGroupName: input.expectedGroupName,\n readEncryptedName: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n input.stillCurrent,\n ).readName,\n groupId: input.groupId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.groupId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n targetUserId: input.targetUserId,\n ...signingContext,\n }));\n if (input.groupId === memberGroupId) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return bundle;\n },\n );\n}\n\nexport function createGroupForOrganization(input: {\n readonly name: string;\n readonly runtime: InternalWorkflowRuntimeInput;\n readonly stillCurrent: () => boolean;\n}) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: signingContext.organizationId,\n objectKind: \"principal\",\n operation: \"group.create\",\n organizationId: signingContext.organizationId,\n },\n () => {\n const creatorEncapsulationKeyPair = requireEncapsulationKeyPair(\n input.runtime,\n );\n const mutate = createRuntimeCurrentOrganizationMutation(input.runtime);\n if (mutate)\n return mutate(\n { ...signingContext, stillCurrent: input.stillCurrent },\n (context) =>\n createCurrentOrganizationGroup({\n ...signingContext,\n context,\n apiClient: input.runtime.apiClient,\n creatorEncapsulationKeyPair,\n execSql: input.runtime.infra.execSql,\n name: input.name,\n metadataAccess: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n context.stillCurrent,\n createSelectedCurrentGroupMetadataContainerVerifier({\n authority: context,\n organizationId: signingContext.organizationId,\n stillCurrent: context.stillCurrent,\n }),\n ),\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n }),\n );\n return createOrganizationGroup({\n stillCurrent: input.stillCurrent,\n apiClient: input.runtime.apiClient,\n creatorEncapsulationKeyPair,\n execSql: input.runtime.infra.execSql,\n name: input.name,\n metadataAccess: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n input.stillCurrent,\n ),\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n });\n },\n );\n}\n\nexport function deleteGroupForOrganization(input: {\n readonly groupId: string;\n readonly runtime: InternalWorkflowRuntimeInput;\n readonly stillCurrent: () => boolean;\n}) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.delete\",\n organizationId: signingContext.organizationId,\n },\n () => {\n const mutate = createRuntimeCurrentOrganizationMutation(input.runtime);\n if (mutate)\n return mutate(\n { ...signingContext, stillCurrent: input.stillCurrent },\n (context) =>\n deleteCurrentOrganizationGroup({\n ...signingContext,\n context,\n groupId: input.groupId,\n apiClient: input.runtime.apiClient,\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n }),\n );\n return deleteOrganizationGroup({\n stillCurrent: input.stillCurrent,\n apiClient: input.runtime.apiClient,\n execSql: input.runtime.infra.execSql,\n groupId: input.groupId,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n });\n },\n );\n}\n\nexport async function removeUserFromOrganizationGroup(\n input: PrincipalMutationRuntime & RemoveOrganizationGroupUserInput,\n) {\n const signingContext = requireSigningContext(input.runtime);\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.groupId,\n objectKind: \"principal\",\n operation: \"group.member.remove\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n let memberGroupId: string | null = null;\n const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n const current = mutateCurrent\n ? await mutateCurrent(input.groupId, {\n kind: \"remove\",\n expectedGroupName: input.expectedGroupName,\n removedUserId: input.removedUserId,\n })\n : undefined;\n memberGroupId = current?.memberGroupId ?? null;\n const bundle =\n current?.response ??\n (await removeOrganizationGroupUser({\n apiClient: input.runtime.apiClient,\n beforePolicyCommit: (_head, authority) => {\n memberGroupId = authority.memberGroupId;\n },\n execSql: input.runtime.infra.execSql,\n expectedGroupName: input.expectedGroupName,\n readEncryptedName: createRuntimeGroupMetadataAccess(\n input.runtime,\n signingContext.organizationId,\n input.stillCurrent,\n ).readName,\n groupId: input.groupId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.groupId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n removedUserId: input.removedUserId,\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n }));\n if (input.groupId === memberGroupId) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return bundle;\n },\n );\n}\n\nexport async function revokeOrganizationGrant(\n input: PrincipalMutationRuntime & OrganizationGrantRef,\n) {\n const signingContext = requireSigningContext(input.runtime);\n const encapsulationKeyPair = requireEncapsulationKeyPair(input.runtime);\n if (input.runtime.infra.dbStatus !== \"ready\") {\n throw new Error(\"Organization local database is unavailable\");\n }\n\n return runWithSecurityIncidentReporting(\n input.runtime.util.reportSecurityIncident,\n {\n objectId: input.subjectId,\n objectKind: \"principal\",\n operation: \"principal.grant.revoke\",\n organizationId: signingContext.organizationId,\n },\n async () => {\n const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n const current =\n input.subjectType === \"group\" && mutateCurrent\n ? await mutateCurrent(input.subjectId, {\n kind: \"revoke\",\n revokedContainerId: input.containerId,\n })\n : undefined;\n const response =\n current?.response ??\n (input.subjectType === \"group\"\n ? await rotateOrganizationGroupForAccessSetShrink({\n apiClient: input.runtime.apiClient,\n execSql: input.runtime.infra.execSql,\n groupId: input.subjectId,\n revokedContainerId: input.containerId,\n prepareContainerMutations: ({ currentPolicy, nextPolicy }) =>\n preparePrincipalContainerMutations({\n currentPolicy,\n groupId: input.subjectId,\n nextPolicy,\n organizationId: signingContext.organizationId,\n revokedContainerId: input.containerId,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n }),\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n ...signingContext,\n })\n : await revokeOrganizationContainerGrant({\n stillCurrent: input.stillCurrent,\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n apiClient: input.runtime.apiClient,\n containerId: input.containerId,\n encapsulationKeyPair,\n execSql: input.runtime.infra.execSql,\n revokedSubject: {\n subjectId: input.subjectId,\n subjectType: input.subjectType,\n },\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n warmReferencedPrincipalPolicies:\n createRuntimePrincipalPolicyWarmer(input.runtime),\n ...signingContext,\n }));\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return response;\n },\n );\n}\n"]}
|
|
@@ -17,7 +17,7 @@ interface PrincipalMutationApiCustodyInput {
|
|
|
17
17
|
readonly readScope: () => PrincipalMutationRuntimeScope | null;
|
|
18
18
|
readonly principalMutationTimeoutMs?: number | undefined;
|
|
19
19
|
}
|
|
20
|
-
/** Keep API methods bound to their real receiver and journal
|
|
20
|
+
/** Keep API methods bound to their real receiver and journal principal policy and group lifecycle writes. */
|
|
21
21
|
export declare function createPrincipalMutationApiCustody(input: PrincipalMutationApiCustodyInput): {
|
|
22
22
|
bind(): PrincipalMutationApi;
|
|
23
23
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { abandonJournaledPrincipalMutation, discardUnreadableJournaledPrincipalMutation, readJournaledPrincipalMutation, } from "../workflows/organizations/principalMutationJournalManagement.js";
|
|
2
|
-
import { recoverJournaledPrincipalMutation
|
|
2
|
+
import { recoverJournaledPrincipalMutation } from "../workflows/organizations/principalMutationJournalSession.js";
|
|
3
3
|
import { createPrincipalMutationDispatcher } from "./principalMutationDeadline.js";
|
|
4
|
+
import { createJournaledPrincipalMutations, dispatchAuthoredPrincipalMutation, } from "./principalMutationDispatch.js";
|
|
4
5
|
function sameScope(current, bound) {
|
|
5
6
|
if (!current || !bound)
|
|
6
7
|
return current === bound;
|
|
@@ -27,7 +28,7 @@ function mutationContext(input, scope, organizationId) {
|
|
|
27
28
|
stillCurrent: () => sameScope(input.readScope(), scope),
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
/** Keep API methods bound to their real receiver and journal
|
|
31
|
+
/** Keep API methods bound to their real receiver and journal principal policy and group lifecycle writes. */
|
|
31
32
|
export function createPrincipalMutationApiCustody(input) {
|
|
32
33
|
const dispatch = createPrincipalMutationDispatcher(input.principalMutationTimeoutMs);
|
|
33
34
|
let cached = null;
|
|
@@ -37,11 +38,6 @@ export function createPrincipalMutationApiCustody(input) {
|
|
|
37
38
|
if (cached && sameScope(scope, cached.scope))
|
|
38
39
|
return cached.api;
|
|
39
40
|
const context = (organizationId) => mutationContext(input, scope, organizationId);
|
|
40
|
-
const commit = async (organizationId, groupId, request, options) => submitJournaledPrincipalMutation({
|
|
41
|
-
...context(organizationId),
|
|
42
|
-
mutation: { groupId, request },
|
|
43
|
-
submit: (mutation) => dispatch(options, (dispatchOptions) => input.api.commitOrganizationGroupPolicyResult(organizationId, mutation.groupId, mutation.request, dispatchOptions)),
|
|
44
|
-
});
|
|
45
41
|
const read = async (organizationId) => scope
|
|
46
42
|
? readJournaledPrincipalMutation(context(organizationId))
|
|
47
43
|
: null;
|
|
@@ -51,6 +47,7 @@ export function createPrincipalMutationApiCustody(input) {
|
|
|
51
47
|
acknowledgeUnknownOutcome,
|
|
52
48
|
});
|
|
53
49
|
const methods = {
|
|
50
|
+
...createJournaledPrincipalMutations(input.api, context, dispatch),
|
|
54
51
|
discardUnreadablePrincipalMutation: async (organizationId, recordId, acknowledgeUnknownOutcome) => discardUnreadableJournaledPrincipalMutation({
|
|
55
52
|
...context(organizationId),
|
|
56
53
|
recordId,
|
|
@@ -58,15 +55,10 @@ export function createPrincipalMutationApiCustody(input) {
|
|
|
58
55
|
}),
|
|
59
56
|
readPendingPrincipalMutation: read,
|
|
60
57
|
abandonPendingPrincipalMutation: abandon,
|
|
61
|
-
commitOrganizationGroupPolicyResult: commit,
|
|
62
|
-
commitOrganizationGroupPolicy: async (...args) => {
|
|
63
|
-
const result = await commit(...args);
|
|
64
|
-
return result.ok ? result.data : null;
|
|
65
|
-
},
|
|
66
58
|
recoverPendingPrincipalMutation: async (organizationId) => {
|
|
67
59
|
await recoverJournaledPrincipalMutation({
|
|
68
60
|
...context(organizationId),
|
|
69
|
-
submit: (mutation) => dispatch({ reportErrors: false }, (dispatchOptions) => input.api
|
|
61
|
+
submit: (mutation) => dispatch({ reportErrors: false }, (dispatchOptions) => dispatchAuthoredPrincipalMutation(input.api, organizationId, mutation, dispatchOptions)),
|
|
70
62
|
});
|
|
71
63
|
},
|
|
72
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalMutationApi.js","sourceRoot":"","sources":["principalMutationApi.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iCAAiC,EACjC,2CAA2C,EAE3C,8BAA8B,GAC/B,MAAM,+DAA+D,CAAC;AACv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from \"../data/sqlite/sqlSchema\";\nimport {\n abandonJournaledPrincipalMutation,\n discardUnreadableJournaledPrincipalMutation,\n type PrincipalMutationRecoveryApi,\n readJournaledPrincipalMutation,\n} from \"../workflows/organizations/principalMutationJournalManagement\";\nimport {\n recoverJournaledPrincipalMutation,\n submitJournaledPrincipalMutation,\n} from \"../workflows/organizations/principalMutationJournalSession\";\nimport { createPrincipalMutationDispatcher } from \"./principalMutationDeadline\";\n\nexport interface PrincipalMutationRuntimeScope {\n readonly database: object;\n readonly execSql: ExecSql;\n readonly generation: number;\n readonly identityTrustDomain: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly userId: string;\n}\n\nfunction sameScope(\n current: PrincipalMutationRuntimeScope | null,\n bound: PrincipalMutationRuntimeScope | null,\n): boolean {\n if (!current || !bound) return current === bound;\n return (\n current.database === bound.database &&\n current.execSql === bound.execSql &&\n current.generation === bound.generation &&\n current.identityTrustDomain === bound.identityTrustDomain &&\n current.signingFingerprint === bound.signingFingerprint &&\n current.signingKeyPair === bound.signingKeyPair &&\n current.userId === bound.userId\n );\n}\n\nexport type PrincipalMutationApi = ApiClient & PrincipalMutationRecoveryApi;\ntype MutationOverrides = Pick<\n ApiClient,\n \"commitOrganizationGroupPolicy\" | \"commitOrganizationGroupPolicyResult\"\n> &\n PrincipalMutationRecoveryApi;\n\ninterface PrincipalMutationApiCustodyInput {\n readonly api: ApiClient;\n readonly readScope: () => PrincipalMutationRuntimeScope | null;\n readonly principalMutationTimeoutMs?: number | undefined;\n}\n\nfunction mutationContext(\n input: PrincipalMutationApiCustodyInput,\n scope: PrincipalMutationRuntimeScope | null,\n organizationId: string,\n) {\n if (!scope)\n throw new Error(\n \"Principal mutations require an authenticated signing identity, a trusted API origin and durable local storage\",\n );\n return {\n execSql: scope.execSql,\n signingKeyPair: scope.signingKeyPair,\n scope: {\n identityTrustDomain: scope.identityTrustDomain,\n organizationId,\n signingFingerprint: scope.signingFingerprint,\n userId: scope.userId,\n },\n stillCurrent: () => sameScope(input.readScope(), scope),\n };\n}\n\n/** Keep API methods bound to their real receiver and journal only policy writes. */\nexport function createPrincipalMutationApiCustody(\n input: PrincipalMutationApiCustodyInput,\n) {\n const dispatch = createPrincipalMutationDispatcher(\n input.principalMutationTimeoutMs,\n );\n let cached: {\n scope: PrincipalMutationRuntimeScope | null;\n api: PrincipalMutationApi;\n } | null = null;\n return {\n bind(): PrincipalMutationApi {\n const scope = input.readScope();\n if (cached && sameScope(scope, cached.scope)) return cached.api;\n const context = (organizationId: string) =>\n mutationContext(input, scope, organizationId);\n const commit: ApiClient[\"commitOrganizationGroupPolicyResult\"] = async (\n organizationId,\n groupId,\n request,\n options,\n ) =>\n submitJournaledPrincipalMutation({\n ...context(organizationId),\n mutation: { groupId, request },\n submit: (mutation) =>\n dispatch(options, (dispatchOptions) =>\n input.api.commitOrganizationGroupPolicyResult(\n organizationId,\n mutation.groupId,\n mutation.request,\n dispatchOptions,\n ),\n ),\n });\n const read: PrincipalMutationRecoveryApi[\"readPendingPrincipalMutation\"] =\n async (organizationId) =>\n scope\n ? readJournaledPrincipalMutation(context(organizationId))\n : null;\n const abandon: PrincipalMutationRecoveryApi[\"abandonPendingPrincipalMutation\"] =\n async (organizationId, mutation, acknowledgeUnknownOutcome) =>\n abandonJournaledPrincipalMutation({\n ...context(organizationId),\n mutation,\n acknowledgeUnknownOutcome,\n });\n const methods = {\n discardUnreadablePrincipalMutation: async (\n organizationId,\n recordId,\n acknowledgeUnknownOutcome,\n ) =>\n discardUnreadableJournaledPrincipalMutation({\n ...context(organizationId),\n recordId,\n acknowledgeUnknownOutcome,\n }),\n readPendingPrincipalMutation: read,\n abandonPendingPrincipalMutation: abandon,\n commitOrganizationGroupPolicyResult: commit,\n commitOrganizationGroupPolicy: async (...args) => {\n const result = await commit(...args);\n return result.ok ? result.data : null;\n },\n recoverPendingPrincipalMutation: async (organizationId) => {\n await recoverJournaledPrincipalMutation({\n ...context(organizationId),\n submit: (mutation) =>\n dispatch({ reportErrors: false }, (dispatchOptions) =>\n input.api.commitOrganizationGroupPolicyResult(\n organizationId,\n mutation.groupId,\n mutation.request,\n dispatchOptions,\n ),\n ),\n });\n },\n } satisfies MutationOverrides;\n const api = bindMutationMethods(input.api, methods);\n cached = { scope, api };\n return api;\n },\n };\n}\n\nfunction bindMutationMethods(\n api: ApiClient,\n methods: MutationOverrides,\n): PrincipalMutationApi {\n const boundMethods = new Map<\n PropertyKey,\n { source: unknown; bound: unknown }\n >();\n const bound = new Proxy(api, {\n get(target, property) {\n if (Object.hasOwn(methods, property))\n return Reflect.get(methods, property);\n const value: unknown = Reflect.get(target, property, target);\n if (typeof value !== \"function\") return value;\n const previous = boundMethods.get(property);\n if (previous?.source === value) return previous.bound;\n const bound = value.bind(target);\n boundMethods.set(property, { source: value, bound });\n return bound;\n },\n });\n // The checked overrides supply the signatures; verify their presence through\n // the reflective boundary before exposing the extended API to callers.\n if (!hasRecoveryMethods(bound))\n throw new Error(\"Principal mutation recovery methods are unavailable\");\n return bound;\n}\n\nfunction hasRecoveryMethods(api: ApiClient): api is PrincipalMutationApi {\n return (\n typeof Reflect.get(api, \"readPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"recoverPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"abandonPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"discardUnreadablePrincipalMutation\") === \"function\"\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"principalMutationApi.js","sourceRoot":"","sources":["principalMutationApi.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iCAAiC,EACjC,2CAA2C,EAE3C,8BAA8B,GAC/B,MAAM,+DAA+D,CAAC;AACvE,OAAO,EAAE,iCAAiC,EAAE,MAAM,4DAA4D,CAAC;AAC/G,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EACL,iCAAiC,EACjC,iCAAiC,GAElC,MAAM,6BAA6B,CAAC;AA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ED,SAAS,kBAAkB,CAAC,GAAc;IACxC,OAAO,CACL,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,8BAA8B,CAAC,KAAK,UAAU;QACtE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,iCAAiC,CAAC,KAAK,UAAU;QACzE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,iCAAiC,CAAC,KAAK,UAAU;QACzE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,oCAAoC,CAAC,KAAK,UAAU,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { SigningKeyPair } from \"@tearleads/crypto\";\nimport type { ExecSql } from \"../data/sqlite/sqlSchema\";\nimport {\n abandonJournaledPrincipalMutation,\n discardUnreadableJournaledPrincipalMutation,\n type PrincipalMutationRecoveryApi,\n readJournaledPrincipalMutation,\n} from \"../workflows/organizations/principalMutationJournalManagement\";\nimport { recoverJournaledPrincipalMutation } from \"../workflows/organizations/principalMutationJournalSession\";\nimport { createPrincipalMutationDispatcher } from \"./principalMutationDeadline\";\nimport {\n createJournaledPrincipalMutations,\n dispatchAuthoredPrincipalMutation,\n type JournaledPrincipalMutationMethods,\n} from \"./principalMutationDispatch\";\n\nexport interface PrincipalMutationRuntimeScope {\n readonly database: object;\n readonly execSql: ExecSql;\n readonly generation: number;\n readonly identityTrustDomain: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly userId: string;\n}\n\nfunction sameScope(\n current: PrincipalMutationRuntimeScope | null,\n bound: PrincipalMutationRuntimeScope | null,\n): boolean {\n if (!current || !bound) return current === bound;\n return (\n current.database === bound.database &&\n current.execSql === bound.execSql &&\n current.generation === bound.generation &&\n current.identityTrustDomain === bound.identityTrustDomain &&\n current.signingFingerprint === bound.signingFingerprint &&\n current.signingKeyPair === bound.signingKeyPair &&\n current.userId === bound.userId\n );\n}\n\nexport type PrincipalMutationApi = ApiClient & PrincipalMutationRecoveryApi;\ntype MutationOverrides = JournaledPrincipalMutationMethods &\n PrincipalMutationRecoveryApi;\n\ninterface PrincipalMutationApiCustodyInput {\n readonly api: ApiClient;\n readonly readScope: () => PrincipalMutationRuntimeScope | null;\n readonly principalMutationTimeoutMs?: number | undefined;\n}\n\nfunction mutationContext(\n input: PrincipalMutationApiCustodyInput,\n scope: PrincipalMutationRuntimeScope | null,\n organizationId: string,\n) {\n if (!scope)\n throw new Error(\n \"Principal mutations require an authenticated signing identity, a trusted API origin and durable local storage\",\n );\n return {\n execSql: scope.execSql,\n signingKeyPair: scope.signingKeyPair,\n scope: {\n identityTrustDomain: scope.identityTrustDomain,\n organizationId,\n signingFingerprint: scope.signingFingerprint,\n userId: scope.userId,\n },\n stillCurrent: () => sameScope(input.readScope(), scope),\n };\n}\n\n/** Keep API methods bound to their real receiver and journal principal policy and group lifecycle writes. */\nexport function createPrincipalMutationApiCustody(\n input: PrincipalMutationApiCustodyInput,\n) {\n const dispatch = createPrincipalMutationDispatcher(\n input.principalMutationTimeoutMs,\n );\n let cached: {\n scope: PrincipalMutationRuntimeScope | null;\n api: PrincipalMutationApi;\n } | null = null;\n return {\n bind(): PrincipalMutationApi {\n const scope = input.readScope();\n if (cached && sameScope(scope, cached.scope)) return cached.api;\n const context = (organizationId: string) =>\n mutationContext(input, scope, organizationId);\n const read: PrincipalMutationRecoveryApi[\"readPendingPrincipalMutation\"] =\n async (organizationId) =>\n scope\n ? readJournaledPrincipalMutation(context(organizationId))\n : null;\n const abandon: PrincipalMutationRecoveryApi[\"abandonPendingPrincipalMutation\"] =\n async (organizationId, mutation, acknowledgeUnknownOutcome) =>\n abandonJournaledPrincipalMutation({\n ...context(organizationId),\n mutation,\n acknowledgeUnknownOutcome,\n });\n const methods = {\n ...createJournaledPrincipalMutations(input.api, context, dispatch),\n discardUnreadablePrincipalMutation: async (\n organizationId,\n recordId,\n acknowledgeUnknownOutcome,\n ) =>\n discardUnreadableJournaledPrincipalMutation({\n ...context(organizationId),\n recordId,\n acknowledgeUnknownOutcome,\n }),\n readPendingPrincipalMutation: read,\n abandonPendingPrincipalMutation: abandon,\n recoverPendingPrincipalMutation: async (organizationId) => {\n await recoverJournaledPrincipalMutation({\n ...context(organizationId),\n submit: (mutation) =>\n dispatch({ reportErrors: false }, (dispatchOptions) =>\n dispatchAuthoredPrincipalMutation(\n input.api,\n organizationId,\n mutation,\n dispatchOptions,\n ),\n ),\n });\n },\n } satisfies MutationOverrides;\n const api = bindMutationMethods(input.api, methods);\n cached = { scope, api };\n return api;\n },\n };\n}\n\nfunction bindMutationMethods(\n api: ApiClient,\n methods: MutationOverrides,\n): PrincipalMutationApi {\n const boundMethods = new Map<\n PropertyKey,\n { source: unknown; bound: unknown }\n >();\n const bound = new Proxy(api, {\n get(target, property) {\n if (Object.hasOwn(methods, property))\n return Reflect.get(methods, property);\n const value: unknown = Reflect.get(target, property, target);\n if (typeof value !== \"function\") return value;\n const previous = boundMethods.get(property);\n if (previous?.source === value) return previous.bound;\n const bound = value.bind(target);\n boundMethods.set(property, { source: value, bound });\n return bound;\n },\n });\n // The checked overrides supply the signatures; verify their presence through\n // the reflective boundary before exposing the extended API to callers.\n if (!hasRecoveryMethods(bound))\n throw new Error(\"Principal mutation recovery methods are unavailable\");\n return bound;\n}\n\nfunction hasRecoveryMethods(api: ApiClient): api is PrincipalMutationApi {\n return (\n typeof Reflect.get(api, \"readPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"recoverPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"abandonPendingPrincipalMutation\") === \"function\" &&\n typeof Reflect.get(api, \"discardUnreadablePrincipalMutation\") === \"function\"\n );\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isCommitOrganizationGroupPolicyResponse, isCreateOrganizationGroupResponse, isDeleteOrganizationGroupResponse, isPrincipalPolicyMutationResponse, } from "../internal/validators/response/index.js";
|
|
2
|
+
import { submitJournaledPrincipalMutation, } from "../workflows/organizations/principalMutationJournalSession.js";
|
|
3
|
+
/** Dispatch the authenticated operation, with no application planning callback. */
|
|
4
|
+
export function dispatchAuthoredPrincipalMutation(api, organizationId, mutation, options = {}) {
|
|
5
|
+
switch (mutation.kind) {
|
|
6
|
+
case "organization":
|
|
7
|
+
return api.putPrincipalPolicyResult("organization", organizationId, mutation.request, options);
|
|
8
|
+
case "group-create":
|
|
9
|
+
return api.createOrganizationGroupResult(organizationId, mutation.request, options);
|
|
10
|
+
case "group-delete":
|
|
11
|
+
return api.deleteOrganizationGroupResult(organizationId, mutation.groupId, mutation.request, options);
|
|
12
|
+
case undefined:
|
|
13
|
+
return api.commitOrganizationGroupPolicyResult(organizationId, mutation.groupId, mutation.request, options);
|
|
14
|
+
default:
|
|
15
|
+
return unsupportedMutation(mutation);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function unsupportedMutation(_mutation) {
|
|
19
|
+
throw new Error("Unsupported principal mutation operation");
|
|
20
|
+
}
|
|
21
|
+
export function createJournaledPrincipalMutations(api, context, dispatch) {
|
|
22
|
+
async function submit(organizationId, mutation, validator, options = {}) {
|
|
23
|
+
const result = await submitJournaledPrincipalMutation({
|
|
24
|
+
...context(organizationId),
|
|
25
|
+
mutation,
|
|
26
|
+
submit: (saved) => dispatch(options, (dispatchOptions) => dispatchAuthoredPrincipalMutation(api, organizationId, saved, dispatchOptions)),
|
|
27
|
+
});
|
|
28
|
+
if (!result.ok)
|
|
29
|
+
return result;
|
|
30
|
+
// The session already verified this operation before clearing its row.
|
|
31
|
+
// This check narrows the union for each existing public API signature.
|
|
32
|
+
if (!validator(result.data))
|
|
33
|
+
throw new Error("Unexpected principal receipt operation");
|
|
34
|
+
return { ok: true, data: result.data };
|
|
35
|
+
}
|
|
36
|
+
const commit = (organizationId, groupId, request, options) => submit(organizationId, { groupId, request }, isCommitOrganizationGroupPolicyResponse, options);
|
|
37
|
+
const create = (organizationId, request, options) => submit(organizationId, { kind: "group-create", groupId: request.groupId, request }, isCreateOrganizationGroupResponse, options);
|
|
38
|
+
const remove = (organizationId, groupId, request, options) => submit(organizationId, { kind: "group-delete", groupId, request }, isDeleteOrganizationGroupResponse, options);
|
|
39
|
+
const put = (_type, organizationId, request, options) => submit(organizationId, { kind: "organization", groupId: null, request }, isPrincipalPolicyMutationResponse, options);
|
|
40
|
+
return {
|
|
41
|
+
commitOrganizationGroupPolicyResult: commit,
|
|
42
|
+
commitOrganizationGroupPolicy: async (...args) => nullable(await commit(...args)),
|
|
43
|
+
createOrganizationGroupResult: create,
|
|
44
|
+
createOrganizationGroup: async (...args) => nullable(await create(...args)),
|
|
45
|
+
deleteOrganizationGroupResult: remove,
|
|
46
|
+
deleteOrganizationGroup: async (...args) => nullable(await remove(...args)),
|
|
47
|
+
putPrincipalPolicyResult: put,
|
|
48
|
+
putPrincipalPolicy: async (...args) => nullable(await put(...args)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function nullable(result) {
|
|
52
|
+
return result.ok ? result.data : null;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=principalMutationDispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principalMutationDispatch.js","sourceRoot":"","sources":["principalMutationDispatch.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,uCAAuC,EACvC,iCAAiC,EACjC,iCAAiC,EACjC,iCAAiC,GAClC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAEL,gCAAgC,GACjC,MAAM,4DAA4D,CAAC;AAiBpE,mFAAmF;AACnF,MAAM,UAAU,iCAAiC,CAC/C,GAAc,EACd,cAAsB,EACtB,QAAmC,EACnC,UAAgC,EAAE;IAElC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,cAAc;YACjB,OAAO,GAAG,CAAC,wBAAwB,CACjC,cAAc,EACd,cAAc,EACd,QAAQ,CAAC,OAAO,EAChB,OAAO,CACR,CAAC;QACJ,KAAK,cAAc;YACj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AAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3E,wBAAwB,EAAE,GAAG;QAC7B,kBAAkB,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;KACpE,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAI,MAAwB;IAC3C,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC","sourcesContent":["import type {\n ApiClient,\n RequestResult,\n RequestResultOptions,\n} from \"@tearleads/api-client\";\nimport {\n isCommitOrganizationGroupPolicyResponse,\n isCreateOrganizationGroupResponse,\n isDeleteOrganizationGroupResponse,\n isPrincipalPolicyMutationResponse,\n} from \"@tearleads/validators/response\";\nimport type { AuthoredPrincipalMutation } from \"../data/principals/principalMutationJournal\";\nimport {\n type PrincipalMutationJournalContext,\n submitJournaledPrincipalMutation,\n} from \"../workflows/organizations/principalMutationJournalSession\";\nimport type { PrincipalMutationResponse } from \"../workflows/organizations/principalOperationReceipt\";\n\nimport type { createPrincipalMutationDispatcher } from \"./principalMutationDeadline\";\n\nexport type JournaledPrincipalMutationMethods = Pick<\n ApiClient,\n | \"commitOrganizationGroupPolicy\"\n | \"commitOrganizationGroupPolicyResult\"\n | \"createOrganizationGroup\"\n | \"createOrganizationGroupResult\"\n | \"deleteOrganizationGroup\"\n | \"deleteOrganizationGroupResult\"\n | \"putPrincipalPolicy\"\n | \"putPrincipalPolicyResult\"\n>;\n\n/** Dispatch the authenticated operation, with no application planning callback. */\nexport function dispatchAuthoredPrincipalMutation(\n api: ApiClient,\n organizationId: string,\n mutation: AuthoredPrincipalMutation,\n options: RequestResultOptions = {},\n): Promise<RequestResult<PrincipalMutationResponse>> {\n switch (mutation.kind) {\n case \"organization\":\n return api.putPrincipalPolicyResult(\n \"organization\",\n organizationId,\n mutation.request,\n options,\n );\n case \"group-create\":\n return api.createOrganizationGroupResult(\n organizationId,\n mutation.request,\n options,\n );\n case \"group-delete\":\n return api.deleteOrganizationGroupResult(\n organizationId,\n mutation.groupId,\n mutation.request,\n options,\n );\n case undefined:\n return api.commitOrganizationGroupPolicyResult(\n organizationId,\n mutation.groupId,\n mutation.request,\n options,\n );\n default:\n return unsupportedMutation(mutation);\n }\n}\n\nfunction unsupportedMutation(_mutation: never): never {\n throw new Error(\"Unsupported principal mutation operation\");\n}\n\nexport function createJournaledPrincipalMutations(\n api: ApiClient,\n context: (\n organizationId: string,\n ) => Omit<PrincipalMutationJournalContext, \"submit\">,\n dispatch: ReturnType<typeof createPrincipalMutationDispatcher>,\n): JournaledPrincipalMutationMethods {\n async function submit<T extends PrincipalMutationResponse>(\n organizationId: string,\n mutation: AuthoredPrincipalMutation,\n validator: (value: unknown) => value is T,\n options: RequestResultOptions = {},\n ): Promise<RequestResult<T>> {\n const result = await submitJournaledPrincipalMutation({\n ...context(organizationId),\n mutation,\n submit: (saved) =>\n dispatch(options, (dispatchOptions) =>\n dispatchAuthoredPrincipalMutation(\n api,\n organizationId,\n saved,\n dispatchOptions,\n ),\n ),\n });\n if (!result.ok) return result;\n // The session already verified this operation before clearing its row.\n // This check narrows the union for each existing public API signature.\n if (!validator(result.data))\n throw new Error(\"Unexpected principal receipt operation\");\n return { ok: true, data: result.data };\n }\n const commit: ApiClient[\"commitOrganizationGroupPolicyResult\"] = (\n organizationId,\n groupId,\n request,\n options,\n ) =>\n submit(\n organizationId,\n { groupId, request },\n isCommitOrganizationGroupPolicyResponse,\n options,\n );\n const create: ApiClient[\"createOrganizationGroupResult\"] = (\n organizationId,\n request,\n options,\n ) =>\n submit(\n organizationId,\n { kind: \"group-create\", groupId: request.groupId, request },\n isCreateOrganizationGroupResponse,\n options,\n );\n const remove: ApiClient[\"deleteOrganizationGroupResult\"] = (\n organizationId,\n groupId,\n request,\n options,\n ) =>\n submit(\n organizationId,\n { kind: \"group-delete\", groupId, request },\n isDeleteOrganizationGroupResponse,\n options,\n );\n const put: ApiClient[\"putPrincipalPolicyResult\"] = (\n _type,\n organizationId,\n request,\n options,\n ) =>\n submit(\n organizationId,\n { kind: \"organization\", groupId: null, request },\n isPrincipalPolicyMutationResponse,\n options,\n );\n return {\n commitOrganizationGroupPolicyResult: commit,\n commitOrganizationGroupPolicy: async (...args) =>\n nullable(await commit(...args)),\n createOrganizationGroupResult: create,\n createOrganizationGroup: async (...args) => nullable(await create(...args)),\n deleteOrganizationGroupResult: remove,\n deleteOrganizationGroup: async (...args) => nullable(await remove(...args)),\n putPrincipalPolicyResult: put,\n putPrincipalPolicy: async (...args) => nullable(await put(...args)),\n };\n}\n\nfunction nullable<T>(result: RequestResult<T>): T | null {\n return result.ok ? result.data : null;\n}\n"]}
|
|
@@ -7,9 +7,9 @@ import type { PrincipalHistoryStage } from "./principalHistoryStagePersistence.j
|
|
|
7
7
|
export interface AcknowledgedPrincipalCurrentPublication {
|
|
8
8
|
readonly policy: VerifiedPrincipalPolicyCurrent;
|
|
9
9
|
readonly prefix: PrincipalHistoryPrefix;
|
|
10
|
-
readonly previousPrefixProgress: string;
|
|
10
|
+
readonly previousPrefixProgress: string | null;
|
|
11
11
|
readonly stage: PrincipalHistoryStage;
|
|
12
|
-
readonly predecessorStage: PrincipalHistoryStage;
|
|
12
|
+
readonly predecessorStage: PrincipalHistoryStage | null;
|
|
13
13
|
readonly evidence: PrincipalHistoryEvidencePage;
|
|
14
14
|
}
|
|
15
15
|
export interface AcknowledgedPrincipalCurrentRetirement {
|