@dhaneshpurohit/mockstar 0.1.3

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 (156) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/LICENSE +21 -0
  3. package/README.md +260 -0
  4. package/dist/cli/commands/init.d.ts +13 -0
  5. package/dist/cli/commands/init.d.ts.map +1 -0
  6. package/dist/cli/commands/migrate.d.ts +13 -0
  7. package/dist/cli/commands/migrate.d.ts.map +1 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +15076 -0
  11. package/dist/core/config/index.d.ts +5 -0
  12. package/dist/core/config/index.d.ts.map +1 -0
  13. package/dist/core/config/loader.d.ts +14 -0
  14. package/dist/core/config/loader.d.ts.map +1 -0
  15. package/dist/core/config/schema.d.ts +5706 -0
  16. package/dist/core/config/schema.d.ts.map +1 -0
  17. package/dist/core/config/snapshot.d.ts +52 -0
  18. package/dist/core/config/snapshot.d.ts.map +1 -0
  19. package/dist/core/config/watcher.d.ts +13 -0
  20. package/dist/core/config/watcher.d.ts.map +1 -0
  21. package/dist/core/errors/boundary.d.ts +22 -0
  22. package/dist/core/errors/boundary.d.ts.map +1 -0
  23. package/dist/core/errors/index.d.ts +3 -0
  24. package/dist/core/errors/index.d.ts.map +1 -0
  25. package/dist/core/errors/process.d.ts +17 -0
  26. package/dist/core/errors/process.d.ts.map +1 -0
  27. package/dist/core/handlers/index.d.ts +4 -0
  28. package/dist/core/handlers/index.d.ts.map +1 -0
  29. package/dist/core/handlers/registry.d.ts +22 -0
  30. package/dist/core/handlers/registry.d.ts.map +1 -0
  31. package/dist/core/handlers/types.d.ts +42 -0
  32. package/dist/core/handlers/types.d.ts.map +1 -0
  33. package/dist/core/journal/index.d.ts +2 -0
  34. package/dist/core/journal/index.d.ts.map +1 -0
  35. package/dist/core/journal/ring-buffer.d.ts +46 -0
  36. package/dist/core/journal/ring-buffer.d.ts.map +1 -0
  37. package/dist/core/matching/discriminators.d.ts +29 -0
  38. package/dist/core/matching/discriminators.d.ts.map +1 -0
  39. package/dist/core/matching/index.d.ts +24 -0
  40. package/dist/core/matching/index.d.ts.map +1 -0
  41. package/dist/core/matching/path-trie.d.ts +21 -0
  42. package/dist/core/matching/path-trie.d.ts.map +1 -0
  43. package/dist/core/observability/index.d.ts +3 -0
  44. package/dist/core/observability/index.d.ts.map +1 -0
  45. package/dist/core/observability/logger.d.ts +18 -0
  46. package/dist/core/observability/logger.d.ts.map +1 -0
  47. package/dist/core/observability/metrics.d.ts +23 -0
  48. package/dist/core/observability/metrics.d.ts.map +1 -0
  49. package/dist/core/preflight.d.ts +18 -0
  50. package/dist/core/preflight.d.ts.map +1 -0
  51. package/dist/core/scenarios/evaluator.d.ts +52 -0
  52. package/dist/core/scenarios/evaluator.d.ts.map +1 -0
  53. package/dist/core/scenarios/index.d.ts +5 -0
  54. package/dist/core/scenarios/index.d.ts.map +1 -0
  55. package/dist/core/scenarios/merger.d.ts +45 -0
  56. package/dist/core/scenarios/merger.d.ts.map +1 -0
  57. package/dist/core/templating/compiler.d.ts +118 -0
  58. package/dist/core/templating/compiler.d.ts.map +1 -0
  59. package/dist/core/templating/faker.d.ts +14 -0
  60. package/dist/core/templating/faker.d.ts.map +1 -0
  61. package/dist/core/templating/index.d.ts +4 -0
  62. package/dist/core/templating/index.d.ts.map +1 -0
  63. package/dist/core/templating/tier2/id.d.ts +27 -0
  64. package/dist/core/templating/tier2/id.d.ts.map +1 -0
  65. package/dist/core/templating/tier2/index.d.ts +4 -0
  66. package/dist/core/templating/tier2/index.d.ts.map +1 -0
  67. package/dist/core/templating/tier2/now.d.ts +15 -0
  68. package/dist/core/templating/tier2/now.d.ts.map +1 -0
  69. package/dist/core/templating/tier2/walker.d.ts +43 -0
  70. package/dist/core/templating/tier2/walker.d.ts.map +1 -0
  71. package/dist/core/tenancy/extractor.d.ts +20 -0
  72. package/dist/core/tenancy/extractor.d.ts.map +1 -0
  73. package/dist/core/tenancy/index.d.ts +2 -0
  74. package/dist/core/tenancy/index.d.ts.map +1 -0
  75. package/dist/features/admin/auth.d.ts +19 -0
  76. package/dist/features/admin/auth.d.ts.map +1 -0
  77. package/dist/features/admin/endpoints.d.ts +21 -0
  78. package/dist/features/admin/endpoints.d.ts.map +1 -0
  79. package/dist/features/admin/index.d.ts +3 -0
  80. package/dist/features/admin/index.d.ts.map +1 -0
  81. package/dist/features/dynamic-mock.d.ts +16 -0
  82. package/dist/features/dynamic-mock.d.ts.map +1 -0
  83. package/dist/features/enhance/boundary.d.ts +26 -0
  84. package/dist/features/enhance/boundary.d.ts.map +1 -0
  85. package/dist/features/enhance/field-mapping.d.ts +23 -0
  86. package/dist/features/enhance/field-mapping.d.ts.map +1 -0
  87. package/dist/features/enhance/index.d.ts +21 -0
  88. package/dist/features/enhance/index.d.ts.map +1 -0
  89. package/dist/features/openapi/converter.d.ts +55 -0
  90. package/dist/features/openapi/converter.d.ts.map +1 -0
  91. package/dist/features/openapi/importer.d.ts +11 -0
  92. package/dist/features/openapi/importer.d.ts.map +1 -0
  93. package/dist/features/openapi/index.d.ts +3 -0
  94. package/dist/features/openapi/index.d.ts.map +1 -0
  95. package/dist/features/pass-through.d.ts +9 -0
  96. package/dist/features/pass-through.d.ts.map +1 -0
  97. package/dist/features/proxy/ca.d.ts +49 -0
  98. package/dist/features/proxy/ca.d.ts.map +1 -0
  99. package/dist/features/proxy/cert-cache.d.ts +34 -0
  100. package/dist/features/proxy/cert-cache.d.ts.map +1 -0
  101. package/dist/features/proxy/cli.d.ts +2 -0
  102. package/dist/features/proxy/cli.d.ts.map +1 -0
  103. package/dist/features/proxy/config.d.ts +71 -0
  104. package/dist/features/proxy/config.d.ts.map +1 -0
  105. package/dist/features/proxy/dns.d.ts +18 -0
  106. package/dist/features/proxy/dns.d.ts.map +1 -0
  107. package/dist/features/proxy/env-detector.d.ts +7 -0
  108. package/dist/features/proxy/env-detector.d.ts.map +1 -0
  109. package/dist/features/proxy/index.d.ts +15 -0
  110. package/dist/features/proxy/index.d.ts.map +1 -0
  111. package/dist/features/proxy/install-journal.d.ts +51 -0
  112. package/dist/features/proxy/install-journal.d.ts.map +1 -0
  113. package/dist/features/proxy/port-bind.d.ts +33 -0
  114. package/dist/features/proxy/port-bind.d.ts.map +1 -0
  115. package/dist/features/proxy/server.d.ts +19 -0
  116. package/dist/features/proxy/server.d.ts.map +1 -0
  117. package/dist/features/proxy/sni-gate.d.ts +17 -0
  118. package/dist/features/proxy/sni-gate.d.ts.map +1 -0
  119. package/dist/features/proxy/tls-adapter.d.ts +52 -0
  120. package/dist/features/proxy/tls-adapter.d.ts.map +1 -0
  121. package/dist/features/proxy/types.d.ts +103 -0
  122. package/dist/features/proxy/types.d.ts.map +1 -0
  123. package/dist/features/proxy/upstream.d.ts +23 -0
  124. package/dist/features/proxy/upstream.d.ts.map +1 -0
  125. package/dist/features/spec/index.d.ts +17 -0
  126. package/dist/features/spec/index.d.ts.map +1 -0
  127. package/dist/features/static-mock.d.ts +23 -0
  128. package/dist/features/static-mock.d.ts.map +1 -0
  129. package/dist/features/url-validator.d.ts +53 -0
  130. package/dist/features/url-validator.d.ts.map +1 -0
  131. package/dist/features/webhooks/circuit-breaker.d.ts +49 -0
  132. package/dist/features/webhooks/circuit-breaker.d.ts.map +1 -0
  133. package/dist/features/webhooks/compile.d.ts +16 -0
  134. package/dist/features/webhooks/compile.d.ts.map +1 -0
  135. package/dist/features/webhooks/dispatcher.d.ts +45 -0
  136. package/dist/features/webhooks/dispatcher.d.ts.map +1 -0
  137. package/dist/features/webhooks/event-registry.d.ts +36 -0
  138. package/dist/features/webhooks/event-registry.d.ts.map +1 -0
  139. package/dist/features/webhooks/index.d.ts +13 -0
  140. package/dist/features/webhooks/index.d.ts.map +1 -0
  141. package/dist/features/webhooks/journal.d.ts +32 -0
  142. package/dist/features/webhooks/journal.d.ts.map +1 -0
  143. package/dist/features/webhooks/queue.d.ts +93 -0
  144. package/dist/features/webhooks/queue.d.ts.map +1 -0
  145. package/dist/features/webhooks/signing.d.ts +35 -0
  146. package/dist/features/webhooks/signing.d.ts.map +1 -0
  147. package/dist/features/webhooks/types.d.ts +96 -0
  148. package/dist/features/webhooks/types.d.ts.map +1 -0
  149. package/dist/index.d.ts +30 -0
  150. package/dist/index.d.ts.map +1 -0
  151. package/dist/index.js +12813 -0
  152. package/dist/server.d.ts +62 -0
  153. package/dist/server.d.ts.map +1 -0
  154. package/dist/version.d.ts +2 -0
  155. package/dist/version.d.ts.map +1 -0
  156. package/package.json +62 -0
@@ -0,0 +1,34 @@
1
+ import type { Hostname, LeafCert, ProxyConfig, ProxySnapshot } from "./types.ts";
2
+ export declare class SnapshotHolder {
3
+ #private;
4
+ constructor(initial: ProxySnapshot);
5
+ /** Atomic reader: callers capture this once per connection (RT-4.2). */
6
+ get(): ProxySnapshot;
7
+ /**
8
+ * Pointer-swap. Returns (previous, next) so the caller can diff and drive
9
+ * forced-close on evicted hostnames.
10
+ */
11
+ swap(next: ProxySnapshot): {
12
+ previous: ProxySnapshot;
13
+ next: ProxySnapshot;
14
+ };
15
+ }
16
+ /**
17
+ * Build an initial snapshot from config: generates leaves for every configured host.
18
+ * Called once at startup; re-called on reload to build the next snapshot.
19
+ */
20
+ export declare function buildSnapshot(config: ProxyConfig, options: {
21
+ version: number;
22
+ previous?: ProxySnapshot;
23
+ }): Promise<ProxySnapshot>;
24
+ /**
25
+ * Given two snapshots, return the set of hostnames present in `previous` but not in `next`.
26
+ * Used by the reload orchestrator to force-close connections on evicted hostnames (RT-4.3).
27
+ */
28
+ export declare function evictedHostnames(previous: ProxySnapshot, next: ProxySnapshot): Set<Hostname>;
29
+ /**
30
+ * Is the given leaf due for renewal soon? Returns true when expiry is within
31
+ * the refresh window (default: 1 hour). Used by a background refresh task.
32
+ */
33
+ export declare function needsRefresh(leaf: LeafCert, windowMs?: number): boolean;
34
+ //# sourceMappingURL=cert-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cert-cache.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/cert-cache.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAc,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI7F,qBAAa,cAAc;;gBAGb,OAAO,EAAE,aAAa;IAIlC,wEAAwE;IACxE,GAAG,IAAI,aAAa;IAIpB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,aAAa,GAAG;QAAE,QAAQ,EAAE,aAAa,CAAC;QAAC,IAAI,EAAE,aAAa,CAAA;KAAE;CAK5E;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,GACrD,OAAO,CAAC,aAAa,CAAC,CA0CxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,GAAG,GAAG,CAAC,QAAQ,CAAC,CAc5F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,SAAc,GAAG,OAAO,CAE5E"}
@@ -0,0 +1,2 @@
1
+ export declare function dispatchProxyCommand(argv: readonly string[]): Promise<number>;
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/cli.ts"],"names":[],"mappings":"AAoCA,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAqBnF"}
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ import type { ProxyConfig } from "./types.ts";
3
+ export declare const HostConfigSchema: z.ZodObject<{
4
+ host: z.ZodString;
5
+ tenant: z.ZodString;
6
+ }, "strict", z.ZodTypeAny, {
7
+ host: string;
8
+ tenant: string;
9
+ }, {
10
+ host: string;
11
+ tenant: string;
12
+ }>;
13
+ export declare const ProxyConfigSchema: z.ZodObject<{
14
+ hosts: z.ZodArray<z.ZodObject<{
15
+ host: z.ZodString;
16
+ tenant: z.ZodString;
17
+ }, "strict", z.ZodTypeAny, {
18
+ host: string;
19
+ tenant: string;
20
+ }, {
21
+ host: string;
22
+ tenant: string;
23
+ }>, "many">;
24
+ mockstarUrl: z.ZodDefault<z.ZodString>;
25
+ listenHost: z.ZodDefault<z.ZodString>;
26
+ listenPort: z.ZodDefault<z.ZodNumber>;
27
+ upstreamTimeoutMs: z.ZodDefault<z.ZodNumber>;
28
+ leafTtlHours: z.ZodDefault<z.ZodNumber>;
29
+ dnsMode: z.ZodDefault<z.ZodEnum<["dnsmasq", "hosts-fallback"]>>;
30
+ }, "strict", z.ZodTypeAny, {
31
+ hosts: {
32
+ host: string;
33
+ tenant: string;
34
+ }[];
35
+ mockstarUrl: string;
36
+ listenHost: string;
37
+ listenPort: number;
38
+ upstreamTimeoutMs: number;
39
+ leafTtlHours: number;
40
+ dnsMode: "dnsmasq" | "hosts-fallback";
41
+ }, {
42
+ hosts: {
43
+ host: string;
44
+ tenant: string;
45
+ }[];
46
+ mockstarUrl?: string | undefined;
47
+ listenHost?: string | undefined;
48
+ listenPort?: number | undefined;
49
+ upstreamTimeoutMs?: number | undefined;
50
+ leafTtlHours?: number | undefined;
51
+ dnsMode?: "dnsmasq" | "hosts-fallback" | undefined;
52
+ }>;
53
+ export type ProxyConfigInput = z.input<typeof ProxyConfigSchema>;
54
+ export declare function loadConfigFile(path: string): Promise<ProxyConfig>;
55
+ export declare function parseConfig(obj: unknown): ProxyConfig;
56
+ /**
57
+ * Watch the config file for changes and invoke `onChange` with the new config.
58
+ * If parsing fails, `onChange` is NOT called (warn-and-keep-previous per mockstar T7 pattern).
59
+ */
60
+ export declare function watchConfig(path: string, onChange: (result: {
61
+ ok: true;
62
+ config: ProxyConfig;
63
+ } | {
64
+ ok: false;
65
+ error: string;
66
+ }) => void, opts?: {
67
+ debounceMs?: number;
68
+ }): Promise<{
69
+ stop: () => void;
70
+ }>;
71
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQ9C,eAAO,MAAM,gBAAgB;;;;;;;;;EAKlB,CAAC;AAEZ,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUnB,CAAC;AAEZ,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAIjE,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAIvE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAErD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,EAC5F,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACjC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC,CA6B/B"}
@@ -0,0 +1,18 @@
1
+ import { join } from "node:path";
2
+ import type { Mutation } from "./install-journal.ts";
3
+ import type { ProxyConfig } from "./types.ts";
4
+ export declare const HOSTS_BLOCK_MARKER = "# BEGIN mockstar-proxy (do not edit)";
5
+ export declare const HOSTS_BLOCK_END = "# END mockstar-proxy";
6
+ export declare const HOSTS_PATH = "/etc/hosts";
7
+ /**
8
+ * Build the install mutation(s) for DNS. Depending on mode, produces either:
9
+ * - dnsmasq config + resolver files + service registration
10
+ * - /etc/hosts block append
11
+ */
12
+ export declare function buildDnsMutations(config: ProxyConfig): Promise<Mutation[]>;
13
+ /** Reverse a hosts-fallback block. Used by install-journal's reverse_hosts_entries handler. */
14
+ export declare function revertHostsBlock(marker: string): Promise<void>;
15
+ /** Stop and remove the dnsmasq service installed by buildDnsmasqMutations. */
16
+ export declare function stopAndRemoveDnsmasq(): Promise<void>;
17
+ export { join };
18
+ //# sourceMappingURL=dns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dns.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/dns.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAc,WAAW,EAAkB,MAAM,YAAY,CAAC;AAK1E,eAAO,MAAM,kBAAkB,yCAAyC,CAAC;AACzE,eAAO,MAAM,eAAe,yBAAyB,CAAC;AACtD,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAKhF;AAED,+FAA+F;AAC/F,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpE;AAED,8EAA8E;AAC9E,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAW1D;AAyHD,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { EnvHostility } from "./types.ts";
2
+ export declare function detectEnvHostility(): Promise<EnvHostility>;
3
+ /**
4
+ * Map an EnvHostility result to a specific remediation message. (RT-10.2)
5
+ */
6
+ export declare function remediationMessage(h: EnvHostility): string;
7
+ //# sourceMappingURL=env-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-detector.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/env-detector.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CAqBhE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CAa1D"}
@@ -0,0 +1,15 @@
1
+ export { caFacts, resolveCaPaths, installCa, uninstallCa, enforceKeyPermissions, nodeExtraCaCertsMessage, scopedCommonName, generateLeaf, } from "./ca.ts";
2
+ export { loadConfigFile, parseConfig, watchConfig, ProxyConfigSchema } from "./config.ts";
3
+ export { SnapshotHolder, buildSnapshot, evictedHostnames, needsRefresh } from "./cert-cache.ts";
4
+ export { sniGate, explainSni } from "./sni-gate.ts";
5
+ export { forwardToMockstar, probeMockstarHealth } from "./upstream.ts";
6
+ export { startTlsServer, bunVersion, snapshotResolver, listenParams, leavesFromSnapshot, } from "./tls-adapter.ts";
7
+ export type { TlsLeaf, TlsServerHandle, TlsServerOptions, RequestMeta } from "./tls-adapter.ts";
8
+ export { startProxyServer, type ProxyRuntime, type StartOptions } from "./server.ts";
9
+ export { detectEnvHostility, remediationMessage } from "./env-detector.ts";
10
+ export { portBindMutation, isPlatformSupported, runPrivileged } from "./port-bind.ts";
11
+ export { appendStep, readJournal, reverseSteps, clearJournal, journalFacts, atomicInstall, executeReverse, type Mutation, } from "./install-journal.ts";
12
+ export { buildDnsMutations, revertHostsBlock, stopAndRemoveDnsmasq, HOSTS_BLOCK_MARKER, HOSTS_BLOCK_END, } from "./dns.ts";
13
+ export type { ProxyConfig, HostConfig, LeafCert, ProxySnapshot, EnvHostility, InstallStep, ReverseCommand, } from "./types.ts";
14
+ export { ProxyError } from "./types.ts";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,KAAK,QAAQ,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,51 @@
1
+ import type { InstallStep, ReverseCommand } from "./types.ts";
2
+ export interface JournalFacts {
3
+ readonly path: string;
4
+ readonly exists: boolean;
5
+ readonly stepCount: number;
6
+ readonly lastStep?: InstallStep;
7
+ readonly corrupt: boolean;
8
+ }
9
+ /**
10
+ * Append a single step. Computes the checksum and writes the line + newline.
11
+ * The write is flushed before returning so a crash after append doesn't lose the record.
12
+ */
13
+ export declare function appendStep(path: string, step: Omit<InstallStep, "step" | "timestamp" | "checksum">): Promise<InstallStep>;
14
+ /** Read the full journal. Throws if any line is corrupt (checksum mismatch). */
15
+ export declare function readJournal(path: string): Promise<InstallStep[]>;
16
+ /**
17
+ * LIFO walk: for each recorded step (newest first), yield the reverse command for
18
+ * the caller to execute. Once a reverse succeeds the caller should call
19
+ * {@link markReversed} — we track this by rewriting the journal atomically on completion.
20
+ *
21
+ * The journal file itself is removed after a successful uninstall (every step reversed).
22
+ */
23
+ export declare function reverseSteps(path: string): AsyncIterable<InstallStep>;
24
+ /**
25
+ * Called by the caller after every step has been successfully reversed (or explicitly skipped).
26
+ * Removes the journal file entirely — uninstall is complete.
27
+ */
28
+ export declare function clearJournal(path: string): Promise<void>;
29
+ /** Produce a JournalFacts summary for `mockstar proxy status`. */
30
+ export declare function journalFacts(path: string): Promise<JournalFacts>;
31
+ /**
32
+ * Execute the atomic-install wrapper. Caller passes a list of mutations, each with
33
+ * an apply fn + a reverse command. If any mutation throws, previously-succeeded
34
+ * steps are reversed in LIFO order. Journal is written after every successful apply.
35
+ */
36
+ export declare function atomicInstall(journalPath: string, mutations: readonly Mutation[], options?: {
37
+ onStep?: (step: InstallStep) => void;
38
+ }): Promise<{
39
+ applied: InstallStep[];
40
+ }>;
41
+ export interface Mutation {
42
+ readonly action: string;
43
+ readonly reverseCommand: ReverseCommand;
44
+ apply(): Promise<void>;
45
+ }
46
+ /**
47
+ * Execute a single reverse command. Used by atomicInstall's rollback path and by
48
+ * `mockstar proxy uninstall`. Each handler is idempotent — re-running is a no-op.
49
+ */
50
+ export declare function executeReverse(cmd: ReverseCommand): Promise<void>;
51
+ //# sourceMappingURL=install-journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-journal.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/install-journal.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,GACzD,OAAO,CAAC,WAAW,CAAC,CAuBtB;AAED,gFAAgF;AAChF,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAEtE;AAED;;;;;;GAMG;AACH,wBAAuB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAM5E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED,kEAAkE;AAClE,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAoBtE;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAA;CAAO,GACrD,OAAO,CAAC;IAAE,OAAO,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,CA8BrC;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CASvE"}
@@ -0,0 +1,33 @@
1
+ import { type ReverseCommand } from "./types.ts";
2
+ export interface PortBindMutation {
3
+ /** Human-readable description for the install journal. */
4
+ readonly action: string;
5
+ /** The reverse command recorded in the journal for uninstall. */
6
+ readonly reverseCommand: ReverseCommand;
7
+ apply(): Promise<void>;
8
+ }
9
+ /**
10
+ * Produce a mutation that grants the running binary cap_net_bind_service (Linux)
11
+ * or configures launchd to socket-activate on port 443 (macOS). Idempotent: re-running
12
+ * is safe.
13
+ *
14
+ * @param binaryPath The absolute path to the mockstar binary (or the Bun binary when
15
+ * running from source). On Linux, setcap is applied to this path.
16
+ */
17
+ export declare function portBindMutation(params: {
18
+ binaryPath: string;
19
+ plistPath?: string;
20
+ launchdLabel?: string;
21
+ }): PortBindMutation;
22
+ /**
23
+ * Spawn a process via `sudo` (macOS/Linux). Used by install mutations that require
24
+ * elevated privileges. The user sees the OS password prompt.
25
+ */
26
+ export declare function runPrivileged(argv: readonly string[]): Promise<{
27
+ exitCode: number;
28
+ stdout: string;
29
+ stderr: string;
30
+ }>;
31
+ /** Does the host OS support our port-443 binding strategy? */
32
+ export declare function isPlatformSupported(): boolean;
33
+ //# sourceMappingURL=port-bind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port-bind.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/port-bind.ts"],"names":[],"mappings":"AAaA,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAI7D,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,gBAAgB,CAgBnB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAE/D;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,IAAI,OAAO,CAG7C"}
@@ -0,0 +1,19 @@
1
+ import { Metrics, type StructuredLogger } from "../../core/observability/index.ts";
2
+ import { SnapshotHolder } from "./cert-cache.ts";
3
+ import { type TlsServerHandle } from "./tls-adapter.ts";
4
+ import type { ProxyConfig } from "./types.ts";
5
+ export interface ProxyRuntime {
6
+ readonly server: TlsServerHandle;
7
+ readonly holder: SnapshotHolder;
8
+ readonly metrics: Metrics;
9
+ readonly logger: StructuredLogger;
10
+ readonly stop: () => Promise<void>;
11
+ }
12
+ export interface StartOptions {
13
+ configPath: string;
14
+ config: ProxyConfig;
15
+ logger?: StructuredLogger;
16
+ watch?: boolean;
17
+ }
18
+ export declare function startProxyServer(opts: StartOptions): Promise<ProxyRuntime>;
19
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/server.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,cAAc,EAAmC,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAoB,KAAK,eAAe,EAAsC,MAAM,kBAAkB,CAAC;AAC9G,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,YAAY,CAAC;AAGxD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAuDhF"}
@@ -0,0 +1,17 @@
1
+ import type { SnapshotHolder } from "./cert-cache.ts";
2
+ import { type SniResolver } from "./tls-adapter.ts";
3
+ /**
4
+ * Build an SniResolver that ALWAYS reads the current snapshot (captured per-call,
5
+ * not per-closure-build). This keeps it safe to pass to the TLS adapter and have
6
+ * it reflect reloads.
7
+ */
8
+ export declare function sniGate(holder: SnapshotHolder): SniResolver;
9
+ /**
10
+ * For diagnostics: given a hostname and the current snapshot, explain why
11
+ * we'd accept or reject. Useful for `mockstar proxy status --explain-sni`.
12
+ */
13
+ export declare function explainSni(holder: SnapshotHolder, servername: string): {
14
+ accepted: boolean;
15
+ reason: string;
16
+ };
17
+ //# sourceMappingURL=sni-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sni-gate.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/sni-gate.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,kBAAkB,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAK3D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,GACjB;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CA0BvC"}
@@ -0,0 +1,52 @@
1
+ import type { ProxyConfig, ProxySnapshot } from "./types.ts";
2
+ export interface TlsLeaf {
3
+ readonly serverName: string;
4
+ readonly certPem: string;
5
+ readonly keyPem: string;
6
+ }
7
+ export interface TlsServerOptions {
8
+ readonly hostname: string;
9
+ readonly port: number;
10
+ /** Initial list of {serverName, cert, key} triples. Use reload() to change. */
11
+ readonly leaves: readonly TlsLeaf[];
12
+ /** HTTP request handler invoked after TLS termination. */
13
+ readonly handle: (req: Request, meta: RequestMeta) => Promise<Response>;
14
+ /** Non-fatal diagnostics sink. */
15
+ readonly onWarn?: (event: string, details: Record<string, unknown>) => void;
16
+ }
17
+ /**
18
+ * A leaf-resolution closure: maps an SNI servername to the cert/key pair to present,
19
+ * or null to reject. NOT consumed by Bun (Bun does its own SNI); used by sni-gate's
20
+ * diagnostics and the gate closure that reads the current snapshot per-call.
21
+ */
22
+ export type SniResolver = (servername: string) => {
23
+ certPem: string;
24
+ keyPem: string;
25
+ } | null;
26
+ export interface RequestMeta {
27
+ /** Hostname from the request URL (already validated by SNI match). */
28
+ readonly servername: string;
29
+ /** Monotonic connection id for log correlation. */
30
+ readonly connectionId: string;
31
+ }
32
+ export interface TlsServerHandle {
33
+ readonly url: string;
34
+ stop(): Promise<void>;
35
+ /** Atomic swap of the TLS config with a new leaf set (RT-4 / TN5). */
36
+ reload(nextLeaves: readonly TlsLeaf[]): Promise<void>;
37
+ /** Close active connections matching a predicate (RT-4.3 forced eviction). */
38
+ closeWhere(predicate: (meta: RequestMeta) => boolean): Promise<void>;
39
+ }
40
+ export declare function startTlsServer(opts: TlsServerOptions): Promise<TlsServerHandle>;
41
+ /** Return the Bun version string, or null when not on Bun. */
42
+ export declare function bunVersion(): string | null;
43
+ /** Translate a ProxySnapshot into the TlsLeaf[] the adapter consumes. */
44
+ export declare function leavesFromSnapshot(snapshot: ProxySnapshot): TlsLeaf[];
45
+ /** Resolver closure used by sni-gate's diagnostics (NOT by Bun — Bun does its own SNI). */
46
+ export declare function snapshotResolver(snapshot: ProxySnapshot): SniResolver;
47
+ /** Normalise a ProxyConfig into listen-parameters consumed by the adapter. */
48
+ export declare function listenParams(config: ProxyConfig): {
49
+ hostname: string;
50
+ port: number;
51
+ };
52
+ //# sourceMappingURL=tls-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tls-adapter.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/tls-adapter.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI7D,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,I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AE,aAAa,GAAG,OAAO,EAAE,CAMrE;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,GAAG,WAAW,CAMrE;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAEpF"}
@@ -0,0 +1,103 @@
1
+ export type TenantName = string;
2
+ export type Hostname = string;
3
+ export interface HostConfig {
4
+ /** Real hostname to intercept, e.g. "api.razorpay.com". */
5
+ readonly host: Hostname;
6
+ /** Mockstar tenant this hostname maps to. */
7
+ readonly tenant: TenantName;
8
+ }
9
+ export interface ProxyConfig {
10
+ /** The ordered list of hostnames this proxy accepts + the tenant each maps to. */
11
+ readonly hosts: readonly HostConfig[];
12
+ /** Upstream mockstar URL (HTTP). Default http://127.0.0.1:3000. */
13
+ readonly mockstarUrl: string;
14
+ /** Listen host (must be 127.0.0.1 per S2). */
15
+ readonly listenHost: string;
16
+ /** Listen port (443 per RT-6). */
17
+ readonly listenPort: number;
18
+ /** Upstream request timeout in ms (T10). */
19
+ readonly upstreamTimeoutMs: number;
20
+ /** Leaf cert TTL in hours (RT-4.1; 24 per TN4). */
21
+ readonly leafTtlHours: number;
22
+ /** DNS strategy — set by env detection at install time. */
23
+ readonly dnsMode: "dnsmasq" | "hosts-fallback";
24
+ }
25
+ export interface LeafCert {
26
+ readonly host: Hostname;
27
+ /** PEM-encoded cert. */
28
+ readonly certPem: string;
29
+ /** PEM-encoded key. */
30
+ readonly keyPem: string;
31
+ /** Unix-ms of NotAfter. */
32
+ readonly expiresAt: number;
33
+ /** Snapshot version that issued this cert (RT-4.2). */
34
+ readonly snapshotVersion: number;
35
+ }
36
+ export interface ProxySnapshot {
37
+ readonly version: number;
38
+ readonly hosts: ReadonlyMap<Hostname, HostConfig>;
39
+ readonly leaves: ReadonlyMap<Hostname, LeafCert>;
40
+ readonly config: ProxyConfig;
41
+ }
42
+ export type EnvHostility = {
43
+ kind: "clean";
44
+ } | {
45
+ kind: "mdm-managed";
46
+ detail: string;
47
+ } | {
48
+ kind: "vpn-resolver-override";
49
+ detail: string;
50
+ } | {
51
+ kind: "port-443-bound";
52
+ detail: string;
53
+ } | {
54
+ kind: "containerized-or-ci";
55
+ detail: string;
56
+ };
57
+ /** A single recorded mutation in the install journal (RT-7). */
58
+ export interface InstallStep {
59
+ readonly step: number;
60
+ readonly timestamp: string;
61
+ readonly action: string;
62
+ readonly reverseCommand: ReverseCommand;
63
+ /** SHA-256 of {step, timestamp, action, reverseCommand} JSON. */
64
+ readonly checksum: string;
65
+ }
66
+ /**
67
+ * A reverse command is a structured, replayable instruction.
68
+ * We deliberately avoid embedding literal shell strings so we can sanitise
69
+ * arguments at replay time and because shell quoting is a footgun.
70
+ */
71
+ export type ReverseCommand = {
72
+ kind: "mkcert_uninstall";
73
+ } | {
74
+ kind: "remove_file";
75
+ path: string;
76
+ } | {
77
+ kind: "remove_dir";
78
+ path: string;
79
+ } | {
80
+ kind: "revert_file";
81
+ path: string;
82
+ originalContent: string;
83
+ } | {
84
+ kind: "dnsmasq_stop_and_remove";
85
+ } | {
86
+ kind: "revert_hosts_entries";
87
+ blockMarker: string;
88
+ } | {
89
+ kind: "setcap_drop";
90
+ path: string;
91
+ } | {
92
+ kind: "launchctl_unload_and_remove";
93
+ plistPath: string;
94
+ } | {
95
+ kind: "noop";
96
+ reason: string;
97
+ };
98
+ export declare class ProxyError extends Error {
99
+ readonly code: string;
100
+ readonly hint?: string | undefined;
101
+ constructor(message: string, code: string, hint?: string | undefined);
102
+ }
103
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/types.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MA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AM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,qBAAa,UAAW,SAAQ,KAAK;aAGjB,IAAI,EAAE,MAAM;aACZ,IAAI,CAAC,EAAE,MAAM;gBAF7B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,YAAA;CAKhC"}
@@ -0,0 +1,23 @@
1
+ import type { LogFields } from "../../core/observability/index.ts";
2
+ import type { HostConfig, ProxyConfig } from "./types.ts";
3
+ export interface ForwardContext {
4
+ readonly config: ProxyConfig;
5
+ readonly host: HostConfig;
6
+ readonly requestId: string;
7
+ readonly logger: {
8
+ info: (fields: LogFields) => void;
9
+ error: (fields: LogFields) => void;
10
+ };
11
+ }
12
+ /**
13
+ * Forward the incoming request to mockstar. Preserves method, path, query, headers,
14
+ * and body. Injects `X-Mockstar-Tenant` + `X-Mockstar-Proxy-Request-Id`. Strips
15
+ * hop-by-hop headers.
16
+ *
17
+ * Returns a 502 with a structured diagnostic body when the upstream is unreachable
18
+ * or times out. Never leaks stack traces.
19
+ */
20
+ export declare function forwardToMockstar(req: Request, ctx: ForwardContext): Promise<Response>;
21
+ /** One-shot health probe. Returns true if mockstar's /health endpoint responds with 200. */
22
+ export declare function probeMockstarHealth(config: ProxyConfig, timeoutMs?: number): Promise<boolean>;
23
+ //# sourceMappingURL=upstream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream.d.ts","sourceRoot":"","sources":["../../../src/features/proxy/upstream.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE;QACf,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;QAClC,KAAK,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;KACpC,CAAC;CACH;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6D5F;AAED,4FAA4F;AAC5F,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAYjG"}
@@ -0,0 +1,17 @@
1
+ export type SpecFormat = "openapi" | "postman" | "unknown";
2
+ export interface ParsedSpec {
3
+ format: SpecFormat;
4
+ /** Flat index: method+path → property names (best-effort name-hint source). */
5
+ fieldsByEndpoint: Map<string, Set<string>>;
6
+ /** Detected provider tag (used ONLY for fixture organisation — never leaks into core code). */
7
+ providerTag: string | null;
8
+ /** Source spec for consumers that want deeper schema inspection. */
9
+ raw: unknown;
10
+ }
11
+ /**
12
+ * Load and index a spec file. Intentionally lightweight: the enhancer uses this only to harvest
13
+ * FIELD NAMES for its name-match heuristic. Complex schema traversal / ref resolution is out of
14
+ * scope — the enhancer falls back to literal field-value inspection if a name isn't in the index.
15
+ */
16
+ export declare function loadSpec(path: string): Promise<ParsedSpec>;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/spec/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,+EAA+E;IAC/E,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,+FAA+F;IAC/F,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,oEAAoE;IACpE,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMhE"}
@@ -0,0 +1,23 @@
1
+ import type { Context } from "hono";
2
+ import type { Entry } from "../core/config/schema.ts";
3
+ import type { CompiledResponse } from "../core/templating/compiler.ts";
4
+ import type { FakerInstance } from "../core/templating/faker.ts";
5
+ import type { Clock } from "../core/templating/tier2/now.ts";
6
+ export interface StaticRenderInput {
7
+ entry: Entry;
8
+ compiled: CompiledResponse;
9
+ ctx: Context;
10
+ params: Record<string, string>;
11
+ faker: FakerInstance;
12
+ tenant: string;
13
+ requestId: string;
14
+ body: unknown;
15
+ /** Injected clock — wall in prod, fixed-epoch in deterministic mode. */
16
+ clock: Clock;
17
+ /** Deterministic mode flag — when true, idHelpers use a seeded PRNG. */
18
+ deterministic: boolean;
19
+ /** Optional response-body byte cap. Defaults to RenderBudget's own default (1 MB). */
20
+ maxResponseBytes?: number;
21
+ }
22
+ export declare function renderStatic(input: StaticRenderInput): Promise<Response>;
23
+ //# sourceMappingURL=static-mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-mock.d.ts","sourceRoot":"","sources":["../../src/features/static-mock.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,gCAAgC,CAAC;AAExF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAG7D,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,wEAAwE;IACxE,KAAK,EAAE,KAAK,CAAC;IACb,wEAAwE;IACxE,aAAa,EAAE,OAAO,CAAC;IACvB,sFAAsF;IACtF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmE9E"}
@@ -0,0 +1,53 @@
1
+ export interface UrlValidationOptions {
2
+ /** Allowed schemes. Default: ['https']. */
3
+ allowedSchemes?: readonly string[];
4
+ /** Allow local/private network targets when explicitly opted in. Default: false. */
5
+ allowPrivateUpstreams?: boolean;
6
+ }
7
+ /**
8
+ * Resolve a hostname to its IP addresses (A + AAAA). Returns address strings.
9
+ * Injectable so the DNS-resolution guard can be tested offline/deterministically.
10
+ */
11
+ export type DnsLookup = (hostname: string) => Promise<string[]>;
12
+ export interface ResolvedValidationOptions extends UrlValidationOptions {
13
+ /** Override DNS resolution (tests). Default: node:dns/promises lookup, A + AAAA. */
14
+ lookup?: DnsLookup;
15
+ }
16
+ export declare class UrlValidationError extends Error {
17
+ readonly url: string;
18
+ readonly reason: string;
19
+ constructor(url: string, reason: string);
20
+ }
21
+ /**
22
+ * Validate an URL for use as a pass-through upstream or OpenAPI `servers.url`.
23
+ * Enforces S6's scheme allowlist + private-range rejection by default.
24
+ *
25
+ * Throws `UrlValidationError` on failure. Returns the parsed URL on success.
26
+ */
27
+ export declare function validateUpstreamUrl(raw: string, opts?: UrlValidationOptions): URL;
28
+ /**
29
+ * Close the DNS-resolution SSRF gap (F1): a public hostname can have an A/AAAA
30
+ * record pointing at a private/loopback/link-local/metadata IP, which the
31
+ * synchronous string-level guard cannot see. Resolve the hostname and reject if
32
+ * ANY resolved address is private. Fails closed on resolution errors.
33
+ *
34
+ * Note: resolution happens microseconds before the caller's fetch, so a narrow
35
+ * DNS-rebinding (TOCTOU) window remains — the resolver here and the kernel
36
+ * resolver used by fetch() are queried separately. For an OSS dev tool with
37
+ * operator-authored upstreams this residual window is accepted; full closure
38
+ * would require pinning the validated IP into the socket connect.
39
+ */
40
+ export declare function assertResolvedHostPublic(parsed: URL, opts?: {
41
+ allowPrivateUpstreams?: boolean;
42
+ lookup?: DnsLookup;
43
+ }): Promise<void>;
44
+ /**
45
+ * Full upstream validation for the request/delivery path: the synchronous
46
+ * string-level checks (scheme allowlist + private IP-literal rejection) PLUS
47
+ * DNS resolution of the hostname with private-range rejection of every resolved
48
+ * address (F1). Use this at the point of fetch; use the synchronous
49
+ * `validateUpstreamUrl` for config-load-time checks where DNS is undesirable.
50
+ */
51
+ export declare function validateUpstreamUrlResolved(raw: string, opts?: ResolvedValidationOptions): Promise<URL>;
52
+ export declare function isPrivateHost(hostname: string): boolean;
53
+ //# sourceMappingURL=url-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-validator.d.ts","sourceRoot":"","sources":["../../src/features/url-validator.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,oFAAoF;IACpF,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAEhE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,oFAAoF;IACpF,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,qBAAa,kBAAmB,SAAQ,KAAK;aAEzB,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,MAAM;gBADd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM;CAKjC;AAYD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,oBAAyB,GAAG,GAAG,CA8BrF;AAeD;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,GAAG,EACX,IAAI,GAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,CAAA;CAAO,GACjE,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAED;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,yBAA8B,GACnC,OAAO,CAAC,GAAG,CAAC,CAOd;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAyCvD"}