@powerhousedao/shared 6.2.2-dev.37 → 6.2.2-dev.38
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/{common-jbDGxlex.d.mts → common-B_LcTLHX.d.mts} +3 -3
- package/dist/clis/args/{common-jbDGxlex.d.mts.map → common-B_LcTLHX.d.mts.map} +1 -1
- package/dist/clis/args/common.d.mts +1 -1
- package/dist/clis/args/connect.d.mts +5 -5
- package/dist/clis/args/index.d.mts +1 -1
- package/dist/clis/args/init.d.mts +1 -1
- package/dist/clis/args/vetra.d.mts +1 -1
- package/dist/clis/build-config.d.mts +4 -4
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/index.d.mts +9 -9
- package/dist/connect/config-loader.d.ts +1 -1
- package/dist/connect/index.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-model/index.d.ts +3 -3
- package/dist/document-model/index.js +228 -33
- package/dist/document-model/index.js.map +1 -1
- package/dist/{index-OItp9eXf.d.ts → index-Dn1S-xxm.d.ts} +117 -12
- package/dist/index-Dn1S-xxm.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/manifest-slim.d.ts +1 -1
- package/dist/{types-aWKQyxzX.d.ts → types-C_b4aIlv.d.ts} +10 -6
- package/dist/types-C_b4aIlv.d.ts.map +1 -0
- package/dist/{types-C7IdvgpK.d.ts → types-DctifWUG.d.ts} +2 -2
- package/dist/{types-C7IdvgpK.d.ts.map → types-DctifWUG.d.ts.map} +1 -1
- package/package.json +1 -1
- package/dist/index-OItp9eXf.d.ts.map +0 -1
- package/dist/types-aWKQyxzX.d.ts.map +0 -1
|
@@ -1037,6 +1037,30 @@ var GroupPrincipalNotAllowedError = class extends Error {
|
|
|
1037
1037
|
this.grantId = grantId;
|
|
1038
1038
|
}
|
|
1039
1039
|
};
|
|
1040
|
+
/**
|
|
1041
|
+
* Thrown when a change would leave a creator-less policy with no grant
|
|
1042
|
+
* permitting execute on the auth scope. Without the creator carve-out no
|
|
1043
|
+
* subject could ever administer such a policy again.
|
|
1044
|
+
*/
|
|
1045
|
+
var AuthAdministrationLockoutError = class extends Error {
|
|
1046
|
+
grantId;
|
|
1047
|
+
constructor(grantId) {
|
|
1048
|
+
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`);
|
|
1049
|
+
this.name = "AuthAdministrationLockoutError";
|
|
1050
|
+
this.grantId = grantId;
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
/**
|
|
1054
|
+
* Thrown when INITIALIZE_AUTH would create a creator-less policy with no grant
|
|
1055
|
+
* permitting execute on the auth scope. Such a policy would be born with no
|
|
1056
|
+
* subject able to administer it.
|
|
1057
|
+
*/
|
|
1058
|
+
var AuthAdministrationMissingError = class extends Error {
|
|
1059
|
+
constructor() {
|
|
1060
|
+
super("Initial grants include no reachable grant permitting execute on the auth scope: a policy with no creator must always include one");
|
|
1061
|
+
this.name = "AuthAdministrationMissingError";
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1040
1064
|
const GRANT_KEYS = new Set([
|
|
1041
1065
|
"id",
|
|
1042
1066
|
"description",
|
|
@@ -1189,15 +1213,77 @@ function assertValidGrant(grant, documentType) {
|
|
|
1189
1213
|
if (problem !== null) throw new InvalidGrantError(grantId, problem);
|
|
1190
1214
|
if (documentType === "@powerhousedao/document-group" && "group" in grant.principal) throw new GroupPrincipalNotAllowedError(grantId);
|
|
1191
1215
|
}
|
|
1192
|
-
/**
|
|
1193
|
-
|
|
1216
|
+
/**
|
|
1217
|
+
* Validates an initial grant list: the count cap, every grant, and — on a
|
|
1218
|
+
* creator-less policy — that some grant keeps the auth scope administrable.
|
|
1219
|
+
*/
|
|
1220
|
+
function assertValidInitialGrants(grants, documentType, creator) {
|
|
1194
1221
|
if (grants.length > 100) throw new InvalidGrantError("", `policy exceeds 100 grants`);
|
|
1195
1222
|
for (const grant of grants) assertValidGrant(grant, documentType);
|
|
1223
|
+
if (creator === void 0 && !administrationReachable(grants)) throw new AuthAdministrationMissingError();
|
|
1196
1224
|
}
|
|
1197
|
-
/**
|
|
1198
|
-
|
|
1225
|
+
/**
|
|
1226
|
+
* Validates a grant upsert: the grant itself, the count cap on append, and
|
|
1227
|
+
* administration retention. Retention is checked on an append as well as an
|
|
1228
|
+
* in-place replace, because a grant appended after the administration grant can
|
|
1229
|
+
* shadow it (evaluation is last-applicable-grant-wins) and so take
|
|
1230
|
+
* administration away without removing anything.
|
|
1231
|
+
*/
|
|
1232
|
+
function assertValidGrantUpsert(grant, existing, documentType, creator) {
|
|
1199
1233
|
assertValidGrant(grant, documentType);
|
|
1200
|
-
|
|
1234
|
+
const exists = existing.some((g) => g.id === grant.id);
|
|
1235
|
+
if (!exists && existing.length >= 100) throw new InvalidGrantError(grant.id, `policy exceeds 100 grants`);
|
|
1236
|
+
assertAuthAdministrationRetained(creator, existing, exists ? existing.map((g) => g.id === grant.id ? grant : g) : [...existing, grant], grant.id);
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* The request whose coverage keeps a policy administrable: a subject who may
|
|
1240
|
+
* SET_GRANT can upsert any grant, so every other repair stays reachable.
|
|
1241
|
+
*/
|
|
1242
|
+
const AUTH_ADMINISTRATION_REQUEST = {
|
|
1243
|
+
verb: "execute",
|
|
1244
|
+
scope: "auth",
|
|
1245
|
+
operation: "SET_GRANT"
|
|
1246
|
+
};
|
|
1247
|
+
/**
|
|
1248
|
+
* Whether some subject can still administer the auth scope under this grant list.
|
|
1249
|
+
*
|
|
1250
|
+
* Asks the evaluator rather than pattern-matching a single grant: evaluation is
|
|
1251
|
+
* last-applicable-grant-wins, so an allow that some later deny shadows keeps
|
|
1252
|
+
* nothing reachable even though it is still present in the list. Only anyone and
|
|
1253
|
+
* address principals are candidates, because those are the ones v1 can match at
|
|
1254
|
+
* all; a `where` condition or a group or match principal never applies.
|
|
1255
|
+
*/
|
|
1256
|
+
function administrationReachable(grants) {
|
|
1257
|
+
return grants.some((grant) => {
|
|
1258
|
+
const subject = administrationCandidate(grant);
|
|
1259
|
+
if (subject === void 0) return false;
|
|
1260
|
+
return evaluateGrantStack(grants, subject, AUTH_ADMINISTRATION_REQUEST).decision === "allow";
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* The subject to test this grant with, or undefined when the grant could never
|
|
1265
|
+
* carry administration for anyone.
|
|
1266
|
+
*/
|
|
1267
|
+
function administrationCandidate(grant) {
|
|
1268
|
+
if (grant.effect !== "allow" || grant.where !== void 0 || !capabilityCovers(grant.capability, AUTH_ADMINISTRATION_REQUEST)) return;
|
|
1269
|
+
if ("address" in grant.principal) return {
|
|
1270
|
+
address: grant.principal.address,
|
|
1271
|
+
key: void 0
|
|
1272
|
+
};
|
|
1273
|
+
if ("anyone" in grant.principal) return {
|
|
1274
|
+
address: void 0,
|
|
1275
|
+
key: void 0
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* A creator-less policy must always retain a grant permitting execute on the
|
|
1280
|
+
* auth scope; on a signed document the creator carve-out keeps administration
|
|
1281
|
+
* reachable instead. Rejects a change that takes the last such grant away. A
|
|
1282
|
+
* policy already without one is left alone: the change is not what locks it.
|
|
1283
|
+
*/
|
|
1284
|
+
function assertAuthAdministrationRetained(creator, previous, next, grantId) {
|
|
1285
|
+
if (creator !== void 0) return;
|
|
1286
|
+
if (administrationReachable(previous) && !administrationReachable(next)) throw new AuthAdministrationLockoutError(grantId);
|
|
1201
1287
|
}
|
|
1202
1288
|
function capabilityCovers(capability, request) {
|
|
1203
1289
|
if (capability.can !== request.verb) return false;
|
|
@@ -1215,17 +1301,33 @@ function principalMatches(principal, subject) {
|
|
|
1215
1301
|
return false;
|
|
1216
1302
|
}
|
|
1217
1303
|
/**
|
|
1218
|
-
* Evaluates a v1 grant stack: default deny, last applicable grant wins
|
|
1219
|
-
* Group and match principals and `where`
|
|
1220
|
-
* grant that uses any of them never applies.
|
|
1304
|
+
* Evaluates a v1 grant stack: default deny, last applicable grant wins, and
|
|
1305
|
+
* reports which grant decided it. Group and match principals and `where`
|
|
1306
|
+
* conditions are not evaluated yet; a grant that uses any of them never applies.
|
|
1221
1307
|
*/
|
|
1222
|
-
function
|
|
1223
|
-
let
|
|
1308
|
+
function evaluateGrantStack(grants, subject, request) {
|
|
1309
|
+
let applicable;
|
|
1224
1310
|
for (const grant of grants) {
|
|
1225
1311
|
if (grant.where !== void 0) continue;
|
|
1226
|
-
if (capabilityCovers(grant.capability, request) && principalMatches(grant.principal, subject))
|
|
1312
|
+
if (capabilityCovers(grant.capability, request) && principalMatches(grant.principal, subject)) applicable = grant;
|
|
1227
1313
|
}
|
|
1228
|
-
return
|
|
1314
|
+
if (applicable === void 0) return {
|
|
1315
|
+
decision: "deny",
|
|
1316
|
+
refusal: "no-applicable-grant"
|
|
1317
|
+
};
|
|
1318
|
+
if (applicable.effect === "deny") return {
|
|
1319
|
+
decision: "deny",
|
|
1320
|
+
refusal: "denied-by-grant",
|
|
1321
|
+
grantId: applicable.id
|
|
1322
|
+
};
|
|
1323
|
+
return { decision: "allow" };
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Evaluates a v1 grant stack: default deny, last applicable grant wins. This is
|
|
1327
|
+
* {@link evaluateGrantStack} with the reason dropped.
|
|
1328
|
+
*/
|
|
1329
|
+
function evaluateGrants(grants, subject, request) {
|
|
1330
|
+
return evaluateGrantStack(grants, subject, request).decision;
|
|
1229
1331
|
}
|
|
1230
1332
|
//#endregion
|
|
1231
1333
|
//#region document-model/constants.ts
|
|
@@ -2003,6 +2105,8 @@ function isDocumentCreator(creatorKey, signerKey) {
|
|
|
2003
2105
|
* (version 0). The input version is the policy language version and must be an
|
|
2004
2106
|
* integer >= 1; 0 is reserved for the uninitialized state. On a signed-header
|
|
2005
2107
|
* document it must be signed by the document creator (`header.sig.publicKey`).
|
|
2108
|
+
* A creator-less policy must include a grant permitting execute on the auth
|
|
2109
|
+
* scope, or it would be born locked out.
|
|
2006
2110
|
*/
|
|
2007
2111
|
function applyInitializeAuthAction(document, action) {
|
|
2008
2112
|
assertActionInputShape(action.input);
|
|
@@ -2010,12 +2114,12 @@ function applyInitializeAuthAction(document, action) {
|
|
|
2010
2114
|
if (!Number.isInteger(version) || version < 1) throw new InvalidAuthVersionError(document.header.id, version);
|
|
2011
2115
|
if (document.state.auth.version !== 0) throw new AuthAlreadyInitializedError(document.header.id);
|
|
2012
2116
|
if (!Array.isArray(grants)) throw new InvalidActionInputError({ grants: "must be an array" });
|
|
2013
|
-
assertValidInitialGrants(grants, document.header.documentType);
|
|
2014
2117
|
const creatorKey = document.header.sig.publicKey;
|
|
2015
2118
|
const signerKey = action.context?.signer?.app.key;
|
|
2016
2119
|
const hasCreator = Boolean(creatorKey.kty || creatorKey.x || creatorKey.y);
|
|
2017
2120
|
if (hasCreator && !isDocumentCreator(creatorKey, signerKey)) throw new AuthInitializerNotCreatorError(document.header.id);
|
|
2018
2121
|
const creator = hasCreator ? signerKey : void 0;
|
|
2122
|
+
assertValidInitialGrants(grants, document.header.documentType, creator);
|
|
2019
2123
|
return {
|
|
2020
2124
|
...document,
|
|
2021
2125
|
state: {
|
|
@@ -2036,32 +2140,42 @@ function applySetGrantAction(document, action) {
|
|
|
2036
2140
|
assertActionInputShape(action.input);
|
|
2037
2141
|
const { grant } = action.input;
|
|
2038
2142
|
const grants = document.state.auth.grants;
|
|
2039
|
-
assertValidGrantUpsert(grant, grants, document.header.documentType);
|
|
2143
|
+
assertValidGrantUpsert(grant, grants, document.header.documentType, document.state.auth.creator);
|
|
2040
2144
|
return withGrants(document, grants.some((g) => g.id === grant.id) ? grants.map((g) => g.id === grant.id ? grant : g) : [...grants, grant]);
|
|
2041
2145
|
}
|
|
2042
|
-
/**
|
|
2146
|
+
/**
|
|
2147
|
+
* Removes a grant by id; throws if the id is not present or if the removal
|
|
2148
|
+
* would leave a creator-less policy with no auth-administration grant.
|
|
2149
|
+
*/
|
|
2043
2150
|
function applyRemoveGrantAction(document, action) {
|
|
2044
2151
|
assertActionInputShape(action.input);
|
|
2045
2152
|
const { id } = action.input;
|
|
2046
|
-
const grants = document.state.auth
|
|
2153
|
+
const { grants, creator } = document.state.auth;
|
|
2047
2154
|
if (!grants.some((g) => g.id === id)) throw new GrantNotFoundError(id);
|
|
2048
|
-
|
|
2155
|
+
const next = grants.filter((g) => g.id !== id);
|
|
2156
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2157
|
+
return withGrants(document, next);
|
|
2049
2158
|
}
|
|
2050
2159
|
/**
|
|
2051
2160
|
* Moves a grant by id to a new index. Order is load-bearing (the last
|
|
2052
2161
|
* applicable grant wins), so the relative order of the other grants is kept.
|
|
2053
2162
|
* The target index is clamped to the valid range; an unknown id throws.
|
|
2163
|
+
*
|
|
2164
|
+
* Order alone decides which grant wins, so a move can take administration away
|
|
2165
|
+
* without changing the list's contents. It carries the same retention rule as
|
|
2166
|
+
* the two mutation paths.
|
|
2054
2167
|
*/
|
|
2055
2168
|
function applyMoveGrantAction(document, action) {
|
|
2056
2169
|
assertActionInputShape(action.input);
|
|
2057
2170
|
const { id, index } = action.input;
|
|
2058
|
-
const grants = document.state.auth
|
|
2171
|
+
const { grants, creator } = document.state.auth;
|
|
2059
2172
|
const from = grants.findIndex((g) => g.id === id);
|
|
2060
2173
|
if (from === -1) throw new GrantNotFoundError(id);
|
|
2061
2174
|
const next = [...grants];
|
|
2062
2175
|
const [moved] = next.splice(from, 1);
|
|
2063
2176
|
const to = Math.max(0, Math.min(index, next.length));
|
|
2064
2177
|
next.splice(to, 0, moved);
|
|
2178
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2065
2179
|
return withGrants(document, next);
|
|
2066
2180
|
}
|
|
2067
2181
|
/**
|
|
@@ -2087,6 +2201,42 @@ function assertAuthPreservedOnDuplicate(documentId, source, duplicated) {
|
|
|
2087
2201
|
if (!source || source.version === 0) return;
|
|
2088
2202
|
if (duplicated === void 0 || duplicated.version !== source.version || duplicated.creator !== source.creator) throw new AuthPolicyNotPreservedError(documentId);
|
|
2089
2203
|
}
|
|
2204
|
+
/**
|
|
2205
|
+
* The auth scope a state snapshot may install, given the policy already there.
|
|
2206
|
+
*
|
|
2207
|
+
* `applyAuthAction` is the validated door onto `state.auth`, but a whole-state
|
|
2208
|
+
* snapshot (UPGRADE_DOCUMENT's `initialState`, LOAD_STATE's `data`) replaces the
|
|
2209
|
+
* scope wholesale and is authorized as a `document`-scope write. Without this,
|
|
2210
|
+
* a subject holding `execute` on `document` and no auth grant at all can install
|
|
2211
|
+
* a policy of its choosing, name itself `creator` (which exempts the policy from
|
|
2212
|
+
* the retention rule for good), or wipe an existing policy by carrying the
|
|
2213
|
+
* default uninitialized one.
|
|
2214
|
+
*
|
|
2215
|
+
* Three cases:
|
|
2216
|
+
*
|
|
2217
|
+
* - the snapshot carries no policy, or an uninitialized one: the document
|
|
2218
|
+
* keeps the policy it has, so a default-state upgrade cannot reset it;
|
|
2219
|
+
* - the document is uninitialized and the snapshot carries a policy: the
|
|
2220
|
+
* policy is installed after the same validation genesis applies, so it
|
|
2221
|
+
* cannot be born locked out;
|
|
2222
|
+
* - both carry a policy: they must agree. A duplicate preserves its source's
|
|
2223
|
+
* policy (see {@link assertAuthPreservedOnDuplicate}), and anything else is
|
|
2224
|
+
* an attempt to replace one policy with another.
|
|
2225
|
+
*/
|
|
2226
|
+
function resolveSnapshotAuth(documentId, documentType, current, incoming) {
|
|
2227
|
+
const currentAuth = current ?? createAuthState({
|
|
2228
|
+
version: 0,
|
|
2229
|
+
grants: []
|
|
2230
|
+
});
|
|
2231
|
+
if (!incoming || !incoming.version) return currentAuth;
|
|
2232
|
+
if (currentAuth.version !== 0) {
|
|
2233
|
+
if (stringify(incoming) !== stringify(currentAuth)) throw new AuthPolicyNotPreservedError(documentId);
|
|
2234
|
+
return incoming;
|
|
2235
|
+
}
|
|
2236
|
+
if (!Array.isArray(incoming.grants)) throw new InvalidActionInputError({ grants: "must be an array" });
|
|
2237
|
+
assertValidInitialGrants(incoming.grants, documentType, incoming.creator);
|
|
2238
|
+
return incoming;
|
|
2239
|
+
}
|
|
2090
2240
|
/** UNDO, REDO and PRUNE are rejected on the auth scope. */
|
|
2091
2241
|
function assertAuthScopeActionAllowed(action) {
|
|
2092
2242
|
if (action.scope === "auth" && [
|
|
@@ -2096,19 +2246,47 @@ function assertAuthScopeActionAllowed(action) {
|
|
|
2096
2246
|
].includes(action.type)) throw new AuthActionNotAllowedError(action.type);
|
|
2097
2247
|
}
|
|
2098
2248
|
/**
|
|
2099
|
-
* Evaluates the auth policy for a single request
|
|
2249
|
+
* Evaluates the auth policy for a single request and reports why it refused.
|
|
2250
|
+
* Pure and deterministic.
|
|
2100
2251
|
*
|
|
2101
2252
|
* An uninitialized policy (version 0, absent auth state, or a legacy `{}`
|
|
2102
2253
|
* auth scope serialized before PHAuthState had a version) leaves the document
|
|
2103
2254
|
* open. Once a policy exists the default is deny, and grants stack in order.
|
|
2104
2255
|
*/
|
|
2256
|
+
function evaluate(auth, subject, request) {
|
|
2257
|
+
if (!auth || !auth.version) return { decision: "allow" };
|
|
2258
|
+
if (request.verb === "execute" && request.scope === "auth" && subject.key !== void 0 && subject.key === auth.creator) return { decision: "allow" };
|
|
2259
|
+
if (auth.version > 1) return {
|
|
2260
|
+
decision: "deny",
|
|
2261
|
+
refusal: "version-unsupported"
|
|
2262
|
+
};
|
|
2263
|
+
return evaluateGrantStack(auth.grants, subject, request);
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Evaluates the auth policy for a single request. Pure and deterministic. This
|
|
2267
|
+
* is {@link evaluate} with the reason dropped.
|
|
2268
|
+
*/
|
|
2105
2269
|
function decide(auth, subject, request) {
|
|
2106
|
-
|
|
2107
|
-
if (request.verb === "execute" && request.scope === "auth" && subject.key !== void 0 && subject.key === auth.creator) return "allow";
|
|
2108
|
-
if (auth.version > 1) return "deny";
|
|
2109
|
-
return evaluateGrants(auth.grants, subject, request);
|
|
2270
|
+
return evaluate(auth, subject, request).decision;
|
|
2110
2271
|
}
|
|
2111
2272
|
//#endregion
|
|
2273
|
+
//#region document-model/denied.ts
|
|
2274
|
+
/**
|
|
2275
|
+
* True iff authorization rejected the action.
|
|
2276
|
+
*/
|
|
2277
|
+
function isDenied(operation) {
|
|
2278
|
+
return operation.deniedReason !== void 0;
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* The closed set of strings persisted as `deniedReason`. Re-evaluation compares
|
|
2282
|
+
* them, so they are consensus data: exact strings that embed no grant id,
|
|
2283
|
+
* subject or timestamp. Changing one is history-visible.
|
|
2284
|
+
*/
|
|
2285
|
+
const DOCUMENT_DELETED_REASON = "document deleted";
|
|
2286
|
+
const AUTH_VERSION_UNSUPPORTED_REASON = "auth policy version unsupported";
|
|
2287
|
+
const AUTH_NO_GRANT_REASON = "no grant permits this operation";
|
|
2288
|
+
const AUTH_DENIED_BY_GRANT_REASON = "denied by grant";
|
|
2289
|
+
//#endregion
|
|
2112
2290
|
//#region document-model/document-schema.ts
|
|
2113
2291
|
const BaseDocumentHeaderSchema = z.object({
|
|
2114
2292
|
id: z.string(),
|
|
@@ -2507,6 +2685,22 @@ function sortMappedOperations(operations) {
|
|
|
2507
2685
|
const defaultCreateState = (state) => {
|
|
2508
2686
|
return state;
|
|
2509
2687
|
};
|
|
2688
|
+
/**
|
|
2689
|
+
* Records an operation in the history without applying it, which is what a
|
|
2690
|
+
* denied operation needs: it occupies its index and contributes no state.
|
|
2691
|
+
*
|
|
2692
|
+
* The scope defaults to the action's own, and is passed explicitly by a rebuild
|
|
2693
|
+
* that is walking one stream and does not want to trust the action's copy.
|
|
2694
|
+
*/
|
|
2695
|
+
function appendWithoutApplying(document, operation, scope = operation.action.scope) {
|
|
2696
|
+
return {
|
|
2697
|
+
...document,
|
|
2698
|
+
operations: {
|
|
2699
|
+
...document.operations,
|
|
2700
|
+
[scope]: [...document.operations[scope] ?? [], operation]
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2510
2704
|
function replayDocument(initialState, operations, reducer, header, dispatch, skipHeaderOperations = {}, options) {
|
|
2511
2705
|
const { checkHashes = true, reuseOperationResultingState, operationResultingStateParser = parseResultingState, skipIndexValidation } = options || {};
|
|
2512
2706
|
const backfilledInitialState = backfillAuthState(initialState);
|
|
@@ -2551,6 +2745,7 @@ function replayDocument(initialState, operations, reducer, header, dispatch, ski
|
|
|
2551
2745
|
};
|
|
2552
2746
|
let result = document;
|
|
2553
2747
|
if (operationsToReplay.length) result = operationsToReplay.reduce((document, operation) => {
|
|
2748
|
+
if (isDenied(operation)) return appendWithoutApplying(document, operation);
|
|
2554
2749
|
return reducer(document, operation.action, dispatch, {
|
|
2555
2750
|
ignoreSkipOperations: true,
|
|
2556
2751
|
checkHashes,
|
|
@@ -3074,13 +3269,15 @@ function redoOperation(document, action, skip) {
|
|
|
3074
3269
|
});
|
|
3075
3270
|
}
|
|
3076
3271
|
function loadStateOperation(document, action) {
|
|
3272
|
+
const loaded = backfillAuthState(action.state.data);
|
|
3273
|
+
loaded.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, loaded.auth);
|
|
3077
3274
|
return {
|
|
3078
3275
|
...document,
|
|
3079
3276
|
header: {
|
|
3080
3277
|
...document.header,
|
|
3081
3278
|
name: action.state.name
|
|
3082
3279
|
},
|
|
3083
|
-
state:
|
|
3280
|
+
state: loaded
|
|
3084
3281
|
};
|
|
3085
3282
|
}
|
|
3086
3283
|
/**
|
|
@@ -3098,12 +3295,6 @@ function operationOutcome(operation) {
|
|
|
3098
3295
|
};
|
|
3099
3296
|
return { kind: "applied" };
|
|
3100
3297
|
}
|
|
3101
|
-
/**
|
|
3102
|
-
* True iff authorization rejected the action.
|
|
3103
|
-
*/
|
|
3104
|
-
function isDenied(operation) {
|
|
3105
|
-
return operation.deniedReason !== void 0;
|
|
3106
|
-
}
|
|
3107
3298
|
//#endregion
|
|
3108
3299
|
//#region document-model/reducer.ts
|
|
3109
3300
|
function replayOperations(initialState, clearedOperations, stateReducer, header, dispatch, documentReducer = baseReducer, skipHeaderOperations = {}, options) {
|
|
@@ -4131,10 +4322,12 @@ function applyInitialState(document, action) {
|
|
|
4131
4322
|
const input = action.input;
|
|
4132
4323
|
const newState = input.initialState || input.state;
|
|
4133
4324
|
if (newState) {
|
|
4134
|
-
|
|
4325
|
+
const merged = backfillAuthState({
|
|
4135
4326
|
...document.state,
|
|
4136
4327
|
...newState
|
|
4137
4328
|
});
|
|
4329
|
+
merged.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, merged.auth);
|
|
4330
|
+
document.state = merged;
|
|
4138
4331
|
document.initialState = document.state;
|
|
4139
4332
|
}
|
|
4140
4333
|
}
|
|
@@ -4314,7 +4507,8 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
4314
4507
|
const segEnd = k < validatedUpgrades.length ? boundaries[k]?.[s] ?? ops.length : ops.length;
|
|
4315
4508
|
const segOps = ops.slice(segStart, segEnd);
|
|
4316
4509
|
for (const op of segOps) {
|
|
4317
|
-
document =
|
|
4510
|
+
if (isDenied(op)) document = appendWithoutApplying(document, op, s);
|
|
4511
|
+
else document = reducer(document, op.action, dispatch, {
|
|
4318
4512
|
ignoreSkipOperations: true,
|
|
4319
4513
|
checkHashes,
|
|
4320
4514
|
skipIndexValidation,
|
|
@@ -4331,6 +4525,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
4331
4525
|
if (!spineOp) continue;
|
|
4332
4526
|
const spineActionType = spineOp.action.type;
|
|
4333
4527
|
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
4528
|
+
if (isDenied(spineOp)) continue;
|
|
4334
4529
|
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
4335
4530
|
else document = reducer(document, spineOp.action, dispatch, {
|
|
4336
4531
|
ignoreSkipOperations: true,
|
|
@@ -4547,6 +4742,6 @@ const getFileBrowser = (file) => {
|
|
|
4547
4742
|
return Promise.resolve().then(() => readFileBrowser(file));
|
|
4548
4743
|
};
|
|
4549
4744
|
//#endregion
|
|
4550
|
-
export { AUTH_ACTION_TYPES, AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthActionNotAllowedError, AuthAlreadyInitializedError, AuthInitializerNotCreatorError, AuthPolicyNotPreservedError, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, 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, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, applyAuthAction, applyDeleteDocumentAction, applyInitializeAuthAction, applyMoveGrantAction, applyRemoveGrantAction, applySetGrantAction, applyUpgradeDocumentAction, 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, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, evaluateGrants, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, grantProblem, groupDocumentType, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, initializeAuth, isAuthAction, isDefinedNonNullAny, isDenied, isDocumentAction, isDocumentCreator, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isPlainValue, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveGrant, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationOutcome, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, removeGrant, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, 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, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
4745
|
+
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, 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, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, evaluate, evaluateGrantStack, evaluateGrants, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, grantProblem, groupDocumentType, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, initializeAuth, isAuthAction, isDefinedNonNullAny, isDenied, isDocumentAction, isDocumentCreator, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isPlainValue, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveGrant, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationOutcome, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, removeGrant, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, resolveSnapshotAuth, 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, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
4551
4746
|
|
|
4552
4747
|
//# sourceMappingURL=index.js.map
|