@tearleads/client-sdk 0.1.247 → 0.1.249
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/Tearleads.js +4 -2
- package/Tearleads.js.map +1 -1
- package/client/organizations/index.js +5 -3
- package/client/organizations/index.js.map +1 -1
- package/client/organizations/organizationGroupPresentation.d.ts +1 -1
- package/client/organizations/organizationGroupPresentation.js.map +1 -1
- package/client/organizations/organizationLeaveRequestVerifier.js +21 -0
- package/client/organizations/organizationLeaveRequestVerifier.js.map +1 -0
- package/client/organizations/{organizationReadModels.d.ts → organizationReadModelCoordinator.d.ts} +18 -16
- package/client/organizations/organizationReadModelCoordinator.js +2 -0
- package/client/organizations/organizationReadModelCoordinator.js.map +1 -0
- package/client/organizations/organizationReadModelPresentation.js +51 -0
- package/client/organizations/organizationReadModelPresentation.js.map +1 -0
- package/client/organizations/organizationReadModelScopes.js +37 -0
- package/client/organizations/organizationReadModelScopes.js.map +1 -0
- package/client/organizations/organizationReadModels.js +131 -88
- package/client/organizations/organizationReadModels.js.map +1 -1
- package/client/organizations/organizationsTypes.d.ts +13 -5
- package/client/organizations/organizationsTypes.js.map +1 -1
- package/client/organizations/principalMutations.d.ts +18 -2
- package/client/organizations/principalMutations.js +29 -15
- package/client/organizations/principalMutations.js.map +1 -1
- package/client/runtime/principalMutationApi.d.ts +2 -0
- package/client/runtime/principalMutationApi.js +2 -0
- package/client/runtime/principalMutationApi.js.map +1 -1
- package/client/runtime/principalMutationDispatch.js +47 -10
- package/client/runtime/principalMutationDispatch.js.map +1 -1
- package/client/runtime/workflowRuntime.js +5 -4
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/containers/shared/mutationRequestOptions.d.ts +2 -0
- package/data/containers/shared/mutationRequestOptions.js.map +1 -1
- package/data/containers/shared/types.d.ts +12 -2
- package/data/containers/shared/types.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelRepository.js +20 -2
- package/data/persistence/organizations/organizationReadModelRepository.js.map +1 -1
- package/data/persistence/principalPolicy/heldOrganizationDirectories.js +53 -0
- package/data/persistence/principalPolicy/heldOrganizationDirectories.js.map +1 -0
- package/data/persistence/verifiedManifestBundlePersistence.d.ts +8 -3
- package/data/persistence/verifiedManifestBundlePersistence.js +34 -15
- package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +4 -1
- package/internal/api-client/client/containerMutations.d.ts +2 -2
- package/internal/api-client/client/containerMutations.js +2 -1
- package/internal/api-client/client/containerMutations.js.map +1 -1
- package/internal/api-client/client/principalPolicies.d.ts +3 -0
- package/internal/api-client/heldDirectoryCitations.d.ts +19 -0
- package/internal/api-client/heldDirectoryCitations.js +37 -0
- package/internal/api-client/heldDirectoryCitations.js.map +1 -0
- package/internal/api-client/index.d.ts +1 -1
- package/internal/api-client/index.js.map +1 -1
- package/internal/api-client/principalPolicyRequests.d.ts +2 -0
- package/internal/api-client/principalPolicyRequests.js +6 -4
- package/internal/api-client/principalPolicyRequests.js.map +1 -1
- package/internal/api-client/routes/containers/mutations.js +3 -3
- package/internal/api-client/routes/containers/mutations.js.map +1 -1
- package/internal/api-client/routes/organizations/createGroup.js +3 -5
- package/internal/api-client/routes/organizations/createGroup.js.map +1 -1
- package/internal/api-client/routes/principals/policy.js +2 -5
- package/internal/api-client/routes/principals/policy.js.map +1 -1
- package/internal/api-client/types.d.ts +6 -0
- package/internal/api-client/types.js.map +1 -1
- package/internal/api-client/verifiedManifestCitations.d.ts +16 -6
- package/internal/api-client/verifiedManifestCitations.js +32 -13
- package/internal/api-client/verifiedManifestCitations.js.map +1 -1
- package/internal/api-client/writerProjectionRequests.js +5 -3
- package/internal/api-client/writerProjectionRequests.js.map +1 -1
- package/internal/validators/knownManifestsRefinements.js +1 -1
- package/internal/validators/knownManifestsRefinements.js.map +1 -1
- package/internal/validators/operation/containerMutations.d.ts +20 -3
- package/internal/validators/operation/containerMutations.js +18 -20
- package/internal/validators/operation/containerMutations.js.map +1 -1
- package/internal/validators/operation/index.d.ts +1 -1
- package/internal/validators/operation/index.js +1 -1
- package/internal/validators/operation/index.js.map +1 -1
- package/internal/validators/operation/organizations.d.ts +17 -1
- package/internal/validators/operation/organizations.js +4 -2
- package/internal/validators/operation/organizations.js.map +1 -1
- package/internal/validators/operation/principals.d.ts +17 -1
- package/internal/validators/operation/principals.js +5 -2
- package/internal/validators/operation/principals.js.map +1 -1
- package/internal/validators/operation/writerProjections.d.ts +11 -11
- package/internal/validators/operation/writerProjections.js +1 -1
- package/internal/validators/operation/writerProjections.js.map +1 -1
- package/internal/validators/request/index.d.ts +1 -1
- package/internal/validators/request/index.js +1 -1
- package/internal/validators/request/index.js.map +1 -1
- package/internal/validators/request/organization.d.ts +15 -0
- package/internal/validators/request/organization.js +8 -0
- package/internal/validators/request/organization.js.map +1 -1
- package/internal/validators/response/areas/organizations.d.ts +3 -2
- package/internal/validators/response/areas/organizations.js +3 -2
- package/internal/validators/response/areas/organizations.js.map +1 -1
- package/internal/validators/response/areas/principals.d.ts +3 -2
- package/internal/validators/response/areas/principals.js +2 -2
- package/internal/validators/response/areas/principals.js.map +1 -1
- package/internal/validators/response/committedReadModel.d.ts +697 -0
- package/internal/validators/response/committedReadModel.js +52 -0
- package/internal/validators/response/committedReadModel.js.map +1 -0
- package/internal/validators/response/container.d.ts +56 -4
- package/internal/validators/response/container.js +5 -5
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/documentMutation.d.ts +4 -4
- package/internal/validators/response/documentMutation.js +2 -2
- package/internal/validators/response/documentMutation.js.map +1 -1
- package/internal/validators/response/organization.d.ts +0 -191
- package/internal/validators/response/organization.js +0 -7
- package/internal/validators/response/organization.js.map +1 -1
- package/internal/validators/response/organizationReadModel.d.ts +167 -0
- package/internal/validators/response/organizationReadModel.js +5 -0
- package/internal/validators/response/organizationReadModel.js.map +1 -1
- package/internal/validators/response/policyEvidenceWire.d.ts +17 -0
- package/internal/validators/response/policyEvidenceWire.js +36 -0
- package/internal/validators/response/policyEvidenceWire.js.map +1 -0
- package/internal/validators/response/principal.d.ts +0 -403
- package/internal/validators/response/principal.js +0 -8
- package/internal/validators/response/principal.js.map +1 -1
- package/internal/validators/response/projectionPolicyEvidence.d.ts +175 -0
- package/internal/validators/response/projectionPolicyEvidence.js +13 -0
- package/internal/validators/response/projectionPolicyEvidence.js.map +1 -1
- package/internal/validators/response/writerProjectionWire.d.ts +11 -7
- package/internal/validators/response/writerProjectionWire.js +19 -10
- package/internal/validators/response/writerProjectionWire.js.map +1 -1
- package/internal/validators/util/index.d.ts +1 -1
- package/internal/validators/util/index.js +1 -1
- package/internal/validators/util/index.js.map +1 -1
- package/internal/validators/util/knownManifestWire.d.ts +9 -3
- package/internal/validators/util/knownManifestWire.js +24 -8
- package/internal/validators/util/knownManifestWire.js.map +1 -1
- package/package.json +1 -1
- package/workflows/container-contents/container-state/organizationHost.d.ts +9 -0
- package/workflows/container-contents/container-state/organizationHost.js.map +1 -1
- package/workflows/container-contents/container-state/remote.js +6 -0
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/containers/child/share/index.d.ts +4 -2
- package/workflows/containers/child/share/index.js +37 -20
- package/workflows/containers/child/share/index.js.map +1 -1
- package/workflows/organizations/containerContentsHost.js +20 -1
- package/workflows/organizations/containerContentsHost.js.map +1 -1
- package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js +5 -1
- package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js.map +1 -1
- package/workflows/organizations/groups/createCurrentOrganizationGroup.js +8 -1
- package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
- package/workflows/organizations/index.d.ts +1 -0
- package/workflows/organizations/index.js +1 -0
- package/workflows/organizations/index.js.map +1 -1
- package/workflows/organizations/readModel/committedReadModel.d.ts +66 -0
- package/workflows/organizations/readModel/committedReadModel.js +150 -0
- package/workflows/organizations/readModel/committedReadModel.js.map +1 -0
- package/workflows/organizations/readModel/readModelProjection.d.ts +15 -2
- package/workflows/organizations/readModel/readModelProjection.js +26 -4
- package/workflows/organizations/readModel/readModelProjection.js.map +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type ContainerAccessLevel } from "../../../../internal/crypto/index.js";
|
|
2
|
-
import type
|
|
3
|
-
import type { ContainerMutationAuthor, ContainerShareApi, ContainerSharePlan } from "../../../../data/containers/shared/types.js";
|
|
2
|
+
import { type ContainerMutationResponse, type ContainerWriterProjectionResponse } from "../../../../internal/validators/response/index.js";
|
|
3
|
+
import type { ContainerMutationAuthor, ContainerShareApi, ContainerShareCommittedReadModel, ContainerSharePlan } from "../../../../data/containers/shared/types.js";
|
|
4
4
|
import { type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../../data/keyingProjectionVerification/index.js";
|
|
5
5
|
import { type ContainerMutationCollaborators } from "../../containerMutationCollaborators.js";
|
|
6
6
|
export interface ShareRemoteContainerRequest {
|
|
7
7
|
accessLevel: ContainerAccessLevel;
|
|
8
8
|
author: ContainerMutationAuthor;
|
|
9
|
+
/** Sends the read-model cursor the sharer holds; none without it. */
|
|
10
|
+
committedReadModel?: ContainerShareCommittedReadModel | undefined;
|
|
9
11
|
containerId: string;
|
|
10
12
|
eventId?: string | undefined;
|
|
11
13
|
previousProjection?: ContainerWriterProjectionResponse | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KeyingVerificationError, } from "../../../../internal/crypto/index.js";
|
|
2
|
+
import { committedReadModelDelta, } from "../../../../internal/validators/response/index.js";
|
|
2
3
|
import { isStaleParentContainerPathFailure } from "../../../../data/containers/shared/mutationFailures.js";
|
|
3
4
|
import { nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../../data/keyingProjectionVerification/index.js";
|
|
4
5
|
import { ProjectionDependencyUnavailableError } from "../../../../data/shared/dependencyUnavailable.js";
|
|
@@ -17,7 +18,7 @@ const STALE_PATH = Symbol("stale-path");
|
|
|
17
18
|
* refusal that ends the share is reported once submission settles, as the
|
|
18
19
|
* plain endpoint's would be; a stale path the share plans again is not.
|
|
19
20
|
*/
|
|
20
|
-
async function submitShare(input, request, retriesStalePath) {
|
|
21
|
+
async function submitShare(input, request, retriesStalePath, readModelCursor) {
|
|
21
22
|
const options = {
|
|
22
23
|
expectedPaymentRequiredOrganizationId: input.author.organizationId,
|
|
23
24
|
};
|
|
@@ -25,7 +26,11 @@ async function submitShare(input, request, retriesStalePath) {
|
|
|
25
26
|
if (!shareContainerResult) {
|
|
26
27
|
return submitPlainContainerMutation(() => input.apiClient.shareContainer(input.containerId, request, options));
|
|
27
28
|
}
|
|
28
|
-
const result = await shareContainerResult.call(input.apiClient, input.containerId, request, {
|
|
29
|
+
const result = await shareContainerResult.call(input.apiClient, input.containerId, request, {
|
|
30
|
+
...options,
|
|
31
|
+
...(readModelCursor ? { readModelCursor } : {}),
|
|
32
|
+
reportErrors: false,
|
|
33
|
+
});
|
|
29
34
|
if (result.ok)
|
|
30
35
|
return { ok: true, data: result.data };
|
|
31
36
|
return retriesStalePath && isStaleParentContainerPathFailure(result)
|
|
@@ -74,24 +79,36 @@ async function shareRemoteContainerOnce(input, recipientEncapsulationPublicKey,
|
|
|
74
79
|
if (!materializedPlan)
|
|
75
80
|
return null;
|
|
76
81
|
let stalePath = false;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
// The acknowledged submit rechecks currency after this lookup, and the
|
|
83
|
+
// delta is offered only once the share's acknowledgement verified.
|
|
84
|
+
const lease = await input.committedReadModel?.begin();
|
|
85
|
+
let delta;
|
|
86
|
+
let shared = null;
|
|
87
|
+
try {
|
|
88
|
+
shared = await submitAcknowledgedContainerMutation({
|
|
89
|
+
reportSecurityIncident: input.reportSecurityIncident,
|
|
90
|
+
recitationPolicies: [],
|
|
91
|
+
apiClient: input.apiClient,
|
|
92
|
+
author: input.author,
|
|
93
|
+
containerKey: materializedPlan.containerKey,
|
|
94
|
+
execSql: input.execSql,
|
|
95
|
+
plan: materializedPlan.plan,
|
|
96
|
+
stillCurrent: input.stillCurrent,
|
|
97
|
+
submit: async () => {
|
|
98
|
+
const result = await submitShare(input, materializedPlan.plan.request, retriesStalePath, lease?.heldCursor);
|
|
99
|
+
if (result.ok)
|
|
100
|
+
delta = committedReadModelDelta(result.data.readModel, input.author.organizationId);
|
|
101
|
+
stalePath =
|
|
102
|
+
!result.ok &&
|
|
103
|
+
retriesStalePath &&
|
|
104
|
+
isStaleParentContainerPathFailure(result);
|
|
105
|
+
return result;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
lease?.settle(shared ? delta : undefined);
|
|
111
|
+
}
|
|
95
112
|
return shared ?? (stalePath ? STALE_PATH : null);
|
|
96
113
|
}
|
|
97
114
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AAQxG,OAAO,EACL,wCAAwC,EAGxC,gCAAgC,GACjC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,oCAAoC,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EACL,kCAAkC,GAEnC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAGL,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,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Y,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,wBAAwB,CAC1C,KAAK,EACL,iBAAiB,CAAC,sBAAsB,EACxC,wBAAwB,EACxB,IAAI,CACL,CAAC;IACF,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,KAAK,CAAC,SAAS,CAAC,8BAA8B,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAC3C,EAAE,GAAG,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,EAC3C,iBAAiB,CAAC,sBAAsB,EACxC,wBAAwB,EACxB,KAAK,CACN,CAAC;IACF,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC/C,CAAC","sourcesContent":["import {\n type ContainerAccessLevel,\n KeyingVerificationError,\n} from \"@tearleads/crypto\";\nimport type { ContainerMutationRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerMutationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { isStaleParentContainerPathFailure } from \"../../../../data/containers/shared/mutationFailures\";\nimport type {\n ContainerMutationAuthor,\n ContainerRotationResult,\n ContainerShareApi,\n ContainerSharePlan,\n MaterializedContainerSharePlan,\n} from \"../../../../data/containers/shared/types\";\nimport {\n nullOnProjectionVerificationCancellation,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../../data/keyingProjectionVerification\";\nimport { ProjectionDependencyUnavailableError } from \"../../../../data/shared/dependencyUnavailable\";\nimport {\n requireTrustedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n} from \"../../../../data/trustedUserIdentity\";\nimport {\n type ContainerMutationCollaborators,\n type ContainerRotationBag,\n containerRotationBag,\n} from \"../../containerMutationCollaborators\";\nimport {\n submitAcknowledgedContainerMutation,\n submitPlainContainerMutation,\n} from \"../mutationSubmit\";\nimport { buildMaterializedContainerSharePlan } from \"./shareMaterialization\";\nimport { resolveShareProjection } from \"./shareProjection\";\n\nasync function buildCurrentContainerSharePlan(\n input: Parameters<typeof buildMaterializedContainerSharePlan>[0],\n): Promise<MaterializedContainerSharePlan | null> {\n return nullOnProjectionVerificationCancellation(() =>\n buildMaterializedContainerSharePlan(input),\n );\n}\n\nexport interface ShareRemoteContainerRequest {\n accessLevel: ContainerAccessLevel;\n author: ContainerMutationAuthor;\n containerId: string;\n eventId?: string | undefined;\n previousProjection?: ContainerWriterProjectionResponse | undefined;\n recipientUserId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}\n\ntype ShareRemoteContainerInput = ShareRemoteContainerRequest &\n ContainerRotationBag<ContainerShareApi> & {\n resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n };\n\nexport type SharedRemoteContainer = {\n containerKey: Uint8Array;\n plan: ContainerSharePlan;\n response: ContainerMutationResponse;\n};\n\n/** A path a head advanced under, which a share plans once more (#2647). */\nconst STALE_PATH = Symbol(\"stale-path\");\n\n/**\n * Submit through the status-bearing endpoint when the adapter has one. The\n * refusal that ends the share is reported once submission settles, as the\n * plain endpoint's would be; a stale path the share plans again is not.\n */\nasync function submitShare(\n input: ShareRemoteContainerInput,\n request: ContainerMutationRequest,\n retriesStalePath: boolean,\n): Promise<ContainerRotationResult> {\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { shareContainerResult } = input.apiClient;\n if (!shareContainerResult) {\n return submitPlainContainerMutation(() =>\n input.apiClient.shareContainer(input.containerId, request, options),\n );\n }\n const result = await shareContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n { ...options, reportErrors: false },\n );\n if (result.ok) return { ok: true, data: result.data };\n return retriesStalePath && isStaleParentContainerPathFailure(result)\n ? { ok: false, code: result.code, status: result.status }\n : result;\n}\n\nfunction planShare(\n input: ShareRemoteContainerInput,\n recipientEncapsulationPublicKey: Uint8Array,\n resolveProjectionUserKey: ProjectionUserKeyResolver,\n) {\n return resolveShareProjection(input, resolveProjectionUserKey).then(\n (previousProjection) =>\n previousProjection &&\n buildCurrentContainerSharePlan({\n accessLevel: input.accessLevel,\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n previousProjection,\n recipient: {\n recipientEncapsulationPublicKey,\n subjectId: input.recipientUserId,\n subjectType: \"user\",\n },\n resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n }),\n );\n}\n\nasync function shareRemoteContainerOnce(\n input: ShareRemoteContainerInput,\n recipientEncapsulationPublicKey: Uint8Array,\n resolveProjectionUserKey: ProjectionUserKeyResolver,\n retriesStalePath: boolean,\n): Promise<SharedRemoteContainer | typeof STALE_PATH | null> {\n let materializedPlan: Awaited<ReturnType<typeof planShare>>;\n try {\n materializedPlan = await planShare(\n input,\n recipientEncapsulationPublicKey,\n resolveProjectionUserKey,\n );\n } catch (error) {\n // The path the share was handed predates a pin this device has since\n // advanced, most often through its own re-citation, or its principal\n // history stops short of a checkpoint another workflow pinned meanwhile\n // (a retryable missing dependency, as a create refreshes). A fresh\n // projection is held to the same pins, so a server that rolls a head\n // back or withholds history still fails the share, on its second plan.\n if (\n retriesStalePath &&\n ((error instanceof KeyingVerificationError &&\n error.code === \"rollback\") ||\n error instanceof ProjectionDependencyUnavailableError)\n )\n return STALE_PATH;\n throw error;\n }\n if (!materializedPlan) return null;\n let stalePath = false;\n const shared = await submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: async () => {\n const result = await submitShare(\n input,\n materializedPlan.plan.request,\n retriesStalePath,\n );\n stalePath =\n !result.ok &&\n retriesStalePath &&\n isStaleParentContainerPathFailure(result);\n return result;\n },\n });\n return shared ?? (stalePath ? STALE_PATH : null);\n}\n\n/**\n * Share a container with a user. A head on the signed path can advance while\n * the share is in flight, most often under this device's own background\n * re-citation of held descendants after a share above it. The API refuses\n * that as a stale path, and verification refuses a projection behind a local\n * pin or checkpoint; either way the share is planned once more from a fresh\n * projection, as a create under a stale parent is.\n */\nexport async function shareRemoteContainer(\n collaborators: ContainerMutationCollaborators<ContainerShareApi>,\n request: ShareRemoteContainerRequest,\n): Promise<SharedRemoteContainer | null> {\n const input: ShareRemoteContainerInput = {\n ...request,\n ...containerRotationBag(collaborators),\n resolveTrustedUserIdentity: collaborators.resolveTrustedUserIdentity,\n };\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container share\",\n );\n const resolveTrustedUserIdentity = requireTrustedUserIdentityResolver(\n input.resolveTrustedUserIdentity,\n );\n const recipientIdentity = await resolveTrustedUserIdentity(\n input.recipientUserId,\n );\n if (!recipientIdentity || input.stillCurrent?.() === false) {\n return null;\n }\n const first = await shareRemoteContainerOnce(\n input,\n recipientIdentity.encapsulationPublicKey,\n resolveProjectionUserKey,\n true,\n );\n if (first !== STALE_PATH) return first;\n if (input.stillCurrent?.() === false) return null;\n input.apiClient.evictContainerWriterProjection?.(input.containerId);\n const second = await shareRemoteContainerOnce(\n { ...input, previousProjection: undefined },\n recipientIdentity.encapsulationPublicKey,\n resolveProjectionUserKey,\n false,\n );\n return second === STALE_PATH ? null : second;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],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AC1C,KAAK,EACL,iBAAiB,CAAC,sBAAsB,EACxC,wBAAwB,EACxB,IAAI,CACL,CAAC;IACF,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,KAAK,CAAC,SAAS,CAAC,8BAA8B,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAC3C,EAAE,GAAG,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,EAC3C,iBAAiB,CAAC,sBAAsB,EACxC,wBAAwB,EACxB,KAAK,CACN,CAAC;IACF,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC/C,CAAC","sourcesContent":["import {\n type ContainerAccessLevel,\n KeyingVerificationError,\n} from \"@tearleads/crypto\";\nimport type { ContainerMutationRequest } from \"@tearleads/validators/request\";\nimport {\n type ContainerMutationResponse,\n type ContainerRotationResponse,\n type ContainerWriterProjectionResponse,\n committedReadModelDelta,\n type OrganizationReadModelDeltaResponse,\n} from \"@tearleads/validators/response\";\nimport { isStaleParentContainerPathFailure } from \"../../../../data/containers/shared/mutationFailures\";\nimport type {\n ContainerMutationAuthor,\n ContainerRotationResult,\n ContainerShareApi,\n ContainerShareCommittedReadModel,\n ContainerSharePlan,\n MaterializedContainerSharePlan,\n} from \"../../../../data/containers/shared/types\";\nimport {\n nullOnProjectionVerificationCancellation,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../../data/keyingProjectionVerification\";\nimport { ProjectionDependencyUnavailableError } from \"../../../../data/shared/dependencyUnavailable\";\nimport {\n requireTrustedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n} from \"../../../../data/trustedUserIdentity\";\nimport {\n type ContainerMutationCollaborators,\n type ContainerRotationBag,\n containerRotationBag,\n} from \"../../containerMutationCollaborators\";\nimport {\n submitAcknowledgedContainerMutation,\n submitPlainContainerMutation,\n} from \"../mutationSubmit\";\nimport { buildMaterializedContainerSharePlan } from \"./shareMaterialization\";\nimport { resolveShareProjection } from \"./shareProjection\";\n\nasync function buildCurrentContainerSharePlan(\n input: Parameters<typeof buildMaterializedContainerSharePlan>[0],\n): Promise<MaterializedContainerSharePlan | null> {\n return nullOnProjectionVerificationCancellation(() =>\n buildMaterializedContainerSharePlan(input),\n );\n}\n\nexport interface ShareRemoteContainerRequest {\n accessLevel: ContainerAccessLevel;\n author: ContainerMutationAuthor;\n /** Sends the read-model cursor the sharer holds; none without it. */\n committedReadModel?: ContainerShareCommittedReadModel | undefined;\n containerId: string;\n eventId?: string | undefined;\n previousProjection?: ContainerWriterProjectionResponse | undefined;\n recipientUserId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}\n\ntype ShareRemoteContainerInput = ShareRemoteContainerRequest &\n ContainerRotationBag<ContainerShareApi> & {\n resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n };\n\nexport type SharedRemoteContainer = {\n containerKey: Uint8Array;\n plan: ContainerSharePlan;\n response: ContainerMutationResponse;\n};\n\n/** A share's outcome, whose acknowledgement may carry a read-model delta. */\ntype ContainerShareSubmitResult =\n | {\n readonly ok: true;\n readonly data: ContainerRotationResponse & {\n readonly readModel?: unknown;\n };\n }\n | Extract<ContainerRotationResult, { ok: false }>;\n\n/** A path a head advanced under, which a share plans once more (#2647). */\nconst STALE_PATH = Symbol(\"stale-path\");\n\n/**\n * Submit through the status-bearing endpoint when the adapter has one. The\n * refusal that ends the share is reported once submission settles, as the\n * plain endpoint's would be; a stale path the share plans again is not.\n */\nasync function submitShare(\n input: ShareRemoteContainerInput,\n request: ContainerMutationRequest,\n retriesStalePath: boolean,\n readModelCursor: string | undefined,\n): Promise<ContainerShareSubmitResult> {\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { shareContainerResult } = input.apiClient;\n if (!shareContainerResult) {\n return submitPlainContainerMutation(() =>\n input.apiClient.shareContainer(input.containerId, request, options),\n );\n }\n const result = await shareContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n {\n ...options,\n ...(readModelCursor ? { readModelCursor } : {}),\n reportErrors: false,\n },\n );\n if (result.ok) return { ok: true, data: result.data };\n return retriesStalePath && isStaleParentContainerPathFailure(result)\n ? { ok: false, code: result.code, status: result.status }\n : result;\n}\n\nfunction planShare(\n input: ShareRemoteContainerInput,\n recipientEncapsulationPublicKey: Uint8Array,\n resolveProjectionUserKey: ProjectionUserKeyResolver,\n) {\n return resolveShareProjection(input, resolveProjectionUserKey).then(\n (previousProjection) =>\n previousProjection &&\n buildCurrentContainerSharePlan({\n accessLevel: input.accessLevel,\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n previousProjection,\n recipient: {\n recipientEncapsulationPublicKey,\n subjectId: input.recipientUserId,\n subjectType: \"user\",\n },\n resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n }),\n );\n}\n\nasync function shareRemoteContainerOnce(\n input: ShareRemoteContainerInput,\n recipientEncapsulationPublicKey: Uint8Array,\n resolveProjectionUserKey: ProjectionUserKeyResolver,\n retriesStalePath: boolean,\n): Promise<SharedRemoteContainer | typeof STALE_PATH | null> {\n let materializedPlan: Awaited<ReturnType<typeof planShare>>;\n try {\n materializedPlan = await planShare(\n input,\n recipientEncapsulationPublicKey,\n resolveProjectionUserKey,\n );\n } catch (error) {\n // The path the share was handed predates a pin this device has since\n // advanced, most often through its own re-citation, or its principal\n // history stops short of a checkpoint another workflow pinned meanwhile\n // (a retryable missing dependency, as a create refreshes). A fresh\n // projection is held to the same pins, so a server that rolls a head\n // back or withholds history still fails the share, on its second plan.\n if (\n retriesStalePath &&\n ((error instanceof KeyingVerificationError &&\n error.code === \"rollback\") ||\n error instanceof ProjectionDependencyUnavailableError)\n )\n return STALE_PATH;\n throw error;\n }\n if (!materializedPlan) return null;\n let stalePath = false;\n // The acknowledged submit rechecks currency after this lookup, and the\n // delta is offered only once the share's acknowledgement verified.\n const lease = await input.committedReadModel?.begin();\n let delta: OrganizationReadModelDeltaResponse | undefined;\n let shared: SharedRemoteContainer | null = null;\n try {\n shared = await submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: async () => {\n const result = await submitShare(\n input,\n materializedPlan.plan.request,\n retriesStalePath,\n lease?.heldCursor,\n );\n if (result.ok)\n delta = committedReadModelDelta(\n result.data.readModel,\n input.author.organizationId,\n );\n stalePath =\n !result.ok &&\n retriesStalePath &&\n isStaleParentContainerPathFailure(result);\n return result;\n },\n });\n } finally {\n lease?.settle(shared ? delta : undefined);\n }\n return shared ?? (stalePath ? STALE_PATH : null);\n}\n\n/**\n * Share a container with a user. A head on the signed path can advance while\n * the share is in flight, most often under this device's own background\n * re-citation of held descendants after a share above it. The API refuses\n * that as a stale path, and verification refuses a projection behind a local\n * pin or checkpoint; either way the share is planned once more from a fresh\n * projection, as a create under a stale parent is.\n */\nexport async function shareRemoteContainer(\n collaborators: ContainerMutationCollaborators<ContainerShareApi>,\n request: ShareRemoteContainerRequest,\n): Promise<SharedRemoteContainer | null> {\n const input: ShareRemoteContainerInput = {\n ...request,\n ...containerRotationBag(collaborators),\n resolveTrustedUserIdentity: collaborators.resolveTrustedUserIdentity,\n };\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container share\",\n );\n const resolveTrustedUserIdentity = requireTrustedUserIdentityResolver(\n input.resolveTrustedUserIdentity,\n );\n const recipientIdentity = await resolveTrustedUserIdentity(\n input.recipientUserId,\n );\n if (!recipientIdentity || input.stillCurrent?.() === false) {\n return null;\n }\n const first = await shareRemoteContainerOnce(\n input,\n recipientIdentity.encapsulationPublicKey,\n resolveProjectionUserKey,\n true,\n );\n if (first !== STALE_PATH) return first;\n if (input.stillCurrent?.() === false) return null;\n input.apiClient.evictContainerWriterProjection?.(input.containerId);\n const second = await shareRemoteContainerOnce(\n { ...input, previousProjection: undefined },\n recipientIdentity.encapsulationPublicKey,\n resolveProjectionUserKey,\n false,\n );\n return second === STALE_PATH ? null : second;\n}\n"]}
|
|
@@ -2,8 +2,27 @@ import { withMetadataRootReload } from "./groupMetadata/groupMetadataErrors.js";
|
|
|
2
2
|
import { createRuntimeGroupMetadataAccess } from "./groupMetadata/groupMetadataRuntime.js";
|
|
3
3
|
import { verifyRuntimeGroupMetadataAuthority } from "./groupMetadata/runtimeGroupMetadataAuthority.js";
|
|
4
4
|
import { createRuntimeCurrentGroupShare, createRuntimeCurrentSharePrincipalPolicy, } from "./groupShare/index.js";
|
|
5
|
-
|
|
5
|
+
import { beginCommittedReadModel } from "./readModel/committedReadModel.js";
|
|
6
|
+
/** A share stamps the grants lane once, when it persists the manifest. */
|
|
7
|
+
const SHARE_READ_MODEL_STAMPS = 1;
|
|
8
|
+
/**
|
|
9
|
+
* The organization operations the composition root hands container contents.
|
|
10
|
+
* A share's committed read-model lease is bound to the session generation the
|
|
11
|
+
* runtime reads when the share begins.
|
|
12
|
+
*/
|
|
13
|
+
export function createContainerContentsOrganizationHost(readSessionGeneration) {
|
|
14
|
+
return {
|
|
15
|
+
...containerContentsOrganizationHost,
|
|
16
|
+
committedReadModel: (scope) => ({
|
|
17
|
+
begin: () => beginCommittedReadModel({ ...scope, sessionGeneration: readSessionGeneration() }, SHARE_READ_MODEL_STAMPS),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The host for standalone runtimes, which have one session generation. */
|
|
6
22
|
export const containerContentsOrganizationHost = {
|
|
23
|
+
committedReadModel: (scope) => ({
|
|
24
|
+
begin: () => beginCommittedReadModel({ ...scope, sessionGeneration: 0 }, SHARE_READ_MODEL_STAMPS),
|
|
25
|
+
}),
|
|
7
26
|
createCurrentGroupShare: createRuntimeCurrentGroupShare,
|
|
8
27
|
createCurrentGroupPolicyReader: createRuntimeCurrentSharePrincipalPolicy,
|
|
9
28
|
groupMetadataNameReader: (runtime, organizationId, stillCurrent) => createRuntimeGroupMetadataAccess(runtime, organizationId, stillCurrent)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containerContentsHost.js","sourceRoot":"","sources":["containerContentsHost.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"containerContentsHost.js","sourceRoot":"","sources":["containerContentsHost.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,0EAA0E;AAC1E,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,uCAAuC,CACrD,qBAAmC;IAEnC,OAAO;QACL,GAAG,iCAAiC;QACpC,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC9B,KAAK,EAAE,GAAG,EAAE,CACV,uBAAuB,CACrB,EAAE,GAAG,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,EAAE,EACxD,uBAAuB,CACxB;SACJ,CAAC;KACH,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iCAAiC,GAC5C;IACE,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC9B,KAAK,EAAE,GAAG,EAAE,CACV,uBAAuB,CACrB,EAAE,GAAG,KAAK,EAAE,iBAAiB,EAAE,CAAC,EAAE,EAClC,uBAAuB,CACxB;KACJ,CAAC;IACF,uBAAuB,EAAE,8BAA8B;IACvD,8BAA8B,EAAE,wCAAwC;IACxE,uBAAuB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,CACjE,gCAAgC,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC;SACpE,QAAQ;IACb,4BAA4B,EAAE,mCAAmC;IACjE,sBAAsB;CACvB,CAAC","sourcesContent":["import type { ContainerContentsOrganizationHost } from \"../container-contents\";\nimport { withMetadataRootReload } from \"./groupMetadata/groupMetadataErrors\";\nimport { createRuntimeGroupMetadataAccess } from \"./groupMetadata/groupMetadataRuntime\";\nimport { verifyRuntimeGroupMetadataAuthority } from \"./groupMetadata/runtimeGroupMetadataAuthority\";\nimport {\n createRuntimeCurrentGroupShare,\n createRuntimeCurrentSharePrincipalPolicy,\n} from \"./groupShare\";\nimport { beginCommittedReadModel } from \"./readModel/committedReadModel\";\n\n/** A share stamps the grants lane once, when it persists the manifest. */\nconst SHARE_READ_MODEL_STAMPS = 1;\n\n/**\n * The organization operations the composition root hands container contents.\n * A share's committed read-model lease is bound to the session generation the\n * runtime reads when the share begins.\n */\nexport function createContainerContentsOrganizationHost(\n readSessionGeneration: () => number,\n): ContainerContentsOrganizationHost {\n return {\n ...containerContentsOrganizationHost,\n committedReadModel: (scope) => ({\n begin: () =>\n beginCommittedReadModel(\n { ...scope, sessionGeneration: readSessionGeneration() },\n SHARE_READ_MODEL_STAMPS,\n ),\n }),\n };\n}\n\n/** The host for standalone runtimes, which have one session generation. */\nexport const containerContentsOrganizationHost: ContainerContentsOrganizationHost =\n {\n committedReadModel: (scope) => ({\n begin: () =>\n beginCommittedReadModel(\n { ...scope, sessionGeneration: 0 },\n SHARE_READ_MODEL_STAMPS,\n ),\n }),\n createCurrentGroupShare: createRuntimeCurrentGroupShare,\n createCurrentGroupPolicyReader: createRuntimeCurrentSharePrincipalPolicy,\n groupMetadataNameReader: (runtime, organizationId, stillCurrent) =>\n createRuntimeGroupMetadataAccess(runtime, organizationId, stillCurrent)\n .readName,\n verifyGroupMetadataAuthority: verifyRuntimeGroupMetadataAuthority,\n withMetadataRootReload,\n };\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { committedReadModelDelta, } from "../../../internal/validators/response/index.js";
|
|
1
2
|
import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
|
|
2
3
|
import { buildOrganizationGroupDirectoryPolicyRequest, replaceOrganizationGroupHead, } from "../../../data/principals/organizationGroupDirectoryRequest.js";
|
|
3
4
|
import { assertAuthoredPrincipalMutationReceipt } from "../principalMutations/principalMutationReceipt.js";
|
|
@@ -66,7 +67,10 @@ export async function commitCurrentGroupPolicyMutation(input) {
|
|
|
66
67
|
}
|
|
67
68
|
await prepared.acknowledge(response.groupPolicy.containerMutations, context.stillCurrent);
|
|
68
69
|
assertProjectionVerificationCurrent(context.stillCurrent);
|
|
69
|
-
|
|
70
|
+
const readModel = committedReadModelDelta(response.readModel, input.organizationId);
|
|
71
|
+
return readModel
|
|
72
|
+
? { ...response.groupPolicy, readModel }
|
|
73
|
+
: response.groupPolicy;
|
|
70
74
|
}
|
|
71
75
|
async function prepareChange(change, signer, preceding) {
|
|
72
76
|
const expectedHead = await groupPolicyMutationHead(change.request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commitCurrentGroupPolicyMutation.js","sourceRoot":"","sources":["commitCurrentGroupPolicyMutation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,4DAA4D,CAAC;AAMpE,OAAO,EAAE,sCAAsC,EAAE,MAAM,gDAAgD,CAAC;AAExG,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAEL,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAwBpE,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,KAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,6BAA6B,CAAC;QACnD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC;KAC9B,CAAC,CAAC;IACH,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM;QACzB,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;QAC3C,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAa,CACpD,KAAK,EACL,MAAM,EACN,MAAM,EAAE,SAAS,CAClB,CAAC;IACF,MAAM,mBAAmB,GA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BAC1D,SAAS;gBACV,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC;QAE/D,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;IACJ,IAAI,UAAU,GAAG,4BAA4B,CAAC;QAC5C,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;IACH,IAAI,UAAU;QACZ,UAAU,GAAG,4BAA4B,CAAC;YACxC,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC,sBAAsB,EAAE,UAAU,EAAE;YAC7D,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;IACL,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB;QACvD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU;QAC1B,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACnD,MAAM,UAAU,GAAG,MAAM,6BAA6B,CAAC;QACrD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC;KAC5C,CAAC,CAAC;IACH,OAAO,4CAA4C,CAAC;QAClD,eAAe;QACf,UAAU;QACV,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,OAAO;QAClD,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n SigningKeyPair,\n VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../../../data/principals/organizationGroupDirectoryRequest\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type {\n PreparedPrincipalContainerRematerializationBatch,\n PrincipalRematerializationPredecessor,\n} from \"../../containers/rematerialization\";\nimport { assertAuthoredPrincipalMutationReceipt } from \"../principalMutations/principalMutationReceipt\";\nimport type { RuntimeCurrentGroupMutationContext } from \"../principalMutations/runtimeCurrentGroupMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\nimport { prepareAuthoredGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport {\n type PrincipalPolicyReadWriteApi,\n submitGroupPolicyCommit,\n} from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\n\ninterface GroupPolicyChange {\n readonly context: RuntimeCurrentGroupMutationContext;\n readonly request: PutPrincipalPolicyRequest;\n readonly prepareContainerMutations: (\n nextPolicy: VerifiedPrincipalPolicyCurrent,\n preceding?: PrincipalRematerializationPredecessor | undefined,\n ) => Promise<PreparedPrincipalContainerRematerializationBatch>;\n}\n\ninterface CommitInput extends GroupPolicyChange {\n readonly member?: GroupPolicyChange | undefined;\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n /** The signer's KEM secret; it keeps the directory key when admins grow. */\n readonly currentUserSecretKey: Uint8Array | null;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** Commit and retain the group, optional roster enrollment and directory together. */\nexport async function commitCurrentGroupPolicyMutation(\n input: CommitInput,\n): Promise<PrincipalPolicyMutationResponse> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const [signer] = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: [input.signerUserId],\n });\n if (!signer) throw new Error(\"Group policy signer is unavailable\");\n const member = input.member\n ? await prepareChange(input.member, signer)\n : null;\n const { expectedHead, prepared } = await prepareChange(\n input,\n signer,\n member?.preceding,\n );\n const organizationRequest = await prepareDirectory(\n input,\n expectedHead,\n member?.expectedHead,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const response = await submitGroupPolicyCommit({\n apiClient: input.apiClient,\n groupId: input.groupId,\n organizationId: input.organizationId,\n request: input.request,\n organizationRequest,\n memberRequest: input.member?.request,\n // A compound retry must rebuild both batches' shared speculative heads.\n // Refuse the whole transaction if a damaged-key repair needs extra rekeys;\n // ordinary adds preserve key epochs and need no descendant carry retry.\n carryDescendantRekeys: member ? undefined : prepared.carry,\n refreshContainerMutations: member\n ? undefined\n : prepared.refreshAfterConflict,\n stillCurrent: context.stillCurrent,\n });\n if (!response) throw new Error(\"Group policy update failed\");\n assertProjectionVerificationCurrent(context.stillCurrent);\n await assertAuthoredPrincipalMutationReceipt(\n {\n groupPolicy: input.request,\n organizationPolicy: organizationRequest,\n ...(input.member ? { memberPolicy: input.member.request } : {}),\n },\n response,\n );\n await context.retainAcknowledged({\n additionalGroups:\n input.member && response.memberPolicy\n ? [\n {\n ...input.member.context.groupRetention,\n request: input.member.request,\n response: response.memberPolicy,\n retiredContainerIds: member?.prepared.retiredContainerIds,\n },\n ]\n : [],\n request: input.request,\n organizationRequest,\n response,\n retiredContainerIds: prepared.retiredContainerIds,\n });\n if (member && response.memberPolicy) {\n await member.prepared.acknowledge(\n response.memberPolicy.containerMutations,\n context.stillCurrent,\n );\n }\n await prepared.acknowledge(\n response.groupPolicy.containerMutations,\n context.stillCurrent,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n return response.groupPolicy;\n}\n\nasync function prepareChange(\n change: GroupPolicyChange,\n signer: Awaited<ReturnType<typeof resolveRequiredUserIdentities>>[number],\n preceding?: PrincipalRematerializationPredecessor,\n) {\n const expectedHead = await groupPolicyMutationHead(change.request);\n const nextPolicy = await prepareAuthoredGroupPolicy({\n verifiedCurrentPolicy: change.context.verifiedCurrentPolicy,\n expectedHead,\n request: change.request,\n signerPublicKeys: [signer],\n externalAuthority: change.context.externalAuthority,\n localPolicyCheckpoint: change.context.localPolicyCheckpoint,\n stillCurrent: change.context.stillCurrent,\n });\n const authored = [\n ...(preceding?.authored ?? []),\n {\n organizationId: change.context.organizationDescriptor.organizationId,\n policy: nextPolicy,\n dependencies: [\n change.context.organizationCurrent.policy,\n change.context.adminCurrent.policy,\n ],\n stillCurrent: change.context.stillCurrent,\n },\n ];\n // A level the batch plans under its own rotation cites this successor\n // before the transaction commits, so the batch resolves it as authored,\n // exactly as the next group in a compound transaction does (#2646).\n const prepared = await change.prepareContainerMutations(nextPolicy, {\n policies: preceding?.policies ?? [],\n projections: preceding?.projections ?? [],\n knownContainerKeks: preceding?.knownContainerKeks ?? new Map(),\n authored,\n });\n change.request.containerMutations = [...prepared.requests];\n return {\n expectedHead,\n prepared,\n preceding: prepared.preceding\n ? { ...prepared.preceding, authored }\n : undefined,\n };\n}\n\nasync function prepareDirectory(\n input: CommitInput,\n expectedHead: Awaited<ReturnType<typeof groupPolicyMutationHead>>,\n memberHead: Awaited<ReturnType<typeof groupPolicyMutationHead>> | undefined,\n) {\n const { context } = input;\n if (\n input.member &&\n (input.member.context.currentPolicy.currentState.principalId !==\n context.memberGroupId ||\n input.member.context.organizationCurrent.current.currentState\n .stateHash !==\n context.organizationCurrent.current.currentState.stateHash)\n )\n throw new Error(\n \"Roster and group changes must share the same organization policy\",\n );\n let groupHeads = replaceOrganizationGroupHead({\n descriptor: context.organizationDescriptor,\n nextHead: expectedHead,\n });\n if (memberHead)\n groupHeads = replaceOrganizationGroupHead({\n descriptor: { ...context.organizationDescriptor, groupHeads },\n nextHead: memberHead,\n });\n const adminProjection = context.isOrganizationAdminsGroup\n ? input.request.projection\n : context.adminCurrent.current.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n return buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: context.organizationCurrent.current,\n currentUserSecretKey: input.currentUserSecretKey,\n descriptor: context.organizationDescriptor,\n groupHeads,\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commitCurrentGroupPolicyMutation.js","sourceRoot":"","sources":["commitCurrentGroupPolicyMutation.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,uBAAuB,GAGxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,4DAA4D,CAAC;AAMpE,OAAO,EAAE,sCAAsC,EAAE,MAAM,gDAAgD,CAAC;AAExG,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAEL,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AA6BpE,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,KAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,6BAA6B,CAAC;QACnD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC;KAC9B,CAAC,CAAC;I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CAAC,eAAe,CAAC;KAC5C,CAAC,CAAC;IACH,OAAO,4CAA4C,CAAC;QAClD,eAAe;QACf,UAAU;QACV,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,OAAO;QAClD,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n SigningKeyPair,\n VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport {\n committedReadModelDelta,\n type OrganizationReadModelDeltaResponse,\n type PrincipalPolicyMutationResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../../../data/principals/organizationGroupDirectoryRequest\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type {\n PreparedPrincipalContainerRematerializationBatch,\n PrincipalRematerializationPredecessor,\n} from \"../../containers/rematerialization\";\nimport { assertAuthoredPrincipalMutationReceipt } from \"../principalMutations/principalMutationReceipt\";\nimport type { RuntimeCurrentGroupMutationContext } from \"../principalMutations/runtimeCurrentGroupMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\nimport { prepareAuthoredGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport {\n type PrincipalPolicyReadWriteApi,\n submitGroupPolicyCommit,\n} from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\n\ninterface GroupPolicyChange {\n readonly context: RuntimeCurrentGroupMutationContext;\n readonly request: PutPrincipalPolicyRequest;\n readonly prepareContainerMutations: (\n nextPolicy: VerifiedPrincipalPolicyCurrent,\n preceding?: PrincipalRematerializationPredecessor | undefined,\n ) => Promise<PreparedPrincipalContainerRematerializationBatch>;\n}\n\ninterface CommitInput extends GroupPolicyChange {\n readonly member?: GroupPolicyChange | undefined;\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n /** The signer's KEM secret; it keeps the directory key when admins grow. */\n readonly currentUserSecretKey: Uint8Array | null;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** The group's acknowledgement, with the read-model delta the commit carried. */\nexport type CommittedGroupPolicy = PrincipalPolicyMutationResponse & {\n readonly readModel?: OrganizationReadModelDeltaResponse | undefined;\n};\n\n/** Commit and retain the group, optional roster enrollment and directory together. */\nexport async function commitCurrentGroupPolicyMutation(\n input: CommitInput,\n): Promise<CommittedGroupPolicy> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const [signer] = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: [input.signerUserId],\n });\n if (!signer) throw new Error(\"Group policy signer is unavailable\");\n const member = input.member\n ? await prepareChange(input.member, signer)\n : null;\n const { expectedHead, prepared } = await prepareChange(\n input,\n signer,\n member?.preceding,\n );\n const organizationRequest = await prepareDirectory(\n input,\n expectedHead,\n member?.expectedHead,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const response = await submitGroupPolicyCommit({\n apiClient: input.apiClient,\n groupId: input.groupId,\n organizationId: input.organizationId,\n request: input.request,\n organizationRequest,\n memberRequest: input.member?.request,\n // A compound retry must rebuild both batches' shared speculative heads.\n // Refuse the whole transaction if a damaged-key repair needs extra rekeys;\n // ordinary adds preserve key epochs and need no descendant carry retry.\n carryDescendantRekeys: member ? undefined : prepared.carry,\n refreshContainerMutations: member\n ? undefined\n : prepared.refreshAfterConflict,\n stillCurrent: context.stillCurrent,\n });\n if (!response) throw new Error(\"Group policy update failed\");\n assertProjectionVerificationCurrent(context.stillCurrent);\n await assertAuthoredPrincipalMutationReceipt(\n {\n groupPolicy: input.request,\n organizationPolicy: organizationRequest,\n ...(input.member ? { memberPolicy: input.member.request } : {}),\n },\n response,\n );\n await context.retainAcknowledged({\n additionalGroups:\n input.member && response.memberPolicy\n ? [\n {\n ...input.member.context.groupRetention,\n request: input.member.request,\n response: response.memberPolicy,\n retiredContainerIds: member?.prepared.retiredContainerIds,\n },\n ]\n : [],\n request: input.request,\n organizationRequest,\n response,\n retiredContainerIds: prepared.retiredContainerIds,\n });\n if (member && response.memberPolicy) {\n await member.prepared.acknowledge(\n response.memberPolicy.containerMutations,\n context.stillCurrent,\n );\n }\n await prepared.acknowledge(\n response.groupPolicy.containerMutations,\n context.stillCurrent,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const readModel = committedReadModelDelta(\n response.readModel,\n input.organizationId,\n );\n return readModel\n ? { ...response.groupPolicy, readModel }\n : response.groupPolicy;\n}\n\nasync function prepareChange(\n change: GroupPolicyChange,\n signer: Awaited<ReturnType<typeof resolveRequiredUserIdentities>>[number],\n preceding?: PrincipalRematerializationPredecessor,\n) {\n const expectedHead = await groupPolicyMutationHead(change.request);\n const nextPolicy = await prepareAuthoredGroupPolicy({\n verifiedCurrentPolicy: change.context.verifiedCurrentPolicy,\n expectedHead,\n request: change.request,\n signerPublicKeys: [signer],\n externalAuthority: change.context.externalAuthority,\n localPolicyCheckpoint: change.context.localPolicyCheckpoint,\n stillCurrent: change.context.stillCurrent,\n });\n const authored = [\n ...(preceding?.authored ?? []),\n {\n organizationId: change.context.organizationDescriptor.organizationId,\n policy: nextPolicy,\n dependencies: [\n change.context.organizationCurrent.policy,\n change.context.adminCurrent.policy,\n ],\n stillCurrent: change.context.stillCurrent,\n },\n ];\n // A level the batch plans under its own rotation cites this successor\n // before the transaction commits, so the batch resolves it as authored,\n // exactly as the next group in a compound transaction does (#2646).\n const prepared = await change.prepareContainerMutations(nextPolicy, {\n policies: preceding?.policies ?? [],\n projections: preceding?.projections ?? [],\n knownContainerKeks: preceding?.knownContainerKeks ?? new Map(),\n authored,\n });\n change.request.containerMutations = [...prepared.requests];\n return {\n expectedHead,\n prepared,\n preceding: prepared.preceding\n ? { ...prepared.preceding, authored }\n : undefined,\n };\n}\n\nasync function prepareDirectory(\n input: CommitInput,\n expectedHead: Awaited<ReturnType<typeof groupPolicyMutationHead>>,\n memberHead: Awaited<ReturnType<typeof groupPolicyMutationHead>> | undefined,\n) {\n const { context } = input;\n if (\n input.member &&\n (input.member.context.currentPolicy.currentState.principalId !==\n context.memberGroupId ||\n input.member.context.organizationCurrent.current.currentState\n .stateHash !==\n context.organizationCurrent.current.currentState.stateHash)\n )\n throw new Error(\n \"Roster and group changes must share the same organization policy\",\n );\n let groupHeads = replaceOrganizationGroupHead({\n descriptor: context.organizationDescriptor,\n nextHead: expectedHead,\n });\n if (memberHead)\n groupHeads = replaceOrganizationGroupHead({\n descriptor: { ...context.organizationDescriptor, groupHeads },\n nextHead: memberHead,\n });\n const adminProjection = context.isOrganizationAdminsGroup\n ? input.request.projection\n : context.adminCurrent.current.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n return buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: context.organizationCurrent.current,\n currentUserSecretKey: input.currentUserSecretKey,\n descriptor: context.organizationDescriptor,\n groupHeads,\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { committedReadModelDelta, } from "../../../internal/validators/response/index.js";
|
|
1
2
|
import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
|
|
2
3
|
import { KeyingCheckpointRepository } from "../../../data/persistence/keyingCheckpoints/keyingCheckpointRepository.js";
|
|
3
4
|
import { principalPolicyReferenceFromBundle } from "../../../data/principalContracts/principalPolicyAdminSigners.js";
|
|
@@ -85,6 +86,12 @@ export async function createCurrentOrganizationGroup(input) {
|
|
|
85
86
|
organizationResponse: stored.organizationPolicy,
|
|
86
87
|
});
|
|
87
88
|
assertProjectionVerificationCurrent(context.stillCurrent);
|
|
88
|
-
|
|
89
|
+
const created = {
|
|
90
|
+
...stored.group,
|
|
91
|
+
name: input.name.trim(),
|
|
92
|
+
nameUnreadable: false,
|
|
93
|
+
};
|
|
94
|
+
const readModel = committedReadModelDelta(stored.readModel, input.organizationId);
|
|
95
|
+
return readModel ? { ...created, readModel } : created;
|
|
89
96
|
}
|
|
90
97
|
//# sourceMappingURL=createCurrentOrganizationGroup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCurrentOrganizationGroup.js","sourceRoot":"","sources":["createCurrentOrganizationGroup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,wEAAwE,CAAC;AACpH,OAAO,EAAE,kCAAkC,EAAE,MAAM,8DAA8D,CAAC;AAClH,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,4DAA4D,CAAC;AACpE,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,iDAAiD,CAAC;AAKzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AAElG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAGjF,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B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;IAC1D,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC3D,2EAA2E;IAC3E,mEAAmE;IACnE,MAAM,6BAA6B,CAAC;QAClC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,OAAO;QACP,QAAQ,EAAE,MAAM,CAAC,KAAK;QACtB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,kBAAkB,CAAC;QAC/B,OAAO,EAAE,OAAO,CAAC,kBAAkB;QACnC,QAAQ,EAAE;YACR,IAAI;YACJ,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS;YACjC,kBAAkB,EAAE,EAAE;SACvB;QACD,mBAAmB;QACnB,oBAAoB,EAAE,MAAM,CAAC,kBAAkB;KAChD,CAAC,CAAC;IACH,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import type { EncapsulationKeyPair, SigningKeyPair } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { KeyingCheckpointRepository } from \"../../../data/persistence/keyingCheckpoints/keyingCheckpointRepository\";\nimport { principalPolicyReferenceFromBundle } from \"../../../data/principalContracts/principalPolicyAdminSigners\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../../../data/principals/organizationGroupDirectoryRequest\";\nimport {\n buildInitialGroupPolicyRequest,\n canonicalGroupNameKey,\n} from \"../../../data/principals/principalPolicyRequest\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type { createGroupMetadataAccess } from \"../groupMetadata/groupMetadataAccess\";\nimport { assertGroupMetadataBinding } from \"../groupMetadata/groupMetadataBinding\";\nimport { readDirectoryGroupName } from \"../groupNames/groupNameUniqueness\";\nimport { acknowledgeInitialGroupPolicy } from \"../groupPolicy/groupPolicyMutationAcknowledgement\";\nimport type { OrganizationPrincipalPolicyApi } from \"../groupPolicy/groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"../groupPolicy/groupPolicyMutationHead\";\nimport type { CurrentOrganizationMutationContext } from \"../principalMutations/runtimeCurrentOrganizationMutation\";\nimport type { OrganizationGroupSummary } from \"../readModel\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\n\n/** Create from bounded current evidence and publish its genuine genesis with the directory. */\nexport async function createCurrentOrganizationGroup(input: {\n readonly apiClient: Pick<\n OrganizationPrincipalPolicyApi,\n \"createOrganizationGroup\"\n >;\n readonly context: CurrentOrganizationMutationContext;\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly execSql: ExecSql;\n readonly metadataAccess: ReturnType<typeof createGroupMetadataAccess>;\n readonly name: string;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<OrganizationGroupSummary> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const nameKey = canonicalGroupNameKey(input.name);\n // Each current recovery is queued by organization. Retain verified heads one\n // at a time so the walk stays bounded without collecting full group histories.\n for (const head of context.descriptor.groupHeads) {\n const group = await context.readGroup(head.principalId);\n const stillCurrent = () => context.stillCurrent() && group.stillCurrent();\n assertProjectionVerificationCurrent(stillCurrent);\n assertGroupMetadataBinding(group.current, context.descriptor);\n const name = await readDirectoryGroupName(\n { ...input, readEncryptedName: input.metadataAccess.readName },\n group.current,\n );\n // Remember independently verified heads even if uniqueness or dispatch\n // later fails; these are observed policies, never speculative successors.\n await new KeyingCheckpointRepository(\n input.execSql,\n ).advanceKeyingCheckpointsAtomically({\n organizationId: input.organizationId,\n access: [],\n policies: [...group.dependencies, group.policy],\n stillCurrent,\n });\n if (name !== null && canonicalGroupNameKey(name) === nameKey)\n throw new Error(\n \"Another signed group in this organization already carries this name\",\n );\n }\n const request = await buildInitialGroupPolicyRequest({\n ...input,\n groupId: crypto.randomUUID(),\n includeSignerAsAdmin: false,\n externalAuthority: {\n ...principalPolicyReferenceFromBundle(context.admins.current),\n principalType: \"group\",\n },\n metadataKey: await input.metadataAccess.loadEncryptionKey(),\n });\n const head = await groupPolicyMutationHead(request.initialGroupPolicy);\n const adminProjection = context.admins.policy.projection;\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n ...input,\n currentPolicy: context.directory.current,\n // Creating a group keeps the admins; the creator's key checks that its\n // envelope still opens the kept directory key.\n currentUserSecretKey: input.creatorEncapsulationKeyPair.secretKey,\n descriptor: context.descriptor,\n groupHeads: replaceOrganizationGroupHead({\n descriptor: context.descriptor,\n nextHead: head,\n }),\n adminProjection,\n adminUsers: await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n }),\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n const stored = await input.apiClient.createOrganizationGroup(\n input.organizationId,\n { ...request, organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n if (!stored) throw new Error(\"Group could not be created\");\n // Genesis really has one signed state. Its acknowledgement is the summary;\n // the retained current is rebuilt from the exact authored request.\n await acknowledgeInitialGroupPolicy({\n organizationId: input.organizationId,\n request,\n response: stored.group,\n stateHash: head.stateHash,\n });\n await context.retainCreatedGroup({\n request: request.initialGroupPolicy,\n response: {\n head,\n createdAt: stored.group.createdAt,\n containerMutations: [],\n },\n organizationRequest,\n organizationResponse: stored.organizationPolicy,\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n return { ...stored.group, name: input.name.trim(), nameUnreadable: false };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createCurrentOrganizationGroup.js","sourceRoot":"","sources":["createCurrentOrganizationGroup.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,GAExB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,wEAAwE,CAAC;AACpH,OAAO,EAAE,kCAAkC,EAAE,MAAM,8DAA8D,CAAC;AAClH,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,4DAA4D,CAAC;AACpE,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,iDAAiD,CAAC;AAKzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AAElG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAGjF,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AAOrC,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,KAiBpD;IACC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,6EAA6E;IAC7E,+EAA+E;IAC/E,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,MAAM,OAA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AE,MAAM,CAAC,KAAK,CAAC,SAAS;YACjC,kBAAkB,EAAE,EAAE;SACvB;QACD,mBAAmB;QACnB,oBAAoB,EAAE,MAAM,CAAC,kBAAkB;KAChD,CAAC,CAAC;IACH,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG;QACd,GAAG,MAAM,CAAC,KAAK;QACf,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;QACvB,cAAc,EAAE,KAAK;KACtB,CAAC;IACF,MAAM,SAAS,GAAG,uBAAuB,CACvC,MAAM,CAAC,SAAS,EAChB,KAAK,CAAC,cAAc,CACrB,CAAC;IACF,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACzD,CAAC","sourcesContent":["import type { EncapsulationKeyPair, SigningKeyPair } from \"@tearleads/crypto\";\nimport {\n committedReadModelDelta,\n type OrganizationReadModelDeltaResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { KeyingCheckpointRepository } from \"../../../data/persistence/keyingCheckpoints/keyingCheckpointRepository\";\nimport { principalPolicyReferenceFromBundle } from \"../../../data/principalContracts/principalPolicyAdminSigners\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../../../data/principals/organizationGroupDirectoryRequest\";\nimport {\n buildInitialGroupPolicyRequest,\n canonicalGroupNameKey,\n} from \"../../../data/principals/principalPolicyRequest\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type { createGroupMetadataAccess } from \"../groupMetadata/groupMetadataAccess\";\nimport { assertGroupMetadataBinding } from \"../groupMetadata/groupMetadataBinding\";\nimport { readDirectoryGroupName } from \"../groupNames/groupNameUniqueness\";\nimport { acknowledgeInitialGroupPolicy } from \"../groupPolicy/groupPolicyMutationAcknowledgement\";\nimport type { OrganizationPrincipalPolicyApi } from \"../groupPolicy/groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"../groupPolicy/groupPolicyMutationHead\";\nimport type { CurrentOrganizationMutationContext } from \"../principalMutations/runtimeCurrentOrganizationMutation\";\nimport type { OrganizationGroupSummary } from \"../readModel\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\n\n/** The created group, with the read-model delta its create response carried. */\nexport type CreatedCurrentOrganizationGroup = OrganizationGroupSummary & {\n readonly readModel?: OrganizationReadModelDeltaResponse | undefined;\n};\n\n/** Create from bounded current evidence and publish its genuine genesis with the directory. */\nexport async function createCurrentOrganizationGroup(input: {\n readonly apiClient: Pick<\n OrganizationPrincipalPolicyApi,\n \"createOrganizationGroup\"\n >;\n readonly context: CurrentOrganizationMutationContext;\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly execSql: ExecSql;\n readonly metadataAccess: ReturnType<typeof createGroupMetadataAccess>;\n readonly name: string;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<CreatedCurrentOrganizationGroup> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const nameKey = canonicalGroupNameKey(input.name);\n // Each current recovery is queued by organization. Retain verified heads one\n // at a time so the walk stays bounded without collecting full group histories.\n for (const head of context.descriptor.groupHeads) {\n const group = await context.readGroup(head.principalId);\n const stillCurrent = () => context.stillCurrent() && group.stillCurrent();\n assertProjectionVerificationCurrent(stillCurrent);\n assertGroupMetadataBinding(group.current, context.descriptor);\n const name = await readDirectoryGroupName(\n { ...input, readEncryptedName: input.metadataAccess.readName },\n group.current,\n );\n // Remember independently verified heads even if uniqueness or dispatch\n // later fails; these are observed policies, never speculative successors.\n await new KeyingCheckpointRepository(\n input.execSql,\n ).advanceKeyingCheckpointsAtomically({\n organizationId: input.organizationId,\n access: [],\n policies: [...group.dependencies, group.policy],\n stillCurrent,\n });\n if (name !== null && canonicalGroupNameKey(name) === nameKey)\n throw new Error(\n \"Another signed group in this organization already carries this name\",\n );\n }\n const request = await buildInitialGroupPolicyRequest({\n ...input,\n groupId: crypto.randomUUID(),\n includeSignerAsAdmin: false,\n externalAuthority: {\n ...principalPolicyReferenceFromBundle(context.admins.current),\n principalType: \"group\",\n },\n metadataKey: await input.metadataAccess.loadEncryptionKey(),\n });\n const head = await groupPolicyMutationHead(request.initialGroupPolicy);\n const adminProjection = context.admins.policy.projection;\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n ...input,\n currentPolicy: context.directory.current,\n // Creating a group keeps the admins; the creator's key checks that its\n // envelope still opens the kept directory key.\n currentUserSecretKey: input.creatorEncapsulationKeyPair.secretKey,\n descriptor: context.descriptor,\n groupHeads: replaceOrganizationGroupHead({\n descriptor: context.descriptor,\n nextHead: head,\n }),\n adminProjection,\n adminUsers: await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n }),\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n const stored = await input.apiClient.createOrganizationGroup(\n input.organizationId,\n { ...request, organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n if (!stored) throw new Error(\"Group could not be created\");\n // Genesis really has one signed state. Its acknowledgement is the summary;\n // the retained current is rebuilt from the exact authored request.\n await acknowledgeInitialGroupPolicy({\n organizationId: input.organizationId,\n request,\n response: stored.group,\n stateHash: head.stateHash,\n });\n await context.retainCreatedGroup({\n request: request.initialGroupPolicy,\n response: {\n head,\n createdAt: stored.group.createdAt,\n containerMutations: [],\n },\n organizationRequest,\n organizationResponse: stored.organizationPolicy,\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n const created = {\n ...stored.group,\n name: input.name.trim(),\n nameUnreadable: false,\n };\n const readModel = committedReadModelDelta(\n stored.readModel,\n input.organizationId,\n );\n return readModel ? { ...created, readModel } : created;\n}\n"]}
|
|
@@ -17,6 +17,7 @@ export type { PrincipalMutationResponse } from "./principalMutations/principalOp
|
|
|
17
17
|
export { type AcknowledgedPrincipalCurrentInput, type AcknowledgedPrincipalCurrentRetirement, retainAcknowledgedPrincipalCurrents, } from "./principalMutations/retainAcknowledgedPrincipalCurrents.js";
|
|
18
18
|
export { addOrganizationGroupUser, buildInitialGroupPolicyRequest, buildInitialMemberGroupPolicyRequest, createOrganizationGroup, removeOrganizationGroupUser, rotateOrganizationGroupForAccessSetShrink, } from "./principalPolicy/index.js";
|
|
19
19
|
export { buildOrganizationGroupPolicyHistory, type OrganizationContainerGrant, type OrganizationContainerGrants, type OrganizationDirectory, type OrganizationDirectoryAndGroups, type OrganizationDirectoryUser, type OrganizationGroupContainer, type OrganizationGroupContainers, type OrganizationGroupDetails, type OrganizationGroupMember, type OrganizationGroupMembers, type OrganizationGroupPolicyHistory, type OrganizationGroupPolicyHistoryEntry, type OrganizationGroupSummary, type OrganizationPolicyGrantChange, type OrganizationPolicyGroupChange, type OrganizationPolicyHistory, type OrganizationPolicyHistoryEntry, type OrganizationPrincipalMemberChange, type OrganizationPrincipalMemberChangeType, type OrganizationPrincipalPolicyHistory, type OrganizationPrincipalPolicyHistoryEntry, type OrganizationProfile, type OrganizationUserDetail, updateOrganizationProfile, updateOrganizationRosterEntry, } from "./readModel/index.js";
|
|
20
|
+
export { applyCommittedOrganizationReadModel, awaitCommittedReadModelOffers, beginCommittedReadModel, type CommittedReadModelLease, type CommittedReadModelOffer, type CommittedReadModelOutcome, claimCommittedReadModelOffer, loadHeldOrganizationReadModelCursor, } from "./readModel/committedReadModel.js";
|
|
20
21
|
export { loadLocalOrganizationDataUsage, type OrganizationDataUsage, type ReconcileOrganizationDataUsageInput, reconcileOrganizationDataUsage, } from "./readModel/dataUsageReadModel.js";
|
|
21
22
|
export { measureOrganizationDeviceDataUsage, ORGANIZATION_DOCUMENT_USAGE_CATEGORIES, type OrganizationDeviceDataUsage, type OrganizationDeviceDocumentUsageCategoryBreakdown, type OrganizationDocumentUsageCategory, } from "./readModel/deviceDataUsage.js";
|
|
22
23
|
export { type LocalOrganizationSummary, listLocalOrganizations, } from "./readModel/listLocalOrganizations.js";
|
|
@@ -15,6 +15,7 @@ export { PrincipalMutationOutcomeUnknownError, recoverJournaledPrincipalMutation
|
|
|
15
15
|
export { retainAcknowledgedPrincipalCurrents, } from "./principalMutations/retainAcknowledgedPrincipalCurrents.js";
|
|
16
16
|
export { addOrganizationGroupUser, buildInitialGroupPolicyRequest, buildInitialMemberGroupPolicyRequest, createOrganizationGroup, removeOrganizationGroupUser, rotateOrganizationGroupForAccessSetShrink, } from "./principalPolicy/index.js";
|
|
17
17
|
export { buildOrganizationGroupPolicyHistory, updateOrganizationProfile, updateOrganizationRosterEntry, } from "./readModel/index.js";
|
|
18
|
+
export { applyCommittedOrganizationReadModel, awaitCommittedReadModelOffers, beginCommittedReadModel, claimCommittedReadModelOffer, loadHeldOrganizationReadModelCursor, } from "./readModel/committedReadModel.js";
|
|
18
19
|
export { loadLocalOrganizationDataUsage, reconcileOrganizationDataUsage, } from "./readModel/dataUsageReadModel.js";
|
|
19
20
|
export { measureOrganizationDeviceDataUsage, ORGANIZATION_DOCUMENT_USAGE_CATEGORIES, } from "./readModel/deviceDataUsage.js";
|
|
20
21
|
export { listLocalOrganizations, } from "./readModel/listLocalOrganizations.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0CAA0C,GAC3C,MAAM,wEAAwE,CAAC;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4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zB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,8BAA8B,EAG9B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GAIvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,kCAAkC,EAClC,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,uCAAuC,EACvC,iCAAiC,EAEjC,uCAAuC,GACxC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,+BAA+B,EAC/B,sCAAsC,EACtC,6CAA6C,EAC7C,kDAAkD,EAClD,+BAA+B,EAC/B,oCAAoC,EACpC,0CAA0C,EAC1C,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC","sourcesContent":["export {\n type OrganizationReadModelInvalidationListener,\n subscribeOrganizationReadModelInvalidation,\n} from \"../../data/persistence/organizations/organizationReadModelInvalidation\";\nexport { PendingPrincipalMutationError } from \"../../data/persistence/principalMutationJournalPersistence\";\nexport type {\n AuthoredPrincipalMutation,\n PrincipalMutationJournalScope,\n} from \"../../data/principals/principalMutationJournal\";\nexport { UnreadablePrincipalMutationError } from \"../../data/principals/principalMutationJournalRecord\";\nexport {\n cancelStripeSubscription,\n changeStripePlan,\n checkNativePurchaseEligibility,\n claimNativeOrganizationSubscription,\n createStripeCheckout,\n createStripeCheckoutSession,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n loadStripeCheckoutOptions,\n type OrganizationBilling,\n type OrganizationBillingHistory,\n type OrganizationBillingHistoryEntry,\n type OrganizationBillingManagementUrl,\n type OrganizationBillingView,\n type OrganizationNativePurchaseEligibility,\n resolveOrganizationBillingView,\n type StripeCheckoutIntent,\n type StripeCheckoutOptions,\n startOrganizationTrial,\n} from \"./billing\";\nexport { revokeOrganizationContainerGrant } from \"./containerGrantRevocation\";\nexport { GroupMembershipNameMismatchError } from \"./groupNames/groupMembershipName\";\nexport {\n GroupShareNameMismatchError,\n shareRemoteContainerWithGroup,\n} from \"./groupShare\";\nexport { deleteOrganizationGroup } from \"./groups/deleteOrganizationGroup\";\nexport {\n type OrganizationLeaveRequestResult,\n setOrganizationLeaveRequested,\n} from \"./memberships/leaveRequest\";\nexport {\n withVerifiedDirectoryUser,\n withVerifiedLeaveRequests,\n withVerifiedUserLeaveRequest,\n} from \"./memberships/leaveRequestVerification\";\nexport {\n type OrganizationContentHost,\n type OrganizationMembership,\n type OrganizationMembershipApi,\n type OrganizationSyncPauseResult,\n refreshOrganizationMemberships,\n setOrganizationSyncPaused,\n} from \"./memberships/organizationMemberships\";\nexport {\n buildOrganizationProfileDocumentPatch,\n createInitializedOrganizationProfileDocument,\n DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME,\n getOrganizationProfileDocumentLocalId,\n ORGANIZATION_PROFILE_DOCUMENT_KIND,\n readOrganizationProfileName,\n} from \"./organizationProfile\";\nexport {\n abandonJournaledPrincipalMutation,\n discardUnreadableJournaledPrincipalMutation,\n readJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalManagement\";\nexport {\n type PrincipalMutationJournalContext,\n PrincipalMutationOutcomeUnknownError,\n recoverJournaledPrincipalMutation,\n submitJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalSession\";\nexport type { PrincipalMutationResponse } from \"./principalMutations/principalOperationReceipt\";\nexport {\n type AcknowledgedPrincipalCurrentInput,\n type AcknowledgedPrincipalCurrentRetirement,\n retainAcknowledgedPrincipalCurrents,\n} from \"./principalMutations/retainAcknowledgedPrincipalCurrents\";\nexport {\n addOrganizationGroupUser,\n buildInitialGroupPolicyRequest,\n buildInitialMemberGroupPolicyRequest,\n createOrganizationGroup,\n removeOrganizationGroupUser,\n rotateOrganizationGroupForAccessSetShrink,\n} from \"./principalPolicy\";\nexport {\n buildOrganizationGroupPolicyHistory,\n type OrganizationContainerGrant,\n type OrganizationContainerGrants,\n type OrganizationDirectory,\n type OrganizationDirectoryAndGroups,\n type OrganizationDirectoryUser,\n type OrganizationGroupContainer,\n type OrganizationGroupContainers,\n type OrganizationGroupDetails,\n type OrganizationGroupMember,\n type OrganizationGroupMembers,\n type OrganizationGroupPolicyHistory,\n type OrganizationGroupPolicyHistoryEntry,\n type OrganizationGroupSummary,\n type OrganizationPolicyGrantChange,\n type OrganizationPolicyGroupChange,\n type OrganizationPolicyHistory,\n type OrganizationPolicyHistoryEntry,\n type OrganizationPrincipalMemberChange,\n type OrganizationPrincipalMemberChangeType,\n type OrganizationPrincipalPolicyHistory,\n type OrganizationPrincipalPolicyHistoryEntry,\n type OrganizationProfile,\n type OrganizationUserDetail,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n} from \"./readModel\";\nexport {\n loadLocalOrganizationDataUsage,\n type OrganizationDataUsage,\n type ReconcileOrganizationDataUsageInput,\n reconcileOrganizationDataUsage,\n} from \"./readModel/dataUsageReadModel\";\nexport {\n measureOrganizationDeviceDataUsage,\n ORGANIZATION_DOCUMENT_USAGE_CATEGORIES,\n type OrganizationDeviceDataUsage,\n type OrganizationDeviceDocumentUsageCategoryBreakdown,\n type OrganizationDocumentUsageCategory,\n} from \"./readModel/deviceDataUsage\";\nexport {\n type LocalOrganizationSummary,\n listLocalOrganizations,\n} from \"./readModel/listLocalOrganizations\";\nexport {\n loadLocalOrganizationContainerGrants,\n loadLocalOrganizationGroupContainers,\n loadLocalOrganizationGroupPolicyHistory,\n loadLocalOrganizationPolicyHistory,\n loadLocalOrganizationPolicyReference,\n loadLocalOrganizationUserDetail,\n} from \"./readModel/localReadModelDetails\";\nexport {\n loadLocalOrganizationDirectoryAndGroups,\n loadLocalOrganizationGroupMembers,\n type ReconcileOrganizationDirectoryAndGroupsInput,\n reconcileOrganizationDirectoryAndGroups,\n} from \"./readModel/readModelProjection\";\nexport {\n buildRosterProfileDocumentPatch,\n createInitializedRosterProfileDocument,\n deriveOrganizationMetadataContainerSystemSlot,\n deriveOrganizationRosterProfileContainerSystemSlot,\n getRosterProfileDocumentLocalId,\n ORGANIZATION_METADATA_CONTAINER_NAME,\n ORGANIZATION_ROSTER_PROFILE_CONTAINER_NAME,\n ROSTER_PROFILE_DOCUMENT_KIND,\n} from \"./rosterProfileContainer\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0CAA0C,GAC3C,MAAM,wEAAwE,CAAC;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAK3G,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,EAC9B,mCAAmC,EACnC,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,EACvB,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EAOzB,8BAA8B,EAG9B,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAEL,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAKL,8BAA8B,EAC9B,yBAAyB,GAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,qCAAqC,EACrC,4CAA4C,EAC5C,0CAA0C,EAC1C,qCAAqC,EACrC,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iCAAiC,EACjC,2CAA2C,EAC3C,8BAA8B,GAC/B,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAEL,oCAAoC,EACpC,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,sDAAsD,CAAC;AAE9D,OAAO,EAGL,mCAAmC,GACpC,MAAM,0DAA0D,CAAC;AAClE,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,oCAAoC,EACpC,uBAAuB,EACvB,2BAA2B,EAC3B,yCAAyC,GAC1C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mCAAmC,EAwBnC,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mCAAmC,EACnC,6BAA6B,EAC7B,uBAAuB,EAIvB,4BAA4B,EAC5B,mCAAmC,GACpC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,8BAA8B,EAG9B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GAIvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,kCAAkC,EAClC,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,uCAAuC,EACvC,iCAAiC,EAEjC,uCAAuC,GACxC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,+BAA+B,EAC/B,sCAAsC,EACtC,6CAA6C,EAC7C,kDAAkD,EAClD,+BAA+B,EAC/B,oCAAoC,EACpC,0CAA0C,EAC1C,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC","sourcesContent":["export {\n type OrganizationReadModelInvalidationListener,\n subscribeOrganizationReadModelInvalidation,\n} from \"../../data/persistence/organizations/organizationReadModelInvalidation\";\nexport { PendingPrincipalMutationError } from \"../../data/persistence/principalMutationJournalPersistence\";\nexport type {\n AuthoredPrincipalMutation,\n PrincipalMutationJournalScope,\n} from \"../../data/principals/principalMutationJournal\";\nexport { UnreadablePrincipalMutationError } from \"../../data/principals/principalMutationJournalRecord\";\nexport {\n cancelStripeSubscription,\n changeStripePlan,\n checkNativePurchaseEligibility,\n claimNativeOrganizationSubscription,\n createStripeCheckout,\n createStripeCheckoutSession,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n loadStripeCheckoutOptions,\n type OrganizationBilling,\n type OrganizationBillingHistory,\n type OrganizationBillingHistoryEntry,\n type OrganizationBillingManagementUrl,\n type OrganizationBillingView,\n type OrganizationNativePurchaseEligibility,\n resolveOrganizationBillingView,\n type StripeCheckoutIntent,\n type StripeCheckoutOptions,\n startOrganizationTrial,\n} from \"./billing\";\nexport { revokeOrganizationContainerGrant } from \"./containerGrantRevocation\";\nexport { GroupMembershipNameMismatchError } from \"./groupNames/groupMembershipName\";\nexport {\n GroupShareNameMismatchError,\n shareRemoteContainerWithGroup,\n} from \"./groupShare\";\nexport { deleteOrganizationGroup } from \"./groups/deleteOrganizationGroup\";\nexport {\n type OrganizationLeaveRequestResult,\n setOrganizationLeaveRequested,\n} from \"./memberships/leaveRequest\";\nexport {\n withVerifiedDirectoryUser,\n withVerifiedLeaveRequests,\n withVerifiedUserLeaveRequest,\n} from \"./memberships/leaveRequestVerification\";\nexport {\n type OrganizationContentHost,\n type OrganizationMembership,\n type OrganizationMembershipApi,\n type OrganizationSyncPauseResult,\n refreshOrganizationMemberships,\n setOrganizationSyncPaused,\n} from \"./memberships/organizationMemberships\";\nexport {\n buildOrganizationProfileDocumentPatch,\n createInitializedOrganizationProfileDocument,\n DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME,\n getOrganizationProfileDocumentLocalId,\n ORGANIZATION_PROFILE_DOCUMENT_KIND,\n readOrganizationProfileName,\n} from \"./organizationProfile\";\nexport {\n abandonJournaledPrincipalMutation,\n discardUnreadableJournaledPrincipalMutation,\n readJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalManagement\";\nexport {\n type PrincipalMutationJournalContext,\n PrincipalMutationOutcomeUnknownError,\n recoverJournaledPrincipalMutation,\n submitJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalSession\";\nexport type { PrincipalMutationResponse } from \"./principalMutations/principalOperationReceipt\";\nexport {\n type AcknowledgedPrincipalCurrentInput,\n type AcknowledgedPrincipalCurrentRetirement,\n retainAcknowledgedPrincipalCurrents,\n} from \"./principalMutations/retainAcknowledgedPrincipalCurrents\";\nexport {\n addOrganizationGroupUser,\n buildInitialGroupPolicyRequest,\n buildInitialMemberGroupPolicyRequest,\n createOrganizationGroup,\n removeOrganizationGroupUser,\n rotateOrganizationGroupForAccessSetShrink,\n} from \"./principalPolicy\";\nexport {\n buildOrganizationGroupPolicyHistory,\n type OrganizationContainerGrant,\n type OrganizationContainerGrants,\n type OrganizationDirectory,\n type OrganizationDirectoryAndGroups,\n type OrganizationDirectoryUser,\n type OrganizationGroupContainer,\n type OrganizationGroupContainers,\n type OrganizationGroupDetails,\n type OrganizationGroupMember,\n type OrganizationGroupMembers,\n type OrganizationGroupPolicyHistory,\n type OrganizationGroupPolicyHistoryEntry,\n type OrganizationGroupSummary,\n type OrganizationPolicyGrantChange,\n type OrganizationPolicyGroupChange,\n type OrganizationPolicyHistory,\n type OrganizationPolicyHistoryEntry,\n type OrganizationPrincipalMemberChange,\n type OrganizationPrincipalMemberChangeType,\n type OrganizationPrincipalPolicyHistory,\n type OrganizationPrincipalPolicyHistoryEntry,\n type OrganizationProfile,\n type OrganizationUserDetail,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n} from \"./readModel\";\nexport {\n applyCommittedOrganizationReadModel,\n awaitCommittedReadModelOffers,\n beginCommittedReadModel,\n type CommittedReadModelLease,\n type CommittedReadModelOffer,\n type CommittedReadModelOutcome,\n claimCommittedReadModelOffer,\n loadHeldOrganizationReadModelCursor,\n} from \"./readModel/committedReadModel\";\nexport {\n loadLocalOrganizationDataUsage,\n type OrganizationDataUsage,\n type ReconcileOrganizationDataUsageInput,\n reconcileOrganizationDataUsage,\n} from \"./readModel/dataUsageReadModel\";\nexport {\n measureOrganizationDeviceDataUsage,\n ORGANIZATION_DOCUMENT_USAGE_CATEGORIES,\n type OrganizationDeviceDataUsage,\n type OrganizationDeviceDocumentUsageCategoryBreakdown,\n type OrganizationDocumentUsageCategory,\n} from \"./readModel/deviceDataUsage\";\nexport {\n type LocalOrganizationSummary,\n listLocalOrganizations,\n} from \"./readModel/listLocalOrganizations\";\nexport {\n loadLocalOrganizationContainerGrants,\n loadLocalOrganizationGroupContainers,\n loadLocalOrganizationGroupPolicyHistory,\n loadLocalOrganizationPolicyHistory,\n loadLocalOrganizationPolicyReference,\n loadLocalOrganizationUserDetail,\n} from \"./readModel/localReadModelDetails\";\nexport {\n loadLocalOrganizationDirectoryAndGroups,\n loadLocalOrganizationGroupMembers,\n type ReconcileOrganizationDirectoryAndGroupsInput,\n reconcileOrganizationDirectoryAndGroups,\n} from \"./readModel/readModelProjection\";\nexport {\n buildRosterProfileDocumentPatch,\n createInitializedRosterProfileDocument,\n deriveOrganizationMetadataContainerSystemSlot,\n deriveOrganizationRosterProfileContainerSystemSlot,\n getRosterProfileDocumentLocalId,\n ORGANIZATION_METADATA_CONTAINER_NAME,\n ORGANIZATION_ROSTER_PROFILE_CONTAINER_NAME,\n ROSTER_PROFILE_DOCUMENT_KIND,\n} from \"./rosterProfileContainer\";\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { OrganizationReadModelDeltaResponse } from "../../../internal/validators/response/index.js";
|
|
2
|
+
import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
|
|
3
|
+
import type { OrganizationDirectoryAndGroups } from "./index.js";
|
|
4
|
+
import { applyOrganizationReadModelPageAt } from "./readModelProjection.js";
|
|
5
|
+
/**
|
|
6
|
+
* The read-model delta one of this device's mutations carried back, and the
|
|
7
|
+
* cursor it held when it sent the mutation: the page a feed read from that
|
|
8
|
+
* cursor returns once the mutation committed.
|
|
9
|
+
*/
|
|
10
|
+
export interface CommittedReadModelOffer {
|
|
11
|
+
readonly delta: OrganizationReadModelDeltaResponse;
|
|
12
|
+
readonly heldCursor: string;
|
|
13
|
+
}
|
|
14
|
+
/** What applying an offer presented; `undefined` when it applied nothing. */
|
|
15
|
+
export type CommittedReadModelOutcome = OrganizationDirectoryAndGroups | null | undefined;
|
|
16
|
+
interface CommittedReadModelScope {
|
|
17
|
+
/** The runtime's domain scope; an identity switch replaces it. */
|
|
18
|
+
readonly domainScope: object;
|
|
19
|
+
readonly execSql: ExecSql;
|
|
20
|
+
readonly organizationId: string;
|
|
21
|
+
/** The runtime's session generation; a logout or new login advances it. */
|
|
22
|
+
readonly sessionGeneration: number;
|
|
23
|
+
readonly userId: string;
|
|
24
|
+
}
|
|
25
|
+
/** A mutation that sent a held cursor; settle it once, when it ends. */
|
|
26
|
+
export interface CommittedReadModelLease {
|
|
27
|
+
readonly heldCursor: string | undefined;
|
|
28
|
+
settle(delta: OrganizationReadModelDeltaResponse | undefined): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Begin a mutation that sends the read-model cursor this requester's next
|
|
32
|
+
* reconcile would request from, so its response can carry the delta from it.
|
|
33
|
+
* Until it settles, a realtime hint's cursor check waits for it. No cursor is
|
|
34
|
+
* held while the requester's presentation is denied, since that reconcile
|
|
35
|
+
* requests a snapshot, or when the projection cannot be read.
|
|
36
|
+
*/
|
|
37
|
+
export declare function beginCommittedReadModel(scope: CommittedReadModelScope,
|
|
38
|
+
/** How many cursors the mutation can stamp; a share stamps one. */
|
|
39
|
+
maxStamps?: number): Promise<CommittedReadModelLease>;
|
|
40
|
+
/**
|
|
41
|
+
* Wait, for a bounded time, for this scope's mutations in flight that could
|
|
42
|
+
* be the commit a realtime hint names, then list every unclaimed delta, oldest
|
|
43
|
+
* first: a hint names a commit, and an offer at or past it reflects that
|
|
44
|
+
* commit. A mutation still in flight after the wait leaves the check to read.
|
|
45
|
+
*/
|
|
46
|
+
export declare function awaitCommittedReadModelOffers(scope: CommittedReadModelScope,
|
|
47
|
+
/** Without a hint position, every mutation in flight is waited for. */
|
|
48
|
+
hintPosition: bigint | undefined, maxWaitMs?: number): Promise<readonly CommittedReadModelOffer[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Apply one offer once, by its delta. The first claimant (a hint's cursor
|
|
51
|
+
* check or the mutation's own reconcile) runs `apply`; a later claimant of the
|
|
52
|
+
* same delta shares that outcome instead of reading. `undefined` when the
|
|
53
|
+
* scope holds no such offer.
|
|
54
|
+
*/
|
|
55
|
+
export declare function claimCommittedReadModelOffer(scope: CommittedReadModelScope, delta: OrganizationReadModelDeltaResponse, apply: (offer: CommittedReadModelOffer) => Promise<CommittedReadModelOutcome>): Promise<CommittedReadModelOutcome> | undefined;
|
|
56
|
+
/** The projection cursor a reconcile of this requester would request from. */
|
|
57
|
+
export declare function loadHeldOrganizationReadModelCursor(scope: CommittedReadModelScope): Promise<string | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Apply the read-model delta a mutation's response carried as the page a feed
|
|
60
|
+
* read from `requestedCursor` returns, with no request. Resolves `undefined`
|
|
61
|
+
* when it is not applied: its cursor does not advance past the one sent, the
|
|
62
|
+
* projection no longer holds that cursor, or the page applied stale. The
|
|
63
|
+
* caller then reads the feed as before.
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyCommittedOrganizationReadModel(input: Parameters<typeof applyOrganizationReadModelPageAt>[0]): Promise<OrganizationDirectoryAndGroups | null | undefined>;
|
|
66
|
+
export {};
|