@hoststack.dev/sdk 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -35,27 +35,32 @@ var CronResource = class {
35
35
  }
36
36
  /** List cron executions for a service. */
37
37
  async list(teamId, serviceId, options) {
38
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
39
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
38
40
  const params = new URLSearchParams();
39
41
  if (options?.limit) params.set("limit", String(options.limit));
40
42
  const qs = params.toString();
41
43
  return this.client.request(
42
44
  "GET",
43
- `/api/services/${teamId}/${serviceId}/cron-executions${qs ? `?${qs}` : ""}`
45
+ `/api/services/${tid}/${sid}/cron-executions${qs ? `?${qs}` : ""}`
44
46
  );
45
47
  }
46
48
  /** Get a single cron execution by ID. */
47
49
  async get(teamId, serviceId, executionId) {
48
- return this.client.request(
49
- "GET",
50
- `/api/services/${teamId}/${serviceId}/cron-executions/${executionId}`
51
- );
50
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
51
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
52
+ const eid = await this.client.resolveId(executionId, {
53
+ kind: "cronExecution",
54
+ teamId: tid,
55
+ serviceId: sid
56
+ });
57
+ return this.client.request("GET", `/api/services/${tid}/${sid}/cron-executions/${eid}`);
52
58
  }
53
59
  /** Trigger an immediate cron execution. */
54
60
  async trigger(teamId, serviceId) {
55
- return this.client.request(
56
- "POST",
57
- `/api/services/${teamId}/${serviceId}/cron-executions/trigger`
58
- );
61
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
62
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
63
+ return this.client.request("POST", `/api/services/${tid}/${sid}/cron-executions/trigger`);
59
64
  }
60
65
  };
61
66
 
@@ -66,39 +71,56 @@ var DatabasesResource = class {
66
71
  }
67
72
  /** List all databases for a project. */
68
73
  async list(teamId, projectId) {
69
- return this.client.request("GET", `/api/databases/${teamId}?projectId=${projectId}`);
74
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
75
+ const pid = await this.client.resolveId(projectId, { kind: "project", teamId: tid });
76
+ return this.client.request("GET", `/api/databases/${tid}?projectId=${pid}`);
70
77
  }
71
78
  /** Get a single database by ID. */
72
79
  async get(teamId, databaseId) {
73
- return this.client.request("GET", `/api/databases/${teamId}/${databaseId}`);
80
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
81
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
82
+ return this.client.request("GET", `/api/databases/${tid}/${did}`);
74
83
  }
75
84
  /** Create a new database. */
76
85
  async create(teamId, data) {
77
- return this.client.request("POST", `/api/databases/${teamId}`, data);
86
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
87
+ return this.client.request("POST", `/api/databases/${tid}`, data);
78
88
  }
79
89
  /** Update a database. */
80
90
  async update(teamId, databaseId, data) {
81
- return this.client.request("PATCH", `/api/databases/${teamId}/${databaseId}`, data);
91
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
92
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
93
+ return this.client.request("PATCH", `/api/databases/${tid}/${did}`, data);
82
94
  }
83
95
  /** Delete a database. */
84
96
  async delete(teamId, databaseId) {
85
- return this.client.request("DELETE", `/api/databases/${teamId}/${databaseId}`);
97
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
98
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
99
+ return this.client.request("DELETE", `/api/databases/${tid}/${did}`);
86
100
  }
87
101
  /** Suspend a database. */
88
102
  async suspend(teamId, databaseId) {
89
- return this.client.request("POST", `/api/databases/${teamId}/${databaseId}/suspend`);
103
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
104
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
105
+ return this.client.request("POST", `/api/databases/${tid}/${did}/suspend`);
90
106
  }
91
107
  /** Resume a suspended database. */
92
108
  async resume(teamId, databaseId) {
93
- return this.client.request("POST", `/api/databases/${teamId}/${databaseId}/resume`);
109
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
110
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
111
+ return this.client.request("POST", `/api/databases/${tid}/${did}/resume`);
94
112
  }
95
113
  /** Get connection credentials. */
96
114
  async getCredentials(teamId, databaseId) {
97
- return this.client.request("GET", `/api/databases/${teamId}/${databaseId}/credentials`);
115
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
116
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
117
+ return this.client.request("GET", `/api/databases/${tid}/${did}/credentials`);
98
118
  }
99
119
  /** Reset the database password. */
100
120
  async resetPassword(teamId, databaseId) {
101
- return this.client.request("POST", `/api/databases/${teamId}/${databaseId}/reset-password`);
121
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
122
+ const did = await this.client.resolveId(databaseId, { kind: "database", teamId: tid });
123
+ return this.client.request("POST", `/api/databases/${tid}/${did}/reset-password`);
102
124
  }
103
125
  };
104
126
 
@@ -107,45 +129,84 @@ var DeploysResource = class {
107
129
  constructor(client) {
108
130
  this.client = client;
109
131
  }
110
- /** List deploys for a service. */
111
- async list(teamId, serviceId) {
112
- return this.client.request("GET", `/api/services/${teamId}/${serviceId}/deploys`);
113
- }
114
- /** Get a single deploy by ID. */
115
- async get(teamId, serviceId, deployId) {
132
+ /**
133
+ * List deploys for a service. Paginated — pass `page` / `perPage` to walk
134
+ * pages. Default page=1, perPage=25, hard cap perPage=100.
135
+ */
136
+ async list(teamId, serviceId, options) {
137
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
138
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
139
+ const params = new URLSearchParams();
140
+ if (options?.page !== void 0) params.set("page", String(options.page));
141
+ if (options?.perPage !== void 0) params.set("perPage", String(options.perPage));
142
+ const qs = params.toString();
116
143
  return this.client.request(
117
144
  "GET",
118
- `/api/services/${teamId}/${serviceId}/deploys/${deployId}`
145
+ `/api/services/${tid}/${sid}/deploys${qs ? `?${qs}` : ""}`
119
146
  );
120
147
  }
148
+ /** Get a single deploy by ID. */
149
+ async get(teamId, serviceId, deployId) {
150
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
151
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
152
+ const did = await this.client.resolveId(deployId, {
153
+ kind: "deploy",
154
+ teamId: tid,
155
+ serviceId: sid
156
+ });
157
+ return this.client.request("GET", `/api/services/${tid}/${sid}/deploys/${did}`);
158
+ }
121
159
  /** Trigger a new deploy. */
122
160
  async trigger(teamId, serviceId, data) {
123
- return this.client.request(
124
- "POST",
125
- `/api/services/${teamId}/${serviceId}/deploys`,
126
- data ?? {}
127
- );
161
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
162
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
163
+ return this.client.request("POST", `/api/services/${tid}/${sid}/deploys`, data ?? {});
128
164
  }
129
165
  /** Cancel an in-progress deploy. */
130
166
  async cancel(teamId, serviceId, deployId) {
131
- return this.client.request(
132
- "POST",
133
- `/api/services/${teamId}/${serviceId}/deploys/${deployId}/cancel`
134
- );
167
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
168
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
169
+ const did = await this.client.resolveId(deployId, {
170
+ kind: "deploy",
171
+ teamId: tid,
172
+ serviceId: sid
173
+ });
174
+ return this.client.request("POST", `/api/services/${tid}/${sid}/deploys/${did}/cancel`);
135
175
  }
136
176
  /** Rollback to a previous deploy. */
137
177
  async rollback(teamId, serviceId, deployId) {
138
- return this.client.request(
139
- "POST",
140
- `/api/services/${teamId}/${serviceId}/deploys/${deployId}/rollback`
141
- );
178
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
179
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
180
+ const did = await this.client.resolveId(deployId, {
181
+ kind: "deploy",
182
+ teamId: tid,
183
+ serviceId: sid
184
+ });
185
+ return this.client.request("POST", `/api/services/${tid}/${sid}/deploys/${did}/rollback`);
142
186
  }
143
- /** Get build logs for a deploy. */
144
- async getLogs(teamId, serviceId, deployId) {
145
- return this.client.request(
146
- "GET",
147
- `/api/services/${teamId}/${serviceId}/deploys/${deployId}/logs`
148
- );
187
+ /**
188
+ * Get build logs for a deploy.
189
+ *
190
+ * Pagination: pass `afterId` from the previous response's `nextAfterId`
191
+ * to fetch the next page. Per-call cap is 5000; default 500.
192
+ */
193
+ async getLogs(teamId, serviceId, deployId, options) {
194
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
195
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
196
+ const did = await this.client.resolveId(deployId, {
197
+ kind: "deploy",
198
+ teamId: tid,
199
+ serviceId: sid
200
+ });
201
+ const params = new URLSearchParams();
202
+ if (options?.search) params.set("search", options.search);
203
+ if (options?.level) params.set("level", options.level);
204
+ if (options?.phase) params.set("phase", options.phase);
205
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
206
+ if (options?.afterId !== void 0) params.set("afterId", String(options.afterId));
207
+ const qs = params.toString();
208
+ const url = `/api/services/${tid}/${sid}/deploys/${did}/logs${qs ? `?${qs}` : ""}`;
209
+ return this.client.request("GET", url);
149
210
  }
150
211
  };
151
212
 
@@ -156,23 +217,31 @@ var DomainsResource = class {
156
217
  }
157
218
  /** List all domains for the active team. */
158
219
  async list(teamId) {
159
- return this.client.request("GET", `/api/domains/${teamId}`);
220
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
221
+ return this.client.request("GET", `/api/domains/${tid}`);
160
222
  }
161
223
  /** Add a custom domain. */
162
224
  async add(teamId, data) {
163
- return this.client.request("POST", `/api/domains/${teamId}`, data);
225
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
226
+ return this.client.request("POST", `/api/domains/${tid}`, data);
164
227
  }
165
228
  /** Update a domain. */
166
229
  async update(teamId, domainId, data) {
167
- return this.client.request("PATCH", `/api/domains/${teamId}/${domainId}`, data);
230
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
231
+ const did = await this.client.resolveId(domainId, { kind: "domain", teamId: tid });
232
+ return this.client.request("PATCH", `/api/domains/${tid}/${did}`, data);
168
233
  }
169
234
  /** Remove a domain. */
170
235
  async remove(teamId, domainId) {
171
- return this.client.request("DELETE", `/api/domains/${teamId}/${domainId}`);
236
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
237
+ const did = await this.client.resolveId(domainId, { kind: "domain", teamId: tid });
238
+ return this.client.request("DELETE", `/api/domains/${tid}/${did}`);
172
239
  }
173
240
  /** Verify domain DNS configuration. */
174
241
  async verify(teamId, domainId) {
175
- return this.client.request("POST", `/api/domains/${teamId}/${domainId}/verify`);
242
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
243
+ const did = await this.client.resolveId(domainId, { kind: "domain", teamId: tid });
244
+ return this.client.request("POST", `/api/domains/${tid}/${did}/verify`);
176
245
  }
177
246
  };
178
247
 
@@ -183,30 +252,43 @@ var EnvVarsResource = class {
183
252
  }
184
253
  /** List all environment variables for a service. */
185
254
  async list(teamId, serviceId) {
186
- return this.client.request("GET", `/api/services/${teamId}/${serviceId}/env`);
255
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
256
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
257
+ return this.client.request("GET", `/api/services/${tid}/${sid}/env`);
187
258
  }
188
259
  /** Create a new environment variable. */
189
260
  async create(teamId, serviceId, data) {
190
- return this.client.request("POST", `/api/services/${teamId}/${serviceId}/env`, data);
261
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
262
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
263
+ return this.client.request("POST", `/api/services/${tid}/${sid}/env`, data);
191
264
  }
192
265
  /** Update an environment variable. */
193
266
  async update(teamId, serviceId, envVarId, data) {
194
- return this.client.request(
195
- "PATCH",
196
- `/api/services/${teamId}/${serviceId}/env/${envVarId}`,
197
- data
198
- );
267
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
268
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
269
+ const eid = await this.client.resolveId(envVarId, {
270
+ kind: "envVar",
271
+ teamId: tid,
272
+ serviceId: sid
273
+ });
274
+ return this.client.request("PATCH", `/api/services/${tid}/${sid}/env/${eid}`, data);
199
275
  }
200
276
  /** Delete an environment variable. */
201
277
  async delete(teamId, serviceId, envVarId) {
202
- return this.client.request(
203
- "DELETE",
204
- `/api/services/${teamId}/${serviceId}/env/${envVarId}`
205
- );
278
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
279
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
280
+ const eid = await this.client.resolveId(envVarId, {
281
+ kind: "envVar",
282
+ teamId: tid,
283
+ serviceId: sid
284
+ });
285
+ return this.client.request("DELETE", `/api/services/${tid}/${sid}/env/${eid}`);
206
286
  }
207
287
  /** Bulk set environment variables (create or update). */
208
288
  async bulkSet(teamId, serviceId, data) {
209
- return this.client.request("PUT", `/api/services/${teamId}/${serviceId}/env/bulk`, data);
289
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
290
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
291
+ return this.client.request("PUT", `/api/services/${tid}/${sid}/env/bulk`, data);
210
292
  }
211
293
  };
212
294
 
@@ -217,23 +299,31 @@ var ProjectsResource = class {
217
299
  }
218
300
  /** List all projects for the active team. */
219
301
  async list(teamId) {
220
- return this.client.request("GET", `/api/projects/${teamId}`);
302
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
303
+ return this.client.request("GET", `/api/projects/${tid}`);
221
304
  }
222
305
  /** Get a single project by ID. */
223
306
  async get(teamId, projectId) {
224
- return this.client.request("GET", `/api/projects/${teamId}/${projectId}`);
307
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
308
+ const pid = await this.client.resolveId(projectId, { kind: "project", teamId: tid });
309
+ return this.client.request("GET", `/api/projects/${tid}/${pid}`);
225
310
  }
226
311
  /** Create a new project. */
227
312
  async create(teamId, data) {
228
- return this.client.request("POST", `/api/projects/${teamId}`, data);
313
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
314
+ return this.client.request("POST", `/api/projects/${tid}`, data);
229
315
  }
230
316
  /** Update a project. */
231
317
  async update(teamId, projectId, data) {
232
- return this.client.request("PATCH", `/api/projects/${teamId}/${projectId}`, data);
318
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
319
+ const pid = await this.client.resolveId(projectId, { kind: "project", teamId: tid });
320
+ return this.client.request("PATCH", `/api/projects/${tid}/${pid}`, data);
233
321
  }
234
322
  /** Delete a project. */
235
323
  async delete(teamId, projectId) {
236
- return this.client.request("DELETE", `/api/projects/${teamId}/${projectId}`);
324
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
325
+ const pid = await this.client.resolveId(projectId, { kind: "project", teamId: tid });
326
+ return this.client.request("DELETE", `/api/projects/${tid}/${pid}`);
237
327
  }
238
328
  };
239
329
 
@@ -301,46 +391,66 @@ var ServicesResource = class {
301
391
  }
302
392
  /** List all services for the active team. */
303
393
  async list(teamId) {
304
- return this.client.request("GET", `/api/services/${teamId}`);
394
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
395
+ return this.client.request("GET", `/api/services/${tid}`);
305
396
  }
306
397
  /** Get a single service by ID. */
307
398
  async get(teamId, serviceId) {
308
- return this.client.request("GET", `/api/services/${teamId}/${serviceId}`);
399
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
400
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
401
+ return this.client.request("GET", `/api/services/${tid}/${sid}`);
309
402
  }
310
403
  /** Create a new service. */
311
404
  async create(teamId, data) {
312
- return this.client.request("POST", `/api/services/${teamId}`, data);
405
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
406
+ return this.client.request("POST", `/api/services/${tid}`, data);
313
407
  }
314
408
  /** Update a service. */
315
409
  async update(teamId, serviceId, data) {
316
- return this.client.request("PATCH", `/api/services/${teamId}/${serviceId}`, data);
410
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
411
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
412
+ return this.client.request("PATCH", `/api/services/${tid}/${sid}`, data);
317
413
  }
318
414
  /** Delete a service. */
319
415
  async delete(teamId, serviceId) {
320
- return this.client.request("DELETE", `/api/services/${teamId}/${serviceId}`);
416
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
417
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
418
+ return this.client.request("DELETE", `/api/services/${tid}/${sid}`);
321
419
  }
322
420
  /** Suspend a service. */
323
421
  async suspend(teamId, serviceId) {
324
- return this.client.request("POST", `/api/services/${teamId}/${serviceId}/suspend`);
422
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
423
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
424
+ return this.client.request("POST", `/api/services/${tid}/${sid}/suspend`);
325
425
  }
326
426
  /** Resume a suspended service. */
327
427
  async resume(teamId, serviceId) {
328
- return this.client.request("POST", `/api/services/${teamId}/${serviceId}/resume`);
428
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
429
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
430
+ return this.client.request("POST", `/api/services/${tid}/${sid}/resume`);
329
431
  }
330
432
  /** Get service metrics. */
331
433
  async getMetrics(teamId, serviceId) {
332
- return this.client.request("GET", `/api/services/${teamId}/${serviceId}/metrics`);
434
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
435
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
436
+ return this.client.request("GET", `/api/services/${tid}/${sid}/metrics`);
333
437
  }
334
438
  /** Get service configuration. */
335
439
  async getConfig(teamId, serviceId) {
336
- return this.client.request("GET", `/api/services/${teamId}/${serviceId}/config`);
440
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
441
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
442
+ return this.client.request("GET", `/api/services/${tid}/${sid}/config`);
337
443
  }
338
444
  /** Update service configuration. */
339
445
  async updateConfig(teamId, serviceId, data) {
340
- return this.client.request("PATCH", `/api/services/${teamId}/${serviceId}/config`, data);
446
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
447
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
448
+ return this.client.request("PATCH", `/api/services/${tid}/${sid}/config`, data);
341
449
  }
342
450
  /** Get runtime logs for a service. */
343
451
  async getRuntimeLogs(teamId, serviceId, options) {
452
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
453
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
344
454
  const params = new URLSearchParams();
345
455
  if (options?.lines) params.set("lines", String(options.lines));
346
456
  if (options?.since) params.set("since", options.since);
@@ -348,7 +458,7 @@ var ServicesResource = class {
348
458
  const qs = params.toString();
349
459
  return this.client.request(
350
460
  "GET",
351
- `/api/services/${teamId}/${serviceId}/runtime-logs${qs ? `?${qs}` : ""}`
461
+ `/api/services/${tid}/${sid}/runtime-logs${qs ? `?${qs}` : ""}`
352
462
  );
353
463
  }
354
464
  /**
@@ -363,9 +473,11 @@ var ServicesResource = class {
363
473
  * }
364
474
  * ```
365
475
  */
366
- streamLogs(teamId, serviceId, options) {
367
- const basePath = `/api/services/${teamId}/${serviceId}/runtime-logs`;
368
- return streamLogsViaPolling(
476
+ async *streamLogs(teamId, serviceId, options) {
477
+ const tid = await this.client.resolveId(teamId, { kind: "team" });
478
+ const sid = await this.client.resolveId(serviceId, { kind: "service", teamId: tid });
479
+ const basePath = `/api/services/${tid}/${sid}/runtime-logs`;
480
+ yield* streamLogsViaPolling(
369
481
  (path) => this.client.request("GET", path),
370
482
  basePath,
371
483
  options
@@ -374,9 +486,21 @@ var ServicesResource = class {
374
486
  };
375
487
 
376
488
  // src/client.ts
489
+ var PREFIX = {
490
+ team: "team_",
491
+ project: "prj_",
492
+ service: "svc_",
493
+ deploy: "dpl_",
494
+ database: "db_",
495
+ domain: "dom_",
496
+ envVar: "env_",
497
+ cronExecution: "cjob_"
498
+ };
377
499
  var HostStack = class {
378
500
  apiKey;
379
501
  baseUrl;
502
+ // publicId → numeric id, scoped by parent context. Lifetime: client instance.
503
+ idCache = /* @__PURE__ */ new Map();
380
504
  /** Manage projects. */
381
505
  projects;
382
506
  /** Manage services (web, worker, cron). */
@@ -441,7 +565,109 @@ var HostStack = class {
441
565
  }
442
566
  return res.json();
443
567
  }
568
+ /**
569
+ * Resolve a publicId-or-numeric id input to a numeric database id. Numeric
570
+ * inputs short-circuit; publicIds (svc_xyz, dpl_xyz, etc.) are looked up
571
+ * via the relevant list endpoint and cached on this client instance.
572
+ *
573
+ * The API addresses everything by numeric id internally; this resolver lets
574
+ * SDK/MCP consumers pass either form interchangeably without burning extra
575
+ * round-trips on subsequent calls.
576
+ */
577
+ async resolveId(input, scope) {
578
+ if (typeof input === "number") return input;
579
+ if (/^\d+$/.test(input)) return Number.parseInt(input, 10);
580
+ const expectedPrefix = PREFIX[scope.kind];
581
+ if (!input.startsWith(expectedPrefix)) {
582
+ throw new HostStackError(
583
+ 400,
584
+ `Invalid ${scope.kind} id "${input}": expected ${expectedPrefix}xxx or numeric.`
585
+ );
586
+ }
587
+ const cacheKey = `${cacheScope(scope)}:${input}`;
588
+ const cached = this.idCache.get(cacheKey);
589
+ if (cached !== void 0) return cached;
590
+ const items = await this.fetchForResolution(scope);
591
+ const match = items.find((it) => it.publicId === input);
592
+ if (!match) {
593
+ throw new NotFoundError(`${scope.kind} ${input} not found`);
594
+ }
595
+ this.idCache.set(cacheKey, match.id);
596
+ return match.id;
597
+ }
598
+ async fetchForResolution(scope) {
599
+ switch (scope.kind) {
600
+ case "team": {
601
+ const r = await this.request(
602
+ "GET",
603
+ "/api/teams"
604
+ );
605
+ return r.teams ?? [];
606
+ }
607
+ case "project": {
608
+ const r = await this.request(
609
+ "GET",
610
+ `/api/projects/${scope.teamId}`
611
+ );
612
+ return r.projects ?? [];
613
+ }
614
+ case "service": {
615
+ const r = await this.request(
616
+ "GET",
617
+ `/api/services/${scope.teamId}`
618
+ );
619
+ return r.services ?? [];
620
+ }
621
+ case "deploy": {
622
+ const r = await this.request(
623
+ "GET",
624
+ `/api/services/${scope.teamId}/${scope.serviceId}/deploys?perPage=100`
625
+ );
626
+ return r.data ?? [];
627
+ }
628
+ case "database": {
629
+ const r = await this.request(
630
+ "GET",
631
+ `/api/databases/${scope.teamId}`
632
+ );
633
+ return r.databases ?? [];
634
+ }
635
+ case "domain": {
636
+ const r = await this.request(
637
+ "GET",
638
+ `/api/domains/${scope.teamId}`
639
+ );
640
+ return r.domains ?? [];
641
+ }
642
+ case "envVar": {
643
+ const r = await this.request(
644
+ "GET",
645
+ `/api/services/${scope.teamId}/${scope.serviceId}/env`
646
+ );
647
+ return r.envVars ?? [];
648
+ }
649
+ case "cronExecution": {
650
+ const r = await this.request("GET", `/api/services/${scope.teamId}/${scope.serviceId}/cron-executions`);
651
+ return r.executions ?? [];
652
+ }
653
+ }
654
+ }
444
655
  };
656
+ function cacheScope(scope) {
657
+ switch (scope.kind) {
658
+ case "team":
659
+ return "team";
660
+ case "project":
661
+ case "service":
662
+ case "database":
663
+ case "domain":
664
+ return `${scope.kind}:${scope.teamId}`;
665
+ case "deploy":
666
+ case "envVar":
667
+ case "cronExecution":
668
+ return `${scope.kind}:${scope.teamId}:${scope.serviceId}`;
669
+ }
670
+ }
445
671
 
446
672
  // src/pagination.ts
447
673
  function buildPaginationQuery(params) {