@powerhousedao/shared 6.2.2-dev.8 → 6.2.2-dev.80
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/dist/clis/args/access-token--9H57y8J.d.mts +18 -0
- package/dist/clis/args/access-token--9H57y8J.d.mts.map +1 -0
- package/dist/clis/args/access-token-To5LaIfL.mjs +22 -0
- package/dist/clis/args/access-token-To5LaIfL.mjs.map +1 -0
- package/dist/clis/args/access-token.d.mts +2 -18
- package/dist/clis/args/access-token.mjs +1 -21
- package/dist/clis/args/{common-dbsvksvf.mjs → common-CcYbXrBx.mjs} +7 -2
- package/dist/clis/args/common-CcYbXrBx.mjs.map +1 -0
- package/dist/clis/args/{common-DfMf08ur.d.mts → common-zPBoTNJF.d.mts} +7 -4
- package/dist/clis/args/{common-DfMf08ur.d.mts.map → common-zPBoTNJF.d.mts.map} +1 -1
- package/dist/clis/args/common.d.mts +2 -2
- package/dist/clis/args/common.mjs +2 -2
- package/dist/clis/args/connect-BVVvCmL9.mjs +198 -0
- package/dist/clis/args/connect-BVVvCmL9.mjs.map +1 -0
- package/dist/clis/args/connect-BtU0MTTc.d.mts +443 -0
- package/dist/clis/args/connect-BtU0MTTc.d.mts.map +1 -0
- package/dist/clis/args/connect.d.mts +2 -434
- package/dist/clis/args/connect.mjs +1 -196
- package/dist/clis/args/{generate-Cs5okckF.mjs → generate-CA916Fvj.mjs} +2 -2
- package/dist/clis/args/{generate-Cs5okckF.mjs.map → generate-CA916Fvj.mjs.map} +1 -1
- package/dist/clis/args/generate-DnV-bfXt.d.mts +87 -0
- package/dist/clis/args/generate-DnV-bfXt.d.mts.map +1 -0
- package/dist/clis/args/generate.d.mts +2 -87
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-BkF9Cxud.mjs → help-Bqbgbalu.mjs} +15 -15
- package/dist/clis/args/{help-BkF9Cxud.mjs.map → help-Bqbgbalu.mjs.map} +1 -1
- package/dist/clis/args/{help-CYjFrzIJ.d.mts → help-CjAsudUn.d.mts} +1 -1
- package/dist/clis/args/{help-CYjFrzIJ.d.mts.map → help-CjAsudUn.d.mts.map} +1 -1
- package/dist/clis/args/help.d.mts +1 -1
- package/dist/clis/args/help.mjs +1 -13
- package/dist/clis/args/index.d.mts +19 -19
- package/dist/clis/args/index.mjs +19 -19
- package/dist/clis/args/init-CUXyfquF.d.mts +55 -0
- package/dist/clis/args/init-CUXyfquF.d.mts.map +1 -0
- package/dist/clis/args/init-rz9Ei7nq.mjs +67 -0
- package/dist/clis/args/init-rz9Ei7nq.mjs.map +1 -0
- package/dist/clis/args/init.d.mts +2 -55
- package/dist/clis/args/init.mjs +1 -66
- package/dist/clis/args/inspect-DtZeoA5c.d.mts +15 -0
- package/dist/clis/args/inspect-DtZeoA5c.d.mts.map +1 -0
- package/dist/clis/args/inspect-tckH8mSw.mjs +15 -0
- package/dist/clis/args/inspect-tckH8mSw.mjs.map +1 -0
- package/dist/clis/args/inspect.d.mts +2 -15
- package/dist/clis/args/inspect.mjs +1 -14
- package/dist/clis/args/install-CkP8zcHb.d.mts +40 -0
- package/dist/clis/args/install-CkP8zcHb.d.mts.map +1 -0
- package/dist/clis/args/install-Sz2DlCHh.mjs +32 -0
- package/dist/clis/args/install-Sz2DlCHh.mjs.map +1 -0
- package/dist/clis/args/install.d.mts +2 -40
- package/dist/clis/args/install.mjs +1 -31
- package/dist/clis/args/list-BGf8s_gj.d.mts +12 -0
- package/dist/clis/args/list-BGf8s_gj.d.mts.map +1 -0
- package/dist/clis/args/list-DM2d6f1m.mjs +7 -0
- package/dist/clis/args/list-DM2d6f1m.mjs.map +1 -0
- package/dist/clis/args/list.d.mts +2 -12
- package/dist/clis/args/list.mjs +1 -6
- package/dist/clis/args/login-DNsHwvqk.d.mts +27 -0
- package/dist/clis/args/login-DNsHwvqk.d.mts.map +1 -0
- package/dist/clis/args/login-DiKT5Jfu.mjs +40 -0
- package/dist/clis/args/login-DiKT5Jfu.mjs.map +1 -0
- package/dist/clis/args/login.d.mts +2 -27
- package/dist/clis/args/login.mjs +1 -39
- package/dist/clis/args/magic-string.es-h_0HDQBQ.mjs +1013 -0
- package/dist/clis/args/magic-string.es-h_0HDQBQ.mjs.map +1 -0
- package/dist/clis/args/migrate-CG_gWc4k.mjs +29 -0
- package/dist/clis/args/migrate-CG_gWc4k.mjs.map +1 -0
- package/dist/clis/args/migrate-sixkWhxm.d.mts +21 -0
- package/dist/clis/args/migrate-sixkWhxm.d.mts.map +1 -0
- package/dist/clis/args/migrate.d.mts +2 -21
- package/dist/clis/args/migrate.mjs +1 -28
- package/dist/clis/args/publish-DDZYsUfV.mjs +19 -0
- package/dist/clis/args/publish-DDZYsUfV.mjs.map +1 -0
- package/dist/clis/args/publish-Dqe5DUst.d.mts +18 -0
- package/dist/clis/args/publish-Dqe5DUst.d.mts.map +1 -0
- package/dist/clis/args/publish.d.mts +2 -18
- package/dist/clis/args/publish.mjs +1 -18
- package/dist/clis/args/registry-C_OVFQmI.mjs +23 -0
- package/dist/clis/args/registry-C_OVFQmI.mjs.map +1 -0
- package/dist/clis/args/registry-C_RfTsKB.d.mts +19 -0
- package/dist/clis/args/registry-C_RfTsKB.d.mts.map +1 -0
- package/dist/clis/args/registry.d.mts +2 -19
- package/dist/clis/args/registry.mjs +1 -22
- package/dist/clis/args/service-CHOOr0Gg.mjs +11 -0
- package/dist/clis/args/service-CHOOr0Gg.mjs.map +1 -0
- package/dist/clis/args/{service-C88bN_g_.d.mts → service-DhIkf8-O.d.mts} +1 -1
- package/dist/clis/args/{service-C88bN_g_.d.mts.map → service-DhIkf8-O.d.mts.map} +1 -1
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +1 -10
- package/dist/clis/args/switchboard-BlPaq2at.d.mts +72 -0
- package/dist/clis/args/switchboard-BlPaq2at.d.mts.map +1 -0
- package/dist/clis/args/switchboard-Dsp7nosi.mjs +85 -0
- package/dist/clis/args/switchboard-Dsp7nosi.mjs.map +1 -0
- package/dist/clis/args/switchboard.d.mts +2 -72
- package/dist/clis/args/switchboard.mjs +1 -84
- package/dist/clis/args/uninstall-BpA3YYbw.d.mts +31 -0
- package/dist/clis/args/uninstall-BpA3YYbw.d.mts.map +1 -0
- package/dist/clis/args/uninstall-CTwTX0u_.mjs +16 -0
- package/dist/clis/args/uninstall-CTwTX0u_.mjs.map +1 -0
- package/dist/clis/args/uninstall.d.mts +2 -31
- package/dist/clis/args/uninstall.mjs +1 -15
- package/dist/clis/args/unpublish-BPMkGEg5.mjs +30 -0
- package/dist/clis/args/unpublish-BPMkGEg5.mjs.map +1 -0
- package/dist/clis/args/unpublish-CvwaIimG.d.mts +24 -0
- package/dist/clis/args/unpublish-CvwaIimG.d.mts.map +1 -0
- package/dist/clis/args/unpublish.d.mts +2 -24
- package/dist/clis/args/unpublish.mjs +1 -29
- package/dist/clis/args/vetra-CoMvTJK7.d.mts +113 -0
- package/dist/clis/args/vetra-CoMvTJK7.d.mts.map +1 -0
- package/dist/clis/args/vetra-b4KUu1Ax.mjs +126 -0
- package/dist/clis/args/vetra-b4KUu1Ax.mjs.map +1 -0
- package/dist/clis/args/vetra-ports.test.d.mts +1 -0
- package/dist/clis/args/vetra-ports.test.mjs +13249 -0
- package/dist/clis/args/vetra-ports.test.mjs.map +1 -0
- package/dist/clis/args/vetra.d.mts +2 -102
- package/dist/clis/args/vetra.mjs +2 -75
- package/dist/clis/build-config.d.mts +1 -1
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/constants.d.mts +189 -53
- package/dist/clis/constants.d.mts.map +1 -1
- package/dist/clis/constants.mjs +11 -3
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index.d.mts +543 -16
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +389 -14
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/project-env.d.mts +27 -0
- package/dist/clis/project-env.d.mts.map +1 -0
- package/dist/clis/project-env.mjs +44 -0
- package/dist/clis/project-env.mjs.map +1 -0
- package/dist/clis/project-ports.d.mts +40 -0
- package/dist/clis/project-ports.d.mts.map +1 -0
- package/dist/clis/project-ports.mjs +90 -0
- package/dist/clis/project-ports.mjs.map +1 -0
- package/dist/{config-loader-19K8n4DO.js → config-loader-B845Hidf.js} +11 -14
- package/dist/config-loader-B845Hidf.js.map +1 -0
- package/dist/connect/config-loader.d.ts +2 -1
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/config-loader.js +1 -1
- package/dist/connect/index.d.ts +447 -14
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +508 -2
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/json-adapter.d.ts.map +1 -1
- package/dist/{constants-C_EQX4DY.d.ts → constants-BP_gjn8g.d.ts} +1 -1
- package/dist/constants-BP_gjn8g.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-model/index.d.ts +4 -5
- package/dist/document-model/index.js +1304 -133
- package/dist/document-model/index.js.map +1 -1
- package/dist/document-model/mock.d.ts +22 -2
- package/dist/document-model/mock.d.ts.map +1 -0
- package/dist/document-model/mock.js +32 -3
- package/dist/document-model/mock.js.map +1 -1
- package/dist/document-model/utils.d.ts +1 -2
- package/dist/document-model/utils.js +1 -2
- package/dist/{index-CQDIrK1k.d.ts → index-C_iVZe7f.d.ts} +1 -1
- package/dist/index-C_iVZe7f.d.ts.map +1 -0
- package/dist/index-h-fhfCG7.d.ts +814 -0
- package/dist/index-h-fhfCG7.d.ts.map +1 -0
- package/dist/index.d.ts +5 -6
- package/dist/processors/index.d.ts +2 -2
- package/dist/registry/index.d.ts +5 -4
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +9 -8
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +1 -1
- package/dist/registry/urls.d.ts +11 -0
- package/dist/registry/urls.d.ts.map +1 -0
- package/dist/registry/urls.js +15 -0
- package/dist/registry/urls.js.map +1 -0
- package/dist/{types-DvWPqxJr.d.ts → types-ByzmqLEu.d.ts} +29 -3
- package/dist/{types-DvWPqxJr.d.ts.map → types-ByzmqLEu.d.ts.map} +1 -1
- package/dist/{types-DXsYu6Tq.d.ts → types-DBj2HxyL.d.ts} +499 -16
- package/dist/types-DBj2HxyL.d.ts.map +1 -0
- package/dist/utils-DP122OSS.d.ts +18 -0
- package/dist/utils-DP122OSS.d.ts.map +1 -0
- package/dist/{utils-DKOFCM0Q.js → utils-aaTmfxFW.js} +45 -2
- package/dist/utils-aaTmfxFW.js.map +1 -0
- package/package.json +12 -1
- package/dist/clis/args/access-token.d.mts.map +0 -1
- package/dist/clis/args/access-token.mjs.map +0 -1
- package/dist/clis/args/common-dbsvksvf.mjs.map +0 -1
- package/dist/clis/args/connect.d.mts.map +0 -1
- package/dist/clis/args/connect.mjs.map +0 -1
- package/dist/clis/args/generate.d.mts.map +0 -1
- package/dist/clis/args/init.d.mts.map +0 -1
- package/dist/clis/args/init.mjs.map +0 -1
- package/dist/clis/args/inspect.d.mts.map +0 -1
- package/dist/clis/args/inspect.mjs.map +0 -1
- package/dist/clis/args/install.d.mts.map +0 -1
- package/dist/clis/args/install.mjs.map +0 -1
- package/dist/clis/args/list.d.mts.map +0 -1
- package/dist/clis/args/list.mjs.map +0 -1
- package/dist/clis/args/login.d.mts.map +0 -1
- package/dist/clis/args/login.mjs.map +0 -1
- package/dist/clis/args/migrate.d.mts.map +0 -1
- package/dist/clis/args/migrate.mjs.map +0 -1
- package/dist/clis/args/publish.d.mts.map +0 -1
- package/dist/clis/args/publish.mjs.map +0 -1
- package/dist/clis/args/registry.d.mts.map +0 -1
- package/dist/clis/args/registry.mjs.map +0 -1
- package/dist/clis/args/service.mjs.map +0 -1
- package/dist/clis/args/switchboard.d.mts.map +0 -1
- package/dist/clis/args/switchboard.mjs.map +0 -1
- package/dist/clis/args/uninstall.d.mts.map +0 -1
- package/dist/clis/args/uninstall.mjs.map +0 -1
- package/dist/clis/args/unpublish.d.mts.map +0 -1
- package/dist/clis/args/unpublish.mjs.map +0 -1
- package/dist/clis/args/vetra.d.mts.map +0 -1
- package/dist/clis/args/vetra.mjs.map +0 -1
- package/dist/config-loader-19K8n4DO.js.map +0 -1
- package/dist/constants-C_EQX4DY.d.ts.map +0 -1
- package/dist/index-CQDIrK1k.d.ts.map +0 -1
- package/dist/index-Dz7JrBXs.d.ts +0 -399
- package/dist/index-Dz7JrBXs.d.ts.map +0 -1
- package/dist/mock-CBcf78ra.d.ts +0 -7
- package/dist/mock-CBcf78ra.d.ts.map +0 -1
- package/dist/types-D0NNBVGA.d.ts +0 -167
- package/dist/types-D0NNBVGA.d.ts.map +0 -1
- package/dist/types-DXsYu6Tq.d.ts.map +0 -1
- package/dist/utils-BEByNOHo.d.ts +0 -9
- package/dist/utils-BEByNOHo.d.ts.map +0 -1
- package/dist/utils-DKOFCM0Q.js.map +0 -1
|
@@ -1,10 +1,110 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { generateMock } from "./mock.js";
|
|
1
|
+
import { a as base58Decode, c as buildOperationSignatureParams, d as hex2ab, i as ab2hex, l as getUnixTimestamp, n as generateId, o as base64UrlToBytes, r as generateMock, s as buildOperationSignatureMessage, t as deriveOperationId, u as hashBrowser } from "../utils-aaTmfxFW.js";
|
|
3
2
|
import { ZodError, z } from "zod";
|
|
4
3
|
import { stringify } from "safe-stable-stringify";
|
|
5
4
|
import { strFromU8, strToU8, unzip, zip } from "fflate";
|
|
6
5
|
import { castDraft, create, unsafe } from "mutative";
|
|
7
6
|
import { constantCase, pascalCase } from "change-case";
|
|
7
|
+
//#region document-model/signatures.ts
|
|
8
|
+
/**
|
|
9
|
+
* What separates a signature's params when it travels as one string.
|
|
10
|
+
*
|
|
11
|
+
* GraphQL declares `signatures` as a list of strings, not a list of lists, so a
|
|
12
|
+
* tuple is joined for transport and split on arrival. The separator is here so
|
|
13
|
+
* the two halves cannot disagree about it - they live in different packages, and
|
|
14
|
+
* a mismatch would corrupt every signature that crossed the wire rather than
|
|
15
|
+
* failing outright.
|
|
16
|
+
*/
|
|
17
|
+
const SIGNATURE_PARAM_SEPARATOR = ", ";
|
|
18
|
+
/** The number of params a signature carries. */
|
|
19
|
+
const SIGNATURE_PARAM_COUNT = 5;
|
|
20
|
+
/** Joins a signature's params for transport. Already-joined input passes through. */
|
|
21
|
+
function serializeSignature(signature) {
|
|
22
|
+
return Array.isArray(signature) ? signature.join(SIGNATURE_PARAM_SEPARATOR) : signature;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Splits a transported signature back into its params. A tuple passes through.
|
|
26
|
+
*
|
|
27
|
+
* Short input is padded rather than refused: verification reads the params by
|
|
28
|
+
* position and fails on a wrong one, which says more than a length complaint
|
|
29
|
+
* raised here would.
|
|
30
|
+
*/
|
|
31
|
+
function deserializeSignature(signature) {
|
|
32
|
+
if (Array.isArray(signature)) return signature;
|
|
33
|
+
const parts = signature.split(SIGNATURE_PARAM_SEPARATOR);
|
|
34
|
+
return Array.from({ length: SIGNATURE_PARAM_COUNT }, (_unused, index) => parts[index] ?? "");
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region document-model/action-transport.ts
|
|
38
|
+
/**
|
|
39
|
+
* Projects an action onto the fields the GraphQL `ActionInput` declares.
|
|
40
|
+
*
|
|
41
|
+
* A projection rather than a spread, because an input object rejects a field it
|
|
42
|
+
* does not declare, and that refusal takes the whole request with it. An action
|
|
43
|
+
* read back out of storage can carry fields the type no longer has - a legacy
|
|
44
|
+
* `attachments` array, or the operation fields left behind by a signing helper
|
|
45
|
+
* that returns an operation - and any one of them would sink an otherwise valid
|
|
46
|
+
* submission.
|
|
47
|
+
*
|
|
48
|
+
* Only fields the action actually carries are emitted, so an unsigned action
|
|
49
|
+
* sends no context at all rather than a context full of nulls.
|
|
50
|
+
*/
|
|
51
|
+
function toTransportAction(action) {
|
|
52
|
+
if (action.input === void 0 || action.input === null) throw new Error(`Action ${action.id} (${action.type}) has no input, which the wire requires`);
|
|
53
|
+
const projected = {
|
|
54
|
+
id: action.id,
|
|
55
|
+
type: action.type,
|
|
56
|
+
timestampUtcMs: action.timestampUtcMs,
|
|
57
|
+
input: action.input,
|
|
58
|
+
scope: action.scope
|
|
59
|
+
};
|
|
60
|
+
const context = toTransportContext(action.context);
|
|
61
|
+
return context ? {
|
|
62
|
+
...projected,
|
|
63
|
+
context
|
|
64
|
+
} : projected;
|
|
65
|
+
}
|
|
66
|
+
function toTransportContext(context) {
|
|
67
|
+
if (!context) return;
|
|
68
|
+
const projected = {};
|
|
69
|
+
if (context.prevOpIndex !== void 0) projected.prevOpIndex = context.prevOpIndex;
|
|
70
|
+
if (context.prevOpHash !== void 0) projected.prevOpHash = context.prevOpHash;
|
|
71
|
+
if (context.nonce !== void 0) projected.nonce = context.nonce;
|
|
72
|
+
const signer = context.signer;
|
|
73
|
+
if (signer) projected.signer = {
|
|
74
|
+
...signer.user ? { user: toTransportSignerUser(signer.user) } : {},
|
|
75
|
+
...signer.app ? { app: toTransportSignerApp(signer.app) } : {},
|
|
76
|
+
signatures: (signer.signatures ?? []).map(serializeSignature)
|
|
77
|
+
};
|
|
78
|
+
return Object.keys(projected).length > 0 ? projected : void 0;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The identity, projected for the same reason the context around it is.
|
|
82
|
+
*
|
|
83
|
+
* A signer is handed in by the app, so what reaches here is only as narrow as
|
|
84
|
+
* whoever built it: an identity carrying a session's DID, credential or profile
|
|
85
|
+
* alongside the address is refused by `ReactorSignerUserInput`, and that
|
|
86
|
+
* refusal takes the whole submission with it.
|
|
87
|
+
*
|
|
88
|
+
* The compiler cannot stand in for this. `UserActionSigner` already declares
|
|
89
|
+
* exactly these three fields, but excess-property checks apply to fresh object
|
|
90
|
+
* literals and never to a variable of a wider type, so a wide identity assigned
|
|
91
|
+
* to the narrow type passes untouched.
|
|
92
|
+
*/
|
|
93
|
+
function toTransportSignerUser(user) {
|
|
94
|
+
return {
|
|
95
|
+
address: user.address,
|
|
96
|
+
networkId: user.networkId,
|
|
97
|
+
chainId: user.chainId
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** The signing app, projected on the same rule as the identity above. */
|
|
101
|
+
function toTransportSignerApp(app) {
|
|
102
|
+
return {
|
|
103
|
+
name: app.name,
|
|
104
|
+
key: app.key
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
8
108
|
//#region document-model/errors.ts
|
|
9
109
|
const FileSystemError = /* @__PURE__ */ new Error("File system not available.");
|
|
10
110
|
var InvalidActionInputError = class extends Error {
|
|
@@ -39,6 +139,75 @@ var DowngradeNotSupportedError = class extends Error {
|
|
|
39
139
|
this.toVersion = toVersion;
|
|
40
140
|
}
|
|
41
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Thrown when INITIALIZE_AUTH is applied to an already-initialized auth scope.
|
|
144
|
+
* The genesis action is valid only at auth revision zero.
|
|
145
|
+
*/
|
|
146
|
+
var AuthAlreadyInitializedError = class extends Error {
|
|
147
|
+
documentId;
|
|
148
|
+
constructor(documentId) {
|
|
149
|
+
super(`Auth scope already initialized for document ${documentId}: INITIALIZE_AUTH is valid only at auth revision zero`);
|
|
150
|
+
this.name = "AuthAlreadyInitializedError";
|
|
151
|
+
this.documentId = documentId;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Thrown when INITIALIZE_AUTH is not signed by the document creator (its signer
|
|
156
|
+
* does not match `header.sig.publicKey`), so it cannot set the auth policy.
|
|
157
|
+
*/
|
|
158
|
+
var AuthInitializerNotCreatorError = class extends Error {
|
|
159
|
+
documentId;
|
|
160
|
+
constructor(documentId) {
|
|
161
|
+
super(`INITIALIZE_AUTH for document ${documentId} must be signed by the document creator`);
|
|
162
|
+
this.name = "AuthInitializerNotCreatorError";
|
|
163
|
+
this.documentId = documentId;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Thrown when INITIALIZE_AUTH carries a version below 1. Version 0 is reserved
|
|
168
|
+
* for the uninitialized auth scope.
|
|
169
|
+
*/
|
|
170
|
+
var InvalidAuthVersionError = class extends Error {
|
|
171
|
+
documentId;
|
|
172
|
+
version;
|
|
173
|
+
constructor(documentId, version) {
|
|
174
|
+
super(`Invalid auth policy version ${version} for document ${documentId}: INITIALIZE_AUTH requires an integer version >= 1`);
|
|
175
|
+
this.name = "InvalidAuthVersionError";
|
|
176
|
+
this.documentId = documentId;
|
|
177
|
+
this.version = version;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/** Thrown when a duplicate would lose the source policy's version or creator binding. */
|
|
181
|
+
var AuthPolicyNotPreservedError = class extends Error {
|
|
182
|
+
documentId;
|
|
183
|
+
constructor(documentId) {
|
|
184
|
+
super(`Duplicating document ${documentId} would not preserve its auth policy: the copy loses the policy version or its creator binding`);
|
|
185
|
+
this.name = "AuthPolicyNotPreservedError";
|
|
186
|
+
this.documentId = documentId;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Thrown when a grant referenced by REMOVE_GRANT or MOVE_GRANT does not exist.
|
|
191
|
+
*/
|
|
192
|
+
var GrantNotFoundError = class extends Error {
|
|
193
|
+
grantId;
|
|
194
|
+
constructor(grantId) {
|
|
195
|
+
super(`Grant not found in auth scope: ${grantId}`);
|
|
196
|
+
this.name = "GrantNotFoundError";
|
|
197
|
+
this.grantId = grantId;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Thrown when a disallowed action (UNDO, REDO, PRUNE) targets the auth scope.
|
|
202
|
+
*/
|
|
203
|
+
var AuthActionNotAllowedError = class extends Error {
|
|
204
|
+
actionType;
|
|
205
|
+
constructor(actionType) {
|
|
206
|
+
super(`${actionType} is not permitted on the auth scope`);
|
|
207
|
+
this.name = "AuthActionNotAllowedError";
|
|
208
|
+
this.actionType = actionType;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
42
211
|
var HashMismatchError = class extends Error {
|
|
43
212
|
_scope;
|
|
44
213
|
_document;
|
|
@@ -65,6 +234,25 @@ var HashMismatchError = class extends Error {
|
|
|
65
234
|
return this._operation;
|
|
66
235
|
}
|
|
67
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* Thrown when replay or import requires a document model version that is not
|
|
239
|
+
* registered. Carries the data the UI needs to explain the mismatch.
|
|
240
|
+
*/
|
|
241
|
+
var UnsupportedDocumentModelVersionError = class extends Error {
|
|
242
|
+
documentType;
|
|
243
|
+
requiredVersion;
|
|
244
|
+
availableVersions;
|
|
245
|
+
constructor(documentType, requiredVersion, availableVersions) {
|
|
246
|
+
super(`No reducer registered for document version ${requiredVersion}. Available versions: ${availableVersions.join(", ")}`);
|
|
247
|
+
this.name = "UnsupportedDocumentModelVersionError";
|
|
248
|
+
this.documentType = documentType;
|
|
249
|
+
this.requiredVersion = requiredVersion;
|
|
250
|
+
this.availableVersions = availableVersions;
|
|
251
|
+
}
|
|
252
|
+
static isError(error) {
|
|
253
|
+
return Error.isError(error) && error.name === "UnsupportedDocumentModelVersionError";
|
|
254
|
+
}
|
|
255
|
+
};
|
|
68
256
|
//#endregion
|
|
69
257
|
//#region document-model/schemas.ts
|
|
70
258
|
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
@@ -553,6 +741,89 @@ const ConfigEntrySchema = z.object({
|
|
|
553
741
|
required: z.boolean().optional(),
|
|
554
742
|
default: z.boolean().optional()
|
|
555
743
|
});
|
|
744
|
+
const PwaUrlPatternSchema = z.union([z.string(), z.strictObject({
|
|
745
|
+
source: z.string(),
|
|
746
|
+
flags: z.string().optional()
|
|
747
|
+
}).refine((p) => {
|
|
748
|
+
try {
|
|
749
|
+
new RegExp(p.source, p.flags);
|
|
750
|
+
return true;
|
|
751
|
+
} catch {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
}, { message: "source/flags do not compile to a valid RegExp" })]);
|
|
755
|
+
const PwaRuntimeCachingSchema = z.strictObject({
|
|
756
|
+
urlPattern: PwaUrlPatternSchema,
|
|
757
|
+
handler: z.enum([
|
|
758
|
+
"CacheFirst",
|
|
759
|
+
"CacheOnly",
|
|
760
|
+
"NetworkFirst",
|
|
761
|
+
"NetworkOnly",
|
|
762
|
+
"StaleWhileRevalidate"
|
|
763
|
+
]),
|
|
764
|
+
method: z.enum([
|
|
765
|
+
"GET",
|
|
766
|
+
"POST",
|
|
767
|
+
"PUT",
|
|
768
|
+
"DELETE",
|
|
769
|
+
"HEAD",
|
|
770
|
+
"PATCH"
|
|
771
|
+
]).optional(),
|
|
772
|
+
options: z.strictObject({
|
|
773
|
+
cacheName: z.string().optional(),
|
|
774
|
+
networkTimeoutSeconds: z.number().optional(),
|
|
775
|
+
expiration: z.strictObject({
|
|
776
|
+
maxEntries: z.number().optional(),
|
|
777
|
+
maxAgeSeconds: z.number().optional()
|
|
778
|
+
}).optional(),
|
|
779
|
+
cacheableResponse: z.strictObject({
|
|
780
|
+
statuses: z.array(z.number()).optional(),
|
|
781
|
+
headers: z.record(z.string(), z.string()).optional()
|
|
782
|
+
}).optional()
|
|
783
|
+
}).optional()
|
|
784
|
+
});
|
|
785
|
+
const PwaIconSchema = z.strictObject({
|
|
786
|
+
src: z.string(),
|
|
787
|
+
sizes: z.string().optional(),
|
|
788
|
+
type: z.string().optional(),
|
|
789
|
+
purpose: z.string().optional()
|
|
790
|
+
});
|
|
791
|
+
const PwaFileHandlerSchema = z.strictObject({
|
|
792
|
+
accept: z.record(z.string(), z.array(z.string().regex(/^\./, "file extensions must start with '.'"))),
|
|
793
|
+
icons: z.array(PwaIconSchema).optional(),
|
|
794
|
+
launch_type: z.enum(["single-client", "multiple-clients"]).optional()
|
|
795
|
+
});
|
|
796
|
+
const PwaManifestOverrideSchema = z.strictObject({
|
|
797
|
+
name: z.string().optional(),
|
|
798
|
+
short_name: z.string().optional(),
|
|
799
|
+
description: z.string().optional(),
|
|
800
|
+
theme_color: z.string().optional(),
|
|
801
|
+
background_color: z.string().optional(),
|
|
802
|
+
display: z.enum([
|
|
803
|
+
"fullscreen",
|
|
804
|
+
"standalone",
|
|
805
|
+
"minimal-ui",
|
|
806
|
+
"browser"
|
|
807
|
+
]).optional(),
|
|
808
|
+
start_url: z.string().optional(),
|
|
809
|
+
scope: z.string().optional(),
|
|
810
|
+
icons: z.array(PwaIconSchema).optional(),
|
|
811
|
+
file_handlers: z.array(PwaFileHandlerSchema).optional(),
|
|
812
|
+
launch_handler: z.strictObject({ client_mode: z.enum([
|
|
813
|
+
"auto",
|
|
814
|
+
"focus-existing",
|
|
815
|
+
"navigate-existing",
|
|
816
|
+
"navigate-new"
|
|
817
|
+
]) }).optional()
|
|
818
|
+
});
|
|
819
|
+
const PwaConfigSchema = z.strictObject({
|
|
820
|
+
manifest: PwaManifestOverrideSchema.optional(),
|
|
821
|
+
globPatterns: z.array(z.string()).optional(),
|
|
822
|
+
globIgnores: z.array(z.string()).optional(),
|
|
823
|
+
maximumFileSizeToCacheInBytes: z.number().optional(),
|
|
824
|
+
runtimeCaching: z.array(PwaRuntimeCachingSchema).optional(),
|
|
825
|
+
navigateFallbackDenylist: z.array(PwaUrlPatternSchema).optional()
|
|
826
|
+
});
|
|
556
827
|
const ManifestSchema = z.object({
|
|
557
828
|
name: z.string(),
|
|
558
829
|
description: z.string().optional(),
|
|
@@ -564,7 +835,8 @@ const ManifestSchema = z.object({
|
|
|
564
835
|
editors: PowerhouseModulesSchema,
|
|
565
836
|
processors: PowerhouseModulesSchema,
|
|
566
837
|
subgraphs: PowerhouseModulesSchema,
|
|
567
|
-
config: z.array(ConfigEntrySchema).optional()
|
|
838
|
+
config: z.array(ConfigEntrySchema).optional(),
|
|
839
|
+
pwa: PwaConfigSchema.optional()
|
|
568
840
|
});
|
|
569
841
|
//#endregion
|
|
570
842
|
//#region document-model/actions.ts
|
|
@@ -850,6 +1122,542 @@ const actions = {
|
|
|
850
1122
|
...documentModelActions
|
|
851
1123
|
};
|
|
852
1124
|
//#endregion
|
|
1125
|
+
//#region document-model/document-type.ts
|
|
1126
|
+
const documentModelDocumentType = "powerhouse/document-model";
|
|
1127
|
+
const groupDocumentType = "powerhouse/reactor-group";
|
|
1128
|
+
/**
|
|
1129
|
+
* The group-model action types that change membership. The groups projection
|
|
1130
|
+
* filters its reads to these, so any other group operation is invisible to a
|
|
1131
|
+
* decision. Kept here so the reactor never depends on the group package; a
|
|
1132
|
+
* reactor-group test guards against drift.
|
|
1133
|
+
*/
|
|
1134
|
+
const groupMembershipActionTypes = ["ADD_MEMBER", "REMOVE_MEMBER"];
|
|
1135
|
+
//#endregion
|
|
1136
|
+
//#region document-model/auth-v1.ts
|
|
1137
|
+
/** Maximum number of grants in a policy. */
|
|
1138
|
+
const MAX_AUTH_GRANTS = 100;
|
|
1139
|
+
/** Maximum nesting depth of a condition tree. */
|
|
1140
|
+
const MAX_CONDITION_DEPTH = 10;
|
|
1141
|
+
/** Maximum node count (conditions plus operands) of a condition tree. */
|
|
1142
|
+
const MAX_CONDITION_NODES = 100;
|
|
1143
|
+
/** Maximum entries in an execute capability's operation list. */
|
|
1144
|
+
const MAX_CAPABILITY_OPERATIONS = 100;
|
|
1145
|
+
/**
|
|
1146
|
+
* Thrown when a grant violates the v1 validation rules. The message is stored
|
|
1147
|
+
* on error operations, so it must be a pure function of the input.
|
|
1148
|
+
*/
|
|
1149
|
+
var InvalidGrantError = class extends Error {
|
|
1150
|
+
grantId;
|
|
1151
|
+
constructor(grantId, problem) {
|
|
1152
|
+
super(`Invalid grant "${grantId}": ${problem}`);
|
|
1153
|
+
this.name = "InvalidGrantError";
|
|
1154
|
+
this.grantId = grantId;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
/** Thrown for a `{ group }` principal on a group document: references never chain. */
|
|
1158
|
+
var GroupPrincipalNotAllowedError = class extends Error {
|
|
1159
|
+
grantId;
|
|
1160
|
+
constructor(grantId) {
|
|
1161
|
+
super(`Grant "${grantId}" uses a group principal on a group document: a group's auth scope cannot reference other groups`);
|
|
1162
|
+
this.name = "GroupPrincipalNotAllowedError";
|
|
1163
|
+
this.grantId = grantId;
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
/**
|
|
1167
|
+
* Thrown when a change would leave a creator-less policy with no grant
|
|
1168
|
+
* permitting execute on the auth scope. Without the creator carve-out no
|
|
1169
|
+
* subject could ever administer such a policy again.
|
|
1170
|
+
*/
|
|
1171
|
+
var AuthAdministrationLockoutError = class extends Error {
|
|
1172
|
+
grantId;
|
|
1173
|
+
constructor(grantId) {
|
|
1174
|
+
super(`Change to grant "${grantId}" would leave no reachable grant permitting execute on the auth scope: a policy with no creator must always retain one`);
|
|
1175
|
+
this.name = "AuthAdministrationLockoutError";
|
|
1176
|
+
this.grantId = grantId;
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
/**
|
|
1180
|
+
* Thrown when INITIALIZE_AUTH would create a creator-less policy with no grant
|
|
1181
|
+
* permitting execute on the auth scope. Such a policy would be born with no
|
|
1182
|
+
* subject able to administer it.
|
|
1183
|
+
*/
|
|
1184
|
+
var AuthAdministrationMissingError = class extends Error {
|
|
1185
|
+
constructor() {
|
|
1186
|
+
super("Initial grants include no reachable grant permitting execute on the auth scope: a policy with no creator must always include one");
|
|
1187
|
+
this.name = "AuthAdministrationMissingError";
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
const GRANT_KEYS = new Set([
|
|
1191
|
+
"id",
|
|
1192
|
+
"description",
|
|
1193
|
+
"effect",
|
|
1194
|
+
"principal",
|
|
1195
|
+
"capability",
|
|
1196
|
+
"where"
|
|
1197
|
+
]);
|
|
1198
|
+
const PRINCIPAL_KINDS = new Set([
|
|
1199
|
+
"anyone",
|
|
1200
|
+
"address",
|
|
1201
|
+
"group",
|
|
1202
|
+
"match"
|
|
1203
|
+
]);
|
|
1204
|
+
const COMPARISON_CONDITION_KINDS = new Set([
|
|
1205
|
+
"eq",
|
|
1206
|
+
"ne",
|
|
1207
|
+
"lt",
|
|
1208
|
+
"lte",
|
|
1209
|
+
"gt",
|
|
1210
|
+
"gte"
|
|
1211
|
+
]);
|
|
1212
|
+
function isPlainValue(value) {
|
|
1213
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1214
|
+
}
|
|
1215
|
+
function operandProblem(value, capabilityScope, budget) {
|
|
1216
|
+
budget.nodes -= 1;
|
|
1217
|
+
if (budget.nodes < 0) return `condition exceeds 100 nodes`;
|
|
1218
|
+
if (!isPlainValue(value)) return "operand must be an object";
|
|
1219
|
+
const keys = Object.keys(value);
|
|
1220
|
+
if (keys.length !== 1) return "operand must have exactly one of attr or lit";
|
|
1221
|
+
if (keys[0] === "attr") {
|
|
1222
|
+
const attr = value.attr;
|
|
1223
|
+
if (typeof attr !== "string" || attr.length === 0) return "attr must be a non-empty string";
|
|
1224
|
+
if (capabilityScope !== void 0 && capabilityScope !== "*" && attr.startsWith("doc.")) {
|
|
1225
|
+
const pathScope = attr.split(".")[1] ?? "";
|
|
1226
|
+
if (pathScope !== capabilityScope) return `condition path "${attr}" reads scope "${pathScope}" but the capability covers only scope "${capabilityScope}"`;
|
|
1227
|
+
}
|
|
1228
|
+
return null;
|
|
1229
|
+
}
|
|
1230
|
+
if (keys[0] === "lit") {
|
|
1231
|
+
const lit = value.lit;
|
|
1232
|
+
if (lit !== null && typeof lit !== "string" && typeof lit !== "number" && typeof lit !== "boolean") return "lit must be a string, number, boolean, or null";
|
|
1233
|
+
if (typeof lit === "number" && !Number.isFinite(lit)) return "lit must be a finite number";
|
|
1234
|
+
if (typeof lit === "number" && Object.is(lit, -0)) return "lit must not be negative zero";
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1237
|
+
return `unknown operand kind "${keys[0]}"`;
|
|
1238
|
+
}
|
|
1239
|
+
function conditionProblem(value, capabilityScope, depth, budget) {
|
|
1240
|
+
if (depth > 10) return `condition exceeds depth 10`;
|
|
1241
|
+
budget.nodes -= 1;
|
|
1242
|
+
if (budget.nodes < 0) return `condition exceeds 100 nodes`;
|
|
1243
|
+
if (!isPlainValue(value)) return "condition must be an object";
|
|
1244
|
+
const keys = Object.keys(value);
|
|
1245
|
+
if (keys.length !== 1) return "condition must have exactly one operator";
|
|
1246
|
+
const kind = keys[0];
|
|
1247
|
+
const body = value[kind];
|
|
1248
|
+
if (COMPARISON_CONDITION_KINDS.has(kind)) {
|
|
1249
|
+
if (!Array.isArray(body) || body.length !== 2) return `${kind} requires a pair of operands`;
|
|
1250
|
+
for (const operand of body) {
|
|
1251
|
+
const problem = operandProblem(operand, capabilityScope, budget);
|
|
1252
|
+
if (problem !== null) return problem;
|
|
1253
|
+
}
|
|
1254
|
+
return null;
|
|
1255
|
+
}
|
|
1256
|
+
if (kind === "in" || kind === "notIn") {
|
|
1257
|
+
if (!Array.isArray(body) || body.length !== 2 || !Array.isArray(body[1])) return `${kind} requires an operand and an operand list`;
|
|
1258
|
+
const first = operandProblem(body[0], capabilityScope, budget);
|
|
1259
|
+
if (first !== null) return first;
|
|
1260
|
+
for (const operand of body[1]) {
|
|
1261
|
+
const problem = operandProblem(operand, capabilityScope, budget);
|
|
1262
|
+
if (problem !== null) return problem;
|
|
1263
|
+
}
|
|
1264
|
+
return null;
|
|
1265
|
+
}
|
|
1266
|
+
if (kind === "exists") return operandProblem(body, capabilityScope, budget);
|
|
1267
|
+
if (kind === "and" || kind === "or") {
|
|
1268
|
+
if (!Array.isArray(body)) return `${kind} requires a condition list`;
|
|
1269
|
+
for (const child of body) {
|
|
1270
|
+
const problem = conditionProblem(child, capabilityScope, depth + 1, budget);
|
|
1271
|
+
if (problem !== null) return problem;
|
|
1272
|
+
}
|
|
1273
|
+
return null;
|
|
1274
|
+
}
|
|
1275
|
+
if (kind === "not") return conditionProblem(body, capabilityScope, depth + 1, budget);
|
|
1276
|
+
return `unknown condition operator "${kind}"`;
|
|
1277
|
+
}
|
|
1278
|
+
function principalProblem(value, capabilityScope) {
|
|
1279
|
+
if (!isPlainValue(value)) return "principal must be an object";
|
|
1280
|
+
const keys = Object.keys(value);
|
|
1281
|
+
if (keys.length !== 1 || !PRINCIPAL_KINDS.has(keys[0])) return "principal must have exactly one of anyone, address, group, or match";
|
|
1282
|
+
const kind = keys[0];
|
|
1283
|
+
if (kind === "anyone" && value.anyone !== true) return "anyone must be true";
|
|
1284
|
+
if (kind === "address") {
|
|
1285
|
+
const address = value.address;
|
|
1286
|
+
if (typeof address !== "string" || address.length === 0) return "address must be a non-empty string";
|
|
1287
|
+
}
|
|
1288
|
+
if (kind === "group") {
|
|
1289
|
+
const group = value.group;
|
|
1290
|
+
if (typeof group !== "string" || group.length === 0) return "group must be a non-empty string";
|
|
1291
|
+
}
|
|
1292
|
+
if (kind === "match") return conditionProblem(value.match, capabilityScope, 1, { nodes: 100 });
|
|
1293
|
+
return null;
|
|
1294
|
+
}
|
|
1295
|
+
function capabilityProblem(value) {
|
|
1296
|
+
if (!isPlainValue(value)) return "capability must be an object";
|
|
1297
|
+
const can = value.can;
|
|
1298
|
+
if (can !== "read" && can !== "execute") return "capability.can must be read or execute";
|
|
1299
|
+
const allowedKeys = can === "execute" ? [
|
|
1300
|
+
"can",
|
|
1301
|
+
"scope",
|
|
1302
|
+
"operation"
|
|
1303
|
+
] : ["can", "scope"];
|
|
1304
|
+
const unknownKeys = Object.keys(value).filter((key) => !allowedKeys.includes(key)).sort();
|
|
1305
|
+
if (unknownKeys.length > 0) return `unknown capability key "${unknownKeys[0]}"`;
|
|
1306
|
+
if (value.scope !== void 0) {
|
|
1307
|
+
if (typeof value.scope !== "string" || value.scope.length === 0) return "capability.scope must be a non-empty string";
|
|
1308
|
+
}
|
|
1309
|
+
if (can === "execute" && value.operation !== void 0) {
|
|
1310
|
+
const operation = value.operation;
|
|
1311
|
+
if (!Array.isArray(operation)) return "capability.operation must be an array";
|
|
1312
|
+
if (operation.length > 100) return `capability.operation exceeds 100 entries`;
|
|
1313
|
+
for (const entry of operation) if (typeof entry !== "string" || entry.length === 0) return "capability.operation entries must be non-empty strings";
|
|
1314
|
+
}
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
/** Returns the first v1-rule violation, or null. Pure, total, deterministic. */
|
|
1318
|
+
function grantProblem(value) {
|
|
1319
|
+
if (!isPlainValue(value)) return "grant must be an object";
|
|
1320
|
+
const unknownKeys = Object.keys(value).filter((key) => !GRANT_KEYS.has(key)).sort();
|
|
1321
|
+
if (unknownKeys.length > 0) return `unknown grant key "${unknownKeys[0]}"`;
|
|
1322
|
+
if (typeof value.id !== "string" || value.id.length === 0) return "id must be a non-empty string";
|
|
1323
|
+
if (typeof value.description !== "string") return "description must be a string";
|
|
1324
|
+
if (value.effect !== "allow" && value.effect !== "deny") return "effect must be allow or deny";
|
|
1325
|
+
const capabilityValue = value.capability;
|
|
1326
|
+
const capability = capabilityProblem(capabilityValue);
|
|
1327
|
+
if (capability !== null) return capability;
|
|
1328
|
+
const capabilityScope = capabilityValue.scope;
|
|
1329
|
+
const principal = principalProblem(value.principal, capabilityScope);
|
|
1330
|
+
if (principal !== null) return principal;
|
|
1331
|
+
if (value.where !== void 0) return conditionProblem(value.where, capabilityScope, 1, { nodes: 100 });
|
|
1332
|
+
return null;
|
|
1333
|
+
}
|
|
1334
|
+
const GrantSchema = () => z.custom((value) => grantProblem(value) === null);
|
|
1335
|
+
/** V1 shape rules plus the group-document group-principal ban. */
|
|
1336
|
+
function assertValidGrant(grant, documentType) {
|
|
1337
|
+
const grantId = isPlainValue(grant) && typeof grant.id === "string" ? grant.id : "";
|
|
1338
|
+
const problem = grantProblem(grant);
|
|
1339
|
+
if (problem !== null) throw new InvalidGrantError(grantId, problem);
|
|
1340
|
+
if (documentType === "powerhouse/reactor-group" && "group" in grant.principal) throw new GroupPrincipalNotAllowedError(grantId);
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Validates an initial grant list: the count cap, every grant, and — on a
|
|
1344
|
+
* creator-less policy — that some grant keeps the auth scope administrable.
|
|
1345
|
+
*/
|
|
1346
|
+
function assertValidInitialGrants(grants, documentType, creator) {
|
|
1347
|
+
if (grants.length > 100) throw new InvalidGrantError("", `policy exceeds 100 grants`);
|
|
1348
|
+
for (const grant of grants) assertValidGrant(grant, documentType);
|
|
1349
|
+
if (creator === void 0 && !administrationReachable(grants)) throw new AuthAdministrationMissingError();
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Validates a grant upsert: the grant itself, the count cap on append, and
|
|
1353
|
+
* administration retention. Retention is checked on an append as well as an
|
|
1354
|
+
* in-place replace, because a grant appended after the administration grant can
|
|
1355
|
+
* shadow it (evaluation is last-applicable-grant-wins) and so take
|
|
1356
|
+
* administration away without removing anything.
|
|
1357
|
+
*/
|
|
1358
|
+
function assertValidGrantUpsert(grant, existing, documentType, creator) {
|
|
1359
|
+
assertValidGrant(grant, documentType);
|
|
1360
|
+
const exists = existing.some((g) => g.id === grant.id);
|
|
1361
|
+
if (!exists && existing.length >= 100) throw new InvalidGrantError(grant.id, `policy exceeds 100 grants`);
|
|
1362
|
+
assertAuthAdministrationRetained(creator, existing, exists ? existing.map((g) => g.id === grant.id ? grant : g) : [...existing, grant], grant.id);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* The request whose coverage keeps a policy administrable: a subject who may
|
|
1366
|
+
* SET_GRANT can upsert any grant, so every other repair stays reachable.
|
|
1367
|
+
*/
|
|
1368
|
+
const AUTH_ADMINISTRATION_REQUEST = {
|
|
1369
|
+
verb: "execute",
|
|
1370
|
+
scope: "auth",
|
|
1371
|
+
operation: "SET_GRANT"
|
|
1372
|
+
};
|
|
1373
|
+
/**
|
|
1374
|
+
* Whether some subject can still administer the auth scope under this grant list.
|
|
1375
|
+
*
|
|
1376
|
+
* Asks the evaluator rather than pattern-matching a single grant: evaluation is
|
|
1377
|
+
* last-applicable-grant-wins, so an allow that some later deny shadows keeps
|
|
1378
|
+
* nothing reachable even though it is still present in the list. Only anyone and
|
|
1379
|
+
* address principals are candidates, because those are the ones v1 can match at
|
|
1380
|
+
* all; a `where` condition or a group or match principal never applies.
|
|
1381
|
+
*/
|
|
1382
|
+
function administrationReachable(grants) {
|
|
1383
|
+
return grants.some((grant) => {
|
|
1384
|
+
const subject = administrationCandidate(grant);
|
|
1385
|
+
if (subject === void 0) return false;
|
|
1386
|
+
return evaluateGrantStack(grants, subject, AUTH_ADMINISTRATION_REQUEST).decision === "allow";
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* The subject to test this grant with, or undefined when the grant could never
|
|
1391
|
+
* carry administration for anyone.
|
|
1392
|
+
*/
|
|
1393
|
+
function administrationCandidate(grant) {
|
|
1394
|
+
if (grant.effect !== "allow" || grant.where !== void 0 || !capabilityCovers(grant.capability, AUTH_ADMINISTRATION_REQUEST)) return;
|
|
1395
|
+
if ("address" in grant.principal) return {
|
|
1396
|
+
address: grant.principal.address,
|
|
1397
|
+
key: void 0
|
|
1398
|
+
};
|
|
1399
|
+
if ("anyone" in grant.principal) return {
|
|
1400
|
+
address: void 0,
|
|
1401
|
+
key: void 0
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* A creator-less policy must always retain a grant permitting execute on the
|
|
1406
|
+
* auth scope; on a signed document the creator carve-out keeps administration
|
|
1407
|
+
* reachable instead. Rejects a change that takes the last such grant away. A
|
|
1408
|
+
* policy already without one is left alone: the change is not what locks it.
|
|
1409
|
+
*/
|
|
1410
|
+
function assertAuthAdministrationRetained(creator, previous, next, grantId) {
|
|
1411
|
+
if (creator !== void 0) return;
|
|
1412
|
+
if (administrationReachable(previous) && !administrationReachable(next)) throw new AuthAdministrationLockoutError(grantId);
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* An operand whose shape validation would have rejected. Distinguished from
|
|
1416
|
+
* an unresolved path so a structurally malformed operand poisons its whole
|
|
1417
|
+
* condition to false rather than reading as "absent", which `not` would
|
|
1418
|
+
* otherwise widen to true.
|
|
1419
|
+
*/
|
|
1420
|
+
const INVALID_OPERAND = Symbol("invalid-operand");
|
|
1421
|
+
/**
|
|
1422
|
+
* Narrows to the values conditions compare. An object, array, or non-finite
|
|
1423
|
+
* number resolves to undefined, and every comparison involving undefined is
|
|
1424
|
+
* false.
|
|
1425
|
+
*/
|
|
1426
|
+
function asConditionValue(value) {
|
|
1427
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
1428
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Resolves one operand. Attr roots: `subject.*`, `doc.<scope>.*` where the
|
|
1432
|
+
* scope must be the executing scope (validation already rejects any other,
|
|
1433
|
+
* but resolution stays total), and `action.input.*`. Path steps read own
|
|
1434
|
+
* properties only, so prototype members can never influence a verdict.
|
|
1435
|
+
*/
|
|
1436
|
+
function resolveOperand(operand, subject, request, conditions) {
|
|
1437
|
+
if (!isPlainValue(operand)) return INVALID_OPERAND;
|
|
1438
|
+
const keys = Object.keys(operand);
|
|
1439
|
+
if (keys.length !== 1) return INVALID_OPERAND;
|
|
1440
|
+
if (keys[0] === "lit") {
|
|
1441
|
+
const value = asConditionValue(operand.lit);
|
|
1442
|
+
return value === void 0 ? INVALID_OPERAND : value;
|
|
1443
|
+
}
|
|
1444
|
+
if (keys[0] !== "attr") return INVALID_OPERAND;
|
|
1445
|
+
const attr = operand.attr;
|
|
1446
|
+
if (typeof attr !== "string" || attr.length === 0) return INVALID_OPERAND;
|
|
1447
|
+
const path = attr.split(".");
|
|
1448
|
+
let value;
|
|
1449
|
+
let rest;
|
|
1450
|
+
if (path[0] === "subject") {
|
|
1451
|
+
value = subject;
|
|
1452
|
+
rest = path.slice(1);
|
|
1453
|
+
} else if (path[0] === "doc") {
|
|
1454
|
+
if (path[1] !== request.scope) return;
|
|
1455
|
+
value = conditions.scopeState;
|
|
1456
|
+
rest = path.slice(2);
|
|
1457
|
+
} else if (path[0] === "action" && path[1] === "input") {
|
|
1458
|
+
value = conditions.actionInput;
|
|
1459
|
+
rest = path.slice(2);
|
|
1460
|
+
} else return;
|
|
1461
|
+
for (const segment of rest) {
|
|
1462
|
+
if (!isPlainValue(value) || !Object.hasOwn(value, segment)) return;
|
|
1463
|
+
value = value[segment];
|
|
1464
|
+
}
|
|
1465
|
+
return asConditionValue(value);
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Total order within one type: numbers numerically, strings by code point.
|
|
1469
|
+
* Everything else, including mixed types, does not order.
|
|
1470
|
+
*/
|
|
1471
|
+
function compareValues(left, right) {
|
|
1472
|
+
if (typeof left === "number" && typeof right === "number") return left < right ? -1 : left > right ? 1 : 0;
|
|
1473
|
+
if (typeof left === "string" && typeof right === "string") {
|
|
1474
|
+
const leftPoints = Array.from(left);
|
|
1475
|
+
const rightPoints = Array.from(right);
|
|
1476
|
+
const shared = Math.min(leftPoints.length, rightPoints.length);
|
|
1477
|
+
for (let i = 0; i < shared; i++) {
|
|
1478
|
+
const a = leftPoints[i].codePointAt(0) ?? 0;
|
|
1479
|
+
const b = rightPoints[i].codePointAt(0) ?? 0;
|
|
1480
|
+
if (a !== b) return a < b ? -1 : 1;
|
|
1481
|
+
}
|
|
1482
|
+
return leftPoints.length === rightPoints.length ? 0 : leftPoints.length < rightPoints.length ? -1 : 1;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Tri-state evaluation: undefined marks a structurally invalid node, which
|
|
1487
|
+
* poisons the whole tree to false at the top — and a structurally malformed
|
|
1488
|
+
* operand poisons its condition the same way. Both are distinct from an
|
|
1489
|
+
* operand whose path fails to resolve, which is a valid comparison that is
|
|
1490
|
+
* false. The distinction keeps `not` from widening over malformed input.
|
|
1491
|
+
*/
|
|
1492
|
+
function evaluateNode(node, subject, request, conditions) {
|
|
1493
|
+
if (!isPlainValue(node)) return;
|
|
1494
|
+
const keys = Object.keys(node);
|
|
1495
|
+
if (keys.length !== 1) return;
|
|
1496
|
+
const kind = keys[0];
|
|
1497
|
+
const body = node[kind];
|
|
1498
|
+
switch (kind) {
|
|
1499
|
+
case "eq":
|
|
1500
|
+
case "ne":
|
|
1501
|
+
case "lt":
|
|
1502
|
+
case "lte":
|
|
1503
|
+
case "gt":
|
|
1504
|
+
case "gte": {
|
|
1505
|
+
if (!Array.isArray(body) || body.length !== 2) return;
|
|
1506
|
+
const left = resolveOperand(body[0], subject, request, conditions);
|
|
1507
|
+
const right = resolveOperand(body[1], subject, request, conditions);
|
|
1508
|
+
if (left === INVALID_OPERAND || right === INVALID_OPERAND) return;
|
|
1509
|
+
if (left === void 0 || right === void 0) return false;
|
|
1510
|
+
if (kind === "eq") return left === right;
|
|
1511
|
+
if (kind === "ne") return left !== right;
|
|
1512
|
+
const order = compareValues(left, right);
|
|
1513
|
+
if (order === void 0) return false;
|
|
1514
|
+
switch (kind) {
|
|
1515
|
+
case "lt": return order < 0;
|
|
1516
|
+
case "lte": return order <= 0;
|
|
1517
|
+
case "gt": return order > 0;
|
|
1518
|
+
case "gte": return order >= 0;
|
|
1519
|
+
}
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
case "in":
|
|
1523
|
+
case "notIn": {
|
|
1524
|
+
if (!Array.isArray(body) || body.length !== 2 || !Array.isArray(body[1])) return;
|
|
1525
|
+
const left = resolveOperand(body[0], subject, request, conditions);
|
|
1526
|
+
if (left === INVALID_OPERAND) return;
|
|
1527
|
+
const elements = body[1].map((element) => resolveOperand(element, subject, request, conditions));
|
|
1528
|
+
if (elements.some((value) => value === INVALID_OPERAND)) return;
|
|
1529
|
+
if (left === void 0) return false;
|
|
1530
|
+
const found = elements.some((value) => value !== void 0 && value === left);
|
|
1531
|
+
return kind === "in" ? found : !found;
|
|
1532
|
+
}
|
|
1533
|
+
case "exists": {
|
|
1534
|
+
const value = resolveOperand(body, subject, request, conditions);
|
|
1535
|
+
if (value === INVALID_OPERAND) return;
|
|
1536
|
+
return value !== void 0;
|
|
1537
|
+
}
|
|
1538
|
+
case "and":
|
|
1539
|
+
case "or": {
|
|
1540
|
+
if (!Array.isArray(body)) return;
|
|
1541
|
+
let result = kind === "and";
|
|
1542
|
+
for (const child of body) {
|
|
1543
|
+
const value = evaluateNode(child, subject, request, conditions);
|
|
1544
|
+
if (value === void 0) return;
|
|
1545
|
+
if (kind === "and") result = result && value;
|
|
1546
|
+
else result = result || value;
|
|
1547
|
+
}
|
|
1548
|
+
return result;
|
|
1549
|
+
}
|
|
1550
|
+
case "not": {
|
|
1551
|
+
const value = evaluateNode(body, subject, request, conditions);
|
|
1552
|
+
return value === void 0 ? void 0 : !value;
|
|
1553
|
+
}
|
|
1554
|
+
default: return;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Evaluates a version-1 condition. Deterministic, total, and pure: any input
|
|
1559
|
+
* shape yields a boolean and never throws, and a malformed condition is
|
|
1560
|
+
* false. These are consensus semantics, versioned by `PHAuthState.version`;
|
|
1561
|
+
* changing them requires a new version.
|
|
1562
|
+
*/
|
|
1563
|
+
function evaluateCondition(condition, subject, request, conditions) {
|
|
1564
|
+
return evaluateNode(condition, subject, request, conditions) === true;
|
|
1565
|
+
}
|
|
1566
|
+
/** Whether a capability's scope reaches the requested one. */
|
|
1567
|
+
function scopeCovers(scope, requested) {
|
|
1568
|
+
return scope === void 0 || scope === "*" || scope === requested;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Whether one grant answers this request.
|
|
1572
|
+
*
|
|
1573
|
+
* A grant allowing execute on a scope also allows reading it: executing an
|
|
1574
|
+
* operation means reading the state it applies to, so permitting the write while
|
|
1575
|
+
* withholding the read would describe an access nobody could use. The converse
|
|
1576
|
+
* does not hold -- a read grant confers no write.
|
|
1577
|
+
*
|
|
1578
|
+
* Only an allow carries across. A deny on execute withholds the write and says
|
|
1579
|
+
* nothing about the read, so a policy locking writes down does not silently
|
|
1580
|
+
* revoke a read grant sitting before it. The operation list is not consulted
|
|
1581
|
+
* either: it restricts which operations may be executed, not whether the scope
|
|
1582
|
+
* is visible, and a read carries no operation to match against.
|
|
1583
|
+
*
|
|
1584
|
+
* Reads are not consensus -- no replica records a read, and the two read call
|
|
1585
|
+
* sites are both inside the read gate -- so this rule is not part of what makes
|
|
1586
|
+
* an operation valid, and does not need a policy version of its own.
|
|
1587
|
+
*/
|
|
1588
|
+
function grantAnswers(grant, request) {
|
|
1589
|
+
if (capabilityCovers(grant.capability, request)) return true;
|
|
1590
|
+
return request.verb === "read" && grant.effect === "allow" && grant.capability.can === "execute" && scopeCovers(grant.capability.scope, request.scope);
|
|
1591
|
+
}
|
|
1592
|
+
function capabilityCovers(capability, request) {
|
|
1593
|
+
if (capability.can !== request.verb) return false;
|
|
1594
|
+
if (!scopeCovers(capability.scope, request.scope)) return false;
|
|
1595
|
+
if (capability.can === "execute") {
|
|
1596
|
+
if (capability.operation === void 0) return true;
|
|
1597
|
+
return request.operation !== void 0 && capability.operation.includes(request.operation);
|
|
1598
|
+
}
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
function principalMatches(principal, subject, request, groups, conditions) {
|
|
1602
|
+
if ("anyone" in principal) return true;
|
|
1603
|
+
if ("address" in principal) return subject.address !== void 0 && subject.address.toLowerCase() === principal.address.toLowerCase();
|
|
1604
|
+
if ("group" in principal) {
|
|
1605
|
+
if (groups === void 0 || subject.address === void 0) return false;
|
|
1606
|
+
const group = groups[principal.group];
|
|
1607
|
+
if (group === void 0 || !Array.isArray(group.members)) return false;
|
|
1608
|
+
const address = subject.address.toLowerCase();
|
|
1609
|
+
return group.members.some((member) => member.toLowerCase() === address);
|
|
1610
|
+
}
|
|
1611
|
+
if ("match" in principal) {
|
|
1612
|
+
if (conditions === void 0) return false;
|
|
1613
|
+
return evaluateCondition(principal.match, subject, request, conditions);
|
|
1614
|
+
}
|
|
1615
|
+
return false;
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* The group document ids named by `{ group }` principals in a grant list, in
|
|
1619
|
+
* order of first appearance. These are the streams the groups projection reads.
|
|
1620
|
+
*/
|
|
1621
|
+
function referencedGroupIds(grants) {
|
|
1622
|
+
const ids = [];
|
|
1623
|
+
for (const grant of grants) if ("group" in grant.principal && !ids.includes(grant.principal.group)) ids.push(grant.principal.group);
|
|
1624
|
+
return ids;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Evaluates a v1 grant stack: default deny, last applicable grant wins, and
|
|
1628
|
+
* reports which grant decided it. Group principals match only against a
|
|
1629
|
+
* supplied groups map, and `where` clauses and { match } principals evaluate
|
|
1630
|
+
* only against a supplied condition context; a grant that uses an unsupplied
|
|
1631
|
+
* feature never applies.
|
|
1632
|
+
*/
|
|
1633
|
+
function evaluateGrantStack(grants, subject, request, groups, conditions) {
|
|
1634
|
+
let applicable;
|
|
1635
|
+
for (const grant of grants) {
|
|
1636
|
+
if (grant.where !== void 0) {
|
|
1637
|
+
if (conditions === void 0) continue;
|
|
1638
|
+
if (!evaluateCondition(grant.where, subject, request, conditions)) continue;
|
|
1639
|
+
}
|
|
1640
|
+
if (grantAnswers(grant, request) && principalMatches(grant.principal, subject, request, groups, conditions)) applicable = grant;
|
|
1641
|
+
}
|
|
1642
|
+
if (applicable === void 0) return {
|
|
1643
|
+
decision: "deny",
|
|
1644
|
+
refusal: "no-applicable-grant"
|
|
1645
|
+
};
|
|
1646
|
+
if (applicable.effect === "deny") return {
|
|
1647
|
+
decision: "deny",
|
|
1648
|
+
refusal: "denied-by-grant",
|
|
1649
|
+
grantId: applicable.id
|
|
1650
|
+
};
|
|
1651
|
+
return { decision: "allow" };
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Evaluates a v1 grant stack: default deny, last applicable grant wins. This is
|
|
1655
|
+
* {@link evaluateGrantStack} with the reason dropped.
|
|
1656
|
+
*/
|
|
1657
|
+
function evaluateGrants(grants, subject, request, groups, conditions) {
|
|
1658
|
+
return evaluateGrantStack(grants, subject, request, groups, conditions).decision;
|
|
1659
|
+
}
|
|
1660
|
+
//#endregion
|
|
853
1661
|
//#region document-model/constants.ts
|
|
854
1662
|
const documentModelFileExtension = "phdm";
|
|
855
1663
|
const documentModelInitialLocalState = {};
|
|
@@ -1436,8 +2244,403 @@ const HASH_ALGORITHM_SHA512 = "sha512";
|
|
|
1436
2244
|
const HASH_ENCODING_BASE64 = "base64";
|
|
1437
2245
|
const HASH_ENCODING_HEX = "hex";
|
|
1438
2246
|
//#endregion
|
|
1439
|
-
//#region document-model/
|
|
1440
|
-
|
|
2247
|
+
//#region document-model/state.ts
|
|
2248
|
+
/**
|
|
2249
|
+
* Creates a default PHAuthState
|
|
2250
|
+
*/
|
|
2251
|
+
function defaultAuthState() {
|
|
2252
|
+
return {
|
|
2253
|
+
version: 0,
|
|
2254
|
+
grants: []
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Creates a default PHDocumentState
|
|
2259
|
+
*/
|
|
2260
|
+
function defaultDocumentState() {
|
|
2261
|
+
return {
|
|
2262
|
+
version: 0,
|
|
2263
|
+
hash: {
|
|
2264
|
+
algorithm: HASH_ALGORITHM_SHA1,
|
|
2265
|
+
encoding: HASH_ENCODING_BASE64
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
/**
|
|
2270
|
+
* Creates a default PHBaseState with auth and document properties
|
|
2271
|
+
*/
|
|
2272
|
+
function defaultBaseState() {
|
|
2273
|
+
return {
|
|
2274
|
+
auth: defaultAuthState(),
|
|
2275
|
+
document: defaultDocumentState()
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Creates a PHAuthState with the given properties
|
|
2280
|
+
*/
|
|
2281
|
+
function createAuthState(auth) {
|
|
2282
|
+
return {
|
|
2283
|
+
...defaultAuthState(),
|
|
2284
|
+
...auth
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Creates a PHDocumentState with the given properties
|
|
2289
|
+
*/
|
|
2290
|
+
function createDocumentState(document) {
|
|
2291
|
+
return {
|
|
2292
|
+
...defaultDocumentState(),
|
|
2293
|
+
...document
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Creates a PHBaseState with the given auth and document properties
|
|
2298
|
+
*/
|
|
2299
|
+
function createBaseState(auth, document) {
|
|
2300
|
+
return {
|
|
2301
|
+
auth: createAuthState(auth),
|
|
2302
|
+
document: createDocumentState(document)
|
|
2303
|
+
};
|
|
2304
|
+
}
|
|
2305
|
+
/**
|
|
2306
|
+
* Backfills the auth scope to the default for legacy documents serialized with
|
|
2307
|
+
* an empty `auth`. Replaces only `state.auth`. Idempotent.
|
|
2308
|
+
*/
|
|
2309
|
+
function backfillAuthState(state) {
|
|
2310
|
+
return {
|
|
2311
|
+
...state,
|
|
2312
|
+
auth: createAuthState(state.auth)
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
function defaultGlobalState() {
|
|
2316
|
+
return {
|
|
2317
|
+
...defaultBaseState(),
|
|
2318
|
+
author: {
|
|
2319
|
+
name: "",
|
|
2320
|
+
website: ""
|
|
2321
|
+
},
|
|
2322
|
+
description: "",
|
|
2323
|
+
extension: "",
|
|
2324
|
+
id: "",
|
|
2325
|
+
name: "",
|
|
2326
|
+
specifications: []
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
function defaultLocalState() {
|
|
2330
|
+
return {};
|
|
2331
|
+
}
|
|
2332
|
+
function defaultPHState() {
|
|
2333
|
+
return {
|
|
2334
|
+
...defaultBaseState(),
|
|
2335
|
+
global: defaultGlobalState(),
|
|
2336
|
+
local: defaultLocalState()
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
function createGlobalState(state) {
|
|
2340
|
+
return {
|
|
2341
|
+
...defaultGlobalState(),
|
|
2342
|
+
...state || {}
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
function createLocalState(state) {
|
|
2346
|
+
return {
|
|
2347
|
+
...defaultLocalState(),
|
|
2348
|
+
...state || {}
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
function createState(baseState, globalState, localState) {
|
|
2352
|
+
return {
|
|
2353
|
+
...createBaseState(baseState?.auth, baseState?.document),
|
|
2354
|
+
global: createGlobalState(globalState),
|
|
2355
|
+
local: createLocalState(localState)
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
//#endregion
|
|
2359
|
+
//#region document-model/auth.ts
|
|
2360
|
+
const AUTH_ACTION_TYPES = [
|
|
2361
|
+
"INITIALIZE_AUTH",
|
|
2362
|
+
"SET_GRANT",
|
|
2363
|
+
"REMOVE_GRANT",
|
|
2364
|
+
"MOVE_GRANT"
|
|
2365
|
+
];
|
|
2366
|
+
function isAuthAction(action) {
|
|
2367
|
+
return AUTH_ACTION_TYPES.includes(action.type);
|
|
2368
|
+
}
|
|
2369
|
+
/** Highest known policy version; decide() fails closed above it. */
|
|
2370
|
+
const MAX_SUPPORTED_AUTH_VERSION = 1;
|
|
2371
|
+
const InitializeAuthActionInputSchema = () => z.object({
|
|
2372
|
+
version: z.number().int().min(1),
|
|
2373
|
+
grants: z.array(GrantSchema()).max(100)
|
|
2374
|
+
});
|
|
2375
|
+
const SetGrantActionInputSchema = () => z.object({ grant: GrantSchema() });
|
|
2376
|
+
const RemoveGrantActionInputSchema = () => z.object({ id: z.string() });
|
|
2377
|
+
const MoveGrantActionInputSchema = () => z.object({
|
|
2378
|
+
id: z.string(),
|
|
2379
|
+
index: z.number()
|
|
2380
|
+
});
|
|
2381
|
+
const initializeAuth = (input) => createAction("INITIALIZE_AUTH", input, void 0, InitializeAuthActionInputSchema, "auth");
|
|
2382
|
+
const setGrant = (input) => createAction("SET_GRANT", input, void 0, SetGrantActionInputSchema, "auth");
|
|
2383
|
+
const removeGrant = (input) => createAction("REMOVE_GRANT", input, void 0, RemoveGrantActionInputSchema, "auth");
|
|
2384
|
+
const moveGrant = (input) => createAction("MOVE_GRANT", input, void 0, MoveGrantActionInputSchema, "auth");
|
|
2385
|
+
/**
|
|
2386
|
+
* Destructuring a null input (reachable via raw synced operations) would
|
|
2387
|
+
* store an engine-specific TypeError message on the error operation.
|
|
2388
|
+
*/
|
|
2389
|
+
function assertActionInputShape(input) {
|
|
2390
|
+
if (!isPlainValue(input)) throw new InvalidActionInputError({ input: "must be an object" });
|
|
2391
|
+
}
|
|
2392
|
+
function withGrants(document, grants) {
|
|
2393
|
+
return {
|
|
2394
|
+
...document,
|
|
2395
|
+
state: {
|
|
2396
|
+
...document.state,
|
|
2397
|
+
auth: {
|
|
2398
|
+
...document.state.auth,
|
|
2399
|
+
grants
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
const P256_PUBKEY_MULTICODEC = [128, 36];
|
|
2405
|
+
const DID_KEY_PREFIX = "did:key:z";
|
|
2406
|
+
function bytesEqual(a, b) {
|
|
2407
|
+
if (a.length !== b.length) return false;
|
|
2408
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
2409
|
+
return true;
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* True when `signerKey` (an ActionSigner app key, a did:key) identifies the same
|
|
2413
|
+
* key recorded as the document creator. Returns false
|
|
2414
|
+
* when there is no creator (empty JWK) or no signer key.
|
|
2415
|
+
*/
|
|
2416
|
+
function isDocumentCreator(creatorKey, signerKey) {
|
|
2417
|
+
if (!creatorKey?.x || !creatorKey.y) return false;
|
|
2418
|
+
if (!signerKey || !signerKey.startsWith(DID_KEY_PREFIX)) return false;
|
|
2419
|
+
const decoded = base58Decode(signerKey.slice(9));
|
|
2420
|
+
if (!decoded || decoded.length !== 35) return false;
|
|
2421
|
+
if (decoded[0] !== P256_PUBKEY_MULTICODEC[0] || decoded[1] !== P256_PUBKEY_MULTICODEC[1]) return false;
|
|
2422
|
+
const parityPrefix = decoded[2];
|
|
2423
|
+
if (parityPrefix !== 2 && parityPrefix !== 3) return false;
|
|
2424
|
+
const didX = decoded.subarray(3, 35);
|
|
2425
|
+
const jwkX = base64UrlToBytes(creatorKey.x);
|
|
2426
|
+
const jwkY = base64UrlToBytes(creatorKey.y);
|
|
2427
|
+
if (jwkX.length !== 32 || jwkY.length !== 32) return false;
|
|
2428
|
+
if (!bytesEqual(didX, jwkX)) return false;
|
|
2429
|
+
return (jwkY[31] & 1) === 1 === (parityPrefix === 3);
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Sets the initial policy. Valid only while the auth scope is uninitialized
|
|
2433
|
+
* (version 0). The input version is the policy language version and must be an
|
|
2434
|
+
* integer >= 1; 0 is reserved for the uninitialized state. On a signed-header
|
|
2435
|
+
* document it must be signed by the document creator (`header.sig.publicKey`).
|
|
2436
|
+
* A creator-less policy must include a grant permitting execute on the auth
|
|
2437
|
+
* scope, or it would be born locked out.
|
|
2438
|
+
*/
|
|
2439
|
+
function applyInitializeAuthAction(document, action) {
|
|
2440
|
+
assertActionInputShape(action.input);
|
|
2441
|
+
const { version, grants } = action.input;
|
|
2442
|
+
if (!Number.isInteger(version) || version < 1) throw new InvalidAuthVersionError(document.header.id, version);
|
|
2443
|
+
if (document.state.auth.version !== 0) throw new AuthAlreadyInitializedError(document.header.id);
|
|
2444
|
+
if (!Array.isArray(grants)) throw new InvalidActionInputError({ grants: "must be an array" });
|
|
2445
|
+
const creatorKey = document.header.sig.publicKey;
|
|
2446
|
+
const signerKey = action.context?.signer?.app.key;
|
|
2447
|
+
const hasCreator = Boolean(creatorKey.kty || creatorKey.x || creatorKey.y);
|
|
2448
|
+
if (hasCreator && !isDocumentCreator(creatorKey, signerKey)) throw new AuthInitializerNotCreatorError(document.header.id);
|
|
2449
|
+
const creator = hasCreator ? signerKey : void 0;
|
|
2450
|
+
assertValidInitialGrants(grants, document.header.documentType, creator);
|
|
2451
|
+
return {
|
|
2452
|
+
...document,
|
|
2453
|
+
state: {
|
|
2454
|
+
...document.state,
|
|
2455
|
+
auth: createAuthState(creator ? {
|
|
2456
|
+
version,
|
|
2457
|
+
grants,
|
|
2458
|
+
creator
|
|
2459
|
+
} : {
|
|
2460
|
+
version,
|
|
2461
|
+
grants
|
|
2462
|
+
})
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
/** Upserts a grant by id: replaces in place if present, otherwise appends. */
|
|
2467
|
+
function applySetGrantAction(document, action) {
|
|
2468
|
+
assertActionInputShape(action.input);
|
|
2469
|
+
const { grant } = action.input;
|
|
2470
|
+
const grants = document.state.auth.grants;
|
|
2471
|
+
assertValidGrantUpsert(grant, grants, document.header.documentType, document.state.auth.creator);
|
|
2472
|
+
return withGrants(document, grants.some((g) => g.id === grant.id) ? grants.map((g) => g.id === grant.id ? grant : g) : [...grants, grant]);
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* Removes a grant by id; throws if the id is not present or if the removal
|
|
2476
|
+
* would leave a creator-less policy with no auth-administration grant.
|
|
2477
|
+
*/
|
|
2478
|
+
function applyRemoveGrantAction(document, action) {
|
|
2479
|
+
assertActionInputShape(action.input);
|
|
2480
|
+
const { id } = action.input;
|
|
2481
|
+
const { grants, creator } = document.state.auth;
|
|
2482
|
+
if (!grants.some((g) => g.id === id)) throw new GrantNotFoundError(id);
|
|
2483
|
+
const next = grants.filter((g) => g.id !== id);
|
|
2484
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2485
|
+
return withGrants(document, next);
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Moves a grant by id to a new index. Order is load-bearing (the last
|
|
2489
|
+
* applicable grant wins), so the relative order of the other grants is kept.
|
|
2490
|
+
* The target index is clamped to the valid range; an unknown id throws.
|
|
2491
|
+
*
|
|
2492
|
+
* Order alone decides which grant wins, so a move can take administration away
|
|
2493
|
+
* without changing the list's contents. It carries the same retention rule as
|
|
2494
|
+
* the two mutation paths.
|
|
2495
|
+
*/
|
|
2496
|
+
function applyMoveGrantAction(document, action) {
|
|
2497
|
+
assertActionInputShape(action.input);
|
|
2498
|
+
const { id, index } = action.input;
|
|
2499
|
+
const { grants, creator } = document.state.auth;
|
|
2500
|
+
const from = grants.findIndex((g) => g.id === id);
|
|
2501
|
+
if (from === -1) throw new GrantNotFoundError(id);
|
|
2502
|
+
const next = [...grants];
|
|
2503
|
+
const [moved] = next.splice(from, 1);
|
|
2504
|
+
const to = Math.max(0, Math.min(index, next.length));
|
|
2505
|
+
next.splice(to, 0, moved);
|
|
2506
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2507
|
+
return withGrants(document, next);
|
|
2508
|
+
}
|
|
2509
|
+
/**
|
|
2510
|
+
* Dispatches an auth-scope action to its handler. This is the auth scope's
|
|
2511
|
+
* dedicated reducer: it is applied by the base reducer instead of the model
|
|
2512
|
+
* reducer, mirroring the document-scope platform handlers. Unknown types are a
|
|
2513
|
+
* no-op, matching the model-reducer default.
|
|
2514
|
+
*/
|
|
2515
|
+
function applyAuthAction(document, action) {
|
|
2516
|
+
switch (action.type) {
|
|
2517
|
+
case "INITIALIZE_AUTH": return applyInitializeAuthAction(document, action);
|
|
2518
|
+
case "SET_GRANT": return applySetGrantAction(document, action);
|
|
2519
|
+
case "REMOVE_GRANT": return applyRemoveGrantAction(document, action);
|
|
2520
|
+
case "MOVE_GRANT": return applyMoveGrantAction(document, action);
|
|
2521
|
+
default: return document;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* Because only creators can initialize auth scopes, we must verify that either
|
|
2526
|
+
* the document has no auth or the version and creator match.
|
|
2527
|
+
*/
|
|
2528
|
+
function assertAuthPreservedOnDuplicate(documentId, source, duplicated) {
|
|
2529
|
+
if (!source || source.version === 0) return;
|
|
2530
|
+
if (duplicated === void 0 || duplicated.version !== source.version || duplicated.creator !== source.creator) throw new AuthPolicyNotPreservedError(documentId);
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* The auth scope a state snapshot may install, given the policy already there.
|
|
2534
|
+
*
|
|
2535
|
+
* `applyAuthAction` is the validated door onto `state.auth`, but a whole-state
|
|
2536
|
+
* snapshot (UPGRADE_DOCUMENT's `initialState`, LOAD_STATE's `data`) replaces the
|
|
2537
|
+
* scope wholesale and is authorized as a `document`-scope write. Without this,
|
|
2538
|
+
* a subject holding `execute` on `document` and no auth grant at all can install
|
|
2539
|
+
* a policy of its choosing, name itself `creator` (which exempts the policy from
|
|
2540
|
+
* the retention rule for good), or wipe an existing policy by carrying the
|
|
2541
|
+
* default uninitialized one.
|
|
2542
|
+
*
|
|
2543
|
+
* Three cases:
|
|
2544
|
+
*
|
|
2545
|
+
* - the snapshot carries no policy, or an uninitialized one: the document
|
|
2546
|
+
* keeps the policy it has, so a default-state upgrade cannot reset it;
|
|
2547
|
+
* - the document is uninitialized and the snapshot carries a policy: the
|
|
2548
|
+
* policy is installed after the same validation genesis applies, so it
|
|
2549
|
+
* cannot be born locked out;
|
|
2550
|
+
* - both carry a policy: they must agree. A duplicate preserves its source's
|
|
2551
|
+
* policy (see {@link assertAuthPreservedOnDuplicate}), and anything else is
|
|
2552
|
+
* an attempt to replace one policy with another.
|
|
2553
|
+
*/
|
|
2554
|
+
function resolveSnapshotAuth(documentId, documentType, current, incoming) {
|
|
2555
|
+
const currentAuth = current ?? createAuthState({
|
|
2556
|
+
version: 0,
|
|
2557
|
+
grants: []
|
|
2558
|
+
});
|
|
2559
|
+
if (!incoming || !incoming.version) return currentAuth;
|
|
2560
|
+
if (currentAuth.version !== 0) {
|
|
2561
|
+
if (stringify(incoming) !== stringify(currentAuth)) throw new AuthPolicyNotPreservedError(documentId);
|
|
2562
|
+
return incoming;
|
|
2563
|
+
}
|
|
2564
|
+
if (!Array.isArray(incoming.grants)) throw new InvalidActionInputError({ grants: "must be an array" });
|
|
2565
|
+
assertValidInitialGrants(incoming.grants, documentType, incoming.creator);
|
|
2566
|
+
return incoming;
|
|
2567
|
+
}
|
|
2568
|
+
/** UNDO, REDO and PRUNE are rejected on the auth scope. */
|
|
2569
|
+
function assertAuthScopeActionAllowed(action) {
|
|
2570
|
+
if (action.scope === "auth" && [
|
|
2571
|
+
"UNDO",
|
|
2572
|
+
"REDO",
|
|
2573
|
+
"PRUNE"
|
|
2574
|
+
].includes(action.type)) throw new AuthActionNotAllowedError(action.type);
|
|
2575
|
+
}
|
|
2576
|
+
/**
|
|
2577
|
+
* Evaluates the auth policy for a single request and reports why it refused.
|
|
2578
|
+
* Pure and deterministic.
|
|
2579
|
+
*
|
|
2580
|
+
* An uninitialized policy (version 0, absent auth state, or a legacy `{}`
|
|
2581
|
+
* auth scope serialized before PHAuthState had a version) leaves the document
|
|
2582
|
+
* open. Once a policy exists the default is deny, and grants stack in order.
|
|
2583
|
+
*
|
|
2584
|
+
* Group principals match only against a supplied groups map (the groups
|
|
2585
|
+
* projection, present when authGroups is on); with no map they never apply.
|
|
2586
|
+
* `where` clauses and { match } principals likewise evaluate only against a
|
|
2587
|
+
* supplied condition context (present when authConditions is on).
|
|
2588
|
+
*/
|
|
2589
|
+
function evaluate(auth, subject, request, groups, conditions) {
|
|
2590
|
+
if (!auth || !auth.version) return { decision: "allow" };
|
|
2591
|
+
if (request.verb === "execute" && request.scope === "auth" && subject.key !== void 0 && subject.key === auth.creator) return { decision: "allow" };
|
|
2592
|
+
if (auth.version > 1) return {
|
|
2593
|
+
decision: "deny",
|
|
2594
|
+
refusal: "version-unsupported"
|
|
2595
|
+
};
|
|
2596
|
+
return evaluateGrantStack(auth.grants, subject, request, groups, conditions);
|
|
2597
|
+
}
|
|
2598
|
+
/**
|
|
2599
|
+
* Evaluates the auth policy for a single request. Pure and deterministic. This
|
|
2600
|
+
* is {@link evaluate} with the reason dropped.
|
|
2601
|
+
*/
|
|
2602
|
+
function decide(auth, subject, request, groups, conditions) {
|
|
2603
|
+
return evaluate(auth, subject, request, groups, conditions).decision;
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* The group document ids a single auth action's input names with `{ group }`
|
|
2607
|
+
* principals. INITIALIZE_AUTH contributes the groups named across its grants,
|
|
2608
|
+
* SET_GRANT the groups named by its one grant; REMOVE_GRANT and MOVE_GRANT
|
|
2609
|
+
* contribute nothing. Total over any input shape, because references are read
|
|
2610
|
+
* from the input as it arrived, including inputs later stored as errors.
|
|
2611
|
+
*/
|
|
2612
|
+
function mentionedGroupIds(action) {
|
|
2613
|
+
const input = action.input;
|
|
2614
|
+
const candidates = [];
|
|
2615
|
+
if (action.type === "INITIALIZE_AUTH" && Array.isArray(input?.grants)) candidates.push(...input.grants);
|
|
2616
|
+
if (action.type === "SET_GRANT" && input?.grant !== void 0) candidates.push(input.grant);
|
|
2617
|
+
const ids = [];
|
|
2618
|
+
for (const candidate of candidates) {
|
|
2619
|
+
if (typeof candidate !== "object" || candidate === null) continue;
|
|
2620
|
+
const principal = candidate.principal;
|
|
2621
|
+
if (typeof principal !== "object" || principal === null) continue;
|
|
2622
|
+
const group = principal.group;
|
|
2623
|
+
if (typeof group === "string" && group !== "" && !ids.includes(group)) ids.push(group);
|
|
2624
|
+
}
|
|
2625
|
+
return ids;
|
|
2626
|
+
}
|
|
2627
|
+
//#endregion
|
|
2628
|
+
//#region document-model/denied.ts
|
|
2629
|
+
/**
|
|
2630
|
+
* True iff authorization rejected the action.
|
|
2631
|
+
*/
|
|
2632
|
+
function isDenied(operation) {
|
|
2633
|
+
return operation.deniedReason !== void 0;
|
|
2634
|
+
}
|
|
2635
|
+
/**
|
|
2636
|
+
* The closed set of strings persisted as `deniedReason`. Re-evaluation compares
|
|
2637
|
+
* them, so they are consensus data: exact strings that embed no grant id,
|
|
2638
|
+
* subject or timestamp. Changing one is history-visible.
|
|
2639
|
+
*/
|
|
2640
|
+
const DOCUMENT_DELETED_REASON = "document deleted";
|
|
2641
|
+
const AUTH_VERSION_UNSUPPORTED_REASON = "auth policy version unsupported";
|
|
2642
|
+
const AUTH_NO_GRANT_REASON = "no grant permits this operation";
|
|
2643
|
+
const AUTH_DENIED_BY_GRANT_REASON = "denied by grant";
|
|
1441
2644
|
//#endregion
|
|
1442
2645
|
//#region document-model/document-schema.ts
|
|
1443
2646
|
const BaseDocumentHeaderSchema = z.object({
|
|
@@ -1710,6 +2913,7 @@ function createDocumentScopeOperations(header, state) {
|
|
|
1710
2913
|
function baseCreateDocument(createState, initialState, documentType = "") {
|
|
1711
2914
|
const state = createState(initialState);
|
|
1712
2915
|
const header = createPresignedHeader(generateId(), documentType);
|
|
2916
|
+
header.protocolVersions = { "base-reducer": 2 };
|
|
1713
2917
|
return {
|
|
1714
2918
|
header,
|
|
1715
2919
|
state,
|
|
@@ -1805,6 +3009,18 @@ function mapSkippedOperationsV2(operations) {
|
|
|
1805
3009
|
* Uses the V2 model where consecutive NOOPs form chains.
|
|
1806
3010
|
* Unlike V1 garbageCollect, this preserves ALL operations but marks which to apply.
|
|
1807
3011
|
*/
|
|
3012
|
+
/**
|
|
3013
|
+
* The base-reducer protocol version a document is written against. Every
|
|
3014
|
+
* document carries one, set from the CREATE_DOCUMENT input. A header without
|
|
3015
|
+
* one was built outside that path, and choosing a version on its behalf would
|
|
3016
|
+
* replay the document through a reducer it was not written for, so it is an
|
|
3017
|
+
* error rather than a default.
|
|
3018
|
+
*/
|
|
3019
|
+
function baseReducerVersion(header) {
|
|
3020
|
+
const version = header.protocolVersions?.["base-reducer"];
|
|
3021
|
+
if (typeof version !== "number") throw new Error(`Document ${header.id} carries no base-reducer protocol version`);
|
|
3022
|
+
return version;
|
|
3023
|
+
}
|
|
1808
3024
|
function garbageCollectV2(sortedOperations) {
|
|
1809
3025
|
const result = [];
|
|
1810
3026
|
let noopChainLength = 0;
|
|
@@ -1824,9 +3040,26 @@ function sortMappedOperations(operations) {
|
|
|
1824
3040
|
const defaultCreateState = (state) => {
|
|
1825
3041
|
return state;
|
|
1826
3042
|
};
|
|
3043
|
+
/**
|
|
3044
|
+
* Records an operation in the history without applying it, which is what a
|
|
3045
|
+
* denied operation needs: it occupies its index and contributes no state.
|
|
3046
|
+
*
|
|
3047
|
+
* The scope defaults to the action's own, and is passed explicitly by a rebuild
|
|
3048
|
+
* that is walking one stream and does not want to trust the action's copy.
|
|
3049
|
+
*/
|
|
3050
|
+
function appendWithoutApplying(document, operation, scope = operation.action.scope) {
|
|
3051
|
+
return {
|
|
3052
|
+
...document,
|
|
3053
|
+
operations: {
|
|
3054
|
+
...document.operations,
|
|
3055
|
+
[scope]: [...document.operations[scope] ?? [], operation]
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
1827
3059
|
function replayDocument(initialState, operations, reducer, header, dispatch, skipHeaderOperations = {}, options) {
|
|
1828
3060
|
const { checkHashes = true, reuseOperationResultingState, operationResultingStateParser = parseResultingState, skipIndexValidation } = options || {};
|
|
1829
|
-
|
|
3061
|
+
const backfilledInitialState = backfillAuthState(initialState);
|
|
3062
|
+
let documentState = backfilledInitialState;
|
|
1830
3063
|
const operationsToReplay = [];
|
|
1831
3064
|
const allScopes = new Set([
|
|
1832
3065
|
...Object.keys(operations),
|
|
@@ -1861,12 +3094,13 @@ function replayDocument(initialState, operations, reducer, header, dispatch, ski
|
|
|
1861
3094
|
const document = {
|
|
1862
3095
|
header,
|
|
1863
3096
|
state: defaultCreateState(documentState),
|
|
1864
|
-
initialState,
|
|
3097
|
+
initialState: backfilledInitialState,
|
|
1865
3098
|
operations: initialOperations,
|
|
1866
3099
|
clipboard: []
|
|
1867
3100
|
};
|
|
1868
3101
|
let result = document;
|
|
1869
3102
|
if (operationsToReplay.length) result = operationsToReplay.reduce((document, operation) => {
|
|
3103
|
+
if (isDenied(operation)) return updateHeaderRevision(appendWithoutApplying(document, operation), operation.action.scope, operation.timestampUtcMs);
|
|
1870
3104
|
return reducer(document, operation.action, dispatch, {
|
|
1871
3105
|
ignoreSkipOperations: true,
|
|
1872
3106
|
checkHashes,
|
|
@@ -2390,14 +3624,31 @@ function redoOperation(document, action, skip) {
|
|
|
2390
3624
|
});
|
|
2391
3625
|
}
|
|
2392
3626
|
function loadStateOperation(document, action) {
|
|
3627
|
+
const loaded = backfillAuthState(action.state.data);
|
|
3628
|
+
loaded.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, loaded.auth);
|
|
2393
3629
|
return {
|
|
2394
3630
|
...document,
|
|
2395
3631
|
header: {
|
|
2396
3632
|
...document.header,
|
|
2397
3633
|
name: action.state.name
|
|
2398
3634
|
},
|
|
2399
|
-
state:
|
|
3635
|
+
state: loaded
|
|
3636
|
+
};
|
|
3637
|
+
}
|
|
3638
|
+
/**
|
|
3639
|
+
* Reads an operation's outcome. A denial takes precedence over a reducer
|
|
3640
|
+
* error, since a denied operation never reaches its reducer.
|
|
3641
|
+
*/
|
|
3642
|
+
function operationOutcome(operation) {
|
|
3643
|
+
if (operation.deniedReason !== void 0) return {
|
|
3644
|
+
kind: "denied",
|
|
3645
|
+
reason: operation.deniedReason
|
|
3646
|
+
};
|
|
3647
|
+
if (operation.error !== void 0) return {
|
|
3648
|
+
kind: "reducer-error",
|
|
3649
|
+
message: operation.error
|
|
2400
3650
|
};
|
|
3651
|
+
return { kind: "applied" };
|
|
2401
3652
|
}
|
|
2402
3653
|
//#endregion
|
|
2403
3654
|
//#region document-model/reducer.ts
|
|
@@ -2572,12 +3823,13 @@ function processUndoOperation(document, scope, customReducer, reuseOperationResu
|
|
|
2572
3823
|
function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
2573
3824
|
const { skip, ignoreSkipOperations = false, reuseOperationResultingState = false, operationResultingStateParser, pruneOnSkip = true, branch = "main" } = options;
|
|
2574
3825
|
let _action = actionFromAction(action);
|
|
3826
|
+
assertAuthScopeActionAllowed(_action);
|
|
2575
3827
|
let skipValue = skip ?? options.replayOptions?.operation.skip ?? 0;
|
|
2576
3828
|
let newDocument = { ...document };
|
|
2577
3829
|
let reuseLastOperationIndex = false;
|
|
2578
3830
|
const shouldProcessSkipOperation = !ignoreSkipOperations && skipValue > 0;
|
|
2579
3831
|
if (isUndoRedo(_action)) {
|
|
2580
|
-
const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex } = processUndoRedo(document, _action, skipValue, options.protocolVersion ??
|
|
3832
|
+
const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex } = processUndoRedo(document, _action, skipValue, options.protocolVersion ?? baseReducerVersion(document.header));
|
|
2581
3833
|
_action = transformedAction;
|
|
2582
3834
|
skipValue = calculatedSkip;
|
|
2583
3835
|
newDocument = processedDocument;
|
|
@@ -2593,7 +3845,7 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
2593
3845
|
branch
|
|
2594
3846
|
};
|
|
2595
3847
|
newDocument = updateDocument(newDocument, _action, reuseLastOperationIndex, skipValue, operationContext, options.replayOptions?.operation, options.skipIndexValidation);
|
|
2596
|
-
const protocolVersion = options.protocolVersion ??
|
|
3848
|
+
const protocolVersion = options.protocolVersion ?? baseReducerVersion(document.header);
|
|
2597
3849
|
if (isUndo(action) && protocolVersion < 2) return processUndoOperation(newDocument, action.scope, customReducer);
|
|
2598
3850
|
const isNoopWithSkip = _action.type === "NOOP" && skipValue > 0;
|
|
2599
3851
|
if ((isUndo(action) || isNoopWithSkip) && protocolVersion >= 2) {
|
|
@@ -2619,6 +3871,13 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
2619
3871
|
}
|
|
2620
3872
|
newDocument = create(newDocument, (draft) => {
|
|
2621
3873
|
try {
|
|
3874
|
+
if (_action.scope === "auth") {
|
|
3875
|
+
const authState = applyAuthAction(newDocument, _action).state;
|
|
3876
|
+
unsafe(() => {
|
|
3877
|
+
draft.state = castDraft(authState);
|
|
3878
|
+
});
|
|
3879
|
+
return;
|
|
3880
|
+
}
|
|
2622
3881
|
const newState = customReducer(draft.state, _action, dispatch);
|
|
2623
3882
|
if (newState) unsafe(() => {
|
|
2624
3883
|
draft.state = castDraft(newState);
|
|
@@ -2648,8 +3907,8 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
2648
3907
|
"PRUNE"
|
|
2649
3908
|
].includes(_action.type)) return newDocument;
|
|
2650
3909
|
const scope = _action.scope || "global";
|
|
2651
|
-
|
|
2652
|
-
|
|
3910
|
+
const replayHash = options.replayOptions?.operation.hash;
|
|
3911
|
+
const hash = replayHash ? replayHash : hashDocumentStateForScope(newDocument, scope);
|
|
2653
3912
|
const lastOperation = newDocument.operations[scope]?.at(-1);
|
|
2654
3913
|
if (lastOperation) {
|
|
2655
3914
|
lastOperation.hash = hash;
|
|
@@ -3414,14 +4673,27 @@ const documentModelStateReducer = (state, action) => {
|
|
|
3414
4673
|
const documentModelReducer = createReducer(documentModelStateReducer);
|
|
3415
4674
|
//#endregion
|
|
3416
4675
|
//#region document-model/upgrades.ts
|
|
4676
|
+
/**
|
|
4677
|
+
* Canonical document-model version normalization: documents stamped with 0
|
|
4678
|
+
* or nothing at all predate versioning and are treated as version 1, the
|
|
4679
|
+
* same version the registry assigns unversioned modules. Every consumer
|
|
4680
|
+
* that resolves a module or compares versions must use this rule; resolving
|
|
4681
|
+
* 0 to "latest" instead re-pins a legacy document's history to whichever
|
|
4682
|
+
* module happens to be newest.
|
|
4683
|
+
*/
|
|
4684
|
+
function normalizeDocumentModelVersion(version) {
|
|
4685
|
+
return version && version > 0 ? version : 1;
|
|
4686
|
+
}
|
|
3417
4687
|
function applyInitialState(document, action) {
|
|
3418
4688
|
const input = action.input;
|
|
3419
4689
|
const newState = input.initialState || input.state;
|
|
3420
4690
|
if (newState) {
|
|
3421
|
-
|
|
4691
|
+
const merged = backfillAuthState({
|
|
3422
4692
|
...document.state,
|
|
3423
4693
|
...newState
|
|
3424
|
-
};
|
|
4694
|
+
});
|
|
4695
|
+
merged.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, merged.auth);
|
|
4696
|
+
document.state = merged;
|
|
3425
4697
|
document.initialState = document.state;
|
|
3426
4698
|
}
|
|
3427
4699
|
}
|
|
@@ -3483,7 +4755,6 @@ function computeUpgradeTransitions(manifest, fromVersion, toVersion) {
|
|
|
3483
4755
|
}
|
|
3484
4756
|
//#endregion
|
|
3485
4757
|
//#region document-model/versioned-replay.ts
|
|
3486
|
-
const NON_DOMAIN_SCOPES$1 = new Set(["auth", "document"]);
|
|
3487
4758
|
function highestReducerVersion(reducers) {
|
|
3488
4759
|
const keys = Object.keys(reducers).map(Number);
|
|
3489
4760
|
if (keys.length === 0) throw new Error("VersionedReplayConfig.reducers must not be empty");
|
|
@@ -3511,15 +4782,15 @@ function highestReducerVersion(reducers) {
|
|
|
3511
4782
|
*/
|
|
3512
4783
|
function replayDocumentVersioned(initialState, operations, config, header, dispatch, options) {
|
|
3513
4784
|
const { checkHashes = true, skipIndexValidation } = options || {};
|
|
3514
|
-
const protocolVersion = header
|
|
4785
|
+
const protocolVersion = baseReducerVersion(header);
|
|
3515
4786
|
const spine = (operations["document"] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3516
4787
|
const upgrades = spine.filter((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
3517
4788
|
const legacyFallback = () => {
|
|
3518
|
-
const
|
|
4789
|
+
const replayOps = Object.fromEntries(Object.entries(operations).filter(([s]) => s !== "document"));
|
|
3519
4790
|
const latestVersion = highestReducerVersion(config.reducers);
|
|
3520
4791
|
const reducer = config.reducers[latestVersion];
|
|
3521
4792
|
return {
|
|
3522
|
-
...replayDocument(initialState,
|
|
4793
|
+
...replayDocument(initialState, replayOps, reducer, header, dispatch, {}, options),
|
|
3523
4794
|
operations
|
|
3524
4795
|
};
|
|
3525
4796
|
};
|
|
@@ -3543,14 +4814,14 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3543
4814
|
const a = op.action;
|
|
3544
4815
|
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
3545
4816
|
});
|
|
3546
|
-
const
|
|
4817
|
+
const replayScopes = Object.keys(operations).filter((s) => s !== "document");
|
|
3547
4818
|
const scopeOps = {};
|
|
3548
|
-
for (const s of
|
|
4819
|
+
for (const s of replayScopes) scopeOps[s] = (operations[s] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3549
4820
|
const boundaries = validatedUpgrades.map((upgradeOp) => {
|
|
3550
4821
|
const revisionSnapshot = upgradeOp.action.input.revision;
|
|
3551
4822
|
const upgradeTimestamp = upgradeOp.timestampUtcMs;
|
|
3552
4823
|
const boundary = {};
|
|
3553
|
-
for (const s of
|
|
4824
|
+
for (const s of replayScopes) {
|
|
3554
4825
|
const ops = scopeOps[s] ?? [];
|
|
3555
4826
|
if (revisionSnapshot !== void 0) {
|
|
3556
4827
|
const rev = revisionSnapshot[s] ?? 0;
|
|
@@ -3568,7 +4839,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3568
4839
|
}
|
|
3569
4840
|
return boundary;
|
|
3570
4841
|
});
|
|
3571
|
-
for (let i = 1; i < boundaries.length; i++) for (const s of
|
|
4842
|
+
for (let i = 1; i < boundaries.length; i++) for (const s of replayScopes) {
|
|
3572
4843
|
const prev = boundaries[i - 1]?.[s] ?? 0;
|
|
3573
4844
|
const curr = boundaries[i]?.[s] ?? 0;
|
|
3574
4845
|
if (boundaries[i]) boundaries[i][s] = Math.max(prev, curr);
|
|
@@ -3580,10 +4851,11 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3580
4851
|
]);
|
|
3581
4852
|
const initialOperations = {};
|
|
3582
4853
|
for (const s of allScopes) initialOperations[s] = [];
|
|
4854
|
+
const backfilledSeed = backfillAuthState(seedState);
|
|
3583
4855
|
let document = {
|
|
3584
4856
|
header,
|
|
3585
|
-
state:
|
|
3586
|
-
initialState:
|
|
4857
|
+
state: backfilledSeed,
|
|
4858
|
+
initialState: backfilledSeed,
|
|
3587
4859
|
operations: initialOperations,
|
|
3588
4860
|
clipboard: []
|
|
3589
4861
|
};
|
|
@@ -3591,17 +4863,15 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3591
4863
|
const segmentEndHashPerScope = /* @__PURE__ */ new Map();
|
|
3592
4864
|
for (let k = 0; k <= validatedUpgrades.length; k++) {
|
|
3593
4865
|
const reducer = config.reducers[currentVersion];
|
|
3594
|
-
if (!reducer)
|
|
3595
|
-
|
|
3596
|
-
throw new Error(`No reducer registered for document version ${currentVersion}. Available versions: ${available}`);
|
|
3597
|
-
}
|
|
3598
|
-
for (const s of domainScopes) {
|
|
4866
|
+
if (!reducer) throw new UnsupportedDocumentModelVersionError(header.documentType, currentVersion, Object.keys(config.reducers).map(Number).sort((a, b) => a - b));
|
|
4867
|
+
for (const s of replayScopes) {
|
|
3599
4868
|
const ops = scopeOps[s] ?? [];
|
|
3600
4869
|
const segStart = k === 0 ? 0 : boundaries[k - 1]?.[s] ?? 0;
|
|
3601
4870
|
const segEnd = k < validatedUpgrades.length ? boundaries[k]?.[s] ?? ops.length : ops.length;
|
|
3602
4871
|
const segOps = ops.slice(segStart, segEnd);
|
|
3603
4872
|
for (const op of segOps) {
|
|
3604
|
-
document =
|
|
4873
|
+
if (isDenied(op)) document = updateHeaderRevision(appendWithoutApplying(document, op, s), s, op.timestampUtcMs);
|
|
4874
|
+
else document = reducer(document, op.action, dispatch, {
|
|
3605
4875
|
ignoreSkipOperations: true,
|
|
3606
4876
|
checkHashes,
|
|
3607
4877
|
skipIndexValidation,
|
|
@@ -3618,6 +4888,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3618
4888
|
if (!spineOp) continue;
|
|
3619
4889
|
const spineActionType = spineOp.action.type;
|
|
3620
4890
|
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
4891
|
+
if (isDenied(spineOp)) continue;
|
|
3621
4892
|
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
3622
4893
|
else document = reducer(document, spineOp.action, dispatch, {
|
|
3623
4894
|
ignoreSkipOperations: true,
|
|
@@ -3648,7 +4919,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3648
4919
|
}
|
|
3649
4920
|
};
|
|
3650
4921
|
if (!checkHashes) {
|
|
3651
|
-
const allReplayedOps =
|
|
4922
|
+
const allReplayedOps = replayScopes.flatMap((s) => scopeOps[s] ?? []);
|
|
3652
4923
|
for (const scope of Object.keys(document.state)) {
|
|
3653
4924
|
const capturedHash = segmentEndHashPerScope.get(scope);
|
|
3654
4925
|
const scopeHash = capturedHash !== void 0 ? capturedHash : hashDocumentStateForScope(document, scope);
|
|
@@ -3692,7 +4963,6 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3692
4963
|
}
|
|
3693
4964
|
//#endregion
|
|
3694
4965
|
//#region document-model/files.ts
|
|
3695
|
-
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
3696
4966
|
function zipAsync(data) {
|
|
3697
4967
|
return new Promise((resolve, reject) => {
|
|
3698
4968
|
zip(data, (err, out) => err ? reject(err) : resolve(out));
|
|
@@ -3799,7 +5069,7 @@ async function parseZipData(data) {
|
|
|
3799
5069
|
async function loadFromZipData(data, reducer, options) {
|
|
3800
5070
|
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
3801
5071
|
return {
|
|
3802
|
-
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) =>
|
|
5072
|
+
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) => scope !== "document")), reducer, header, void 0, {}, options),
|
|
3803
5073
|
operations: clearedOperations
|
|
3804
5074
|
};
|
|
3805
5075
|
}
|
|
@@ -3835,105 +5105,6 @@ const getFileBrowser = (file) => {
|
|
|
3835
5105
|
return Promise.resolve().then(() => readFileBrowser(file));
|
|
3836
5106
|
};
|
|
3837
5107
|
//#endregion
|
|
3838
|
-
|
|
3839
|
-
/**
|
|
3840
|
-
* Creates a default PHAuthState
|
|
3841
|
-
*/
|
|
3842
|
-
function defaultAuthState() {
|
|
3843
|
-
return {};
|
|
3844
|
-
}
|
|
3845
|
-
/**
|
|
3846
|
-
* Creates a default PHDocumentState
|
|
3847
|
-
*/
|
|
3848
|
-
function defaultDocumentState() {
|
|
3849
|
-
return {
|
|
3850
|
-
version: 0,
|
|
3851
|
-
hash: {
|
|
3852
|
-
algorithm: HASH_ALGORITHM_SHA1,
|
|
3853
|
-
encoding: HASH_ENCODING_BASE64
|
|
3854
|
-
}
|
|
3855
|
-
};
|
|
3856
|
-
}
|
|
3857
|
-
/**
|
|
3858
|
-
* Creates a default PHBaseState with auth and document properties
|
|
3859
|
-
*/
|
|
3860
|
-
function defaultBaseState() {
|
|
3861
|
-
return {
|
|
3862
|
-
auth: defaultAuthState(),
|
|
3863
|
-
document: defaultDocumentState()
|
|
3864
|
-
};
|
|
3865
|
-
}
|
|
3866
|
-
/**
|
|
3867
|
-
* Creates a PHAuthState with the given properties
|
|
3868
|
-
*/
|
|
3869
|
-
function createAuthState(auth) {
|
|
3870
|
-
return {
|
|
3871
|
-
...defaultAuthState(),
|
|
3872
|
-
...auth
|
|
3873
|
-
};
|
|
3874
|
-
}
|
|
3875
|
-
/**
|
|
3876
|
-
* Creates a PHDocumentState with the given properties
|
|
3877
|
-
*/
|
|
3878
|
-
function createDocumentState(document) {
|
|
3879
|
-
return {
|
|
3880
|
-
...defaultDocumentState(),
|
|
3881
|
-
...document
|
|
3882
|
-
};
|
|
3883
|
-
}
|
|
3884
|
-
/**
|
|
3885
|
-
* Creates a PHBaseState with the given auth and document properties
|
|
3886
|
-
*/
|
|
3887
|
-
function createBaseState(auth, document) {
|
|
3888
|
-
return {
|
|
3889
|
-
auth: createAuthState(auth),
|
|
3890
|
-
document: createDocumentState(document)
|
|
3891
|
-
};
|
|
3892
|
-
}
|
|
3893
|
-
function defaultGlobalState() {
|
|
3894
|
-
return {
|
|
3895
|
-
...defaultBaseState(),
|
|
3896
|
-
author: {
|
|
3897
|
-
name: "",
|
|
3898
|
-
website: ""
|
|
3899
|
-
},
|
|
3900
|
-
description: "",
|
|
3901
|
-
extension: "",
|
|
3902
|
-
id: "",
|
|
3903
|
-
name: "",
|
|
3904
|
-
specifications: []
|
|
3905
|
-
};
|
|
3906
|
-
}
|
|
3907
|
-
function defaultLocalState() {
|
|
3908
|
-
return {};
|
|
3909
|
-
}
|
|
3910
|
-
function defaultPHState() {
|
|
3911
|
-
return {
|
|
3912
|
-
...defaultBaseState(),
|
|
3913
|
-
global: defaultGlobalState(),
|
|
3914
|
-
local: defaultLocalState()
|
|
3915
|
-
};
|
|
3916
|
-
}
|
|
3917
|
-
function createGlobalState(state) {
|
|
3918
|
-
return {
|
|
3919
|
-
...defaultGlobalState(),
|
|
3920
|
-
...state || {}
|
|
3921
|
-
};
|
|
3922
|
-
}
|
|
3923
|
-
function createLocalState(state) {
|
|
3924
|
-
return {
|
|
3925
|
-
...defaultLocalState(),
|
|
3926
|
-
...state || {}
|
|
3927
|
-
};
|
|
3928
|
-
}
|
|
3929
|
-
function createState(baseState, globalState, localState) {
|
|
3930
|
-
return {
|
|
3931
|
-
...createBaseState(baseState?.auth, baseState?.document),
|
|
3932
|
-
global: createGlobalState(globalState),
|
|
3933
|
-
local: createLocalState(localState)
|
|
3934
|
-
};
|
|
3935
|
-
}
|
|
3936
|
-
//#endregion
|
|
3937
|
-
export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, DowngradeNotSupportedError, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, applyDeleteDocumentAction, applyUpgradeDocumentAction, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseLoadFromInputVersioned, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, computeUpgradeTransitions, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
5108
|
+
export { AUTH_ACTION_TYPES, AUTH_DENIED_BY_GRANT_REASON, AUTH_NO_GRANT_REASON, AUTH_VERSION_UNSUPPORTED_REASON, AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthActionNotAllowedError, AuthAdministrationLockoutError, AuthAdministrationMissingError, AuthAlreadyInitializedError, AuthInitializerNotCreatorError, AuthPolicyNotPreservedError, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DOCUMENT_DELETED_REASON, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, DowngradeNotSupportedError, FileSystemError, GrantNotFoundError, GrantSchema, GroupPrincipalNotAllowedError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, InitializeAuthActionInputSchema, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, InvalidAuthVersionError, InvalidGrantError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, MAX_AUTH_GRANTS, MAX_CAPABILITY_OPERATIONS, MAX_CONDITION_DEPTH, MAX_CONDITION_NODES, MAX_SUPPORTED_AUTH_VERSION, ManifestSchema, ModuleSchema, MoveGrantActionInputSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, PwaConfigSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, RemoveGrantActionInputSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetGrantActionInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UnsupportedDocumentModelVersionError, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, appendWithoutApplying, applyAuthAction, applyDeleteDocumentAction, applyInitializeAuthAction, applyMoveGrantAction, applyRemoveGrantAction, applySetGrantAction, applyUpgradeDocumentAction, assertAuthAdministrationRetained, assertAuthPreservedOnDuplicate, assertAuthScopeActionAllowed, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, assertValidGrant, assertValidGrantUpsert, assertValidInitialGrants, attachBranch, backfillAuthState, base58Decode, base64UrlToBytes, baseActions, baseCreateDocument, baseLoadFromInput, baseLoadFromInputVersioned, baseReducer, baseReducerVersion, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, computeUpgradeTransitions, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, decide, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, deserializeSignature, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, evaluate, evaluateCondition, evaluateGrantStack, evaluateGrants, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, grantProblem, groupDocumentType, groupMembershipActionTypes, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, initializeAuth, isAuthAction, isDefinedNonNullAny, isDenied, isDocumentAction, isDocumentCreator, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isPlainValue, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, mentionedGroupIds, merge, moveGrant, moveOperation, nextSkipNumber, noop, normalizeDocumentModelVersion, operationExampleCreators, operationFromAction, operationFromOperation, operationOutcome, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, referencedGroupIds, releaseNewVersion, removeExistingOperations, removeGrant, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, resolveSnapshotAuth, serializeSignature, setAuthorName, setAuthorWebsite, setGrant, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, toTransportAction, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
3938
5109
|
|
|
3939
5110
|
//# sourceMappingURL=index.js.map
|