@chesapeake/stack 0.1.4 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to
7
7
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
+ ## [0.1.5] - 2026-08-03
10
+
11
+ ### Added
12
+
13
+ - `lib/githubIssue`: product-neutral GitHub issue URL parsing, PR rejection,
14
+ snapshot normalization, and import keys
15
+
9
16
  ## [0.1.4] - 2026-08-03
10
17
 
11
18
  ### Added
package/index.ts CHANGED
@@ -26,4 +26,5 @@
26
26
  export * from "./components/ui/index.ts";
27
27
  export * from "./components/ux/index.ts";
28
28
  export * from "./lib/utils.ts";
29
+ export * from "./lib/githubIssue.ts";
29
30
  export { default as tailwindPreset } from "./tailwind.preset.ts";
@@ -0,0 +1,186 @@
1
+ // Copyright 2026 Chesapeake Computing
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Product-neutral GitHub issue helpers shared by browser apps (denoise-ui, void-ui).
6
+ * Does not call GitHub or any product API — parse, validate, and normalize only.
7
+ */
8
+
9
+ export interface ParsedGitHubIssueRef {
10
+ owner: string;
11
+ repo: string;
12
+ number: number;
13
+ /** Canonical https://github.com/{owner}/{repo}/issues/{number} URL. */
14
+ url: string;
15
+ }
16
+
17
+ export interface GitHubIssueLabel {
18
+ id?: number;
19
+ name: string;
20
+ color?: string;
21
+ description?: string | null;
22
+ default?: boolean;
23
+ }
24
+
25
+ /** Minimal issue snapshot suitable for local task persistence. */
26
+ export interface GitHubIssueSnapshot {
27
+ number: number;
28
+ title: string;
29
+ body: string | null;
30
+ state: "open" | "closed";
31
+ html_url: string;
32
+ labels: GitHubIssueLabel[];
33
+ created_at: string;
34
+ updated_at: string;
35
+ closed_at: string | null;
36
+ owner: string;
37
+ repo: string;
38
+ repository: string;
39
+ }
40
+
41
+ const ISSUE_PATH =
42
+ /^\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/issues\/([1-9]\d*)\/?$/;
43
+
44
+ const PULL_PATH =
45
+ /^\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/pull\/([1-9]\d*)\/?$/;
46
+
47
+ function isRecord(value: unknown): value is Record<string, unknown> {
48
+ return typeof value === "object" && value !== null && !Array.isArray(value);
49
+ }
50
+
51
+ /**
52
+ * Parse a GitHub issue URL into owner/repo/number.
53
+ * Rejects pull-request URLs (`/pull/N`) and non-github.com hosts.
54
+ */
55
+ export function parseGitHubIssueUrl(
56
+ value: string
57
+ ): ParsedGitHubIssueRef | null {
58
+ const trimmed = value.trim();
59
+ if (trimmed === "") return null;
60
+
61
+ let url: URL;
62
+ try {
63
+ url = new URL(trimmed);
64
+ } catch {
65
+ return null;
66
+ }
67
+
68
+ if (url.protocol !== "https:" || url.hostname !== "github.com") {
69
+ return null;
70
+ }
71
+
72
+ if (PULL_PATH.test(url.pathname)) {
73
+ return null;
74
+ }
75
+
76
+ const match = ISSUE_PATH.exec(url.pathname);
77
+ if (!match) return null;
78
+
79
+ const owner = match[1];
80
+ const repo = match[2];
81
+ const number = Number(match[3]);
82
+ if (!Number.isSafeInteger(number) || number < 1) return null;
83
+
84
+ return {
85
+ owner,
86
+ repo,
87
+ number,
88
+ url: canonicalGitHubIssueUrl(owner, repo, number),
89
+ };
90
+ }
91
+
92
+ export function canonicalGitHubIssueUrl(
93
+ owner: string,
94
+ repo: string,
95
+ number: number
96
+ ): string {
97
+ return `https://github.com/${owner}/${repo}/issues/${String(number)}`;
98
+ }
99
+
100
+ export function githubIssueImportKey(
101
+ owner: string,
102
+ repo: string,
103
+ number: number
104
+ ): string {
105
+ return `${owner}/${repo}#${String(number)}`.toLowerCase();
106
+ }
107
+
108
+ /** True when a GitHub Issues API payload represents a pull request. */
109
+ export function isGitHubPullRequestPayload(value: unknown): boolean {
110
+ if (!isRecord(value)) return false;
111
+ return value.pull_request != null;
112
+ }
113
+
114
+ export function isValidRepoName(value: string): boolean {
115
+ return /^[A-Za-z0-9_.-]+$/.test(value) && value.length > 0 && value.length <= 100;
116
+ }
117
+
118
+ export function isValidIssueNumber(value: unknown): value is number {
119
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
120
+ }
121
+
122
+ function parseLabels(value: unknown): GitHubIssueLabel[] {
123
+ if (!Array.isArray(value)) return [];
124
+ const labels: GitHubIssueLabel[] = [];
125
+ for (const item of value) {
126
+ if (!isRecord(item) || typeof item.name !== "string") continue;
127
+ labels.push({
128
+ ...(typeof item.id === "number" ? { id: item.id } : {}),
129
+ name: item.name,
130
+ ...(typeof item.color === "string" ? { color: item.color } : {}),
131
+ ...(item.description === null || typeof item.description === "string"
132
+ ? { description: item.description }
133
+ : {}),
134
+ ...(typeof item.default === "boolean" ? { default: item.default } : {}),
135
+ });
136
+ }
137
+ return labels;
138
+ }
139
+
140
+ /**
141
+ * Normalize a GitHub Issues API payload (or a Void API response) into a
142
+ * snapshot. Returns null for pull requests or malformed payloads.
143
+ */
144
+ export function normalizeGitHubIssue(
145
+ value: unknown,
146
+ owner: string,
147
+ repo: string
148
+ ): GitHubIssueSnapshot | null {
149
+ if (!isRecord(value)) return null;
150
+ if (isGitHubPullRequestPayload(value)) return null;
151
+
152
+ if (
153
+ typeof value.number !== "number" ||
154
+ !isValidIssueNumber(value.number) ||
155
+ typeof value.title !== "string" ||
156
+ (value.state !== "open" && value.state !== "closed") ||
157
+ typeof value.html_url !== "string" ||
158
+ value.html_url.trim() === "" ||
159
+ typeof value.created_at !== "string" ||
160
+ typeof value.updated_at !== "string"
161
+ ) {
162
+ return null;
163
+ }
164
+
165
+ const body =
166
+ value.body === null || typeof value.body === "string" ? value.body : null;
167
+ const closedAt =
168
+ value.closed_at === null || typeof value.closed_at === "string"
169
+ ? value.closed_at
170
+ : null;
171
+
172
+ return {
173
+ number: value.number,
174
+ title: value.title,
175
+ body,
176
+ state: value.state,
177
+ html_url: value.html_url,
178
+ labels: parseLabels(value.labels),
179
+ created_at: value.created_at,
180
+ updated_at: value.updated_at,
181
+ closed_at: closedAt,
182
+ owner,
183
+ repo,
184
+ repository: `${owner}/${repo}`,
185
+ };
186
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chesapeake/stack",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A simple, reusable React component library and design system built on shadcn/ui with Tailwind CSS",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.2.0",
@@ -123,6 +123,7 @@
123
123
  "./components/ux/auth/github/AuthCallback": "./components/ux/auth/github/AuthCallback.tsx",
124
124
  "./components/ux/auth/github/types": "./components/ux/auth/github/types.ts",
125
125
  "./lib/utils": "./lib/utils.ts",
126
+ "./lib/githubIssue": "./lib/githubIssue.ts",
126
127
  "./types/user": "./types/user.ts",
127
128
  "./styles": "./styles/index.css",
128
129
  "./tailwind.preset": "./tailwind.preset.ts",