@innovatorved/code-lab 0.1.7 → 0.1.9

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript Definitions for @innovatorved/code-lab v0.1.7
2
+ * TypeScript Definitions for @innovatorved/code-lab v0.1.9
3
3
  */
4
4
 
5
5
  export interface CodeLabStep {
@@ -107,6 +107,213 @@ export interface CodeLabCloneOptions {
107
107
  signal?: AbortSignal;
108
108
  }
109
109
 
110
+ /** Per-directive allowlists for the Web Preview Content-Security-Policy. */
111
+ export interface CodeLabPreviewCspSources {
112
+ scriptSrc?: string[];
113
+ styleSrc?: string[];
114
+ imgSrc?: string[];
115
+ fontSrc?: string[];
116
+ connectSrc?: string[];
117
+ mediaSrc?: string[];
118
+ workerSrc?: string[];
119
+ frameSrc?: string[];
120
+ }
121
+
122
+ export interface CodeLabPreviewCsp extends CodeLabPreviewCspSources {
123
+ /**
124
+ * - balanced (default) allows the CDNs the built-in preview server resolves
125
+ * bare imports to (jsDelivr, esm.sh), plus fonts.googleapis.com.
126
+ * - strict blocks every remote host; only same-origin, data: and blob:.
127
+ * - custom uses only the allowlists you provide.
128
+ */
129
+ mode?: 'strict' | 'balanced' | 'custom';
130
+ }
131
+
132
+ /** Payload emitted when a preview document violates its Content-Security-Policy. */
133
+ export interface CodeLabPreviewViolation {
134
+ directive: string;
135
+ blockedURI: string;
136
+ }
137
+
138
+ /**
139
+ * Build, validate and describe Web Preview Content-Security-Policies.
140
+ * Bundled into both the workbench and dist/preview-sw.js.
141
+ */
142
+ export interface CodeLabCspAPI {
143
+ buildPreviewPolicy(options?: {
144
+ mode?: 'strict' | 'balanced' | 'custom';
145
+ hostOrigin?: string;
146
+ frameAncestors?: string;
147
+ } & CodeLabPreviewCspSources): string;
148
+ normalizePreviewCspConfig(raw: unknown): {
149
+ mode: 'strict' | 'balanced' | 'custom';
150
+ allow: CodeLabPreviewCspSources;
151
+ };
152
+ describePreviewNetwork(config: unknown): string[];
153
+ buildPreviewShims(): string;
154
+ normalizeOrigin(raw: unknown): string | null;
155
+ PREVIEW_SHIM_MARKER: string;
156
+ }
157
+
158
+ export declare const CodeLabCsp: CodeLabCspAPI;
159
+
160
+ export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
161
+
162
+ export type CodeLabErrorCode =
163
+ | 'E_PERSISTENCE'
164
+ | 'E_WORKER_TIMEOUT'
165
+ | 'E_WORKER_CRASH'
166
+ | 'E_WORKER_INIT'
167
+ | 'E_CSP_VIOLATION'
168
+ | 'E_PREVIEW_SW'
169
+ | 'E_PREVIEW_RENDER'
170
+ | 'E_NETWORK_BLOCKED'
171
+ | 'E_VFS'
172
+ | 'E_SHELL'
173
+ | 'E_TERMINAL'
174
+ | 'E_MONACO_LOAD'
175
+ | 'E_PACKAGE_FETCH'
176
+ | 'E_CLONE_FAILED'
177
+ | 'E_EXTENSION';
178
+
179
+ export interface CodeLabErrorOptions {
180
+ cause?: unknown;
181
+ context?: Record<string, unknown>;
182
+ }
183
+
184
+ export declare class CodeLabError extends Error {
185
+ readonly code: CodeLabErrorCode;
186
+ readonly context?: Record<string, unknown>;
187
+ readonly cause?: unknown;
188
+ constructor(code: CodeLabErrorCode, message: string, options?: CodeLabErrorOptions);
189
+ }
190
+
191
+ export interface Logger {
192
+ readonly level: LogLevel;
193
+ error(message: string, meta?: unknown): void;
194
+ warn(message: string, meta?: unknown): void;
195
+ info(message: string, meta?: unknown): void;
196
+ debug(message: string, meta?: unknown): void;
197
+ }
198
+
199
+ export interface CreateLoggerOptions {
200
+ level?: LogLevel;
201
+ scope?: string;
202
+ sink?: Partial<Record<Exclude<LogLevel, 'silent'>, (line: string, meta?: unknown) => void>>;
203
+ }
204
+
205
+ export declare function isCodeLabError(value: unknown): value is CodeLabError;
206
+ export declare function createLogger(input?: LogLevel | CreateLoggerOptions | Logger): Logger;
207
+ export declare const DEFAULT_LOGGER: Logger;
208
+ export declare const LOG_PREFIX = '[code-lab]';
209
+
210
+ export interface SafeHtml {
211
+ readonly __html: string;
212
+ toString(): string;
213
+ }
214
+
215
+ export declare function escapeHtml(value: unknown): string;
216
+ export declare function raw(trustedHtml: string): SafeHtml;
217
+ export declare function isSafeHtml(value: unknown): value is SafeHtml;
218
+ export declare function html(strings: TemplateStringsArray, ...values: unknown[]): SafeHtml;
219
+
220
+ export declare function computeCrc32(data: string | Uint8Array): number;
221
+ export declare function sanitizeZipPath(rawPath: string): string;
222
+ export declare function createZip(files: Record<string, string | Uint8Array>): Uint8Array;
223
+ export declare function extractZip(archive: Uint8Array): Record<string, Uint8Array>;
224
+ export declare const CodeLabZip: {
225
+ computeCrc32: typeof computeCrc32;
226
+ sanitizeZipPath: typeof sanitizeZipPath;
227
+ createZip: typeof createZip;
228
+ extractZip: typeof extractZip;
229
+ };
230
+
231
+ export interface WorkspaceProjectData {
232
+ id: string;
233
+ name?: string;
234
+ files?: Record<string, string>;
235
+ updatedAt?: number;
236
+ [key: string]: unknown;
237
+ }
238
+
239
+ export interface WorkspaceProjectSummary {
240
+ id: string;
241
+ name: string;
242
+ updatedAt: number;
243
+ fileCount: number;
244
+ }
245
+
246
+ export declare class WorkspaceStorage {
247
+ constructor(options?: Record<string, unknown>);
248
+ getBackendType(): 'indexeddb' | 'localstorage' | 'memory';
249
+ saveProject(project: WorkspaceProjectData): Promise<boolean>;
250
+ loadProject(id: string): Promise<WorkspaceProjectData | null>;
251
+ listProjects(): Promise<WorkspaceProjectSummary[]>;
252
+ deleteProject(id: string): Promise<boolean>;
253
+ }
254
+ export declare function createWorkspaceStorage(options?: Record<string, unknown>): WorkspaceStorage;
255
+ export declare const CodeLabStorage: {
256
+ WorkspaceStorage: typeof WorkspaceStorage;
257
+ createWorkspaceStorage: typeof createWorkspaceStorage;
258
+ };
259
+
260
+ export interface SearchOptions {
261
+ query: string;
262
+ caseSensitive?: boolean;
263
+ wholeWord?: boolean;
264
+ regex?: boolean;
265
+ include?: string;
266
+ exclude?: string;
267
+ }
268
+
269
+ export declare function searchInFiles(files: Record<string, string>, options: SearchOptions): any;
270
+ export declare function replaceInFiles(files: Record<string, string>, options: SearchOptions, replacement: string): any;
271
+ export declare function matchesGlob(filePath: string, globPattern?: string): boolean;
272
+ export declare function escapeRegex(literal: string): string;
273
+ export declare function normalizeSearchPath(rawPath: string): string;
274
+ export declare const CodeLabSearch: {
275
+ searchInFiles: typeof searchInFiles;
276
+ replaceInFiles: typeof replaceInFiles;
277
+ matchesGlob: typeof matchesGlob;
278
+ escapeRegex: typeof escapeRegex;
279
+ normalizeSearchPath: typeof normalizeSearchPath;
280
+ };
281
+
282
+ export declare class DiagnosticsStore {
283
+ add(item: any): void;
284
+ remove(id: string): void;
285
+ clear(source?: string): void;
286
+ getAll(filter?: any): any[];
287
+ getByFile(file: string): any[];
288
+ subscribe(listener: (items: any[]) => void): () => void;
289
+ }
290
+ export declare function createDiagnosticsStore(): DiagnosticsStore;
291
+ export declare const CodeLabDiagnostics: {
292
+ DiagnosticsStore: typeof DiagnosticsStore;
293
+ createDiagnosticsStore: typeof createDiagnosticsStore;
294
+ };
295
+
296
+ export declare function createGitState(initialFiles?: Record<string, string>, branch?: string): any;
297
+ export declare function computeGitStatus(vfsFiles: Record<string, string>, repoRoot: string, gitState: any): any;
298
+ export declare function stageFile(path: string, vfsFiles: Record<string, string>, gitState: any): boolean;
299
+ export declare function unstageFile(path: string, gitState: any): boolean;
300
+ export declare function commitChanges(message: string, author: string | undefined, gitState: any): any;
301
+ export declare function computeShortCommitHash(input: string): string;
302
+ export declare const CodeLabScm: {
303
+ createGitState: typeof createGitState;
304
+ computeGitStatus: typeof computeGitStatus;
305
+ stageFile: typeof stageFile;
306
+ unstageFile: typeof unstageFile;
307
+ commitChanges: typeof commitChanges;
308
+ computeShortCommitHash: typeof computeShortCommitHash;
309
+ };
310
+
311
+ export interface CodeLabSaveStateEvent {
312
+ state: 'saved' | 'failed';
313
+ key: string;
314
+ error?: CodeLabError;
315
+ }
316
+
110
317
  export interface CodeLabOptions {
111
318
  /** Unique identifier used for localStorage persistence */
112
319
  id?: string;
@@ -116,6 +323,15 @@ export interface CodeLabOptions {
116
323
  title?: string;
117
324
  /** Subtitle / summary displayed in the guide panel when README.md is absent */
118
325
  summary?: string;
326
+ /** Content-Security-Policy applied to Web Preview documents */
327
+ previewCsp?: CodeLabPreviewCsp | 'strict' | 'balanced' | 'custom';
328
+ /**
329
+ * Origin used to serve previews from a different origin than the IDE.
330
+ * Requires the preview relay (apps/preview-origin), which has not shipped
331
+ * yet: the option is currently ignored with a console warning rather than
332
+ * silently returning 503s.
333
+ */
334
+ previewOrigin?: string;
119
335
  /** Initial workbench mode ('guided' | 'sandbox') */
120
336
  mode?: 'guided' | 'sandbox';
121
337
  /** Initial workspace language ('js' | 'ts') */
@@ -125,6 +341,10 @@ export interface CodeLabOptions {
125
341
  theme?: 'dark' | 'light' | 'auto';
126
342
  /** Set to false to disable localStorage persistence and use in-memory state only */
127
343
  persistState?: boolean;
344
+ /** Structured logger or log level ('silent' | 'error' | 'warn' | 'info' | 'debug', default: 'warn') */
345
+ logger?: LogLevel | CreateLoggerOptions | Logger;
346
+ /** Shortcut for setting logger level */
347
+ logLevel?: LogLevel;
128
348
  /** Public GitHub repository URL or owner/repo shorthand to automatically clone on mount */
129
349
  repo?: string;
130
350
  githubRepo?: string;
@@ -234,12 +454,32 @@ export declare class CodeLabWorkbench {
234
454
  downloadFile(path?: string): { filename: string; content: string } | null;
235
455
  exportWorkspace(options?: { download?: boolean }): Record<string, any>;
236
456
  importWorkspace(snapshotOrJson: string | Record<string, any>): boolean;
457
+ exportZip(options?: { download?: boolean; filename?: string }): Uint8Array | null;
458
+ importZip(archiveBytes: Uint8Array, options?: { merge?: boolean }): number;
459
+ showSearchModal(initialQuery?: string): void;
460
+ showScmModal(): void;
461
+ getDiagnostics(filter?: { file?: string; severity?: 'error' | 'warning' | 'info'; source?: string }): any[];
462
+ showProblemsModal(): void;
463
+ listTerminalSessions(): Array<{ id: string; name: string; active: boolean }>;
464
+ createTerminalSession(name?: string): string;
465
+ switchTerminalSession(id: string): boolean;
466
+ closeTerminalSession(id: string): boolean;
467
+ saveProjectToStorage(projectId?: string): Promise<boolean>;
468
+ loadProjectFromStorage(projectId?: string): Promise<boolean>;
237
469
  getFiles(): Record<string, string>;
238
470
  setFiles(filesMap: Record<string, string>, options?: { merge?: boolean }): this;
239
471
  getFile(path: string): string | null;
240
472
  setFile(path: string, content: string, options?: { open?: boolean }): this;
241
473
  getOpenTabs(): string[];
242
474
  reset(): this;
475
+ previewOrigin: string | null;
476
+ previewCsp: { mode: 'strict' | 'balanced' | 'custom'; allow: CodeLabPreviewCspSources };
477
+ logger: Logger;
478
+ saveStatusState: 'saved' | 'failed';
479
+ lastSaveError: CodeLabError | null;
480
+ on(event: 'preview-violation', handler: (detail: CodeLabPreviewViolation) => void): () => void;
481
+ on(event: 'save-state', handler: (detail: CodeLabSaveStateEvent) => void): () => void;
482
+ on(event: 'error', handler: (detail: CodeLabError) => void): () => void;
243
483
  on(event: string, handler: (detail: any) => void): () => void;
244
484
  off(event: string, handler: (detail: any) => void): this;
245
485
  use(plugin: (workbench: CodeLabWorkbench, options?: any) => any, options?: any): this;
@@ -266,6 +506,16 @@ export declare class CodeLabElement extends HTMLElement {
266
506
  showDiffModal(targetFile?: string, compareTarget?: 'solution' | 'starter'): void;
267
507
  exportWorkspace(options?: { download?: boolean }): Record<string, any> | null;
268
508
  importWorkspace(snapshotOrJson: string | Record<string, any>): boolean;
509
+ exportZip(options?: { download?: boolean; filename?: string }): Uint8Array | null;
510
+ importZip(archiveBytes: Uint8Array, options?: { merge?: boolean }): number;
511
+ showSearchModal(initialQuery?: string): void;
512
+ showScmModal(): void;
513
+ getDiagnostics(filter?: { file?: string; severity?: 'error' | 'warning' | 'info'; source?: string }): any[];
514
+ showProblemsModal(): void;
515
+ listTerminalSessions(): Array<{ id: string; name: string; active: boolean }>;
516
+ createTerminalSession(name?: string): string | null;
517
+ switchTerminalSession(id: string): boolean;
518
+ closeTerminalSession(id: string): boolean;
269
519
  cloneRepo(repoUrlOrSlug: string, options?: CodeLabCloneOptions): Promise<any>;
270
520
  }
271
521
 
@@ -346,6 +596,26 @@ export interface CodeLabStatic {
346
596
  unmount(container: HTMLElement | string): void;
347
597
  cloneRepo(vfsOrWorkbench: any, repoInput: string, options?: CodeLabCloneOptions): Promise<any>;
348
598
  parseGitHubRepoUrl: CodeLabShellAPI['parseGitHubRepoUrl'];
599
+ CodeLabError: typeof CodeLabError;
600
+ isCodeLabError: typeof isCodeLabError;
601
+ createLogger: typeof createLogger;
602
+ Logger: {
603
+ CodeLabError: typeof CodeLabError;
604
+ isCodeLabError: typeof isCodeLabError;
605
+ createLogger: typeof createLogger;
606
+ DEFAULT_LOGGER: Logger;
607
+ LOG_PREFIX: typeof LOG_PREFIX;
608
+ };
609
+ html: typeof html;
610
+ raw: typeof raw;
611
+ isSafeHtml: typeof isSafeHtml;
612
+ escapeHtml: typeof escapeHtml;
613
+ Html: {
614
+ html: typeof html;
615
+ raw: typeof raw;
616
+ isSafeHtml: typeof isSafeHtml;
617
+ escapeHtml: typeof escapeHtml;
618
+ };
349
619
  }
350
620
 
351
621
  export declare const CodeLab: CodeLabStatic;