alpic 0.0.0-staging.dfd352e → 0.0.0-staging.e051bb2

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 (296) hide show
  1. package/README.md +72 -0
  2. package/bin/run.js +5 -0
  3. package/dist/__tests__/alpic-command.test.d.ts +1 -0
  4. package/dist/__tests__/alpic-command.test.js +41 -0
  5. package/dist/__tests__/alpic-command.test.js.map +1 -0
  6. package/dist/__tests__/audit.e2e.test.d.ts +1 -0
  7. package/dist/__tests__/audit.e2e.test.js +764 -0
  8. package/dist/__tests__/audit.e2e.test.js.map +1 -0
  9. package/dist/__tests__/auth.e2e.test.d.ts +1 -0
  10. package/dist/__tests__/auth.e2e.test.js +162 -0
  11. package/dist/__tests__/auth.e2e.test.js.map +1 -0
  12. package/dist/__tests__/deploy-flags.e2e.test.d.ts +1 -0
  13. package/dist/__tests__/deploy-flags.e2e.test.js +228 -0
  14. package/dist/__tests__/deploy-flags.e2e.test.js.map +1 -0
  15. package/dist/__tests__/deploy.e2e.test.js +65 -66
  16. package/dist/__tests__/deploy.e2e.test.js.map +1 -1
  17. package/dist/__tests__/deployment-inspect.e2e.test.d.ts +1 -0
  18. package/dist/__tests__/deployment-inspect.e2e.test.js +119 -0
  19. package/dist/__tests__/deployment-inspect.e2e.test.js.map +1 -0
  20. package/dist/__tests__/deployment-list.e2e.test.d.ts +1 -0
  21. package/dist/__tests__/deployment-list.e2e.test.js +181 -0
  22. package/dist/__tests__/deployment-list.e2e.test.js.map +1 -0
  23. package/dist/__tests__/deployment-logs.e2e.test.d.ts +1 -0
  24. package/dist/__tests__/deployment-logs.e2e.test.js +276 -0
  25. package/dist/__tests__/deployment-logs.e2e.test.js.map +1 -0
  26. package/dist/__tests__/environment-inspect.e2e.test.d.ts +1 -0
  27. package/dist/__tests__/environment-inspect.e2e.test.js +110 -0
  28. package/dist/__tests__/environment-inspect.e2e.test.js.map +1 -0
  29. package/dist/__tests__/environment-list.e2e.test.d.ts +1 -0
  30. package/dist/__tests__/environment-list.e2e.test.js +89 -0
  31. package/dist/__tests__/environment-list.e2e.test.js.map +1 -0
  32. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.d.ts +1 -0
  33. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.js +368 -0
  34. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.js.map +1 -0
  35. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.d.ts +1 -0
  36. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.js +224 -0
  37. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.js.map +1 -0
  38. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.d.ts +1 -0
  39. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.js +148 -0
  40. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.js.map +1 -0
  41. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.d.ts +1 -0
  42. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.js +337 -0
  43. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.js.map +1 -0
  44. package/dist/__tests__/environment-variable/environment-variable-validation.test.d.ts +1 -0
  45. package/dist/__tests__/environment-variable/environment-variable-validation.test.js +20 -0
  46. package/dist/__tests__/environment-variable/environment-variable-validation.test.js.map +1 -0
  47. package/dist/__tests__/fixtures/demo-project/index.js +1 -1
  48. package/dist/__tests__/fixtures/demo-project/index.js.map +1 -1
  49. package/dist/__tests__/git-flags.e2e.test.d.ts +1 -0
  50. package/dist/__tests__/git-flags.e2e.test.js +133 -0
  51. package/dist/__tests__/git-flags.e2e.test.js.map +1 -0
  52. package/dist/__tests__/git.e2e.test.js +76 -25
  53. package/dist/__tests__/git.e2e.test.js.map +1 -1
  54. package/dist/__tests__/link.e2e.test.d.ts +1 -0
  55. package/dist/__tests__/link.e2e.test.js +473 -0
  56. package/dist/__tests__/link.e2e.test.js.map +1 -0
  57. package/dist/__tests__/logs.e2e.test.d.ts +1 -0
  58. package/dist/__tests__/logs.e2e.test.js +330 -0
  59. package/dist/__tests__/logs.e2e.test.js.map +1 -0
  60. package/dist/__tests__/mock-api.d.ts +47 -0
  61. package/dist/__tests__/mock-api.js +886 -0
  62. package/dist/__tests__/mock-api.js.map +1 -0
  63. package/dist/__tests__/playground/playground-configure.e2e.test.d.ts +1 -0
  64. package/dist/__tests__/playground/playground-configure.e2e.test.js +135 -0
  65. package/dist/__tests__/playground/playground-configure.e2e.test.js.map +1 -0
  66. package/dist/__tests__/playground/playground-enable-disable.e2e.test.d.ts +1 -0
  67. package/dist/__tests__/playground/playground-enable-disable.e2e.test.js +104 -0
  68. package/dist/__tests__/playground/playground-enable-disable.e2e.test.js.map +1 -0
  69. package/dist/__tests__/playground/playground-example-prompt.e2e.test.d.ts +1 -0
  70. package/dist/__tests__/playground/playground-example-prompt.e2e.test.js +282 -0
  71. package/dist/__tests__/playground/playground-example-prompt.e2e.test.js.map +1 -0
  72. package/dist/__tests__/playground/playground-headers.e2e.test.d.ts +1 -0
  73. package/dist/__tests__/playground/playground-headers.e2e.test.js +324 -0
  74. package/dist/__tests__/playground/playground-headers.e2e.test.js.map +1 -0
  75. package/dist/__tests__/playground/playground-status.e2e.test.d.ts +1 -0
  76. package/dist/__tests__/playground/playground-status.e2e.test.js +88 -0
  77. package/dist/__tests__/playground/playground-status.e2e.test.js.map +1 -0
  78. package/dist/__tests__/project-inspect.e2e.test.d.ts +1 -0
  79. package/dist/__tests__/project-inspect.e2e.test.js +84 -0
  80. package/dist/__tests__/project-inspect.e2e.test.js.map +1 -0
  81. package/dist/__tests__/project-list.e2e.test.d.ts +1 -0
  82. package/dist/__tests__/project-list.e2e.test.js +95 -0
  83. package/dist/__tests__/project-list.e2e.test.js.map +1 -0
  84. package/dist/__tests__/publish.e2e.test.d.ts +1 -0
  85. package/dist/__tests__/publish.e2e.test.js +575 -0
  86. package/dist/__tests__/publish.e2e.test.js.map +1 -0
  87. package/dist/__tests__/team-inspect.e2e.test.d.ts +1 -0
  88. package/dist/__tests__/team-inspect.e2e.test.js +86 -0
  89. package/dist/__tests__/team-inspect.e2e.test.js.map +1 -0
  90. package/dist/__tests__/team-list.e2e.test.d.ts +1 -0
  91. package/dist/__tests__/team-list.e2e.test.js +58 -0
  92. package/dist/__tests__/team-list.e2e.test.js.map +1 -0
  93. package/dist/__tests__/tunnel.e2e.test.d.ts +1 -0
  94. package/dist/__tests__/tunnel.e2e.test.js +74 -0
  95. package/dist/__tests__/tunnel.e2e.test.js.map +1 -0
  96. package/dist/__tests__/utils.d.ts +24 -5
  97. package/dist/__tests__/utils.js +144 -25
  98. package/dist/__tests__/utils.js.map +1 -1
  99. package/dist/api.d.ts +1 -2
  100. package/dist/api.js +13 -10
  101. package/dist/api.js.map +1 -1
  102. package/dist/commands/audit.d.ts +13 -0
  103. package/dist/commands/audit.js +45 -0
  104. package/dist/commands/audit.js.map +1 -0
  105. package/dist/commands/deploy.d.ts +8 -2
  106. package/dist/commands/deploy.js +73 -30
  107. package/dist/commands/deploy.js.map +1 -1
  108. package/dist/commands/deployment/inspect.d.ts +11 -0
  109. package/dist/commands/deployment/inspect.js +91 -0
  110. package/dist/commands/deployment/inspect.js.map +1 -0
  111. package/dist/commands/deployment/list.d.ts +12 -0
  112. package/dist/commands/deployment/list.js +94 -0
  113. package/dist/commands/deployment/list.js.map +1 -0
  114. package/dist/commands/deployment/logs.d.ts +12 -0
  115. package/dist/commands/deployment/logs.js +53 -0
  116. package/dist/commands/deployment/logs.js.map +1 -0
  117. package/dist/commands/environment/inspect.d.ts +13 -0
  118. package/dist/commands/environment/inspect.js +51 -0
  119. package/dist/commands/environment/inspect.js.map +1 -0
  120. package/dist/commands/environment/list.d.ts +11 -0
  121. package/dist/commands/environment/list.js +56 -0
  122. package/dist/commands/environment/list.js.map +1 -0
  123. package/dist/commands/environment-variable/add.d.ts +13 -0
  124. package/dist/commands/environment-variable/add.js +46 -0
  125. package/dist/commands/environment-variable/add.js.map +1 -0
  126. package/dist/commands/environment-variable/list.d.ts +9 -0
  127. package/dist/commands/environment-variable/list.js +45 -0
  128. package/dist/commands/environment-variable/list.js.map +1 -0
  129. package/dist/commands/environment-variable/remove.d.ts +10 -0
  130. package/dist/commands/environment-variable/remove.js +29 -0
  131. package/dist/commands/environment-variable/remove.js.map +1 -0
  132. package/dist/commands/environment-variable/update.d.ts +12 -0
  133. package/dist/commands/environment-variable/update.js +37 -0
  134. package/dist/commands/environment-variable/update.js.map +1 -0
  135. package/dist/commands/git/connect.d.ts +2 -2
  136. package/dist/commands/git/connect.js +26 -35
  137. package/dist/commands/git/connect.js.map +1 -1
  138. package/dist/commands/git/disconnect.d.ts +0 -3
  139. package/dist/commands/git/disconnect.js +14 -33
  140. package/dist/commands/git/disconnect.js.map +1 -1
  141. package/dist/commands/git.js +3 -3
  142. package/dist/commands/git.js.map +1 -1
  143. package/dist/commands/link.d.ts +17 -0
  144. package/dist/commands/link.js +102 -0
  145. package/dist/commands/link.js.map +1 -0
  146. package/dist/commands/login.d.ts +6 -0
  147. package/dist/commands/login.js +21 -0
  148. package/dist/commands/login.js.map +1 -0
  149. package/dist/commands/logout.d.ts +6 -0
  150. package/dist/commands/logout.js +20 -0
  151. package/dist/commands/logout.js.map +1 -0
  152. package/dist/commands/logs.d.ts +16 -0
  153. package/dist/commands/logs.js +123 -0
  154. package/dist/commands/logs.js.map +1 -0
  155. package/dist/commands/playground/configure.d.ts +12 -0
  156. package/dist/commands/playground/configure.js +39 -0
  157. package/dist/commands/playground/configure.js.map +1 -0
  158. package/dist/commands/playground/disable.d.ts +9 -0
  159. package/dist/commands/playground/disable.js +24 -0
  160. package/dist/commands/playground/disable.js.map +1 -0
  161. package/dist/commands/playground/enable.d.ts +9 -0
  162. package/dist/commands/playground/enable.js +24 -0
  163. package/dist/commands/playground/enable.js.map +1 -0
  164. package/dist/commands/playground/example-prompt/add.d.ts +12 -0
  165. package/dist/commands/playground/example-prompt/add.js +39 -0
  166. package/dist/commands/playground/example-prompt/add.js.map +1 -0
  167. package/dist/commands/playground/example-prompt/list.d.ts +9 -0
  168. package/dist/commands/playground/example-prompt/list.js +24 -0
  169. package/dist/commands/playground/example-prompt/list.js.map +1 -0
  170. package/dist/commands/playground/example-prompt/remove.d.ts +11 -0
  171. package/dist/commands/playground/example-prompt/remove.js +34 -0
  172. package/dist/commands/playground/example-prompt/remove.js.map +1 -0
  173. package/dist/commands/playground/headers/add.d.ts +14 -0
  174. package/dist/commands/playground/headers/add.js +49 -0
  175. package/dist/commands/playground/headers/add.js.map +1 -0
  176. package/dist/commands/playground/headers/list.d.ts +9 -0
  177. package/dist/commands/playground/headers/list.js +24 -0
  178. package/dist/commands/playground/headers/list.js.map +1 -0
  179. package/dist/commands/playground/headers/remove.d.ts +11 -0
  180. package/dist/commands/playground/headers/remove.js +34 -0
  181. package/dist/commands/playground/headers/remove.js.map +1 -0
  182. package/dist/commands/playground/status.d.ts +9 -0
  183. package/dist/commands/playground/status.js +24 -0
  184. package/dist/commands/playground/status.js.map +1 -0
  185. package/dist/commands/project/inspect.d.ts +11 -0
  186. package/dist/commands/project/inspect.js +75 -0
  187. package/dist/commands/project/inspect.js.map +1 -0
  188. package/dist/commands/project/list.d.ts +10 -0
  189. package/dist/commands/project/list.js +50 -0
  190. package/dist/commands/project/list.js.map +1 -0
  191. package/dist/commands/publish.d.ts +15 -0
  192. package/dist/commands/publish.js +44 -0
  193. package/dist/commands/publish.js.map +1 -0
  194. package/dist/commands/team/inspect.d.ts +10 -0
  195. package/dist/commands/team/inspect.js +97 -0
  196. package/dist/commands/team/inspect.js.map +1 -0
  197. package/dist/commands/team/list.d.ts +9 -0
  198. package/dist/commands/team/list.js +40 -0
  199. package/dist/commands/team/list.js.map +1 -0
  200. package/dist/commands/tunnel.d.ts +10 -0
  201. package/dist/commands/tunnel.js +137 -0
  202. package/dist/commands/tunnel.js.map +1 -0
  203. package/dist/commands/whoami.d.ts +6 -0
  204. package/dist/commands/whoami.js +13 -0
  205. package/dist/commands/whoami.js.map +1 -0
  206. package/dist/env.d.ts +5 -0
  207. package/dist/env.js +11 -0
  208. package/dist/env.js.map +1 -0
  209. package/dist/lib/agent-mode.d.ts +3 -0
  210. package/dist/lib/agent-mode.js +33 -0
  211. package/dist/lib/agent-mode.js.map +1 -0
  212. package/dist/lib/alpic-command.d.ts +9 -0
  213. package/dist/lib/alpic-command.js +32 -8
  214. package/dist/lib/alpic-command.js.map +1 -1
  215. package/dist/lib/archive.d.ts +3 -3
  216. package/dist/lib/archive.js +21 -19
  217. package/dist/lib/archive.js.map +1 -1
  218. package/dist/lib/audit.d.ts +16 -0
  219. package/dist/lib/audit.js +271 -0
  220. package/dist/lib/audit.js.map +1 -0
  221. package/dist/lib/auth/auth.d.ts +5 -0
  222. package/dist/lib/auth/auth.js +46 -0
  223. package/dist/lib/auth/auth.js.map +1 -0
  224. package/dist/lib/auth/oauth/client.d.ts +28 -0
  225. package/dist/lib/auth/oauth/client.js +116 -0
  226. package/dist/lib/auth/oauth/client.js.map +1 -0
  227. package/dist/lib/auth/oauth/constants.d.ts +2 -0
  228. package/dist/lib/auth/oauth/constants.js +3 -0
  229. package/dist/lib/auth/oauth/constants.js.map +1 -0
  230. package/dist/lib/auth/oauth/server/assets/alpic-mountain.png +0 -0
  231. package/dist/lib/auth/oauth/server/assets/authorize.html +195 -0
  232. package/dist/lib/auth/oauth/server/assets/callback.html +88 -0
  233. package/dist/lib/auth/oauth/server/index.d.ts +9 -0
  234. package/dist/lib/auth/oauth/server/index.js +128 -0
  235. package/dist/lib/auth/oauth/server/index.js.map +1 -0
  236. package/dist/lib/auth/whoami.d.ts +1 -0
  237. package/dist/lib/auth/whoami.js +45 -0
  238. package/dist/lib/auth/whoami.js.map +1 -0
  239. package/dist/lib/base-workflow.d.ts +12 -0
  240. package/dist/lib/base-workflow.js +30 -0
  241. package/dist/lib/base-workflow.js.map +1 -0
  242. package/dist/lib/config.d.ts +3 -2
  243. package/dist/lib/config.js +8 -7
  244. package/dist/lib/config.js.map +1 -1
  245. package/dist/lib/deployment.d.ts +74 -4
  246. package/dist/lib/deployment.js +125 -10
  247. package/dist/lib/deployment.js.map +1 -1
  248. package/dist/lib/environment-variable.d.ts +37 -0
  249. package/dist/lib/environment-variable.js +302 -0
  250. package/dist/lib/environment-variable.js.map +1 -0
  251. package/dist/lib/git.d.ts +13 -4
  252. package/dist/lib/git.js +68 -28
  253. package/dist/lib/git.js.map +1 -1
  254. package/dist/lib/global-store.d.ts +28 -0
  255. package/dist/lib/global-store.js +76 -0
  256. package/dist/lib/global-store.js.map +1 -0
  257. package/dist/lib/link.d.ts +85 -0
  258. package/dist/lib/link.js +469 -0
  259. package/dist/lib/link.js.map +1 -0
  260. package/dist/lib/logs.d.ts +20 -0
  261. package/dist/lib/logs.js +89 -0
  262. package/dist/lib/logs.js.map +1 -0
  263. package/dist/lib/playground.d.ts +53 -0
  264. package/dist/lib/playground.js +289 -0
  265. package/dist/lib/playground.js.map +1 -0
  266. package/dist/lib/publish.d.ts +22 -0
  267. package/dist/lib/publish.js +201 -0
  268. package/dist/lib/publish.js.map +1 -0
  269. package/dist/lib/resolve.d.ts +24 -0
  270. package/dist/lib/resolve.js +122 -0
  271. package/dist/lib/resolve.js.map +1 -0
  272. package/dist/lib/table.d.ts +8 -0
  273. package/dist/lib/table.js +27 -0
  274. package/dist/lib/table.js.map +1 -0
  275. package/dist/lib/telemetry.js +8 -7
  276. package/dist/lib/telemetry.js.map +1 -1
  277. package/dist/lib/utils.d.ts +38 -0
  278. package/dist/lib/utils.js +57 -0
  279. package/dist/lib/utils.js.map +1 -0
  280. package/dist/lib/utils.test.d.ts +1 -0
  281. package/dist/lib/utils.test.js +44 -0
  282. package/dist/lib/utils.test.js.map +1 -0
  283. package/dist/types.d.ts +1 -0
  284. package/package.json +37 -22
  285. package/dist/__tests__/mock-server.d.ts +0 -22
  286. package/dist/__tests__/mock-server.js +0 -445
  287. package/dist/__tests__/mock-server.js.map +0 -1
  288. package/dist/lib/auth.d.ts +0 -1
  289. package/dist/lib/auth.js +0 -10
  290. package/dist/lib/auth.js.map +0 -1
  291. package/dist/lib/global-config.d.ts +0 -9
  292. package/dist/lib/global-config.js +0 -48
  293. package/dist/lib/global-config.js.map +0 -1
  294. package/dist/lib/project.d.ts +0 -67
  295. package/dist/lib/project.js +0 -285
  296. package/dist/lib/project.js.map +0 -1
@@ -0,0 +1,886 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import * as https from "node:https";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { contract } from "@alpic-ai/api";
7
+ import { OpenAPIHandler } from "@orpc/openapi/node";
8
+ import { implement, ORPCError } from "@orpc/server";
9
+ import express, {} from "express";
10
+ import { inc as semverInc } from "semver";
11
+ const __testDirname = dirname(fileURLToPath(import.meta.url));
12
+ const FIXTURE_CERT_PATH = join(__testDirname, "fixtures", "certs", "localhost-cert.pem");
13
+ const FIXTURE_KEY_PATH = join(__testDirname, "fixtures", "certs", "localhost-key.pem");
14
+ function getTlsAssets() {
15
+ return {
16
+ key: readFileSync(FIXTURE_KEY_PATH, "utf8"),
17
+ cert: readFileSync(FIXTURE_CERT_PATH, "utf8"),
18
+ certPath: FIXTURE_CERT_PATH,
19
+ };
20
+ }
21
+ export class MockApiServer {
22
+ server = null;
23
+ app;
24
+ port = null;
25
+ mockData;
26
+ callHistory = [];
27
+ constructor() {
28
+ this.app = express();
29
+ this.mockData = {
30
+ teams: null,
31
+ projects: new Map(),
32
+ environments: new Map(),
33
+ deployments: new Map(),
34
+ environmentVariables: new Map(),
35
+ runtimeLogs: new Map(),
36
+ runtimeLogPages: new Map(),
37
+ deploymentLogPages: new Map(),
38
+ deploymentLogCallCounts: new Map(),
39
+ publishedServers: new Map(),
40
+ beaconGetResponses: [],
41
+ beaconGetCallCount: 0,
42
+ playgrounds: new Map(),
43
+ };
44
+ }
45
+ async start() {
46
+ if (this.server) {
47
+ throw new Error("Server is already running");
48
+ }
49
+ this.configureServer();
50
+ const tlsAssets = getTlsAssets();
51
+ process.env.NODE_EXTRA_CA_CERTS = tlsAssets.certPath;
52
+ const httpsOptions = { key: tlsAssets.key, cert: tlsAssets.cert };
53
+ return new Promise((resolve) => {
54
+ this.server = https.createServer(httpsOptions, this.app).listen(0, "127.0.0.1", () => {
55
+ if (!this.server) {
56
+ throw new Error("Server is not running");
57
+ }
58
+ const address = this.server.address();
59
+ this.port = address.port;
60
+ const url = `https://127.0.0.1:${this.port}`;
61
+ resolve(url);
62
+ });
63
+ });
64
+ }
65
+ configureServer() {
66
+ this.app.put("/__mock__upload/:token", express.raw({ type: "*/*", limit: "50mb" }), async (req, res) => {
67
+ const apiCall = {
68
+ method: req.method,
69
+ path: req.path,
70
+ timestamp: new Date(),
71
+ input: { token: req.params.token, size: req.body.length },
72
+ responseStatus: 200,
73
+ };
74
+ this.callHistory.push(apiCall);
75
+ res.status(200).end();
76
+ });
77
+ this.app.use(express.json());
78
+ this.app.get("/.well-known/oauth-protected-resource", (_req, res) => {
79
+ const base = `https://127.0.0.1:${this.port}`;
80
+ res.status(200).json({
81
+ resource: "https://api.alpic.ai",
82
+ authorization_servers: [base],
83
+ bearer_methods_supported: ["header"],
84
+ scopes_supported: ["openid", "email", "profile"],
85
+ resource_documentation: "https://docs.alpic.ai",
86
+ });
87
+ });
88
+ this.app.get("/.well-known/openid-configuration", (_req, res) => {
89
+ const base = `https://127.0.0.1:${this.port}`;
90
+ res.status(200).json({
91
+ issuer: base,
92
+ userinfo_endpoint: `${base}/oauth2/userInfo`,
93
+ authorization_endpoint: `${base}/oauth2/authorize`,
94
+ token_endpoint: `${base}/oauth2/token`,
95
+ jwks_uri: `${base}/.well-known/jwks.json`,
96
+ });
97
+ });
98
+ this.app.get("/oauth2/userInfo", (req, res) => {
99
+ const auth = req.headers.authorization;
100
+ if (!auth?.startsWith("Bearer ")) {
101
+ res.status(401).json({ error: "Missing or invalid Authorization" });
102
+ return;
103
+ }
104
+ res.status(200).json({
105
+ sub: "test-sub",
106
+ email_verified: "true",
107
+ identities: [],
108
+ name: "Test User",
109
+ email: "test@example.com",
110
+ picture: "",
111
+ username: "testuser",
112
+ });
113
+ });
114
+ const router = implement(contract).router({
115
+ tunnels: {
116
+ getTicket: {
117
+ v1: implement(contract.tunnels.getTicket.v1).handler(async () => {
118
+ return {
119
+ subdomain: "cool-mongoose-123",
120
+ ticket: "mock-ticket",
121
+ tunnelHost: "tunnel.alpic.dev",
122
+ };
123
+ }),
124
+ },
125
+ },
126
+ teams: {
127
+ list: {
128
+ v1: implement(contract.teams.list.v1).handler(async () => {
129
+ if (this.mockData.teams) {
130
+ return this.mockData.teams;
131
+ }
132
+ return [
133
+ {
134
+ id: "mock-team-id",
135
+ name: "Mock Team",
136
+ createdAt: new Date(),
137
+ hasStripeAccount: false,
138
+ },
139
+ ];
140
+ }),
141
+ },
142
+ },
143
+ analytics: {
144
+ get: {
145
+ v1: implement(contract.analytics.get.v1).handler(async ({ input }) => {
146
+ const project = this.mockData.projects.get(input.projectId);
147
+ if (!project) {
148
+ throw new ORPCError("NOT_FOUND", {
149
+ message: "Project not found",
150
+ });
151
+ }
152
+ const emptyTimeSeries = {
153
+ sessions_count: [],
154
+ requests_count: [],
155
+ requests_latency_mean: [],
156
+ tool_errors: [],
157
+ mcp_errors: [],
158
+ output_token_mean: [],
159
+ task_count: [],
160
+ };
161
+ return {
162
+ metadata: {
163
+ startTimestamp: input.startTimestamp,
164
+ endTimestamp: input.endTimestamp,
165
+ timeZone: input.timeZone,
166
+ startDate: new Date(input.startTimestamp),
167
+ interval: "1h",
168
+ },
169
+ timeSeries: emptyTimeSeries,
170
+ };
171
+ }),
172
+ },
173
+ },
174
+ projects: {
175
+ list: {
176
+ v1: implement(contract.projects.list.v1).handler(async ({ input }) => {
177
+ let projects = Array.from(this.mockData.projects.values());
178
+ if (input?.teamId) {
179
+ projects = projects.filter((project) => project.teamId === input.teamId);
180
+ }
181
+ return projects.map((project) => ({
182
+ id: project.id,
183
+ name: project.name,
184
+ teamId: project.teamId,
185
+ environments: project.environments,
186
+ productionEnvironment: project.productionEnvironment,
187
+ sourceRepository: project.sourceRepository,
188
+ runtime: project.runtime,
189
+ transport: project.transport,
190
+ rootDirectory: project.rootDirectory,
191
+ buildCommand: project.buildCommand,
192
+ buildOutputDir: project.buildOutputDir,
193
+ installCommand: project.installCommand,
194
+ startCommand: project.startCommand,
195
+ createdAt: project.createdAt,
196
+ }));
197
+ }),
198
+ },
199
+ get: {
200
+ v1: implement(contract.projects.get.v1).handler(async ({ input }) => {
201
+ const project = this.mockData.projects.get(input.projectId);
202
+ if (!project) {
203
+ throw new ORPCError("NOT_FOUND", {
204
+ message: "Project not found",
205
+ });
206
+ }
207
+ return project;
208
+ }),
209
+ },
210
+ create: {
211
+ v1: implement(contract.projects.create.v1).handler(async ({ input }) => {
212
+ const projectId = randomUUID();
213
+ const teamId = input.teamId ?? "mock-team-id";
214
+ const productionEnvId = randomUUID();
215
+ const productionEnvName = "production";
216
+ const project = {
217
+ id: projectId,
218
+ name: input.name,
219
+ teamId,
220
+ environments: [],
221
+ productionEnvironment: {
222
+ id: productionEnvId,
223
+ name: productionEnvName,
224
+ },
225
+ sourceRepository: input.sourceRepository ?? null,
226
+ runtime: input.runtime,
227
+ transport: input.transport ?? null,
228
+ rootDirectory: input.rootDirectory ?? null,
229
+ buildCommand: input.settings?.buildCommand ?? null,
230
+ buildOutputDir: input.settings?.buildOutputDir ?? null,
231
+ installCommand: input.settings?.installCommand ?? null,
232
+ startCommand: input.settings?.startCommand ?? null,
233
+ createdAt: new Date(),
234
+ };
235
+ const environment = {
236
+ id: productionEnvId,
237
+ name: productionEnvName,
238
+ sourceBranch: null,
239
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
240
+ domains: [`https://mcp-${projectId}.alpic.ai`],
241
+ createdAt: new Date(),
242
+ projectId,
243
+ };
244
+ this.mockData.environments.set(productionEnvId, environment);
245
+ const fullProject = {
246
+ ...project,
247
+ productionEnvironment: {
248
+ id: productionEnvId,
249
+ name: productionEnvName,
250
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
251
+ domains: [],
252
+ latestDeployment: null,
253
+ },
254
+ environments: [
255
+ {
256
+ id: productionEnvId,
257
+ name: productionEnvName,
258
+ sourceBranch: null,
259
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
260
+ createdAt: new Date(),
261
+ projectId,
262
+ latestDeployment: null,
263
+ },
264
+ ],
265
+ };
266
+ this.mockData.projects.set(projectId, fullProject);
267
+ return project;
268
+ }),
269
+ },
270
+ update: {
271
+ v1: implement(contract.projects.update.v1).handler(async ({ input }) => {
272
+ const project = this.mockData.projects.get(input.projectId);
273
+ if (!project) {
274
+ throw new ORPCError("NOT_FOUND", {
275
+ message: "Project not found",
276
+ });
277
+ }
278
+ if (input.sourceRepository !== undefined) {
279
+ project.sourceRepository = input.sourceRepository;
280
+ }
281
+ this.mockData.projects.set(input.projectId, project);
282
+ return project;
283
+ }),
284
+ },
285
+ delete: {
286
+ v1: implement(contract.projects.delete.v1).handler(async ({ input }) => {
287
+ const project = this.mockData.projects.get(input.projectId);
288
+ if (!project) {
289
+ throw new ORPCError("NOT_FOUND", {
290
+ message: "Project not found",
291
+ });
292
+ }
293
+ this.mockData.projects.delete(input.projectId);
294
+ return { success: true };
295
+ }),
296
+ },
297
+ },
298
+ environments: {
299
+ create: {
300
+ v1: implement(contract.environments.create.v1).handler(async ({ input }) => {
301
+ const project = this.mockData.projects.get(input.projectId);
302
+ if (!project) {
303
+ throw new ORPCError("NOT_FOUND", {
304
+ message: "Project not found",
305
+ });
306
+ }
307
+ const environmentId = randomUUID();
308
+ const mcpServerUrl = `https://mcp-${environmentId}.alpic.ai`;
309
+ const createdAt = new Date();
310
+ const environment = {
311
+ id: environmentId,
312
+ name: input.name,
313
+ sourceBranch: input.sourceBranch,
314
+ mcpServerUrl,
315
+ domains: [mcpServerUrl],
316
+ createdAt,
317
+ projectId: input.projectId,
318
+ };
319
+ this.mockData.environments.set(environmentId, environment);
320
+ this.mockData.projects.set(input.projectId, {
321
+ ...project,
322
+ environments: [
323
+ ...project.environments,
324
+ {
325
+ id: environmentId,
326
+ name: input.name,
327
+ sourceBranch: input.sourceBranch,
328
+ mcpServerUrl,
329
+ createdAt,
330
+ projectId: input.projectId,
331
+ latestDeployment: null,
332
+ },
333
+ ],
334
+ });
335
+ return {
336
+ id: environmentId,
337
+ name: input.name,
338
+ sourceBranch: input.sourceBranch,
339
+ createdAt,
340
+ projectId: input.projectId,
341
+ urls: [mcpServerUrl],
342
+ };
343
+ }),
344
+ },
345
+ get: {
346
+ v1: implement(contract.environments.get.v1).handler(async ({ input }) => {
347
+ const environment = this.mockData.environments.get(input.environmentId);
348
+ if (!environment) {
349
+ throw new ORPCError("NOT_FOUND", {
350
+ message: "Environment not found",
351
+ });
352
+ }
353
+ return environment;
354
+ }),
355
+ },
356
+ getLogs: {
357
+ v1: implement(contract.environments.getLogs.v1).handler(async ({ input }) => {
358
+ const environment = this.mockData.environments.get(input.environmentId);
359
+ if (!environment) {
360
+ throw new ORPCError("NOT_FOUND", {
361
+ message: "Environment not found",
362
+ });
363
+ }
364
+ const pagedLogs = this.mockData.runtimeLogPages.get(input.environmentId);
365
+ const pageIndex = input.nextToken === undefined ? 0 : Number.parseInt(input.nextToken, 10);
366
+ const allLogs = pagedLogs === undefined
367
+ ? (this.mockData.runtimeLogs.get(input.environmentId) ?? [])
368
+ : (pagedLogs[pageIndex] ?? []);
369
+ let logs = allLogs;
370
+ if (input.level !== undefined) {
371
+ const levels = input.level;
372
+ logs = allLogs.filter((log) => levels.includes(log.type));
373
+ }
374
+ const nextToken = pagedLogs === undefined || pageIndex + 1 >= pagedLogs.length ? null : String(pageIndex + 1);
375
+ return { logs, nextToken };
376
+ }),
377
+ },
378
+ getLatestLogs: {
379
+ v1: implement(contract.environments.getLatestLogs.v1).handler(async ({ input }) => {
380
+ const environment = this.mockData.environments.get(input.environmentId);
381
+ if (!environment) {
382
+ throw new ORPCError("NOT_FOUND", {
383
+ message: "Environment not found",
384
+ });
385
+ }
386
+ let logs = this.mockData.runtimeLogs.get(input.environmentId) ?? [];
387
+ if (input.level !== undefined) {
388
+ const levels = input.level;
389
+ logs = logs.filter((log) => levels.includes(log.type));
390
+ }
391
+ return { logs: logs.slice(-input.limit) };
392
+ }),
393
+ },
394
+ deploy: {
395
+ v1: implement(contract.environments.deploy.v1).handler(async ({ input }) => {
396
+ const environment = this.mockData.environments.get(input.environmentId);
397
+ if (!environment) {
398
+ throw new ORPCError("NOT_FOUND", {
399
+ message: "Environment not found",
400
+ });
401
+ }
402
+ const deploymentId = randomUUID();
403
+ const deployment = {
404
+ id: deploymentId,
405
+ status: "ongoing",
406
+ environmentId: environment.id,
407
+ environmentName: environment.name,
408
+ isCurrent: false,
409
+ sourceRef: environment.sourceBranch,
410
+ sourceCommitId: randomUUID().slice(0, 7),
411
+ sourceCommitMessage: "Mock deployment",
412
+ authorUsername: "test-user",
413
+ authorAvatarUrl: null,
414
+ startedAt: new Date(),
415
+ completedAt: null,
416
+ deploymentPageUrl: "https://app.alpic.ai/deployments/mock",
417
+ };
418
+ this.mockData.deployments.set(deploymentId, deployment);
419
+ return deployment;
420
+ }),
421
+ },
422
+ },
423
+ environmentVariables: {
424
+ list: {
425
+ v1: implement(contract.environmentVariables.list.v1).handler(async ({ input }) => {
426
+ const environment = this.mockData.environments.get(input.environmentId);
427
+ if (!environment) {
428
+ throw new ORPCError("NOT_FOUND", {
429
+ message: "Environment not found",
430
+ });
431
+ }
432
+ return this.mockData.environmentVariables.get(input.environmentId) ?? [];
433
+ }),
434
+ },
435
+ create: {
436
+ v1: implement(contract.environmentVariables.create.v1).handler(async ({ input }) => {
437
+ const environment = this.mockData.environments.get(input.environmentId);
438
+ if (!environment) {
439
+ throw new ORPCError("NOT_FOUND", {
440
+ message: "Environment not found",
441
+ });
442
+ }
443
+ const existing = this.mockData.environmentVariables.get(input.environmentId) ?? [];
444
+ const existingByKey = new Map(existing.map((variable) => [variable.key, variable]));
445
+ for (const incoming of input.environmentVariables) {
446
+ const existingVar = existingByKey.get(incoming.key);
447
+ if (existingVar?.isSecret && incoming.isSecret === false) {
448
+ throw new ORPCError("BAD_REQUEST", {
449
+ message: "Cannot change a secret variable back to non-secret. Delete and recreate it instead.",
450
+ });
451
+ }
452
+ }
453
+ const updated = existing.map((existingVar) => {
454
+ const incoming = input.environmentVariables.find((variable) => variable.key === existingVar.key);
455
+ if (!incoming)
456
+ return existingVar;
457
+ return {
458
+ ...existingVar,
459
+ value: incoming.value,
460
+ isSecret: !existingVar.isSecret && incoming.isSecret === true ? true : existingVar.isSecret,
461
+ };
462
+ });
463
+ const existingKeys = new Set(existing.map((variable) => variable.key));
464
+ const newVars = input.environmentVariables
465
+ .filter((variable) => !existingKeys.has(variable.key))
466
+ .map((variable) => ({
467
+ id: randomUUID(),
468
+ key: variable.key,
469
+ value: variable.value,
470
+ isSecret: variable.isSecret,
471
+ createdAt: new Date(),
472
+ }));
473
+ this.mockData.environmentVariables.set(input.environmentId, [...updated, ...newVars]);
474
+ return { success: true };
475
+ }),
476
+ },
477
+ update: {
478
+ v1: implement(contract.environmentVariables.update.v1).handler(async ({ input }) => {
479
+ for (const [environmentId, variables] of this.mockData.environmentVariables.entries()) {
480
+ const index = variables.findIndex((variable) => variable.id === input.environmentVariableId);
481
+ if (index !== -1) {
482
+ const updated = variables.map((variable, i) => i === index
483
+ ? {
484
+ ...variable,
485
+ key: input.key,
486
+ value: input.value ?? variable.value,
487
+ isSecret: input.isSecret ?? variable.isSecret,
488
+ }
489
+ : variable);
490
+ this.mockData.environmentVariables.set(environmentId, updated);
491
+ return { success: true };
492
+ }
493
+ }
494
+ throw new ORPCError("NOT_FOUND", {
495
+ message: "Environment variable not found",
496
+ });
497
+ }),
498
+ },
499
+ delete: {
500
+ v1: implement(contract.environmentVariables.delete.v1).handler(async ({ input }) => {
501
+ for (const [environmentId, variables] of this.mockData.environmentVariables.entries()) {
502
+ const index = variables.findIndex((variable) => variable.id === input.environmentVariableId);
503
+ if (index !== -1) {
504
+ this.mockData.environmentVariables.set(environmentId, variables.filter((_, i) => i !== index));
505
+ return { success: true };
506
+ }
507
+ }
508
+ throw new ORPCError("NOT_FOUND", {
509
+ message: "Environment variable not found",
510
+ });
511
+ }),
512
+ },
513
+ },
514
+ playground: {
515
+ get: {
516
+ v1: implement(contract.playground.get.v1).handler(async ({ input }) => {
517
+ const environment = this.mockData.environments.get(input.environmentId);
518
+ if (!environment) {
519
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
520
+ }
521
+ return (this.mockData.playgrounds.get(input.environmentId) ?? { isPlaygroundEnabled: true, serverMetadata: null });
522
+ }),
523
+ },
524
+ upsert: {
525
+ v1: implement(contract.playground.upsert.v1).handler(async ({ input }) => {
526
+ const environment = this.mockData.environments.get(input.environmentId);
527
+ if (!environment) {
528
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
529
+ }
530
+ const current = this.mockData.playgrounds.get(input.environmentId) ?? {
531
+ isPlaygroundEnabled: true,
532
+ serverMetadata: null,
533
+ };
534
+ const hasMetadataFields = input.name !== undefined ||
535
+ input.description !== undefined ||
536
+ input.headers !== undefined ||
537
+ input.examplePrompts !== undefined;
538
+ const updated = {
539
+ isPlaygroundEnabled: input.isPlaygroundEnabled ?? current.isPlaygroundEnabled,
540
+ serverMetadata: hasMetadataFields
541
+ ? {
542
+ name: input.name ?? current.serverMetadata?.name ?? "",
543
+ description: input.description ?? current.serverMetadata?.description ?? "",
544
+ headers: (input.headers ?? current.serverMetadata?.headers ?? []).map((header) => ({
545
+ name: header.name,
546
+ description: header.description,
547
+ isRequired: header.isRequired ?? false,
548
+ isSecret: header.isSecret ?? false,
549
+ })),
550
+ examplePrompts: input.examplePrompts ?? current.serverMetadata?.examplePrompts ?? [],
551
+ }
552
+ : current.serverMetadata,
553
+ };
554
+ this.mockData.playgrounds.set(input.environmentId, updated);
555
+ return updated;
556
+ }),
557
+ },
558
+ },
559
+ distribution: {
560
+ get: {
561
+ v1: implement(contract.distribution.get.v1).handler(async ({ input }) => {
562
+ const existing = this.mockData.publishedServers.get(`${input.projectId}:${input.domain}`);
563
+ return {
564
+ serverFields: existing ?? {
565
+ $schema: "https://registry.modelcontextprotocol.io/schemas/1.0/server.json",
566
+ name: "",
567
+ description: "",
568
+ },
569
+ };
570
+ }),
571
+ },
572
+ publish: {
573
+ v1: implement(contract.distribution.publish.v1).handler(async ({ input }) => {
574
+ const project = this.mockData.projects.get(input.projectId);
575
+ if (!project) {
576
+ throw new ORPCError("NOT_FOUND", {
577
+ message: "Project not found",
578
+ });
579
+ }
580
+ const key = `${input.projectId}:${input.domain}`;
581
+ const existing = this.mockData.publishedServers.get(key);
582
+ const version = existing?.version ? (semverInc(existing.version, "patch") ?? "0.0.1") : "0.0.1";
583
+ const serverFields = {
584
+ $schema: "https://registry.modelcontextprotocol.io/schemas/1.0/server.json",
585
+ name: input.domain,
586
+ description: input.description,
587
+ title: input.title,
588
+ version,
589
+ ...(input.websiteUrl ? { websiteUrl: input.websiteUrl } : {}),
590
+ ...(input.iconSrc ? { icons: [{ src: input.iconSrc }] } : {}),
591
+ };
592
+ if (!input.dryRun) {
593
+ this.mockData.publishedServers.set(key, serverFields);
594
+ }
595
+ return { serverFields };
596
+ }),
597
+ },
598
+ },
599
+ beacon: {
600
+ create: {
601
+ v1: implement(contract.beacon.create.v1).handler(async () => {
602
+ return { id: "mock-analysis-id" };
603
+ }),
604
+ },
605
+ get: {
606
+ v1: implement(contract.beacon.get.v1).handler(async () => {
607
+ if (this.mockData.beaconGetResponses.length > 0) {
608
+ const index = Math.min(this.mockData.beaconGetCallCount, this.mockData.beaconGetResponses.length - 1);
609
+ this.mockData.beaconGetCallCount++;
610
+ const response = this.mockData.beaconGetResponses[index];
611
+ if (!response) {
612
+ throw new Error("Missing mocked beacon.get response");
613
+ }
614
+ return response;
615
+ }
616
+ return {
617
+ id: "mock-analysis-id",
618
+ targetUrl: "https://example.com/mcp",
619
+ status: "completed",
620
+ durationMs: 1234,
621
+ createdAt: new Date(),
622
+ report: {
623
+ schemaVersion: "v20260224",
624
+ auditId: "mock-analysis-id",
625
+ targetUrl: "https://example.com/mcp",
626
+ startedAt: new Date().toISOString(),
627
+ completedAt: new Date().toISOString(),
628
+ durationMs: 1234,
629
+ results: [],
630
+ requiresAuth: false,
631
+ hasViewSupport: false,
632
+ isReadyForPlatform: { chatgpt: true, claudeai: true },
633
+ },
634
+ };
635
+ }),
636
+ },
637
+ },
638
+ deployments: {
639
+ list: {
640
+ v1: implement(contract.deployments.list.v1).handler(async ({ input }) => {
641
+ const project = this.mockData.projects.get(input.projectId);
642
+ if (!project) {
643
+ throw new ORPCError("NOT_FOUND", {
644
+ message: "Project not found",
645
+ });
646
+ }
647
+ let deployments = Array.from(this.mockData.deployments.values());
648
+ if (input.environmentId) {
649
+ deployments = deployments.filter((deployment) => deployment.environmentId === input.environmentId);
650
+ }
651
+ if (input.status?.length) {
652
+ deployments = deployments.filter((deployment) => input.status.includes(deployment.status));
653
+ }
654
+ return deployments.map((deployment) => ({
655
+ ...deployment,
656
+ isCurrent: deployment.status === "deployed",
657
+ }));
658
+ }),
659
+ },
660
+ get: {
661
+ v1: implement(contract.deployments.get.v1).handler(async ({ input }) => {
662
+ const deployment = this.mockData.deployments.get(input.deploymentId);
663
+ if (!deployment) {
664
+ throw new ORPCError("NOT_FOUND", {
665
+ message: "Deployment not found",
666
+ });
667
+ }
668
+ if (deployment.status === "ongoing") {
669
+ const updatedDeployment = {
670
+ ...deployment,
671
+ status: "deployed",
672
+ completedAt: new Date(),
673
+ deploymentPageUrl: deployment.deploymentPageUrl ?? null,
674
+ };
675
+ this.mockData.deployments.set(input.deploymentId, updatedDeployment);
676
+ return updatedDeployment;
677
+ }
678
+ return deployment;
679
+ }),
680
+ },
681
+ getLogs: {
682
+ v1: implement(contract.deployments.getLogs.v1).handler(async ({ input }) => {
683
+ const deployment = this.mockData.deployments.get(input.deploymentId);
684
+ if (!deployment) {
685
+ throw new ORPCError("NOT_FOUND", {
686
+ message: "Deployment not found",
687
+ });
688
+ }
689
+ const pages = this.mockData.deploymentLogPages.get(input.deploymentId);
690
+ if (pages !== undefined) {
691
+ const callCount = this.mockData.deploymentLogCallCounts.get(input.deploymentId) ?? 0;
692
+ const pageIndex = Math.min(callCount, pages.length - 1);
693
+ this.mockData.deploymentLogCallCounts.set(input.deploymentId, callCount + 1);
694
+ return pages[pageIndex] ?? { logs: [], hasMoreLogs: false };
695
+ }
696
+ return {
697
+ logs: [{ timestamp: new Date(), content: "Mock log entry" }],
698
+ hasMoreLogs: false,
699
+ };
700
+ }),
701
+ },
702
+ uploadArtifact: {
703
+ v1: implement(contract.deployments.uploadArtifact.v1).handler(async () => {
704
+ const token = randomUUID();
705
+ const baseUrl = `https://127.0.0.1:${this.port}`;
706
+ const uploadUrl = `${baseUrl}/__mock__upload/${token}`;
707
+ return {
708
+ uploadUrl,
709
+ token,
710
+ expiresAt: new Date(Date.now() + 3600000),
711
+ };
712
+ }),
713
+ },
714
+ },
715
+ });
716
+ const handler = new OpenAPIHandler(router);
717
+ this.app.use(async (req, res) => {
718
+ const apiCall = {
719
+ method: req.method,
720
+ path: req.path,
721
+ timestamp: new Date(),
722
+ };
723
+ if (req.method === "GET") {
724
+ if (Object.keys(req.query).length > 0) {
725
+ apiCall.input = req.query;
726
+ }
727
+ }
728
+ else if (req.body) {
729
+ apiCall.input = req.body;
730
+ }
731
+ const result = await handler.handle(req, res, {
732
+ context: {},
733
+ });
734
+ if (!result.matched) {
735
+ apiCall.responseStatus = 404;
736
+ this.callHistory.push(apiCall);
737
+ res.status(404).json({ error: "Not found" });
738
+ return;
739
+ }
740
+ apiCall.responseStatus = res.statusCode || 200;
741
+ this.callHistory.push(apiCall);
742
+ });
743
+ }
744
+ reset() {
745
+ this.callHistory = [];
746
+ this.mockData = {
747
+ teams: null,
748
+ projects: new Map(),
749
+ environments: new Map(),
750
+ deployments: new Map(),
751
+ environmentVariables: new Map(),
752
+ runtimeLogs: new Map(),
753
+ runtimeLogPages: new Map(),
754
+ deploymentLogPages: new Map(),
755
+ deploymentLogCallCounts: new Map(),
756
+ publishedServers: new Map(),
757
+ beaconGetResponses: [],
758
+ beaconGetCallCount: 0,
759
+ playgrounds: new Map(),
760
+ };
761
+ }
762
+ async stop() {
763
+ return new Promise((resolve, reject) => {
764
+ if (!this.server) {
765
+ resolve();
766
+ return;
767
+ }
768
+ this.server.close((error) => {
769
+ if (error) {
770
+ console.error("[MOCK] Error stopping server:", error);
771
+ reject(error);
772
+ }
773
+ else {
774
+ this.server = null;
775
+ resolve();
776
+ }
777
+ });
778
+ });
779
+ }
780
+ getCalls(method, pathPattern) {
781
+ return this.callHistory.filter((call) => {
782
+ if (method && call.method !== method)
783
+ return false;
784
+ if (pathPattern) {
785
+ if (typeof pathPattern === "string") {
786
+ if (!call.path.includes(pathPattern))
787
+ return false;
788
+ }
789
+ else {
790
+ if (!pathPattern.test(call.path))
791
+ return false;
792
+ }
793
+ }
794
+ return true;
795
+ });
796
+ }
797
+ getLastCall(method, pathPattern) {
798
+ for (let i = this.callHistory.length - 1; i >= 0; i--) {
799
+ const call = this.callHistory[i];
800
+ if (!call)
801
+ continue;
802
+ if (method && call.method !== method)
803
+ continue;
804
+ if (pathPattern) {
805
+ if (typeof pathPattern === "string") {
806
+ if (!call.path.includes(pathPattern))
807
+ continue;
808
+ }
809
+ else {
810
+ if (!pathPattern.test(call.path))
811
+ continue;
812
+ }
813
+ }
814
+ return call;
815
+ }
816
+ return undefined;
817
+ }
818
+ setTeams(teams) {
819
+ this.mockData.teams = teams.map((team) => ({
820
+ ...team,
821
+ createdAt: new Date("2024-01-01T00:00:00.000Z"),
822
+ hasStripeAccount: false,
823
+ }));
824
+ }
825
+ addEnvironmentVariables(environmentId, variables) {
826
+ this.mockData.environmentVariables.set(environmentId, variables);
827
+ }
828
+ setRuntimeLogs(environmentId, logs) {
829
+ this.mockData.runtimeLogs.set(environmentId, logs);
830
+ this.mockData.runtimeLogPages.delete(environmentId);
831
+ }
832
+ setRuntimeLogPages(environmentId, pages) {
833
+ this.mockData.runtimeLogPages.set(environmentId, pages);
834
+ this.mockData.runtimeLogs.delete(environmentId);
835
+ }
836
+ setPublishedServer(projectId, domain, server) {
837
+ this.mockData.publishedServers.set(`${projectId}:${domain}`, server);
838
+ }
839
+ addDeployments(deployments) {
840
+ for (const deployment of deployments) {
841
+ this.mockData.deployments.set(deployment.id, {
842
+ ...deployment,
843
+ deploymentPageUrl: null,
844
+ });
845
+ }
846
+ }
847
+ setDeploymentLogPages(deploymentId, pages) {
848
+ this.mockData.deploymentLogPages.set(deploymentId, pages);
849
+ this.mockData.deploymentLogCallCounts.set(deploymentId, 0);
850
+ }
851
+ setBeaconGetResponses(responses) {
852
+ this.mockData.beaconGetResponses = responses;
853
+ this.mockData.beaconGetCallCount = 0;
854
+ }
855
+ setPlayground(environmentId, playground) {
856
+ this.mockData.playgrounds.set(environmentId, playground);
857
+ }
858
+ addProject(project) {
859
+ this.mockData.projects.set(project.id, project);
860
+ if (project.productionEnvironment) {
861
+ const env = {
862
+ id: project.productionEnvironment.id,
863
+ name: project.productionEnvironment.name,
864
+ sourceBranch: null,
865
+ mcpServerUrl: project.productionEnvironment.mcpServerUrl,
866
+ domains: [project.productionEnvironment.mcpServerUrl],
867
+ createdAt: new Date(),
868
+ projectId: project.id,
869
+ };
870
+ this.mockData.environments.set(env.id, env);
871
+ }
872
+ for (const env of project.environments) {
873
+ const fullEnv = {
874
+ id: env.id,
875
+ name: env.name,
876
+ sourceBranch: env.sourceBranch,
877
+ mcpServerUrl: env.mcpServerUrl,
878
+ domains: [env.mcpServerUrl],
879
+ createdAt: env.createdAt,
880
+ projectId: project.id,
881
+ };
882
+ this.mockData.environments.set(env.id, fullEnv);
883
+ }
884
+ }
885
+ }
886
+ //# sourceMappingURL=mock-api.js.map