alpic 0.0.0-dev.ff7eedf → 0.0.0-staging.039ae14

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 (177) hide show
  1. package/dist/__tests__/auth.e2e.test.d.ts +1 -0
  2. package/dist/__tests__/auth.e2e.test.js +158 -0
  3. package/dist/__tests__/auth.e2e.test.js.map +1 -0
  4. package/dist/__tests__/deploy-flags.e2e.test.d.ts +1 -0
  5. package/dist/__tests__/deploy-flags.e2e.test.js +111 -0
  6. package/dist/__tests__/deploy-flags.e2e.test.js.map +1 -0
  7. package/dist/__tests__/deploy.e2e.test.d.ts +1 -0
  8. package/dist/__tests__/deploy.e2e.test.js +168 -0
  9. package/dist/__tests__/deploy.e2e.test.js.map +1 -0
  10. package/dist/__tests__/deployment-inspect.e2e.test.d.ts +1 -0
  11. package/dist/__tests__/deployment-inspect.e2e.test.js +111 -0
  12. package/dist/__tests__/deployment-inspect.e2e.test.js.map +1 -0
  13. package/dist/__tests__/deployment-list.e2e.test.d.ts +1 -0
  14. package/dist/__tests__/deployment-list.e2e.test.js +108 -0
  15. package/dist/__tests__/deployment-list.e2e.test.js.map +1 -0
  16. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.d.ts +1 -0
  17. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.js +250 -0
  18. package/dist/__tests__/environment-variable/environment-variable-add.e2e.test.js.map +1 -0
  19. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.d.ts +1 -0
  20. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.js +122 -0
  21. package/dist/__tests__/environment-variable/environment-variable-list.e2e.test.js.map +1 -0
  22. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.d.ts +1 -0
  23. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.js +139 -0
  24. package/dist/__tests__/environment-variable/environment-variable-remove.e2e.test.js.map +1 -0
  25. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.d.ts +1 -0
  26. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.js +319 -0
  27. package/dist/__tests__/environment-variable/environment-variable-update.e2e.test.js.map +1 -0
  28. package/dist/__tests__/environment-variable/environment-variable-validation.test.d.ts +1 -0
  29. package/dist/__tests__/environment-variable/environment-variable-validation.test.js +20 -0
  30. package/dist/__tests__/environment-variable/environment-variable-validation.test.js.map +1 -0
  31. package/dist/__tests__/fixtures/demo-project/index.d.ts +1 -0
  32. package/dist/__tests__/fixtures/demo-project/index.js +4 -0
  33. package/dist/__tests__/fixtures/demo-project/index.js.map +1 -0
  34. package/dist/__tests__/git-flags.e2e.test.d.ts +1 -0
  35. package/dist/__tests__/git-flags.e2e.test.js +124 -0
  36. package/dist/__tests__/git-flags.e2e.test.js.map +1 -0
  37. package/dist/__tests__/git.e2e.test.d.ts +1 -0
  38. package/dist/__tests__/git.e2e.test.js +221 -0
  39. package/dist/__tests__/git.e2e.test.js.map +1 -0
  40. package/dist/__tests__/logs.e2e.test.d.ts +1 -0
  41. package/dist/__tests__/logs.e2e.test.js +197 -0
  42. package/dist/__tests__/logs.e2e.test.js.map +1 -0
  43. package/dist/__tests__/mock-server.d.ts +27 -0
  44. package/dist/__tests__/mock-server.js +633 -0
  45. package/dist/__tests__/mock-server.js.map +1 -0
  46. package/dist/__tests__/utils.d.ts +69 -0
  47. package/dist/__tests__/utils.js +272 -0
  48. package/dist/__tests__/utils.js.map +1 -0
  49. package/dist/api.d.ts +3 -0
  50. package/dist/api.js +15 -0
  51. package/dist/api.js.map +1 -0
  52. package/dist/commands/deploy.d.ts +12 -0
  53. package/dist/commands/deploy.js +100 -0
  54. package/dist/commands/deploy.js.map +1 -0
  55. package/dist/commands/deployment/inspect.d.ts +11 -0
  56. package/dist/commands/deployment/inspect.js +68 -0
  57. package/dist/commands/deployment/inspect.js.map +1 -0
  58. package/dist/commands/deployment/list.d.ts +11 -0
  59. package/dist/commands/deployment/list.js +85 -0
  60. package/dist/commands/deployment/list.js.map +1 -0
  61. package/dist/commands/environment-variable/add.d.ts +14 -0
  62. package/dist/commands/environment-variable/add.js +46 -0
  63. package/dist/commands/environment-variable/add.js.map +1 -0
  64. package/dist/commands/environment-variable/list.d.ts +9 -0
  65. package/dist/commands/environment-variable/list.js +44 -0
  66. package/dist/commands/environment-variable/list.js.map +1 -0
  67. package/dist/commands/environment-variable/remove.d.ts +11 -0
  68. package/dist/commands/environment-variable/remove.js +32 -0
  69. package/dist/commands/environment-variable/remove.js.map +1 -0
  70. package/dist/commands/environment-variable/update.d.ts +13 -0
  71. package/dist/commands/environment-variable/update.js +40 -0
  72. package/dist/commands/environment-variable/update.js.map +1 -0
  73. package/dist/commands/git/connect.d.ts +10 -0
  74. package/dist/commands/git/connect.js +58 -0
  75. package/dist/commands/git/connect.js.map +1 -0
  76. package/dist/commands/git/disconnect.d.ts +9 -0
  77. package/dist/commands/git/disconnect.js +41 -0
  78. package/dist/commands/git/disconnect.js.map +1 -0
  79. package/dist/commands/{hello.d.ts → git.d.ts} +1 -1
  80. package/dist/commands/git.js +17 -0
  81. package/dist/commands/git.js.map +1 -0
  82. package/dist/commands/login.d.ts +6 -0
  83. package/dist/commands/login.js +34 -0
  84. package/dist/commands/login.js.map +1 -0
  85. package/dist/commands/logout.d.ts +6 -0
  86. package/dist/commands/logout.js +20 -0
  87. package/dist/commands/logout.js.map +1 -0
  88. package/dist/commands/logs.d.ts +16 -0
  89. package/dist/commands/logs.js +96 -0
  90. package/dist/commands/logs.js.map +1 -0
  91. package/dist/commands/telemetry/disable.d.ts +5 -0
  92. package/dist/commands/telemetry/disable.js +14 -0
  93. package/dist/commands/telemetry/disable.js.map +1 -0
  94. package/dist/commands/telemetry/enable.d.ts +5 -0
  95. package/dist/commands/telemetry/enable.js +13 -0
  96. package/dist/commands/telemetry/enable.js.map +1 -0
  97. package/dist/commands/telemetry/status.d.ts +5 -0
  98. package/dist/commands/telemetry/status.js +19 -0
  99. package/dist/commands/telemetry/status.js.map +1 -0
  100. package/dist/commands/whoami.d.ts +6 -0
  101. package/dist/commands/whoami.js +13 -0
  102. package/dist/commands/whoami.js.map +1 -0
  103. package/dist/env.d.ts +4 -0
  104. package/dist/env.js +10 -0
  105. package/dist/env.js.map +1 -0
  106. package/dist/lib/alpic-command.d.ts +6 -0
  107. package/dist/lib/alpic-command.js +27 -0
  108. package/dist/lib/alpic-command.js.map +1 -0
  109. package/dist/lib/archive.d.ts +7 -0
  110. package/dist/lib/archive.js +51 -0
  111. package/dist/lib/archive.js.map +1 -0
  112. package/dist/lib/auth/auth.d.ts +2 -0
  113. package/dist/lib/auth/auth.js +21 -0
  114. package/dist/lib/auth/auth.js.map +1 -0
  115. package/dist/lib/auth/oauth/client.d.ts +28 -0
  116. package/dist/lib/auth/oauth/client.js +110 -0
  117. package/dist/lib/auth/oauth/client.js.map +1 -0
  118. package/dist/lib/auth/oauth/constants.d.ts +2 -0
  119. package/dist/lib/auth/oauth/constants.js +3 -0
  120. package/dist/lib/auth/oauth/constants.js.map +1 -0
  121. package/dist/lib/auth/oauth/server/assets/alpic-mountain.png +0 -0
  122. package/dist/lib/auth/oauth/server/assets/authorize.html +195 -0
  123. package/dist/lib/auth/oauth/server/assets/callback.html +88 -0
  124. package/dist/lib/auth/oauth/server/index.d.ts +8 -0
  125. package/dist/lib/auth/oauth/server/index.js +102 -0
  126. package/dist/lib/auth/oauth/server/index.js.map +1 -0
  127. package/dist/lib/auth/whoami.d.ts +1 -0
  128. package/dist/lib/auth/whoami.js +41 -0
  129. package/dist/lib/auth/whoami.js.map +1 -0
  130. package/dist/lib/base-workflow.d.ts +10 -0
  131. package/dist/lib/base-workflow.js +22 -0
  132. package/dist/lib/base-workflow.js.map +1 -0
  133. package/dist/lib/config.d.ts +11 -0
  134. package/dist/lib/config.js +31 -0
  135. package/dist/lib/config.js.map +1 -0
  136. package/dist/lib/deployment.d.ts +73 -0
  137. package/dist/lib/deployment.js +112 -0
  138. package/dist/lib/deployment.js.map +1 -0
  139. package/dist/lib/environment-variable.d.ts +41 -0
  140. package/dist/lib/environment-variable.js +304 -0
  141. package/dist/lib/environment-variable.js.map +1 -0
  142. package/dist/lib/git.d.ts +22 -0
  143. package/dist/lib/git.js +131 -0
  144. package/dist/lib/git.js.map +1 -0
  145. package/dist/lib/global-store.d.ts +28 -0
  146. package/dist/lib/global-store.js +76 -0
  147. package/dist/lib/global-store.js.map +1 -0
  148. package/dist/lib/logs.d.ts +19 -0
  149. package/dist/lib/logs.js +83 -0
  150. package/dist/lib/logs.js.map +1 -0
  151. package/dist/lib/project.d.ts +74 -0
  152. package/dist/lib/project.js +306 -0
  153. package/dist/lib/project.js.map +1 -0
  154. package/dist/lib/table.d.ts +8 -0
  155. package/dist/lib/table.js +27 -0
  156. package/dist/lib/table.js.map +1 -0
  157. package/dist/lib/telemetry.d.ts +7 -0
  158. package/dist/lib/telemetry.js +66 -0
  159. package/dist/lib/telemetry.js.map +1 -0
  160. package/dist/lib/upload.d.ts +1 -0
  161. package/dist/lib/upload.js +14 -0
  162. package/dist/lib/upload.js.map +1 -0
  163. package/dist/lib/utils.d.ts +4 -0
  164. package/dist/lib/utils.js +21 -0
  165. package/dist/lib/utils.js.map +1 -0
  166. package/dist/lib/utils.test.d.ts +1 -0
  167. package/dist/lib/utils.test.js +21 -0
  168. package/dist/lib/utils.test.js.map +1 -0
  169. package/dist/posthog.d.ts +3 -0
  170. package/dist/posthog.js +10 -0
  171. package/dist/posthog.js.map +1 -0
  172. package/dist/types.d.ts +7 -0
  173. package/dist/types.js +2 -0
  174. package/dist/types.js.map +1 -0
  175. package/package.json +40 -10
  176. package/dist/commands/hello.js +0 -10
  177. package/dist/commands/hello.js.map +0 -1
@@ -0,0 +1,633 @@
1
+ import * as https from "node:https";
2
+ import { OpenAPIHandler } from "@orpc/openapi/node";
3
+ import { ORPCError, implement } from "@orpc/server";
4
+ import express, {} from "express";
5
+ import { randomUUID } from "node:crypto";
6
+ import { readFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { contract } from "@alpic-ai/api";
10
+ const __testDirname = dirname(fileURLToPath(import.meta.url));
11
+ const FIXTURE_CERT_PATH = join(__testDirname, "fixtures", "certs", "localhost-cert.pem");
12
+ const FIXTURE_KEY_PATH = join(__testDirname, "fixtures", "certs", "localhost-key.pem");
13
+ function getTlsAssets() {
14
+ return {
15
+ key: readFileSync(FIXTURE_KEY_PATH, "utf8"),
16
+ cert: readFileSync(FIXTURE_CERT_PATH, "utf8"),
17
+ certPath: FIXTURE_CERT_PATH,
18
+ };
19
+ }
20
+ export class MockApiServer {
21
+ server = null;
22
+ app;
23
+ port = null;
24
+ mockData;
25
+ callHistory = [];
26
+ constructor() {
27
+ this.app = express();
28
+ this.mockData = {
29
+ projects: new Map(),
30
+ environments: new Map(),
31
+ deployments: new Map(),
32
+ environmentVariables: new Map(),
33
+ runtimeLogs: new Map(),
34
+ runtimeLogPages: new Map(),
35
+ };
36
+ }
37
+ async start() {
38
+ if (this.server) {
39
+ throw new Error("Server is already running");
40
+ }
41
+ this.configureServer();
42
+ const tlsAssets = getTlsAssets();
43
+ process.env.NODE_EXTRA_CA_CERTS = tlsAssets.certPath;
44
+ const httpsOptions = { key: tlsAssets.key, cert: tlsAssets.cert };
45
+ return new Promise((resolve) => {
46
+ this.server = https.createServer(httpsOptions, this.app).listen(0, "127.0.0.1", () => {
47
+ if (!this.server) {
48
+ throw new Error("Server is not running");
49
+ }
50
+ const address = this.server.address();
51
+ this.port = address.port;
52
+ const url = `https://127.0.0.1:${this.port}`;
53
+ resolve(url);
54
+ });
55
+ });
56
+ }
57
+ configureServer() {
58
+ this.app.put("/__mock__upload/:token", express.raw({ type: "*/*", limit: "50mb" }), async (req, res) => {
59
+ const apiCall = {
60
+ method: req.method,
61
+ path: req.path,
62
+ timestamp: new Date(),
63
+ input: { token: req.params.token, size: req.body.length },
64
+ responseStatus: 200,
65
+ };
66
+ this.callHistory.push(apiCall);
67
+ res.status(200).end();
68
+ });
69
+ this.app.use(express.json());
70
+ this.app.get("/.well-known/oauth-protected-resource", (_req, res) => {
71
+ const base = `https://127.0.0.1:${this.port}`;
72
+ res.status(200).json({
73
+ resource: "https://api.alpic.ai",
74
+ authorization_servers: [base],
75
+ bearer_methods_supported: ["header"],
76
+ scopes_supported: ["openid", "email", "profile"],
77
+ resource_documentation: "https://docs.alpic.ai",
78
+ });
79
+ });
80
+ this.app.get("/.well-known/openid-configuration", (_req, res) => {
81
+ const base = `https://127.0.0.1:${this.port}`;
82
+ res.status(200).json({
83
+ issuer: base,
84
+ userinfo_endpoint: `${base}/oauth2/userInfo`,
85
+ authorization_endpoint: `${base}/oauth2/authorize`,
86
+ token_endpoint: `${base}/oauth2/token`,
87
+ jwks_uri: `${base}/.well-known/jwks.json`,
88
+ });
89
+ });
90
+ this.app.get("/oauth2/userInfo", (req, res) => {
91
+ const auth = req.headers.authorization;
92
+ if (!auth?.startsWith("Bearer ")) {
93
+ res.status(401).json({ error: "Missing or invalid Authorization" });
94
+ return;
95
+ }
96
+ res.status(200).json({
97
+ sub: "test-sub",
98
+ email_verified: "true",
99
+ identities: [],
100
+ name: "Test User",
101
+ email: "test@example.com",
102
+ picture: "",
103
+ username: "testuser",
104
+ });
105
+ });
106
+ const router = implement(contract).router({
107
+ tunnels: {
108
+ getTicket: {
109
+ v1: implement(contract.tunnels.getTicket.v1).handler(async () => {
110
+ return {
111
+ subdomain: "cool-mongoose-123",
112
+ ticket: "mock-ticket",
113
+ tunnelHost: "tunnel.alpic.dev",
114
+ };
115
+ }),
116
+ },
117
+ },
118
+ teams: {
119
+ list: {
120
+ v1: implement(contract.teams.list.v1).handler(async () => {
121
+ return [
122
+ {
123
+ id: "mock-team-id",
124
+ name: "Mock Team",
125
+ createdAt: new Date(),
126
+ hasStripeAccount: false,
127
+ },
128
+ ];
129
+ }),
130
+ },
131
+ },
132
+ analytics: {
133
+ get: {
134
+ v1: implement(contract.analytics.get.v1).handler(async ({ input }) => {
135
+ const project = this.mockData.projects.get(input.projectId);
136
+ if (!project) {
137
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
138
+ }
139
+ const emptyTimeSeries = {
140
+ sessions_count: [],
141
+ requests_count: [],
142
+ requests_latency_mean: [],
143
+ tool_errors: [],
144
+ mcp_errors: [],
145
+ output_token_mean: [],
146
+ task_count: [],
147
+ };
148
+ return {
149
+ metadata: {
150
+ startTimestamp: input.startTimestamp,
151
+ endTimestamp: input.endTimestamp,
152
+ timeZone: input.timeZone,
153
+ startDate: new Date(input.startTimestamp),
154
+ interval: "1h",
155
+ },
156
+ timeSeries: emptyTimeSeries,
157
+ };
158
+ }),
159
+ },
160
+ },
161
+ projects: {
162
+ list: {
163
+ v1: implement(contract.projects.list.v1).handler(async () => {
164
+ return Array.from(this.mockData.projects.values()).map((project) => ({
165
+ id: project.id,
166
+ name: project.name,
167
+ teamId: project.teamId,
168
+ environments: project.environments,
169
+ productionEnvironment: project.productionEnvironment,
170
+ sourceRepository: project.sourceRepository,
171
+ runtime: project.runtime,
172
+ transport: project.transport,
173
+ rootDirectory: project.rootDirectory,
174
+ buildCommand: project.buildCommand,
175
+ buildOutputDir: project.buildOutputDir,
176
+ installCommand: project.installCommand,
177
+ startCommand: project.startCommand,
178
+ createdAt: project.createdAt,
179
+ }));
180
+ }),
181
+ },
182
+ get: {
183
+ v1: implement(contract.projects.get.v1).handler(async ({ input }) => {
184
+ const project = this.mockData.projects.get(input.projectId);
185
+ if (!project) {
186
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
187
+ }
188
+ return project;
189
+ }),
190
+ },
191
+ create: {
192
+ v1: implement(contract.projects.create.v1).handler(async ({ input }) => {
193
+ const projectId = randomUUID();
194
+ const teamId = "mock-team-id";
195
+ const productionEnvId = randomUUID();
196
+ const productionEnvName = "production";
197
+ const project = {
198
+ id: projectId,
199
+ name: input.name,
200
+ teamId,
201
+ environments: [],
202
+ productionEnvironment: {
203
+ id: productionEnvId,
204
+ name: productionEnvName,
205
+ },
206
+ sourceRepository: input.sourceRepository ?? null,
207
+ runtime: input.runtime,
208
+ transport: input.transport ?? null,
209
+ rootDirectory: input.rootDirectory ?? null,
210
+ buildCommand: input.settings?.buildCommand ?? null,
211
+ buildOutputDir: input.settings?.buildOutputDir ?? null,
212
+ installCommand: input.settings?.installCommand ?? null,
213
+ startCommand: input.settings?.startCommand ?? null,
214
+ createdAt: new Date(),
215
+ };
216
+ const environment = {
217
+ id: productionEnvId,
218
+ name: productionEnvName,
219
+ sourceBranch: null,
220
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
221
+ domains: [`https://mcp-${projectId}.alpic.ai`],
222
+ createdAt: new Date(),
223
+ projectId,
224
+ };
225
+ this.mockData.environments.set(productionEnvId, environment);
226
+ const fullProject = {
227
+ ...project,
228
+ productionEnvironment: {
229
+ id: productionEnvId,
230
+ name: productionEnvName,
231
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
232
+ domains: [],
233
+ latestDeployment: null,
234
+ },
235
+ environments: [
236
+ {
237
+ id: productionEnvId,
238
+ name: productionEnvName,
239
+ sourceBranch: null,
240
+ mcpServerUrl: `https://mcp-${projectId}.alpic.ai`,
241
+ createdAt: new Date(),
242
+ projectId,
243
+ latestDeployment: null,
244
+ },
245
+ ],
246
+ };
247
+ this.mockData.projects.set(projectId, fullProject);
248
+ return project;
249
+ }),
250
+ },
251
+ update: {
252
+ v1: implement(contract.projects.update.v1).handler(async ({ input }) => {
253
+ const project = this.mockData.projects.get(input.projectId);
254
+ if (!project) {
255
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
256
+ }
257
+ if (input.sourceRepository !== undefined) {
258
+ project.sourceRepository = input.sourceRepository;
259
+ }
260
+ this.mockData.projects.set(input.projectId, project);
261
+ return project;
262
+ }),
263
+ },
264
+ delete: {
265
+ v1: implement(contract.projects.delete.v1).handler(async ({ input }) => {
266
+ const project = this.mockData.projects.get(input.projectId);
267
+ if (!project) {
268
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
269
+ }
270
+ this.mockData.projects.delete(input.projectId);
271
+ return { success: true };
272
+ }),
273
+ },
274
+ },
275
+ environments: {
276
+ create: {
277
+ v1: implement(contract.environments.create.v1).handler(async ({ input }) => {
278
+ const project = this.mockData.projects.get(input.projectId);
279
+ if (!project) {
280
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
281
+ }
282
+ const environmentId = randomUUID();
283
+ const mcpServerUrl = `https://mcp-${environmentId}.alpic.ai`;
284
+ const createdAt = new Date();
285
+ const environment = {
286
+ id: environmentId,
287
+ name: input.name,
288
+ sourceBranch: input.sourceBranch,
289
+ mcpServerUrl,
290
+ domains: [mcpServerUrl],
291
+ createdAt,
292
+ projectId: input.projectId,
293
+ };
294
+ this.mockData.environments.set(environmentId, environment);
295
+ this.mockData.projects.set(input.projectId, {
296
+ ...project,
297
+ environments: [
298
+ ...project.environments,
299
+ {
300
+ id: environmentId,
301
+ name: input.name,
302
+ sourceBranch: input.sourceBranch,
303
+ mcpServerUrl,
304
+ createdAt,
305
+ projectId: input.projectId,
306
+ latestDeployment: null,
307
+ },
308
+ ],
309
+ });
310
+ return {
311
+ id: environmentId,
312
+ name: input.name,
313
+ sourceBranch: input.sourceBranch,
314
+ createdAt,
315
+ projectId: input.projectId,
316
+ urls: [mcpServerUrl],
317
+ };
318
+ }),
319
+ },
320
+ get: {
321
+ v1: implement(contract.environments.get.v1).handler(async ({ input }) => {
322
+ const environment = this.mockData.environments.get(input.environmentId);
323
+ if (!environment) {
324
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
325
+ }
326
+ return environment;
327
+ }),
328
+ },
329
+ getLogs: {
330
+ v1: implement(contract.environments.getLogs.v1).handler(async ({ input }) => {
331
+ const environment = this.mockData.environments.get(input.environmentId);
332
+ if (!environment) {
333
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
334
+ }
335
+ const pagedLogs = this.mockData.runtimeLogPages.get(input.environmentId);
336
+ const pageIndex = input.nextToken === undefined ? 0 : Number.parseInt(input.nextToken, 10);
337
+ const allLogs = pagedLogs === undefined
338
+ ? (this.mockData.runtimeLogs.get(input.environmentId) ?? [])
339
+ : (pagedLogs[pageIndex] ?? []);
340
+ const logs = input.level === undefined
341
+ ? allLogs
342
+ : allLogs.filter((log) => input.level.includes(log.type));
343
+ const nextToken = pagedLogs === undefined || pageIndex + 1 >= pagedLogs.length ? null : String(pageIndex + 1);
344
+ return { logs, nextToken };
345
+ }),
346
+ },
347
+ deploy: {
348
+ v1: implement(contract.environments.deploy.v1).handler(async ({ input }) => {
349
+ const environment = this.mockData.environments.get(input.environmentId);
350
+ if (!environment) {
351
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
352
+ }
353
+ const deploymentId = randomUUID();
354
+ const deployment = {
355
+ id: deploymentId,
356
+ status: "ongoing",
357
+ environmentId: environment.id,
358
+ environmentName: environment.name,
359
+ isCurrent: false,
360
+ sourceRef: environment.sourceBranch,
361
+ sourceCommitId: randomUUID().slice(0, 7),
362
+ sourceCommitMessage: "Mock deployment",
363
+ authorUsername: "test-user",
364
+ authorAvatarUrl: null,
365
+ startedAt: new Date(),
366
+ completedAt: null,
367
+ deploymentPageUrl: "https://app.alpic.ai/deployments/mock",
368
+ };
369
+ this.mockData.deployments.set(deploymentId, deployment);
370
+ return deployment;
371
+ }),
372
+ },
373
+ },
374
+ environmentVariables: {
375
+ list: {
376
+ v1: implement(contract.environmentVariables.list.v1).handler(async ({ input }) => {
377
+ const environment = this.mockData.environments.get(input.environmentId);
378
+ if (!environment) {
379
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
380
+ }
381
+ return this.mockData.environmentVariables.get(input.environmentId) ?? [];
382
+ }),
383
+ },
384
+ create: {
385
+ v1: implement(contract.environmentVariables.create.v1).handler(async ({ input }) => {
386
+ const environment = this.mockData.environments.get(input.environmentId);
387
+ if (!environment) {
388
+ throw new ORPCError("NOT_FOUND", { message: "Environment not found" });
389
+ }
390
+ const existing = this.mockData.environmentVariables.get(input.environmentId) ?? [];
391
+ const newVars = input.environmentVariables.map((variable) => ({
392
+ id: randomUUID(),
393
+ key: variable.key,
394
+ value: variable.value,
395
+ isSecret: variable.isSecret,
396
+ createdAt: new Date(),
397
+ }));
398
+ for (const newVar of newVars) {
399
+ if (existing.some((existingVar) => existingVar.key === newVar.key)) {
400
+ throw new ORPCError("BAD_REQUEST", {
401
+ message: `Environment variable "${newVar.key}" already exists`,
402
+ });
403
+ }
404
+ }
405
+ this.mockData.environmentVariables.set(input.environmentId, [...existing, ...newVars]);
406
+ return { success: true };
407
+ }),
408
+ },
409
+ update: {
410
+ v1: implement(contract.environmentVariables.update.v1).handler(async ({ input }) => {
411
+ for (const [environmentId, variables] of this.mockData.environmentVariables.entries()) {
412
+ const index = variables.findIndex((variable) => variable.id === input.environmentVariableId);
413
+ if (index !== -1) {
414
+ const updated = variables.map((variable, i) => i === index
415
+ ? { ...variable, key: input.key, value: input.value ?? variable.value, isSecret: input.isSecret }
416
+ : variable);
417
+ this.mockData.environmentVariables.set(environmentId, updated);
418
+ return { success: true };
419
+ }
420
+ }
421
+ throw new ORPCError("NOT_FOUND", { message: "Environment variable not found" });
422
+ }),
423
+ },
424
+ delete: {
425
+ v1: implement(contract.environmentVariables.delete.v1).handler(async ({ input }) => {
426
+ for (const [environmentId, variables] of this.mockData.environmentVariables.entries()) {
427
+ const index = variables.findIndex((variable) => variable.id === input.environmentVariableId);
428
+ if (index !== -1) {
429
+ this.mockData.environmentVariables.set(environmentId, variables.filter((_, i) => i !== index));
430
+ return { success: true };
431
+ }
432
+ }
433
+ throw new ORPCError("NOT_FOUND", { message: "Environment variable not found" });
434
+ }),
435
+ },
436
+ },
437
+ deployments: {
438
+ list: {
439
+ v1: implement(contract.deployments.list.v1).handler(async ({ input }) => {
440
+ const project = this.mockData.projects.get(input.projectId);
441
+ if (!project) {
442
+ throw new ORPCError("NOT_FOUND", { message: "Project not found" });
443
+ }
444
+ let deployments = Array.from(this.mockData.deployments.values());
445
+ if (input.environmentId) {
446
+ deployments = deployments.filter((deployment) => deployment.environmentId === input.environmentId);
447
+ }
448
+ if (input.status?.length) {
449
+ deployments = deployments.filter((deployment) => input.status.includes(deployment.status));
450
+ }
451
+ return deployments.map((deployment) => ({
452
+ ...deployment,
453
+ isCurrent: deployment.status === "deployed",
454
+ }));
455
+ }),
456
+ },
457
+ get: {
458
+ v1: implement(contract.deployments.get.v1).handler(async ({ input }) => {
459
+ const deployment = this.mockData.deployments.get(input.deploymentId);
460
+ if (!deployment) {
461
+ throw new ORPCError("NOT_FOUND", { message: "Deployment not found" });
462
+ }
463
+ if (deployment.status === "ongoing") {
464
+ const updatedDeployment = {
465
+ ...deployment,
466
+ status: "deployed",
467
+ completedAt: new Date(),
468
+ deploymentPageUrl: deployment.deploymentPageUrl ?? null,
469
+ };
470
+ this.mockData.deployments.set(input.deploymentId, updatedDeployment);
471
+ return updatedDeployment;
472
+ }
473
+ return deployment;
474
+ }),
475
+ },
476
+ getLogs: {
477
+ v1: implement(contract.deployments.getLogs.v1).handler(async ({ input }) => {
478
+ const deployment = this.mockData.deployments.get(input.deploymentId);
479
+ if (!deployment) {
480
+ throw new ORPCError("NOT_FOUND", { message: "Deployment not found" });
481
+ }
482
+ return {
483
+ logs: [{ timestamp: new Date(), content: "Mock log entry" }],
484
+ hasMoreLogs: false,
485
+ };
486
+ }),
487
+ },
488
+ uploadArtifact: {
489
+ v1: implement(contract.deployments.uploadArtifact.v1).handler(async () => {
490
+ const token = randomUUID();
491
+ const baseUrl = `https://127.0.0.1:${this.port}`;
492
+ const uploadUrl = `${baseUrl}/__mock__upload/${token}`;
493
+ return {
494
+ uploadUrl,
495
+ token,
496
+ expiresAt: new Date(Date.now() + 3600000),
497
+ };
498
+ }),
499
+ },
500
+ },
501
+ });
502
+ const handler = new OpenAPIHandler(router);
503
+ this.app.use(async (req, res) => {
504
+ const apiCall = {
505
+ method: req.method,
506
+ path: req.path,
507
+ timestamp: new Date(),
508
+ };
509
+ if (req.method === "GET") {
510
+ if (Object.keys(req.query).length > 0) {
511
+ apiCall.input = req.query;
512
+ }
513
+ }
514
+ else if (req.body) {
515
+ apiCall.input = req.body;
516
+ }
517
+ const result = await handler.handle(req, res, {
518
+ context: {},
519
+ });
520
+ if (!result.matched) {
521
+ apiCall.responseStatus = 404;
522
+ this.callHistory.push(apiCall);
523
+ res.status(404).json({ error: "Not found" });
524
+ return;
525
+ }
526
+ apiCall.responseStatus = res.statusCode || 200;
527
+ this.callHistory.push(apiCall);
528
+ });
529
+ }
530
+ async stop() {
531
+ return new Promise((resolve, reject) => {
532
+ if (!this.server) {
533
+ resolve();
534
+ return;
535
+ }
536
+ this.server.close((error) => {
537
+ if (error) {
538
+ console.error("[MOCK] Error stopping server:", error);
539
+ reject(error);
540
+ }
541
+ else {
542
+ this.server = null;
543
+ resolve();
544
+ }
545
+ });
546
+ });
547
+ }
548
+ getCalls(method, pathPattern) {
549
+ return this.callHistory.filter((call) => {
550
+ if (method && call.method !== method)
551
+ return false;
552
+ if (pathPattern) {
553
+ if (typeof pathPattern === "string") {
554
+ if (!call.path.includes(pathPattern))
555
+ return false;
556
+ }
557
+ else {
558
+ if (!pathPattern.test(call.path))
559
+ return false;
560
+ }
561
+ }
562
+ return true;
563
+ });
564
+ }
565
+ getLastCall(method, pathPattern) {
566
+ for (let i = this.callHistory.length - 1; i >= 0; i--) {
567
+ const call = this.callHistory[i];
568
+ if (!call)
569
+ continue;
570
+ if (method && call.method !== method)
571
+ continue;
572
+ if (pathPattern) {
573
+ if (typeof pathPattern === "string") {
574
+ if (!call.path.includes(pathPattern))
575
+ continue;
576
+ }
577
+ else {
578
+ if (!pathPattern.test(call.path))
579
+ continue;
580
+ }
581
+ }
582
+ return call;
583
+ }
584
+ return undefined;
585
+ }
586
+ addEnvironmentVariables(environmentId, variables) {
587
+ this.mockData.environmentVariables.set(environmentId, variables);
588
+ }
589
+ setRuntimeLogs(environmentId, logs) {
590
+ this.mockData.runtimeLogs.set(environmentId, logs);
591
+ this.mockData.runtimeLogPages.delete(environmentId);
592
+ }
593
+ setRuntimeLogPages(environmentId, pages) {
594
+ this.mockData.runtimeLogPages.set(environmentId, pages);
595
+ this.mockData.runtimeLogs.delete(environmentId);
596
+ }
597
+ addDeployments(deployments) {
598
+ for (const deployment of deployments) {
599
+ this.mockData.deployments.set(deployment.id, {
600
+ ...deployment,
601
+ deploymentPageUrl: null,
602
+ });
603
+ }
604
+ }
605
+ addProject(project) {
606
+ this.mockData.projects.set(project.id, project);
607
+ if (project.productionEnvironment) {
608
+ const env = {
609
+ id: project.productionEnvironment.id,
610
+ name: project.productionEnvironment.name,
611
+ sourceBranch: null,
612
+ mcpServerUrl: project.productionEnvironment.mcpServerUrl,
613
+ domains: [project.productionEnvironment.mcpServerUrl],
614
+ createdAt: new Date(),
615
+ projectId: project.id,
616
+ };
617
+ this.mockData.environments.set(env.id, env);
618
+ }
619
+ for (const env of project.environments) {
620
+ const fullEnv = {
621
+ id: env.id,
622
+ name: env.name,
623
+ sourceBranch: env.sourceBranch,
624
+ mcpServerUrl: env.mcpServerUrl,
625
+ domains: [env.mcpServerUrl],
626
+ createdAt: env.createdAt,
627
+ projectId: project.id,
628
+ };
629
+ this.mockData.environments.set(env.id, fullEnv);
630
+ }
631
+ }
632
+ }
633
+ //# sourceMappingURL=mock-server.js.map