@tearleads/client-sdk 0.1.209 → 0.1.211
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/organizations/index.js +5 -5
- package/client/organizations/index.js.map +1 -1
- package/client/organizations/principalMutationScope.js +7 -1
- package/client/organizations/principalMutationScope.js.map +1 -1
- package/client/organizations/principalMutations.d.ts +8 -6
- package/client/organizations/principalMutations.js +8 -8
- package/client/organizations/principalMutations.js.map +1 -1
- package/client/organizations/recipientAdmission.d.ts +2 -1
- package/client/organizations/recipientAdmission.js +2 -2
- package/client/organizations/recipientAdmission.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +2 -1
- package/client/runtime/workflowRuntime.js +1 -1
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/persistence/container-contents/documentMoveIntentPersistence.js +47 -30
- package/data/persistence/container-contents/documentMoveIntentPersistence.js.map +1 -1
- package/data/persistence/container-contents/documentPlacementIntentEnqueue.js +6 -14
- package/data/persistence/container-contents/documentPlacementIntentEnqueue.js.map +1 -1
- package/package.json +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntentErrors.js +2 -2
- package/workflows/container-contents/documentMove/documentMoveIntentErrors.js.map +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntentSettlement.js +3 -2
- package/workflows/container-contents/documentMove/documentMoveIntentSettlement.js.map +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntentSync.js +4 -3
- package/workflows/container-contents/documentMove/documentMoveIntentSync.js.map +1 -1
- package/workflows/container-contents/pendingWrites/index.js +3 -3
- package/workflows/container-contents/pendingWrites/index.js.map +1 -1
- package/workflows/container-contents/recovery/accessRestoration.js +4 -7
- package/workflows/container-contents/recovery/accessRestoration.js.map +1 -1
|
@@ -7,7 +7,7 @@ import { createOrganizationReadModelCoordinator, leaveRequestVerifier, } from ".
|
|
|
7
7
|
import { activeOrganizationDataRuntime, authenticatedOrganizationId, runForOrganization, } from "./organizationWorkflowRuntime.js";
|
|
8
8
|
import { listPendingBlobDeletions } from "./pendingBlobDeletions.js";
|
|
9
9
|
import { abandonPendingOrganizationPolicyMutation, discardUnreadableOrganizationPolicyMutation, readPendingOrganizationPolicyMutation, retryPendingOrganizationPolicyMutation, } from "./principalMutationRecovery.js";
|
|
10
|
-
import {
|
|
10
|
+
import { currentOrganizationSigningMutation } from "./principalMutationScope.js";
|
|
11
11
|
import { addUserToOrganizationGroup, createGroupForOrganization, deleteGroupForOrganization, removeUserFromOrganizationGroup, revokeOrganizationGrant, } from "./principalMutations.js";
|
|
12
12
|
import { admitGroupMutation } from "./recipientAdmission.js";
|
|
13
13
|
export function createOrganizations(runtime, containerContents, openReconciler) {
|
|
@@ -53,13 +53,13 @@ class OrganizationsService {
|
|
|
53
53
|
createGroup(name) {
|
|
54
54
|
return createGroupForOrganization({
|
|
55
55
|
name,
|
|
56
|
-
...
|
|
56
|
+
...currentOrganizationSigningMutation(this.runtimeService),
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
deleteGroup(groupId) {
|
|
60
60
|
return deleteGroupForOrganization({
|
|
61
61
|
groupId,
|
|
62
|
-
...
|
|
62
|
+
...currentOrganizationSigningMutation(this.runtimeService),
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
loadBilling() {
|
|
@@ -222,7 +222,7 @@ class OrganizationsService {
|
|
|
222
222
|
...input,
|
|
223
223
|
containerContents: this.containerContents,
|
|
224
224
|
readModelCoordinator: this.readModelCoordinator,
|
|
225
|
-
...
|
|
225
|
+
...currentOrganizationSigningMutation(this.runtimeService),
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
async revokeGrant(grant) {
|
|
@@ -230,7 +230,7 @@ class OrganizationsService {
|
|
|
230
230
|
...grant,
|
|
231
231
|
containerContents: this.containerContents,
|
|
232
232
|
readModelCoordinator: this.readModelCoordinator,
|
|
233
|
-
...
|
|
233
|
+
...currentOrganizationSigningMutation(this.runtimeService),
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
startTrial(organizationId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,EAC9B,mCAAmC,EACnC,oBAAoB,EACpB,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EACzB,kCAAkC,EAClC,sBAAsB,EACtB,yBAAyB,EACzB,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,sCAAsC,GAEvC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,wCAAwC,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EACL,6BAA6B,GAG9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,sCAAsC,EACtC,oBAAoB,GAErB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAEL,wCAAwC,EAExC,2CAA2C,EAC3C,qCAAqC,EACrC,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAEL,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAG1B,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAqD1D,MAAM,UAAU,mBAAmB,CACjC,OAAwB,EACxB,iBAAoC,EACpC,cAAmD;IAEnD,OAAO,IAAI,oBAAoB,CAAC,OA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,IAAI,CAAC,MAAM,IAAI,EAAE;aAClC,CAAC,CACH,CACF,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,iBAAgC;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QACpD,MAAM,cAAc,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,yBAAyB,CAAC;YAC/B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,cAAc;YACd,iBAAiB;SAClB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAuC;QAC/D,OAAO,+BAA+B,CAAC;YACrC,GAAG,KAAK;YACR,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,GAAG,2BAA2B,CAAC,IAAI,CAAC,cAAc,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAA2B;QAC3C,OAAO,uBAAuB,CAAC;YAC7B,GAAG,KAAK;YACR,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,GAAG,2BAA2B,CAAC,IAAI,CAAC,cAAc,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,cAAuB;QAChC,OAAO,kBAAkB,CACvB,IAAI,CAAC,cAAc,EACnB,sBAAsB,EACtB,cAAc,CACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { NativeSubscriptionStore } from \"@tearleads/validators/billing\";\nimport type { PendingBlobDeletionsQuery } from \"@tearleads/validators/operation\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n cancelStripeSubscription,\n changeStripePlan,\n checkNativePurchaseEligibility,\n claimNativeOrganizationSubscription,\n createStripeCheckout,\n createStripeCheckoutSession,\n listLocalOrganizations,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n loadStripeCheckoutOptions,\n measureOrganizationDeviceDataUsage,\n startOrganizationTrial,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n withVerifiedDirectoryUser,\n} from \"../../workflows/organizations\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport {\n createOrganizationDataUsageCoordinator,\n type OrganizationDataUsageCoordinator,\n} from \"./organizationDataUsage\";\nimport { loadOrganizationGroupPresentationDetails } from \"./organizationGroupPresentation\";\nimport {\n createOrganizationMemberships,\n type OrganizationContentReconciler,\n type OrganizationMemberships,\n} from \"./organizationMemberships\";\nimport {\n createOrganizationReadModelCoordinator,\n leaveRequestVerifier,\n type OrganizationReadModelCoordinator,\n} from \"./organizationReadModels\";\nimport type { Organizations } from \"./organizationsTypes\";\nimport {\n activeOrganizationDataRuntime,\n authenticatedOrganizationId,\n runForOrganization,\n} from \"./organizationWorkflowRuntime\";\nimport { listPendingBlobDeletions } from \"./pendingBlobDeletions\";\nimport {\n type AbandonOrganizationPolicyMutationInput,\n abandonPendingOrganizationPolicyMutation,\n type DiscardUnreadableOrganizationPolicyMutationInput,\n discardUnreadableOrganizationPolicyMutation,\n readPendingOrganizationPolicyMutation,\n retryPendingOrganizationPolicyMutation,\n} from \"./principalMutationRecovery\";\nimport { currentOrganizationMutation } from \"./principalMutationScope\";\nimport {\n type AddOrganizationGroupUserInput,\n addUserToOrganizationGroup,\n createGroupForOrganization,\n deleteGroupForOrganization,\n type OrganizationGrantRef,\n type RemoveOrganizationGroupUserInput,\n removeUserFromOrganizationGroup,\n revokeOrganizationGrant,\n} from \"./principalMutations\";\nimport { admitGroupMutation } from \"./recipientAdmission\";\n\nexport type {\n LocalOrganizationSummary,\n OrganizationBilling,\n OrganizationBillingHistory,\n OrganizationBillingHistoryEntry,\n OrganizationBillingManagementUrl,\n OrganizationBillingView,\n OrganizationContainerGrant,\n OrganizationContainerGrants,\n OrganizationDataUsage,\n OrganizationDeviceDataUsage,\n OrganizationDeviceDocumentUsageCategoryBreakdown,\n OrganizationDirectory,\n OrganizationDirectoryAndGroups,\n OrganizationDirectoryUser,\n OrganizationGroupContainer,\n OrganizationGroupContainers,\n OrganizationGroupDetails,\n OrganizationGroupMember,\n OrganizationGroupMembers,\n OrganizationGroupPolicyHistory,\n OrganizationGroupSummary,\n OrganizationLeaveRequestResult,\n OrganizationMembership,\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n OrganizationPolicyHistory,\n OrganizationPolicyHistoryEntry,\n OrganizationProfile,\n OrganizationSyncPauseResult,\n OrganizationUserDetail,\n} from \"../../workflows/organizations\";\nexport type {\n OrganizationContentReconciler,\n OrganizationMemberships,\n} from \"./organizationMemberships\";\nexport type {\n OrganizationGroupMutationReceipt,\n OrganizationGroupMutationResult,\n Organizations,\n} from \"./organizationsTypes\";\nexport type {\n AbandonOrganizationPolicyMutationInput,\n DiscardUnreadableOrganizationPolicyMutationInput,\n} from \"./principalMutationRecovery\";\nexport type {\n AddOrganizationGroupUserInput,\n OrganizationGrantRef,\n RemoveOrganizationGroupUserInput,\n} from \"./principalMutations\";\n\nexport function createOrganizations(\n runtime: InternalRuntime,\n containerContents: ContainerContents,\n openReconciler: () => OrganizationContentReconciler,\n): Organizations {\n return new OrganizationsService(runtime, containerContents, openReconciler);\n}\n\nclass OrganizationsService implements Organizations {\n readonly memberships: OrganizationMemberships;\n private readonly dataUsageCoordinator: OrganizationDataUsageCoordinator;\n private readonly readModelCoordinator: OrganizationReadModelCoordinator;\n\n constructor(\n private readonly runtimeService: InternalRuntime,\n private readonly containerContents: ContainerContents,\n openReconciler: () => OrganizationContentReconciler,\n ) {\n this.dataUsageCoordinator = createOrganizationDataUsageCoordinator(\n this.runtimeService,\n );\n this.readModelCoordinator = createOrganizationReadModelCoordinator(\n this.runtimeService,\n );\n this.memberships = createOrganizationMemberships(\n this.runtimeService,\n this.containerContents,\n openReconciler,\n );\n }\n\n listPendingBlobDeletions(\n organizationId: string,\n query?: PendingBlobDeletionsQuery,\n ) {\n return listPendingBlobDeletions(this.runtimeService, organizationId, query);\n }\n\n async addUserToGroup(input: AddOrganizationGroupUserInput) {\n const mutation = await admitGroupMutation(\n this.runtimeService,\n input.targetUserId,\n );\n return addUserToOrganizationGroup({\n ...input,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...mutation,\n });\n }\n\n readPendingPolicyMutation(organizationId: string) {\n return readPendingOrganizationPolicyMutation(\n this.runtimeService,\n organizationId,\n );\n }\n\n discardUnreadablePolicyMutation(\n input: DiscardUnreadableOrganizationPolicyMutationInput,\n ) {\n return discardUnreadableOrganizationPolicyMutation(\n this.runtimeService,\n input,\n );\n }\n\n retryPendingPolicyMutation(organizationId: string) {\n return retryPendingOrganizationPolicyMutation(\n this.runtimeService,\n organizationId,\n );\n }\n\n abandonPendingPolicyMutation(input: AbandonOrganizationPolicyMutationInput) {\n return abandonPendingOrganizationPolicyMutation(this.runtimeService, input);\n }\n\n createGroup(name: string) {\n return createGroupForOrganization({\n name,\n ...currentOrganizationMutation(this.runtimeService),\n });\n }\n\n deleteGroup(groupId: string) {\n return deleteGroupForOrganization({\n groupId,\n ...currentOrganizationMutation(this.runtimeService),\n });\n }\n\n loadBilling() {\n return runForOrganization(this.runtimeService, loadOrganizationBilling);\n }\n\n loadBillingForOrganization(organizationId: string) {\n // Gated on an authenticated session rather than on the target being the\n // active org. The server still enforces membership, so an org the caller\n // cannot reach resolves to `null`.\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBilling,\n organizationId,\n );\n }\n\n loadBillingHistory() {\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBillingHistory,\n );\n }\n\n loadBillingManagementUrl() {\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBillingManagementUrl,\n );\n }\n\n loadStripeCheckoutOptions(organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n loadStripeCheckoutOptions,\n organizationId,\n );\n }\n\n createStripeCheckout(priceId: string, organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n (input) => createStripeCheckout({ ...input, priceId }),\n organizationId,\n );\n }\n\n createStripeCheckoutSession(\n priceId: string,\n returnUrl: string,\n organizationId?: string,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => createStripeCheckoutSession({ ...input, priceId, returnUrl }),\n organizationId,\n );\n }\n\n cancelStripeSubscription() {\n return runForOrganization(this.runtimeService, cancelStripeSubscription);\n }\n\n changeStripePlan(\n priceId: string,\n currentSeatCount: number,\n organizationId?: string,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => changeStripePlan({ ...input, currentSeatCount, priceId }),\n organizationId,\n );\n }\n\n claimNativeSubscription(\n organizationId: string,\n store: NativeSubscriptionStore,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => claimNativeOrganizationSubscription({ ...input, store }),\n organizationId,\n );\n }\n\n checkNativePurchaseEligibility(\n organizationId: string,\n store: NativeSubscriptionStore,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => checkNativePurchaseEligibility({ ...input, store }),\n organizationId,\n );\n }\n\n loadDataUsage() {\n return this.dataUsageCoordinator.reconcile();\n }\n\n loadLocalDataUsage() {\n return this.dataUsageCoordinator.loadLocal();\n }\n\n loadDeviceDataUsage() {\n const active = activeOrganizationDataRuntime(this.runtimeService);\n if (!active) {\n return Promise.resolve(null);\n }\n return measureOrganizationDeviceDataUsage({\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n });\n }\n\n loadAppliedReadModelCursor() {\n return this.readModelCoordinator.loadAppliedCursor();\n }\n\n loadDirectoryAndGroups() {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.read_model.reconcile\",\n organizationId: runtime.auth.organizationId,\n },\n () => this.readModelCoordinator.reconcile(),\n );\n }\n\n loadDirectoryAndGroupsAfterMutation() {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.read_model.reconcile_after_mutation\",\n organizationId: runtime.auth.organizationId,\n },\n () => this.readModelCoordinator.reconcileAfterMutation(),\n );\n }\n\n loadLocalDirectoryAndGroups() {\n return this.readModelCoordinator.loadLocal();\n }\n\n loadGroupMembers(groupId: string) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId || groupId.length === 0) {\n return Promise.resolve(null);\n }\n\n return runtime.apiClient.listOrganizationGroupMembers(\n organizationId,\n groupId,\n );\n }\n\n loadGroupPresentationDetails(groupId: string, beforeVersion?: number) {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: groupId,\n objectKind: \"principal\",\n operation: \"group.presentation.load\",\n organizationId: runtime.auth.organizationId,\n },\n () =>\n loadOrganizationGroupPresentationDetails({\n groupId,\n beforeVersion,\n readModelCoordinator: this.readModelCoordinator,\n runtime,\n }),\n );\n }\n\n loadGrants() {\n return this.readModelCoordinator.loadLocalGrants();\n }\n\n loadGroupContainers(groupId: string) {\n return this.readModelCoordinator.loadLocalGroupContainers(groupId);\n }\n\n listLocalOrganizations() {\n const runtime = this.runtimeService.workflowInput();\n if (runtime.infra.dbStatus !== \"ready\") {\n return Promise.resolve([]);\n }\n\n return listLocalOrganizations({ execSql: runtime.infra.execSql });\n }\n\n loadPolicyHistory(beforeVersion?: number) {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.policy_history.load\",\n organizationId: runtime.auth.organizationId,\n },\n () =>\n this.readModelCoordinator.loadOrganizationPolicyHistory(\n undefined,\n beforeVersion,\n ),\n );\n }\n\n loadUserDetail(userId: string) {\n return this.readModelCoordinator.loadLocalUserDetail(userId);\n }\n\n async updateRosterEntry(userId: string, profileDocumentId: string | null) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId || userId.length === 0) {\n return null;\n }\n\n const user = await updateOrganizationRosterEntry({\n apiClient: runtime.apiClient,\n organizationId,\n profileDocumentId,\n userId,\n });\n // Callers store this response as directory state, so its leave request\n // passes the same check as one read from the read model.\n return (\n user &&\n withVerifiedDirectoryUser(\n organizationId,\n user,\n leaveRequestVerifier(this.runtimeService, runtime, {\n organizationId,\n userId: runtime.auth.userId ?? \"\",\n }),\n )\n );\n }\n\n updateProfile(profileDocumentId: string | null) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId) {\n return Promise.resolve(null);\n }\n\n return updateOrganizationProfile({\n apiClient: runtime.apiClient,\n organizationId,\n profileDocumentId,\n });\n }\n\n async removeUserFromGroup(input: RemoveOrganizationGroupUserInput) {\n return removeUserFromOrganizationGroup({\n ...input,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...currentOrganizationMutation(this.runtimeService),\n });\n }\n\n async revokeGrant(grant: OrganizationGrantRef) {\n return revokeOrganizationGrant({\n ...grant,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...currentOrganizationMutation(this.runtimeService),\n });\n }\n\n startTrial(organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n startOrganizationTrial,\n organizationId,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EA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,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,yBAAyB,CAAC;YAC/B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,cAAc;YACd,iBAAiB;SAClB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,KAAuC;QAC/D,OAAO,+BAA+B,CAAC;YACrC,GAAG,KAAK;YACR,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,GAAG,kCAAkC,CAAC,IAAI,CAAC,cAAc,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAA2B;QAC3C,OAAO,uBAAuB,CAAC;YAC7B,GAAG,KAAK;YACR,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,GAAG,kCAAkC,CAAC,IAAI,CAAC,cAAc,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,cAAuB;QAChC,OAAO,kBAAkB,CACvB,IAAI,CAAC,cAAc,EACnB,sBAAsB,EACtB,cAAc,CACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { NativeSubscriptionStore } from \"@tearleads/validators/billing\";\nimport type { PendingBlobDeletionsQuery } from \"@tearleads/validators/operation\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n cancelStripeSubscription,\n changeStripePlan,\n checkNativePurchaseEligibility,\n claimNativeOrganizationSubscription,\n createStripeCheckout,\n createStripeCheckoutSession,\n listLocalOrganizations,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n loadStripeCheckoutOptions,\n measureOrganizationDeviceDataUsage,\n startOrganizationTrial,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n withVerifiedDirectoryUser,\n} from \"../../workflows/organizations\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport {\n createOrganizationDataUsageCoordinator,\n type OrganizationDataUsageCoordinator,\n} from \"./organizationDataUsage\";\nimport { loadOrganizationGroupPresentationDetails } from \"./organizationGroupPresentation\";\nimport {\n createOrganizationMemberships,\n type OrganizationContentReconciler,\n type OrganizationMemberships,\n} from \"./organizationMemberships\";\nimport {\n createOrganizationReadModelCoordinator,\n leaveRequestVerifier,\n type OrganizationReadModelCoordinator,\n} from \"./organizationReadModels\";\nimport type { Organizations } from \"./organizationsTypes\";\nimport {\n activeOrganizationDataRuntime,\n authenticatedOrganizationId,\n runForOrganization,\n} from \"./organizationWorkflowRuntime\";\nimport { listPendingBlobDeletions } from \"./pendingBlobDeletions\";\nimport {\n type AbandonOrganizationPolicyMutationInput,\n abandonPendingOrganizationPolicyMutation,\n type DiscardUnreadableOrganizationPolicyMutationInput,\n discardUnreadableOrganizationPolicyMutation,\n readPendingOrganizationPolicyMutation,\n retryPendingOrganizationPolicyMutation,\n} from \"./principalMutationRecovery\";\nimport { currentOrganizationSigningMutation } from \"./principalMutationScope\";\nimport {\n type AddOrganizationGroupUserInput,\n addUserToOrganizationGroup,\n createGroupForOrganization,\n deleteGroupForOrganization,\n type OrganizationGrantRef,\n type RemoveOrganizationGroupUserInput,\n removeUserFromOrganizationGroup,\n revokeOrganizationGrant,\n} from \"./principalMutations\";\nimport { admitGroupMutation } from \"./recipientAdmission\";\n\nexport type {\n LocalOrganizationSummary,\n OrganizationBilling,\n OrganizationBillingHistory,\n OrganizationBillingHistoryEntry,\n OrganizationBillingManagementUrl,\n OrganizationBillingView,\n OrganizationContainerGrant,\n OrganizationContainerGrants,\n OrganizationDataUsage,\n OrganizationDeviceDataUsage,\n OrganizationDeviceDocumentUsageCategoryBreakdown,\n OrganizationDirectory,\n OrganizationDirectoryAndGroups,\n OrganizationDirectoryUser,\n OrganizationGroupContainer,\n OrganizationGroupContainers,\n OrganizationGroupDetails,\n OrganizationGroupMember,\n OrganizationGroupMembers,\n OrganizationGroupPolicyHistory,\n OrganizationGroupSummary,\n OrganizationLeaveRequestResult,\n OrganizationMembership,\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n OrganizationPolicyHistory,\n OrganizationPolicyHistoryEntry,\n OrganizationProfile,\n OrganizationSyncPauseResult,\n OrganizationUserDetail,\n} from \"../../workflows/organizations\";\nexport type {\n OrganizationContentReconciler,\n OrganizationMemberships,\n} from \"./organizationMemberships\";\nexport type {\n OrganizationGroupMutationReceipt,\n OrganizationGroupMutationResult,\n Organizations,\n} from \"./organizationsTypes\";\nexport type {\n AbandonOrganizationPolicyMutationInput,\n DiscardUnreadableOrganizationPolicyMutationInput,\n} from \"./principalMutationRecovery\";\nexport type {\n AddOrganizationGroupUserInput,\n OrganizationGrantRef,\n RemoveOrganizationGroupUserInput,\n} from \"./principalMutations\";\n\nexport function createOrganizations(\n runtime: InternalRuntime,\n containerContents: ContainerContents,\n openReconciler: () => OrganizationContentReconciler,\n): Organizations {\n return new OrganizationsService(runtime, containerContents, openReconciler);\n}\n\nclass OrganizationsService implements Organizations {\n readonly memberships: OrganizationMemberships;\n private readonly dataUsageCoordinator: OrganizationDataUsageCoordinator;\n private readonly readModelCoordinator: OrganizationReadModelCoordinator;\n\n constructor(\n private readonly runtimeService: InternalRuntime,\n private readonly containerContents: ContainerContents,\n openReconciler: () => OrganizationContentReconciler,\n ) {\n this.dataUsageCoordinator = createOrganizationDataUsageCoordinator(\n this.runtimeService,\n );\n this.readModelCoordinator = createOrganizationReadModelCoordinator(\n this.runtimeService,\n );\n this.memberships = createOrganizationMemberships(\n this.runtimeService,\n this.containerContents,\n openReconciler,\n );\n }\n\n listPendingBlobDeletions(\n organizationId: string,\n query?: PendingBlobDeletionsQuery,\n ) {\n return listPendingBlobDeletions(this.runtimeService, organizationId, query);\n }\n\n async addUserToGroup(input: AddOrganizationGroupUserInput) {\n const mutation = await admitGroupMutation(\n this.runtimeService,\n input.targetUserId,\n );\n return addUserToOrganizationGroup({\n ...input,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...mutation,\n });\n }\n\n readPendingPolicyMutation(organizationId: string) {\n return readPendingOrganizationPolicyMutation(\n this.runtimeService,\n organizationId,\n );\n }\n\n discardUnreadablePolicyMutation(\n input: DiscardUnreadableOrganizationPolicyMutationInput,\n ) {\n return discardUnreadableOrganizationPolicyMutation(\n this.runtimeService,\n input,\n );\n }\n\n retryPendingPolicyMutation(organizationId: string) {\n return retryPendingOrganizationPolicyMutation(\n this.runtimeService,\n organizationId,\n );\n }\n\n abandonPendingPolicyMutation(input: AbandonOrganizationPolicyMutationInput) {\n return abandonPendingOrganizationPolicyMutation(this.runtimeService, input);\n }\n\n createGroup(name: string) {\n return createGroupForOrganization({\n name,\n ...currentOrganizationSigningMutation(this.runtimeService),\n });\n }\n\n deleteGroup(groupId: string) {\n return deleteGroupForOrganization({\n groupId,\n ...currentOrganizationSigningMutation(this.runtimeService),\n });\n }\n\n loadBilling() {\n return runForOrganization(this.runtimeService, loadOrganizationBilling);\n }\n\n loadBillingForOrganization(organizationId: string) {\n // Gated on an authenticated session rather than on the target being the\n // active org. The server still enforces membership, so an org the caller\n // cannot reach resolves to `null`.\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBilling,\n organizationId,\n );\n }\n\n loadBillingHistory() {\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBillingHistory,\n );\n }\n\n loadBillingManagementUrl() {\n return runForOrganization(\n this.runtimeService,\n loadOrganizationBillingManagementUrl,\n );\n }\n\n loadStripeCheckoutOptions(organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n loadStripeCheckoutOptions,\n organizationId,\n );\n }\n\n createStripeCheckout(priceId: string, organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n (input) => createStripeCheckout({ ...input, priceId }),\n organizationId,\n );\n }\n\n createStripeCheckoutSession(\n priceId: string,\n returnUrl: string,\n organizationId?: string,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => createStripeCheckoutSession({ ...input, priceId, returnUrl }),\n organizationId,\n );\n }\n\n cancelStripeSubscription() {\n return runForOrganization(this.runtimeService, cancelStripeSubscription);\n }\n\n changeStripePlan(\n priceId: string,\n currentSeatCount: number,\n organizationId?: string,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => changeStripePlan({ ...input, currentSeatCount, priceId }),\n organizationId,\n );\n }\n\n claimNativeSubscription(\n organizationId: string,\n store: NativeSubscriptionStore,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => claimNativeOrganizationSubscription({ ...input, store }),\n organizationId,\n );\n }\n\n checkNativePurchaseEligibility(\n organizationId: string,\n store: NativeSubscriptionStore,\n ) {\n return runForOrganization(\n this.runtimeService,\n (input) => checkNativePurchaseEligibility({ ...input, store }),\n organizationId,\n );\n }\n\n loadDataUsage() {\n return this.dataUsageCoordinator.reconcile();\n }\n\n loadLocalDataUsage() {\n return this.dataUsageCoordinator.loadLocal();\n }\n\n loadDeviceDataUsage() {\n const active = activeOrganizationDataRuntime(this.runtimeService);\n if (!active) {\n return Promise.resolve(null);\n }\n return measureOrganizationDeviceDataUsage({\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n });\n }\n\n loadAppliedReadModelCursor() {\n return this.readModelCoordinator.loadAppliedCursor();\n }\n\n loadDirectoryAndGroups() {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.read_model.reconcile\",\n organizationId: runtime.auth.organizationId,\n },\n () => this.readModelCoordinator.reconcile(),\n );\n }\n\n loadDirectoryAndGroupsAfterMutation() {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.read_model.reconcile_after_mutation\",\n organizationId: runtime.auth.organizationId,\n },\n () => this.readModelCoordinator.reconcileAfterMutation(),\n );\n }\n\n loadLocalDirectoryAndGroups() {\n return this.readModelCoordinator.loadLocal();\n }\n\n loadGroupMembers(groupId: string) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId || groupId.length === 0) {\n return Promise.resolve(null);\n }\n\n return runtime.apiClient.listOrganizationGroupMembers(\n organizationId,\n groupId,\n );\n }\n\n loadGroupPresentationDetails(groupId: string, beforeVersion?: number) {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: groupId,\n objectKind: \"principal\",\n operation: \"group.presentation.load\",\n organizationId: runtime.auth.organizationId,\n },\n () =>\n loadOrganizationGroupPresentationDetails({\n groupId,\n beforeVersion,\n readModelCoordinator: this.readModelCoordinator,\n runtime,\n }),\n );\n }\n\n loadGrants() {\n return this.readModelCoordinator.loadLocalGrants();\n }\n\n loadGroupContainers(groupId: string) {\n return this.readModelCoordinator.loadLocalGroupContainers(groupId);\n }\n\n listLocalOrganizations() {\n const runtime = this.runtimeService.workflowInput();\n if (runtime.infra.dbStatus !== \"ready\") {\n return Promise.resolve([]);\n }\n\n return listLocalOrganizations({ execSql: runtime.infra.execSql });\n }\n\n loadPolicyHistory(beforeVersion?: number) {\n const runtime = this.runtimeService.workflowInput();\n return runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: runtime.auth.organizationId,\n objectKind: \"principal\",\n operation: \"organization.policy_history.load\",\n organizationId: runtime.auth.organizationId,\n },\n () =>\n this.readModelCoordinator.loadOrganizationPolicyHistory(\n undefined,\n beforeVersion,\n ),\n );\n }\n\n loadUserDetail(userId: string) {\n return this.readModelCoordinator.loadLocalUserDetail(userId);\n }\n\n async updateRosterEntry(userId: string, profileDocumentId: string | null) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId || userId.length === 0) {\n return null;\n }\n\n const user = await updateOrganizationRosterEntry({\n apiClient: runtime.apiClient,\n organizationId,\n profileDocumentId,\n userId,\n });\n // Callers store this response as directory state, so its leave request\n // passes the same check as one read from the read model.\n return (\n user &&\n withVerifiedDirectoryUser(\n organizationId,\n user,\n leaveRequestVerifier(this.runtimeService, runtime, {\n organizationId,\n userId: runtime.auth.userId ?? \"\",\n }),\n )\n );\n }\n\n updateProfile(profileDocumentId: string | null) {\n const runtime = this.runtimeService.workflowInput();\n const organizationId = authenticatedOrganizationId(runtime);\n if (!organizationId) {\n return Promise.resolve(null);\n }\n\n return updateOrganizationProfile({\n apiClient: runtime.apiClient,\n organizationId,\n profileDocumentId,\n });\n }\n\n async removeUserFromGroup(input: RemoveOrganizationGroupUserInput) {\n return removeUserFromOrganizationGroup({\n ...input,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...currentOrganizationSigningMutation(this.runtimeService),\n });\n }\n\n async revokeGrant(grant: OrganizationGrantRef) {\n return revokeOrganizationGrant({\n ...grant,\n containerContents: this.containerContents,\n readModelCoordinator: this.readModelCoordinator,\n ...currentOrganizationSigningMutation(this.runtimeService),\n });\n }\n\n startTrial(organizationId?: string) {\n return runForOrganization(\n this.runtimeService,\n startOrganizationTrial,\n organizationId,\n );\n }\n}\n"]}
|
|
@@ -12,7 +12,6 @@ export function currentOrganizationMutation(service, allowTokenRenewal = false)
|
|
|
12
12
|
(allowTokenRenewal
|
|
13
13
|
? current.apiClient === runtime.apiClient
|
|
14
14
|
: service.sessionGeneration === sessionGeneration) &&
|
|
15
|
-
current.identityTrustDomain === runtime.identityTrustDomain &&
|
|
16
15
|
current.infra.dbStatus === "ready" &&
|
|
17
16
|
current.infra.execSql === runtime.infra.execSql &&
|
|
18
17
|
current.state.domainScope === runtime.state.domainScope &&
|
|
@@ -23,4 +22,11 @@ export function currentOrganizationMutation(service, allowTokenRenewal = false)
|
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
24
|
}
|
|
25
|
+
/** A signed mutation's scope: the client's fixed trust domain and its lifetime. */
|
|
26
|
+
export function currentOrganizationSigningMutation(service) {
|
|
27
|
+
return {
|
|
28
|
+
identityTrustDomain: service.identityTrustDomain,
|
|
29
|
+
...currentOrganizationMutation(service),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
26
32
|
//# sourceMappingURL=principalMutationScope.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalMutationScope.js","sourceRoot":"","sources":["principalMutationScope.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,MAAM,UAAU,2BAA2B,CACzC,OAAqE,EACrE,iBAAiB,GAAG,KAAK;IAEzB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACpD,OAAO;QACL,OAAO;QACP,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YACxC,OAAO;YACL,gEAAgE;YAChE,iEAAiE;YACjE,CAAC,iBAAiB;gBAChB,CAAC,CAAC,OAAO,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS;gBACzC,CAAC,CAAC,OAAO,CAAC,iBAAiB,KAAK,iBAAiB,CAAC;gBACpD,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"principalMutationScope.js","sourceRoot":"","sources":["principalMutationScope.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,MAAM,UAAU,2BAA2B,CACzC,OAAqE,EACrE,iBAAiB,GAAG,KAAK;IAEzB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACpD,OAAO;QACL,OAAO;QACP,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YACxC,OAAO;YACL,gEAAgE;YAChE,iEAAiE;YACjE,CAAC,iBAAiB;gBAChB,CAAC,CAAC,OAAO,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS;gBACzC,CAAC,CAAC,OAAO,CAAC,iBAAiB,KAAK,iBAAiB,CAAC;gBACpD,OAAO,CAAC,KAAK,CAAC,QAAQ,KAAK,OAAO;gBAClC,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO;gBAC/C,OAAO,CAAC,KAAK,CAAC,WAAW,KAAK,OAAO,CAAC,KAAK,CAAC,WAAW;gBACvD,OAAO,CAAC,IAAI,CAAC,eAAe;gBAC5B,OAAO,CAAC,IAAI,CAAC,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,cAAc;gBAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,MAAM;gBAC3C,OAAO,CAAC,MAAM,CAAC,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,kBAAkB,CACxE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,kCAAkC,CAChD,OAGC;IAED,OAAO;QACL,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,GAAG,2BAA2B,CAAC,OAAO,CAAC;KACxC,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalRuntime } from \"../runtime/workflowRuntime\";\n\n/** Capture a mutation's identity/database lifetime without freezing live status. */\nexport function currentOrganizationMutation(\n service: Pick<InternalRuntime, \"workflowInput\" | \"sessionGeneration\">,\n allowTokenRenewal = false,\n) {\n const runtime = service.workflowInput();\n const sessionGeneration = service.sessionGeneration;\n return {\n runtime,\n stillCurrent: () => {\n const current = service.workflowInput();\n return (\n // Journal API custody survives token renewal, but its identity,\n // organization and storage generation are still bound immutably.\n (allowTokenRenewal\n ? current.apiClient === runtime.apiClient\n : service.sessionGeneration === sessionGeneration) &&\n current.infra.dbStatus === \"ready\" &&\n current.infra.execSql === runtime.infra.execSql &&\n current.state.domainScope === runtime.state.domainScope &&\n current.auth.isAuthenticated &&\n current.auth.organizationId === runtime.auth.organizationId &&\n current.auth.userId === runtime.auth.userId &&\n current.crypto.signingFingerprint === runtime.crypto.signingFingerprint\n );\n },\n };\n}\n\n/** A signed mutation's scope: the client's fixed trust domain and its lifetime. */\nexport function currentOrganizationSigningMutation(\n service: Pick<\n InternalRuntime,\n \"identityTrustDomain\" | \"workflowInput\" | \"sessionGeneration\"\n >,\n) {\n return {\n identityTrustDomain: service.identityTrustDomain,\n ...currentOrganizationMutation(service),\n };\n}\n"]}
|
|
@@ -18,11 +18,15 @@ export interface AddOrganizationGroupUserInput extends OrganizationGroupUserMuta
|
|
|
18
18
|
export interface RemoveOrganizationGroupUserInput extends OrganizationGroupUserMutationInput {
|
|
19
19
|
removedUserId: string;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
/** The client's fixed trust domain and the mutation's runtime snapshot. */
|
|
22
|
+
interface OrganizationMutationScope {
|
|
23
|
+
readonly identityTrustDomain: string | null;
|
|
24
|
+
readonly runtime: InternalWorkflowRuntimeInput;
|
|
25
|
+
}
|
|
26
|
+
interface PrincipalMutationRuntime extends OrganizationMutationScope {
|
|
22
27
|
readonly stillCurrent: () => boolean;
|
|
23
28
|
readonly containerContents: ContainerContents;
|
|
24
29
|
readonly readModelCoordinator: OrganizationReadModelCoordinator;
|
|
25
|
-
readonly runtime: InternalWorkflowRuntimeInput;
|
|
26
30
|
}
|
|
27
31
|
export declare function addUserToOrganizationGroup(input: PrincipalMutationRuntime & AddOrganizationGroupUserInput & {
|
|
28
32
|
readonly admission: GroupMemberAdmission;
|
|
@@ -61,14 +65,12 @@ export declare function addUserToOrganizationGroup(input: PrincipalMutationRunti
|
|
|
61
65
|
};
|
|
62
66
|
};
|
|
63
67
|
}>;
|
|
64
|
-
export declare function createGroupForOrganization(input: {
|
|
68
|
+
export declare function createGroupForOrganization(input: OrganizationMutationScope & {
|
|
65
69
|
readonly name: string;
|
|
66
|
-
readonly runtime: InternalWorkflowRuntimeInput;
|
|
67
70
|
readonly stillCurrent: () => boolean;
|
|
68
71
|
}): Promise<import("./index.js").OrganizationGroupSummary>;
|
|
69
|
-
export declare function deleteGroupForOrganization(input: {
|
|
72
|
+
export declare function deleteGroupForOrganization(input: OrganizationMutationScope & {
|
|
70
73
|
readonly groupId: string;
|
|
71
|
-
readonly runtime: InternalWorkflowRuntimeInput;
|
|
72
74
|
readonly stillCurrent: () => boolean;
|
|
73
75
|
}): Promise<{
|
|
74
76
|
deleted: true;
|
|
@@ -10,8 +10,8 @@ import { createRuntimeCurrentOrganizationMutation } from "../../workflows/organi
|
|
|
10
10
|
import { createRuntimePrincipalPolicyWarmer } from "../../workflows/principals/runtimePolicyWarmer.js";
|
|
11
11
|
import { createCurrentPrincipalMutation } from "./currentPrincipalMutations.js";
|
|
12
12
|
import { syncOrganizationMetadataProfile } from "./organizationMetadataProfileSync.js";
|
|
13
|
-
function requireSigningContext(runtime) {
|
|
14
|
-
if (!
|
|
13
|
+
function requireSigningContext({ identityTrustDomain, runtime, }) {
|
|
14
|
+
if (!identityTrustDomain ||
|
|
15
15
|
!runtime.auth.organizationId ||
|
|
16
16
|
!runtime.auth.userId ||
|
|
17
17
|
!runtime.crypto.signingFingerprint ||
|
|
@@ -19,7 +19,7 @@ function requireSigningContext(runtime) {
|
|
|
19
19
|
throw new Error("Organization signing context is unavailable");
|
|
20
20
|
}
|
|
21
21
|
return {
|
|
22
|
-
identityTrustDomain
|
|
22
|
+
identityTrustDomain,
|
|
23
23
|
organizationId: runtime.auth.organizationId,
|
|
24
24
|
signerUserId: runtime.auth.userId,
|
|
25
25
|
signingFingerprint: runtime.crypto.signingFingerprint,
|
|
@@ -33,7 +33,7 @@ function requireEncapsulationKeyPair(runtime) {
|
|
|
33
33
|
return runtime.crypto.encapsulationKeyPair;
|
|
34
34
|
}
|
|
35
35
|
export async function addUserToOrganizationGroup(input) {
|
|
36
|
-
const signingContext = requireSigningContext(input
|
|
36
|
+
const signingContext = requireSigningContext(input);
|
|
37
37
|
return runWithSecurityIncidentReporting(input.runtime.util.reportSecurityIncident, {
|
|
38
38
|
objectId: input.groupId,
|
|
39
39
|
objectKind: "principal",
|
|
@@ -67,7 +67,7 @@ export async function addUserToOrganizationGroup(input) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
export function createGroupForOrganization(input) {
|
|
70
|
-
const signingContext = requireSigningContext(input
|
|
70
|
+
const signingContext = requireSigningContext(input);
|
|
71
71
|
return runWithSecurityIncidentReporting(input.runtime.util.reportSecurityIncident, {
|
|
72
72
|
objectId: signingContext.organizationId,
|
|
73
73
|
objectKind: "principal",
|
|
@@ -96,7 +96,7 @@ export function createGroupForOrganization(input) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
export function deleteGroupForOrganization(input) {
|
|
99
|
-
const signingContext = requireSigningContext(input
|
|
99
|
+
const signingContext = requireSigningContext(input);
|
|
100
100
|
return runWithSecurityIncidentReporting(input.runtime.util.reportSecurityIncident, {
|
|
101
101
|
objectId: input.groupId,
|
|
102
102
|
objectKind: "principal",
|
|
@@ -116,7 +116,7 @@ export function deleteGroupForOrganization(input) {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
export async function removeUserFromOrganizationGroup(input) {
|
|
119
|
-
const signingContext = requireSigningContext(input
|
|
119
|
+
const signingContext = requireSigningContext(input);
|
|
120
120
|
return runWithSecurityIncidentReporting(input.runtime.util.reportSecurityIncident, {
|
|
121
121
|
objectId: input.groupId,
|
|
122
122
|
objectKind: "principal",
|
|
@@ -149,7 +149,7 @@ export async function removeUserFromOrganizationGroup(input) {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
export async function revokeOrganizationGrant(input) {
|
|
152
|
-
const signingContext = requireSigningContext(input
|
|
152
|
+
const signingContext = requireSigningContext(input);
|
|
153
153
|
const encapsulationKeyPair = requireEncapsulationKeyPair(input.runtime);
|
|
154
154
|
if (input.runtime.infra.dbStatus !== "ready") {
|
|
155
155
|
throw new Error("Organization local database is unavailable");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalMutations.js","sourceRoot":"","sources":["principalMutations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,mDAAmD,EAAE,MAAM,2EAA2E,CAAC;AAChJ,OAAO,EAAE,gCAAgC,EAAE,MAAM,kEAAkE,CAAC;AACpH,OAAO,EAAE,8BAA8B,EAAE,MAAM,qEAAqE,CAAC;AACrH,OAAO,EAAE,8BAA8B,EAAE,MAAM,qEAAqE,CAAC;AACrH,OAAO,EAAE,wCAAwC,EAAE,MAAM,qFAAqF,CAAC;AAC/I,OAAO,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAGpG,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAmCpF,SAAS,qBAAqB,CAC5B,OAAqC;IAErC,IACE,CAAC,OAAO,CAAC,mBAAmB;QAC5B,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,mBAAmB,EAAE,OAAO,C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E,QAAQ;oBACd,kBAAkB,EAAE,KAAK,CAAC,WAAW;iBACtC,CAAC,CACH,CAAC,QAAQ,CAAC;YACb,CAAC;YACD,OAAO,gCAAgC,CAAC;gBACtC,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,UAAU,EAAE,IAAI,wBAAwB,CAAC;oBACvC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;oBAC5B,sBAAsB,EAAE,oBAAoB,CAAC,SAAS;oBACtD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;oBACpC,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB;oBACjE,0BAA0B,EACxB,KAAK,CAAC,OAAO,CAAC,0BAA0B;iBAC3C,CAAC;gBACF,cAAc,EAAE;oBACd,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;iBAC/B;gBACD,0BAA0B,EAAE,KAAK,CAAC,OAAO,CAAC,0BAA0B;gBACpE,+BAA+B,EAAE,kCAAkC,CACjE,KAAK,CAAC,OAAO,CACd;gBACD,GAAG,cAAc;aAClB,CAAC,CAAC;QACL,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,MAAM,EAAE,CAAC;QAChC,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 { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport { ContainerMutationService } from \"../../workflows/containers\";\nimport { revokeOrganizationContainerGrant } from \"../../workflows/organizations\";\nimport { createSelectedCurrentGroupMetadataContainerVerifier } from \"../../workflows/organizations/groupMetadata/currentGroupMetadataAuthority\";\nimport { createRuntimeGroupMetadataAccess } from \"../../workflows/organizations/groupMetadata/groupMetadataRuntime\";\nimport { createCurrentOrganizationGroup } from \"../../workflows/organizations/groups/createCurrentOrganizationGroup\";\nimport { deleteCurrentOrganizationGroup } from \"../../workflows/organizations/groups/deleteCurrentOrganizationGroup\";\nimport { createRuntimeCurrentOrganizationMutation } from \"../../workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalWorkflowRuntimeInput } from \"../runtime/workflowRuntime\";\nimport { createCurrentPrincipalMutation } from \"./currentPrincipalMutations\";\nimport { syncOrganizationMetadataProfile } from \"./organizationMetadataProfileSync\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModels\";\nimport type { GroupMemberAdmission } from \"./recipientAdmission\";\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 identityTrustDomain: string;\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.identityTrustDomain ||\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 identityTrustDomain: runtime.identityTrustDomain,\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 &\n AddOrganizationGroupUserInput & {\n readonly admission: GroupMemberAdmission;\n },\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 const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n const {\n memberGroupId,\n response: bundle,\n enrolled,\n } = await mutateCurrent(input.groupId, {\n kind: \"add\",\n expectedGroupName: input.expectedGroupName,\n targetUserId: input.targetUserId,\n admission: input.admission,\n });\n if (input.groupId === memberGroupId || enrolled) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n // The verified post-commit read is the mutation's own: callers apply\n // this directory instead of reading the read model a second time.\n const directoryAndGroups =\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return { directoryAndGroups, receipt: 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 throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\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 },\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 throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\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 },\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 const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n const { memberGroupId, response: bundle } = await mutateCurrent(\n input.groupId,\n {\n kind: \"remove\",\n expectedGroupName: input.expectedGroupName,\n removedUserId: input.removedUserId,\n },\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 // The verified post-commit read is the mutation's own: callers apply\n // this directory instead of reading the read model a second time.\n const directoryAndGroups =\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return { directoryAndGroups, receipt: 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 revoke = async () => {\n if (input.subjectType === \"group\") {\n const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n return (\n await mutateCurrent(input.subjectId, {\n kind: \"revoke\",\n revokedContainerId: input.containerId,\n })\n ).response;\n }\n return revokeOrganizationContainerGrant({\n stillCurrent: input.stillCurrent,\n containerId: input.containerId,\n containers: new ContainerMutationService({\n api: input.runtime.apiClient,\n encapsulationSecretKey: encapsulationKeyPair.secretKey,\n execSql: input.runtime.infra.execSql,\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n }),\n revokedSubject: {\n subjectId: input.subjectId,\n subjectType: input.subjectType,\n },\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(\n input.runtime,\n ),\n ...signingContext,\n });\n };\n const response = await revoke();\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,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,mDAAmD,EAAE,MAAM,2EAA2E,CAAC;AAChJ,OAAO,EAAE,gCAAgC,EAAE,MAAM,kEAAkE,CAAC;AACpH,OAAO,EAAE,8BAA8B,EAAE,MAAM,qEAAqE,CAAC;AACrH,OAAO,EAAE,8BAA8B,EAAE,M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AK,CAAC,OAAO,CACd;gBACD,GAAG,cAAc;aAClB,CAAC,CAAC;QACL,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,MAAM,EAAE,CAAC;QAChC,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 { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport { ContainerMutationService } from \"../../workflows/containers\";\nimport { revokeOrganizationContainerGrant } from \"../../workflows/organizations\";\nimport { createSelectedCurrentGroupMetadataContainerVerifier } from \"../../workflows/organizations/groupMetadata/currentGroupMetadataAuthority\";\nimport { createRuntimeGroupMetadataAccess } from \"../../workflows/organizations/groupMetadata/groupMetadataRuntime\";\nimport { createCurrentOrganizationGroup } from \"../../workflows/organizations/groups/createCurrentOrganizationGroup\";\nimport { deleteCurrentOrganizationGroup } from \"../../workflows/organizations/groups/deleteCurrentOrganizationGroup\";\nimport { createRuntimeCurrentOrganizationMutation } from \"../../workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { ContainerContents } from \"../containerContents\";\nimport type { InternalWorkflowRuntimeInput } from \"../runtime/workflowRuntime\";\nimport { createCurrentPrincipalMutation } from \"./currentPrincipalMutations\";\nimport { syncOrganizationMetadataProfile } from \"./organizationMetadataProfileSync\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModels\";\nimport type { GroupMemberAdmission } from \"./recipientAdmission\";\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 identityTrustDomain: string;\n organizationId: string;\n signerUserId: string;\n signingFingerprint: string;\n signingKeyPair: NonNullable<\n InternalWorkflowRuntimeInput[\"crypto\"][\"signingKeyPair\"]\n >;\n}\n\n/** The client's fixed trust domain and the mutation's runtime snapshot. */\ninterface OrganizationMutationScope {\n readonly identityTrustDomain: string | null;\n readonly runtime: InternalWorkflowRuntimeInput;\n}\n\nfunction requireSigningContext({\n identityTrustDomain,\n runtime,\n}: OrganizationMutationScope): OrganizationSigningContext {\n if (\n !identityTrustDomain ||\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 identityTrustDomain,\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 extends OrganizationMutationScope {\n readonly stillCurrent: () => boolean;\n readonly containerContents: ContainerContents;\n readonly readModelCoordinator: OrganizationReadModelCoordinator;\n}\n\nexport async function addUserToOrganizationGroup(\n input: PrincipalMutationRuntime &\n AddOrganizationGroupUserInput & {\n readonly admission: GroupMemberAdmission;\n },\n) {\n const signingContext = requireSigningContext(input);\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 const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n const {\n memberGroupId,\n response: bundle,\n enrolled,\n } = await mutateCurrent(input.groupId, {\n kind: \"add\",\n expectedGroupName: input.expectedGroupName,\n targetUserId: input.targetUserId,\n admission: input.admission,\n });\n if (input.groupId === memberGroupId || enrolled) {\n await syncOrganizationMetadataProfile({\n containerContents: input.containerContents,\n log: input.runtime.util.log,\n organizationId: signingContext.organizationId,\n });\n }\n // The verified post-commit read is the mutation's own: callers apply\n // this directory instead of reading the read model a second time.\n const directoryAndGroups =\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return { directoryAndGroups, receipt: bundle };\n },\n );\n}\n\nexport function createGroupForOrganization(\n input: OrganizationMutationScope & {\n readonly name: string;\n readonly stillCurrent: () => boolean;\n },\n) {\n const signingContext = requireSigningContext(input);\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 throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\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 },\n );\n}\n\nexport function deleteGroupForOrganization(\n input: OrganizationMutationScope & {\n readonly groupId: string;\n readonly stillCurrent: () => boolean;\n },\n) {\n const signingContext = requireSigningContext(input);\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 throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\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 },\n );\n}\n\nexport async function removeUserFromOrganizationGroup(\n input: PrincipalMutationRuntime & RemoveOrganizationGroupUserInput,\n) {\n const signingContext = requireSigningContext(input);\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 const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n const { memberGroupId, response: bundle } = await mutateCurrent(\n input.groupId,\n {\n kind: \"remove\",\n expectedGroupName: input.expectedGroupName,\n removedUserId: input.removedUserId,\n },\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 // The verified post-commit read is the mutation's own: callers apply\n // this directory instead of reading the read model a second time.\n const directoryAndGroups =\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return { directoryAndGroups, receipt: bundle };\n },\n );\n}\n\nexport async function revokeOrganizationGrant(\n input: PrincipalMutationRuntime & OrganizationGrantRef,\n) {\n const signingContext = requireSigningContext(input);\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 revoke = async () => {\n if (input.subjectType === \"group\") {\n const mutateCurrent = createCurrentPrincipalMutation({\n ...signingContext,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!mutateCurrent)\n throw new ProjectionDependencyUnavailableError(\n \"Principal history recovery is unavailable\",\n );\n return (\n await mutateCurrent(input.subjectId, {\n kind: \"revoke\",\n revokedContainerId: input.containerId,\n })\n ).response;\n }\n return revokeOrganizationContainerGrant({\n stillCurrent: input.stillCurrent,\n containerId: input.containerId,\n containers: new ContainerMutationService({\n api: input.runtime.apiClient,\n encapsulationSecretKey: encapsulationKeyPair.secretKey,\n execSql: input.runtime.infra.execSql,\n reportSecurityIncident: input.runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n }),\n revokedSubject: {\n subjectId: input.subjectId,\n subjectType: input.subjectType,\n },\n resolveTrustedUserIdentity: input.runtime.resolveTrustedUserIdentity,\n warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(\n input.runtime,\n ),\n ...signingContext,\n });\n };\n const response = await revoke();\n await input.readModelCoordinator.reconcileAfterMutation(\n signingContext.organizationId,\n );\n return response;\n },\n );\n}\n"]}
|
|
@@ -28,8 +28,9 @@ export type GroupMemberAdmission = (members: Pick<PrincipalPolicyBundleResponse,
|
|
|
28
28
|
/** The proof is usable only at its exact Members head, within this runtime. */
|
|
29
29
|
export declare function requireGroupMemberAdmission(service: AdmissionRuntimeService, admittingExecSql: ExecSql, userId: string): Promise<GroupMemberAdmission>;
|
|
30
30
|
/** Capture the mutation scope before obtaining its head-bound admission proof. */
|
|
31
|
-
export declare function admitGroupMutation(service: AdmissionRuntimeService, userId: string): Promise<{
|
|
31
|
+
export declare function admitGroupMutation(service: AdmissionRuntimeService & Pick<InternalRuntime, "identityTrustDomain">, userId: string): Promise<{
|
|
32
32
|
admission: GroupMemberAdmission;
|
|
33
33
|
runtime: import("../runtime/workflowRuntime.js").InternalWorkflowRuntimeInput;
|
|
34
34
|
stillCurrent: () => boolean;
|
|
35
|
+
identityTrustDomain: string | null;
|
|
35
36
|
}>;
|
|
@@ -5,7 +5,7 @@ import { principalHeadMatchesReference } from "../../data/principals/organizatio
|
|
|
5
5
|
import { DatabaseUnavailableError } from "../../data/sync/databaseUnavailable.js";
|
|
6
6
|
import { UnverifiedUserIdentityError, } from "../../data/trustedUserIdentity/index.js";
|
|
7
7
|
import { isRosterVouchedRecipient, } from "../../workflows/organizations/memberships/rosterVouchedAdmission.js";
|
|
8
|
-
import { currentOrganizationMutation } from "./principalMutationScope.js";
|
|
8
|
+
import { currentOrganizationMutation, currentOrganizationSigningMutation, } from "./principalMutationScope.js";
|
|
9
9
|
import { createRosterAdmissionEvidence } from "./rosterAdmissionEvidence.js";
|
|
10
10
|
export { loadServedStateEnvelopes } from "./rosterAdmissionEvidence.js";
|
|
11
11
|
/** Thrown inside the staged scope so a refused recipient publishes nothing. */
|
|
@@ -142,7 +142,7 @@ export async function requireGroupMemberAdmission(service, admittingExecSql, use
|
|
|
142
142
|
}
|
|
143
143
|
/** Capture the mutation scope before obtaining its head-bound admission proof. */
|
|
144
144
|
export async function admitGroupMutation(service, userId) {
|
|
145
|
-
const mutation =
|
|
145
|
+
const mutation = currentOrganizationSigningMutation(service);
|
|
146
146
|
const admission = await requireGroupMemberAdmission(service, mutation.runtime.infra.execSql, userId);
|
|
147
147
|
if (!mutation.stillCurrent())
|
|
148
148
|
throw new DatabaseUnavailableError("The active database changed while admitting this user. Try again.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recipientAdmission.js","sourceRoot":"","sources":["recipientAdmission.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAGtG,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAGL,2BAA2B,GAC5B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,wBAAwB,GAGzB,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAOrE,+EAA+E;AAC/E,MAAM,mBAAoB,SAAQ,KAAK;CAAG;AAE1C,KAAK,UAAU,SAAS,CACtB,SAAuE;IAEvE,OAAO;QACL,2BAA2B,EAAE,SAAS,CAAC,2BAA2B;QAClE,yBAAyB,EACvB,MAAM,oCAAoC,CAAC,SAAS,CAAC;QACvD,qBAAqB,EAAE,SAAS,CAAC,qBAAqB;QACtD,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,8BAA8B,CAC3C,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;IACF,aAAa,EAAE,CAAC;IAChB,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,aAAa,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC;YAC1E,sEAAsE;YACtE,0EAA0E;YAC1E,MAAM,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACxE,CAAC;aAAM,IACL,SAAS,CAAC,MAAM,KAAK,QAAQ;YAC7B,CAAC,6BAA6B,CAAC,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,EACpE,CAAC;YACD,MAAM,IAAI,oCAAoC,CAC5C,uDAAuD,CACxD,CAAC;QACJ,CAAC;QACD,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAgC,EAChC,MAAc;IAEd,MAAM,QAAQ,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,MAAM,2BAA2B,CACjD,OAAO,EACP,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAC9B,MAAM,CACP,CAAC;IACF,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;QAC1B,MAAM,IAAI,wBAAwB,CAChC,mEAAmE,CACpE,CAAC;IACJ,OAAO,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import type {\n ContainerAccessLevel,\n ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { computeUserIdentityBundleFingerprint } from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { DatabaseUnavailableError } from \"../../data/sync/databaseUnavailable\";\nimport {\n type StagedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n UnverifiedUserIdentityError,\n} from \"../../data/trustedUserIdentity\";\nimport {\n isRosterVouchedRecipient,\n type RosterAdmissionEvidence,\n type RosterAdmissionPin,\n} from \"../../workflows/organizations/memberships/rosterVouchedAdmission\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { currentOrganizationMutation } from \"./principalMutationScope\";\nimport { createRosterAdmissionEvidence } from \"./rosterAdmissionEvidence\";\n\nexport { loadServedStateEnvelopes } from \"./rosterAdmissionEvidence\";\n\ntype AdmissionRuntimeService = Pick<\n InternalRuntime,\n \"identityLinks\" | \"sessionGeneration\" | \"workflowInput\"\n>;\n\n/** Thrown inside the staged scope so a refused recipient publishes nothing. */\nclass RecipientNotVouched extends Error {}\n\nasync function stagedPin(\n candidate: NonNullable<Awaited<ReturnType<StagedUserIdentityResolver>>>,\n): Promise<RosterAdmissionPin> {\n return {\n encapsulationKeyFingerprint: candidate.encapsulationKeyFingerprint,\n identityBundleFingerprint:\n await computeUserIdentityBundleFingerprint(candidate),\n signingKeyFingerprint: candidate.signingKeyFingerprint,\n verified: false,\n };\n}\n\n/**\n * Admit against the server's first answers without pinning them: the\n * recipient's answer, and that of any historical signer the chain needs but\n * this device has not pinned (a departed admin seen only in older Members\n * states), are staged. Each is checked against its committed Members bundle,\n * and all are pinned as observed only once the signed roster vouches for the\n * recipient's exact identity bundle. A substituted answer leaves no pin, so a\n * corrected retry or the honest identity link still succeeds.\n */\nasync function isStagedRosterVouchedRecipient(\n userId: string,\n evidence: RosterAdmissionEvidence,\n resolver: TrustedUserIdentityResolver,\n assertCurrent: (() => void) | undefined,\n): Promise<boolean> {\n // Without staging, admit only a durable pin: never pin before the roster.\n if (!resolver.withPinnedIdentities)\n return isRosterVouchedRecipient(userId, evidence);\n try {\n return await resolver.withPinnedIdentities(\n [userId],\n async (resolve) => {\n const candidate = await resolve(userId);\n const vouched =\n candidate !== null &&\n (await isRosterVouchedRecipient(userId, {\n ...evidence,\n loadPin: async (id) => {\n const pin = await evidence.loadPin(id);\n if (pin) return pin;\n const staged = id === userId ? candidate : await resolve(id);\n return staged ? stagedPin(staged) : null;\n },\n }));\n if (!vouched) throw new RecipientNotVouched();\n return true;\n },\n { publish: true, assertCurrent },\n );\n } catch (error) {\n if (error instanceof RecipientNotVouched) return false;\n throw error;\n }\n}\n\n/**\n * Whether the signed roster vouches for `userId` on this device, for exactly\n * the domain-scoped signing and encapsulation identity bundle the server\n * serves. Served material that fails verification is recorded as a security\n * incident before the error propagates.\n */\nexport function isReportedRosterVouchedRecipient(input: {\n readonly evidence: RosterAdmissionEvidence;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly userId: string;\n /** The admission's lifetime, checked inside every pin write. */\n readonly assertCurrent?: (() => void) | undefined;\n}): Promise<boolean> {\n const { evidence, userId } = input;\n return runWithSecurityIncidentReporting(\n input.reportSecurityIncident,\n {\n objectId: userId,\n objectKind: \"user\",\n operation: \"container.share.roster_vouch\",\n organizationId: input.organizationId,\n },\n () =>\n isStagedRosterVouchedRecipient(\n userId,\n evidence,\n input.resolveTrustedUserIdentity,\n input.assertCurrent,\n ),\n );\n}\n\ntype RecipientAdmission =\n | { readonly status: \"verified\" }\n | { readonly status: \"roster\"; readonly head: ReferencedPrincipalHead };\n\nasync function requireOrganizationRecipient(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n): Promise<RecipientAdmission> {\n try {\n await service.identityLinks.requireVerified(userId, admittingExecSql);\n return { status: \"verified\" };\n } catch (error) {\n const runtime = service.workflowInput();\n const organizationId = runtime.auth.organizationId;\n if (!(error instanceof UnverifiedUserIdentityError) || !organizationId)\n throw error;\n const evidence = createRosterAdmissionEvidence(\n service,\n admittingExecSql,\n organizationId,\n );\n if (!evidence) throw error;\n let head: ReferencedPrincipalHead | undefined;\n const vouched = await isReportedRosterVouchedRecipient({\n assertCurrent: admissionLifetime(service, admittingExecSql),\n evidence: {\n ...evidence,\n async loadCurrentMembers() {\n const members = await evidence.loadCurrentMembers();\n head = members.head;\n return members;\n },\n },\n organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n userId,\n });\n if (!vouched || !head) throw error;\n return { status: \"roster\", head };\n }\n}\n\nfunction admissionLifetime(service: AdmissionRuntimeService, execSql: ExecSql) {\n const scope = currentOrganizationMutation(service);\n return () => {\n if (scope.runtime.infra.execSql !== execSql || !scope.stillCurrent())\n throw new DatabaseUnavailableError(\n \"The active identity or database changed while admitting this user. Try again.\",\n );\n };\n}\n\n/** Full-bundle roster authentication admits read, write, and admin shares. */\nexport async function requireShareRecipient(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n _accessLevel: ContainerAccessLevel,\n): Promise<void> {\n const assertCurrent = admissionLifetime(service, admittingExecSql);\n assertCurrent();\n await requireOrganizationRecipient(service, admittingExecSql, userId);\n assertCurrent();\n}\n\nexport type GroupMemberAdmission = (\n members: Pick<\n PrincipalPolicyBundleResponse,\n \"currentState\" | \"currentProjection\"\n >,\n) => Promise<void>;\n\n/** The proof is usable only at its exact Members head, within this runtime. */\nexport async function requireGroupMemberAdmission(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n): Promise<GroupMemberAdmission> {\n const assertCurrent = admissionLifetime(service, admittingExecSql);\n assertCurrent();\n const admission = await requireOrganizationRecipient(\n service,\n admittingExecSql,\n userId,\n );\n assertCurrent();\n return async (members) => {\n assertCurrent();\n if (!members.currentProjection.some((member) => member.userId === userId)) {\n // A retry may find the user removed since the proof. Enrollment still\n // requires this device's self/link anchor, never an earlier roster proof.\n await service.identityLinks.requireVerified(userId, admittingExecSql);\n } else if (\n admission.status === \"roster\" &&\n !principalHeadMatchesReference(members.currentState, admission.head)\n ) {\n throw new ProjectionDependencyUnavailableError(\n \"Members changed while admitting this user. Try again.\",\n );\n }\n assertCurrent();\n };\n}\n\n/** Capture the mutation scope before obtaining its head-bound admission proof. */\nexport async function admitGroupMutation(\n service: AdmissionRuntimeService,\n userId: string,\n) {\n const mutation = currentOrganizationMutation(service);\n const admission = await requireGroupMemberAdmission(\n service,\n mutation.runtime.infra.execSql,\n userId,\n );\n if (!mutation.stillCurrent())\n throw new DatabaseUnavailableError(\n \"The active database changed while admitting this user. Try again.\",\n );\n return { ...mutation, admission };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recipientAdmission.js","sourceRoot":"","sources":["recipientAdmission.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAGtG,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAGL,2BAA2B,GAC5B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,wBAAwB,GAGzB,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAOrE,+EAA+E;AAC/E,MAAM,mBAAoB,SAAQ,KAAK;CAAG;AAE1C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;IACJ,OAAO,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import type {\n ContainerAccessLevel,\n ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { computeUserIdentityBundleFingerprint } from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { DatabaseUnavailableError } from \"../../data/sync/databaseUnavailable\";\nimport {\n type StagedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n UnverifiedUserIdentityError,\n} from \"../../data/trustedUserIdentity\";\nimport {\n isRosterVouchedRecipient,\n type RosterAdmissionEvidence,\n type RosterAdmissionPin,\n} from \"../../workflows/organizations/memberships/rosterVouchedAdmission\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport {\n currentOrganizationMutation,\n currentOrganizationSigningMutation,\n} from \"./principalMutationScope\";\nimport { createRosterAdmissionEvidence } from \"./rosterAdmissionEvidence\";\n\nexport { loadServedStateEnvelopes } from \"./rosterAdmissionEvidence\";\n\ntype AdmissionRuntimeService = Pick<\n InternalRuntime,\n \"identityLinks\" | \"sessionGeneration\" | \"workflowInput\"\n>;\n\n/** Thrown inside the staged scope so a refused recipient publishes nothing. */\nclass RecipientNotVouched extends Error {}\n\nasync function stagedPin(\n candidate: NonNullable<Awaited<ReturnType<StagedUserIdentityResolver>>>,\n): Promise<RosterAdmissionPin> {\n return {\n encapsulationKeyFingerprint: candidate.encapsulationKeyFingerprint,\n identityBundleFingerprint:\n await computeUserIdentityBundleFingerprint(candidate),\n signingKeyFingerprint: candidate.signingKeyFingerprint,\n verified: false,\n };\n}\n\n/**\n * Admit against the server's first answers without pinning them: the\n * recipient's answer, and that of any historical signer the chain needs but\n * this device has not pinned (a departed admin seen only in older Members\n * states), are staged. Each is checked against its committed Members bundle,\n * and all are pinned as observed only once the signed roster vouches for the\n * recipient's exact identity bundle. A substituted answer leaves no pin, so a\n * corrected retry or the honest identity link still succeeds.\n */\nasync function isStagedRosterVouchedRecipient(\n userId: string,\n evidence: RosterAdmissionEvidence,\n resolver: TrustedUserIdentityResolver,\n assertCurrent: (() => void) | undefined,\n): Promise<boolean> {\n // Without staging, admit only a durable pin: never pin before the roster.\n if (!resolver.withPinnedIdentities)\n return isRosterVouchedRecipient(userId, evidence);\n try {\n return await resolver.withPinnedIdentities(\n [userId],\n async (resolve) => {\n const candidate = await resolve(userId);\n const vouched =\n candidate !== null &&\n (await isRosterVouchedRecipient(userId, {\n ...evidence,\n loadPin: async (id) => {\n const pin = await evidence.loadPin(id);\n if (pin) return pin;\n const staged = id === userId ? candidate : await resolve(id);\n return staged ? stagedPin(staged) : null;\n },\n }));\n if (!vouched) throw new RecipientNotVouched();\n return true;\n },\n { publish: true, assertCurrent },\n );\n } catch (error) {\n if (error instanceof RecipientNotVouched) return false;\n throw error;\n }\n}\n\n/**\n * Whether the signed roster vouches for `userId` on this device, for exactly\n * the domain-scoped signing and encapsulation identity bundle the server\n * serves. Served material that fails verification is recorded as a security\n * incident before the error propagates.\n */\nexport function isReportedRosterVouchedRecipient(input: {\n readonly evidence: RosterAdmissionEvidence;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly userId: string;\n /** The admission's lifetime, checked inside every pin write. */\n readonly assertCurrent?: (() => void) | undefined;\n}): Promise<boolean> {\n const { evidence, userId } = input;\n return runWithSecurityIncidentReporting(\n input.reportSecurityIncident,\n {\n objectId: userId,\n objectKind: \"user\",\n operation: \"container.share.roster_vouch\",\n organizationId: input.organizationId,\n },\n () =>\n isStagedRosterVouchedRecipient(\n userId,\n evidence,\n input.resolveTrustedUserIdentity,\n input.assertCurrent,\n ),\n );\n}\n\ntype RecipientAdmission =\n | { readonly status: \"verified\" }\n | { readonly status: \"roster\"; readonly head: ReferencedPrincipalHead };\n\nasync function requireOrganizationRecipient(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n): Promise<RecipientAdmission> {\n try {\n await service.identityLinks.requireVerified(userId, admittingExecSql);\n return { status: \"verified\" };\n } catch (error) {\n const runtime = service.workflowInput();\n const organizationId = runtime.auth.organizationId;\n if (!(error instanceof UnverifiedUserIdentityError) || !organizationId)\n throw error;\n const evidence = createRosterAdmissionEvidence(\n service,\n admittingExecSql,\n organizationId,\n );\n if (!evidence) throw error;\n let head: ReferencedPrincipalHead | undefined;\n const vouched = await isReportedRosterVouchedRecipient({\n assertCurrent: admissionLifetime(service, admittingExecSql),\n evidence: {\n ...evidence,\n async loadCurrentMembers() {\n const members = await evidence.loadCurrentMembers();\n head = members.head;\n return members;\n },\n },\n organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n userId,\n });\n if (!vouched || !head) throw error;\n return { status: \"roster\", head };\n }\n}\n\nfunction admissionLifetime(service: AdmissionRuntimeService, execSql: ExecSql) {\n const scope = currentOrganizationMutation(service);\n return () => {\n if (scope.runtime.infra.execSql !== execSql || !scope.stillCurrent())\n throw new DatabaseUnavailableError(\n \"The active identity or database changed while admitting this user. Try again.\",\n );\n };\n}\n\n/** Full-bundle roster authentication admits read, write, and admin shares. */\nexport async function requireShareRecipient(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n _accessLevel: ContainerAccessLevel,\n): Promise<void> {\n const assertCurrent = admissionLifetime(service, admittingExecSql);\n assertCurrent();\n await requireOrganizationRecipient(service, admittingExecSql, userId);\n assertCurrent();\n}\n\nexport type GroupMemberAdmission = (\n members: Pick<\n PrincipalPolicyBundleResponse,\n \"currentState\" | \"currentProjection\"\n >,\n) => Promise<void>;\n\n/** The proof is usable only at its exact Members head, within this runtime. */\nexport async function requireGroupMemberAdmission(\n service: AdmissionRuntimeService,\n admittingExecSql: ExecSql,\n userId: string,\n): Promise<GroupMemberAdmission> {\n const assertCurrent = admissionLifetime(service, admittingExecSql);\n assertCurrent();\n const admission = await requireOrganizationRecipient(\n service,\n admittingExecSql,\n userId,\n );\n assertCurrent();\n return async (members) => {\n assertCurrent();\n if (!members.currentProjection.some((member) => member.userId === userId)) {\n // A retry may find the user removed since the proof. Enrollment still\n // requires this device's self/link anchor, never an earlier roster proof.\n await service.identityLinks.requireVerified(userId, admittingExecSql);\n } else if (\n admission.status === \"roster\" &&\n !principalHeadMatchesReference(members.currentState, admission.head)\n ) {\n throw new ProjectionDependencyUnavailableError(\n \"Members changed while admitting this user. Try again.\",\n );\n }\n assertCurrent();\n };\n}\n\n/** Capture the mutation scope before obtaining its head-bound admission proof. */\nexport async function admitGroupMutation(\n service: AdmissionRuntimeService &\n Pick<InternalRuntime, \"identityTrustDomain\">,\n userId: string,\n) {\n const mutation = currentOrganizationSigningMutation(service);\n const admission = await requireGroupMemberAdmission(\n service,\n mutation.runtime.infra.execSql,\n userId,\n );\n if (!mutation.stillCurrent())\n throw new DatabaseUnavailableError(\n \"The active database changed while admitting this user. Try again.\",\n );\n return { ...mutation, admission };\n}\n"]}
|
|
@@ -27,12 +27,13 @@ export interface Runtime {
|
|
|
27
27
|
subscribe(listener: RuntimeListener): () => void;
|
|
28
28
|
}
|
|
29
29
|
export interface InternalWorkflowRuntimeInput extends WorkflowRuntimeGroups {
|
|
30
|
-
readonly identityTrustDomain: string | null;
|
|
31
30
|
readonly apiClient: PrincipalMutationApi;
|
|
32
31
|
readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
|
|
33
32
|
readonly withPrincipalHistoryProtection?: PrincipalHistoryProtectionLease | undefined;
|
|
34
33
|
}
|
|
35
34
|
export interface InternalRuntime {
|
|
35
|
+
/** Resolved once by the composition root; constant for the client's life. */
|
|
36
|
+
readonly identityTrustDomain: string | null;
|
|
36
37
|
identityLinks: Pick<TrustedUserIdentityService, "createLink" | "createLinkFor" | "verifyLink" | "loadAdmissionPin" | "resolvePinned" | "resolveVerified" | "requireVerified">;
|
|
37
38
|
retirePrincipalHistoryProtection(): void;
|
|
38
39
|
readonly sessionGeneration: number;
|
|
@@ -77,6 +77,7 @@ export function createRuntime(dependencies) {
|
|
|
77
77
|
});
|
|
78
78
|
const runtimeInput = createRuntimeInputFactory(dependencies, resolveTrustedUserIdentity, historyProtection.bind, createRuntimeMutationApi(dependencies, () => runtimeSubscription.mutationGeneration).bind);
|
|
79
79
|
return {
|
|
80
|
+
identityTrustDomain: dependencies.identityTrustDomain,
|
|
80
81
|
identityLinks: trustedUserIdentityService,
|
|
81
82
|
retirePrincipalHistoryProtection: historyProtection.retire,
|
|
82
83
|
get sessionGeneration() {
|
|
@@ -233,7 +234,6 @@ function createRuntimeInputFactory(dependencies, resolveTrustedUserIdentity, bin
|
|
|
233
234
|
});
|
|
234
235
|
util = runtimeInputUtilities(dependencies, util);
|
|
235
236
|
return {
|
|
236
|
-
identityTrustDomain: dependencies.identityTrustDomain,
|
|
237
237
|
apiClient: bindMutationApi(),
|
|
238
238
|
auth,
|
|
239
239
|
crypto,
|