@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.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.
|
|
63
|
+
var version = "0.2.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.
|
|
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;
|
|
@@ -5046,7 +5046,8 @@ async function getTemplateTags(client, { templateID }) {
|
|
|
5046
5046
|
return res.data.map((item) => ({
|
|
5047
5047
|
tag: item.tag,
|
|
5048
5048
|
buildId: item.buildID,
|
|
5049
|
-
createdAt: new Date(item.createdAt)
|
|
5049
|
+
createdAt: new Date(item.createdAt),
|
|
5050
|
+
version: item.version
|
|
5050
5051
|
}));
|
|
5051
5052
|
}
|
|
5052
5053
|
|
|
@@ -5272,126 +5273,10 @@ function handleCmdEntrypointInstruction(instruction, templateBuilder) {
|
|
|
5272
5273
|
}
|
|
5273
5274
|
}
|
|
5274
5275
|
|
|
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
5276
|
// 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
5277
|
async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
5393
5278
|
var _a3, _b, _c, _d, _e, _f;
|
|
5394
|
-
|
|
5279
|
+
assertBuildIdentity(candidate);
|
|
5395
5280
|
assertTemplateAndTag(candidate.templateId, tag);
|
|
5396
5281
|
assertExpectation(expected);
|
|
5397
5282
|
const response = await client.api.PUT("/templates/{templateID}/tags/{tag}", {
|
|
@@ -5417,7 +5302,7 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5417
5302
|
expectedBuildId: expected == null ? void 0 : expected.buildId,
|
|
5418
5303
|
expectedVersion: (_f = expected == null ? void 0 : expected.version) != null ? _f : 0,
|
|
5419
5304
|
reason: response.error.code,
|
|
5420
|
-
message: `409: ${message}.
|
|
5305
|
+
message: `409: ${message}. Read its current head with Template.getTags() before retrying.`
|
|
5421
5306
|
});
|
|
5422
5307
|
}
|
|
5423
5308
|
const error = handleApiError(response, TemplateError);
|
|
@@ -5427,14 +5312,10 @@ async function promoteTemplateTag(client, candidate, tag, expected, signal) {
|
|
|
5427
5312
|
if (!response.data) {
|
|
5428
5313
|
throw new TemplateError("Enclave API returned no promoted template tag");
|
|
5429
5314
|
}
|
|
5430
|
-
return mapTagHead(response.data);
|
|
5431
|
-
}
|
|
5432
|
-
function mapTagHead(head) {
|
|
5433
5315
|
return {
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
version:
|
|
5437
|
-
createdAt: new Date(head.createdAt)
|
|
5316
|
+
buildId: response.data.buildID,
|
|
5317
|
+
tags: [response.data.tag],
|
|
5318
|
+
version: response.data.version
|
|
5438
5319
|
};
|
|
5439
5320
|
}
|
|
5440
5321
|
function assertTemplateAndTag(templateId, tag) {
|
|
@@ -5442,7 +5323,7 @@ function assertTemplateAndTag(templateId, tag) {
|
|
|
5442
5323
|
throw new InvalidArgumentError("templateId and tag are required");
|
|
5443
5324
|
}
|
|
5444
5325
|
}
|
|
5445
|
-
function
|
|
5326
|
+
function assertBuildIdentity(candidate) {
|
|
5446
5327
|
if (!candidate.templateId.trim() || !candidate.buildId.trim()) {
|
|
5447
5328
|
throw new InvalidArgumentError("templateId and buildId are required");
|
|
5448
5329
|
}
|
|
@@ -5597,29 +5478,6 @@ var TemplateBase = class {
|
|
|
5597
5478
|
logsOffset: options == null ? void 0 : options.logsOffset
|
|
5598
5479
|
});
|
|
5599
5480
|
}
|
|
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
5481
|
/**
|
|
5624
5482
|
* Check if a template with the given name exists.
|
|
5625
5483
|
*
|
|
@@ -5657,10 +5515,25 @@ var TemplateBase = class {
|
|
|
5657
5515
|
* await Template.assignTags('my-template:v1.0', ['production', 'stable'])
|
|
5658
5516
|
* ```
|
|
5659
5517
|
*/
|
|
5660
|
-
static async assignTags(
|
|
5518
|
+
static async assignTags(target, tags, options) {
|
|
5661
5519
|
const config = ConnectionConfig.forGlobal(options);
|
|
5662
5520
|
const client = new ApiClient(config);
|
|
5663
5521
|
const normalizedTags = Array.isArray(tags) ? tags : [tags];
|
|
5522
|
+
if ((options == null ? void 0 : options.expect) !== void 0) {
|
|
5523
|
+
if (typeof target === "string" || normalizedTags.length !== 1) {
|
|
5524
|
+
throw new InvalidArgumentError(
|
|
5525
|
+
"assignTags with expect requires an exact build ({ templateId, buildId }) and exactly one tag"
|
|
5526
|
+
);
|
|
5527
|
+
}
|
|
5528
|
+
return promoteTemplateTag(
|
|
5529
|
+
client,
|
|
5530
|
+
target,
|
|
5531
|
+
normalizedTags[0],
|
|
5532
|
+
options.expect,
|
|
5533
|
+
config.getSignal(options.requestTimeoutMs)
|
|
5534
|
+
);
|
|
5535
|
+
}
|
|
5536
|
+
const targetName = typeof target === "string" ? target : `${target.templateId}:${target.buildId}`;
|
|
5664
5537
|
return assignTags(client, { targetName, tags: normalizedTags });
|
|
5665
5538
|
}
|
|
5666
5539
|
/**
|
|
@@ -5705,42 +5578,6 @@ var TemplateBase = class {
|
|
|
5705
5578
|
const client = new ApiClient(config);
|
|
5706
5579
|
return getTemplateTags(client, { templateID: templateId });
|
|
5707
5580
|
}
|
|
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
5581
|
fromDebianImage(variant = "stable") {
|
|
5745
5582
|
return this.fromImage(`debian:${variant}`);
|
|
5746
5583
|
}
|
|
@@ -6418,15 +6255,10 @@ function Template(options) {
|
|
|
6418
6255
|
Template.build = TemplateBase.build;
|
|
6419
6256
|
Template.buildInBackground = TemplateBase.buildInBackground;
|
|
6420
6257
|
Template.getBuildStatus = TemplateBase.getBuildStatus;
|
|
6421
|
-
Template.activate = TemplateBase.activate;
|
|
6422
|
-
Template.getActivation = TemplateBase.getActivation;
|
|
6423
|
-
Template.deactivate = TemplateBase.deactivate;
|
|
6424
6258
|
Template.exists = TemplateBase.exists;
|
|
6425
6259
|
Template.assignTags = TemplateBase.assignTags;
|
|
6426
6260
|
Template.removeTags = TemplateBase.removeTags;
|
|
6427
6261
|
Template.getTags = TemplateBase.getTags;
|
|
6428
|
-
Template.getTagHead = TemplateBase.getTagHead;
|
|
6429
|
-
Template.promoteTag = TemplateBase.promoteTag;
|
|
6430
6262
|
Template.toJSON = TemplateBase.toJSON;
|
|
6431
6263
|
Template.toDockerfile = TemplateBase.toDockerfile;
|
|
6432
6264
|
|