@spacefast/common 0.2.1 → 0.4.1

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.
Files changed (226) hide show
  1. package/dist/agents/marketplace-prompts.d.ts +1 -0
  2. package/dist/agents/marketplace-prompts.js +6 -0
  3. package/dist/agents/registry/core.d.ts +4 -12
  4. package/dist/agents/registry/core.js +7 -28
  5. package/dist/config/domains.d.ts +10 -8
  6. package/dist/config/domains.js +4 -7
  7. package/dist/contracts/access-core.d.ts +135 -0
  8. package/dist/contracts/access-core.js +242 -0
  9. package/dist/contracts/access-profiles.d.ts +8 -8
  10. package/dist/contracts/access-profiles.js +8 -8
  11. package/dist/contracts/access.d.ts +14 -103
  12. package/dist/contracts/access.js +10 -210
  13. package/dist/contracts/activity.d.ts +54 -55
  14. package/dist/contracts/activity.js +38 -9
  15. package/dist/contracts/api-keys.d.ts +69 -26
  16. package/dist/contracts/api-keys.js +29 -2
  17. package/dist/contracts/application-journal.d.ts +197 -4
  18. package/dist/contracts/application-journal.js +97 -16
  19. package/dist/contracts/auth.d.ts +20 -0
  20. package/dist/contracts/auth.js +18 -0
  21. package/dist/contracts/beta.d.ts +13 -0
  22. package/dist/contracts/beta.js +28 -0
  23. package/dist/contracts/billing.d.ts +2 -2
  24. package/dist/contracts/bootstrap.d.ts +23 -6
  25. package/dist/contracts/builds.d.ts +24 -4
  26. package/dist/contracts/builds.js +16 -4
  27. package/dist/contracts/channels.d.ts +43 -0
  28. package/dist/contracts/channels.js +22 -6
  29. package/dist/contracts/comments.d.ts +49 -0
  30. package/dist/contracts/comments.js +61 -2
  31. package/dist/contracts/commerce.d.ts +19 -13
  32. package/dist/contracts/connector-access.d.ts +28 -0
  33. package/dist/contracts/connector-access.js +31 -0
  34. package/dist/contracts/connectors.d.ts +2382 -0
  35. package/dist/contracts/connectors.js +941 -0
  36. package/dist/contracts/content-contract-verification.d.ts +112 -58
  37. package/dist/contracts/content-contract-verification.js +42 -54
  38. package/dist/contracts/content-model-emit.d.ts +97 -0
  39. package/dist/contracts/content-model-emit.js +306 -0
  40. package/dist/contracts/content-model-sdk.d.ts +101 -0
  41. package/dist/contracts/content-model-sdk.js +232 -0
  42. package/dist/contracts/{content-program.d.ts → content-model.d.ts} +338 -82
  43. package/dist/contracts/{content-program.js → content-model.js} +291 -63
  44. package/dist/contracts/content-platform-fixture.d.ts +380 -110
  45. package/dist/contracts/content-platform-fixture.js +8 -8
  46. package/dist/contracts/content-sync.d.ts +197 -74
  47. package/dist/contracts/content-sync.js +98 -37
  48. package/dist/contracts/content.d.ts +30 -422
  49. package/dist/contracts/content.js +34 -294
  50. package/dist/contracts/dashboard-prefs.d.ts +10 -3
  51. package/dist/contracts/dashboard-prefs.js +6 -3
  52. package/dist/contracts/data-location.d.ts +9 -0
  53. package/dist/contracts/data-location.js +7 -0
  54. package/dist/contracts/deployment-comparison.d.ts +67 -0
  55. package/dist/contracts/deployment-comparison.js +68 -0
  56. package/dist/contracts/device-auth.d.ts +55 -11
  57. package/dist/contracts/domains.d.ts +40 -16
  58. package/dist/contracts/domains.js +23 -0
  59. package/dist/contracts/enums.d.ts +1 -10
  60. package/dist/contracts/enums.js +0 -15
  61. package/dist/contracts/error-code-meta.d.ts +388 -20
  62. package/dist/contracts/error-code-meta.js +201 -5
  63. package/dist/contracts/error-codes.d.ts +17 -4
  64. package/dist/contracts/error-codes.js +109 -10
  65. package/dist/contracts/events.d.ts +5 -0
  66. package/dist/contracts/events.js +12 -3
  67. package/dist/contracts/execution.d.ts +5 -1
  68. package/dist/contracts/execution.js +4 -0
  69. package/dist/contracts/feature-lifecycle.d.ts +53 -20
  70. package/dist/contracts/feature-lifecycle.js +65 -23
  71. package/dist/contracts/features.d.ts +57 -31
  72. package/dist/contracts/features.js +0 -1
  73. package/dist/contracts/feedback.d.ts +124 -0
  74. package/dist/contracts/feedback.js +64 -0
  75. package/dist/contracts/fixtures/content-model-sdk-v1.generated.d.ts +129 -0
  76. package/dist/contracts/fixtures/content-model-sdk-v1.generated.js +48 -0
  77. package/dist/contracts/fixtures/content-platform-v1.json +101 -49
  78. package/dist/contracts/frame-session.d.ts +60 -10
  79. package/dist/contracts/frame-session.js +52 -12
  80. package/dist/contracts/functions.d.ts +28 -2
  81. package/dist/contracts/functions.js +25 -2
  82. package/dist/contracts/grant-copy.d.ts +2 -0
  83. package/dist/contracts/grant-copy.js +2 -0
  84. package/dist/contracts/grants-core.d.ts +95 -0
  85. package/dist/contracts/grants-core.js +435 -0
  86. package/dist/contracts/grants.d.ts +13 -84
  87. package/dist/contracts/grants.js +21 -369
  88. package/dist/contracts/ids-core.d.ts +11 -0
  89. package/dist/contracts/ids-core.js +14 -0
  90. package/dist/contracts/ids.d.ts +7 -4
  91. package/dist/contracts/ids.js +12 -4
  92. package/dist/contracts/internal.d.ts +18 -0
  93. package/dist/contracts/internal.js +19 -0
  94. package/dist/contracts/mcp.d.ts +8 -18
  95. package/dist/contracts/mcp.js +2 -23
  96. package/dist/contracts/notifications.d.ts +4 -1
  97. package/dist/contracts/notifications.js +1 -0
  98. package/dist/contracts/oauth-resources.d.ts +55 -9
  99. package/dist/contracts/oauth-resources.js +64 -1
  100. package/dist/contracts/oauth-scope-actions.d.ts +27 -3
  101. package/dist/contracts/oauth-scope-actions.js +18 -8
  102. package/dist/contracts/operations.d.ts +1 -1
  103. package/dist/contracts/partner-account.d.ts +629 -0
  104. package/dist/contracts/partner-account.js +18 -0
  105. package/dist/contracts/principal-assertion.d.ts +74 -1
  106. package/dist/contracts/principal-assertion.js +67 -3
  107. package/dist/contracts/publish-archive.d.ts +22 -1
  108. package/dist/contracts/push-new.d.ts +3 -3
  109. package/dist/contracts/push-new.js +1 -1
  110. package/dist/contracts/quotas.js +2 -1
  111. package/dist/contracts/repository-connections.d.ts +10 -6
  112. package/dist/contracts/repository-connections.js +15 -0
  113. package/dist/contracts/resources.d.ts +6 -5
  114. package/dist/contracts/resources.js +7 -0
  115. package/dist/contracts/route-inventory.d.ts +74 -19
  116. package/dist/contracts/route-inventory.js +20 -6
  117. package/dist/contracts/runtime-api.d.ts +415 -4
  118. package/dist/contracts/runtime-api.js +60 -15
  119. package/dist/contracts/runtime-app.d.ts +6 -1
  120. package/dist/contracts/runtime-components.d.ts +646 -18
  121. package/dist/contracts/runtime-components.js +304 -188
  122. package/dist/contracts/runtime-services.d.ts +15 -0
  123. package/dist/contracts/runtime-services.js +25 -0
  124. package/dist/contracts/runtime-storage.d.ts +32 -0
  125. package/dist/contracts/runtime-storage.js +37 -0
  126. package/dist/contracts/source-workspaces.d.ts +511 -0
  127. package/dist/contracts/source-workspaces.js +276 -0
  128. package/dist/contracts/space-config-spacefast.d.ts +394 -0
  129. package/dist/contracts/space-config-spacefast.js +70 -0
  130. package/dist/contracts/space-config.d.ts +177 -90
  131. package/dist/contracts/space-config.js +77 -92
  132. package/dist/contracts/spaces.d.ts +132 -24
  133. package/dist/contracts/spaces.js +77 -13
  134. package/dist/contracts/superadmin-connectors.d.ts +371 -0
  135. package/dist/contracts/superadmin-connectors.js +61 -0
  136. package/dist/contracts/superadmin-emails.d.ts +1 -1
  137. package/dist/contracts/superadmin-emails.js +1 -1
  138. package/dist/contracts/superadmin-entities.d.ts +105 -0
  139. package/dist/contracts/superadmin-entities.js +64 -0
  140. package/dist/contracts/superadmin-runtime.d.ts +35 -116
  141. package/dist/contracts/superadmin-runtime.js +13 -69
  142. package/dist/contracts/superadmin-search.d.ts +12 -14
  143. package/dist/contracts/superadmin-search.js +2 -2
  144. package/dist/contracts/superadmin-spaces.d.ts +15 -72
  145. package/dist/contracts/superadmin-spaces.js +2 -7
  146. package/dist/contracts/superadmin-teams.d.ts +12 -0
  147. package/dist/contracts/superadmin-teams.js +7 -1
  148. package/dist/contracts/superadmin-tenants.d.ts +44 -16
  149. package/dist/contracts/superadmin.d.ts +2 -2
  150. package/dist/contracts/tags.d.ts +12 -12
  151. package/dist/contracts/teams.d.ts +29 -1
  152. package/dist/contracts/teams.js +24 -2
  153. package/dist/contracts/tenants.d.ts +98 -0
  154. package/dist/contracts/tenants.js +20 -0
  155. package/dist/contracts/transfers.d.ts +92 -0
  156. package/dist/contracts/transfers.js +37 -0
  157. package/dist/contracts/usage.d.ts +9 -1
  158. package/dist/contracts/usage.js +2 -0
  159. package/dist/contracts/visual-review.d.ts +448 -0
  160. package/dist/contracts/visual-review.js +156 -0
  161. package/dist/contracts/wordpress-php-toolkit.json +9 -0
  162. package/dist/contracts/work-mode.d.ts +24 -0
  163. package/dist/contracts/work-mode.js +17 -0
  164. package/dist/contracts/wp-cli.d.ts +66 -0
  165. package/dist/contracts/wp-cli.js +68 -0
  166. package/dist/contracts/zero-catalog.d.ts +29 -0
  167. package/dist/contracts/zero-catalog.js +55 -0
  168. package/dist/contracts/zero-platform-abilities.generated.d.ts +31 -0
  169. package/dist/contracts/zero-platform-abilities.generated.js +373 -0
  170. package/dist/contracts/zero-spacefast.d.ts +444 -0
  171. package/dist/contracts/zero-spacefast.js +149 -0
  172. package/dist/contracts/zero-types.d.ts +47 -0
  173. package/dist/contracts/zero-types.js +263 -0
  174. package/dist/contracts/zero.d.ts +781 -14
  175. package/dist/contracts/zero.js +204 -10
  176. package/dist/dashboard-paths/index.d.ts +2 -2
  177. package/dist/dashboard-paths/route-reservations.generated.d.ts +2 -2
  178. package/dist/dashboard-paths/route-reservations.generated.js +5 -0
  179. package/dist/docs/agent-prose.d.ts +1 -1
  180. package/dist/docs/agent-prose.js +15 -18
  181. package/dist/docs/agent-setup.d.ts +1 -1
  182. package/dist/docs/agent-setup.js +5 -13
  183. package/dist/docs/catalog.d.ts +64 -28
  184. package/dist/docs/catalog.js +155 -28
  185. package/dist/docs/error-docs.d.ts +365 -17
  186. package/dist/docs/error-docs.js +369 -21
  187. package/dist/docs/reference-urls.js +1 -1
  188. package/dist/docs/skills.d.ts +84 -84
  189. package/dist/docs/skills.js +66 -47
  190. package/dist/docs/start-prompts.d.ts +14 -0
  191. package/dist/docs/start-prompts.js +20 -0
  192. package/dist/utils/account-labels.d.ts +7 -0
  193. package/dist/utils/account-labels.js +15 -0
  194. package/dist/utils/auth.d.ts +1 -0
  195. package/dist/utils/auth.js +1 -0
  196. package/dist/utils/credential-policy.d.ts +22 -1
  197. package/dist/utils/credential-policy.js +55 -6
  198. package/dist/utils/local-space-state.d.ts +7 -0
  199. package/dist/utils/local-space-state.js +7 -0
  200. package/dist/utils/logger.d.ts +34 -0
  201. package/dist/utils/logger.js +144 -0
  202. package/dist/utils/page-routes.d.ts +9 -0
  203. package/dist/utils/page-routes.js +82 -0
  204. package/dist/utils/pages.d.ts +2 -0
  205. package/dist/utils/pages.js +7 -0
  206. package/dist/utils/publish-form-data.d.ts +2 -0
  207. package/dist/utils/publish-form-data.js +2 -0
  208. package/dist/utils/publish-policy-spacefast.d.ts +13 -0
  209. package/dist/utils/publish-policy-spacefast.js +117 -0
  210. package/dist/utils/publish-policy.d.ts +22 -16
  211. package/dist/utils/publish-policy.fixtures.json +15 -0
  212. package/dist/utils/publish-policy.js +62 -139
  213. package/dist/utils/query-client.js +9 -1
  214. package/dist/utils/runtime-upload.d.ts +4 -0
  215. package/dist/utils/runtime-upload.js +5 -0
  216. package/dist/utils/space-config.d.ts +2 -3
  217. package/dist/utils/space-config.js +1 -1
  218. package/dist/utils/uploaded-source.d.ts +4 -0
  219. package/dist/utils/uploaded-source.js +12 -0
  220. package/dist/visual-review.d.ts +4 -0
  221. package/dist/visual-review.js +208 -0
  222. package/dist/vocabulary.d.ts +38 -0
  223. package/dist/vocabulary.js +55 -0
  224. package/package.json +7 -2
  225. package/dist/agents/registry/deeplink-probes.d.ts +0 -23
  226. package/dist/agents/registry/deeplink-probes.js +0 -18
@@ -0,0 +1,435 @@
1
+ import { z } from "zod";
2
+ import { ISO_COUNTRY_CODES } from "./countries.js";
3
+ // The grant VOCABULARY: what an authority looks like, independent of who holds
4
+ // one. A capability set, a resource pattern set, a target selector and the
5
+ // constraints that fence them are the same grammar wherever a runtime enforces
6
+ // them, so this half carries no host concepts and no host ids.
7
+ //
8
+ // WHO holds a grant — audiences, sources, stored Grant records, credentials,
9
+ // identity connections — is Spacefast's sharing model and lives in `./grants.js`.
10
+ export const GRANT_CAPABILITIES = [
11
+ "page.view",
12
+ "comments.read",
13
+ "comments.write",
14
+ "content.publish",
15
+ "access.manage",
16
+ ];
17
+ export const grantCapabilitySchema = z.enum(GRANT_CAPABILITIES);
18
+ /** An opaque reference to something a grant points at (a version, a branch, a holder). */
19
+ export const grantReferenceSchema = z.string().trim().min(1).max(255);
20
+ /**
21
+ * A verification key an external token issuer publishes: a key id and a raw
22
+ * Ed25519 public key, base64url-encoded. Key material, not a host concept — the
23
+ * same shape serves identity connections and a partner's declared issuers.
24
+ */
25
+ export const identityConnectionPublicKeySchema = z
26
+ .object({
27
+ kid: z.string().min(1).max(64),
28
+ publicKey: z
29
+ .string()
30
+ .regex(/^[A-Za-z0-9_-]{43}$/, "publicKey must be a raw Ed25519 public key"),
31
+ })
32
+ .strict();
33
+ function hasUnsafePatternCharacter(value) {
34
+ for (const character of value) {
35
+ const codePoint = character.codePointAt(0);
36
+ if (codePoint === undefined ||
37
+ codePoint <= 0x1f ||
38
+ codePoint === 0x7f ||
39
+ character === "\\" ||
40
+ character === "?" ||
41
+ character === "#") {
42
+ return true;
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+ /**
48
+ * Canonical resource-pattern syntax shared by config compilation and evaluation.
49
+ * `*` matches one path segment and `**` matches zero or more segments. Wildcards
50
+ * are whole segments so a pattern can never disguise an encoded separator.
51
+ *
52
+ * Unlike URL-route canonicalization, resource patterns retain a terminal
53
+ * `index.html`: Grants can constrain the visitor-facing route and the artifact
54
+ * it resolves to independently.
55
+ */
56
+ export function normalizeGrantResourcePattern(input) {
57
+ if (!input.startsWith("/") || input.startsWith("//") || hasUnsafePatternCharacter(input)) {
58
+ throw new TypeError("resource pattern must be a plain absolute URL path pattern");
59
+ }
60
+ if (/%2f|%5c|%2a/iu.test(input)) {
61
+ throw new TypeError("resource pattern contains an ambiguous encoded separator or wildcard");
62
+ }
63
+ let decoded;
64
+ try {
65
+ decoded = decodeURIComponent(input);
66
+ }
67
+ catch {
68
+ throw new TypeError("resource pattern contains malformed percent encoding");
69
+ }
70
+ if (hasUnsafePatternCharacter(decoded)) {
71
+ throw new TypeError("resource pattern contains an unsafe character");
72
+ }
73
+ const segments = [];
74
+ for (const rawSegment of decoded.split("/")) {
75
+ const segment = rawSegment.normalize("NFC");
76
+ if (segment === "" || segment === ".")
77
+ continue;
78
+ if (segment === "..") {
79
+ if (segments.length === 0)
80
+ throw new TypeError("resource pattern escapes the URL root");
81
+ segments.pop();
82
+ continue;
83
+ }
84
+ if (segment.includes("*") && segment !== "*" && segment !== "**") {
85
+ throw new TypeError("resource wildcards must occupy a whole path segment");
86
+ }
87
+ segments.push(segment);
88
+ }
89
+ return segments.length === 0 ? "/" : `/${segments.join("/")}`;
90
+ }
91
+ export const grantResourcePatternSchema = z
92
+ .string()
93
+ .min(1)
94
+ .max(1024)
95
+ .check((context) => {
96
+ try {
97
+ context.value = normalizeGrantResourcePattern(context.value);
98
+ }
99
+ catch (error) {
100
+ context.issues.push({
101
+ code: "custom",
102
+ input: context.value,
103
+ message: error instanceof Error ? error.message : "invalid resource pattern",
104
+ });
105
+ }
106
+ });
107
+ export function uniqueArray(values) {
108
+ return new Set(values).size === values.length;
109
+ }
110
+ export const GRANT_RESOURCE_PATTERN_LIMIT = 100;
111
+ export const grantResourceSetSchema = z
112
+ .object({
113
+ include: z.array(grantResourcePatternSchema).min(1).max(GRANT_RESOURCE_PATTERN_LIMIT),
114
+ exclude: z.array(grantResourcePatternSchema).max(GRANT_RESOURCE_PATTERN_LIMIT).default([]),
115
+ })
116
+ .strict()
117
+ .superRefine((value, context) => {
118
+ if (value.include.length + value.exclude.length > GRANT_RESOURCE_PATTERN_LIMIT) {
119
+ context.addIssue({
120
+ code: "custom",
121
+ message: `resource sets support up to ${GRANT_RESOURCE_PATTERN_LIMIT} patterns`,
122
+ });
123
+ }
124
+ if (!uniqueArray(value.include)) {
125
+ context.addIssue({
126
+ code: "custom",
127
+ path: ["include"],
128
+ message: "include patterns must be unique",
129
+ });
130
+ }
131
+ if (!uniqueArray(value.exclude)) {
132
+ context.addIssue({
133
+ code: "custom",
134
+ path: ["exclude"],
135
+ message: "exclude patterns must be unique",
136
+ });
137
+ }
138
+ });
139
+ export const GRANT_TARGET_KINDS = ["live", "version", "branch", "all_versions"];
140
+ export const grantTargetKindSchema = z.enum(GRANT_TARGET_KINDS);
141
+ export const grantTargetSelectorSchema = z.discriminatedUnion("kind", [
142
+ z.object({ kind: z.literal("live") }).strict(),
143
+ z.object({ kind: z.literal("version"), versionId: grantReferenceSchema }).strict(),
144
+ z.object({ kind: z.literal("branch"), branch: grantReferenceSchema }).strict(),
145
+ z.object({ kind: z.literal("all_versions") }).strict(),
146
+ ]);
147
+ function parseIpv4(input) {
148
+ const parts = input.split(".");
149
+ if (parts.length !== 4)
150
+ return null;
151
+ let bits = 0n;
152
+ for (const part of parts) {
153
+ if (!/^(?:0|[1-9][0-9]{0,2})$/u.test(part))
154
+ return null;
155
+ const value = Number(part);
156
+ if (value > 255)
157
+ return null;
158
+ bits = (bits << 8n) | BigInt(value);
159
+ }
160
+ return { bits, width: 32 };
161
+ }
162
+ function parseIpv6(input) {
163
+ if (input === "" || input.includes("%") || input.split("::").length > 2)
164
+ return null;
165
+ let value = input.toLowerCase();
166
+ const ipv4Tail = value.match(/(?:^|:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/u)?.[1];
167
+ if (ipv4Tail) {
168
+ const parsed = parseIpv4(ipv4Tail);
169
+ if (!parsed)
170
+ return null;
171
+ value = `${value.slice(0, -ipv4Tail.length)}${Number((parsed.bits >> 16n) & 0xffffn).toString(16)}:${Number(parsed.bits & 0xffffn).toString(16)}`;
172
+ }
173
+ const [leftText, rightText] = value.split("::");
174
+ const left = leftText ? leftText.split(":") : [];
175
+ const right = rightText ? rightText.split(":") : [];
176
+ if ([...left, ...right].some((part) => !/^[0-9a-f]{1,4}$/u.test(part)))
177
+ return null;
178
+ const compressed = value.includes("::");
179
+ const missing = 8 - left.length - right.length;
180
+ if ((!compressed && missing !== 0) || (compressed && missing < 1))
181
+ return null;
182
+ const parts = [...left, ...Array.from({ length: missing }, () => "0"), ...right];
183
+ if (parts.length !== 8)
184
+ return null;
185
+ return {
186
+ bits: parts.reduce((bits, part) => (bits << 16n) | BigInt(`0x${part}`), 0n),
187
+ width: 128,
188
+ };
189
+ }
190
+ function parseIpAddress(input) {
191
+ return parseIpv4(input) ?? parseIpv6(input);
192
+ }
193
+ export function normalizeGrantNetworkCidr(input) {
194
+ const value = input.trim().toLowerCase();
195
+ const separator = value.lastIndexOf("/");
196
+ const address = separator === -1 ? value : value.slice(0, separator);
197
+ const parsed = parseIpAddress(address);
198
+ if (!parsed)
199
+ throw new TypeError("network rules require a valid IPv4 or IPv6 address");
200
+ if (separator === -1)
201
+ return value;
202
+ const prefixText = value.slice(separator + 1);
203
+ if (!/^(?:0|[1-9][0-9]{0,2})$/u.test(prefixText)) {
204
+ throw new TypeError("network rules require a valid CIDR prefix");
205
+ }
206
+ const prefix = Number(prefixText);
207
+ if (prefix > parsed.width)
208
+ throw new TypeError("network CIDR prefix exceeds its address width");
209
+ return `${address}/${prefix}`;
210
+ }
211
+ export function grantNetworkCidrMatches(cidr, ipAddress) {
212
+ let canonical;
213
+ try {
214
+ canonical = normalizeGrantNetworkCidr(cidr);
215
+ }
216
+ catch {
217
+ return false;
218
+ }
219
+ const separator = canonical.lastIndexOf("/");
220
+ const networkText = separator === -1 ? canonical : canonical.slice(0, separator);
221
+ const network = parseIpAddress(networkText);
222
+ const address = parseIpAddress(ipAddress.trim().toLowerCase());
223
+ if (!network || !address || network.width !== address.width)
224
+ return false;
225
+ const prefix = separator === -1 ? network.width : Number(canonical.slice(separator + 1));
226
+ if (prefix === 0)
227
+ return true;
228
+ const shift = BigInt(network.width - prefix);
229
+ return network.bits >> shift === address.bits >> shift;
230
+ }
231
+ const grantNetworkCidrSchema = z
232
+ .string()
233
+ .min(1)
234
+ .max(64)
235
+ .check((context) => {
236
+ try {
237
+ context.value = normalizeGrantNetworkCidr(context.value);
238
+ }
239
+ catch (error) {
240
+ context.issues.push({
241
+ code: "custom",
242
+ input: context.value,
243
+ message: error instanceof Error ? error.message : "invalid network rule",
244
+ });
245
+ }
246
+ });
247
+ const grantCountrySchema = z
248
+ .string()
249
+ .length(2)
250
+ .overwrite((country) => country.toUpperCase())
251
+ .refine((country) => ISO_COUNTRY_CODES.some((candidate) => candidate === country), "Country must be an ISO 3166-1 alpha-2 code.");
252
+ const grantConstraintDateSchema = z.string().datetime();
253
+ const grantConstraintMaxUsesSchema = z.number().int().positive().max(1_000_000);
254
+ const grantConstraintIpCidrsSchema = z.array(grantNetworkCidrSchema).min(1).max(50);
255
+ const grantConstraintCountriesSchema = z.array(grantCountrySchema).min(1).max(250);
256
+ const grantConstraintUserAgentsSchema = z.array(z.string().trim().min(1).max(200)).min(1).max(50);
257
+ const grantNetworkConstraintsSchema = z
258
+ .object({
259
+ ipCidrs: grantConstraintIpCidrsSchema.optional(),
260
+ countries: grantConstraintCountriesSchema.optional(),
261
+ excludedCountries: grantConstraintCountriesSchema.optional(),
262
+ excludedUserAgentSubstrings: grantConstraintUserAgentsSchema.optional(),
263
+ })
264
+ .strict()
265
+ .superRefine((network, context) => {
266
+ if (network.ipCidrs === undefined &&
267
+ network.countries === undefined &&
268
+ network.excludedCountries === undefined &&
269
+ network.excludedUserAgentSubstrings === undefined) {
270
+ context.addIssue({
271
+ code: "custom",
272
+ message: "network requires at least one IP, country, or user-agent selector",
273
+ });
274
+ }
275
+ });
276
+ export const grantFrameOriginSchema = z
277
+ .string()
278
+ .trim()
279
+ .min(1)
280
+ .max(2_048)
281
+ .check((context) => {
282
+ let url;
283
+ try {
284
+ url = new URL(context.value);
285
+ }
286
+ catch {
287
+ context.issues.push({
288
+ code: "custom",
289
+ input: context.value,
290
+ message: "frameOrigin must be an HTTPS origin",
291
+ });
292
+ return;
293
+ }
294
+ const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
295
+ if ((url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) ||
296
+ url.username ||
297
+ url.password ||
298
+ url.pathname !== "/" ||
299
+ url.search ||
300
+ url.hash) {
301
+ context.issues.push({
302
+ code: "custom",
303
+ input: context.value,
304
+ message: "frameOrigin must be an HTTPS origin without a path, query, or credentials",
305
+ });
306
+ return;
307
+ }
308
+ context.value = url.origin;
309
+ });
310
+ export const grantConstraintsSchema = z
311
+ .object({
312
+ notBefore: grantConstraintDateSchema.optional(),
313
+ expiresAt: grantConstraintDateSchema.optional(),
314
+ maxUses: grantConstraintMaxUsesSchema.optional(),
315
+ requireVerifiedEmail: z.boolean().optional(),
316
+ network: grantNetworkConstraintsSchema.optional(),
317
+ frameOrigin: grantFrameOriginSchema.optional(),
318
+ })
319
+ .strict()
320
+ .superRefine((value, context) => {
321
+ if (value.notBefore !== undefined &&
322
+ value.expiresAt !== undefined &&
323
+ Date.parse(value.notBefore) >= Date.parse(value.expiresAt)) {
324
+ context.addIssue({
325
+ code: "custom",
326
+ path: ["expiresAt"],
327
+ message: "expiresAt must be later than notBefore",
328
+ });
329
+ }
330
+ });
331
+ /** Field-scoped PATCH shape. `null` clears one constraint without replacing its siblings. */
332
+ export const grantConstraintsPatchSchema = z
333
+ .object({
334
+ notBefore: grantConstraintDateSchema.nullable().optional(),
335
+ expiresAt: grantConstraintDateSchema.nullable().optional(),
336
+ maxUses: grantConstraintMaxUsesSchema.nullable().optional(),
337
+ requireVerifiedEmail: z.boolean().nullable().optional(),
338
+ frameOrigin: grantFrameOriginSchema.nullable().optional(),
339
+ network: z
340
+ .object({
341
+ ipCidrs: grantConstraintIpCidrsSchema.nullable().optional(),
342
+ countries: grantConstraintCountriesSchema.nullable().optional(),
343
+ excludedCountries: grantConstraintCountriesSchema.nullable().optional(),
344
+ excludedUserAgentSubstrings: grantConstraintUserAgentsSchema.nullable().optional(),
345
+ })
346
+ .strict()
347
+ .nullable()
348
+ .optional(),
349
+ })
350
+ .strict();
351
+ export function diffGrantConstraints(original, draft) {
352
+ let network;
353
+ if (JSON.stringify(original.network) === JSON.stringify(draft.network)) {
354
+ network = undefined;
355
+ }
356
+ else if (draft.network === undefined) {
357
+ network = null;
358
+ }
359
+ else {
360
+ const changedNetwork = {};
361
+ if (JSON.stringify(original.network?.ipCidrs) !== JSON.stringify(draft.network.ipCidrs)) {
362
+ changedNetwork.ipCidrs = draft.network.ipCidrs ?? null;
363
+ }
364
+ if (JSON.stringify(original.network?.countries) !== JSON.stringify(draft.network.countries)) {
365
+ changedNetwork.countries = draft.network.countries ?? null;
366
+ }
367
+ if (JSON.stringify(original.network?.excludedCountries) !==
368
+ JSON.stringify(draft.network.excludedCountries)) {
369
+ changedNetwork.excludedCountries = draft.network.excludedCountries ?? null;
370
+ }
371
+ if (JSON.stringify(original.network?.excludedUserAgentSubstrings) !==
372
+ JSON.stringify(draft.network.excludedUserAgentSubstrings)) {
373
+ changedNetwork.excludedUserAgentSubstrings =
374
+ draft.network.excludedUserAgentSubstrings ?? null;
375
+ }
376
+ network = changedNetwork;
377
+ }
378
+ const patch = {};
379
+ if (original.notBefore !== draft.notBefore) {
380
+ patch.notBefore = draft.notBefore ?? null;
381
+ }
382
+ if (original.expiresAt !== draft.expiresAt) {
383
+ patch.expiresAt = draft.expiresAt ?? null;
384
+ }
385
+ if (original.maxUses !== draft.maxUses) {
386
+ patch.maxUses = draft.maxUses ?? null;
387
+ }
388
+ if (original.requireVerifiedEmail !== draft.requireVerifiedEmail) {
389
+ patch.requireVerifiedEmail = draft.requireVerifiedEmail ?? null;
390
+ }
391
+ if (network !== undefined) {
392
+ patch.network = network;
393
+ }
394
+ if (original.frameOrigin !== draft.frameOrigin) {
395
+ patch.frameOrigin = draft.frameOrigin ?? null;
396
+ }
397
+ return Object.keys(patch).length === 0 ? undefined : patch;
398
+ }
399
+ export function applyGrantConstraintsPatch(current, patch) {
400
+ let network = current.network;
401
+ if (patch.network === null) {
402
+ network = undefined;
403
+ }
404
+ else if (patch.network !== undefined) {
405
+ network = { ...current.network };
406
+ if (patch.network.ipCidrs !== undefined) {
407
+ network.ipCidrs = patch.network.ipCidrs ?? undefined;
408
+ }
409
+ if (patch.network.countries !== undefined) {
410
+ network.countries = patch.network.countries ?? undefined;
411
+ }
412
+ if (patch.network.excludedCountries !== undefined) {
413
+ network.excludedCountries = patch.network.excludedCountries ?? undefined;
414
+ }
415
+ if (patch.network.excludedUserAgentSubstrings !== undefined) {
416
+ network.excludedUserAgentSubstrings = patch.network.excludedUserAgentSubstrings ?? undefined;
417
+ }
418
+ }
419
+ const compactNetwork = network && Object.values(network).some((value) => value !== undefined) ? network : undefined;
420
+ const next = {
421
+ ...current,
422
+ frameOrigin: patch.frameOrigin === undefined ? current.frameOrigin : (patch.frameOrigin ?? undefined),
423
+ network: compactNetwork,
424
+ };
425
+ if (patch.notBefore !== undefined)
426
+ next.notBefore = patch.notBefore ?? undefined;
427
+ if (patch.expiresAt !== undefined)
428
+ next.expiresAt = patch.expiresAt ?? undefined;
429
+ if (patch.maxUses !== undefined)
430
+ next.maxUses = patch.maxUses ?? undefined;
431
+ if (patch.requireVerifiedEmail !== undefined) {
432
+ next.requireVerifiedEmail = patch.requireVerifiedEmail ?? undefined;
433
+ }
434
+ return grantConstraintsSchema.parse(next);
435
+ }
@@ -1,13 +1,5 @@
1
1
  import { z } from "zod";
2
- export declare const GRANT_CAPABILITIES: readonly ["page.view", "comments.read", "comments.write", "content.publish", "access.manage"];
3
- export declare const grantCapabilitySchema: z.ZodEnum<{
4
- "page.view": "page.view";
5
- "comments.read": "comments.read";
6
- "comments.write": "comments.write";
7
- "content.publish": "content.publish";
8
- "access.manage": "access.manage";
9
- }>;
10
- export type GrantCapability = z.infer<typeof grantCapabilitySchema>;
2
+ export * from "./grants-core.js";
11
3
  export declare const GRANT_AUDIENCE_KINDS: readonly ["public", "team", "person", "link", "password", "machine", "external"];
12
4
  export declare const grantAudienceKindSchema: z.ZodEnum<{
13
5
  link: "link";
@@ -42,75 +34,6 @@ export declare const grantAudienceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
42
34
  subject: z.ZodString;
43
35
  }, z.core.$strict>], "kind">;
44
36
  export type GrantAudience = z.infer<typeof grantAudienceSchema>;
45
- /**
46
- * Canonical resource-pattern syntax shared by config compilation and evaluation.
47
- * `*` matches one path segment and `**` matches zero or more segments. Wildcards
48
- * are whole segments so a pattern can never disguise an encoded separator.
49
- *
50
- * Unlike URL-route canonicalization, resource patterns retain a terminal
51
- * `index.html`: Grants can constrain the visitor-facing route and the artifact
52
- * it resolves to independently.
53
- */
54
- export declare function normalizeGrantResourcePattern(input: string): string;
55
- export declare const grantResourcePatternSchema: z.ZodString;
56
- export type GrantResourcePattern = z.infer<typeof grantResourcePatternSchema>;
57
- export declare const GRANT_RESOURCE_PATTERN_LIMIT = 100;
58
- export declare const grantResourceSetSchema: z.ZodObject<{
59
- include: z.ZodArray<z.ZodString>;
60
- exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
61
- }, z.core.$strict>;
62
- export type GrantResourceSet = z.infer<typeof grantResourceSetSchema>;
63
- export declare const GRANT_TARGET_KINDS: readonly ["live", "version", "branch", "all_versions"];
64
- export declare const grantTargetKindSchema: z.ZodEnum<{
65
- live: "live";
66
- version: "version";
67
- branch: "branch";
68
- all_versions: "all_versions";
69
- }>;
70
- export type GrantTargetKind = z.infer<typeof grantTargetKindSchema>;
71
- export declare const grantTargetSelectorSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
72
- kind: z.ZodLiteral<"live">;
73
- }, z.core.$strict>, z.ZodObject<{
74
- kind: z.ZodLiteral<"version">;
75
- versionId: z.ZodString;
76
- }, z.core.$strict>, z.ZodObject<{
77
- kind: z.ZodLiteral<"branch">;
78
- branch: z.ZodString;
79
- }, z.core.$strict>, z.ZodObject<{
80
- kind: z.ZodLiteral<"all_versions">;
81
- }, z.core.$strict>], "kind">;
82
- export type GrantTargetSelector = z.infer<typeof grantTargetSelectorSchema>;
83
- export declare function normalizeGrantNetworkCidr(input: string): string;
84
- export declare function grantNetworkCidrMatches(cidr: string, ipAddress: string): boolean;
85
- export declare const grantConstraintsSchema: z.ZodObject<{
86
- notBefore: z.ZodOptional<z.ZodString>;
87
- expiresAt: z.ZodOptional<z.ZodString>;
88
- maxUses: z.ZodOptional<z.ZodNumber>;
89
- requireVerifiedEmail: z.ZodOptional<z.ZodBoolean>;
90
- network: z.ZodOptional<z.ZodObject<{
91
- ipCidrs: z.ZodOptional<z.ZodArray<z.ZodString>>;
92
- countries: z.ZodOptional<z.ZodArray<z.ZodString>>;
93
- excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
- excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
95
- }, z.core.$strict>>;
96
- }, z.core.$strict>;
97
- export type GrantConstraints = z.infer<typeof grantConstraintsSchema>;
98
- /** Field-scoped PATCH shape. `null` clears one constraint without replacing its siblings. */
99
- export declare const grantConstraintsPatchSchema: z.ZodObject<{
100
- notBefore: z.ZodOptional<z.ZodNullable<z.ZodString>>;
101
- expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
- maxUses: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
103
- requireVerifiedEmail: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
104
- network: z.ZodOptional<z.ZodNullable<z.ZodObject<{
105
- ipCidrs: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
106
- countries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
107
- excludedCountries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
108
- excludedUserAgentSubstrings: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
109
- }, z.core.$strict>>>;
110
- }, z.core.$strict>;
111
- export type GrantConstraintsPatch = z.infer<typeof grantConstraintsPatchSchema>;
112
- export declare function diffGrantConstraints(original: GrantConstraints, draft: GrantConstraints): GrantConstraintsPatch | undefined;
113
- export declare function applyGrantConstraintsPatch(current: GrantConstraints, patch: GrantConstraintsPatch): GrantConstraints;
114
37
  export declare const GRANT_SOURCE_KINDS: readonly ["config", "managed", "system"];
115
38
  export declare const grantSourceKindSchema: z.ZodEnum<{
116
39
  config: "config";
@@ -180,6 +103,7 @@ export declare const grantSchema: z.ZodObject<{
180
103
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
181
104
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
182
105
  }, z.core.$strict>>;
106
+ frameOrigin: z.ZodOptional<z.ZodString>;
183
107
  }, z.core.$strict>>;
184
108
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
185
109
  kind: z.ZodLiteral<"live">;
@@ -249,6 +173,7 @@ export declare const managedGrantWriteSchema: z.ZodObject<{
249
173
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
250
174
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
251
175
  }, z.core.$strict>>;
176
+ frameOrigin: z.ZodOptional<z.ZodString>;
252
177
  }, z.core.$strict>>;
253
178
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
254
179
  kind: z.ZodLiteral<"live">;
@@ -292,6 +217,7 @@ export declare const directManagedGrantWriteSchema: z.ZodObject<{
292
217
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
293
218
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
294
219
  }, z.core.$strict>>;
220
+ frameOrigin: z.ZodOptional<z.ZodString>;
295
221
  }, z.core.$strict>>;
296
222
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
297
223
  kind: z.ZodLiteral<"live">;
@@ -339,6 +265,7 @@ export declare const spaceGrantCreateSchema: z.ZodObject<{
339
265
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
340
266
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
341
267
  }, z.core.$strict>>;
268
+ frameOrigin: z.ZodOptional<z.ZodString>;
342
269
  }, z.core.$strict>>;
343
270
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
344
271
  kind: z.ZodLiteral<"live">;
@@ -423,6 +350,7 @@ export declare const spaceGrantSchema: z.ZodObject<{
423
350
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
424
351
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
425
352
  }, z.core.$strict>>;
353
+ frameOrigin: z.ZodOptional<z.ZodString>;
426
354
  }, z.core.$strict>>;
427
355
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
428
356
  kind: z.ZodLiteral<"live">;
@@ -593,6 +521,7 @@ export declare const grantCheckSchema: z.ZodObject<{
593
521
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
594
522
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
595
523
  }, z.core.$strict>>;
524
+ frameOrigin: z.ZodOptional<z.ZodString>;
596
525
  }, z.core.$strict>>;
597
526
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
598
527
  kind: z.ZodLiteral<"live">;
@@ -685,6 +614,7 @@ export declare const grantCheckSchema: z.ZodObject<{
685
614
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
686
615
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
687
616
  }, z.core.$strict>>;
617
+ frameOrigin: z.ZodOptional<z.ZodString>;
688
618
  }, z.core.$strict>>;
689
619
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
690
620
  kind: z.ZodLiteral<"live">;
@@ -762,6 +692,7 @@ export declare const passwordCredentialCreateSchema: z.ZodObject<{
762
692
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
763
693
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
764
694
  }, z.core.$strict>>;
695
+ frameOrigin: z.ZodOptional<z.ZodString>;
765
696
  }, z.core.$strict>>;
766
697
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
767
698
  kind: z.ZodLiteral<"live">;
@@ -804,6 +735,7 @@ export declare const machineCredentialCreateSchema: z.ZodObject<{
804
735
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
805
736
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
806
737
  }, z.core.$strict>>;
738
+ frameOrigin: z.ZodOptional<z.ZodString>;
807
739
  }, z.core.$strict>>;
808
740
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
809
741
  kind: z.ZodLiteral<"live">;
@@ -867,6 +799,7 @@ export declare const passwordCredentialSchema: z.ZodObject<{
867
799
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
868
800
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
869
801
  }, z.core.$strict>>;
802
+ frameOrigin: z.ZodOptional<z.ZodString>;
870
803
  }, z.core.$strict>>;
871
804
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
872
805
  kind: z.ZodLiteral<"live">;
@@ -957,6 +890,7 @@ export declare const machineCredentialSchema: z.ZodObject<{
957
890
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
958
891
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
959
892
  }, z.core.$strict>>;
893
+ frameOrigin: z.ZodOptional<z.ZodString>;
960
894
  }, z.core.$strict>>;
961
895
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
962
896
  kind: z.ZodLiteral<"live">;
@@ -1049,6 +983,7 @@ export declare const machineCredentialSecretSchema: z.ZodObject<{
1049
983
  excludedCountries: z.ZodOptional<z.ZodArray<z.ZodString>>;
1050
984
  excludedUserAgentSubstrings: z.ZodOptional<z.ZodArray<z.ZodString>>;
1051
985
  }, z.core.$strict>>;
986
+ frameOrigin: z.ZodOptional<z.ZodString>;
1052
987
  }, z.core.$strict>>;
1053
988
  target: z.ZodDiscriminatedUnion<[z.ZodObject<{
1054
989
  kind: z.ZodLiteral<"live">;
@@ -1118,11 +1053,6 @@ export declare const credentialRevocationSchema: z.ZodObject<{
1118
1053
  }, z.core.$strict>;
1119
1054
  export declare const IDENTITY_CONNECTION_DEFAULT_TTL_SECONDS: number;
1120
1055
  export declare const EXTERNAL_IDENTITY_MAX_TTL_SECONDS: number;
1121
- export declare const identityConnectionPublicKeySchema: z.ZodObject<{
1122
- kid: z.ZodString;
1123
- publicKey: z.ZodString;
1124
- }, z.core.$strict>;
1125
- export type IdentityConnectionPublicKey = z.infer<typeof identityConnectionPublicKeySchema>;
1126
1056
  /**
1127
1057
  * Issuers the platform stamps on its own external Grants. A Team-configured
1128
1058
  * connection may not claim one: the authority reference an external audience
@@ -1184,4 +1114,3 @@ export declare const identityConnectionSchema: z.ZodObject<{
1184
1114
  revokedAt: z.ZodNullable<z.ZodString>;
1185
1115
  }, z.core.$strict>;
1186
1116
  export type IdentityConnection = z.infer<typeof identityConnectionSchema>;
1187
- export {};