canopycms 0.0.50 → 0.0.52

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 (75) hide show
  1. package/dist/api/__test__/mock-client.js +2 -2
  2. package/dist/api/__test__/mock-client.js.map +1 -1
  3. package/dist/api/branch.d.ts +6 -0
  4. package/dist/api/branch.d.ts.map +1 -1
  5. package/dist/api/branch.js +12 -7
  6. package/dist/api/branch.js.map +1 -1
  7. package/dist/api/entries-constants.d.ts +17 -0
  8. package/dist/api/entries-constants.d.ts.map +1 -0
  9. package/dist/api/entries-constants.js +17 -0
  10. package/dist/api/entries-constants.js.map +1 -0
  11. package/dist/api/entries.d.ts +5 -4
  12. package/dist/api/entries.d.ts.map +1 -1
  13. package/dist/api/entries.js +10 -7
  14. package/dist/api/entries.js.map +1 -1
  15. package/dist/api/github-sync.d.ts.map +1 -1
  16. package/dist/api/github-sync.js +2 -1
  17. package/dist/api/github-sync.js.map +1 -1
  18. package/dist/api/schema.d.ts +7 -2
  19. package/dist/api/schema.d.ts.map +1 -1
  20. package/dist/api/schema.js +0 -3
  21. package/dist/api/schema.js.map +1 -1
  22. package/dist/api/validators.d.ts +6 -0
  23. package/dist/api/validators.d.ts.map +1 -1
  24. package/dist/api/validators.js +8 -0
  25. package/dist/api/validators.js.map +1 -1
  26. package/dist/branch-metadata.d.ts.map +1 -1
  27. package/dist/branch-metadata.js +2 -0
  28. package/dist/branch-metadata.js.map +1 -1
  29. package/dist/branch-workspace.d.ts.map +1 -1
  30. package/dist/branch-workspace.js +13 -1
  31. package/dist/branch-workspace.js.map +1 -1
  32. package/dist/cli/generate-ai-content.js +57 -31
  33. package/dist/cli/init.js +3 -0
  34. package/dist/config/schemas/config.d.ts.map +1 -1
  35. package/dist/config/schemas/config.js +3 -0
  36. package/dist/config/schemas/config.js.map +1 -1
  37. package/dist/editor/CanopyEditor.d.ts.map +1 -1
  38. package/dist/editor/CanopyEditor.js +3 -1
  39. package/dist/editor/CanopyEditor.js.map +1 -1
  40. package/dist/editor/CanopyEditorPage.d.ts.map +1 -1
  41. package/dist/editor/CanopyEditorPage.js +4 -1
  42. package/dist/editor/CanopyEditorPage.js.map +1 -1
  43. package/dist/editor/Editor.d.ts.map +1 -1
  44. package/dist/editor/Editor.js +14 -3
  45. package/dist/editor/Editor.js.map +1 -1
  46. package/dist/editor/components/EditorHeader.js +1 -1
  47. package/dist/editor/components/EditorHeader.js.map +1 -1
  48. package/dist/editor/hooks/useBranchManager.d.ts.map +1 -1
  49. package/dist/editor/hooks/useBranchManager.js +25 -4
  50. package/dist/editor/hooks/useBranchManager.js.map +1 -1
  51. package/dist/editor/hooks/useEntryManager.d.ts +15 -0
  52. package/dist/editor/hooks/useEntryManager.d.ts.map +1 -1
  53. package/dist/editor/hooks/useEntryManager.js +55 -8
  54. package/dist/editor/hooks/useEntryManager.js.map +1 -1
  55. package/dist/git-manager.d.ts +6 -2
  56. package/dist/git-manager.d.ts.map +1 -1
  57. package/dist/git-manager.js +45 -40
  58. package/dist/git-manager.js.map +1 -1
  59. package/dist/http/handler.d.ts.map +1 -1
  60. package/dist/http/handler.js +26 -2
  61. package/dist/http/handler.js.map +1 -1
  62. package/dist/services.d.ts.map +1 -1
  63. package/dist/services.js +53 -26
  64. package/dist/services.js.map +1 -1
  65. package/dist/types.d.ts +2 -0
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/utils/error.d.ts +16 -0
  68. package/dist/utils/error.d.ts.map +1 -1
  69. package/dist/utils/error.js +46 -0
  70. package/dist/utils/error.js.map +1 -1
  71. package/dist/utils/git.d.ts +21 -0
  72. package/dist/utils/git.d.ts.map +1 -1
  73. package/dist/utils/git.js +22 -0
  74. package/dist/utils/git.js.map +1 -1
  75. package/package.json +1 -1
@@ -28,6 +28,52 @@ export function getErrorMessage(err) {
28
28
  }
29
29
  return String(err);
30
30
  }
31
+ /**
32
+ * Redact sensitive material from an error message before sending it to API
33
+ * clients. Log the ORIGINAL message server-side; send the sanitized one.
34
+ *
35
+ * Git/filesystem errors are unbounded (stderr varies by git version, locale,
36
+ * and hooks can print anything), so enumerating safe messages is not
37
+ * feasible. Instead, redact the known-sensitive SHAPES that can appear in
38
+ * any of them:
39
+ * - credentials embedded in URLs (`https://x-access-token:tok@github.com/…`)
40
+ * - absolute filesystem paths (workspace roots, EFS mounts, home directories)
41
+ *
42
+ * Paths under the current working directory are shortened to relative form
43
+ * (CMS-internal layout like `.canopy-dev/remote.git` is useful for debugging
44
+ * and not sensitive); absolute paths outside it are replaced with `<path>`.
45
+ */
46
+ export function sanitizeErrorMessage(message) {
47
+ let result = message;
48
+ // Credentials in URLs: scheme://user:token@host or scheme://token@host.
49
+ // Anchored on the literal `://` (leaving the scheme untouched) — a `\w+`
50
+ // scheme prefix would backtrack polynomially on long word-character runs
51
+ // (CodeQL js/polynomial-redos).
52
+ result = result.replace(/(:\/\/)[^/\s@]+@/g, '$1***@');
53
+ // Paths under the project root become relative (split/join avoids regex
54
+ // escaping issues with arbitrary cwd values). The bare-cwd replacement is
55
+ // anchored to a token boundary so sibling directories that merely share
56
+ // the cwd prefix (e.g. `${cwd}-other/…`) stay absolute and get fully
57
+ // redacted below instead of leaking a mangled remainder.
58
+ const cwd = process.cwd();
59
+ if (cwd !== '/') {
60
+ result = result.split(`${cwd}/`).join('');
61
+ const cwdPattern = cwd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
+ result = result.replace(new RegExp(`${cwdPattern}(?=[\\s'"),:;]|$)`, 'g'), '.');
63
+ }
64
+ // Quoted absolute paths (git quotes most paths in its messages): redact
65
+ // the whole quoted span, spaces included.
66
+ result = result.replace(/'\/[^']*'/g, "'<path>'").replace(/"\/[^"]*"/g, '"<path>"');
67
+ // Remaining absolute POSIX paths (outside cwd, e.g. /mnt/efs/…). The
68
+ // leading boundary keeps URL slashes (`https://host/…`) untouched. Known
69
+ // limitation: an UNQUOTED path containing spaces is only redacted up to
70
+ // the first space — spaces are legal both inside paths and as message
71
+ // separators, so this is not generally solvable here.
72
+ result = result.replace(/(^|[\s'"(=])\/(?:[^/\s'")]+\/)+[^/\s'")]*/g, '$1<path>');
73
+ // Windows drive paths
74
+ result = result.replace(/[A-Za-z]:\\[^\s'")]+/g, '<path>');
75
+ return result;
76
+ }
31
77
  /**
32
78
  * Type guard to check if an error is a Node.js system error with a code property.
33
79
  *
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC,OAAO,CAAA;IACpB,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,CAAA;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.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E;IACxE,sEAAsE;IACtE,sDAAsD;IACtD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,4CAA4C,EAAE,UAAU,CAAC,CAAA;IACjF,sBAAsB;IACtB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAA;IAC1D,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,CAAA;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAClD,CAAC"}
@@ -1,7 +1,28 @@
1
+ import type { OperatingMode } from '../operating-mode';
1
2
  /**
2
3
  * Detect the current HEAD branch name for a given repository root.
3
4
  * Returns the branch name, or the provided fallback (default 'main')
4
5
  * if detection fails or HEAD is detached.
5
6
  */
6
7
  export declare function detectHeadBranch(repoRoot: string, fallback?: string): Promise<string>;
8
+ /**
9
+ * Resolve the base branch — the fork point for CMS editing branches and the
10
+ * branch used to seed workspace clones.
11
+ *
12
+ * This is the single definition of base-branch behavior (see ARCHITECTURE.md
13
+ * "Branch Identity"):
14
+ * - An explicitly configured `defaultBaseBranch` always wins, in both modes.
15
+ * - In dev mode it is detected from the current git HEAD, so workspaces fork
16
+ * from the branch the developer has checked out.
17
+ * - Otherwise it is 'main'.
18
+ *
19
+ * Static deployments never reach git operations, so callers in static paths
20
+ * must short-circuit before calling this (see createCanopyServices).
21
+ */
22
+ export declare function resolveBaseBranch(options: {
23
+ defaultBaseBranch?: string;
24
+ mode: OperatingMode;
25
+ /** Repo root used for dev-mode HEAD detection. Defaults to process.cwd(). */
26
+ detectFrom?: string;
27
+ }): Promise<string>;
7
28
  //# sourceMappingURL=git.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAe,GACxB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAe,GACxB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,IAAI,EAAE,aAAa,CAAA;IACnB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAMlB"}
package/dist/utils/git.js CHANGED
@@ -14,4 +14,26 @@ export async function detectHeadBranch(repoRoot, fallback = 'main') {
14
14
  return fallback;
15
15
  }
16
16
  }
17
+ /**
18
+ * Resolve the base branch — the fork point for CMS editing branches and the
19
+ * branch used to seed workspace clones.
20
+ *
21
+ * This is the single definition of base-branch behavior (see ARCHITECTURE.md
22
+ * "Branch Identity"):
23
+ * - An explicitly configured `defaultBaseBranch` always wins, in both modes.
24
+ * - In dev mode it is detected from the current git HEAD, so workspaces fork
25
+ * from the branch the developer has checked out.
26
+ * - Otherwise it is 'main'.
27
+ *
28
+ * Static deployments never reach git operations, so callers in static paths
29
+ * must short-circuit before calling this (see createCanopyServices).
30
+ */
31
+ export async function resolveBaseBranch(options) {
32
+ if (options.defaultBaseBranch)
33
+ return options.defaultBaseBranch;
34
+ if (options.mode === 'dev') {
35
+ return detectHeadBranch(options.detectFrom ?? process.cwd());
36
+ }
37
+ return 'main';
38
+ }
17
39
  //# sourceMappingURL=git.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,WAAmB,MAAM;IAEzB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAClE,OAAO,IAAI,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAA;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAA;IACjB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAItC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,WAAmB,MAAM;IAEzB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAClE,OAAO,IAAI,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAA;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAA;IACjB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAKvC;IACC,IAAI,OAAO,CAAC,iBAAiB;QAAE,OAAO,OAAO,CAAC,iBAAiB,CAAA;IAC/D,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAO,gBAAgB,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "@codemirror/language, @lezer/highlight: workaround — @mdxeditor/editor uses cm6-theme-basic-light which peer-requires these but mdxeditor doesn't declare them as dependencies",
3
3
  "name": "canopycms",
4
- "version": "0.0.50",
4
+ "version": "0.0.52",
5
5
  "description": "CanopyCMS core package: schema-driven content, branch-aware editing, and editor UI for Next.js.",
6
6
  "license": "MIT",
7
7
  "repository": {