@payloadcms/figma 1.0.0-beta.3 → 1.0.0-beta.5

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 (187) hide show
  1. package/dist/adapters/asset-collection.d.ts +15 -0
  2. package/dist/adapters/asset-collection.js +51 -45
  3. package/dist/adapters/build-lambda-zip.d.ts +8 -9
  4. package/dist/adapters/build-lambda-zip.js +36 -44
  5. package/dist/adapters/index.d.ts +4 -0
  6. package/dist/adapters/index.js +4 -0
  7. package/dist/adapters/lambdaLimits.d.ts +6 -0
  8. package/dist/adapters/lambdaLimits.js +5 -0
  9. package/dist/adapters/nextjs-assets.d.ts +7 -0
  10. package/dist/adapters/nextjs-assets.js +44 -0
  11. package/dist/adapters/nextjs.d.ts +8 -0
  12. package/dist/adapters/nextjs.js +19 -37
  13. package/dist/adapters/nitro.js +18 -43
  14. package/dist/adapters/omit-optional-sharp.d.ts +22 -0
  15. package/dist/adapters/omit-optional-sharp.js +158 -0
  16. package/dist/adapters/secret-files.js +8 -1
  17. package/dist/adapters/types.d.ts +8 -0
  18. package/dist/adapters/v2/core/build.d.ts +69 -0
  19. package/dist/adapters/v2/core/build.js +183 -0
  20. package/dist/adapters/v2/core/content-type.d.ts +3 -0
  21. package/dist/adapters/v2/core/content-type.js +41 -0
  22. package/dist/adapters/v2/core/getRelativePathError.d.ts +5 -0
  23. package/dist/adapters/v2/core/getRelativePathError.js +21 -0
  24. package/dist/adapters/v2/core/index.d.ts +15 -0
  25. package/dist/adapters/v2/core/index.js +13 -0
  26. package/dist/adapters/v2/core/limits.d.ts +28 -0
  27. package/dist/adapters/v2/core/limits.js +26 -0
  28. package/dist/adapters/v2/core/manifest-version.d.ts +10 -0
  29. package/dist/adapters/v2/core/manifest-version.js +14 -0
  30. package/dist/adapters/v2/core/server-zip.d.ts +58 -0
  31. package/dist/adapters/v2/core/server-zip.js +123 -0
  32. package/dist/adapters/v2/core/services.d.ts +46 -0
  33. package/dist/adapters/v2/core/services.js +202 -0
  34. package/dist/adapters/v2/core/static-path.d.ts +13 -0
  35. package/dist/adapters/v2/core/static-path.js +32 -0
  36. package/dist/adapters/v2/core/static-site.d.ts +26 -0
  37. package/dist/adapters/v2/core/static-site.js +95 -0
  38. package/dist/adapters/v2/core/types.d.ts +128 -0
  39. package/dist/adapters/v2/core/types.js +7 -0
  40. package/dist/adapters/v2/core/upload.d.ts +67 -0
  41. package/dist/adapters/v2/core/upload.js +198 -0
  42. package/dist/adapters/v2/core/validateDeployment/createIssue.d.ts +3 -0
  43. package/dist/adapters/v2/core/validateDeployment/createIssue.js +7 -0
  44. package/dist/adapters/v2/core/validateDeployment/escapePointer.d.ts +2 -0
  45. package/dist/adapters/v2/core/validateDeployment/escapePointer.js +3 -0
  46. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.d.ts +2 -0
  47. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.js +10 -0
  48. package/dist/adapters/v2/core/validateDeployment/types.d.ts +16 -0
  49. package/dist/adapters/v2/core/validateDeployment/types.js +8 -0
  50. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.d.ts +3 -0
  51. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.js +30 -0
  52. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.d.ts +8 -0
  53. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.js +26 -0
  54. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.d.ts +7 -0
  55. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.js +11 -0
  56. package/dist/adapters/v2/core/validateDeployment/validateCounts.d.ts +3 -0
  57. package/dist/adapters/v2/core/validateDeployment/validateCounts.js +41 -0
  58. package/dist/adapters/v2/core/validateDeployment/validateFallback.d.ts +3 -0
  59. package/dist/adapters/v2/core/validateDeployment/validateFallback.js +21 -0
  60. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.d.ts +6 -0
  61. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.js +13 -0
  62. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.d.ts +2 -0
  63. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.js +13 -0
  64. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.d.ts +11 -0
  65. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.js +38 -0
  66. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.d.ts +3 -0
  67. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.js +17 -0
  68. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.d.ts +6 -0
  69. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.js +24 -0
  70. package/dist/adapters/v2/core/validateDeployment/validateId.d.ts +7 -0
  71. package/dist/adapters/v2/core/validateDeployment/validateId.js +12 -0
  72. package/dist/adapters/v2/core/validateDeployment/validateMatch.d.ts +15 -0
  73. package/dist/adapters/v2/core/validateDeployment/validateMatch.js +74 -0
  74. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.d.ts +7 -0
  75. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.js +21 -0
  76. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.d.ts +3 -0
  77. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.js +16 -0
  78. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.d.ts +11 -0
  79. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.js +48 -0
  80. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.d.ts +10 -0
  81. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.js +16 -0
  82. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.d.ts +8 -0
  83. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.js +25 -0
  84. package/dist/adapters/v2/core/validateDeployment/validateResponses.d.ts +7 -0
  85. package/dist/adapters/v2/core/validateDeployment/validateResponses.js +59 -0
  86. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.d.ts +10 -0
  87. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.js +12 -0
  88. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.d.ts +14 -0
  89. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.js +59 -0
  90. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.d.ts +11 -0
  91. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.js +20 -0
  92. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.d.ts +11 -0
  93. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.js +26 -0
  94. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.d.ts +13 -0
  95. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.js +25 -0
  96. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.d.ts +12 -0
  97. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.js +35 -0
  98. package/dist/adapters/v2/core/validateDeployment/validateRoutes.d.ts +6 -0
  99. package/dist/adapters/v2/core/validateDeployment/validateRoutes.js +55 -0
  100. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.d.ts +3 -0
  101. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.js +12 -0
  102. package/dist/adapters/v2/core/validateDeployment/validateServers.d.ts +7 -0
  103. package/dist/adapters/v2/core/validateDeployment/validateServers.js +59 -0
  104. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.d.ts +3 -0
  105. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.js +22 -0
  106. package/dist/adapters/v2/core/validateDeployment.d.ts +7 -0
  107. package/dist/adapters/v2/core/validateDeployment.js +42 -0
  108. package/dist/adapters/v2/core/write.d.ts +21 -0
  109. package/dist/adapters/v2/core/write.js +30 -0
  110. package/dist/adapters/v2/nextjs/coverage.d.ts +45 -0
  111. package/dist/adapters/v2/nextjs/coverage.js +113 -0
  112. package/dist/adapters/v2/nextjs/read-build-output.d.ts +116 -0
  113. package/dist/adapters/v2/nextjs/read-build-output.js +368 -0
  114. package/dist/adapters/v2/nextjs/translate.d.ts +20 -0
  115. package/dist/adapters/v2/nextjs/translate.js +400 -0
  116. package/dist/adapters/vite.d.ts +7 -0
  117. package/dist/adapters/vite.js +47 -0
  118. package/dist/adapters/writeZip.d.ts +20 -0
  119. package/dist/adapters/writeZip.js +28 -0
  120. package/dist/api/control-plane.d.ts +28 -6
  121. package/dist/api/control-plane.js +67 -64
  122. package/dist/auth/cli-build-context.d.ts +3 -0
  123. package/dist/auth/cli-build-context.js +2 -0
  124. package/dist/auth/oauth-flow.d.ts +3 -3
  125. package/dist/auth/oauth-flow.js +13 -3
  126. package/dist/cli.js +15 -0
  127. package/dist/commands/build-manifest.d.ts +49 -0
  128. package/dist/commands/build-manifest.js +111 -0
  129. package/dist/commands/deploy.js +195 -26
  130. package/dist/db-content-api/generated/content-api-types.d.ts +18 -14
  131. package/dist/db-content-api/index.js +4 -1
  132. package/dist/db-content-api/utilities/where.js +2 -6
  133. package/dist/endpoints/client-config.d.ts +3 -0
  134. package/dist/endpoints/client-config.js +87 -0
  135. package/dist/image-transforms/constants.d.ts +8 -0
  136. package/dist/image-transforms/constants.js +26 -0
  137. package/dist/image-transforms/createImageTransformer.d.ts +6 -0
  138. package/dist/image-transforms/createImageTransformer.js +100 -0
  139. package/dist/image-transforms/deliverImageResponse.d.ts +11 -0
  140. package/dist/image-transforms/deliverImageResponse.js +43 -0
  141. package/dist/image-transforms/imageRevision.d.ts +14 -0
  142. package/dist/image-transforms/imageRevision.js +115 -0
  143. package/dist/image-transforms/normalizeMediaType.d.ts +2 -0
  144. package/dist/image-transforms/normalizeMediaType.js +3 -0
  145. package/dist/image-transforms/parseImageOverrides.d.ts +4 -0
  146. package/dist/image-transforms/parseImageOverrides.js +20 -0
  147. package/dist/image-transforms/preserveImageRedirectHeaders.d.ts +2 -0
  148. package/dist/image-transforms/preserveImageRedirectHeaders.js +30 -0
  149. package/dist/image-transforms/preventConflictingImageTransformers.d.ts +9 -0
  150. package/dist/image-transforms/preventConflictingImageTransformers.js +67 -0
  151. package/dist/image-transforms/serveImageRequest.d.ts +6 -0
  152. package/dist/image-transforms/serveImageRequest.js +97 -0
  153. package/dist/image-transforms/storedImage.d.ts +49 -0
  154. package/dist/image-transforms/storedImage.js +84 -0
  155. package/dist/image-transforms/types.d.ts +9 -0
  156. package/dist/image-transforms/types.js +1 -0
  157. package/dist/image-transforms/variantMetadata.d.ts +13 -0
  158. package/dist/image-transforms/variantMetadata.js +164 -0
  159. package/dist/imageSizeOptions.d.ts +8 -8
  160. package/dist/imageSizeOptions.js +0 -2
  161. package/dist/index.d.ts +1 -0
  162. package/dist/oauth/hooks/refresh.js +9 -4
  163. package/dist/oauth/strategy/index.js +34 -14
  164. package/dist/oauth/utilities/createTokenCookie.d.ts +11 -0
  165. package/dist/oauth/utilities/createTokenCookie.js +21 -0
  166. package/dist/oauth/utilities/refreshTokens.d.ts +7 -5
  167. package/dist/oauth/utilities/refreshTokens.js +7 -23
  168. package/dist/plugin/build-config.d.ts +3 -4
  169. package/dist/plugin/build-config.js +39 -18
  170. package/dist/plugin/mcp-oauth.d.ts +18 -7
  171. package/dist/plugin/mcp-oauth.js +123 -10
  172. package/dist/skills/deploy-to-figma/SKILL.md +8 -8
  173. package/dist/skills/deploy-to-figma/references/cli-reference.md +1 -1
  174. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +2 -1
  175. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +2 -1
  176. package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +2 -1
  177. package/dist/storage-content-api/buildMediaResponseHeaders.js +11 -5
  178. package/dist/storage-content-api/isRunningInLambda.d.ts +2 -0
  179. package/dist/storage-content-api/isRunningInLambda.js +3 -0
  180. package/dist/storage-content-api/staticHandler.js +13 -51
  181. package/dist/storage-content-api/streamMediaResponse.d.ts +17 -0
  182. package/dist/storage-content-api/streamMediaResponse.js +96 -0
  183. package/dist/utils/lambda-config.js +1 -1
  184. package/dist/utils/messages.js +8 -0
  185. package/dist/utils/next-image-loader-config.js +43 -6
  186. package/dist/utils/next-image-loader-file.js +8 -0
  187. package/package.json +12 -4
@@ -0,0 +1,13 @@
1
+ const HOP_BY_HOP_HEADERS = new Set([
2
+ 'connection',
3
+ 'keep-alive',
4
+ 'proxy-authenticate',
5
+ 'proxy-authorization',
6
+ 'te',
7
+ 'trailer',
8
+ 'transfer-encoding',
9
+ 'upgrade'
10
+ ]);
11
+ /** Header fields only the platform may change: hop-by-hop, framing and forwarding fields. */ export function isReservedRuleHeader(lowercaseName) {
12
+ return HOP_BY_HOP_HEADERS.has(lowercaseName) || lowercaseName === 'content-length' || lowercaseName === 'host' || lowercaseName === 'forwarded' || lowercaseName === 'x-real-ip' || lowercaseName.startsWith('x-forwarded-') || lowercaseName.startsWith('x-figma-cloud-');
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { ManifestHeaderOp } from '../../types.js';
2
+ interface ValidateHeaderOpArgs {
3
+ op: ManifestHeaderOp;
4
+ pointer: string;
5
+ }
6
+ /**
7
+ * A header rule can't touch Cache-Control (cache policies own it) or platform-reserved fields,
8
+ * and can't append to a field that may appear only once.
9
+ */
10
+ export declare function validateHeaderOp({ op, pointer }: ValidateHeaderOpArgs): import("../types.js").ManifestIssue[];
11
+ export {};
@@ -0,0 +1,38 @@
1
+ import { createIssue } from '../createIssue.js';
2
+ import { SINGLETON_HEADERS } from '../singletonHeaders.js';
3
+ import { ManifestIssueCode } from '../types.js';
4
+ import { validateHeaderName } from '../validateHeaderName.js';
5
+ import { validateHeaderValue } from '../validateHeaderValue.js';
6
+ import { isReservedRuleHeader } from './validateHeaderOp/isReservedRuleHeader.js';
7
+ /**
8
+ * A header rule can't touch Cache-Control (cache policies own it) or platform-reserved fields,
9
+ * and can't append to a field that may appear only once.
10
+ */ export function validateHeaderOp({ op, pointer }) {
11
+ const name = op.name.toLowerCase();
12
+ const namePointer = `${pointer}/name`;
13
+ const reservedMessage = name === 'cache-control' ? 'header rules cannot set Cache-Control; use a cache policy' : isReservedRuleHeader(name) ? `header rules cannot change ${op.name}` : undefined;
14
+ return [
15
+ ...validateHeaderName({
16
+ name: op.name,
17
+ pointer: namePointer
18
+ }),
19
+ ...reservedMessage ? [
20
+ createIssue({
21
+ code: ManifestIssueCode.HEADER_RESERVED,
22
+ message: reservedMessage,
23
+ pointer: namePointer
24
+ })
25
+ ] : [],
26
+ ...op.op === 'append' && SINGLETON_HEADERS.has(name) ? [
27
+ createIssue({
28
+ code: ManifestIssueCode.HTTP_INVALID,
29
+ message: `${op.name} can appear only once; use set`,
30
+ pointer: `${pointer}/op`
31
+ })
32
+ ] : [],
33
+ ...op.op === 'remove' ? [] : validateHeaderValue({
34
+ pointer: `${pointer}/value`,
35
+ value: op.value
36
+ })
37
+ ];
38
+ }
@@ -0,0 +1,3 @@
1
+ import type { DeploymentManifestV2 } from '../types.js';
2
+ /** Every header rule has a valid match and only operations the platform allows. */
3
+ export declare function validateHeaderRules(manifest: DeploymentManifestV2): import("./types.js").ManifestIssue[];
@@ -0,0 +1,17 @@
1
+ import { validateHeaderOp } from './validateHeaderRules/validateHeaderOp.js';
2
+ import { validateMatch } from './validateMatch.js';
3
+ /** Every header rule has a valid match and only operations the platform allows. */ export function validateHeaderRules(manifest) {
4
+ return (manifest.headers ?? []).flatMap((rule, index)=>{
5
+ const pointer = `/headers/${index}`;
6
+ return [
7
+ ...validateMatch({
8
+ match: rule.match,
9
+ pointer: `${pointer}/match`
10
+ }).issues,
11
+ ...rule.ops.flatMap((op, opIndex)=>validateHeaderOp({
12
+ op,
13
+ pointer: `${pointer}/ops/${opIndex}`
14
+ }))
15
+ ];
16
+ });
17
+ }
@@ -0,0 +1,6 @@
1
+ interface ValidateHeaderValueArgs {
2
+ pointer: string;
3
+ value: string;
4
+ }
5
+ export declare function validateHeaderValue({ pointer, value }: ValidateHeaderValueArgs): import("./types.js").ManifestIssue[];
6
+ export {};
@@ -0,0 +1,24 @@
1
+ import { MANIFEST_V2_LIMITS } from '../limits.js';
2
+ import { createIssue } from './createIssue.js';
3
+ import { ManifestIssueCode } from './types.js';
4
+ // Allows horizontal tab; rejects NUL, CR, LF, DEL and other control characters.
5
+ // eslint-disable-next-line no-control-regex
6
+ const HEADER_VALUE_FORBIDDEN = /[\u0000-\u0008\u000A-\u001F\u007F]/;
7
+ export function validateHeaderValue({ pointer, value }) {
8
+ return [
9
+ ...HEADER_VALUE_FORBIDDEN.test(value) ? [
10
+ createIssue({
11
+ code: ManifestIssueCode.SCHEMA_INVALID,
12
+ message: 'header values cannot contain CR, LF, NUL or control characters',
13
+ pointer
14
+ })
15
+ ] : [],
16
+ ...Buffer.byteLength(value) > MANIFEST_V2_LIMITS.maxHeaderValueBytes ? [
17
+ createIssue({
18
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
19
+ message: `header value is longer than ${MANIFEST_V2_LIMITS.maxHeaderValueBytes} bytes`,
20
+ pointer
21
+ })
22
+ ] : []
23
+ ];
24
+ }
@@ -0,0 +1,7 @@
1
+ interface ValidateIdArgs {
2
+ id: string;
3
+ pointer: string;
4
+ }
5
+ /** IDs are 1–128 ASCII letters, digits, `.`, `_` or `-`, starting with a letter or digit. */
6
+ export declare function validateId({ id, pointer }: ValidateIdArgs): import("./types.js").ManifestIssue[];
7
+ export {};
@@ -0,0 +1,12 @@
1
+ import { createIssue } from './createIssue.js';
2
+ import { ManifestIssueCode } from './types.js';
3
+ const ID_PATTERN = /^[A-Z0-9][\w.-]{0,127}$/i;
4
+ /** IDs are 1–128 ASCII letters, digits, `.`, `_` or `-`, starting with a letter or digit. */ export function validateId({ id, pointer }) {
5
+ return ID_PATTERN.test(id) ? [] : [
6
+ createIssue({
7
+ code: ManifestIssueCode.SCHEMA_INVALID,
8
+ message: `invalid ID ${JSON.stringify(id)}`,
9
+ pointer
10
+ })
11
+ ];
12
+ }
@@ -0,0 +1,15 @@
1
+ import type { ManifestMatch } from '../types.js';
2
+ import type { ManifestIssue } from './types.js';
3
+ interface ValidateMatchArgs {
4
+ match: ManifestMatch;
5
+ pointer: string;
6
+ }
7
+ /**
8
+ * Validates a route or header-rule match. Returns its issues and the parameter names its path
9
+ * pattern captures, which redirect locations and rewrite paths may reference.
10
+ */
11
+ export declare function validateMatch({ match, pointer }: ValidateMatchArgs): {
12
+ issues: ManifestIssue[];
13
+ params: string[];
14
+ };
15
+ export {};
@@ -0,0 +1,74 @@
1
+ import { MANIFEST_V2_LIMITS } from '../limits.js';
2
+ import { createIssue } from './createIssue.js';
3
+ import { ManifestIssueCode } from './types.js';
4
+ import { validatePublicPath } from './validatePublicPath.js';
5
+ const PARAM_SEGMENT = /^:([A-Z_]\w*)(\*)?$/i;
6
+ /**
7
+ * Validates a route or header-rule match. Returns its issues and the parameter names its path
8
+ * pattern captures, which redirect locations and rewrite paths may reference.
9
+ */ export function validateMatch({ match, pointer }) {
10
+ const issues = [
11
+ 'has',
12
+ 'missing'
13
+ ].filter((key)=>(match[key]?.length ?? 0) > MANIFEST_V2_LIMITS.maxConditionsPerList).map((key)=>createIssue({
14
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
15
+ message: `at most ${MANIFEST_V2_LIMITS.maxConditionsPerList} conditions are allowed`,
16
+ pointer: `${pointer}/${key}`
17
+ }));
18
+ if (match.methods?.length === 0) {
19
+ issues.push(createIssue({
20
+ code: ManifestIssueCode.SCHEMA_INVALID,
21
+ message: 'methods must not be empty; omit it to match any method',
22
+ pointer: `${pointer}/methods`
23
+ }));
24
+ }
25
+ if (match.path === undefined) {
26
+ return {
27
+ issues,
28
+ params: []
29
+ };
30
+ }
31
+ const pathPointer = `${pointer}/path`;
32
+ const segments = match.path.split('/').slice(1);
33
+ const params = [];
34
+ issues.push(...validatePublicPath({
35
+ pointer: pathPointer,
36
+ publicPath: match.path
37
+ }));
38
+ for (const [index, segment] of segments.entries()){
39
+ if (!segment.startsWith(':')) {
40
+ continue;
41
+ }
42
+ const parsed = PARAM_SEGMENT.exec(segment);
43
+ if (!parsed) {
44
+ issues.push(pathIssue(pathPointer, `invalid path parameter ${segment}`));
45
+ continue;
46
+ }
47
+ const [, name, catchAll] = parsed;
48
+ if (catchAll && index !== segments.length - 1) {
49
+ issues.push(pathIssue(pathPointer, `${segment} must be the last segment`));
50
+ }
51
+ if (params.includes(name)) {
52
+ issues.push(pathIssue(pathPointer, `duplicate path parameter ${name}`));
53
+ }
54
+ params.push(name);
55
+ }
56
+ if (params.length > MANIFEST_V2_LIMITS.maxPathParams) {
57
+ issues.push(createIssue({
58
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
59
+ message: `at most ${MANIFEST_V2_LIMITS.maxPathParams} path parameters are allowed`,
60
+ pointer: pathPointer
61
+ }));
62
+ }
63
+ return {
64
+ issues,
65
+ params
66
+ };
67
+ }
68
+ function pathIssue(pointer, message) {
69
+ return createIssue({
70
+ code: ManifestIssueCode.SCHEMA_INVALID,
71
+ message,
72
+ pointer
73
+ });
74
+ }
@@ -0,0 +1,7 @@
1
+ interface ValidatePublicPathArgs {
2
+ pointer: string;
3
+ publicPath: string;
4
+ }
5
+ /** A public path starts with exactly one `/` and fits the path length limit. */
6
+ export declare function validatePublicPath({ pointer, publicPath }: ValidatePublicPathArgs): import("./types.js").ManifestIssue[];
7
+ export {};
@@ -0,0 +1,21 @@
1
+ import { MANIFEST_V2_LIMITS } from '../limits.js';
2
+ import { createIssue } from './createIssue.js';
3
+ import { ManifestIssueCode } from './types.js';
4
+ /** A public path starts with exactly one `/` and fits the path length limit. */ export function validatePublicPath({ pointer, publicPath }) {
5
+ return [
6
+ ...!publicPath.startsWith('/') || publicPath.startsWith('//') ? [
7
+ createIssue({
8
+ code: ManifestIssueCode.SCHEMA_INVALID,
9
+ message: `path ${JSON.stringify(publicPath)} must start with one "/"`,
10
+ pointer
11
+ })
12
+ ] : [],
13
+ ...publicPath.length > MANIFEST_V2_LIMITS.maxPathLength ? [
14
+ createIssue({
15
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
16
+ message: `path is longer than ${MANIFEST_V2_LIMITS.maxPathLength} characters`,
17
+ pointer
18
+ })
19
+ ] : []
20
+ ];
21
+ }
@@ -0,0 +1,3 @@
1
+ import type { ManifestHeader } from '../../../types.js';
2
+ /** Indexes of singleton fields that already appeared earlier in the list, in one pass. */
3
+ export declare function findRepeatedSingletons(headers: ManifestHeader[]): Set<number>;
@@ -0,0 +1,16 @@
1
+ import { SINGLETON_HEADERS } from '../../singletonHeaders.js';
2
+ /** Indexes of singleton fields that already appeared earlier in the list, in one pass. */ export function findRepeatedSingletons(headers) {
3
+ const seen = new Set();
4
+ const repeated = new Set();
5
+ for (const [index, header] of headers.entries()){
6
+ const name = header.name.toLowerCase();
7
+ if (!SINGLETON_HEADERS.has(name)) {
8
+ continue;
9
+ }
10
+ if (seen.has(name)) {
11
+ repeated.add(index);
12
+ }
13
+ seen.add(name);
14
+ }
15
+ return repeated;
16
+ }
@@ -0,0 +1,11 @@
1
+ import type { ManifestHeader } from '../../types.js';
2
+ interface ValidateHeaderListArgs {
3
+ headers: ManifestHeader[];
4
+ pointer: string;
5
+ }
6
+ /**
7
+ * A response's ordered header list: valid names and values, singleton fields at most once, and
8
+ * the header block within its field-count and byte limits.
9
+ */
10
+ export declare function validateHeaderList({ headers, pointer }: ValidateHeaderListArgs): import("../types.js").ManifestIssue[];
11
+ export {};
@@ -0,0 +1,48 @@
1
+ import { MANIFEST_V2_LIMITS } from '../../limits.js';
2
+ import { createIssue } from '../createIssue.js';
3
+ import { ManifestIssueCode } from '../types.js';
4
+ import { validateHeaderName } from '../validateHeaderName.js';
5
+ import { validateHeaderValue } from '../validateHeaderValue.js';
6
+ import { findRepeatedSingletons } from './validateHeaderList/findRepeatedSingletons.js';
7
+ /**
8
+ * A response's ordered header list: valid names and values, singleton fields at most once, and
9
+ * the header block within its field-count and byte limits.
10
+ */ export function validateHeaderList({ headers, pointer }) {
11
+ const repeatedSingletons = findRepeatedSingletons(headers);
12
+ const fieldIssues = headers.flatMap((header, index)=>[
13
+ ...validateHeaderName({
14
+ name: header.name,
15
+ pointer: `${pointer}/${index}/name`
16
+ }),
17
+ ...validateHeaderValue({
18
+ pointer: `${pointer}/${index}/value`,
19
+ value: header.value
20
+ }),
21
+ ...repeatedSingletons.has(index) ? [
22
+ createIssue({
23
+ code: ManifestIssueCode.HTTP_INVALID,
24
+ message: `${header.name} can appear only once`,
25
+ pointer: `${pointer}/${index}`
26
+ })
27
+ ] : []
28
+ ]);
29
+ // HTTP/1.1 serialization: name + ": " + value + CRLF for each field, then the final CRLF.
30
+ const blockBytes = headers.reduce((total, header)=>total + Buffer.byteLength(header.name) + Buffer.byteLength(header.value) + 4, 2);
31
+ return [
32
+ ...fieldIssues,
33
+ ...headers.length > MANIFEST_V2_LIMITS.maxHeaderBlockFields ? [
34
+ createIssue({
35
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
36
+ message: `at most ${MANIFEST_V2_LIMITS.maxHeaderBlockFields} headers are allowed`,
37
+ pointer
38
+ })
39
+ ] : [],
40
+ ...blockBytes > MANIFEST_V2_LIMITS.maxHeaderBlockBytes ? [
41
+ createIssue({
42
+ code: ManifestIssueCode.LIMIT_EXCEEDED,
43
+ message: `headers are ${blockBytes} bytes; the limit is ${MANIFEST_V2_LIMITS.maxHeaderBlockBytes}`,
44
+ pointer
45
+ })
46
+ ] : []
47
+ ];
48
+ }
@@ -0,0 +1,10 @@
1
+ import type { DeploymentManifestV2, ManifestResponse } from '../../types.js';
2
+ interface ValidateResponseBodyArgs {
3
+ manifest: DeploymentManifestV2;
4
+ pointer: string;
5
+ response: ManifestResponse;
6
+ serverArtifactIds: Set<string>;
7
+ }
8
+ /** A body names a declared artifact that isn't a server ZIP, since server ZIPs are never public. */
9
+ export declare function validateResponseBody({ manifest, pointer, response, serverArtifactIds, }: ValidateResponseBodyArgs): import("../types.js").ManifestIssue[];
10
+ export {};
@@ -0,0 +1,16 @@
1
+ import { createIssue } from '../createIssue.js';
2
+ import { ManifestIssueCode } from '../types.js';
3
+ /** A body names a declared artifact that isn't a server ZIP, since server ZIPs are never public. */ export function validateResponseBody({ manifest, pointer, response, serverArtifactIds }) {
4
+ if (!response.body) {
5
+ return [];
6
+ }
7
+ const { artifact } = response.body;
8
+ const message = !Object.hasOwn(manifest.artifacts, artifact) ? `unknown artifact ${artifact}` : serverArtifactIds.has(artifact) ? 'a server artifact cannot be a public response body' : undefined;
9
+ return message ? [
10
+ createIssue({
11
+ code: ManifestIssueCode.REFERENCE_INVALID,
12
+ message,
13
+ pointer: `${pointer}/body/artifact`
14
+ })
15
+ ] : [];
16
+ }
@@ -0,0 +1,8 @@
1
+ interface ValidateResponseStatusArgs {
2
+ hasBody: boolean;
3
+ pointer: string;
4
+ status: number;
5
+ }
6
+ /** A status is an integer from 200 to 599, and 204, 205 and 304 can't have a body. */
7
+ export declare function validateResponseStatus({ hasBody, pointer, status }: ValidateResponseStatusArgs): import("../types.js").ManifestIssue[];
8
+ export {};
@@ -0,0 +1,25 @@
1
+ import { createIssue } from '../createIssue.js';
2
+ import { ManifestIssueCode } from '../types.js';
3
+ const BODYLESS_STATUSES = new Set([
4
+ 204,
5
+ 205,
6
+ 304
7
+ ]);
8
+ /** A status is an integer from 200 to 599, and 204, 205 and 304 can't have a body. */ export function validateResponseStatus({ hasBody, pointer, status }) {
9
+ return [
10
+ ...!Number.isInteger(status) || status < 200 || status > 599 ? [
11
+ createIssue({
12
+ code: ManifestIssueCode.HTTP_INVALID,
13
+ message: 'status must be an integer from 200 to 599',
14
+ pointer: `${pointer}/metadata/status`
15
+ })
16
+ ] : [],
17
+ ...hasBody && BODYLESS_STATUSES.has(status) ? [
18
+ createIssue({
19
+ code: ManifestIssueCode.HTTP_INVALID,
20
+ message: `status ${status} cannot have a body`,
21
+ pointer: `${pointer}/body`
22
+ })
23
+ ] : []
24
+ ];
25
+ }
@@ -0,0 +1,7 @@
1
+ import type { DeploymentManifestV2 } from '../types.js';
2
+ /**
3
+ * Every response has a valid ID, a body that names a public artifact (never a server ZIP), a
4
+ * status from 200 to 599 that allows its body, valid headers (with Location for redirects) and a
5
+ * valid cache policy.
6
+ */
7
+ export declare function validateResponses(manifest: DeploymentManifestV2): import("./types.js").ManifestIssue[];
@@ -0,0 +1,59 @@
1
+ import { createIssue } from './createIssue.js';
2
+ import { escapePointer } from './escapePointer.js';
3
+ import { ManifestIssueCode } from './types.js';
4
+ import { validateCachePolicy } from './validateCachePolicy.js';
5
+ import { validateId } from './validateId.js';
6
+ import { validateHeaderList } from './validateResponses/validateHeaderList.js';
7
+ import { validateResponseBody } from './validateResponses/validateResponseBody.js';
8
+ import { validateResponseStatus } from './validateResponses/validateResponseStatus.js';
9
+ const REDIRECT_STATUSES = new Set([
10
+ 301,
11
+ 302,
12
+ 303,
13
+ 307,
14
+ 308
15
+ ]);
16
+ /**
17
+ * Every response has a valid ID, a body that names a public artifact (never a server ZIP), a
18
+ * status from 200 to 599 that allows its body, valid headers (with Location for redirects) and a
19
+ * valid cache policy.
20
+ */ export function validateResponses(manifest) {
21
+ const serverArtifactIds = new Set(Object.values(manifest.servers ?? {}).map((server)=>server.artifact));
22
+ return Object.entries(manifest.responses).flatMap(([id, response])=>{
23
+ const pointer = `/responses/${escapePointer(id)}`;
24
+ const status = response.metadata?.status ?? 200;
25
+ const headers = response.metadata?.headers ?? [];
26
+ return [
27
+ ...validateId({
28
+ id,
29
+ pointer
30
+ }),
31
+ ...validateResponseBody({
32
+ manifest,
33
+ pointer,
34
+ response,
35
+ serverArtifactIds
36
+ }),
37
+ ...validateResponseStatus({
38
+ hasBody: response.body !== null,
39
+ pointer,
40
+ status
41
+ }),
42
+ ...validateHeaderList({
43
+ headers,
44
+ pointer: `${pointer}/metadata/headers`
45
+ }),
46
+ ...REDIRECT_STATUSES.has(status) && !headers.some((header)=>header.name.toLowerCase() === 'location') ? [
47
+ createIssue({
48
+ code: ManifestIssueCode.HTTP_INVALID,
49
+ message: `redirect status ${status} needs a Location header`,
50
+ pointer: `${pointer}/metadata/headers`
51
+ })
52
+ ] : [],
53
+ ...response.cache ? validateCachePolicy({
54
+ cache: response.cache,
55
+ pointer: `${pointer}/cache`
56
+ }) : []
57
+ ];
58
+ });
59
+ }
@@ -0,0 +1,10 @@
1
+ interface ValidateCapturesArgs {
2
+ /** Parameter names the route's path pattern captures. */
3
+ params: string[];
4
+ pointer: string;
5
+ /** A redirect location or rewrite path that may reference `:name` or `:name*`. */
6
+ value: string;
7
+ }
8
+ /** Every `:name` a location or rewrite path references must be captured by the route's path. */
9
+ export declare function validateCaptures({ params, pointer, value }: ValidateCapturesArgs): import("../../types.js").ManifestIssue[];
10
+ export {};
@@ -0,0 +1,12 @@
1
+ import { createIssue } from '../../createIssue.js';
2
+ import { ManifestIssueCode } from '../../types.js';
3
+ const CAPTURE_REFERENCE = /:([A-Z_]\w*)\*?/gi;
4
+ /** Every `:name` a location or rewrite path references must be captured by the route's path. */ export function validateCaptures({ params, pointer, value }) {
5
+ return [
6
+ ...value.matchAll(CAPTURE_REFERENCE)
7
+ ].map(([, name])=>name).filter((name)=>!params.includes(name)).map((name)=>createIssue({
8
+ code: ManifestIssueCode.REFERENCE_INVALID,
9
+ message: `:${name} is not captured by the route path`,
10
+ pointer
11
+ }));
12
+ }
@@ -0,0 +1,14 @@
1
+ import type { ManifestRouteAction } from '../../../types.js';
2
+ interface ValidateRedirectActionArgs {
3
+ action: Extract<ManifestRouteAction, {
4
+ type: 'redirect';
5
+ }>;
6
+ params: string[];
7
+ pointer: string;
8
+ }
9
+ /**
10
+ * A redirect uses a redirect status and an origin-relative or fixed-host https:// location with no
11
+ * backslash, and the location is a valid header value.
12
+ */
13
+ export declare function validateRedirectAction({ action, params, pointer }: ValidateRedirectActionArgs): import("../../types.js").ManifestIssue[];
14
+ export {};
@@ -0,0 +1,59 @@
1
+ import { createIssue } from '../../createIssue.js';
2
+ import { ManifestIssueCode } from '../../types.js';
3
+ import { validateHeaderValue } from '../../validateHeaderValue.js';
4
+ import { validateCaptures } from './validateCaptures.js';
5
+ const REDIRECT_STATUSES = new Set([
6
+ 301,
7
+ 302,
8
+ 303,
9
+ 307,
10
+ 308
11
+ ]);
12
+ // Everything up to the first `/`, `?` or `#` after `https://`: the authority, which stays fixed.
13
+ const HTTPS_AUTHORITY = /^https:\/\/[^/?#]*/;
14
+ /**
15
+ * A redirect uses a redirect status and an origin-relative or fixed-host https:// location with no
16
+ * backslash, and the location is a valid header value.
17
+ */ export function validateRedirectAction({ action, params, pointer }) {
18
+ const isOriginRelative = action.location.startsWith('/') && !action.location.startsWith('//');
19
+ // Browsers read `\` as `/` in Location, so `/\host` would act as protocol-relative `//host`.
20
+ const isValidLocation = !action.location.includes('\\') && (isOriginRelative || isFixedHostHttpsUrl(action.location));
21
+ return [
22
+ ...REDIRECT_STATUSES.has(action.status) ? [] : [
23
+ createIssue({
24
+ code: ManifestIssueCode.HTTP_INVALID,
25
+ message: 'redirect status must be 301, 302, 303, 307 or 308',
26
+ pointer: `${pointer}/status`
27
+ })
28
+ ],
29
+ ...isValidLocation ? [] : [
30
+ createIssue({
31
+ code: ManifestIssueCode.HTTP_INVALID,
32
+ message: 'location must be an origin-relative path or an https:// URL with a fixed host',
33
+ pointer: `${pointer}/location`
34
+ })
35
+ ],
36
+ // The location is sent as the Location header value.
37
+ ...validateHeaderValue({
38
+ pointer: `${pointer}/location`,
39
+ value: action.location
40
+ }),
41
+ ...validateCaptures({
42
+ params,
43
+ pointer: `${pointer}/location`,
44
+ // Only the path, query and fragment of an absolute URL can reference captures.
45
+ value: isOriginRelative ? action.location : action.location.replace(HTTPS_AUTHORITY, '')
46
+ })
47
+ ];
48
+ }
49
+ /**
50
+ * An https:// URL that parses, has a host and has no userinfo. The literal lowercase prefix rejects
51
+ * forms the URL parser would repair, such as `https:/host` or `HTTPS:\\host`. A capture in the host
52
+ * (`https://:name.example.com`) doesn't parse, so the authority is constant.
53
+ */ function isFixedHostHttpsUrl(location) {
54
+ if (!location.startsWith('https://') || !URL.canParse(location)) {
55
+ return false;
56
+ }
57
+ const url = new URL(location);
58
+ return url.hostname !== '' && url.username === '' && url.password === '';
59
+ }
@@ -0,0 +1,11 @@
1
+ import type { ManifestRouteAction } from '../../../types.js';
2
+ interface ValidateRewriteActionArgs {
3
+ action: Extract<ManifestRouteAction, {
4
+ type: 'rewrite';
5
+ }>;
6
+ params: string[];
7
+ pointer: string;
8
+ }
9
+ /** A rewrite path starts with one `/` and has no query, fragment or `..` segment. */
10
+ export declare function validateRewriteAction({ action, params, pointer }: ValidateRewriteActionArgs): import("../../types.js").ManifestIssue[];
11
+ export {};
@@ -0,0 +1,20 @@
1
+ import { createIssue } from '../../createIssue.js';
2
+ import { ManifestIssueCode } from '../../types.js';
3
+ import { validateCaptures } from './validateCaptures.js';
4
+ /** A rewrite path starts with one `/` and has no query, fragment or `..` segment. */ export function validateRewriteAction({ action, params, pointer }) {
5
+ const isValidPath = action.path.startsWith('/') && !action.path.startsWith('//') && !/[?#]/.test(action.path) && !action.path.split('/').includes('..');
6
+ return [
7
+ ...isValidPath ? [] : [
8
+ createIssue({
9
+ code: ManifestIssueCode.SCHEMA_INVALID,
10
+ message: 'rewrite path must start with one "/" and have no query, fragment or ".." segment',
11
+ pointer: `${pointer}/path`
12
+ })
13
+ ],
14
+ ...validateCaptures({
15
+ params,
16
+ pointer: `${pointer}/path`,
17
+ value: action.path
18
+ })
19
+ ];
20
+ }
@@ -0,0 +1,11 @@
1
+ import type { DeploymentManifestV2, ManifestRouteAction } from '../../../types.js';
2
+ interface ValidateServerActionArgs {
3
+ action: Extract<ManifestRouteAction, {
4
+ type: 'server';
5
+ }>;
6
+ manifest: DeploymentManifestV2;
7
+ pointer: string;
8
+ }
9
+ /** A server action names a declared server, with a cache policy that isn't immutable. */
10
+ export declare function validateServerAction({ action, manifest, pointer }: ValidateServerActionArgs): import("../../types.js").ManifestIssue[];
11
+ export {};