@conloca/content-api 0.2.3 → 0.2.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 (103) hide show
  1. package/dist/.build-inputs.json +22 -11
  2. package/dist/asset-constraints.d.ts +9 -1
  3. package/dist/asset-constraints.d.ts.map +1 -1
  4. package/dist/asset-constraints.js +10 -2
  5. package/dist/asset-constraints.js.map +1 -1
  6. package/dist/asset-metadata-record.d.ts +18 -0
  7. package/dist/asset-metadata-record.d.ts.map +1 -0
  8. package/dist/asset-metadata-record.js +59 -0
  9. package/dist/asset-metadata-record.js.map +1 -0
  10. package/dist/asset-metadata-store.d.ts.map +1 -1
  11. package/dist/asset-metadata-store.js +7 -26
  12. package/dist/asset-metadata-store.js.map +1 -1
  13. package/dist/asset-naming.d.ts +39 -0
  14. package/dist/asset-naming.d.ts.map +1 -0
  15. package/dist/asset-naming.js +123 -0
  16. package/dist/asset-naming.js.map +1 -0
  17. package/dist/asset-operations.d.ts +3 -5
  18. package/dist/asset-operations.d.ts.map +1 -1
  19. package/dist/asset-operations.js +99 -90
  20. package/dist/asset-operations.js.map +1 -1
  21. package/dist/asset-types.d.ts +2 -0
  22. package/dist/asset-types.d.ts.map +1 -1
  23. package/dist/asset-usage.d.ts +8 -1
  24. package/dist/asset-usage.d.ts.map +1 -1
  25. package/dist/asset-usage.js +4 -1
  26. package/dist/asset-usage.js.map +1 -1
  27. package/dist/draft-media-ref.d.ts +9 -0
  28. package/dist/draft-media-ref.d.ts.map +1 -0
  29. package/dist/draft-media-ref.js +47 -0
  30. package/dist/draft-media-ref.js.map +1 -0
  31. package/dist/editor-host.d.ts +53 -0
  32. package/dist/editor-host.d.ts.map +1 -1
  33. package/dist/editor-host.js +92 -0
  34. package/dist/editor-host.js.map +1 -1
  35. package/dist/git-operations.d.ts +0 -5
  36. package/dist/git-operations.d.ts.map +1 -1
  37. package/dist/git-operations.js +1 -33
  38. package/dist/git-operations.js.map +1 -1
  39. package/dist/image-format.d.ts +9 -0
  40. package/dist/image-format.d.ts.map +1 -0
  41. package/dist/image-format.js +100 -0
  42. package/dist/image-format.js.map +1 -0
  43. package/dist/image-metadata.d.ts +11 -0
  44. package/dist/image-metadata.d.ts.map +1 -0
  45. package/dist/image-metadata.js +283 -0
  46. package/dist/image-metadata.js.map +1 -0
  47. package/dist/image-shrink.d.ts +15 -0
  48. package/dist/image-shrink.d.ts.map +1 -0
  49. package/dist/image-shrink.js +52 -0
  50. package/dist/image-shrink.js.map +1 -0
  51. package/dist/index.d.ts +7 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +14 -3
  54. package/dist/index.js.map +1 -1
  55. package/dist/lfs-attributes.d.ts +26 -0
  56. package/dist/lfs-attributes.d.ts.map +1 -0
  57. package/dist/lfs-attributes.js +285 -0
  58. package/dist/lfs-attributes.js.map +1 -0
  59. package/dist/skill-stamp.d.ts +10 -0
  60. package/dist/skill-stamp.d.ts.map +1 -0
  61. package/dist/skill-stamp.js +42 -0
  62. package/dist/skill-stamp.js.map +1 -0
  63. package/dist/svg-sanitize.d.ts +8 -0
  64. package/dist/svg-sanitize.d.ts.map +1 -0
  65. package/dist/svg-sanitize.js +260 -0
  66. package/dist/svg-sanitize.js.map +1 -0
  67. package/dist/types.d.ts +7 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/upload-bytes.d.ts +17 -0
  70. package/dist/upload-bytes.d.ts.map +1 -0
  71. package/dist/upload-bytes.js +43 -0
  72. package/dist/upload-bytes.js.map +1 -0
  73. package/dist/upload-refusals.d.ts +24 -0
  74. package/dist/upload-refusals.d.ts.map +1 -0
  75. package/dist/upload-refusals.js +49 -0
  76. package/dist/upload-refusals.js.map +1 -0
  77. package/dist/vxjson-serialize.js +2 -2
  78. package/dist/vxjson-serialize.js.map +1 -1
  79. package/dist/vxjson.js +1 -1
  80. package/dist/vxjson.js.map +1 -1
  81. package/package.json +45 -7
  82. package/src/asset-constraints.ts +14 -2
  83. package/src/asset-metadata-record.ts +57 -0
  84. package/src/asset-metadata-store.ts +12 -21
  85. package/src/asset-naming.ts +120 -0
  86. package/src/asset-operations.ts +108 -91
  87. package/src/asset-types.ts +2 -0
  88. package/src/asset-usage.ts +16 -2
  89. package/src/draft-media-ref.ts +46 -0
  90. package/src/editor-host.ts +117 -1
  91. package/src/git-operations.ts +1 -38
  92. package/src/image-format.ts +87 -0
  93. package/src/image-metadata.ts +266 -0
  94. package/src/image-shrink.ts +57 -0
  95. package/src/index.ts +45 -3
  96. package/src/lfs-attributes.ts +291 -0
  97. package/src/skill-stamp.ts +45 -0
  98. package/src/svg-sanitize.ts +260 -0
  99. package/src/types.ts +7 -0
  100. package/src/upload-bytes.ts +46 -0
  101. package/src/upload-refusals.ts +59 -0
  102. package/src/vxjson-serialize.ts +2 -2
  103. package/src/vxjson.ts +1 -1
package/src/types.ts CHANGED
@@ -386,6 +386,13 @@ export interface SitesConfig {
386
386
  };
387
387
  /** Path the site is served under, as Astro's `base`: starts and ends with `/`; default `/`. */
388
388
  base?: string;
389
+ /**
390
+ * Address of a separate preview deployment for this site, per locale, each an `https://` origin. Once a workspace
391
+ * admin confirms it, every preview link of this site opens there.
392
+ */
393
+ previewUrl?: {
394
+ [locale: string]: string;
395
+ };
389
396
  /**
390
397
  * Optional filesystem path for this site's mdx-type pages.
391
398
  * When set, .mdx files under this path are surfaced in the CMS
@@ -0,0 +1,46 @@
1
+ /**
2
+ * What every server does to an upload's bytes before it measures and names them: read the real format, give the file
3
+ * that format's extension, strip photo metadata and sanitise SVG. A subpath export (`@conloca/content-api/upload-bytes`),
4
+ * off the barrel, so svgo stays out of browser bundles.
5
+ */
6
+ import { sniffImageFormat } from './image-format.js';
7
+ import { stripImageMetadata } from './image-metadata.js';
8
+ import { sanitizeSvg } from './svg-sanitize.js';
9
+ import { unreadableImageRefusal } from './upload-refusals.js';
10
+
11
+ export { sniffImageFormat } from './image-format.js';
12
+
13
+ /** The upload ready to measure and name, or the sentence it is refused with. */
14
+ export type ConformedUpload = { ok: true; bytes: Uint8Array; filename: string } | { ok: false; refusal: string };
15
+
16
+ /**
17
+ * `bytes` as they are stored, under `filename` with the extension of the format they actually hold (`.jpg` for
18
+ * JPEG): JPEG, PNG and WebP without metadata, SVG sanitised, GIF, ICO and AVIF unchanged. Bytes that are no stored
19
+ * image format, or that cannot be stripped or sanitised, are refused as unreadable.
20
+ */
21
+ export function conformUploadBytes(bytes: Uint8Array, filename: string): ConformedUpload {
22
+ const format = sniffImageFormat(bytes);
23
+ const unreadable: ConformedUpload = { ok: false, refusal: unreadableImageRefusal(filename) };
24
+ if (format === null) return unreadable;
25
+ const extension = format === 'jpeg' ? 'jpg' : format;
26
+ const dot = filename.lastIndexOf('.');
27
+ const named = dot > 0 ? filename.slice(dot + 1).toLowerCase() : '';
28
+ const sameFormat = named === extension || (format === 'jpeg' && named === 'jpeg');
29
+ const stored = sameFormat ? filename : `${dot > 0 ? filename.slice(0, dot) : filename}.${extension}`;
30
+
31
+ if (format === 'jpeg' || format === 'png' || format === 'webp') {
32
+ const stripped = stripImageMetadata(bytes, format);
33
+ return stripped === null ? unreadable : { ok: true, bytes: stripped, filename: stored };
34
+ }
35
+ if (format === 'svg') {
36
+ let text: string;
37
+ try {
38
+ text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
39
+ } catch {
40
+ return unreadable;
41
+ }
42
+ const sanitized = sanitizeSvg(text);
43
+ return sanitized === null ? unreadable : { ok: true, bytes: new TextEncoder().encode(sanitized), filename: stored };
44
+ }
45
+ return { ok: true, bytes, filename: stored };
46
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Every sentence an upload is refused or warned with, in every editor and on every server. Each names the file and
3
+ * the next step, so no raw server string reaches the person uploading. Pure strings: the browser entry re-exports
4
+ * them.
5
+ */
6
+
7
+ /** Megabytes as people count them, rounded up so a file just over the limit never reads as "25 MB". */
8
+ function megabytes(bytes: number): number {
9
+ return Math.ceil(bytes / 2 ** 20);
10
+ }
11
+
12
+ function overLimit(limit: number): string {
13
+ return `over the ${megabytes(limit)} MB limit for files stored in your site`;
14
+ }
15
+
16
+ /** A file over the size limit. */
17
+ export function tooLargeRefusal(name: string, bytes: number, limit: number): string {
18
+ return `${name} is ${megabytes(bytes)} MB, ${overLimit(limit)}. Save a smaller copy and upload that.`;
19
+ }
20
+
21
+ /** A video: the site's own embed component is where it belongs. */
22
+ export function videoRefusal(name: string): string {
23
+ return `${name} is a video. Videos are not stored with your site’s images: upload it to a video service and add it to the page with your site’s video embed component.`;
24
+ }
25
+
26
+ /** A file whose type the site does not store, with the formats it does. */
27
+ export function unsupportedTypeRefusal(name: string, formats: readonly string[]): string {
28
+ return `${name} is not an image the editor can store. Use one of: ${formats.map((f) => f.toUpperCase()).join(', ')}.`;
29
+ }
30
+
31
+ /** A file named as an image whose bytes are not one. */
32
+ export function unreadableImageRefusal(name: string): string {
33
+ return `${name} could not be read as an image. Export it again from the program that made it and upload the new file.`;
34
+ }
35
+
36
+ /** A URL import that failed; `detail` says why in plain words. */
37
+ export function importRefusal(detail: string): string {
38
+ return `The image at that link could not be downloaded: ${detail}. Check the link, or download the image and upload the file.`;
39
+ }
40
+
41
+ /** A URL import whose body passed the size limit. */
42
+ export function importTooLargeRefusal(limit: number): string {
43
+ return importRefusal(`it is ${overLimit(limit)}`);
44
+ }
45
+
46
+ /** An online editor upload a Git LFS rule in the repository would catch. */
47
+ export function lfsRefusal(name: string, attributesPath: string, pattern: string): string {
48
+ return `${name} would be stored in Git LFS by the rule "${pattern}" in ${attributesPath}, and the online editor cannot store files in Git LFS. Remove that rule from the repository, or add the image with Git on your computer.`;
49
+ }
50
+
51
+ /** An online editor upload checked before the branch's files are in the editor's copy. */
52
+ export function repoNotReadyRefusal(): string {
53
+ return 'The editor is still reading this branch from your repository. Try again in a minute.';
54
+ }
55
+
56
+ /** A large photo stored unshrunk because the optional `sharp` is not installed. */
57
+ export function shrinkUnavailableWarning(name: string): string {
58
+ return `${name} is larger than 2560 pixels and was stored without shrinking, because the image library sharp is not installed. Run "bun add sharp" in the site to shrink future uploads.`;
59
+ }
@@ -61,6 +61,6 @@ export function serializeVxjson(data: VXJSONFile): string {
61
61
  );
62
62
  }
63
63
 
64
- // Build final JSON string efficiently
65
- return `${metadataWithoutClosing}${contentFieldPrefix}${contentJson}\n}`;
64
+ // Build final JSON string efficiently; end with a newline like any text file Git tracks
65
+ return `${metadataWithoutClosing}${contentFieldPrefix}${contentJson}\n}\n`;
66
66
  }
package/src/vxjson.ts CHANGED
@@ -210,7 +210,7 @@ function calculateEtagsFromVXJSONBuffer(
210
210
  const contentView = new JsonWhitespaceSkippingView(contentHasher);
211
211
 
212
212
  contentHasher.update(openBrace); // {
213
- contentView.updateBuffer(buffer, contentStartPos, buffer.length - 1); // content field to end, exclude final }
213
+ contentView.updateBuffer(buffer, contentStartPos, pos); // content field to the root's closing }, excluded with any trailing whitespace
214
214
  contentHasher.update(closeBrace); // }
215
215
 
216
216
  const contentEtag = toUrlSafeBase64(contentHasher.digest() as Uint8Array);