@ericsanchezok/meta-protocol 1.1.9 → 1.1.10

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,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@ericsanchezok/meta-protocol",
4
- "version": "1.1.9",
4
+ "version": "1.1.10",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "types": "./src/index.ts",
package/src/env.ts CHANGED
@@ -15,13 +15,68 @@ export namespace MetaProtocolEnv {
15
15
 
16
16
  export type Target = { kind: "local" } | { kind: "remote"; envID: EnvID }
17
17
 
18
+ const LOCAL_ALIASES = new Set([
19
+ "local",
20
+ ":local",
21
+ "localhost",
22
+ "127.0.0.1",
23
+ "::1",
24
+ "loopback",
25
+ "self",
26
+ ":self",
27
+ "current",
28
+ ":current",
29
+ "host",
30
+ ":host",
31
+ "this",
32
+ ":this",
33
+ ])
34
+
35
+ const PLACEHOLDER_ALIASES = new Set(["undefined", "null", "none", "nil", "n/a"])
36
+
37
+ export class InvalidEnvIDError extends Error {
38
+ constructor(
39
+ readonly envID: string,
40
+ readonly reason: "placeholder_alias",
41
+ ) {
42
+ super(
43
+ `Invalid envID \"${envID}\". This looks like a placeholder value, not a real remote environment ID. ` +
44
+ `For local execution, omit envID entirely. For remote execution, pass a real remote envID such as \"env_...\".`,
45
+ )
46
+ this.name = "MetaProtocolInvalidEnvIDError"
47
+ }
48
+ }
49
+
50
+ export function normalize(envID?: string): EnvID | undefined {
51
+ if (envID === undefined) {
52
+ return undefined
53
+ }
54
+
55
+ const trimmed = envID.trim()
56
+ if (!trimmed) {
57
+ return undefined
58
+ }
59
+
60
+ const lowered = trimmed.toLowerCase()
61
+ if (LOCAL_ALIASES.has(lowered)) {
62
+ return undefined
63
+ }
64
+
65
+ if (PLACEHOLDER_ALIASES.has(lowered)) {
66
+ throw new InvalidEnvIDError(trimmed, "placeholder_alias")
67
+ }
68
+
69
+ return trimmed as EnvID
70
+ }
71
+
18
72
  export function resolve(envID?: string): Target {
19
- if (!envID) {
73
+ const normalized = normalize(envID)
74
+ if (!normalized) {
20
75
  return { kind: "local" }
21
76
  }
22
77
  return {
23
78
  kind: "remote",
24
- envID,
79
+ envID: normalized,
25
80
  }
26
81
  }
27
82
  }
@@ -0,0 +1 @@
1
+ export {}