@powerhousedao/shared 6.2.2-dev.4 → 6.2.2-dev.41
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.mjs +1 -1
- package/dist/clis/args/{common-DfMf08ur.d.mts → common-B_LcTLHX.d.mts} +7 -4
- package/dist/clis/args/{common-DfMf08ur.d.mts.map → common-B_LcTLHX.d.mts.map} +1 -1
- 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.d.mts +2 -2
- package/dist/clis/args/common.mjs +2 -2
- package/dist/clis/args/connect.d.mts +14 -5
- package/dist/clis/args/connect.d.mts.map +1 -1
- package/dist/clis/args/connect.mjs +2 -1
- package/dist/clis/args/connect.mjs.map +1 -1
- package/dist/clis/args/{generate-Cs5okckF.mjs → generate-CQ78RxVS.mjs} +2 -2
- package/dist/clis/args/{generate-Cs5okckF.mjs.map → generate-CQ78RxVS.mjs.map} +1 -1
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-BkF9Cxud.mjs → help-Dk-d57W1.mjs} +3 -3
- package/dist/clis/args/{help-BkF9Cxud.mjs.map → help-Dk-d57W1.mjs.map} +1 -1
- package/dist/clis/args/help.mjs +1 -1
- package/dist/clis/args/index.d.mts +2 -2
- package/dist/clis/args/index.mjs +4 -4
- package/dist/clis/args/init.mjs +1 -1
- package/dist/clis/args/inspect.mjs +1 -1
- package/dist/clis/args/install.mjs +1 -1
- package/dist/clis/args/list.mjs +1 -1
- package/dist/clis/args/login.mjs +1 -1
- package/dist/clis/args/migrate.mjs +1 -1
- package/dist/clis/args/publish.mjs +1 -1
- package/dist/clis/args/registry.mjs +1 -1
- package/dist/clis/args/service.mjs +1 -1
- package/dist/clis/args/switchboard.mjs +1 -1
- package/dist/clis/args/uninstall.mjs +1 -1
- package/dist/clis/args/unpublish.mjs +1 -1
- package/dist/clis/args/vetra.d.mts +1 -1
- package/dist/clis/args/vetra.mjs +1 -1
- 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 +156 -49
- package/dist/clis/constants.d.mts.map +1 -1
- package/dist/clis/constants.mjs +6 -2
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index.d.mts +423 -5
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +258 -3
- package/dist/clis/index.mjs.map +1 -1
- package/dist/connect/config-loader.d.ts +2 -1
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/index.d.ts +399 -2
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +465 -1
- 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-drive/index.d.ts.map +1 -1
- package/dist/document-model/index.d.ts +5 -5
- package/dist/document-model/index.js +935 -126
- package/dist/document-model/index.js.map +1 -1
- package/dist/document-model/mock.d.ts +1 -1
- package/dist/document-model/mock.js +32 -3
- package/dist/document-model/mock.js.map +1 -1
- package/dist/document-model/utils.d.ts +2 -2
- package/dist/document-model/utils.js +1 -1
- package/dist/{index-CQDIrK1k.d.ts → index-BJU79_T5.d.ts} +1 -1
- package/dist/index-BJU79_T5.d.ts.map +1 -0
- package/dist/{index-DLx4nU83.d.ts → index-Dn1S-xxm.d.ts} +310 -3
- package/dist/index-Dn1S-xxm.d.ts.map +1 -0
- package/dist/index.d.ts +5 -6
- package/dist/mock-BcFWPQyK.d.ts +22 -0
- package/dist/mock-BcFWPQyK.d.ts.map +1 -0
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +5 -4
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +5 -4
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +1 -1
- package/dist/registry/manifest-slim.d.ts.map +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-Bo4Rb8Yf.d.ts → types-C_b4aIlv.d.ts} +404 -12
- package/dist/types-C_b4aIlv.d.ts.map +1 -0
- package/dist/{types-CgGSyOl6.d.ts → types-DctifWUG.d.ts} +32 -3
- package/dist/{types-CgGSyOl6.d.ts.map → types-DctifWUG.d.ts.map} +1 -1
- package/dist/{utils-BEByNOHo.d.ts → utils-1EXU6Qr1.d.ts} +1 -1
- package/dist/utils-1EXU6Qr1.d.ts.map +1 -0
- package/dist/{utils-DKOFCM0Q.js → utils-CTt1XRn-.js} +36 -2
- package/dist/utils-CTt1XRn-.js.map +1 -0
- package/package.json +1 -1
- package/dist/clis/args/common-dbsvksvf.mjs.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-DLx4nU83.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-Bo4Rb8Yf.d.ts.map +0 -1
- package/dist/types-D0NNBVGA.d.ts +0 -167
- package/dist/types-D0NNBVGA.d.ts.map +0 -1
- package/dist/utils-BEByNOHo.d.ts.map +0 -1
- package/dist/utils-DKOFCM0Q.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as base64UrlToBytes, c as getUnixTimestamp, i as base58Decode, l as hashBrowser, n as generateId, o as buildOperationSignatureMessage, r as ab2hex, s as buildOperationSignatureParams, t as deriveOperationId, u as hex2ab } from "../utils-CTt1XRn-.js";
|
|
2
2
|
import { generateMock } from "./mock.js";
|
|
3
3
|
import { ZodError, z } from "zod";
|
|
4
4
|
import { stringify } from "safe-stable-stringify";
|
|
@@ -39,6 +39,75 @@ var DowngradeNotSupportedError = class extends Error {
|
|
|
39
39
|
this.toVersion = toVersion;
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when INITIALIZE_AUTH is applied to an already-initialized auth scope.
|
|
44
|
+
* The genesis action is valid only at auth revision zero.
|
|
45
|
+
*/
|
|
46
|
+
var AuthAlreadyInitializedError = class extends Error {
|
|
47
|
+
documentId;
|
|
48
|
+
constructor(documentId) {
|
|
49
|
+
super(`Auth scope already initialized for document ${documentId}: INITIALIZE_AUTH is valid only at auth revision zero`);
|
|
50
|
+
this.name = "AuthAlreadyInitializedError";
|
|
51
|
+
this.documentId = documentId;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Thrown when INITIALIZE_AUTH is not signed by the document creator (its signer
|
|
56
|
+
* does not match `header.sig.publicKey`), so it cannot set the auth policy.
|
|
57
|
+
*/
|
|
58
|
+
var AuthInitializerNotCreatorError = class extends Error {
|
|
59
|
+
documentId;
|
|
60
|
+
constructor(documentId) {
|
|
61
|
+
super(`INITIALIZE_AUTH for document ${documentId} must be signed by the document creator`);
|
|
62
|
+
this.name = "AuthInitializerNotCreatorError";
|
|
63
|
+
this.documentId = documentId;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when INITIALIZE_AUTH carries a version below 1. Version 0 is reserved
|
|
68
|
+
* for the uninitialized auth scope.
|
|
69
|
+
*/
|
|
70
|
+
var InvalidAuthVersionError = class extends Error {
|
|
71
|
+
documentId;
|
|
72
|
+
version;
|
|
73
|
+
constructor(documentId, version) {
|
|
74
|
+
super(`Invalid auth policy version ${version} for document ${documentId}: INITIALIZE_AUTH requires an integer version >= 1`);
|
|
75
|
+
this.name = "InvalidAuthVersionError";
|
|
76
|
+
this.documentId = documentId;
|
|
77
|
+
this.version = version;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/** Thrown when a duplicate would lose the source policy's version or creator binding. */
|
|
81
|
+
var AuthPolicyNotPreservedError = class extends Error {
|
|
82
|
+
documentId;
|
|
83
|
+
constructor(documentId) {
|
|
84
|
+
super(`Duplicating document ${documentId} would not preserve its auth policy: the copy loses the policy version or its creator binding`);
|
|
85
|
+
this.name = "AuthPolicyNotPreservedError";
|
|
86
|
+
this.documentId = documentId;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Thrown when a grant referenced by REMOVE_GRANT or MOVE_GRANT does not exist.
|
|
91
|
+
*/
|
|
92
|
+
var GrantNotFoundError = class extends Error {
|
|
93
|
+
grantId;
|
|
94
|
+
constructor(grantId) {
|
|
95
|
+
super(`Grant not found in auth scope: ${grantId}`);
|
|
96
|
+
this.name = "GrantNotFoundError";
|
|
97
|
+
this.grantId = grantId;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Thrown when a disallowed action (UNDO, REDO, PRUNE) targets the auth scope.
|
|
102
|
+
*/
|
|
103
|
+
var AuthActionNotAllowedError = class extends Error {
|
|
104
|
+
actionType;
|
|
105
|
+
constructor(actionType) {
|
|
106
|
+
super(`${actionType} is not permitted on the auth scope`);
|
|
107
|
+
this.name = "AuthActionNotAllowedError";
|
|
108
|
+
this.actionType = actionType;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
42
111
|
var HashMismatchError = class extends Error {
|
|
43
112
|
_scope;
|
|
44
113
|
_document;
|
|
@@ -553,17 +622,102 @@ const ConfigEntrySchema = z.object({
|
|
|
553
622
|
required: z.boolean().optional(),
|
|
554
623
|
default: z.boolean().optional()
|
|
555
624
|
});
|
|
625
|
+
const PwaUrlPatternSchema = z.union([z.string(), z.strictObject({
|
|
626
|
+
source: z.string(),
|
|
627
|
+
flags: z.string().optional()
|
|
628
|
+
}).refine((p) => {
|
|
629
|
+
try {
|
|
630
|
+
new RegExp(p.source, p.flags);
|
|
631
|
+
return true;
|
|
632
|
+
} catch {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
}, { message: "source/flags do not compile to a valid RegExp" })]);
|
|
636
|
+
const PwaRuntimeCachingSchema = z.strictObject({
|
|
637
|
+
urlPattern: PwaUrlPatternSchema,
|
|
638
|
+
handler: z.enum([
|
|
639
|
+
"CacheFirst",
|
|
640
|
+
"CacheOnly",
|
|
641
|
+
"NetworkFirst",
|
|
642
|
+
"NetworkOnly",
|
|
643
|
+
"StaleWhileRevalidate"
|
|
644
|
+
]),
|
|
645
|
+
method: z.enum([
|
|
646
|
+
"GET",
|
|
647
|
+
"POST",
|
|
648
|
+
"PUT",
|
|
649
|
+
"DELETE",
|
|
650
|
+
"HEAD",
|
|
651
|
+
"PATCH"
|
|
652
|
+
]).optional(),
|
|
653
|
+
options: z.strictObject({
|
|
654
|
+
cacheName: z.string().optional(),
|
|
655
|
+
networkTimeoutSeconds: z.number().optional(),
|
|
656
|
+
expiration: z.strictObject({
|
|
657
|
+
maxEntries: z.number().optional(),
|
|
658
|
+
maxAgeSeconds: z.number().optional()
|
|
659
|
+
}).optional(),
|
|
660
|
+
cacheableResponse: z.strictObject({
|
|
661
|
+
statuses: z.array(z.number()).optional(),
|
|
662
|
+
headers: z.record(z.string(), z.string()).optional()
|
|
663
|
+
}).optional()
|
|
664
|
+
}).optional()
|
|
665
|
+
});
|
|
666
|
+
const PwaIconSchema = z.strictObject({
|
|
667
|
+
src: z.string(),
|
|
668
|
+
sizes: z.string().optional(),
|
|
669
|
+
type: z.string().optional(),
|
|
670
|
+
purpose: z.string().optional()
|
|
671
|
+
});
|
|
672
|
+
const PwaFileHandlerSchema = z.strictObject({
|
|
673
|
+
accept: z.record(z.string(), z.array(z.string().regex(/^\./, "file extensions must start with '.'"))),
|
|
674
|
+
icons: z.array(PwaIconSchema).optional(),
|
|
675
|
+
launch_type: z.enum(["single-client", "multiple-clients"]).optional()
|
|
676
|
+
});
|
|
677
|
+
const PwaManifestOverrideSchema = z.strictObject({
|
|
678
|
+
name: z.string().optional(),
|
|
679
|
+
short_name: z.string().optional(),
|
|
680
|
+
description: z.string().optional(),
|
|
681
|
+
theme_color: z.string().optional(),
|
|
682
|
+
background_color: z.string().optional(),
|
|
683
|
+
display: z.enum([
|
|
684
|
+
"fullscreen",
|
|
685
|
+
"standalone",
|
|
686
|
+
"minimal-ui",
|
|
687
|
+
"browser"
|
|
688
|
+
]).optional(),
|
|
689
|
+
start_url: z.string().optional(),
|
|
690
|
+
scope: z.string().optional(),
|
|
691
|
+
icons: z.array(PwaIconSchema).optional(),
|
|
692
|
+
file_handlers: z.array(PwaFileHandlerSchema).optional(),
|
|
693
|
+
launch_handler: z.strictObject({ client_mode: z.enum([
|
|
694
|
+
"auto",
|
|
695
|
+
"focus-existing",
|
|
696
|
+
"navigate-existing",
|
|
697
|
+
"navigate-new"
|
|
698
|
+
]) }).optional()
|
|
699
|
+
});
|
|
700
|
+
const PwaConfigSchema = z.strictObject({
|
|
701
|
+
manifest: PwaManifestOverrideSchema.optional(),
|
|
702
|
+
globPatterns: z.array(z.string()).optional(),
|
|
703
|
+
globIgnores: z.array(z.string()).optional(),
|
|
704
|
+
maximumFileSizeToCacheInBytes: z.number().optional(),
|
|
705
|
+
runtimeCaching: z.array(PwaRuntimeCachingSchema).optional(),
|
|
706
|
+
navigateFallbackDenylist: z.array(PwaUrlPatternSchema).optional()
|
|
707
|
+
});
|
|
556
708
|
const ManifestSchema = z.object({
|
|
557
709
|
name: z.string(),
|
|
558
710
|
description: z.string().optional(),
|
|
559
711
|
category: z.string().optional(),
|
|
712
|
+
image: z.string().optional(),
|
|
560
713
|
publisher: PublisherSchema.optional(),
|
|
561
714
|
documentModels: PowerhouseModulesSchema,
|
|
562
715
|
apps: PowerhouseModulesSchema,
|
|
563
716
|
editors: PowerhouseModulesSchema,
|
|
564
717
|
processors: PowerhouseModulesSchema,
|
|
565
718
|
subgraphs: PowerhouseModulesSchema,
|
|
566
|
-
config: z.array(ConfigEntrySchema).optional()
|
|
719
|
+
config: z.array(ConfigEntrySchema).optional(),
|
|
720
|
+
pwa: PwaConfigSchema.optional()
|
|
567
721
|
});
|
|
568
722
|
//#endregion
|
|
569
723
|
//#region document-model/actions.ts
|
|
@@ -849,6 +1003,333 @@ const actions = {
|
|
|
849
1003
|
...documentModelActions
|
|
850
1004
|
};
|
|
851
1005
|
//#endregion
|
|
1006
|
+
//#region document-model/document-type.ts
|
|
1007
|
+
const documentModelDocumentType = "powerhouse/document-model";
|
|
1008
|
+
const groupDocumentType = "@powerhousedao/document-group";
|
|
1009
|
+
//#endregion
|
|
1010
|
+
//#region document-model/auth-v1.ts
|
|
1011
|
+
/** Maximum number of grants in a policy. */
|
|
1012
|
+
const MAX_AUTH_GRANTS = 100;
|
|
1013
|
+
/** Maximum nesting depth of a condition tree. */
|
|
1014
|
+
const MAX_CONDITION_DEPTH = 10;
|
|
1015
|
+
/** Maximum node count (conditions plus operands) of a condition tree. */
|
|
1016
|
+
const MAX_CONDITION_NODES = 100;
|
|
1017
|
+
/** Maximum entries in an execute capability's operation list. */
|
|
1018
|
+
const MAX_CAPABILITY_OPERATIONS = 100;
|
|
1019
|
+
/**
|
|
1020
|
+
* Thrown when a grant violates the v1 validation rules. The message is stored
|
|
1021
|
+
* on error operations, so it must be a pure function of the input.
|
|
1022
|
+
*/
|
|
1023
|
+
var InvalidGrantError = class extends Error {
|
|
1024
|
+
grantId;
|
|
1025
|
+
constructor(grantId, problem) {
|
|
1026
|
+
super(`Invalid grant "${grantId}": ${problem}`);
|
|
1027
|
+
this.name = "InvalidGrantError";
|
|
1028
|
+
this.grantId = grantId;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
/** Thrown for a `{ group }` principal on a group document: references never chain. */
|
|
1032
|
+
var GroupPrincipalNotAllowedError = class extends Error {
|
|
1033
|
+
grantId;
|
|
1034
|
+
constructor(grantId) {
|
|
1035
|
+
super(`Grant "${grantId}" uses a group principal on a group document: a group's auth scope cannot reference other groups`);
|
|
1036
|
+
this.name = "GroupPrincipalNotAllowedError";
|
|
1037
|
+
this.grantId = grantId;
|
|
1038
|
+
}
|
|
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
|
+
};
|
|
1064
|
+
const GRANT_KEYS = new Set([
|
|
1065
|
+
"id",
|
|
1066
|
+
"description",
|
|
1067
|
+
"effect",
|
|
1068
|
+
"principal",
|
|
1069
|
+
"capability",
|
|
1070
|
+
"where"
|
|
1071
|
+
]);
|
|
1072
|
+
const PRINCIPAL_KINDS = new Set([
|
|
1073
|
+
"anyone",
|
|
1074
|
+
"address",
|
|
1075
|
+
"group",
|
|
1076
|
+
"match"
|
|
1077
|
+
]);
|
|
1078
|
+
const COMPARISON_CONDITION_KINDS = new Set([
|
|
1079
|
+
"eq",
|
|
1080
|
+
"ne",
|
|
1081
|
+
"lt",
|
|
1082
|
+
"lte",
|
|
1083
|
+
"gt",
|
|
1084
|
+
"gte"
|
|
1085
|
+
]);
|
|
1086
|
+
function isPlainValue(value) {
|
|
1087
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1088
|
+
}
|
|
1089
|
+
function operandProblem(value, capabilityScope, budget) {
|
|
1090
|
+
budget.nodes -= 1;
|
|
1091
|
+
if (budget.nodes < 0) return `condition exceeds 100 nodes`;
|
|
1092
|
+
if (!isPlainValue(value)) return "operand must be an object";
|
|
1093
|
+
const keys = Object.keys(value);
|
|
1094
|
+
if (keys.length !== 1) return "operand must have exactly one of attr or lit";
|
|
1095
|
+
if (keys[0] === "attr") {
|
|
1096
|
+
const attr = value.attr;
|
|
1097
|
+
if (typeof attr !== "string" || attr.length === 0) return "attr must be a non-empty string";
|
|
1098
|
+
if (capabilityScope !== void 0 && capabilityScope !== "*" && attr.startsWith("doc.")) {
|
|
1099
|
+
const pathScope = attr.split(".")[1] ?? "";
|
|
1100
|
+
if (pathScope !== capabilityScope) return `condition path "${attr}" reads scope "${pathScope}" but the capability covers only scope "${capabilityScope}"`;
|
|
1101
|
+
}
|
|
1102
|
+
return null;
|
|
1103
|
+
}
|
|
1104
|
+
if (keys[0] === "lit") {
|
|
1105
|
+
const lit = value.lit;
|
|
1106
|
+
if (lit !== null && typeof lit !== "string" && typeof lit !== "number" && typeof lit !== "boolean") return "lit must be a string, number, boolean, or null";
|
|
1107
|
+
if (typeof lit === "number" && !Number.isFinite(lit)) return "lit must be a finite number";
|
|
1108
|
+
if (typeof lit === "number" && Object.is(lit, -0)) return "lit must not be negative zero";
|
|
1109
|
+
return null;
|
|
1110
|
+
}
|
|
1111
|
+
return `unknown operand kind "${keys[0]}"`;
|
|
1112
|
+
}
|
|
1113
|
+
function conditionProblem(value, capabilityScope, depth, budget) {
|
|
1114
|
+
if (depth > 10) return `condition exceeds depth 10`;
|
|
1115
|
+
budget.nodes -= 1;
|
|
1116
|
+
if (budget.nodes < 0) return `condition exceeds 100 nodes`;
|
|
1117
|
+
if (!isPlainValue(value)) return "condition must be an object";
|
|
1118
|
+
const keys = Object.keys(value);
|
|
1119
|
+
if (keys.length !== 1) return "condition must have exactly one operator";
|
|
1120
|
+
const kind = keys[0];
|
|
1121
|
+
const body = value[kind];
|
|
1122
|
+
if (COMPARISON_CONDITION_KINDS.has(kind)) {
|
|
1123
|
+
if (!Array.isArray(body) || body.length !== 2) return `${kind} requires a pair of operands`;
|
|
1124
|
+
for (const operand of body) {
|
|
1125
|
+
const problem = operandProblem(operand, capabilityScope, budget);
|
|
1126
|
+
if (problem !== null) return problem;
|
|
1127
|
+
}
|
|
1128
|
+
return null;
|
|
1129
|
+
}
|
|
1130
|
+
if (kind === "in" || kind === "notIn") {
|
|
1131
|
+
if (!Array.isArray(body) || body.length !== 2 || !Array.isArray(body[1])) return `${kind} requires an operand and an operand list`;
|
|
1132
|
+
const first = operandProblem(body[0], capabilityScope, budget);
|
|
1133
|
+
if (first !== null) return first;
|
|
1134
|
+
for (const operand of body[1]) {
|
|
1135
|
+
const problem = operandProblem(operand, capabilityScope, budget);
|
|
1136
|
+
if (problem !== null) return problem;
|
|
1137
|
+
}
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
if (kind === "exists") return operandProblem(body, capabilityScope, budget);
|
|
1141
|
+
if (kind === "and" || kind === "or") {
|
|
1142
|
+
if (!Array.isArray(body)) return `${kind} requires a condition list`;
|
|
1143
|
+
for (const child of body) {
|
|
1144
|
+
const problem = conditionProblem(child, capabilityScope, depth + 1, budget);
|
|
1145
|
+
if (problem !== null) return problem;
|
|
1146
|
+
}
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
if (kind === "not") return conditionProblem(body, capabilityScope, depth + 1, budget);
|
|
1150
|
+
return `unknown condition operator "${kind}"`;
|
|
1151
|
+
}
|
|
1152
|
+
function principalProblem(value, capabilityScope) {
|
|
1153
|
+
if (!isPlainValue(value)) return "principal must be an object";
|
|
1154
|
+
const keys = Object.keys(value);
|
|
1155
|
+
if (keys.length !== 1 || !PRINCIPAL_KINDS.has(keys[0])) return "principal must have exactly one of anyone, address, group, or match";
|
|
1156
|
+
const kind = keys[0];
|
|
1157
|
+
if (kind === "anyone" && value.anyone !== true) return "anyone must be true";
|
|
1158
|
+
if (kind === "address") {
|
|
1159
|
+
const address = value.address;
|
|
1160
|
+
if (typeof address !== "string" || address.length === 0) return "address must be a non-empty string";
|
|
1161
|
+
}
|
|
1162
|
+
if (kind === "group") {
|
|
1163
|
+
const group = value.group;
|
|
1164
|
+
if (typeof group !== "string" || group.length === 0) return "group must be a non-empty string";
|
|
1165
|
+
}
|
|
1166
|
+
if (kind === "match") return conditionProblem(value.match, capabilityScope, 1, { nodes: 100 });
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
function capabilityProblem(value) {
|
|
1170
|
+
if (!isPlainValue(value)) return "capability must be an object";
|
|
1171
|
+
const can = value.can;
|
|
1172
|
+
if (can !== "read" && can !== "execute") return "capability.can must be read or execute";
|
|
1173
|
+
const allowedKeys = can === "execute" ? [
|
|
1174
|
+
"can",
|
|
1175
|
+
"scope",
|
|
1176
|
+
"operation"
|
|
1177
|
+
] : ["can", "scope"];
|
|
1178
|
+
const unknownKeys = Object.keys(value).filter((key) => !allowedKeys.includes(key)).sort();
|
|
1179
|
+
if (unknownKeys.length > 0) return `unknown capability key "${unknownKeys[0]}"`;
|
|
1180
|
+
if (value.scope !== void 0) {
|
|
1181
|
+
if (typeof value.scope !== "string" || value.scope.length === 0) return "capability.scope must be a non-empty string";
|
|
1182
|
+
}
|
|
1183
|
+
if (can === "execute" && value.operation !== void 0) {
|
|
1184
|
+
const operation = value.operation;
|
|
1185
|
+
if (!Array.isArray(operation)) return "capability.operation must be an array";
|
|
1186
|
+
if (operation.length > 100) return `capability.operation exceeds 100 entries`;
|
|
1187
|
+
for (const entry of operation) if (typeof entry !== "string" || entry.length === 0) return "capability.operation entries must be non-empty strings";
|
|
1188
|
+
}
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
/** Returns the first v1-rule violation, or null. Pure, total, deterministic. */
|
|
1192
|
+
function grantProblem(value) {
|
|
1193
|
+
if (!isPlainValue(value)) return "grant must be an object";
|
|
1194
|
+
const unknownKeys = Object.keys(value).filter((key) => !GRANT_KEYS.has(key)).sort();
|
|
1195
|
+
if (unknownKeys.length > 0) return `unknown grant key "${unknownKeys[0]}"`;
|
|
1196
|
+
if (typeof value.id !== "string" || value.id.length === 0) return "id must be a non-empty string";
|
|
1197
|
+
if (typeof value.description !== "string") return "description must be a string";
|
|
1198
|
+
if (value.effect !== "allow" && value.effect !== "deny") return "effect must be allow or deny";
|
|
1199
|
+
const capabilityValue = value.capability;
|
|
1200
|
+
const capability = capabilityProblem(capabilityValue);
|
|
1201
|
+
if (capability !== null) return capability;
|
|
1202
|
+
const capabilityScope = capabilityValue.scope;
|
|
1203
|
+
const principal = principalProblem(value.principal, capabilityScope);
|
|
1204
|
+
if (principal !== null) return principal;
|
|
1205
|
+
if (value.where !== void 0) return conditionProblem(value.where, capabilityScope, 1, { nodes: 100 });
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
const GrantSchema = () => z.custom((value) => grantProblem(value) === null);
|
|
1209
|
+
/** V1 shape rules plus the group-document group-principal ban. */
|
|
1210
|
+
function assertValidGrant(grant, documentType) {
|
|
1211
|
+
const grantId = isPlainValue(grant) && typeof grant.id === "string" ? grant.id : "";
|
|
1212
|
+
const problem = grantProblem(grant);
|
|
1213
|
+
if (problem !== null) throw new InvalidGrantError(grantId, problem);
|
|
1214
|
+
if (documentType === "@powerhousedao/document-group" && "group" in grant.principal) throw new GroupPrincipalNotAllowedError(grantId);
|
|
1215
|
+
}
|
|
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) {
|
|
1221
|
+
if (grants.length > 100) throw new InvalidGrantError("", `policy exceeds 100 grants`);
|
|
1222
|
+
for (const grant of grants) assertValidGrant(grant, documentType);
|
|
1223
|
+
if (creator === void 0 && !administrationReachable(grants)) throw new AuthAdministrationMissingError();
|
|
1224
|
+
}
|
|
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) {
|
|
1233
|
+
assertValidGrant(grant, documentType);
|
|
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);
|
|
1287
|
+
}
|
|
1288
|
+
function capabilityCovers(capability, request) {
|
|
1289
|
+
if (capability.can !== request.verb) return false;
|
|
1290
|
+
const scope = capability.scope;
|
|
1291
|
+
if (scope !== void 0 && scope !== "*" && scope !== request.scope) return false;
|
|
1292
|
+
if (capability.can === "execute") {
|
|
1293
|
+
if (capability.operation === void 0) return true;
|
|
1294
|
+
return request.operation !== void 0 && capability.operation.includes(request.operation);
|
|
1295
|
+
}
|
|
1296
|
+
return true;
|
|
1297
|
+
}
|
|
1298
|
+
function principalMatches(principal, subject) {
|
|
1299
|
+
if ("anyone" in principal) return true;
|
|
1300
|
+
if ("address" in principal) return subject.address !== void 0 && subject.address.toLowerCase() === principal.address.toLowerCase();
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
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.
|
|
1307
|
+
*/
|
|
1308
|
+
function evaluateGrantStack(grants, subject, request) {
|
|
1309
|
+
let applicable;
|
|
1310
|
+
for (const grant of grants) {
|
|
1311
|
+
if (grant.where !== void 0) continue;
|
|
1312
|
+
if (capabilityCovers(grant.capability, request) && principalMatches(grant.principal, subject)) applicable = grant;
|
|
1313
|
+
}
|
|
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;
|
|
1331
|
+
}
|
|
1332
|
+
//#endregion
|
|
852
1333
|
//#region document-model/constants.ts
|
|
853
1334
|
const documentModelFileExtension = "phdm";
|
|
854
1335
|
const documentModelInitialLocalState = {};
|
|
@@ -1435,8 +1916,376 @@ const HASH_ALGORITHM_SHA512 = "sha512";
|
|
|
1435
1916
|
const HASH_ENCODING_BASE64 = "base64";
|
|
1436
1917
|
const HASH_ENCODING_HEX = "hex";
|
|
1437
1918
|
//#endregion
|
|
1438
|
-
//#region document-model/
|
|
1439
|
-
|
|
1919
|
+
//#region document-model/state.ts
|
|
1920
|
+
/**
|
|
1921
|
+
* Creates a default PHAuthState
|
|
1922
|
+
*/
|
|
1923
|
+
function defaultAuthState() {
|
|
1924
|
+
return {
|
|
1925
|
+
version: 0,
|
|
1926
|
+
grants: []
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Creates a default PHDocumentState
|
|
1931
|
+
*/
|
|
1932
|
+
function defaultDocumentState() {
|
|
1933
|
+
return {
|
|
1934
|
+
version: 0,
|
|
1935
|
+
hash: {
|
|
1936
|
+
algorithm: HASH_ALGORITHM_SHA1,
|
|
1937
|
+
encoding: HASH_ENCODING_BASE64
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Creates a default PHBaseState with auth and document properties
|
|
1943
|
+
*/
|
|
1944
|
+
function defaultBaseState() {
|
|
1945
|
+
return {
|
|
1946
|
+
auth: defaultAuthState(),
|
|
1947
|
+
document: defaultDocumentState()
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Creates a PHAuthState with the given properties
|
|
1952
|
+
*/
|
|
1953
|
+
function createAuthState(auth) {
|
|
1954
|
+
return {
|
|
1955
|
+
...defaultAuthState(),
|
|
1956
|
+
...auth
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Creates a PHDocumentState with the given properties
|
|
1961
|
+
*/
|
|
1962
|
+
function createDocumentState(document) {
|
|
1963
|
+
return {
|
|
1964
|
+
...defaultDocumentState(),
|
|
1965
|
+
...document
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Creates a PHBaseState with the given auth and document properties
|
|
1970
|
+
*/
|
|
1971
|
+
function createBaseState(auth, document) {
|
|
1972
|
+
return {
|
|
1973
|
+
auth: createAuthState(auth),
|
|
1974
|
+
document: createDocumentState(document)
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Backfills the auth scope to the default for legacy documents serialized with
|
|
1979
|
+
* an empty `auth`. Replaces only `state.auth`. Idempotent.
|
|
1980
|
+
*/
|
|
1981
|
+
function backfillAuthState(state) {
|
|
1982
|
+
return {
|
|
1983
|
+
...state,
|
|
1984
|
+
auth: createAuthState(state.auth)
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
function defaultGlobalState() {
|
|
1988
|
+
return {
|
|
1989
|
+
...defaultBaseState(),
|
|
1990
|
+
author: {
|
|
1991
|
+
name: "",
|
|
1992
|
+
website: ""
|
|
1993
|
+
},
|
|
1994
|
+
description: "",
|
|
1995
|
+
extension: "",
|
|
1996
|
+
id: "",
|
|
1997
|
+
name: "",
|
|
1998
|
+
specifications: []
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
function defaultLocalState() {
|
|
2002
|
+
return {};
|
|
2003
|
+
}
|
|
2004
|
+
function defaultPHState() {
|
|
2005
|
+
return {
|
|
2006
|
+
...defaultBaseState(),
|
|
2007
|
+
global: defaultGlobalState(),
|
|
2008
|
+
local: defaultLocalState()
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
function createGlobalState(state) {
|
|
2012
|
+
return {
|
|
2013
|
+
...defaultGlobalState(),
|
|
2014
|
+
...state || {}
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
function createLocalState(state) {
|
|
2018
|
+
return {
|
|
2019
|
+
...defaultLocalState(),
|
|
2020
|
+
...state || {}
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
function createState(baseState, globalState, localState) {
|
|
2024
|
+
return {
|
|
2025
|
+
...createBaseState(baseState?.auth, baseState?.document),
|
|
2026
|
+
global: createGlobalState(globalState),
|
|
2027
|
+
local: createLocalState(localState)
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
//#endregion
|
|
2031
|
+
//#region document-model/auth.ts
|
|
2032
|
+
const AUTH_ACTION_TYPES = [
|
|
2033
|
+
"INITIALIZE_AUTH",
|
|
2034
|
+
"SET_GRANT",
|
|
2035
|
+
"REMOVE_GRANT",
|
|
2036
|
+
"MOVE_GRANT"
|
|
2037
|
+
];
|
|
2038
|
+
function isAuthAction(action) {
|
|
2039
|
+
return AUTH_ACTION_TYPES.includes(action.type);
|
|
2040
|
+
}
|
|
2041
|
+
/** Highest known policy version; decide() fails closed above it. */
|
|
2042
|
+
const MAX_SUPPORTED_AUTH_VERSION = 1;
|
|
2043
|
+
const InitializeAuthActionInputSchema = () => z.object({
|
|
2044
|
+
version: z.number().int().min(1),
|
|
2045
|
+
grants: z.array(GrantSchema()).max(100)
|
|
2046
|
+
});
|
|
2047
|
+
const SetGrantActionInputSchema = () => z.object({ grant: GrantSchema() });
|
|
2048
|
+
const RemoveGrantActionInputSchema = () => z.object({ id: z.string() });
|
|
2049
|
+
const MoveGrantActionInputSchema = () => z.object({
|
|
2050
|
+
id: z.string(),
|
|
2051
|
+
index: z.number()
|
|
2052
|
+
});
|
|
2053
|
+
const initializeAuth = (input) => createAction("INITIALIZE_AUTH", input, void 0, InitializeAuthActionInputSchema, "auth");
|
|
2054
|
+
const setGrant = (input) => createAction("SET_GRANT", input, void 0, SetGrantActionInputSchema, "auth");
|
|
2055
|
+
const removeGrant = (input) => createAction("REMOVE_GRANT", input, void 0, RemoveGrantActionInputSchema, "auth");
|
|
2056
|
+
const moveGrant = (input) => createAction("MOVE_GRANT", input, void 0, MoveGrantActionInputSchema, "auth");
|
|
2057
|
+
/**
|
|
2058
|
+
* Destructuring a null input (reachable via raw synced operations) would
|
|
2059
|
+
* store an engine-specific TypeError message on the error operation.
|
|
2060
|
+
*/
|
|
2061
|
+
function assertActionInputShape(input) {
|
|
2062
|
+
if (!isPlainValue(input)) throw new InvalidActionInputError({ input: "must be an object" });
|
|
2063
|
+
}
|
|
2064
|
+
function withGrants(document, grants) {
|
|
2065
|
+
return {
|
|
2066
|
+
...document,
|
|
2067
|
+
state: {
|
|
2068
|
+
...document.state,
|
|
2069
|
+
auth: {
|
|
2070
|
+
...document.state.auth,
|
|
2071
|
+
grants
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
const P256_PUBKEY_MULTICODEC = [128, 36];
|
|
2077
|
+
const DID_KEY_PREFIX = "did:key:z";
|
|
2078
|
+
function bytesEqual(a, b) {
|
|
2079
|
+
if (a.length !== b.length) return false;
|
|
2080
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
2081
|
+
return true;
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* True when `signerKey` (an ActionSigner app key, a did:key) identifies the same
|
|
2085
|
+
* key recorded as the document creator. Returns false
|
|
2086
|
+
* when there is no creator (empty JWK) or no signer key.
|
|
2087
|
+
*/
|
|
2088
|
+
function isDocumentCreator(creatorKey, signerKey) {
|
|
2089
|
+
if (!creatorKey?.x || !creatorKey.y) return false;
|
|
2090
|
+
if (!signerKey || !signerKey.startsWith(DID_KEY_PREFIX)) return false;
|
|
2091
|
+
const decoded = base58Decode(signerKey.slice(9));
|
|
2092
|
+
if (!decoded || decoded.length !== 35) return false;
|
|
2093
|
+
if (decoded[0] !== P256_PUBKEY_MULTICODEC[0] || decoded[1] !== P256_PUBKEY_MULTICODEC[1]) return false;
|
|
2094
|
+
const parityPrefix = decoded[2];
|
|
2095
|
+
if (parityPrefix !== 2 && parityPrefix !== 3) return false;
|
|
2096
|
+
const didX = decoded.subarray(3, 35);
|
|
2097
|
+
const jwkX = base64UrlToBytes(creatorKey.x);
|
|
2098
|
+
const jwkY = base64UrlToBytes(creatorKey.y);
|
|
2099
|
+
if (jwkX.length !== 32 || jwkY.length !== 32) return false;
|
|
2100
|
+
if (!bytesEqual(didX, jwkX)) return false;
|
|
2101
|
+
return (jwkY[31] & 1) === 1 === (parityPrefix === 3);
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Sets the initial policy. Valid only while the auth scope is uninitialized
|
|
2105
|
+
* (version 0). The input version is the policy language version and must be an
|
|
2106
|
+
* integer >= 1; 0 is reserved for the uninitialized state. On a signed-header
|
|
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.
|
|
2110
|
+
*/
|
|
2111
|
+
function applyInitializeAuthAction(document, action) {
|
|
2112
|
+
assertActionInputShape(action.input);
|
|
2113
|
+
const { version, grants } = action.input;
|
|
2114
|
+
if (!Number.isInteger(version) || version < 1) throw new InvalidAuthVersionError(document.header.id, version);
|
|
2115
|
+
if (document.state.auth.version !== 0) throw new AuthAlreadyInitializedError(document.header.id);
|
|
2116
|
+
if (!Array.isArray(grants)) throw new InvalidActionInputError({ grants: "must be an array" });
|
|
2117
|
+
const creatorKey = document.header.sig.publicKey;
|
|
2118
|
+
const signerKey = action.context?.signer?.app.key;
|
|
2119
|
+
const hasCreator = Boolean(creatorKey.kty || creatorKey.x || creatorKey.y);
|
|
2120
|
+
if (hasCreator && !isDocumentCreator(creatorKey, signerKey)) throw new AuthInitializerNotCreatorError(document.header.id);
|
|
2121
|
+
const creator = hasCreator ? signerKey : void 0;
|
|
2122
|
+
assertValidInitialGrants(grants, document.header.documentType, creator);
|
|
2123
|
+
return {
|
|
2124
|
+
...document,
|
|
2125
|
+
state: {
|
|
2126
|
+
...document.state,
|
|
2127
|
+
auth: createAuthState(creator ? {
|
|
2128
|
+
version,
|
|
2129
|
+
grants,
|
|
2130
|
+
creator
|
|
2131
|
+
} : {
|
|
2132
|
+
version,
|
|
2133
|
+
grants
|
|
2134
|
+
})
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
/** Upserts a grant by id: replaces in place if present, otherwise appends. */
|
|
2139
|
+
function applySetGrantAction(document, action) {
|
|
2140
|
+
assertActionInputShape(action.input);
|
|
2141
|
+
const { grant } = action.input;
|
|
2142
|
+
const grants = document.state.auth.grants;
|
|
2143
|
+
assertValidGrantUpsert(grant, grants, document.header.documentType, document.state.auth.creator);
|
|
2144
|
+
return withGrants(document, grants.some((g) => g.id === grant.id) ? grants.map((g) => g.id === grant.id ? grant : g) : [...grants, grant]);
|
|
2145
|
+
}
|
|
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
|
+
*/
|
|
2150
|
+
function applyRemoveGrantAction(document, action) {
|
|
2151
|
+
assertActionInputShape(action.input);
|
|
2152
|
+
const { id } = action.input;
|
|
2153
|
+
const { grants, creator } = document.state.auth;
|
|
2154
|
+
if (!grants.some((g) => g.id === id)) throw new GrantNotFoundError(id);
|
|
2155
|
+
const next = grants.filter((g) => g.id !== id);
|
|
2156
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2157
|
+
return withGrants(document, next);
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Moves a grant by id to a new index. Order is load-bearing (the last
|
|
2161
|
+
* applicable grant wins), so the relative order of the other grants is kept.
|
|
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.
|
|
2167
|
+
*/
|
|
2168
|
+
function applyMoveGrantAction(document, action) {
|
|
2169
|
+
assertActionInputShape(action.input);
|
|
2170
|
+
const { id, index } = action.input;
|
|
2171
|
+
const { grants, creator } = document.state.auth;
|
|
2172
|
+
const from = grants.findIndex((g) => g.id === id);
|
|
2173
|
+
if (from === -1) throw new GrantNotFoundError(id);
|
|
2174
|
+
const next = [...grants];
|
|
2175
|
+
const [moved] = next.splice(from, 1);
|
|
2176
|
+
const to = Math.max(0, Math.min(index, next.length));
|
|
2177
|
+
next.splice(to, 0, moved);
|
|
2178
|
+
assertAuthAdministrationRetained(creator, grants, next, id);
|
|
2179
|
+
return withGrants(document, next);
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Dispatches an auth-scope action to its handler. This is the auth scope's
|
|
2183
|
+
* dedicated reducer: it is applied by the base reducer instead of the model
|
|
2184
|
+
* reducer, mirroring the document-scope platform handlers. Unknown types are a
|
|
2185
|
+
* no-op, matching the model-reducer default.
|
|
2186
|
+
*/
|
|
2187
|
+
function applyAuthAction(document, action) {
|
|
2188
|
+
switch (action.type) {
|
|
2189
|
+
case "INITIALIZE_AUTH": return applyInitializeAuthAction(document, action);
|
|
2190
|
+
case "SET_GRANT": return applySetGrantAction(document, action);
|
|
2191
|
+
case "REMOVE_GRANT": return applyRemoveGrantAction(document, action);
|
|
2192
|
+
case "MOVE_GRANT": return applyMoveGrantAction(document, action);
|
|
2193
|
+
default: return document;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Because only creators can initialize auth scopes, we must verify that either
|
|
2198
|
+
* the document has no auth or the version and creator match.
|
|
2199
|
+
*/
|
|
2200
|
+
function assertAuthPreservedOnDuplicate(documentId, source, duplicated) {
|
|
2201
|
+
if (!source || source.version === 0) return;
|
|
2202
|
+
if (duplicated === void 0 || duplicated.version !== source.version || duplicated.creator !== source.creator) throw new AuthPolicyNotPreservedError(documentId);
|
|
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
|
+
}
|
|
2240
|
+
/** UNDO, REDO and PRUNE are rejected on the auth scope. */
|
|
2241
|
+
function assertAuthScopeActionAllowed(action) {
|
|
2242
|
+
if (action.scope === "auth" && [
|
|
2243
|
+
"UNDO",
|
|
2244
|
+
"REDO",
|
|
2245
|
+
"PRUNE"
|
|
2246
|
+
].includes(action.type)) throw new AuthActionNotAllowedError(action.type);
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Evaluates the auth policy for a single request and reports why it refused.
|
|
2250
|
+
* Pure and deterministic.
|
|
2251
|
+
*
|
|
2252
|
+
* An uninitialized policy (version 0, absent auth state, or a legacy `{}`
|
|
2253
|
+
* auth scope serialized before PHAuthState had a version) leaves the document
|
|
2254
|
+
* open. Once a policy exists the default is deny, and grants stack in order.
|
|
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
|
+
*/
|
|
2269
|
+
function decide(auth, subject, request) {
|
|
2270
|
+
return evaluate(auth, subject, request).decision;
|
|
2271
|
+
}
|
|
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";
|
|
1440
2289
|
//#endregion
|
|
1441
2290
|
//#region document-model/document-schema.ts
|
|
1442
2291
|
const BaseDocumentHeaderSchema = z.object({
|
|
@@ -1709,6 +2558,7 @@ function createDocumentScopeOperations(header, state) {
|
|
|
1709
2558
|
function baseCreateDocument(createState, initialState, documentType = "") {
|
|
1710
2559
|
const state = createState(initialState);
|
|
1711
2560
|
const header = createPresignedHeader(generateId(), documentType);
|
|
2561
|
+
header.protocolVersions = { "base-reducer": 2 };
|
|
1712
2562
|
return {
|
|
1713
2563
|
header,
|
|
1714
2564
|
state,
|
|
@@ -1804,6 +2654,18 @@ function mapSkippedOperationsV2(operations) {
|
|
|
1804
2654
|
* Uses the V2 model where consecutive NOOPs form chains.
|
|
1805
2655
|
* Unlike V1 garbageCollect, this preserves ALL operations but marks which to apply.
|
|
1806
2656
|
*/
|
|
2657
|
+
/**
|
|
2658
|
+
* The base-reducer protocol version a document is written against. Every
|
|
2659
|
+
* document carries one, set from the CREATE_DOCUMENT input. A header without
|
|
2660
|
+
* one was built outside that path, and choosing a version on its behalf would
|
|
2661
|
+
* replay the document through a reducer it was not written for, so it is an
|
|
2662
|
+
* error rather than a default.
|
|
2663
|
+
*/
|
|
2664
|
+
function baseReducerVersion(header) {
|
|
2665
|
+
const version = header.protocolVersions?.["base-reducer"];
|
|
2666
|
+
if (typeof version !== "number") throw new Error(`Document ${header.id} carries no base-reducer protocol version`);
|
|
2667
|
+
return version;
|
|
2668
|
+
}
|
|
1807
2669
|
function garbageCollectV2(sortedOperations) {
|
|
1808
2670
|
const result = [];
|
|
1809
2671
|
let noopChainLength = 0;
|
|
@@ -1823,9 +2685,26 @@ function sortMappedOperations(operations) {
|
|
|
1823
2685
|
const defaultCreateState = (state) => {
|
|
1824
2686
|
return state;
|
|
1825
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
|
+
}
|
|
1826
2704
|
function replayDocument(initialState, operations, reducer, header, dispatch, skipHeaderOperations = {}, options) {
|
|
1827
2705
|
const { checkHashes = true, reuseOperationResultingState, operationResultingStateParser = parseResultingState, skipIndexValidation } = options || {};
|
|
1828
|
-
|
|
2706
|
+
const backfilledInitialState = backfillAuthState(initialState);
|
|
2707
|
+
let documentState = backfilledInitialState;
|
|
1829
2708
|
const operationsToReplay = [];
|
|
1830
2709
|
const allScopes = new Set([
|
|
1831
2710
|
...Object.keys(operations),
|
|
@@ -1860,12 +2739,13 @@ function replayDocument(initialState, operations, reducer, header, dispatch, ski
|
|
|
1860
2739
|
const document = {
|
|
1861
2740
|
header,
|
|
1862
2741
|
state: defaultCreateState(documentState),
|
|
1863
|
-
initialState,
|
|
2742
|
+
initialState: backfilledInitialState,
|
|
1864
2743
|
operations: initialOperations,
|
|
1865
2744
|
clipboard: []
|
|
1866
2745
|
};
|
|
1867
2746
|
let result = document;
|
|
1868
2747
|
if (operationsToReplay.length) result = operationsToReplay.reduce((document, operation) => {
|
|
2748
|
+
if (isDenied(operation)) return appendWithoutApplying(document, operation);
|
|
1869
2749
|
return reducer(document, operation.action, dispatch, {
|
|
1870
2750
|
ignoreSkipOperations: true,
|
|
1871
2751
|
checkHashes,
|
|
@@ -2389,14 +3269,31 @@ function redoOperation(document, action, skip) {
|
|
|
2389
3269
|
});
|
|
2390
3270
|
}
|
|
2391
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);
|
|
2392
3274
|
return {
|
|
2393
3275
|
...document,
|
|
2394
3276
|
header: {
|
|
2395
3277
|
...document.header,
|
|
2396
3278
|
name: action.state.name
|
|
2397
3279
|
},
|
|
2398
|
-
state:
|
|
3280
|
+
state: loaded
|
|
3281
|
+
};
|
|
3282
|
+
}
|
|
3283
|
+
/**
|
|
3284
|
+
* Reads an operation's outcome. A denial takes precedence over a reducer
|
|
3285
|
+
* error, since a denied operation never reaches its reducer.
|
|
3286
|
+
*/
|
|
3287
|
+
function operationOutcome(operation) {
|
|
3288
|
+
if (operation.deniedReason !== void 0) return {
|
|
3289
|
+
kind: "denied",
|
|
3290
|
+
reason: operation.deniedReason
|
|
3291
|
+
};
|
|
3292
|
+
if (operation.error !== void 0) return {
|
|
3293
|
+
kind: "reducer-error",
|
|
3294
|
+
message: operation.error
|
|
2399
3295
|
};
|
|
3296
|
+
return { kind: "applied" };
|
|
2400
3297
|
}
|
|
2401
3298
|
//#endregion
|
|
2402
3299
|
//#region document-model/reducer.ts
|
|
@@ -2571,12 +3468,13 @@ function processUndoOperation(document, scope, customReducer, reuseOperationResu
|
|
|
2571
3468
|
function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
2572
3469
|
const { skip, ignoreSkipOperations = false, reuseOperationResultingState = false, operationResultingStateParser, pruneOnSkip = true, branch = "main" } = options;
|
|
2573
3470
|
let _action = actionFromAction(action);
|
|
3471
|
+
assertAuthScopeActionAllowed(_action);
|
|
2574
3472
|
let skipValue = skip ?? options.replayOptions?.operation.skip ?? 0;
|
|
2575
3473
|
let newDocument = { ...document };
|
|
2576
3474
|
let reuseLastOperationIndex = false;
|
|
2577
3475
|
const shouldProcessSkipOperation = !ignoreSkipOperations && skipValue > 0;
|
|
2578
3476
|
if (isUndoRedo(_action)) {
|
|
2579
|
-
const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex } = processUndoRedo(document, _action, skipValue, options.protocolVersion ??
|
|
3477
|
+
const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex } = processUndoRedo(document, _action, skipValue, options.protocolVersion ?? baseReducerVersion(document.header));
|
|
2580
3478
|
_action = transformedAction;
|
|
2581
3479
|
skipValue = calculatedSkip;
|
|
2582
3480
|
newDocument = processedDocument;
|
|
@@ -2592,7 +3490,7 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
2592
3490
|
branch
|
|
2593
3491
|
};
|
|
2594
3492
|
newDocument = updateDocument(newDocument, _action, reuseLastOperationIndex, skipValue, operationContext, options.replayOptions?.operation, options.skipIndexValidation);
|
|
2595
|
-
const protocolVersion = options.protocolVersion ??
|
|
3493
|
+
const protocolVersion = options.protocolVersion ?? baseReducerVersion(document.header);
|
|
2596
3494
|
if (isUndo(action) && protocolVersion < 2) return processUndoOperation(newDocument, action.scope, customReducer);
|
|
2597
3495
|
const isNoopWithSkip = _action.type === "NOOP" && skipValue > 0;
|
|
2598
3496
|
if ((isUndo(action) || isNoopWithSkip) && protocolVersion >= 2) {
|
|
@@ -2618,6 +3516,13 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
2618
3516
|
}
|
|
2619
3517
|
newDocument = create(newDocument, (draft) => {
|
|
2620
3518
|
try {
|
|
3519
|
+
if (_action.scope === "auth") {
|
|
3520
|
+
const authState = applyAuthAction(newDocument, _action).state;
|
|
3521
|
+
unsafe(() => {
|
|
3522
|
+
draft.state = castDraft(authState);
|
|
3523
|
+
});
|
|
3524
|
+
return;
|
|
3525
|
+
}
|
|
2621
3526
|
const newState = customReducer(draft.state, _action, dispatch);
|
|
2622
3527
|
if (newState) unsafe(() => {
|
|
2623
3528
|
draft.state = castDraft(newState);
|
|
@@ -3417,10 +4322,12 @@ function applyInitialState(document, action) {
|
|
|
3417
4322
|
const input = action.input;
|
|
3418
4323
|
const newState = input.initialState || input.state;
|
|
3419
4324
|
if (newState) {
|
|
3420
|
-
|
|
4325
|
+
const merged = backfillAuthState({
|
|
3421
4326
|
...document.state,
|
|
3422
4327
|
...newState
|
|
3423
|
-
};
|
|
4328
|
+
});
|
|
4329
|
+
merged.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, merged.auth);
|
|
4330
|
+
document.state = merged;
|
|
3424
4331
|
document.initialState = document.state;
|
|
3425
4332
|
}
|
|
3426
4333
|
}
|
|
@@ -3482,7 +4389,6 @@ function computeUpgradeTransitions(manifest, fromVersion, toVersion) {
|
|
|
3482
4389
|
}
|
|
3483
4390
|
//#endregion
|
|
3484
4391
|
//#region document-model/versioned-replay.ts
|
|
3485
|
-
const NON_DOMAIN_SCOPES$1 = new Set(["auth", "document"]);
|
|
3486
4392
|
function highestReducerVersion(reducers) {
|
|
3487
4393
|
const keys = Object.keys(reducers).map(Number);
|
|
3488
4394
|
if (keys.length === 0) throw new Error("VersionedReplayConfig.reducers must not be empty");
|
|
@@ -3510,15 +4416,15 @@ function highestReducerVersion(reducers) {
|
|
|
3510
4416
|
*/
|
|
3511
4417
|
function replayDocumentVersioned(initialState, operations, config, header, dispatch, options) {
|
|
3512
4418
|
const { checkHashes = true, skipIndexValidation } = options || {};
|
|
3513
|
-
const protocolVersion = header
|
|
4419
|
+
const protocolVersion = baseReducerVersion(header);
|
|
3514
4420
|
const spine = (operations["document"] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3515
4421
|
const upgrades = spine.filter((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
3516
4422
|
const legacyFallback = () => {
|
|
3517
|
-
const
|
|
4423
|
+
const replayOps = Object.fromEntries(Object.entries(operations).filter(([s]) => s !== "document"));
|
|
3518
4424
|
const latestVersion = highestReducerVersion(config.reducers);
|
|
3519
4425
|
const reducer = config.reducers[latestVersion];
|
|
3520
4426
|
return {
|
|
3521
|
-
...replayDocument(initialState,
|
|
4427
|
+
...replayDocument(initialState, replayOps, reducer, header, dispatch, {}, options),
|
|
3522
4428
|
operations
|
|
3523
4429
|
};
|
|
3524
4430
|
};
|
|
@@ -3542,14 +4448,14 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3542
4448
|
const a = op.action;
|
|
3543
4449
|
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
3544
4450
|
});
|
|
3545
|
-
const
|
|
4451
|
+
const replayScopes = Object.keys(operations).filter((s) => s !== "document");
|
|
3546
4452
|
const scopeOps = {};
|
|
3547
|
-
for (const s of
|
|
4453
|
+
for (const s of replayScopes) scopeOps[s] = (operations[s] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3548
4454
|
const boundaries = validatedUpgrades.map((upgradeOp) => {
|
|
3549
4455
|
const revisionSnapshot = upgradeOp.action.input.revision;
|
|
3550
4456
|
const upgradeTimestamp = upgradeOp.timestampUtcMs;
|
|
3551
4457
|
const boundary = {};
|
|
3552
|
-
for (const s of
|
|
4458
|
+
for (const s of replayScopes) {
|
|
3553
4459
|
const ops = scopeOps[s] ?? [];
|
|
3554
4460
|
if (revisionSnapshot !== void 0) {
|
|
3555
4461
|
const rev = revisionSnapshot[s] ?? 0;
|
|
@@ -3567,7 +4473,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3567
4473
|
}
|
|
3568
4474
|
return boundary;
|
|
3569
4475
|
});
|
|
3570
|
-
for (let i = 1; i < boundaries.length; i++) for (const s of
|
|
4476
|
+
for (let i = 1; i < boundaries.length; i++) for (const s of replayScopes) {
|
|
3571
4477
|
const prev = boundaries[i - 1]?.[s] ?? 0;
|
|
3572
4478
|
const curr = boundaries[i]?.[s] ?? 0;
|
|
3573
4479
|
if (boundaries[i]) boundaries[i][s] = Math.max(prev, curr);
|
|
@@ -3579,10 +4485,11 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3579
4485
|
]);
|
|
3580
4486
|
const initialOperations = {};
|
|
3581
4487
|
for (const s of allScopes) initialOperations[s] = [];
|
|
4488
|
+
const backfilledSeed = backfillAuthState(seedState);
|
|
3582
4489
|
let document = {
|
|
3583
4490
|
header,
|
|
3584
|
-
state:
|
|
3585
|
-
initialState:
|
|
4491
|
+
state: backfilledSeed,
|
|
4492
|
+
initialState: backfilledSeed,
|
|
3586
4493
|
operations: initialOperations,
|
|
3587
4494
|
clipboard: []
|
|
3588
4495
|
};
|
|
@@ -3594,13 +4501,14 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3594
4501
|
const available = Object.keys(config.reducers).join(", ");
|
|
3595
4502
|
throw new Error(`No reducer registered for document version ${currentVersion}. Available versions: ${available}`);
|
|
3596
4503
|
}
|
|
3597
|
-
for (const s of
|
|
4504
|
+
for (const s of replayScopes) {
|
|
3598
4505
|
const ops = scopeOps[s] ?? [];
|
|
3599
4506
|
const segStart = k === 0 ? 0 : boundaries[k - 1]?.[s] ?? 0;
|
|
3600
4507
|
const segEnd = k < validatedUpgrades.length ? boundaries[k]?.[s] ?? ops.length : ops.length;
|
|
3601
4508
|
const segOps = ops.slice(segStart, segEnd);
|
|
3602
4509
|
for (const op of segOps) {
|
|
3603
|
-
document =
|
|
4510
|
+
if (isDenied(op)) document = appendWithoutApplying(document, op, s);
|
|
4511
|
+
else document = reducer(document, op.action, dispatch, {
|
|
3604
4512
|
ignoreSkipOperations: true,
|
|
3605
4513
|
checkHashes,
|
|
3606
4514
|
skipIndexValidation,
|
|
@@ -3617,6 +4525,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3617
4525
|
if (!spineOp) continue;
|
|
3618
4526
|
const spineActionType = spineOp.action.type;
|
|
3619
4527
|
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
4528
|
+
if (isDenied(spineOp)) continue;
|
|
3620
4529
|
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
3621
4530
|
else document = reducer(document, spineOp.action, dispatch, {
|
|
3622
4531
|
ignoreSkipOperations: true,
|
|
@@ -3647,7 +4556,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3647
4556
|
}
|
|
3648
4557
|
};
|
|
3649
4558
|
if (!checkHashes) {
|
|
3650
|
-
const allReplayedOps =
|
|
4559
|
+
const allReplayedOps = replayScopes.flatMap((s) => scopeOps[s] ?? []);
|
|
3651
4560
|
for (const scope of Object.keys(document.state)) {
|
|
3652
4561
|
const capturedHash = segmentEndHashPerScope.get(scope);
|
|
3653
4562
|
const scopeHash = capturedHash !== void 0 ? capturedHash : hashDocumentStateForScope(document, scope);
|
|
@@ -3691,7 +4600,6 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
3691
4600
|
}
|
|
3692
4601
|
//#endregion
|
|
3693
4602
|
//#region document-model/files.ts
|
|
3694
|
-
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
3695
4603
|
function zipAsync(data) {
|
|
3696
4604
|
return new Promise((resolve, reject) => {
|
|
3697
4605
|
zip(data, (err, out) => err ? reject(err) : resolve(out));
|
|
@@ -3798,7 +4706,7 @@ async function parseZipData(data) {
|
|
|
3798
4706
|
async function loadFromZipData(data, reducer, options) {
|
|
3799
4707
|
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
3800
4708
|
return {
|
|
3801
|
-
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) =>
|
|
4709
|
+
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) => scope !== "document")), reducer, header, void 0, {}, options),
|
|
3802
4710
|
operations: clearedOperations
|
|
3803
4711
|
};
|
|
3804
4712
|
}
|
|
@@ -3834,105 +4742,6 @@ const getFileBrowser = (file) => {
|
|
|
3834
4742
|
return Promise.resolve().then(() => readFileBrowser(file));
|
|
3835
4743
|
};
|
|
3836
4744
|
//#endregion
|
|
3837
|
-
|
|
3838
|
-
/**
|
|
3839
|
-
* Creates a default PHAuthState
|
|
3840
|
-
*/
|
|
3841
|
-
function defaultAuthState() {
|
|
3842
|
-
return {};
|
|
3843
|
-
}
|
|
3844
|
-
/**
|
|
3845
|
-
* Creates a default PHDocumentState
|
|
3846
|
-
*/
|
|
3847
|
-
function defaultDocumentState() {
|
|
3848
|
-
return {
|
|
3849
|
-
version: 0,
|
|
3850
|
-
hash: {
|
|
3851
|
-
algorithm: HASH_ALGORITHM_SHA1,
|
|
3852
|
-
encoding: HASH_ENCODING_BASE64
|
|
3853
|
-
}
|
|
3854
|
-
};
|
|
3855
|
-
}
|
|
3856
|
-
/**
|
|
3857
|
-
* Creates a default PHBaseState with auth and document properties
|
|
3858
|
-
*/
|
|
3859
|
-
function defaultBaseState() {
|
|
3860
|
-
return {
|
|
3861
|
-
auth: defaultAuthState(),
|
|
3862
|
-
document: defaultDocumentState()
|
|
3863
|
-
};
|
|
3864
|
-
}
|
|
3865
|
-
/**
|
|
3866
|
-
* Creates a PHAuthState with the given properties
|
|
3867
|
-
*/
|
|
3868
|
-
function createAuthState(auth) {
|
|
3869
|
-
return {
|
|
3870
|
-
...defaultAuthState(),
|
|
3871
|
-
...auth
|
|
3872
|
-
};
|
|
3873
|
-
}
|
|
3874
|
-
/**
|
|
3875
|
-
* Creates a PHDocumentState with the given properties
|
|
3876
|
-
*/
|
|
3877
|
-
function createDocumentState(document) {
|
|
3878
|
-
return {
|
|
3879
|
-
...defaultDocumentState(),
|
|
3880
|
-
...document
|
|
3881
|
-
};
|
|
3882
|
-
}
|
|
3883
|
-
/**
|
|
3884
|
-
* Creates a PHBaseState with the given auth and document properties
|
|
3885
|
-
*/
|
|
3886
|
-
function createBaseState(auth, document) {
|
|
3887
|
-
return {
|
|
3888
|
-
auth: createAuthState(auth),
|
|
3889
|
-
document: createDocumentState(document)
|
|
3890
|
-
};
|
|
3891
|
-
}
|
|
3892
|
-
function defaultGlobalState() {
|
|
3893
|
-
return {
|
|
3894
|
-
...defaultBaseState(),
|
|
3895
|
-
author: {
|
|
3896
|
-
name: "",
|
|
3897
|
-
website: ""
|
|
3898
|
-
},
|
|
3899
|
-
description: "",
|
|
3900
|
-
extension: "",
|
|
3901
|
-
id: "",
|
|
3902
|
-
name: "",
|
|
3903
|
-
specifications: []
|
|
3904
|
-
};
|
|
3905
|
-
}
|
|
3906
|
-
function defaultLocalState() {
|
|
3907
|
-
return {};
|
|
3908
|
-
}
|
|
3909
|
-
function defaultPHState() {
|
|
3910
|
-
return {
|
|
3911
|
-
...defaultBaseState(),
|
|
3912
|
-
global: defaultGlobalState(),
|
|
3913
|
-
local: defaultLocalState()
|
|
3914
|
-
};
|
|
3915
|
-
}
|
|
3916
|
-
function createGlobalState(state) {
|
|
3917
|
-
return {
|
|
3918
|
-
...defaultGlobalState(),
|
|
3919
|
-
...state || {}
|
|
3920
|
-
};
|
|
3921
|
-
}
|
|
3922
|
-
function createLocalState(state) {
|
|
3923
|
-
return {
|
|
3924
|
-
...defaultLocalState(),
|
|
3925
|
-
...state || {}
|
|
3926
|
-
};
|
|
3927
|
-
}
|
|
3928
|
-
function createState(baseState, globalState, localState) {
|
|
3929
|
-
return {
|
|
3930
|
-
...createBaseState(baseState?.auth, baseState?.document),
|
|
3931
|
-
global: createGlobalState(globalState),
|
|
3932
|
-
local: createLocalState(localState)
|
|
3933
|
-
};
|
|
3934
|
-
}
|
|
3935
|
-
//#endregion
|
|
3936
|
-
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 };
|
|
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 };
|
|
3937
4746
|
|
|
3938
4747
|
//# sourceMappingURL=index.js.map
|