@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.d.mts +36 -258
- package/dist/index.d.ts +36 -258
- package/dist/index.js +28 -197
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -128,7 +128,7 @@ var import_openapi_fetch = __toESM(require("openapi-fetch"));
|
|
|
128
128
|
var import_platform2 = __toESM(require("platform"));
|
|
129
129
|
|
|
130
130
|
// package.json
|
|
131
|
-
var version = "0.
|
|
131
|
+
var version = "0.3.0";
|
|
132
132
|
|
|
133
133
|
// src/utils.ts
|
|
134
134
|
var import_platform = __toESM(require("platform"));
|
|
@@ -317,7 +317,7 @@ var TemplateTagConflictError = class extends TemplateError {
|
|
|
317
317
|
constructor(options) {
|
|
318
318
|
var _a3;
|
|
319
319
|
super(
|
|
320
|
-
(_a3 = options.message) != null ? _a3 : `Template tag "${options.tag}" conflicted with another mutation.
|
|
320
|
+
(_a3 = options.message) != null ? _a3 : `Template tag "${options.tag}" conflicted with another mutation. Read its current head with Template.getTags() before retrying.`
|
|
321
321
|
);
|
|
322
322
|
this.name = "TemplateTagConflictError";
|
|
323
323
|
this.templateId = options.templateId;
|
|
@@ -3429,7 +3429,7 @@ var SandboxApi = class {
|
|
|
3429
3429
|
return true;
|
|
3430
3430
|
}
|
|
3431
3431
|
static async createSandbox(template, timeoutMs, opts) {
|
|
3432
|
-
var _a3, _b
|
|
3432
|
+
var _a3, _b;
|
|
3433
3433
|
const config = ConnectionConfig.forSandbox(opts);
|
|
3434
3434
|
const client = new ApiClient(config);
|
|
3435
3435
|
const idempotencyKey = (_a3 = opts == null ? void 0 : opts.idempotencyKey) != null ? _a3 : crypto.randomUUID();
|
|
@@ -3448,8 +3448,7 @@ var SandboxApi = class {
|
|
|
3448
3448
|
mcp: opts == null ? void 0 : opts.mcp,
|
|
3449
3449
|
envVars: opts == null ? void 0 : opts.envs,
|
|
3450
3450
|
timeout: timeoutToSeconds(timeoutMs),
|
|
3451
|
-
|
|
3452
|
-
allow_internet_access: (_c = opts == null ? void 0 : opts.allowInternetAccess) != null ? _c : true,
|
|
3451
|
+
allow_internet_access: (_b = opts == null ? void 0 : opts.allowInternetAccess) != null ? _b : true,
|
|
3453
3452
|
network: opts == null ? void 0 : opts.network,
|
|
3454
3453
|
autoPause: pauseOnTimeout
|
|
3455
3454
|
}, pauseOnTimeout ? { autoResume: { policy: lifecycle.autoResume ? "any" : "off" } } : {}), config.region ? { region: config.region } : {});
|
|
@@ -5102,7 +5101,8 @@ async function getTemplateTags(client, { templateID }) {
|
|
|
5102
5101
|
return res.data.map((item) => ({
|
|
5103
5102
|
tag: item.tag,
|
|
5104
5103
|
buildId: item.buildID,
|
|
5105
|
-
createdAt: new Date(item.createdAt)
|
|
5104
|
+
createdAt: new Date(item.createdAt),
|
|
5105
|
+
version: item.version
|
|
5106
5106
|
}));
|
|
5107
5107
|
}
|
|
5108
5108
|
|
|
@@ -5326,126 +5326,10 @@ function handleCmdEntrypointInstruction(instruction, templateBuilder) {
|
|
|
5326
5326
|
}
|
|
5327
5327
|
}
|
|
5328
5328
|
|
|
5329
|
-
// src/template/activationApi.ts
|
|
5330
|
-
async function activateTemplate(build, options = {}) {
|
|
5331
|
-
assertBuildIdentity(build);
|
|
5332
|
-
assertExpectedVersion(options.expectedVersion);
|
|
5333
|
-
const region = resolveRegion(options.region);
|
|
5334
|
-
const config = ConnectionConfig.forGlobal(options);
|
|
5335
|
-
const client = new ApiClient(config);
|
|
5336
|
-
const response = await client.api.POST(
|
|
5337
|
-
"/templates/{templateID}/activations/{region}",
|
|
5338
|
-
{
|
|
5339
|
-
params: {
|
|
5340
|
-
path: {
|
|
5341
|
-
templateID: build.templateId,
|
|
5342
|
-
region
|
|
5343
|
-
}
|
|
5344
|
-
},
|
|
5345
|
-
body: {
|
|
5346
|
-
buildID: build.buildId,
|
|
5347
|
-
active: true,
|
|
5348
|
-
requiredReadyNodes: options.requiredReadyNodes,
|
|
5349
|
-
allowRemoteFallback: options.allowRemoteFallback,
|
|
5350
|
-
expectedVersion: options.expectedVersion
|
|
5351
|
-
},
|
|
5352
|
-
signal: config.getSignal(options.requestTimeoutMs)
|
|
5353
|
-
}
|
|
5354
|
-
);
|
|
5355
|
-
return responseData(response, "Enclave API returned no template activation");
|
|
5356
|
-
}
|
|
5357
|
-
async function deactivateTemplate(build, options = {}) {
|
|
5358
|
-
assertBuildIdentity(build);
|
|
5359
|
-
assertExpectedVersion(options.expectedVersion);
|
|
5360
|
-
const region = resolveRegion(options.region);
|
|
5361
|
-
const config = ConnectionConfig.forGlobal(options);
|
|
5362
|
-
const client = new ApiClient(config);
|
|
5363
|
-
const response = await client.api.POST(
|
|
5364
|
-
"/templates/{templateID}/activations/{region}",
|
|
5365
|
-
{
|
|
5366
|
-
params: {
|
|
5367
|
-
path: {
|
|
5368
|
-
templateID: build.templateId,
|
|
5369
|
-
region
|
|
5370
|
-
}
|
|
5371
|
-
},
|
|
5372
|
-
body: {
|
|
5373
|
-
buildID: build.buildId,
|
|
5374
|
-
active: false,
|
|
5375
|
-
expectedVersion: options.expectedVersion
|
|
5376
|
-
},
|
|
5377
|
-
signal: config.getSignal(options.requestTimeoutMs)
|
|
5378
|
-
}
|
|
5379
|
-
);
|
|
5380
|
-
return responseData(response, "Enclave API returned no template activation");
|
|
5381
|
-
}
|
|
5382
|
-
async function getTemplateActivation(templateId, options = {}) {
|
|
5383
|
-
if (!templateId.trim()) {
|
|
5384
|
-
throw new InvalidArgumentError("templateId is required");
|
|
5385
|
-
}
|
|
5386
|
-
if (options.buildId !== void 0 && !options.buildId.trim()) {
|
|
5387
|
-
throw new InvalidArgumentError("buildId must not be empty");
|
|
5388
|
-
}
|
|
5389
|
-
const region = resolveRegion(options.region);
|
|
5390
|
-
const config = ConnectionConfig.forSandbox(__spreadProps(__spreadValues({}, options), { region }));
|
|
5391
|
-
const client = new ApiClient(config);
|
|
5392
|
-
const response = await client.api.GET(
|
|
5393
|
-
"/templates/{templateID}/activations/{region}",
|
|
5394
|
-
{
|
|
5395
|
-
params: {
|
|
5396
|
-
path: {
|
|
5397
|
-
templateID: templateId,
|
|
5398
|
-
region
|
|
5399
|
-
},
|
|
5400
|
-
query: {
|
|
5401
|
-
buildID: options.buildId
|
|
5402
|
-
}
|
|
5403
|
-
},
|
|
5404
|
-
signal: config.getSignal(options.requestTimeoutMs)
|
|
5405
|
-
}
|
|
5406
|
-
);
|
|
5407
|
-
return responseData(response, "Enclave API returned no template activation");
|
|
5408
|
-
}
|
|
5409
|
-
function assertBuildIdentity(build) {
|
|
5410
|
-
if (!build.templateId.trim() || !build.buildId.trim()) {
|
|
5411
|
-
throw new InvalidArgumentError("templateId and buildId are required");
|
|
5412
|
-
}
|
|
5413
|
-
}
|
|
5414
|
-
function resolveRegion(region) {
|
|
5415
|
-
return ConnectionConfig.resolveRegion(region);
|
|
5416
|
-
}
|
|
5417
|
-
function assertExpectedVersion(expectedVersion) {
|
|
5418
|
-
if (expectedVersion !== void 0 && (!Number.isSafeInteger(expectedVersion) || expectedVersion < 0)) {
|
|
5419
|
-
throw new InvalidArgumentError(
|
|
5420
|
-
"expectedVersion must be a non-negative safe integer"
|
|
5421
|
-
);
|
|
5422
|
-
}
|
|
5423
|
-
}
|
|
5424
|
-
|
|
5425
5329
|
// src/template/tagHeadApi.ts
|
|
5426
|
-
async function getTemplateTagHead(client, templateId, tag, signal) {
|
|
5427
|
-
assertTemplateAndTag(templateId, tag);
|
|
5428
|
-
const response = await client.api.GET("/templates/{templateID}/tags/{tag}", {
|
|
5429
|
-
params: {
|
|
5430
|
-
path: {
|
|
5431
|
-
templateID: templateId,
|
|
5432
|
-
tag
|
|
5433
|
-
}
|
|
5434
|
-
},
|
|
5435
|
-
signal
|
|
5436
|
-
});
|
|
5437
|
-
const error = handleApiError(response, TemplateError);
|
|
5438
|
-
if (error) {
|
|
5439
|
-
throw error;
|
|
5440
|
-
}
|
|
5441
|
-
if (!response.data) {
|
|
5442
|
-
throw new TemplateError("Enclave API returned no template tag head");
|
|
5443
|
-
}
|
|
5444
|
-
return mapTagHead(response.data);
|
|
5445
|
-
}
|
|
5446
5330
|
async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
5447
5331
|
var _a3, _b, _c, _d, _e, _f;
|
|
5448
|
-
|
|
5332
|
+
assertBuildIdentity(candidate);
|
|
5449
5333
|
assertTemplateAndTag(candidate.templateId, tag);
|
|
5450
5334
|
assertExpectation(expected);
|
|
5451
5335
|
const response = await client.api.PUT("/templates/{templateID}/tags/{tag}", {
|
|
@@ -5471,7 +5355,7 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5471
5355
|
expectedBuildId: expected == null ? void 0 : expected.buildId,
|
|
5472
5356
|
expectedVersion: (_f = expected == null ? void 0 : expected.version) != null ? _f : 0,
|
|
5473
5357
|
reason: response.error.code,
|
|
5474
|
-
message: `409: ${message}.
|
|
5358
|
+
message: `409: ${message}. Read its current head with Template.getTags() before retrying.`
|
|
5475
5359
|
});
|
|
5476
5360
|
}
|
|
5477
5361
|
const error = handleApiError(response, TemplateError);
|
|
@@ -5481,14 +5365,10 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5481
5365
|
if (!response.data) {
|
|
5482
5366
|
throw new TemplateError("Enclave API returned no promoted template tag");
|
|
5483
5367
|
}
|
|
5484
|
-
return mapTagHead(response.data);
|
|
5485
|
-
}
|
|
5486
|
-
function mapTagHead(head) {
|
|
5487
5368
|
return {
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
version:
|
|
5491
|
-
createdAt: new Date(head.createdAt)
|
|
5369
|
+
buildId: response.data.buildID,
|
|
5370
|
+
tags: [response.data.tag],
|
|
5371
|
+
version: response.data.version
|
|
5492
5372
|
};
|
|
5493
5373
|
}
|
|
5494
5374
|
function assertTemplateAndTag(templateId, tag) {
|
|
@@ -5496,7 +5376,7 @@ function assertTemplateAndTag(templateId, tag) {
|
|
|
5496
5376
|
throw new InvalidArgumentError("templateId and tag are required");
|
|
5497
5377
|
}
|
|
5498
5378
|
}
|
|
5499
|
-
function
|
|
5379
|
+
function assertBuildIdentity(candidate) {
|
|
5500
5380
|
if (!candidate.templateId.trim() || !candidate.buildId.trim()) {
|
|
5501
5381
|
throw new InvalidArgumentError("templateId and buildId are required");
|
|
5502
5382
|
}
|
|
@@ -5651,29 +5531,6 @@ var TemplateBase = class {
|
|
|
5651
5531
|
logsOffset: options == null ? void 0 : options.logsOffset
|
|
5652
5532
|
});
|
|
5653
5533
|
}
|
|
5654
|
-
/**
|
|
5655
|
-
* Materialize one immutable template build in a region before create.
|
|
5656
|
-
*
|
|
5657
|
-
* The request is recorded on the global control plane; hydration then runs
|
|
5658
|
-
* asynchronously inside the selected region. Poll {@link getActivation}
|
|
5659
|
-
* until the returned status is `ready`.
|
|
5660
|
-
*/
|
|
5661
|
-
static async activate(data, options) {
|
|
5662
|
-
return activateTemplate(data, options);
|
|
5663
|
-
}
|
|
5664
|
-
/**
|
|
5665
|
-
* Return desired state plus exact-generation evidence from the selected
|
|
5666
|
-
* regional cell.
|
|
5667
|
-
*/
|
|
5668
|
-
static async getActivation(templateId, options) {
|
|
5669
|
-
return getTemplateActivation(templateId, options);
|
|
5670
|
-
}
|
|
5671
|
-
/**
|
|
5672
|
-
* Stop pinning and maintaining one exact build generation in a region.
|
|
5673
|
-
*/
|
|
5674
|
-
static async deactivate(data, options) {
|
|
5675
|
-
return deactivateTemplate(data, options);
|
|
5676
|
-
}
|
|
5677
5534
|
/**
|
|
5678
5535
|
* Check if a template with the given name exists.
|
|
5679
5536
|
*
|
|
@@ -5711,10 +5568,25 @@ var TemplateBase = class {
|
|
|
5711
5568
|
* await Template.assignTags('my-template:v1.0', ['production', 'stable'])
|
|
5712
5569
|
* ```
|
|
5713
5570
|
*/
|
|
5714
|
-
static async assignTags(
|
|
5571
|
+
static async assignTags(target, tags, options) {
|
|
5715
5572
|
const config = ConnectionConfig.forGlobal(options);
|
|
5716
5573
|
const client = new ApiClient(config);
|
|
5717
5574
|
const normalizedTags = Array.isArray(tags) ? tags : [tags];
|
|
5575
|
+
if ((options == null ? void 0 : options.expect) !== void 0) {
|
|
5576
|
+
if (typeof target === "string" || normalizedTags.length !== 1) {
|
|
5577
|
+
throw new InvalidArgumentError(
|
|
5578
|
+
"assignTags with expect requires an exact build ({ templateId, buildId }) and exactly one tag"
|
|
5579
|
+
);
|
|
5580
|
+
}
|
|
5581
|
+
return promoteTemplateTag(
|
|
5582
|
+
client,
|
|
5583
|
+
target,
|
|
5584
|
+
normalizedTags[0],
|
|
5585
|
+
options.expect,
|
|
5586
|
+
config.getSignal(options.requestTimeoutMs)
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
const targetName = typeof target === "string" ? target : `${target.templateId}:${target.buildId}`;
|
|
5718
5590
|
return assignTags(client, { targetName, tags: normalizedTags });
|
|
5719
5591
|
}
|
|
5720
5592
|
/**
|
|
@@ -5759,42 +5631,6 @@ var TemplateBase = class {
|
|
|
5759
5631
|
const client = new ApiClient(config);
|
|
5760
5632
|
return getTemplateTags(client, { templateID: templateId });
|
|
5761
5633
|
}
|
|
5762
|
-
/**
|
|
5763
|
-
* Get the authoritative traffic-selection token for one template tag.
|
|
5764
|
-
*
|
|
5765
|
-
* Pass the returned head directly to {@link promoteTag}; its monotonic
|
|
5766
|
-
* version prevents concurrent releasers from silently overwriting each
|
|
5767
|
-
* other.
|
|
5768
|
-
*/
|
|
5769
|
-
static async getTagHead(templateId, tag, options) {
|
|
5770
|
-
const config = ConnectionConfig.forGlobal(options);
|
|
5771
|
-
const client = new ApiClient(config);
|
|
5772
|
-
return getTemplateTagHead(
|
|
5773
|
-
client,
|
|
5774
|
-
templateId,
|
|
5775
|
-
tag,
|
|
5776
|
-
config.getSignal(options == null ? void 0 : options.requestTimeoutMs)
|
|
5777
|
-
);
|
|
5778
|
-
}
|
|
5779
|
-
/**
|
|
5780
|
-
* Atomically move one template tag to an exact ready, durable build.
|
|
5781
|
-
*
|
|
5782
|
-
* Use a head returned by {@link getTagHead} as `expected`. Pass `null` only
|
|
5783
|
-
* when creating a tag that must not already exist. A concurrent change throws
|
|
5784
|
-
* `TemplateTagConflictError`; fetch the head again before deciding whether to
|
|
5785
|
-
* retry.
|
|
5786
|
-
*/
|
|
5787
|
-
static async promoteTag(candidate, tag, expected, options) {
|
|
5788
|
-
const config = ConnectionConfig.forGlobal(options);
|
|
5789
|
-
const client = new ApiClient(config);
|
|
5790
|
-
return promoteTemplateTag(
|
|
5791
|
-
client,
|
|
5792
|
-
candidate,
|
|
5793
|
-
tag,
|
|
5794
|
-
expected,
|
|
5795
|
-
config.getSignal(options == null ? void 0 : options.requestTimeoutMs)
|
|
5796
|
-
);
|
|
5797
|
-
}
|
|
5798
5634
|
fromDebianImage(variant = "stable") {
|
|
5799
5635
|
return this.fromImage(`debian:${variant}`);
|
|
5800
5636
|
}
|
|
@@ -6472,15 +6308,10 @@ function Template(options) {
|
|
|
6472
6308
|
Template.build = TemplateBase.build;
|
|
6473
6309
|
Template.buildInBackground = TemplateBase.buildInBackground;
|
|
6474
6310
|
Template.getBuildStatus = TemplateBase.getBuildStatus;
|
|
6475
|
-
Template.activate = TemplateBase.activate;
|
|
6476
|
-
Template.getActivation = TemplateBase.getActivation;
|
|
6477
|
-
Template.deactivate = TemplateBase.deactivate;
|
|
6478
6311
|
Template.exists = TemplateBase.exists;
|
|
6479
6312
|
Template.assignTags = TemplateBase.assignTags;
|
|
6480
6313
|
Template.removeTags = TemplateBase.removeTags;
|
|
6481
6314
|
Template.getTags = TemplateBase.getTags;
|
|
6482
|
-
Template.getTagHead = TemplateBase.getTagHead;
|
|
6483
|
-
Template.promoteTag = TemplateBase.promoteTag;
|
|
6484
6315
|
Template.toJSON = TemplateBase.toJSON;
|
|
6485
6316
|
Template.toDockerfile = TemplateBase.toDockerfile;
|
|
6486
6317
|
|