@promigence/sdk 0.1.0-beta.12

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.
Files changed (104) hide show
  1. package/NOTICE +14 -0
  2. package/README.md +54 -0
  3. package/dist/blake3.d.ts +10 -0
  4. package/dist/blake3.js +111 -0
  5. package/dist/bundle.d.ts +96 -0
  6. package/dist/bundle.js +227 -0
  7. package/dist/ca-guard.d.ts +1 -0
  8. package/dist/ca-guard.js +166 -0
  9. package/dist/caller.d.ts +73 -0
  10. package/dist/caller.js +47 -0
  11. package/dist/cjs/blake3.d.ts +10 -0
  12. package/dist/cjs/blake3.js +116 -0
  13. package/dist/cjs/bundle.d.ts +96 -0
  14. package/dist/cjs/bundle.js +242 -0
  15. package/dist/cjs/ca-guard.d.ts +1 -0
  16. package/dist/cjs/ca-guard.js +174 -0
  17. package/dist/cjs/caller.d.ts +73 -0
  18. package/dist/cjs/caller.js +57 -0
  19. package/dist/cjs/client.d.ts +3015 -0
  20. package/dist/cjs/client.js +2617 -0
  21. package/dist/cjs/command-errors.d.ts +41 -0
  22. package/dist/cjs/command-errors.js +43 -0
  23. package/dist/cjs/context.d.ts +119 -0
  24. package/dist/cjs/context.js +598 -0
  25. package/dist/cjs/core.d.ts +285 -0
  26. package/dist/cjs/core.js +290 -0
  27. package/dist/cjs/credstore.d.ts +90 -0
  28. package/dist/cjs/credstore.js +219 -0
  29. package/dist/cjs/dispatcher.d.ts +58 -0
  30. package/dist/cjs/dispatcher.js +91 -0
  31. package/dist/cjs/github.d.ts +158 -0
  32. package/dist/cjs/github.js +84 -0
  33. package/dist/cjs/gitlab.d.ts +104 -0
  34. package/dist/cjs/gitlab.js +24 -0
  35. package/dist/cjs/handles.d.ts +82 -0
  36. package/dist/cjs/handles.js +139 -0
  37. package/dist/cjs/hint.d.ts +1 -0
  38. package/dist/cjs/hint.js +10 -0
  39. package/dist/cjs/http2.d.ts +206 -0
  40. package/dist/cjs/http2.js +1932 -0
  41. package/dist/cjs/index.d.ts +34 -0
  42. package/dist/cjs/index.js +31 -0
  43. package/dist/cjs/keyed.gen.d.ts +1 -0
  44. package/dist/cjs/keyed.gen.js +10 -0
  45. package/dist/cjs/models.gen.d.ts +6162 -0
  46. package/dist/cjs/models.gen.js +2 -0
  47. package/dist/cjs/package.json +1 -0
  48. package/dist/cjs/proxy.d.ts +40 -0
  49. package/dist/cjs/proxy.js +257 -0
  50. package/dist/cjs/pty.d.ts +171 -0
  51. package/dist/cjs/pty.js +504 -0
  52. package/dist/cjs/sandbox.d.ts +537 -0
  53. package/dist/cjs/sandbox.js +736 -0
  54. package/dist/cjs/ssh.d.ts +25 -0
  55. package/dist/cjs/ssh.js +117 -0
  56. package/dist/cjs/trace.d.ts +33 -0
  57. package/dist/cjs/trace.js +88 -0
  58. package/dist/cjs/transport-worker.d.ts +1 -0
  59. package/dist/cjs/transport-worker.js +468 -0
  60. package/dist/cjs/warm.d.ts +1 -0
  61. package/dist/cjs/warm.js +43 -0
  62. package/dist/client.d.ts +3015 -0
  63. package/dist/client.js +2583 -0
  64. package/dist/command-errors.d.ts +41 -0
  65. package/dist/command-errors.js +36 -0
  66. package/dist/context.d.ts +119 -0
  67. package/dist/context.js +588 -0
  68. package/dist/core.d.ts +285 -0
  69. package/dist/core.js +266 -0
  70. package/dist/credstore.d.ts +90 -0
  71. package/dist/credstore.js +206 -0
  72. package/dist/dispatcher.d.ts +58 -0
  73. package/dist/dispatcher.js +86 -0
  74. package/dist/github.d.ts +158 -0
  75. package/dist/github.js +78 -0
  76. package/dist/gitlab.d.ts +104 -0
  77. package/dist/gitlab.js +20 -0
  78. package/dist/handles.d.ts +82 -0
  79. package/dist/handles.js +135 -0
  80. package/dist/hint.d.ts +1 -0
  81. package/dist/hint.js +7 -0
  82. package/dist/http2.d.ts +206 -0
  83. package/dist/http2.js +1921 -0
  84. package/dist/index.d.ts +34 -0
  85. package/dist/index.js +15 -0
  86. package/dist/keyed.gen.d.ts +1 -0
  87. package/dist/keyed.gen.js +7 -0
  88. package/dist/models.gen.d.ts +6162 -0
  89. package/dist/models.gen.js +1 -0
  90. package/dist/proxy.d.ts +40 -0
  91. package/dist/proxy.js +249 -0
  92. package/dist/pty.d.ts +171 -0
  93. package/dist/pty.js +496 -0
  94. package/dist/sandbox.d.ts +537 -0
  95. package/dist/sandbox.js +725 -0
  96. package/dist/ssh.d.ts +25 -0
  97. package/dist/ssh.js +114 -0
  98. package/dist/trace.d.ts +33 -0
  99. package/dist/trace.js +80 -0
  100. package/dist/transport-worker.d.ts +1 -0
  101. package/dist/transport-worker.js +466 -0
  102. package/dist/warm.d.ts +1 -0
  103. package/dist/warm.js +40 -0
  104. package/package.json +54 -0
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__caGuardInternals = exports.guardCertChain = exports.CompromisedKeyError = void 0;
4
+ exports.compromisedKeyCause = compromisedKeyCause;
5
+ exports.chainHasCompromisedKey = chainHasCompromisedKey;
6
+ exports.makeCertChainGuard = makeCertChainGuard;
7
+ exports.guardedFetchDispatcher = guardedFetchDispatcher;
8
+ const crypto = require("node:crypto");
9
+ const tls = require("node:tls");
10
+ const DISTRUSTED_SPKI_SHA256 = new Set([
11
+ "ebed6475c2c2d80fcb199f3fe8dd6e6b3ce60b77eb15d4e42c3dec0c6f5b5105",
12
+ "49dd353dc2b919a3770645117d0e60c16115e7d1bc259eefe734b00ea434fe5f",
13
+ "e0254c7fcdc265e2f0f8a428dabb75ab4ae039b4872d62f5ee57f0877d5a8a41",
14
+ "5c0660a2b164910d8ff589c18e14552e9e0ec237dcefe2cb736d41a4811f81a0",
15
+ "43bffa19d6ef651451f6841e019931e96f6f2eaeff28ab4b6f1ce4576de2717b",
16
+ "63ecefee431d49523bc1136c4e72d0206a477086caf606cd5cf025686c109cf8",
17
+ "ec4ffa1ad0ac88081314b7aaffef6a91f97cd57291bb5ba686c5415f5eb4f6b6",
18
+ "92c063d67e8f14db71d288e11266ffdaf69cbf115f7bab14f3bc2f68d25e0e30",
19
+ ]);
20
+ const MAX_CHAIN_DEPTH = 10;
21
+ const COMPROMISED_KEY_MESSAGE = "The server's certificate chain uses a key that is publicly known to be compromised, so the connection was refused.";
22
+ class CompromisedKeyError extends Error {
23
+ constructor() {
24
+ super(COMPROMISED_KEY_MESSAGE);
25
+ this.name = "CompromisedKeyError";
26
+ }
27
+ }
28
+ exports.CompromisedKeyError = CompromisedKeyError;
29
+ function compromisedKeyCause(err) {
30
+ try {
31
+ let e = err;
32
+ for (let i = 0; i < 4; i++) {
33
+ if (typeof e !== "object" || e === null)
34
+ return undefined;
35
+ if (e instanceof CompromisedKeyError)
36
+ return e;
37
+ e = e.cause;
38
+ }
39
+ }
40
+ catch {
41
+ }
42
+ return undefined;
43
+ }
44
+ const TEST_HASHES = new Set();
45
+ let parseCount = 0;
46
+ function spkiSha256(raw) {
47
+ parseCount++;
48
+ try {
49
+ const der = new crypto.X509Certificate(raw).publicKey.export({ type: "spki", format: "der" });
50
+ return crypto.createHash("sha256").update(der).digest("hex");
51
+ }
52
+ catch {
53
+ return undefined;
54
+ }
55
+ }
56
+ const SPKI_BY_FINGERPRINT = new Map();
57
+ const SPKI_CACHE_MAX = 512;
58
+ function certSpkiSha256(node, raw) {
59
+ const fp = node.fingerprint256;
60
+ if (typeof fp !== "string" || fp === "")
61
+ return spkiSha256(raw);
62
+ const hit = SPKI_BY_FINGERPRINT.get(fp);
63
+ if (hit !== undefined)
64
+ return hit;
65
+ const hash = spkiSha256(raw);
66
+ if (hash === undefined)
67
+ return undefined;
68
+ if (SPKI_BY_FINGERPRINT.size >= SPKI_CACHE_MAX) {
69
+ for (const oldest of SPKI_BY_FINGERPRINT.keys()) {
70
+ SPKI_BY_FINGERPRINT.delete(oldest);
71
+ break;
72
+ }
73
+ }
74
+ SPKI_BY_FINGERPRINT.set(fp, hash);
75
+ return hash;
76
+ }
77
+ function chainHasCompromisedKey(cert) {
78
+ try {
79
+ let node = cert;
80
+ const seen = new Set();
81
+ for (let depth = 0; node && depth < MAX_CHAIN_DEPTH; depth++) {
82
+ if (seen.has(node))
83
+ break;
84
+ seen.add(node);
85
+ const raw = node.raw;
86
+ if (raw !== undefined && raw.length > 0) {
87
+ const hash = certSpkiSha256(node, raw);
88
+ if (hash !== undefined && DISTRUSTED_SPKI_SHA256.has(hash))
89
+ return true;
90
+ }
91
+ const issuer = node.issuerCertificate;
92
+ if (issuer === undefined || issuer === node)
93
+ break;
94
+ node = issuer;
95
+ }
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ return false;
101
+ }
102
+ function makeCertChainGuard(prev = tls.checkServerIdentity) {
103
+ return (host, cert) => {
104
+ const prevResult = prev(host, cert);
105
+ if (prevResult)
106
+ return prevResult;
107
+ return chainHasCompromisedKey(cert) ? new CompromisedKeyError() : undefined;
108
+ };
109
+ }
110
+ exports.guardCertChain = makeCertChainGuard();
111
+ const DISPATCHER_KEYS = [Symbol.for("undici.globalDispatcher.1"), Symbol.for("undici.globalDispatcher.2")];
112
+ let guardedAgent;
113
+ function isNode() {
114
+ try {
115
+ const v = typeof process === "object" ? process.versions : undefined;
116
+ return Boolean(v?.["node"]) && !v?.["bun"] && !v?.["deno"];
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ function undiciAgentCtor() {
123
+ for (const key of DISPATCHER_KEYS) {
124
+ const d = globalThis[key];
125
+ const ctor = d?.constructor;
126
+ if (typeof ctor === "function" && ctor.name === "Agent")
127
+ return ctor;
128
+ }
129
+ return undefined;
130
+ }
131
+ function guardedFetchDispatcher() {
132
+ if (guardedAgent !== undefined)
133
+ return guardedAgent === null ? undefined : guardedAgent;
134
+ guardedAgent = null;
135
+ try {
136
+ if (!isNode())
137
+ return undefined;
138
+ const Agent = undiciAgentCtor();
139
+ if (Agent === undefined)
140
+ return undefined;
141
+ const agent = new Agent({ connect: { checkServerIdentity: exports.guardCertChain } });
142
+ if (agent !== null && typeof agent.dispatch === "function") {
143
+ guardedAgent = agent;
144
+ return agent;
145
+ }
146
+ }
147
+ catch {
148
+ }
149
+ return undefined;
150
+ }
151
+ exports.__caGuardInternals = {
152
+ distrustedCount() {
153
+ return DISTRUSTED_SPKI_SHA256.size;
154
+ },
155
+ has(hashHex) {
156
+ return DISTRUSTED_SPKI_SHA256.has(hashHex);
157
+ },
158
+ addForTest(hashHex) {
159
+ DISTRUSTED_SPKI_SHA256.add(hashHex);
160
+ TEST_HASHES.add(hashHex);
161
+ },
162
+ testHashes() {
163
+ return [...TEST_HASHES];
164
+ },
165
+ parses() {
166
+ return parseCount;
167
+ },
168
+ cacheSize() {
169
+ return SPKI_BY_FINGERPRINT.size;
170
+ },
171
+ resetAgent() {
172
+ guardedAgent = undefined;
173
+ },
174
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `setCaller` — first-party attribution of SDK traffic.
3
+ *
4
+ * A caller is a short label naming the framework, harness or adapter driving this SDK: `cli`,
5
+ * `harbor`, `inspect`, or whatever you set yourself. It rides on one request header and on the
6
+ * `user-agent`, so we can see which integrations are actually used and build the next one where
7
+ * it is wanted.
8
+ *
9
+ * ## Nothing is ever auto-detected
10
+ *
11
+ * This module does not look at your process, your packages, your paths or your code, and it
12
+ * never will. There is no scan of `node_modules`, no walk of the module cache, no read of
13
+ * `argv`, no inspection of the process tree — nothing that could turn "which framework is this?"
14
+ * into a report about a customer's machine. Scanning a customer's process and phoning home about
15
+ * what is installed there is a reputational risk we are not taking, and a label we guessed would
16
+ * be worth less than one we were given. We only ever report a label we ship ourselves or one the
17
+ * customer sets on purpose.
18
+ *
19
+ * What is sent: a name, and optionally a version. That is the whole payload.
20
+ *
21
+ * ## Precedence (highest first)
22
+ *
23
+ * 1. `caller` in the client options
24
+ * 2. `setCaller(name, version)`
25
+ * 3. `PROMIGENCE_CALLER` (`name` or `name/version`)
26
+ * 4. the default an adapter package set with `setCaller(name, version, { default: true })`
27
+ * 5. none — and none is the default, so an SDK nobody configured sends no label at all
28
+ *
29
+ * ## Validation
30
+ *
31
+ * `name` must match `^[a-z0-9][a-z0-9._-]{0,31}$` after trimming and lower-casing; `version` must
32
+ * match `^[A-Za-z0-9.+_~-]{0,31}$`. Anything else is dropped silently — an invalid name sends no
33
+ * label, an invalid version sends the name alone. Telemetry never raises, never logs to stdout
34
+ * and never stops a request: the work is what matters, the label is not.
35
+ */
36
+ /** The request header the label rides on. */
37
+ export declare const CALLER_HEADER = "promigence-caller";
38
+ /** `PROMIGENCE_CALLER=harbor` or `PROMIGENCE_CALLER=harbor/0.1.0`. */
39
+ export declare const CALLER_ENV = "PROMIGENCE_CALLER";
40
+ export declare const CALLER_NAME_RE: RegExp;
41
+ export declare const CALLER_VERSION_RE: RegExp;
42
+ export declare const RESERVED_CALLERS: readonly string[];
43
+ /**
44
+ * The token for `name` (+ `version`), or `undefined` when the name is not a valid label.
45
+ * An invalid version is dropped on its own, leaving the name.
46
+ */
47
+ export declare function callerToken(name: string, version?: string): string | undefined;
48
+ /** `harbor` or `harbor/0.1.0` as one string (the env var, the `caller` option). */
49
+ export declare function parseCallerToken(raw: string | undefined): string | undefined;
50
+ /**
51
+ * Name the framework or harness driving this SDK.
52
+ *
53
+ * ```ts
54
+ * import { setCaller } from "promigence";
55
+ * setCaller("my-harness", "2.1.0");
56
+ * ```
57
+ *
58
+ * `{ default: true }` is for a package that ships an integration: it sets the label only for a
59
+ * customer who has not set one of their own, and `PROMIGENCE_CALLER` still wins over it.
60
+ *
61
+ * An unusable name is ignored. This never throws.
62
+ */
63
+ export declare function setCaller(name: string, version?: string, options?: {
64
+ default?: boolean;
65
+ }): void;
66
+ /** The label that would be sent, ignoring any per-client `caller` option. */
67
+ export declare function getCaller(): string | undefined;
68
+ /** Everything unset again (tests). */
69
+ export declare function clearCaller(): void;
70
+ /** The label one client sends: its own option first, then everything `getCaller` considers. */
71
+ export declare function resolveCaller(explicit?: string): string | undefined;
72
+ /** `promigence/0.1.0 node/22.0.0` + ` (harbor/0.1.0)`, when there is a label to add. */
73
+ export declare function userAgentWithCaller(userAgent: string, caller: string | undefined): string;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESERVED_CALLERS = exports.CALLER_VERSION_RE = exports.CALLER_NAME_RE = exports.CALLER_ENV = exports.CALLER_HEADER = void 0;
4
+ exports.callerToken = callerToken;
5
+ exports.parseCallerToken = parseCallerToken;
6
+ exports.setCaller = setCaller;
7
+ exports.getCaller = getCaller;
8
+ exports.clearCaller = clearCaller;
9
+ exports.resolveCaller = resolveCaller;
10
+ exports.userAgentWithCaller = userAgentWithCaller;
11
+ exports.CALLER_HEADER = "promigence-caller";
12
+ exports.CALLER_ENV = "PROMIGENCE_CALLER";
13
+ exports.CALLER_NAME_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
14
+ exports.CALLER_VERSION_RE = /^[A-Za-z0-9.+_~-]{0,31}$/;
15
+ exports.RESERVED_CALLERS = [
16
+ "cli", "harbor", "inspect", "e2b-compat", "computesdk", "mcp",
17
+ ];
18
+ let globalCaller;
19
+ let defaultCaller;
20
+ function callerToken(name, version) {
21
+ const n = typeof name === "string" ? name.trim().toLowerCase() : "";
22
+ if (!exports.CALLER_NAME_RE.test(n))
23
+ return undefined;
24
+ const v = typeof version === "string" ? version.trim() : "";
25
+ if (!v || !exports.CALLER_VERSION_RE.test(v))
26
+ return n;
27
+ return `${n}/${v}`;
28
+ }
29
+ function parseCallerToken(raw) {
30
+ if (typeof raw !== "string")
31
+ return undefined;
32
+ const t = raw.trim();
33
+ if (!t)
34
+ return undefined;
35
+ const slash = t.indexOf("/");
36
+ return slash < 0 ? callerToken(t) : callerToken(t.slice(0, slash), t.slice(slash + 1));
37
+ }
38
+ function setCaller(name, version, options) {
39
+ const token = callerToken(name, version);
40
+ if (options?.default)
41
+ defaultCaller = token;
42
+ else
43
+ globalCaller = token;
44
+ }
45
+ function getCaller() {
46
+ return globalCaller ?? parseCallerToken(process.env[exports.CALLER_ENV]) ?? defaultCaller;
47
+ }
48
+ function clearCaller() {
49
+ globalCaller = undefined;
50
+ defaultCaller = undefined;
51
+ }
52
+ function resolveCaller(explicit) {
53
+ return parseCallerToken(explicit) ?? getCaller();
54
+ }
55
+ function userAgentWithCaller(userAgent, caller) {
56
+ return caller ? `${userAgent} (${caller})` : userAgent;
57
+ }