@enclave-run/sdk 0.1.0 → 0.2.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 -250
- package/dist/index.d.ts +36 -250
- package/dist/index.js +26 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -194
- 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.2.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;
|
|
@@ -5102,7 +5102,8 @@ async function getTemplateTags(client, { templateID }) {
|
|
|
5102
5102
|
return res.data.map((item) => ({
|
|
5103
5103
|
tag: item.tag,
|
|
5104
5104
|
buildId: item.buildID,
|
|
5105
|
-
createdAt: new Date(item.createdAt)
|
|
5105
|
+
createdAt: new Date(item.createdAt),
|
|
5106
|
+
version: item.version
|
|
5106
5107
|
}));
|
|
5107
5108
|
}
|
|
5108
5109
|
|
|
@@ -5326,126 +5327,10 @@ function handleCmdEntrypointInstruction(instruction, templateBuilder) {
|
|
|
5326
5327
|
}
|
|
5327
5328
|
}
|
|
5328
5329
|
|
|
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
5330
|
// 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
5331
|
async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
5447
5332
|
var _a3, _b, _c, _d, _e, _f;
|
|
5448
|
-
|
|
5333
|
+
assertBuildIdentity(candidate);
|
|
5449
5334
|
assertTemplateAndTag(candidate.templateId, tag);
|
|
5450
5335
|
assertExpectation(expected);
|
|
5451
5336
|
const response = await client.api.PUT("/templates/{templateID}/tags/{tag}", {
|
|
@@ -5471,7 +5356,7 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5471
5356
|
expectedBuildId: expected == null ? void 0 : expected.buildId,
|
|
5472
5357
|
expectedVersion: (_f = expected == null ? void 0 : expected.version) != null ? _f : 0,
|
|
5473
5358
|
reason: response.error.code,
|
|
5474
|
-
message: `409: ${message}.
|
|
5359
|
+
message: `409: ${message}. Read its current head with Template.getTags() before retrying.`
|
|
5475
5360
|
});
|
|
5476
5361
|
}
|
|
5477
5362
|
const error = handleApiError(response, TemplateError);
|
|
@@ -5481,14 +5366,10 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5481
5366
|
if (!response.data) {
|
|
5482
5367
|
throw new TemplateError("Enclave API returned no promoted template tag");
|
|
5483
5368
|
}
|
|
5484
|
-
return mapTagHead(response.data);
|
|
5485
|
-
}
|
|
5486
|
-
function mapTagHead(head) {
|
|
5487
5369
|
return {
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
version:
|
|
5491
|
-
createdAt: new Date(head.createdAt)
|
|
5370
|
+
buildId: response.data.buildID,
|
|
5371
|
+
tags: [response.data.tag],
|
|
5372
|
+
version: response.data.version
|
|
5492
5373
|
};
|
|
5493
5374
|
}
|
|
5494
5375
|
function assertTemplateAndTag(templateId, tag) {
|
|
@@ -5496,7 +5377,7 @@ function assertTemplateAndTag(templateId, tag) {
|
|
|
5496
5377
|
throw new InvalidArgumentError("templateId and tag are required");
|
|
5497
5378
|
}
|
|
5498
5379
|
}
|
|
5499
|
-
function
|
|
5380
|
+
function assertBuildIdentity(candidate) {
|
|
5500
5381
|
if (!candidate.templateId.trim() || !candidate.buildId.trim()) {
|
|
5501
5382
|
throw new InvalidArgumentError("templateId and buildId are required");
|
|
5502
5383
|
}
|
|
@@ -5651,29 +5532,6 @@ var TemplateBase = class {
|
|
|
5651
5532
|
logsOffset: options == null ? void 0 : options.logsOffset
|
|
5652
5533
|
});
|
|
5653
5534
|
}
|
|
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
5535
|
/**
|
|
5678
5536
|
* Check if a template with the given name exists.
|
|
5679
5537
|
*
|
|
@@ -5711,10 +5569,25 @@ var TemplateBase = class {
|
|
|
5711
5569
|
* await Template.assignTags('my-template:v1.0', ['production', 'stable'])
|
|
5712
5570
|
* ```
|
|
5713
5571
|
*/
|
|
5714
|
-
static async assignTags(
|
|
5572
|
+
static async assignTags(target, tags, options) {
|
|
5715
5573
|
const config = ConnectionConfig.forGlobal(options);
|
|
5716
5574
|
const client = new ApiClient(config);
|
|
5717
5575
|
const normalizedTags = Array.isArray(tags) ? tags : [tags];
|
|
5576
|
+
if ((options == null ? void 0 : options.expect) !== void 0) {
|
|
5577
|
+
if (typeof target === "string" || normalizedTags.length !== 1) {
|
|
5578
|
+
throw new InvalidArgumentError(
|
|
5579
|
+
"assignTags with expect requires an exact build ({ templateId, buildId }) and exactly one tag"
|
|
5580
|
+
);
|
|
5581
|
+
}
|
|
5582
|
+
return promoteTemplateTag(
|
|
5583
|
+
client,
|
|
5584
|
+
target,
|
|
5585
|
+
normalizedTags[0],
|
|
5586
|
+
options.expect,
|
|
5587
|
+
config.getSignal(options.requestTimeoutMs)
|
|
5588
|
+
);
|
|
5589
|
+
}
|
|
5590
|
+
const targetName = typeof target === "string" ? target : `${target.templateId}:${target.buildId}`;
|
|
5718
5591
|
return assignTags(client, { targetName, tags: normalizedTags });
|
|
5719
5592
|
}
|
|
5720
5593
|
/**
|
|
@@ -5759,42 +5632,6 @@ var TemplateBase = class {
|
|
|
5759
5632
|
const client = new ApiClient(config);
|
|
5760
5633
|
return getTemplateTags(client, { templateID: templateId });
|
|
5761
5634
|
}
|
|
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
5635
|
fromDebianImage(variant = "stable") {
|
|
5799
5636
|
return this.fromImage(`debian:${variant}`);
|
|
5800
5637
|
}
|
|
@@ -6472,15 +6309,10 @@ function Template(options) {
|
|
|
6472
6309
|
Template.build = TemplateBase.build;
|
|
6473
6310
|
Template.buildInBackground = TemplateBase.buildInBackground;
|
|
6474
6311
|
Template.getBuildStatus = TemplateBase.getBuildStatus;
|
|
6475
|
-
Template.activate = TemplateBase.activate;
|
|
6476
|
-
Template.getActivation = TemplateBase.getActivation;
|
|
6477
|
-
Template.deactivate = TemplateBase.deactivate;
|
|
6478
6312
|
Template.exists = TemplateBase.exists;
|
|
6479
6313
|
Template.assignTags = TemplateBase.assignTags;
|
|
6480
6314
|
Template.removeTags = TemplateBase.removeTags;
|
|
6481
6315
|
Template.getTags = TemplateBase.getTags;
|
|
6482
|
-
Template.getTagHead = TemplateBase.getTagHead;
|
|
6483
|
-
Template.promoteTag = TemplateBase.promoteTag;
|
|
6484
6316
|
Template.toJSON = TemplateBase.toJSON;
|
|
6485
6317
|
Template.toDockerfile = TemplateBase.toDockerfile;
|
|
6486
6318
|
|