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