@enclave-run/sdk 0.1.0 → 0.3.0

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.mjs CHANGED
@@ -60,7 +60,7 @@ import createClient from "openapi-fetch";
60
60
  import platform2 from "platform";
61
61
 
62
62
  // package.json
63
- var version = "0.1.0";
63
+ var version = "0.3.0";
64
64
 
65
65
  // src/utils.ts
66
66
  import platform from "platform";
@@ -249,7 +249,7 @@ var TemplateTagConflictError = class extends TemplateError {
249
249
  constructor(options) {
250
250
  var _a3;
251
251
  super(
252
- (_a3 = options.message) != null ? _a3 : `Template tag "${options.tag}" conflicted with another mutation. Fetch its current head with Template.getTagHead() before retrying.`
252
+ (_a3 = options.message) != null ? _a3 : `Template tag "${options.tag}" conflicted with another mutation. Read its current head with Template.getTags() before retrying.`
253
253
  );
254
254
  this.name = "TemplateTagConflictError";
255
255
  this.templateId = options.templateId;
@@ -3373,7 +3373,7 @@ var SandboxApi = class {
3373
3373
  return true;
3374
3374
  }
3375
3375
  static async createSandbox(template, timeoutMs, opts) {
3376
- var _a3, _b, _c;
3376
+ var _a3, _b;
3377
3377
  const config = ConnectionConfig.forSandbox(opts);
3378
3378
  const client = new ApiClient(config);
3379
3379
  const idempotencyKey = (_a3 = opts == null ? void 0 : opts.idempotencyKey) != null ? _a3 : crypto.randomUUID();
@@ -3392,8 +3392,7 @@ var SandboxApi = class {
3392
3392
  mcp: opts == null ? void 0 : opts.mcp,
3393
3393
  envVars: opts == null ? void 0 : opts.envs,
3394
3394
  timeout: timeoutToSeconds(timeoutMs),
3395
- secure: (_b = opts == null ? void 0 : opts.secure) != null ? _b : true,
3396
- allow_internet_access: (_c = opts == null ? void 0 : opts.allowInternetAccess) != null ? _c : true,
3395
+ allow_internet_access: (_b = opts == null ? void 0 : opts.allowInternetAccess) != null ? _b : true,
3397
3396
  network: opts == null ? void 0 : opts.network,
3398
3397
  autoPause: pauseOnTimeout
3399
3398
  }, pauseOnTimeout ? { autoResume: { policy: lifecycle.autoResume ? "any" : "off" } } : {}), config.region ? { region: config.region } : {});
@@ -5046,7 +5045,8 @@ async function getTemplateTags(client, { templateID }) {
5046
5045
  return res.data.map((item) => ({
5047
5046
  tag: item.tag,
5048
5047
  buildId: item.buildID,
5049
- createdAt: new Date(item.createdAt)
5048
+ createdAt: new Date(item.createdAt),
5049
+ version: item.version
5050
5050
  }));
5051
5051
  }
5052
5052
 
@@ -5272,126 +5272,10 @@ function handleCmdEntrypointInstruction(instruction, templateBuilder) {
5272
5272
  }
5273
5273
  }
5274
5274
 
5275
- // src/template/activationApi.ts
5276
- async function activateTemplate(build, options = {}) {
5277
- assertBuildIdentity(build);
5278
- assertExpectedVersion(options.expectedVersion);
5279
- const region = resolveRegion(options.region);
5280
- const config = ConnectionConfig.forGlobal(options);
5281
- const client = new ApiClient(config);
5282
- const response = await client.api.POST(
5283
- "/templates/{templateID}/activations/{region}",
5284
- {
5285
- params: {
5286
- path: {
5287
- templateID: build.templateId,
5288
- region
5289
- }
5290
- },
5291
- body: {
5292
- buildID: build.buildId,
5293
- active: true,
5294
- requiredReadyNodes: options.requiredReadyNodes,
5295
- allowRemoteFallback: options.allowRemoteFallback,
5296
- expectedVersion: options.expectedVersion
5297
- },
5298
- signal: config.getSignal(options.requestTimeoutMs)
5299
- }
5300
- );
5301
- return responseData(response, "Enclave API returned no template activation");
5302
- }
5303
- async function deactivateTemplate(build, options = {}) {
5304
- assertBuildIdentity(build);
5305
- assertExpectedVersion(options.expectedVersion);
5306
- const region = resolveRegion(options.region);
5307
- const config = ConnectionConfig.forGlobal(options);
5308
- const client = new ApiClient(config);
5309
- const response = await client.api.POST(
5310
- "/templates/{templateID}/activations/{region}",
5311
- {
5312
- params: {
5313
- path: {
5314
- templateID: build.templateId,
5315
- region
5316
- }
5317
- },
5318
- body: {
5319
- buildID: build.buildId,
5320
- active: false,
5321
- expectedVersion: options.expectedVersion
5322
- },
5323
- signal: config.getSignal(options.requestTimeoutMs)
5324
- }
5325
- );
5326
- return responseData(response, "Enclave API returned no template activation");
5327
- }
5328
- async function getTemplateActivation(templateId, options = {}) {
5329
- if (!templateId.trim()) {
5330
- throw new InvalidArgumentError("templateId is required");
5331
- }
5332
- if (options.buildId !== void 0 && !options.buildId.trim()) {
5333
- throw new InvalidArgumentError("buildId must not be empty");
5334
- }
5335
- const region = resolveRegion(options.region);
5336
- const config = ConnectionConfig.forSandbox(__spreadProps(__spreadValues({}, options), { region }));
5337
- const client = new ApiClient(config);
5338
- const response = await client.api.GET(
5339
- "/templates/{templateID}/activations/{region}",
5340
- {
5341
- params: {
5342
- path: {
5343
- templateID: templateId,
5344
- region
5345
- },
5346
- query: {
5347
- buildID: options.buildId
5348
- }
5349
- },
5350
- signal: config.getSignal(options.requestTimeoutMs)
5351
- }
5352
- );
5353
- return responseData(response, "Enclave API returned no template activation");
5354
- }
5355
- function assertBuildIdentity(build) {
5356
- if (!build.templateId.trim() || !build.buildId.trim()) {
5357
- throw new InvalidArgumentError("templateId and buildId are required");
5358
- }
5359
- }
5360
- function resolveRegion(region) {
5361
- return ConnectionConfig.resolveRegion(region);
5362
- }
5363
- function assertExpectedVersion(expectedVersion) {
5364
- if (expectedVersion !== void 0 && (!Number.isSafeInteger(expectedVersion) || expectedVersion < 0)) {
5365
- throw new InvalidArgumentError(
5366
- "expectedVersion must be a non-negative safe integer"
5367
- );
5368
- }
5369
- }
5370
-
5371
5275
  // src/template/tagHeadApi.ts
5372
- async function getTemplateTagHead(client, templateId, tag, signal) {
5373
- assertTemplateAndTag(templateId, tag);
5374
- const response = await client.api.GET("/templates/{templateID}/tags/{tag}", {
5375
- params: {
5376
- path: {
5377
- templateID: templateId,
5378
- tag
5379
- }
5380
- },
5381
- signal
5382
- });
5383
- const error = handleApiError(response, TemplateError);
5384
- if (error) {
5385
- throw error;
5386
- }
5387
- if (!response.data) {
5388
- throw new TemplateError("Enclave API returned no template tag head");
5389
- }
5390
- return mapTagHead(response.data);
5391
- }
5392
5276
  async function promoteTemplateTag(client, candidate, tag, expected, signal) {
5393
5277
  var _a3, _b, _c, _d, _e, _f;
5394
- assertBuildIdentity2(candidate);
5278
+ assertBuildIdentity(candidate);
5395
5279
  assertTemplateAndTag(candidate.templateId, tag);
5396
5280
  assertExpectation(expected);
5397
5281
  const response = await client.api.PUT("/templates/{templateID}/tags/{tag}", {
@@ -5417,7 +5301,7 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
5417
5301
  expectedBuildId: expected == null ? void 0 : expected.buildId,
5418
5302
  expectedVersion: (_f = expected == null ? void 0 : expected.version) != null ? _f : 0,
5419
5303
  reason: response.error.code,
5420
- message: `409: ${message}. Fetch its current head with Template.getTagHead() before retrying.`
5304
+ message: `409: ${message}. Read its current head with Template.getTags() before retrying.`
5421
5305
  });
5422
5306
  }
5423
5307
  const error = handleApiError(response, TemplateError);
@@ -5427,14 +5311,10 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
5427
5311
  if (!response.data) {
5428
5312
  throw new TemplateError("Enclave API returned no promoted template tag");
5429
5313
  }
5430
- return mapTagHead(response.data);
5431
- }
5432
- function mapTagHead(head) {
5433
5314
  return {
5434
- tag: head.tag,
5435
- buildId: head.buildID,
5436
- version: head.version,
5437
- createdAt: new Date(head.createdAt)
5315
+ buildId: response.data.buildID,
5316
+ tags: [response.data.tag],
5317
+ version: response.data.version
5438
5318
  };
5439
5319
  }
5440
5320
  function assertTemplateAndTag(templateId, tag) {
@@ -5442,7 +5322,7 @@ function assertTemplateAndTag(templateId, tag) {
5442
5322
  throw new InvalidArgumentError("templateId and tag are required");
5443
5323
  }
5444
5324
  }
5445
- function assertBuildIdentity2(candidate) {
5325
+ function assertBuildIdentity(candidate) {
5446
5326
  if (!candidate.templateId.trim() || !candidate.buildId.trim()) {
5447
5327
  throw new InvalidArgumentError("templateId and buildId are required");
5448
5328
  }
@@ -5597,29 +5477,6 @@ var TemplateBase = class {
5597
5477
  logsOffset: options == null ? void 0 : options.logsOffset
5598
5478
  });
5599
5479
  }
5600
- /**
5601
- * Materialize one immutable template build in a region before create.
5602
- *
5603
- * The request is recorded on the global control plane; hydration then runs
5604
- * asynchronously inside the selected region. Poll {@link getActivation}
5605
- * until the returned status is `ready`.
5606
- */
5607
- static async activate(data, options) {
5608
- return activateTemplate(data, options);
5609
- }
5610
- /**
5611
- * Return desired state plus exact-generation evidence from the selected
5612
- * regional cell.
5613
- */
5614
- static async getActivation(templateId, options) {
5615
- return getTemplateActivation(templateId, options);
5616
- }
5617
- /**
5618
- * Stop pinning and maintaining one exact build generation in a region.
5619
- */
5620
- static async deactivate(data, options) {
5621
- return deactivateTemplate(data, options);
5622
- }
5623
5480
  /**
5624
5481
  * Check if a template with the given name exists.
5625
5482
  *
@@ -5657,10 +5514,25 @@ var TemplateBase = class {
5657
5514
  * await Template.assignTags('my-template:v1.0', ['production', 'stable'])
5658
5515
  * ```
5659
5516
  */
5660
- static async assignTags(targetName, tags, options) {
5517
+ static async assignTags(target, tags, options) {
5661
5518
  const config = ConnectionConfig.forGlobal(options);
5662
5519
  const client = new ApiClient(config);
5663
5520
  const normalizedTags = Array.isArray(tags) ? tags : [tags];
5521
+ if ((options == null ? void 0 : options.expect) !== void 0) {
5522
+ if (typeof target === "string" || normalizedTags.length !== 1) {
5523
+ throw new InvalidArgumentError(
5524
+ "assignTags with expect requires an exact build ({ templateId, buildId }) and exactly one tag"
5525
+ );
5526
+ }
5527
+ return promoteTemplateTag(
5528
+ client,
5529
+ target,
5530
+ normalizedTags[0],
5531
+ options.expect,
5532
+ config.getSignal(options.requestTimeoutMs)
5533
+ );
5534
+ }
5535
+ const targetName = typeof target === "string" ? target : `${target.templateId}:${target.buildId}`;
5664
5536
  return assignTags(client, { targetName, tags: normalizedTags });
5665
5537
  }
5666
5538
  /**
@@ -5705,42 +5577,6 @@ var TemplateBase = class {
5705
5577
  const client = new ApiClient(config);
5706
5578
  return getTemplateTags(client, { templateID: templateId });
5707
5579
  }
5708
- /**
5709
- * Get the authoritative traffic-selection token for one template tag.
5710
- *
5711
- * Pass the returned head directly to {@link promoteTag}; its monotonic
5712
- * version prevents concurrent releasers from silently overwriting each
5713
- * other.
5714
- */
5715
- static async getTagHead(templateId, tag, options) {
5716
- const config = ConnectionConfig.forGlobal(options);
5717
- const client = new ApiClient(config);
5718
- return getTemplateTagHead(
5719
- client,
5720
- templateId,
5721
- tag,
5722
- config.getSignal(options == null ? void 0 : options.requestTimeoutMs)
5723
- );
5724
- }
5725
- /**
5726
- * Atomically move one template tag to an exact ready, durable build.
5727
- *
5728
- * Use a head returned by {@link getTagHead} as `expected`. Pass `null` only
5729
- * when creating a tag that must not already exist. A concurrent change throws
5730
- * `TemplateTagConflictError`; fetch the head again before deciding whether to
5731
- * retry.
5732
- */
5733
- static async promoteTag(candidate, tag, expected, options) {
5734
- const config = ConnectionConfig.forGlobal(options);
5735
- const client = new ApiClient(config);
5736
- return promoteTemplateTag(
5737
- client,
5738
- candidate,
5739
- tag,
5740
- expected,
5741
- config.getSignal(options == null ? void 0 : options.requestTimeoutMs)
5742
- );
5743
- }
5744
5580
  fromDebianImage(variant = "stable") {
5745
5581
  return this.fromImage(`debian:${variant}`);
5746
5582
  }
@@ -6418,15 +6254,10 @@ function Template(options) {
6418
6254
  Template.build = TemplateBase.build;
6419
6255
  Template.buildInBackground = TemplateBase.buildInBackground;
6420
6256
  Template.getBuildStatus = TemplateBase.getBuildStatus;
6421
- Template.activate = TemplateBase.activate;
6422
- Template.getActivation = TemplateBase.getActivation;
6423
- Template.deactivate = TemplateBase.deactivate;
6424
6257
  Template.exists = TemplateBase.exists;
6425
6258
  Template.assignTags = TemplateBase.assignTags;
6426
6259
  Template.removeTags = TemplateBase.removeTags;
6427
6260
  Template.getTags = TemplateBase.getTags;
6428
- Template.getTagHead = TemplateBase.getTagHead;
6429
- Template.promoteTag = TemplateBase.promoteTag;
6430
6261
  Template.toJSON = TemplateBase.toJSON;
6431
6262
  Template.toDockerfile = TemplateBase.toDockerfile;
6432
6263