poe-code 3.0.306 → 3.0.307

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.306",
3
+ "version": "3.0.307",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -3,10 +3,108 @@ import { highlight } from "./highlight.js";
3
3
  import { SCRIPT } from "./script.js";
4
4
  import { CSS } from "./styles.js";
5
5
  import { TEMPLATE } from "./template.js";
6
+ const DEFAULT_ACCENT = "#2563eb";
7
+ function isAsciiHexDigit(value) {
8
+ const code = value.charCodeAt(0);
9
+ return ((code >= 48 && code <= 57) ||
10
+ (code >= 65 && code <= 70) ||
11
+ (code >= 97 && code <= 102));
12
+ }
13
+ function isHexColor(value) {
14
+ if (!value.startsWith("#")) {
15
+ return false;
16
+ }
17
+ if (![4, 5, 7, 9].includes(value.length)) {
18
+ return false;
19
+ }
20
+ for (const char of value.slice(1)) {
21
+ if (!isAsciiHexDigit(char)) {
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }
27
+ function isNamedColor(value) {
28
+ if (value.length === 0) {
29
+ return false;
30
+ }
31
+ for (const char of value) {
32
+ const code = char.charCodeAt(0);
33
+ if (!((code >= 65 && code <= 90) || (code >= 97 && code <= 122))) {
34
+ return false;
35
+ }
36
+ }
37
+ return true;
38
+ }
39
+ function sanitizeAccent(value) {
40
+ const trimmed = value.trim();
41
+ if (isHexColor(trimmed) || isNamedColor(trimmed)) {
42
+ return trimmed;
43
+ }
44
+ return DEFAULT_ACCENT;
45
+ }
46
+ function hasUnsafeHrefCharacter(value) {
47
+ for (const char of value) {
48
+ const code = char.charCodeAt(0);
49
+ if (code <= 32 || code === 127) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ function schemeDelimiterIndex(value) {
56
+ const colon = value.indexOf(":");
57
+ if (colon === -1) {
58
+ return -1;
59
+ }
60
+ const slash = value.indexOf("/");
61
+ const question = value.indexOf("?");
62
+ const hash = value.indexOf("#");
63
+ const precedingDelimiters = [slash, question, hash].filter((index) => index !== -1);
64
+ if (precedingDelimiters.some((index) => index < colon)) {
65
+ return -1;
66
+ }
67
+ return colon;
68
+ }
69
+ function safeHref(value) {
70
+ if (value === undefined) {
71
+ return undefined;
72
+ }
73
+ const trimmed = value.trim();
74
+ if (trimmed.length === 0 || hasUnsafeHrefCharacter(trimmed)) {
75
+ return undefined;
76
+ }
77
+ const delimiter = schemeDelimiterIndex(trimmed);
78
+ if (delimiter === -1) {
79
+ return trimmed;
80
+ }
81
+ const scheme = trimmed.slice(0, delimiter).toLowerCase();
82
+ return scheme === "http" || scheme === "https" ? trimmed : undefined;
83
+ }
84
+ function stripFragment(value) {
85
+ const hash = value.indexOf("#");
86
+ return hash === -1 ? value : value.slice(0, hash);
87
+ }
88
+ function docsHref(value) {
89
+ return stripFragment(safeHref(value) ?? "#docs");
90
+ }
91
+ function docsAnchorHref(baseHref, anchor) {
92
+ return baseHref === "#docs" ? baseHref : `${baseHref}#${anchor}`;
93
+ }
6
94
  export function renderLandingPage(page) {
7
- const styles = renderTemplate(CSS, { accent: page.accent });
95
+ const accent = sanitizeAccent(page.accent);
96
+ const docsUrl = docsHref(page.docsUrl);
97
+ const styles = renderTemplate(CSS, { accent });
8
98
  const view = {
9
99
  ...page,
100
+ accent,
101
+ repoUrl: safeHref(page.repoUrl),
102
+ docsUrl,
103
+ docsHelloWorldUrl: docsAnchorHref(docsUrl, "hello-world"),
104
+ docsRuntimeUrl: docsAnchorHref(docsUrl, "one-binary-three-runtimes"),
105
+ docsSecretsUrl: docsAnchorHref(docsUrl, "secrets"),
106
+ docsMigrationUrl: docsAnchorHref(docsUrl, "migrating-from-a-folder-of-scripts"),
107
+ copyInstall: page.includeJs && page.install !== undefined,
10
108
  installHtml: page.install === undefined ? undefined : highlight(page.install),
11
109
  useCases: page.useCases.map((useCase) => ({
12
110
  ...useCase,
@@ -33,7 +33,9 @@ export const TEMPLATE = String.raw `<!doctype html>
33
33
  {{#install}}
34
34
  <div class="install">
35
35
  <code><span aria-hidden="true">$ </span>{{{installHtml}}}</code>
36
+ {{#copyInstall}}
36
37
  <button class="copy" type="button" data-copy="{{install}}" aria-label="Copy {{install}}">Copy</button>
38
+ {{/copyInstall}}
37
39
  </div>
38
40
  {{/install}}
39
41
  </div>
@@ -112,10 +114,10 @@ export const TEMPLATE = String.raw `<!doctype html>
112
114
  <a class="text-link" href="{{docsUrl}}">Read the Toolcraft README <span aria-hidden="true">→</span></a>
113
115
  </div>
114
116
  <div class="docs-grid">
115
- <a class="doc-card" href="{{docsUrl}}#hello-world"><span>01</span><strong>Start with one command</strong><small>Install, define, and run a typed CLI in five minutes.</small></a>
116
- <a class="doc-card" href="{{docsUrl}}#one-binary-three-runtimes"><span>02</span><strong>Choose a runtime</strong><small>CLI, MCP, and SDK from the same command tree.</small></a>
117
- <a class="doc-card" href="{{docsUrl}}#secrets"><span>03</span><strong>Add safety controls</strong><small>Secrets, preconditions, services, and human approval.</small></a>
118
- <a class="doc-card" href="{{docsUrl}}#migrating-from-a-folder-of-scripts"><span>04</span><strong>Migrate existing scripts</strong><small>Adopt Toolcraft incrementally without rewriting useful logic.</small></a>
117
+ <a class="doc-card" href="{{docsHelloWorldUrl}}"><span>01</span><strong>Start with one command</strong><small>Install, define, and run a typed CLI in five minutes.</small></a>
118
+ <a class="doc-card" href="{{docsRuntimeUrl}}"><span>02</span><strong>Choose a runtime</strong><small>CLI, MCP, and SDK from the same command tree.</small></a>
119
+ <a class="doc-card" href="{{docsSecretsUrl}}"><span>03</span><strong>Add safety controls</strong><small>Secrets, preconditions, services, and human approval.</small></a>
120
+ <a class="doc-card" href="{{docsMigrationUrl}}"><span>04</span><strong>Migrate existing scripts</strong><small>Adopt Toolcraft incrementally without rewriting useful logic.</small></a>
119
121
  </div>
120
122
  </div>
121
123
  </section>