@slicervm/sdk 0.1.6 → 0.1.7

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
@@ -266,6 +266,7 @@ function createVMReqToWire(r) {
266
266
  if (r.ip !== void 0) o.ip = r.ip;
267
267
  if (r.tags !== void 0) o.tags = r.tags;
268
268
  if (r.secrets !== void 0) o.secrets = r.secrets;
269
+ if (r.network !== void 0) o.network = r.network;
269
270
  return o;
270
271
  }
271
272
  function createVMResFromWire(w) {
@@ -1262,17 +1263,173 @@ function buildListQuery(opts) {
1262
1263
  return s ? `?${s}` : "";
1263
1264
  }
1264
1265
 
1266
+ // src/proxy.ts
1267
+ var ProxySecretBearer = "bearer";
1268
+ var ProxySecretBasic = "basic";
1269
+ function clientFromWire(w) {
1270
+ return { name: w.name, createdAt: w.created_at };
1271
+ }
1272
+ function clientCreatedFromWire(w) {
1273
+ return { name: w.name, token: w.token, createdAt: w.created_at };
1274
+ }
1275
+ function secretFromWire2(w) {
1276
+ const out = { name: w.name, host: w.host, createdAt: w.created_at };
1277
+ if (w.type) out.type = w.type;
1278
+ return out;
1279
+ }
1280
+ function ruleFromWire(w) {
1281
+ const out = { host: w.host };
1282
+ if (w.secret) out.secret = w.secret;
1283
+ if (w.methods && w.methods.length > 0) out.methods = w.methods;
1284
+ if (w.paths && w.paths.length > 0) out.paths = w.paths;
1285
+ if (w.expires && w.expires !== "0001-01-01T00:00:00Z") out.expires = w.expires;
1286
+ if (w.passthrough) out.passthrough = w.passthrough;
1287
+ return out;
1288
+ }
1289
+ var ProxyAPI = class {
1290
+ constructor(transport) {
1291
+ this.transport = transport;
1292
+ this.clients = new ProxyClientsAPI(transport);
1293
+ this.secrets = new ProxySecretsAPI(transport);
1294
+ this.allows = new ProxyAllowsAPI(transport);
1295
+ }
1296
+ transport;
1297
+ clients;
1298
+ secrets;
1299
+ allows;
1300
+ };
1301
+ var ProxyClientsAPI = class {
1302
+ constructor(transport) {
1303
+ this.transport = transport;
1304
+ }
1305
+ transport;
1306
+ /** Mint a new proxy client. The returned token is shown once. */
1307
+ async create(name, opts = {}) {
1308
+ const body = { name };
1309
+ if (opts.token) body.token = opts.token;
1310
+ const wire = await this.transport.request(
1311
+ "POST",
1312
+ "/proxy/v1/clients",
1313
+ body
1314
+ );
1315
+ return clientCreatedFromWire(wire);
1316
+ }
1317
+ async list() {
1318
+ const wire = await this.transport.request("GET", "/proxy/v1/clients");
1319
+ return (wire ?? []).map(clientFromWire);
1320
+ }
1321
+ /**
1322
+ * Revoke the token, drop every allow rule the client owned, and
1323
+ * remove the client.
1324
+ */
1325
+ async delete(name) {
1326
+ await this.transport.request("DELETE", `/proxy/v1/clients/${encodeURIComponent(name)}`);
1327
+ }
1328
+ /** List a client's allow rules in declaration order (first-match-wins). */
1329
+ async rules(name) {
1330
+ const wire = await this.transport.request(
1331
+ "GET",
1332
+ `/proxy/v1/clients/${encodeURIComponent(name)}`
1333
+ );
1334
+ return (wire ?? []).map(ruleFromWire);
1335
+ }
1336
+ };
1337
+ var ProxySecretsAPI = class {
1338
+ constructor(transport) {
1339
+ this.transport = transport;
1340
+ }
1341
+ transport;
1342
+ async create(req) {
1343
+ const body = {
1344
+ name: req.name,
1345
+ host: req.host,
1346
+ value: req.value
1347
+ };
1348
+ if (req.type) body.type = req.type;
1349
+ await this.transport.request("POST", "/proxy/v1/secrets", body);
1350
+ }
1351
+ async list() {
1352
+ const wire = await this.transport.request("GET", "/proxy/v1/secrets");
1353
+ return (wire ?? []).map(secretFromWire2);
1354
+ }
1355
+ /**
1356
+ * Remove a secret. Allow rules that reference it stop matching until
1357
+ * the secret is recreated or the rule is rewritten.
1358
+ */
1359
+ async delete(name) {
1360
+ await this.transport.request("DELETE", `/proxy/v1/secrets/${encodeURIComponent(name)}`);
1361
+ }
1362
+ };
1363
+ var ProxyAllowsAPI = class {
1364
+ constructor(transport) {
1365
+ this.transport = transport;
1366
+ }
1367
+ transport;
1368
+ /** Add an allow rule. Returns the resolved rule with absolute `expires`. */
1369
+ async add(req) {
1370
+ const body = {
1371
+ client: req.client,
1372
+ host: req.host
1373
+ };
1374
+ if (req.secret) body.secret = req.secret;
1375
+ if (req.methods && req.methods.length > 0) body.methods = req.methods;
1376
+ if (req.paths && req.paths.length > 0) body.paths = req.paths;
1377
+ if (req.ttlSeconds && req.ttlSeconds > 0) body.ttl_seconds = req.ttlSeconds;
1378
+ if (req.passthrough) body.passthrough = true;
1379
+ const wire = await this.transport.request(
1380
+ "POST",
1381
+ "/proxy/v1/allows",
1382
+ body
1383
+ );
1384
+ return ruleFromWire(wire);
1385
+ }
1386
+ /**
1387
+ * Host-bulk revoke: removes **every** rule on the client whose host
1388
+ * matches. For surgical removal of one rule among siblings on the
1389
+ * same host (e.g. several path-scoped rules on `github.com`), use
1390
+ * `removeByTuple` instead.
1391
+ */
1392
+ async remove(client, host) {
1393
+ await this.transport.request(
1394
+ "DELETE",
1395
+ `/proxy/v1/allows/${encodeURIComponent(client)}/${encodeURIComponent(host)}`
1396
+ );
1397
+ }
1398
+ /**
1399
+ * Surgical revoke: removes the single rule whose
1400
+ * (host, methods, paths, passthrough) tuple matches the request.
1401
+ * Pass exactly the same fields you used at create time. Method and
1402
+ * host casing are normalised server-side, so `"GET"` / `"get"` and
1403
+ * `"github.com"` / `"GITHUB.COM"` all match the same stored rule.
1404
+ *
1405
+ * Returns 404 (surfaced as a SlicerAPIError) when no rule matches.
1406
+ */
1407
+ async removeByTuple(req) {
1408
+ const body = {
1409
+ client: req.client,
1410
+ host: req.host
1411
+ };
1412
+ if (req.secret) body.secret = req.secret;
1413
+ if (req.methods && req.methods.length > 0) body.methods = req.methods;
1414
+ if (req.paths && req.paths.length > 0) body.paths = req.paths;
1415
+ if (req.passthrough) body.passthrough = true;
1416
+ await this.transport.request("POST", "/proxy/v1/allows/revoke", body);
1417
+ }
1418
+ };
1419
+
1265
1420
  // src/client.ts
1266
1421
  var SlicerClient = class _SlicerClient {
1267
1422
  transport;
1268
1423
  hostGroups;
1269
1424
  vms;
1270
1425
  secrets;
1426
+ proxy;
1271
1427
  constructor(opts) {
1272
1428
  this.transport = new TransportClient(opts);
1273
1429
  this.hostGroups = new HostGroupsAPI(this.transport);
1274
1430
  this.vms = new VMsAPI(this.transport);
1275
1431
  this.secrets = new SecretsAPI(this.transport);
1432
+ this.proxy = new ProxyAPI(this.transport);
1276
1433
  }
1277
1434
  static fromEnv(overrides = {}) {
1278
1435
  const baseURL = overrides.baseURL ?? process.env.SLICER_URL;
@@ -1441,6 +1598,12 @@ exports.GiB = GiB;
1441
1598
  exports.HostGroupsAPI = HostGroupsAPI;
1442
1599
  exports.MiB = MiB;
1443
1600
  exports.NonRootUser = NonRootUser;
1601
+ exports.ProxyAPI = ProxyAPI;
1602
+ exports.ProxyAllowsAPI = ProxyAllowsAPI;
1603
+ exports.ProxyClientsAPI = ProxyClientsAPI;
1604
+ exports.ProxySecretBasic = ProxySecretBasic;
1605
+ exports.ProxySecretBearer = ProxySecretBearer;
1606
+ exports.ProxySecretsAPI = ProxySecretsAPI;
1444
1607
  exports.SecretExistsError = SecretExistsError;
1445
1608
  exports.SecretsAPI = SecretsAPI;
1446
1609
  exports.SlicerAPIError = SlicerAPIError;