@tearleads/client-sdk 0.1.47 → 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/organizations/currentPrincipalMutations.js +36 -17
- package/client/organizations/currentPrincipalMutations.js.map +1 -1
- package/client/organizations/principalContainerMutations.js +1 -0
- package/client/organizations/principalContainerMutations.js.map +1 -1
- package/client/organizations/principalMutations.js +2 -2
- package/client/organizations/principalMutations.js.map +1 -1
- package/data/persistence/documents/internal/documentRows.js +37 -41
- package/data/persistence/documents/internal/documentRows.js.map +1 -1
- package/data/persistence/principalHistoryEvidencePersistence.js +17 -18
- package/data/persistence/principalHistoryEvidencePersistence.js.map +1 -1
- package/data/persistence/principalHistoryNodeRetention.js +164 -39
- package/data/persistence/principalHistoryNodeRetention.js.map +1 -1
- package/data/persistence/principalPolicyReferenceIndexPersistence.js +101 -38
- package/data/persistence/principalPolicyReferenceIndexPersistence.js.map +1 -1
- package/data/principals/principalMutationJournalShape.js +6 -0
- package/data/principals/principalMutationJournalShape.js.map +1 -1
- package/data/sqlite/sqliteUpsert.js +9 -0
- package/data/sqlite/sqliteUpsert.js.map +1 -0
- package/internal/api-client/ApiClient.d.ts +122 -0
- package/internal/api-client/principalPolicyRequests.d.ts +122 -0
- package/internal/validators/operation/principals.d.ts +1026 -206
- package/internal/validators/request/principal.d.ts +332 -0
- package/internal/validators/request/principal.js +1 -0
- package/internal/validators/request/principal.js.map +1 -1
- package/internal/validators/response/principal.d.ts +488 -0
- package/internal/validators/response/principal.js +1 -0
- package/internal/validators/response/principal.js.map +1 -1
- package/package.json +1 -1
- package/workflows/containers/child/rekeyProjection.d.ts +6 -1
- package/workflows/containers/child/rekeyProjection.js +41 -0
- package/workflows/containers/child/rekeyProjection.js.map +1 -1
- package/workflows/organizations/authoredPrincipalPolicyWarmer.js +25 -0
- package/workflows/organizations/authoredPrincipalPolicyWarmer.js.map +1 -0
- package/workflows/organizations/commitCurrentGroupPolicyMutation.js +101 -34
- package/workflows/organizations/commitCurrentGroupPolicyMutation.js.map +1 -1
- package/workflows/organizations/groupPolicyMutationContext.d.ts +5 -52
- package/workflows/organizations/groupPolicyMutationContext.js +2 -65
- package/workflows/organizations/groupPolicyMutationContext.js.map +1 -1
- package/workflows/organizations/precedingPrincipalRematerialization.js +31 -0
- package/workflows/organizations/precedingPrincipalRematerialization.js.map +1 -0
- package/workflows/organizations/principalContainerRematerialization.js +39 -7
- package/workflows/organizations/principalContainerRematerialization.js.map +1 -1
- package/workflows/organizations/principalContainerRematerializationPlanning.js +6 -1
- package/workflows/organizations/principalContainerRematerializationPlanning.js.map +1 -1
- package/workflows/organizations/principalContainerRematerializationTargets.js +0 -11
- package/workflows/organizations/principalContainerRematerializationTargets.js.map +1 -1
- package/workflows/organizations/principalMutationReceipt.js +6 -0
- package/workflows/organizations/principalMutationReceipt.js.map +1 -1
- package/workflows/organizations/principalPolicyApi.d.ts +33 -0
- package/workflows/organizations/principalPolicyApi.js +2 -0
- package/workflows/organizations/principalPolicyApi.js.map +1 -0
- package/workflows/organizations/runtimeCurrentGroupMutation.js +36 -19
- package/workflows/organizations/runtimeCurrentGroupMutation.js.map +1 -1
- package/workflows/organizations/submitGroupPolicyCommit.d.ts +22 -0
- package/workflows/organizations/submitGroupPolicyCommit.js +71 -0
- package/workflows/organizations/submitGroupPolicyCommit.js.map +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ContainerMutationRequest, PutPrincipalPolicyRequest } from "../../internal/validators/request/index.js";
|
|
2
|
+
import { type CommitOrganizationGroupPolicyResponse } from "../../internal/validators/response/index.js";
|
|
3
|
+
import type { PrincipalPolicyReadWriteApi } from "./principalPolicyApi.js";
|
|
4
|
+
/**
|
|
5
|
+
* Commit, answering one refusal: a rematerialized rekey or revoke that would
|
|
6
|
+
* strand a level above a directly granted container is refused with the
|
|
7
|
+
* descendant rekeys it must carry. The refused attempt rolled back whole, so
|
|
8
|
+
* the served heads still stand; the batch is signed again with the named
|
|
9
|
+
* levels woven in, replaces the container mutations, and the commit is retried
|
|
10
|
+
* once. A second refusal means the tree moved underneath, and the caller's own
|
|
11
|
+
* retry starts from a fresh policy.
|
|
12
|
+
*/
|
|
13
|
+
export declare function submitGroupPolicyCommit(input: {
|
|
14
|
+
readonly apiClient: PrincipalPolicyReadWriteApi;
|
|
15
|
+
readonly carryDescendantRekeys?: ((requiredContainerIds: readonly string[]) => Promise<readonly ContainerMutationRequest[]>) | undefined;
|
|
16
|
+
readonly groupId: string;
|
|
17
|
+
readonly organizationId: string;
|
|
18
|
+
readonly organizationRequest: PutPrincipalPolicyRequest;
|
|
19
|
+
readonly memberRequest?: PutPrincipalPolicyRequest | undefined;
|
|
20
|
+
readonly request: PutPrincipalPolicyRequest;
|
|
21
|
+
readonly stillCurrent?: (() => boolean) | undefined;
|
|
22
|
+
}): Promise<CommitOrganizationGroupPolicyResponse | null>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CONTAINER_MUTATION_ERROR_CODES, } from "../../internal/validators/response/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Commit, answering one refusal: a rematerialized rekey or revoke that would
|
|
4
|
+
* strand a level above a directly granted container is refused with the
|
|
5
|
+
* descendant rekeys it must carry. The refused attempt rolled back whole, so
|
|
6
|
+
* the served heads still stand; the batch is signed again with the named
|
|
7
|
+
* levels woven in, replaces the container mutations, and the commit is retried
|
|
8
|
+
* once. A second refusal means the tree moved underneath, and the caller's own
|
|
9
|
+
* retry starts from a fresh policy.
|
|
10
|
+
*/
|
|
11
|
+
export async function submitGroupPolicyCommit(input) {
|
|
12
|
+
const body = () => ({
|
|
13
|
+
groupPolicy: input.request,
|
|
14
|
+
...(input.memberRequest ? { memberPolicy: input.memberRequest } : {}),
|
|
15
|
+
organizationPolicy: input.organizationRequest,
|
|
16
|
+
});
|
|
17
|
+
const { commitOrganizationGroupPolicyResult } = input.apiClient;
|
|
18
|
+
if (!commitOrganizationGroupPolicyResult) {
|
|
19
|
+
return input.apiClient.commitOrganizationGroupPolicy(input.organizationId, input.groupId, body());
|
|
20
|
+
}
|
|
21
|
+
const first = await commitOrganizationGroupPolicyResult.call(input.apiClient, input.organizationId, input.groupId, body(), { reportErrors: false });
|
|
22
|
+
if (first.ok)
|
|
23
|
+
return first.data;
|
|
24
|
+
if (first.kind === "cancelled")
|
|
25
|
+
return null;
|
|
26
|
+
if (first.kind === "outcome-unknown")
|
|
27
|
+
throw new Error(first.message ??
|
|
28
|
+
"Policy request may have committed; refresh before retrying");
|
|
29
|
+
if (input.memberRequest &&
|
|
30
|
+
first.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired) {
|
|
31
|
+
throw new Error("Repair the affected container keys before retrying enrollment; no memberships were changed");
|
|
32
|
+
}
|
|
33
|
+
if (!input.carryDescendantRekeys ||
|
|
34
|
+
first.code !== CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired ||
|
|
35
|
+
!first.requiredContainerIds?.length) {
|
|
36
|
+
first.report?.();
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
let carried;
|
|
40
|
+
try {
|
|
41
|
+
carried = await input.carryDescendantRekeys(first.requiredContainerIds);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// The refusal was answerable, and the answer failed: surface both. Once
|
|
45
|
+
// the generation that owned the attempt is gone, only the failure is
|
|
46
|
+
// surfaced; a superseded refusal is not an error.
|
|
47
|
+
if (input.stillCurrent?.() !== false)
|
|
48
|
+
first.report?.();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
if (input.stillCurrent?.() === false)
|
|
52
|
+
return null;
|
|
53
|
+
// Nothing signed means the same refusal again; report the one already had.
|
|
54
|
+
if (carried.length === 0) {
|
|
55
|
+
first.report?.();
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
input.request.containerMutations = [...carried];
|
|
59
|
+
const second = await commitOrganizationGroupPolicyResult.call(input.apiClient, input.organizationId, input.groupId, body(), { reportErrors: false });
|
|
60
|
+
if (!second.ok) {
|
|
61
|
+
if (second.kind === "cancelled")
|
|
62
|
+
return null;
|
|
63
|
+
if (second.kind === "outcome-unknown")
|
|
64
|
+
throw new Error(second.message ??
|
|
65
|
+
"Policy request may have committed; refresh before retrying");
|
|
66
|
+
second.report?.();
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return second.data;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=submitGroupPolicyCommit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submitGroupPolicyCommit.js","sourceRoot":"","sources":["submitGroupPolicyCommit.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,8BAA8B,GAE/B,MAAM,gCAAgC,CAAC;AAGxC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAa7C;IACC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;QAClB,WAAW,EAAE,KAAK,CAAC,OAAO;QAC1B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,kBAAkB,EAAE,KAAK,CAAC,mBAAmB;KAC9C,CAAC,CAAC;IACH,MAAM,EAAE,mCAAmC,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IAChE,IAAI,CAAC,mCAAmC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,SAAS,CAAC,6BAA6B,CAClD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,CACP,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,mCAAmC,CAAC,IAAI,CAC1D,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,EACN,EAAE,YAAY,EAAE,KAAK,EAAE,CACxB,CA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,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,mCAAmC,CAAC,IAAI,CAC3D,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,EACN,EAAE,YAAY,EAAE,KAAK,EAAE,CACxB,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB;YACnC,MAAM,IAAI,KAAK,CACb,MAAM,CAAC,OAAO;gBACZ,4DAA4D,CAC/D,CAAC;QACJ,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type {\n ContainerMutationRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport {\n CONTAINER_MUTATION_ERROR_CODES,\n type CommitOrganizationGroupPolicyResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyReadWriteApi } from \"./principalPolicyApi\";\n\n/**\n * Commit, answering one refusal: a rematerialized rekey or revoke that would\n * strand a level above a directly granted container is refused with the\n * descendant rekeys it must carry. The refused attempt rolled back whole, so\n * the served heads still stand; the batch is signed again with the named\n * levels woven in, replaces the container mutations, and the commit is retried\n * once. A second refusal means the tree moved underneath, and the caller's own\n * retry starts from a fresh policy.\n */\nexport async function submitGroupPolicyCommit(input: {\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly carryDescendantRekeys?:\n | ((\n requiredContainerIds: readonly string[],\n ) => Promise<readonly ContainerMutationRequest[]>)\n | undefined;\n readonly groupId: string;\n readonly organizationId: string;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly memberRequest?: PutPrincipalPolicyRequest | undefined;\n readonly request: PutPrincipalPolicyRequest;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<CommitOrganizationGroupPolicyResponse | null> {\n const body = () => ({\n groupPolicy: input.request,\n ...(input.memberRequest ? { memberPolicy: input.memberRequest } : {}),\n organizationPolicy: input.organizationRequest,\n });\n const { commitOrganizationGroupPolicyResult } = input.apiClient;\n if (!commitOrganizationGroupPolicyResult) {\n return input.apiClient.commitOrganizationGroupPolicy(\n input.organizationId,\n input.groupId,\n body(),\n );\n }\n const first = await commitOrganizationGroupPolicyResult.call(\n input.apiClient,\n input.organizationId,\n input.groupId,\n body(),\n { reportErrors: false },\n );\n if (first.ok) return first.data;\n if (first.kind === \"cancelled\") return null;\n if (first.kind === \"outcome-unknown\")\n throw new Error(\n first.message ??\n \"Policy request may have committed; refresh before retrying\",\n );\n if (\n input.memberRequest &&\n first.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired\n ) {\n throw new Error(\n \"Repair the affected container keys before retrying enrollment; no memberships were changed\",\n );\n }\n if (\n !input.carryDescendantRekeys ||\n first.code !== CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired ||\n !first.requiredContainerIds?.length\n ) {\n first.report?.();\n return null;\n }\n let carried: readonly ContainerMutationRequest[];\n try {\n carried = await input.carryDescendantRekeys(first.requiredContainerIds);\n } catch (error) {\n // The refusal was answerable, and the answer failed: surface both. Once\n // the generation that owned the attempt is gone, only the failure is\n // surfaced; a superseded refusal is not an error.\n if (input.stillCurrent?.() !== false) first.report?.();\n throw error;\n }\n if (input.stillCurrent?.() === false) return null;\n // Nothing signed means the same refusal again; report the one already had.\n if (carried.length === 0) {\n first.report?.();\n return null;\n }\n input.request.containerMutations = [...carried];\n const second = await commitOrganizationGroupPolicyResult.call(\n input.apiClient,\n input.organizationId,\n input.groupId,\n body(),\n { reportErrors: false },\n );\n if (!second.ok) {\n if (second.kind === \"cancelled\") return null;\n if (second.kind === \"outcome-unknown\")\n throw new Error(\n second.message ??\n \"Policy request may have committed; refresh before retrying\",\n );\n second.report?.();\n return null;\n }\n return second.data;\n}\n"]}
|