canopycms 0.0.68-int.101 → 0.0.68-int.103

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 (65) hide show
  1. package/README.md +3 -1
  2. package/dist/api/client.d.ts +2 -1
  3. package/dist/api/client.js +2 -1
  4. package/dist/assets/asset-url.d.ts +6 -0
  5. package/dist/assets/asset-url.js +9 -0
  6. package/dist/auth/plugin.d.ts +1 -1
  7. package/dist/cli/cli.js +692 -652
  8. package/dist/cli/generate-ai-content.js +406 -96
  9. package/dist/cli/init.js +1 -80
  10. package/dist/config/schemas/config.d.ts +3 -0
  11. package/dist/config/schemas/config.js +1 -0
  12. package/dist/config/types.d.ts +15 -0
  13. package/dist/content-reader.d.ts +9 -0
  14. package/dist/content-reader.js +8 -4
  15. package/dist/content-store.d.ts +4 -0
  16. package/dist/content-store.js +3 -1
  17. package/dist/editor/Editor.js +3 -1
  18. package/dist/editor/FormRenderer.js +78 -9
  19. package/dist/editor/components/EditorCrashScreen.d.ts +17 -0
  20. package/dist/editor/components/EditorCrashScreen.js +22 -0
  21. package/dist/editor/components/EditorErrorBoundary.d.ts +38 -0
  22. package/dist/editor/components/EditorErrorBoundary.js +40 -0
  23. package/dist/editor/context/ApiClientContext.d.ts +2 -1
  24. package/dist/editor/context/ApiClientContext.js +2 -1
  25. package/dist/editor/context/AssetContext.d.ts +2 -7
  26. package/dist/editor/context/AssetContext.js +2 -12
  27. package/dist/editor/fields/FieldCrashFallback.d.ts +17 -0
  28. package/dist/editor/fields/FieldCrashFallback.js +30 -0
  29. package/dist/editor/fields/ImageField.js +8 -5
  30. package/dist/editor/fields/MarkdownField.d.ts +21 -0
  31. package/dist/editor/fields/MarkdownField.js +51 -19
  32. package/dist/editor/fields/markdown-export-options.d.ts +2 -0
  33. package/dist/editor/fields/markdown-export-options.js +8 -0
  34. package/dist/editor/fields/mdx-jsx-support.d.ts +5 -1
  35. package/dist/editor/fields/mdx-jsx-support.js +74 -70
  36. package/dist/editor/fields/rich-text-failures.d.ts +5 -0
  37. package/dist/editor/fields/rich-text-failures.js +26 -0
  38. package/dist/editor/hooks/useEntryManager.js +19 -5
  39. package/dist/editor/media/AssetCard.d.ts +2 -5
  40. package/dist/editor/media/AssetCard.js +4 -7
  41. package/dist/editor/media/editor-image-src.d.ts +6 -5
  42. package/dist/editor/media/editor-image-src.js +7 -9
  43. package/dist/editor/preview-asset-base.d.ts +5 -4
  44. package/dist/editor/preview-asset-base.js +9 -5
  45. package/dist/editor/preview-bridge.d.ts +8 -0
  46. package/dist/editor/preview-bridge.js +22 -6
  47. package/dist/editor/raw-asset-base.d.ts +5 -0
  48. package/dist/editor/raw-asset-base.js +14 -0
  49. package/dist/editor/utils/editor-errors.d.ts +19 -0
  50. package/dist/editor/utils/editor-errors.js +32 -0
  51. package/dist/http/handler.js +7 -2
  52. package/dist/preview.d.ts +1 -1
  53. package/dist/preview.js +1 -1
  54. package/dist/server.d.ts +9 -0
  55. package/dist/server.js +9 -0
  56. package/dist/url-exclusivity-fixtures.d.ts +7 -0
  57. package/dist/url-exclusivity-fixtures.js +10 -0
  58. package/dist/utils/content-serialize.d.ts +7 -5
  59. package/dist/utils/content-serialize.js +58 -9
  60. package/dist/utils/error.js +6 -2
  61. package/dist/utils/markdown-body-splice.d.ts +39 -0
  62. package/dist/utils/markdown-body-splice.js +421 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +15 -1
package/README.md CHANGED
@@ -637,7 +637,9 @@ media: { adapter: 's3', bucket: 'my-site-assets', region: 'us-east-1' }
637
637
 
638
638
  Passing an `image` field value applies its stored crop (`opts.crop` overrides it). Its `width`
639
639
  and `height` are the uncropped original's, so scale them by `crop.w` and `crop.h` for a cropped
640
- value. SVGs and PDFs are served statically, with no transform.
640
+ value. SVGs and PDFs are served statically, with no transform. The package declares
641
+ `sideEffects`, so this import adds under 7 KB minified to a client bundle and none of the
642
+ config schemas.
641
643
 
642
644
  - **Where `/assets` is mounted** — the URLs above are root-relative, because that is what gets
643
645
  stored in content and content moves between branches and environments. If your renderer sees
@@ -32,7 +32,8 @@ export interface ApiClientOptions {
32
32
  */
33
33
  trailingSlash?: boolean;
34
34
  /**
35
- * Called whenever a response comes back 401: the credential is no longer accepted. A
35
+ * Called whenever a response says the credential is no longer accepted: HTTP 401, or a
36
+ * handler's body with `status: 401` under the HTTP status `unauthenticatedStatus` chose. A
36
37
  * notification, not a retry; the editor's auth gate uses it to show sign-in.
37
38
  */
38
39
  onUnauthorized?: () => void;
@@ -341,7 +341,8 @@ export class CanopyApiClient {
341
341
  response = await this.fetchFn(url, init);
342
342
  parsed = await response.json().catch(() => undefined);
343
343
  }
344
- if (response.status === 401) {
344
+ // The body's status is the signal: `unauthenticatedStatus` may send it under HTTP 419.
345
+ if (response.status === 401 || (isApiResponseBody(parsed) && parsed.status === 401)) {
345
346
  this.onUnauthorized?.();
346
347
  return { ok: false, status: 401, error: errorFromBody(parsed) ?? 'Unauthorized' };
347
348
  }
@@ -41,6 +41,12 @@ export interface AssetUrlOptions {
41
41
  */
42
42
  baseUrl?: string;
43
43
  }
44
+ /**
45
+ * Whether `src` is in canopycms's own `/assets` URL space - a transform or static asset src the
46
+ * asset store serves. Every other src (a site's own static file, an off-site URL, a `data:` URI)
47
+ * is the host's, and the asset store never serves it.
48
+ */
49
+ export declare function isAssetStoreSrc(src: string): boolean;
44
50
  /**
45
51
  * Build a transform URL, merging `opts` and `ref.crop` over the directives already present
46
52
  * in `ref.src` (see `mergeDirectives` for precedence). For static srcs (svg/pdf under
@@ -9,6 +9,15 @@ import { getPreviewAssetBase } from '../editor/preview-asset-base.js';
9
9
  import { ASSET_PREFIXES } from './asset-prefixes.js';
10
10
  import { formatDirectives, isAllowedTransformWidth, parseTransformPath, } from './transform-directives.js';
11
11
  const TRANSFORM_URL_PREFIX = `/${ASSET_PREFIXES.transform}/`;
12
+ const ASSET_SPACE_PREFIX = `/${ASSET_PREFIXES.public}/`;
13
+ /**
14
+ * Whether `src` is in canopycms's own `/assets` URL space - a transform or static asset src the
15
+ * asset store serves. Every other src (a site's own static file, an off-site URL, a `data:` URI)
16
+ * is the host's, and the asset store never serves it.
17
+ */
18
+ export function isAssetStoreSrc(src) {
19
+ return src.startsWith(ASSET_SPACE_PREFIX);
20
+ }
12
21
  /**
13
22
  * Test-only. A function stored on `globalThis` under this symbol is called with every URL
14
23
  * `assetUrl` returns; the dual-build fixture installs one during a static export to prove
@@ -14,7 +14,7 @@ export interface AuthPlugin {
14
14
  * groups; core applies bootstrap admins.
15
15
  *
16
16
  * CREDENTIAL failures (missing, invalid or expired token) RESOLVE to
17
- * `{ success: false }` and map to a 401. CONFIGURATION errors (an absent
17
+ * `{ success: false }` and map to `unauthenticatedStatus` (default 401). CONFIGURATION errors (an absent
18
18
  * CLERK_SECRET_KEY, say) may THROW instead: they are operator mistakes, and
19
19
  * belong in a loud 500 rather than a quiet auth denial. A custom adapter
20
20
  * calling this directly must be ready for that rejection.