@innovatorved/code-lab 0.1.7 → 0.1.8

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/dist/csp.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @innovatorved/code-lab — Web Preview Content-Security-Policy builder
3
+ * ============================================================================
4
+ * One place that knows how a preview policy is assembled. Before this module
5
+ * existed the policy was copy-pasted into `preview-sw.js` and `workbench.ts`
6
+ * under a "keep both copies in sync" comment — the classic drift bug.
7
+ *
8
+ * Why the host origin appears literally instead of `'self'`:
9
+ * previews are served in a sandboxed iframe (`allow-scripts`, deliberately
10
+ * *without* `allow-same-origin`). A sandboxed document has an opaque origin, so
11
+ * `'self'` matches no URL at all and the app's own `/__preview/<port>/app.js`
12
+ * would be blocked. Naming the host origin keeps the app's assets loadable
13
+ * while the sandbox keeps it away from host DOM and storage.
14
+ *
15
+ * Bundled as a classic script (`globalName: CodeLabCsp`) so the Service Worker
16
+ * and the workbench can both consume it without a module loader.
17
+ */
18
+ export type PreviewCspMode = 'strict' | 'balanced' | 'custom';
19
+ /** Per-directive network allowlist. Values are origins or CSP source keywords. */
20
+ export interface PreviewCspSources {
21
+ scriptSrc?: string[];
22
+ styleSrc?: string[];
23
+ imgSrc?: string[];
24
+ fontSrc?: string[];
25
+ connectSrc?: string[];
26
+ mediaSrc?: string[];
27
+ workerSrc?: string[];
28
+ frameSrc?: string[];
29
+ }
30
+ export interface PreviewCspConfig extends PreviewCspSources {
31
+ mode?: PreviewCspMode | string;
32
+ }
33
+ export interface PreviewCspOptions extends PreviewCspConfig {
34
+ /** Origin that serves `/__preview/*` (the host page). Falls back to `'self'`. */
35
+ hostOrigin?: string;
36
+ /** Value for `frame-ancestors`; defaults to `'self'`. */
37
+ frameAncestors?: string;
38
+ }
39
+ export interface NormalizedPreviewCsp {
40
+ mode: PreviewCspMode;
41
+ allow: PreviewCspSources;
42
+ }
43
+ /** HTML marker so the shim block is injected exactly once. */
44
+ export declare const PREVIEW_SHIM_MARKER = "data-codelab-preview-shims";
45
+ /** Accepts `"https://a.example"` and returns its origin; `null` otherwise. */
46
+ export declare function normalizeOrigin(raw: unknown): string | null;
47
+ /**
48
+ * Validate an author-supplied `previewCsp` option. Unknown modes fall back to
49
+ * `balanced`; invalid source entries are dropped rather than shipped.
50
+ */
51
+ export declare function normalizePreviewCspConfig(raw: unknown): NormalizedPreviewCsp;
52
+ /**
53
+ * Build the policy string for one preview document.
54
+ *
55
+ * `unsafe-inline`/`unsafe-eval` stay enabled on purpose: previews are arbitrary
56
+ * user code and inline import maps are part of how they run. Isolation comes
57
+ * from the iframe sandbox (opaque origin), not from the CSP.
58
+ */
59
+ export declare function buildPreviewPolicy(options?: PreviewCspOptions): string;
60
+ /**
61
+ * Network hosts a preview may reach, for display in the Web Preview toolbar.
62
+ * Returns remote origins only — the host origin and CSP keywords are omitted.
63
+ */
64
+ export declare function describePreviewNetwork(config: unknown): string[];
65
+ /**
66
+ * Scripts injected into every preview document:
67
+ *
68
+ * 1. In-memory `localStorage`/`sessionStorage` — a sandboxed (opaque origin)
69
+ * document throws `SecurityError` on access, which breaks any preview that
70
+ * touches storage at module top level. In-memory equivalents keep the app
71
+ * running; sub-resource loading is unaffected.
72
+ * 2. A `securitypolicyviolation` reporter that forwards to the host via
73
+ * `postMessage`. The host validates `event.source` (the document origin is
74
+ * opaque, so `event.origin` is the string `"null"` and is not usable).
75
+ */
76
+ export declare function buildPreviewShims(): string;
77
+ /** Default export keeps the IIFE global (`CodeLabCsp`) shaped like the sources. */
78
+ declare const _default: {
79
+ buildPreviewPolicy: typeof buildPreviewPolicy;
80
+ buildPreviewShims: typeof buildPreviewShims;
81
+ describePreviewNetwork: typeof describePreviewNetwork;
82
+ normalizePreviewCspConfig: typeof normalizePreviewCspConfig;
83
+ normalizeOrigin: typeof normalizeOrigin;
84
+ PREVIEW_SHIM_MARKER: string;
85
+ };
86
+ export default _default;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @innovatorved/code-lab — Unified Diagnostics & Problems Aggregator Store
3
+ * ============================================================================
4
+ * Aggregates diagnostics from Monaco TypeScript/JavaScript workers, runtime
5
+ * execution exceptions, preview errors, and linters into a reactive store
6
+ * driving editor markers and the bottom drawer Problems panel.
7
+ *
8
+ * Strict leaf module: fully typed, zero explicit any, zero empty catches.
9
+ */
10
+ export type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
11
+ export interface DiagnosticItem {
12
+ id: string;
13
+ file: string;
14
+ line: number;
15
+ col?: number;
16
+ column?: number;
17
+ endLine?: number;
18
+ endCol?: number;
19
+ endColumn?: number;
20
+ message: string;
21
+ severity: DiagnosticSeverity;
22
+ source?: string;
23
+ code?: string | number;
24
+ tags?: string[];
25
+ }
26
+ export type DiagnosticListener = (items: DiagnosticItem[]) => void;
27
+ export declare class DiagnosticsStore {
28
+ private readonly items;
29
+ private readonly listeners;
30
+ add(item: DiagnosticItem): void;
31
+ remove(id: string): void;
32
+ clear(source?: string): void;
33
+ getAll(): DiagnosticItem[];
34
+ getByFile(file: string): DiagnosticItem[];
35
+ subscribe(listener: DiagnosticListener): () => void;
36
+ private notify;
37
+ }
38
+ export declare function createDiagnosticsStore(): DiagnosticsStore;
39
+ declare const _default: {
40
+ DiagnosticsStore: typeof DiagnosticsStore;
41
+ createDiagnosticsStore: typeof createDiagnosticsStore;
42
+ };
43
+ export default _default;
@@ -4181,6 +4181,69 @@ var WorkbenchOptionsSchema = external_exports.object({
4181
4181
  onStepComplete: external_exports.function().args(external_exports.any(), external_exports.number()).returns(external_exports.void()).optional(),
4182
4182
  onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
4183
4183
  });
4184
+ var SearchOptionsSchema = external_exports.object({
4185
+ query: external_exports.string().default(""),
4186
+ caseSensitive: external_exports.boolean().optional().default(false),
4187
+ wholeWord: external_exports.boolean().optional().default(false),
4188
+ regex: external_exports.boolean().optional().default(false),
4189
+ isRegex: external_exports.boolean().optional().default(false),
4190
+ include: external_exports.string().optional(),
4191
+ includeGlob: external_exports.string().optional(),
4192
+ includePattern: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
4193
+ exclude: external_exports.string().optional(),
4194
+ excludeGlob: external_exports.string().optional(),
4195
+ excludePattern: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
4196
+ maxMatches: external_exports.number().int().positive().optional(),
4197
+ maxMatchesPerFile: external_exports.number().int().positive().optional()
4198
+ });
4199
+ var DiagnosticSeveritySchema = external_exports.enum(["error", "warning", "info", "hint"]);
4200
+ var DiagnosticItemSchema = external_exports.object({
4201
+ id: external_exports.string(),
4202
+ file: external_exports.string(),
4203
+ line: external_exports.number().int(),
4204
+ col: external_exports.number().int().optional(),
4205
+ column: external_exports.number().int().optional(),
4206
+ endLine: external_exports.number().int().optional(),
4207
+ endCol: external_exports.number().int().optional(),
4208
+ endColumn: external_exports.number().int().optional(),
4209
+ message: external_exports.string(),
4210
+ severity: DiagnosticSeveritySchema,
4211
+ source: external_exports.string().optional(),
4212
+ code: external_exports.union([external_exports.string(), external_exports.number()]).optional(),
4213
+ tags: external_exports.array(external_exports.string()).optional()
4214
+ });
4215
+ var StoredProjectSchema = external_exports.object({
4216
+ id: external_exports.string(),
4217
+ name: external_exports.string(),
4218
+ files: external_exports.record(external_exports.string()),
4219
+ updatedAt: external_exports.number(),
4220
+ createdAt: external_exports.number().optional(),
4221
+ entry: external_exports.string().optional(),
4222
+ testEntry: external_exports.string().optional(),
4223
+ version: external_exports.number().optional()
4224
+ });
4225
+ var GitFileChangeTypeSchema = external_exports.enum(["modified", "added", "deleted", "untracked"]);
4226
+ var GitFileStatusSchema = external_exports.object({
4227
+ path: external_exports.string(),
4228
+ status: GitFileChangeTypeSchema,
4229
+ staged: external_exports.boolean(),
4230
+ oldContent: external_exports.string().optional(),
4231
+ newContent: external_exports.string().optional()
4232
+ });
4233
+ var GitStateSummarySchema = external_exports.object({
4234
+ branch: external_exports.string().default("main"),
4235
+ headCommit: external_exports.string().optional(),
4236
+ branches: external_exports.array(external_exports.string()).default(["main"]),
4237
+ staged: external_exports.array(GitFileStatusSchema).default([]),
4238
+ unstaged: external_exports.array(GitFileStatusSchema).default([]),
4239
+ untracked: external_exports.array(GitFileStatusSchema).default([]),
4240
+ modified: external_exports.array(GitFileStatusSchema).optional(),
4241
+ deleted: external_exports.array(GitFileStatusSchema).optional(),
4242
+ hasChanges: external_exports.boolean().default(false),
4243
+ isClean: external_exports.boolean().default(true),
4244
+ ahead: external_exports.number().int().default(0),
4245
+ behind: external_exports.number().int().default(0)
4246
+ });
4184
4247
 
4185
4248
  // src/extensions/guided-lab.ts
4186
4249
  function guidedLabExtension(workbench, options = {}) {
@@ -4201,6 +4201,69 @@ var CodeLabGuidedLab = (() => {
4201
4201
  onStepComplete: external_exports.function().args(external_exports.any(), external_exports.number()).returns(external_exports.void()).optional(),
4202
4202
  onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
4203
4203
  });
4204
+ var SearchOptionsSchema = external_exports.object({
4205
+ query: external_exports.string().default(""),
4206
+ caseSensitive: external_exports.boolean().optional().default(false),
4207
+ wholeWord: external_exports.boolean().optional().default(false),
4208
+ regex: external_exports.boolean().optional().default(false),
4209
+ isRegex: external_exports.boolean().optional().default(false),
4210
+ include: external_exports.string().optional(),
4211
+ includeGlob: external_exports.string().optional(),
4212
+ includePattern: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
4213
+ exclude: external_exports.string().optional(),
4214
+ excludeGlob: external_exports.string().optional(),
4215
+ excludePattern: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
4216
+ maxMatches: external_exports.number().int().positive().optional(),
4217
+ maxMatchesPerFile: external_exports.number().int().positive().optional()
4218
+ });
4219
+ var DiagnosticSeveritySchema = external_exports.enum(["error", "warning", "info", "hint"]);
4220
+ var DiagnosticItemSchema = external_exports.object({
4221
+ id: external_exports.string(),
4222
+ file: external_exports.string(),
4223
+ line: external_exports.number().int(),
4224
+ col: external_exports.number().int().optional(),
4225
+ column: external_exports.number().int().optional(),
4226
+ endLine: external_exports.number().int().optional(),
4227
+ endCol: external_exports.number().int().optional(),
4228
+ endColumn: external_exports.number().int().optional(),
4229
+ message: external_exports.string(),
4230
+ severity: DiagnosticSeveritySchema,
4231
+ source: external_exports.string().optional(),
4232
+ code: external_exports.union([external_exports.string(), external_exports.number()]).optional(),
4233
+ tags: external_exports.array(external_exports.string()).optional()
4234
+ });
4235
+ var StoredProjectSchema = external_exports.object({
4236
+ id: external_exports.string(),
4237
+ name: external_exports.string(),
4238
+ files: external_exports.record(external_exports.string()),
4239
+ updatedAt: external_exports.number(),
4240
+ createdAt: external_exports.number().optional(),
4241
+ entry: external_exports.string().optional(),
4242
+ testEntry: external_exports.string().optional(),
4243
+ version: external_exports.number().optional()
4244
+ });
4245
+ var GitFileChangeTypeSchema = external_exports.enum(["modified", "added", "deleted", "untracked"]);
4246
+ var GitFileStatusSchema = external_exports.object({
4247
+ path: external_exports.string(),
4248
+ status: GitFileChangeTypeSchema,
4249
+ staged: external_exports.boolean(),
4250
+ oldContent: external_exports.string().optional(),
4251
+ newContent: external_exports.string().optional()
4252
+ });
4253
+ var GitStateSummarySchema = external_exports.object({
4254
+ branch: external_exports.string().default("main"),
4255
+ headCommit: external_exports.string().optional(),
4256
+ branches: external_exports.array(external_exports.string()).default(["main"]),
4257
+ staged: external_exports.array(GitFileStatusSchema).default([]),
4258
+ unstaged: external_exports.array(GitFileStatusSchema).default([]),
4259
+ untracked: external_exports.array(GitFileStatusSchema).default([]),
4260
+ modified: external_exports.array(GitFileStatusSchema).optional(),
4261
+ deleted: external_exports.array(GitFileStatusSchema).optional(),
4262
+ hasChanges: external_exports.boolean().default(false),
4263
+ isClean: external_exports.boolean().default(true),
4264
+ ahead: external_exports.number().int().default(0),
4265
+ behind: external_exports.number().int().default(0)
4266
+ });
4204
4267
 
4205
4268
  // src/extensions/guided-lab.ts
4206
4269
  function guidedLabExtension(workbench, options = {}) {
package/dist/html.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @innovatorved/code-lab — Safe HTML Tagged Template & Escaping Primitives
3
+ * ============================================================================
4
+ * Strict TypeScript leaf module. Every interpolated value in `html\`...\`` is
5
+ * HTML-escaped by default unless explicitly wrapped with `raw(...)` or
6
+ * produced by nested `html\`...\`` calls.
7
+ */
8
+ declare const SAFE_HTML_BRAND: unique symbol;
9
+ export interface SafeHtml {
10
+ readonly [SAFE_HTML_BRAND]: true;
11
+ readonly __html: string;
12
+ toString(): string;
13
+ }
14
+ export declare function isSafeHtml(value: unknown): value is SafeHtml;
15
+ export declare function escapeHtml(value: unknown): string;
16
+ export declare function raw(trustedHtml: string): SafeHtml;
17
+ export declare function html(strings: TemplateStringsArray, ...values: unknown[]): SafeHtml;
18
+ declare const _htmlNamespace: {
19
+ escapeHtml: typeof escapeHtml;
20
+ raw: typeof raw;
21
+ isSafeHtml: typeof isSafeHtml;
22
+ html: typeof html;
23
+ };
24
+ export default _htmlNamespace;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  /**
2
- * @innovatorved/code-lab v0.1.7
2
+ * @innovatorved/code-lab v0.1.8
3
3
  * Browser-native IDE, POSIX Shell, Web Worker Node.js/Bun Runtime, and Git Engine.
4
4
  */
5
5
  export * from './schemas';
6
+ export * from './logger';
7
+ export { SafeHtml, isSafeHtml, raw, html } from './html';
8
+ export * from './csp';
9
+ export * from './zip';
10
+ export { type StorageBackendType, type ProjectSummary, type WorkspaceStorageOptions, WorkspaceStorage, createWorkspaceStorage } from './storage';
11
+ export { type SearchMatchItem, type SearchMatchGroup, type SearchResult, type ReplaceResult, escapeRegex, normalizeSearchPath, matchesGlob, searchInFiles, replaceInFiles } from './search';
12
+ export { type DiagnosticListener, DiagnosticsStore, createDiagnosticsStore } from './diagnostics';
13
+ export { type GitCommitRecord, type GitState, type GitStatusResult, computeShortCommitHash, createGitState, computeGitStatus, stageFile, unstageFile, commitChanges } from './scm';
6
14
  export * from './runtime';
7
15
  export { createPosixShell, cloneGitHubRepository, parseGitHubRepoUrl, CodeLabShell } from './shell';
8
16
  export * from './terminal';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @innovatorved/code-lab — Shared Leveled Logger & Typed Error Hierarchy
3
+ * ============================================================================
4
+ * Bundled as `CodeLabLogger` into the runtime, shell, terminal, and workbench
5
+ * bundles so no subsystem needs empty `catch` blocks or ad-hoc console calls.
6
+ */
7
+ export declare const LOG_PREFIX = "[code-lab]";
8
+ export type CodeLabLogLevel = 'debug' | 'info' | 'warn' | 'error';
9
+ export interface CodeLabLogSink {
10
+ debug?: (...args: unknown[]) => void;
11
+ info?: (...args: unknown[]) => void;
12
+ warn?: (...args: unknown[]) => void;
13
+ error?: (...args: unknown[]) => void;
14
+ }
15
+ export interface CodeLabLoggerOptions {
16
+ logger?: CodeLabLogSink | null;
17
+ debug?: boolean;
18
+ prefix?: string;
19
+ }
20
+ export interface CodeLabLogger {
21
+ debug: (...args: unknown[]) => void;
22
+ info: (...args: unknown[]) => void;
23
+ warn: (...args: unknown[]) => void;
24
+ error: (...args: unknown[]) => void;
25
+ }
26
+ export type CodeLabErrorCode = 'E_SAVE' | 'E_PERSISTENCE' | 'E_INSTALL' | 'E_PREVIEW' | 'E_RUNTIME' | 'E_SHELL' | 'E_CLONE' | 'E_CONFIG';
27
+ export interface CodeLabErrorOptions {
28
+ cause?: unknown;
29
+ recoverable?: boolean;
30
+ details?: Record<string, unknown>;
31
+ context?: Record<string, unknown>;
32
+ }
33
+ /**
34
+ * Structured error surfaced through `wb.on('error', ...)` and `wb.on('save-state', ...)`.
35
+ */
36
+ export declare class CodeLabError extends Error {
37
+ readonly code: CodeLabErrorCode;
38
+ readonly options: CodeLabErrorOptions;
39
+ readonly cause?: unknown;
40
+ readonly recoverable: boolean;
41
+ readonly details?: Record<string, unknown>;
42
+ readonly context?: Record<string, unknown>;
43
+ constructor(code: CodeLabErrorCode, message: string, options?: CodeLabErrorOptions);
44
+ }
45
+ export declare function isCodeLabError(value: unknown): value is CodeLabError;
46
+ /**
47
+ * Small leveled logger. Hosts can pass `options.logger` to route diagnostics
48
+ * into their own telemetry; `options.debug` enables verbose output. Errors and
49
+ * warnings are never silently discarded.
50
+ */
51
+ export declare function createLogger(options?: CodeLabLoggerOptions): CodeLabLogger;
52
+ export declare const DEFAULT_LOGGER: CodeLabLogger;
53
+ declare const _loggerNamespace: {
54
+ LOG_PREFIX: string;
55
+ CodeLabError: typeof CodeLabError;
56
+ isCodeLabError: typeof isCodeLabError;
57
+ createLogger: typeof createLogger;
58
+ DEFAULT_LOGGER: CodeLabLogger;
59
+ };
60
+ export default _loggerNamespace;