@cjhyy/code-shell-web 0.9.22 → 0.9.25

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/index.d.ts CHANGED
@@ -23,3 +23,5 @@ export * from "./lib/mobileAttachments.js";
23
23
  export * from "./lib/uiLanguage.js";
24
24
  export { mobile } from "./i18n/mobile.js";
25
25
  export { translate, t, webMessages, type WebTranslationKey, type WebTranslateParams, } from "./i18n/translate.js";
26
+ export { isEnvironmentDescriptor, projectReferenceKey } from "./lib/environment.js";
27
+ export type { EnvironmentDescriptor, ProjectReference } from "./lib/environment.js";
package/dist/index.js CHANGED
@@ -27,3 +27,4 @@ export * from "./lib/uiLanguage.js";
27
27
  // ── i18n: mobile namespace dict + zh-fallback translate ─────────────────────
28
28
  export { mobile } from "./i18n/mobile.js";
29
29
  export { translate, t, webMessages, } from "./i18n/translate.js";
30
+ export { isEnvironmentDescriptor, projectReferenceKey } from "./lib/environment.js";
@@ -0,0 +1,16 @@
1
+ /** Browser-safe discovery contract. A project identifier is only unique inside its host. */
2
+ export interface EnvironmentDescriptor {
3
+ version: 1;
4
+ id: string;
5
+ name: string;
6
+ kind: "desktop" | "hub" | "project-host";
7
+ entryPath: "/" | "/mobile";
8
+ }
9
+ export interface ProjectReference {
10
+ environmentId: string;
11
+ projectId: string;
12
+ rootId?: string;
13
+ }
14
+ export declare function isEnvironmentDescriptor(value: unknown): value is EnvironmentDescriptor;
15
+ /** Tuple encoding avoids collisions without exposing or interpreting filesystem paths. */
16
+ export declare function projectReferenceKey(reference: ProjectReference): string;
@@ -0,0 +1,25 @@
1
+ const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
2
+ export function isEnvironmentDescriptor(value) {
3
+ if (!value || typeof value !== "object")
4
+ return false;
5
+ const record = value;
6
+ return (record.version === 1 &&
7
+ typeof record.id === "string" &&
8
+ UUID.test(record.id) &&
9
+ typeof record.name === "string" &&
10
+ record.name.trim().length > 0 &&
11
+ record.name.length <= 128 &&
12
+ !/[\u0000-\u001f\u007f]/.test(record.name) &&
13
+ ["desktop", "hub", "project-host"].includes(record.kind) &&
14
+ record.entryPath === (record.kind === "desktop" ? "/mobile" : "/"));
15
+ }
16
+ /** Tuple encoding avoids collisions without exposing or interpreting filesystem paths. */
17
+ export function projectReferenceKey(reference) {
18
+ for (const value of [reference.environmentId, reference.projectId, reference.rootId]) {
19
+ if (value !== undefined && (typeof value !== "string" || !UUID.test(value)))
20
+ throw new Error("Invalid project reference");
21
+ }
22
+ if (!reference.environmentId || !reference.projectId)
23
+ throw new Error("Incomplete project reference");
24
+ return JSON.stringify([reference.environmentId, reference.projectId, reference.rootId ?? null]);
25
+ }