@clef-sh/agent 0.1.11-beta.62 → 0.1.11-beta.68

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/agent.cjs CHANGED
@@ -44607,22 +44607,22 @@ var require_crypto2 = __commonJS({
44607
44607
  "use strict";
44608
44608
  Object.defineProperty(exports2, "__esModule", { value: true });
44609
44609
  exports2.NodeCrypto = void 0;
44610
- var crypto17 = require("crypto");
44610
+ var crypto18 = require("crypto");
44611
44611
  var NodeCrypto = class {
44612
44612
  async sha256DigestBase64(str) {
44613
- return crypto17.createHash("sha256").update(str).digest("base64");
44613
+ return crypto18.createHash("sha256").update(str).digest("base64");
44614
44614
  }
44615
44615
  randomBytesBase64(count) {
44616
- return crypto17.randomBytes(count).toString("base64");
44616
+ return crypto18.randomBytes(count).toString("base64");
44617
44617
  }
44618
44618
  async verify(pubkey, data, signature) {
44619
- const verifier = crypto17.createVerify("RSA-SHA256");
44619
+ const verifier = crypto18.createVerify("RSA-SHA256");
44620
44620
  verifier.update(data);
44621
44621
  verifier.end();
44622
44622
  return verifier.verify(pubkey, signature, "base64");
44623
44623
  }
44624
44624
  async sign(privateKey, data) {
44625
- const signer = crypto17.createSign("RSA-SHA256");
44625
+ const signer = crypto18.createSign("RSA-SHA256");
44626
44626
  signer.update(data);
44627
44627
  signer.end();
44628
44628
  return signer.sign(privateKey, "base64");
@@ -44640,7 +44640,7 @@ var require_crypto2 = __commonJS({
44640
44640
  * string in hexadecimal encoding.
44641
44641
  */
44642
44642
  async sha256DigestHex(str) {
44643
- return crypto17.createHash("sha256").update(str).digest("hex");
44643
+ return crypto18.createHash("sha256").update(str).digest("hex");
44644
44644
  }
44645
44645
  /**
44646
44646
  * Computes the HMAC hash of a message using the provided crypto key and the
@@ -44652,7 +44652,7 @@ var require_crypto2 = __commonJS({
44652
44652
  */
44653
44653
  async signWithHmacSha256(key, msg) {
44654
44654
  const cryptoKey = typeof key === "string" ? key : toBuffer(key);
44655
- return toArrayBuffer(crypto17.createHmac("sha256", cryptoKey).update(msg).digest());
44655
+ return toArrayBuffer(crypto18.createHmac("sha256", cryptoKey).update(msg).digest());
44656
44656
  }
44657
44657
  };
44658
44658
  exports2.NodeCrypto = NodeCrypto;
@@ -45430,10 +45430,10 @@ var require_oauth2client = __commonJS({
45430
45430
  * https://github.com/googleapis/google-auth-library-nodejs/blob/main/samples/oauth2-codeVerifier.js
45431
45431
  */
45432
45432
  async generateCodeVerifierAsync() {
45433
- const crypto17 = (0, crypto_1.createCrypto)();
45434
- const randomString = crypto17.randomBytesBase64(96);
45433
+ const crypto18 = (0, crypto_1.createCrypto)();
45434
+ const randomString = crypto18.randomBytesBase64(96);
45435
45435
  const codeVerifier = randomString.replace(/\+/g, "~").replace(/=/g, "_").replace(/\//g, "-");
45436
- const unencodedCodeChallenge = await crypto17.sha256DigestBase64(codeVerifier);
45436
+ const unencodedCodeChallenge = await crypto18.sha256DigestBase64(codeVerifier);
45437
45437
  const codeChallenge = unencodedCodeChallenge.split("=")[0].replace(/\+/g, "-").replace(/\//g, "_");
45438
45438
  return { codeVerifier, codeChallenge };
45439
45439
  }
@@ -45877,7 +45877,7 @@ var require_oauth2client = __commonJS({
45877
45877
  * @return Returns a promise resolving to LoginTicket on verification.
45878
45878
  */
45879
45879
  async verifySignedJwtWithCertsAsync(jwt2, certs, requiredAudience, issuers, maxExpiry) {
45880
- const crypto17 = (0, crypto_1.createCrypto)();
45880
+ const crypto18 = (0, crypto_1.createCrypto)();
45881
45881
  if (!maxExpiry) {
45882
45882
  maxExpiry = _OAuth2Client.DEFAULT_MAX_TOKEN_LIFETIME_SECS_;
45883
45883
  }
@@ -45890,7 +45890,7 @@ var require_oauth2client = __commonJS({
45890
45890
  let envelope;
45891
45891
  let payload;
45892
45892
  try {
45893
- envelope = JSON.parse(crypto17.decodeBase64StringUtf8(segments[0]));
45893
+ envelope = JSON.parse(crypto18.decodeBase64StringUtf8(segments[0]));
45894
45894
  } catch (err) {
45895
45895
  if (err instanceof Error) {
45896
45896
  err.message = `Can't parse token envelope: ${segments[0]}': ${err.message}`;
@@ -45901,7 +45901,7 @@ var require_oauth2client = __commonJS({
45901
45901
  throw new Error("Can't parse token envelope: " + segments[0]);
45902
45902
  }
45903
45903
  try {
45904
- payload = JSON.parse(crypto17.decodeBase64StringUtf8(segments[1]));
45904
+ payload = JSON.parse(crypto18.decodeBase64StringUtf8(segments[1]));
45905
45905
  } catch (err) {
45906
45906
  if (err instanceof Error) {
45907
45907
  err.message = `Can't parse token payload '${segments[0]}`;
@@ -45918,7 +45918,7 @@ var require_oauth2client = __commonJS({
45918
45918
  if (envelope.alg === "ES256") {
45919
45919
  signature = formatEcdsa.joseToDer(signature, "ES256").toString("base64");
45920
45920
  }
45921
- const verified = await crypto17.verify(cert, signed, signature);
45921
+ const verified = await crypto18.verify(cert, signed, signature);
45922
45922
  if (!verified) {
45923
45923
  throw new Error("Invalid token signature: " + jwt2);
45924
45924
  }
@@ -46286,14 +46286,14 @@ var require_buffer_equal_constant_time = __commonJS({
46286
46286
  var require_jwa = __commonJS({
46287
46287
  "../../node_modules/jwa/index.js"(exports2, module2) {
46288
46288
  var Buffer3 = require_safe_buffer().Buffer;
46289
- var crypto17 = require("crypto");
46289
+ var crypto18 = require("crypto");
46290
46290
  var formatEcdsa = require_ecdsa_sig_formatter();
46291
46291
  var util2 = require("util");
46292
46292
  var MSG_INVALID_ALGORITHM = '"%s" is not a valid algorithm.\n Supported algorithms are:\n "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".';
46293
46293
  var MSG_INVALID_SECRET = "secret must be a string or buffer";
46294
46294
  var MSG_INVALID_VERIFIER_KEY = "key must be a string or a buffer";
46295
46295
  var MSG_INVALID_SIGNER_KEY = "key must be a string, a buffer or an object";
46296
- var supportsKeyObjects = typeof crypto17.createPublicKey === "function";
46296
+ var supportsKeyObjects = typeof crypto18.createPublicKey === "function";
46297
46297
  if (supportsKeyObjects) {
46298
46298
  MSG_INVALID_VERIFIER_KEY += " or a KeyObject";
46299
46299
  MSG_INVALID_SECRET += "or a KeyObject";
@@ -46383,17 +46383,17 @@ var require_jwa = __commonJS({
46383
46383
  return function sign2(thing, secret) {
46384
46384
  checkIsSecretKey(secret);
46385
46385
  thing = normalizeInput(thing);
46386
- var hmac = crypto17.createHmac("sha" + bits, secret);
46386
+ var hmac = crypto18.createHmac("sha" + bits, secret);
46387
46387
  var sig = (hmac.update(thing), hmac.digest("base64"));
46388
46388
  return fromBase64(sig);
46389
46389
  };
46390
46390
  }
46391
46391
  var bufferEqual;
46392
- var timingSafeEqual2 = "timingSafeEqual" in crypto17 ? function timingSafeEqual3(a, b) {
46392
+ var timingSafeEqual2 = "timingSafeEqual" in crypto18 ? function timingSafeEqual3(a, b) {
46393
46393
  if (a.byteLength !== b.byteLength) {
46394
46394
  return false;
46395
46395
  }
46396
- return crypto17.timingSafeEqual(a, b);
46396
+ return crypto18.timingSafeEqual(a, b);
46397
46397
  } : function timingSafeEqual3(a, b) {
46398
46398
  if (!bufferEqual) {
46399
46399
  bufferEqual = require_buffer_equal_constant_time();
@@ -46410,7 +46410,7 @@ var require_jwa = __commonJS({
46410
46410
  return function sign2(thing, privateKey) {
46411
46411
  checkIsPrivateKey(privateKey);
46412
46412
  thing = normalizeInput(thing);
46413
- var signer = crypto17.createSign("RSA-SHA" + bits);
46413
+ var signer = crypto18.createSign("RSA-SHA" + bits);
46414
46414
  var sig = (signer.update(thing), signer.sign(privateKey, "base64"));
46415
46415
  return fromBase64(sig);
46416
46416
  };
@@ -46420,7 +46420,7 @@ var require_jwa = __commonJS({
46420
46420
  checkIsPublicKey(publicKey);
46421
46421
  thing = normalizeInput(thing);
46422
46422
  signature = toBase64(signature);
46423
- var verifier = crypto17.createVerify("RSA-SHA" + bits);
46423
+ var verifier = crypto18.createVerify("RSA-SHA" + bits);
46424
46424
  verifier.update(thing);
46425
46425
  return verifier.verify(publicKey, signature, "base64");
46426
46426
  };
@@ -46429,11 +46429,11 @@ var require_jwa = __commonJS({
46429
46429
  return function sign2(thing, privateKey) {
46430
46430
  checkIsPrivateKey(privateKey);
46431
46431
  thing = normalizeInput(thing);
46432
- var signer = crypto17.createSign("RSA-SHA" + bits);
46432
+ var signer = crypto18.createSign("RSA-SHA" + bits);
46433
46433
  var sig = (signer.update(thing), signer.sign({
46434
46434
  key: privateKey,
46435
- padding: crypto17.constants.RSA_PKCS1_PSS_PADDING,
46436
- saltLength: crypto17.constants.RSA_PSS_SALTLEN_DIGEST
46435
+ padding: crypto18.constants.RSA_PKCS1_PSS_PADDING,
46436
+ saltLength: crypto18.constants.RSA_PSS_SALTLEN_DIGEST
46437
46437
  }, "base64"));
46438
46438
  return fromBase64(sig);
46439
46439
  };
@@ -46443,12 +46443,12 @@ var require_jwa = __commonJS({
46443
46443
  checkIsPublicKey(publicKey);
46444
46444
  thing = normalizeInput(thing);
46445
46445
  signature = toBase64(signature);
46446
- var verifier = crypto17.createVerify("RSA-SHA" + bits);
46446
+ var verifier = crypto18.createVerify("RSA-SHA" + bits);
46447
46447
  verifier.update(thing);
46448
46448
  return verifier.verify({
46449
46449
  key: publicKey,
46450
- padding: crypto17.constants.RSA_PKCS1_PSS_PADDING,
46451
- saltLength: crypto17.constants.RSA_PSS_SALTLEN_DIGEST
46450
+ padding: crypto18.constants.RSA_PKCS1_PSS_PADDING,
46451
+ saltLength: crypto18.constants.RSA_PSS_SALTLEN_DIGEST
46452
46452
  }, signature, "base64");
46453
46453
  };
46454
46454
  }
@@ -48606,14 +48606,14 @@ var require_awsrequestsigner = __commonJS({
48606
48606
  }
48607
48607
  };
48608
48608
  exports2.AwsRequestSigner = AwsRequestSigner;
48609
- async function sign2(crypto17, key, msg) {
48610
- return await crypto17.signWithHmacSha256(key, msg);
48611
- }
48612
- async function getSigningKey(crypto17, key, dateStamp, region, serviceName) {
48613
- const kDate = await sign2(crypto17, `AWS4${key}`, dateStamp);
48614
- const kRegion = await sign2(crypto17, kDate, region);
48615
- const kService = await sign2(crypto17, kRegion, serviceName);
48616
- const kSigning = await sign2(crypto17, kService, "aws4_request");
48609
+ async function sign2(crypto18, key, msg) {
48610
+ return await crypto18.signWithHmacSha256(key, msg);
48611
+ }
48612
+ async function getSigningKey(crypto18, key, dateStamp, region, serviceName) {
48613
+ const kDate = await sign2(crypto18, `AWS4${key}`, dateStamp);
48614
+ const kRegion = await sign2(crypto18, kDate, region);
48615
+ const kService = await sign2(crypto18, kRegion, serviceName);
48616
+ const kSigning = await sign2(crypto18, kService, "aws4_request");
48617
48617
  return kSigning;
48618
48618
  }
48619
48619
  async function generateAuthenticationHeaderMap(options) {
@@ -50198,24 +50198,24 @@ var require_googleauth = __commonJS({
50198
50198
  const signed = await client.sign(data);
50199
50199
  return signed.signedBlob;
50200
50200
  }
50201
- const crypto17 = (0, crypto_1.createCrypto)();
50201
+ const crypto18 = (0, crypto_1.createCrypto)();
50202
50202
  if (client instanceof jwtclient_1.JWT && client.key) {
50203
- const sign2 = await crypto17.sign(client.key, data);
50203
+ const sign2 = await crypto18.sign(client.key, data);
50204
50204
  return sign2;
50205
50205
  }
50206
50206
  const creds = await this.getCredentials();
50207
50207
  if (!creds.client_email) {
50208
50208
  throw new Error("Cannot sign data without `client_email`.");
50209
50209
  }
50210
- return this.signBlob(crypto17, creds.client_email, data, endpoint);
50210
+ return this.signBlob(crypto18, creds.client_email, data, endpoint);
50211
50211
  }
50212
- async signBlob(crypto17, emailOrUniqueId, data, endpoint) {
50212
+ async signBlob(crypto18, emailOrUniqueId, data, endpoint) {
50213
50213
  const url = new URL(endpoint + `${emailOrUniqueId}:signBlob`);
50214
50214
  const res = await this.request({
50215
50215
  method: "POST",
50216
50216
  url: url.href,
50217
50217
  data: {
50218
- payload: crypto17.encodeBase64StringUtf8(data)
50218
+ payload: crypto18.encodeBase64StringUtf8(data)
50219
50219
  },
50220
50220
  retry: true,
50221
50221
  retryConfig: {
@@ -50632,7 +50632,7 @@ var require_src10 = __commonJS({
50632
50632
  var require_object_hash = __commonJS({
50633
50633
  "../../node_modules/object-hash/index.js"(exports2, module2) {
50634
50634
  "use strict";
50635
- var crypto17 = require("crypto");
50635
+ var crypto18 = require("crypto");
50636
50636
  exports2 = module2.exports = objectHash;
50637
50637
  function objectHash(object, options) {
50638
50638
  options = applyDefaults(object, options);
@@ -50650,7 +50650,7 @@ var require_object_hash = __commonJS({
50650
50650
  exports2.keysMD5 = function(object) {
50651
50651
  return objectHash(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
50652
50652
  };
50653
- var hashes = crypto17.getHashes ? crypto17.getHashes().slice() : ["sha1", "md5"];
50653
+ var hashes = crypto18.getHashes ? crypto18.getHashes().slice() : ["sha1", "md5"];
50654
50654
  hashes.push("passthrough");
50655
50655
  var encodings = ["buffer", "hex", "binary", "base64"];
50656
50656
  function applyDefaults(object, sourceOptions) {
@@ -50696,7 +50696,7 @@ var require_object_hash = __commonJS({
50696
50696
  function hash(object, options) {
50697
50697
  var hashingStream;
50698
50698
  if (options.algorithm !== "passthrough") {
50699
- hashingStream = crypto17.createHash(options.algorithm);
50699
+ hashingStream = crypto18.createHash(options.algorithm);
50700
50700
  } else {
50701
50701
  hashingStream = new PassThrough();
50702
50702
  }
@@ -150124,14 +150124,14 @@ var require_etag = __commonJS({
150124
150124
  "../../node_modules/etag/index.js"(exports2, module2) {
150125
150125
  "use strict";
150126
150126
  module2.exports = etag;
150127
- var crypto17 = require("crypto");
150127
+ var crypto18 = require("crypto");
150128
150128
  var Stats = require("fs").Stats;
150129
150129
  var toString = Object.prototype.toString;
150130
150130
  function entitytag(entity) {
150131
150131
  if (entity.length === 0) {
150132
150132
  return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"';
150133
150133
  }
150134
- var hash = crypto17.createHash("sha1").update(entity, "utf8").digest("base64").substring(0, 27);
150134
+ var hash = crypto18.createHash("sha1").update(entity, "utf8").digest("base64").substring(0, 27);
150135
150135
  var len = typeof entity === "string" ? Buffer.byteLength(entity, "utf8") : entity.length;
150136
150136
  return '"' + len.toString(16) + "-" + hash + '"';
150137
150137
  }
@@ -172492,17 +172492,17 @@ var require_content_disposition = __commonJS({
172492
172492
  // ../../node_modules/cookie-signature/index.js
172493
172493
  var require_cookie_signature = __commonJS({
172494
172494
  "../../node_modules/cookie-signature/index.js"(exports2) {
172495
- var crypto17 = require("crypto");
172495
+ var crypto18 = require("crypto");
172496
172496
  exports2.sign = function(val, secret) {
172497
172497
  if ("string" != typeof val) throw new TypeError("Cookie value must be provided as a string.");
172498
172498
  if (null == secret) throw new TypeError("Secret key must be provided.");
172499
- return val + "." + crypto17.createHmac("sha256", secret).update(val).digest("base64").replace(/\=+$/, "");
172499
+ return val + "." + crypto18.createHmac("sha256", secret).update(val).digest("base64").replace(/\=+$/, "");
172500
172500
  };
172501
172501
  exports2.unsign = function(input, secret) {
172502
172502
  if ("string" != typeof input) throw new TypeError("Signed cookie string must be provided.");
172503
172503
  if (null == secret) throw new TypeError("Secret key must be provided.");
172504
172504
  var tentativeValue = input.slice(0, input.lastIndexOf(".")), expectedInput = exports2.sign(tentativeValue, secret), expectedBuffer = Buffer.from(expectedInput), inputBuffer = Buffer.from(input);
172505
- return expectedBuffer.length === inputBuffer.length && crypto17.timingSafeEqual(expectedBuffer, inputBuffer) ? tentativeValue : false;
172505
+ return expectedBuffer.length === inputBuffer.length && crypto18.timingSafeEqual(expectedBuffer, inputBuffer) ? tentativeValue : false;
172506
172506
  };
172507
172507
  }
172508
172508
  });
@@ -183802,7 +183802,7 @@ var ArtifactDecryptor = class {
183802
183802
  } finally {
183803
183803
  plaintext = "";
183804
183804
  }
183805
- return { values, keys: artifact.keys, revision: artifact.revision };
183805
+ return { values, keys: Object.keys(values), revision: artifact.revision };
183806
183806
  }
183807
183807
  /** KMS envelope: unwrap DEK via KMS, then AES-256-GCM decrypt. */
183808
183808
  async decryptKmsEnvelope(artifact) {
@@ -183859,14 +183859,13 @@ var ArtifactDecryptor = class {
183859
183859
  var crypto15 = __toESM(require("crypto"));
183860
183860
  function buildSigningPayload(artifact) {
183861
183861
  const fields = [
183862
- "clef-sig-v2",
183862
+ "clef-sig-v3",
183863
183863
  String(artifact.version),
183864
183864
  artifact.identity,
183865
183865
  artifact.environment,
183866
183866
  artifact.revision,
183867
183867
  artifact.packedAt,
183868
183868
  artifact.ciphertextHash,
183869
- [...artifact.keys].sort().join(","),
183870
183869
  artifact.expiresAt ?? "",
183871
183870
  artifact.envelope?.provider ?? "",
183872
183871
  artifact.envelope?.keyId ?? "",
@@ -183950,7 +183949,6 @@ var ArtifactPoller = class {
183950
183949
  this.options.onRefresh?.(artifact.revision);
183951
183950
  this.telemetry?.artifactRefreshed({
183952
183951
  revision: artifact.revision,
183953
- keyCount: artifact.keys.length,
183954
183952
  kmsEnvelope: !!artifact.envelope
183955
183953
  });
183956
183954
  }
@@ -184113,14 +184111,15 @@ var ArtifactPoller = class {
184113
184111
  const artifact = this.validateArtifact(parsed);
184114
184112
  if (artifact.revision === this.lastRevision) return;
184115
184113
  const { values } = await this.decryptor.decrypt(artifact);
184116
- this.options.cache.swap(values, artifact.keys, artifact.revision);
184114
+ const keys = Object.keys(values);
184115
+ this.options.cache.swap(values, keys, artifact.revision);
184117
184116
  this.lastRevision = artifact.revision;
184118
184117
  this.lastContentHash = contentHash ?? null;
184119
184118
  this.lastExpiresAt = artifact.expiresAt ?? null;
184120
184119
  this.options.onRefresh?.(artifact.revision);
184121
184120
  this.telemetry?.artifactRefreshed({
184122
184121
  revision: artifact.revision,
184123
- keyCount: artifact.keys.length,
184122
+ keyCount: keys.length,
184124
184123
  kmsEnvelope: !!artifact.envelope
184125
184124
  });
184126
184125
  }
@@ -184228,10 +184227,6 @@ var EncryptedArtifactStore = class {
184228
184227
  getStoredAt() {
184229
184228
  return this._storedAt;
184230
184229
  }
184231
- /** Get key names from the stored artifact metadata (no decryption needed). */
184232
- getKeys() {
184233
- return this.artifact ? [...this.artifact.keys] : [];
184234
- }
184235
184230
  /** Get the revision from the stored artifact. */
184236
184231
  getRevision() {
184237
184232
  return this.artifact?.revision ?? null;
@@ -184594,6 +184589,176 @@ var VcsArtifactSource = class {
184594
184589
  }
184595
184590
  };
184596
184591
 
184592
+ // ../runtime/src/sources/s3.ts
184593
+ var crypto17 = __toESM(require("crypto"));
184594
+ function isS3Url(url) {
184595
+ return parseS3UrlSafe(url) !== null;
184596
+ }
184597
+ function parseS3Url(url) {
184598
+ const loc = parseS3UrlSafe(url);
184599
+ if (!loc) throw new Error(`Not a valid S3 URL: ${url}`);
184600
+ return loc;
184601
+ }
184602
+ function parseS3UrlSafe(url) {
184603
+ let u;
184604
+ try {
184605
+ u = new URL(url);
184606
+ } catch {
184607
+ return null;
184608
+ }
184609
+ if (u.protocol !== "https:") return null;
184610
+ const host = u.hostname;
184611
+ const key = u.pathname.slice(1);
184612
+ if (!key) return null;
184613
+ const vhMatch = host.match(/^(.+)\.s3\.([a-z0-9-]+)\.amazonaws\.com$/) ?? host.match(/^(.+)\.s3\.amazonaws\.com$/);
184614
+ if (vhMatch) {
184615
+ return { bucket: vhMatch[1], key, region: vhMatch[2] || "us-east-1" };
184616
+ }
184617
+ const psMatch = host.match(/^s3\.([a-z0-9-]+)\.amazonaws\.com$/) ?? host.match(/^s3\.amazonaws\.com$/);
184618
+ if (psMatch) {
184619
+ const slashIdx = key.indexOf("/");
184620
+ if (slashIdx < 0) return null;
184621
+ return {
184622
+ bucket: key.slice(0, slashIdx),
184623
+ key: key.slice(slashIdx + 1),
184624
+ region: psMatch[1] || "us-east-1"
184625
+ };
184626
+ }
184627
+ return null;
184628
+ }
184629
+ var S3ArtifactSource = class {
184630
+ url;
184631
+ location;
184632
+ cachedCredentials = null;
184633
+ constructor(url) {
184634
+ this.url = url;
184635
+ this.location = parseS3Url(url);
184636
+ }
184637
+ async fetch() {
184638
+ const creds = await this.resolveCredentials();
184639
+ const { bucket, key, region } = this.location;
184640
+ const host = `${bucket}.s3.${region}.amazonaws.com`;
184641
+ const path4 = `/${encodeS3Key(key)}`;
184642
+ const now = /* @__PURE__ */ new Date();
184643
+ const headers = signS3GetRequest(host, path4, region, creds, now);
184644
+ const res = await globalThis.fetch(`https://${host}${path4}`, { headers });
184645
+ if (!res.ok) {
184646
+ throw new Error(
184647
+ `Failed to fetch artifact from ${this.describe()}: ${res.status} ${res.statusText}`
184648
+ );
184649
+ }
184650
+ const raw = await res.text();
184651
+ const etag = res.headers.get("etag") ?? void 0;
184652
+ return { raw, contentHash: etag };
184653
+ }
184654
+ describe() {
184655
+ const { bucket, key } = this.location;
184656
+ return `S3 s3://${bucket}/${key}`;
184657
+ }
184658
+ async resolveCredentials() {
184659
+ if (this.cachedCredentials && Date.now() < this.cachedCredentials.expiresAt - 3e5) {
184660
+ return this.cachedCredentials.creds;
184661
+ }
184662
+ const relativeUri = process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI;
184663
+ if (relativeUri) {
184664
+ return this.fetchEcsCredentials(`http://169.254.170.2${relativeUri}`);
184665
+ }
184666
+ const fullUri = process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI;
184667
+ if (fullUri) {
184668
+ return this.fetchEcsCredentials(fullUri);
184669
+ }
184670
+ const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
184671
+ const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
184672
+ if (accessKeyId && secretAccessKey) {
184673
+ return {
184674
+ accessKeyId,
184675
+ secretAccessKey,
184676
+ sessionToken: process.env.AWS_SESSION_TOKEN
184677
+ };
184678
+ }
184679
+ throw new Error(
184680
+ "No AWS credentials found. Set AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, or run in ECS/Fargate with a task role."
184681
+ );
184682
+ }
184683
+ async fetchEcsCredentials(endpoint) {
184684
+ const headers = {};
184685
+ const authToken = process.env.AWS_CONTAINER_AUTHORIZATION_TOKEN;
184686
+ if (authToken) {
184687
+ headers["Authorization"] = authToken;
184688
+ }
184689
+ const res = await globalThis.fetch(endpoint, { headers });
184690
+ if (!res.ok) {
184691
+ throw new Error(`Failed to fetch ECS credentials: ${res.status} ${res.statusText}`);
184692
+ }
184693
+ const data = await res.json();
184694
+ const creds = {
184695
+ accessKeyId: data.AccessKeyId,
184696
+ secretAccessKey: data.SecretAccessKey,
184697
+ sessionToken: data.Token
184698
+ };
184699
+ if (data.Expiration) {
184700
+ this.cachedCredentials = {
184701
+ creds,
184702
+ expiresAt: new Date(data.Expiration).getTime()
184703
+ };
184704
+ }
184705
+ return creds;
184706
+ }
184707
+ };
184708
+ function hmacSha256(key, data) {
184709
+ return crypto17.createHmac("sha256", key).update(data, "utf-8").digest();
184710
+ }
184711
+ function sha256Hex(data) {
184712
+ return crypto17.createHash("sha256").update(data, "utf-8").digest("hex");
184713
+ }
184714
+ function toAmzDate(date) {
184715
+ return date.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
184716
+ }
184717
+ function toDateStamp(date) {
184718
+ return toAmzDate(date).slice(0, 8);
184719
+ }
184720
+ function encodeS3Key(key) {
184721
+ return key.split("/").map((s) => encodeURIComponent(s)).join("/");
184722
+ }
184723
+ function signS3GetRequest(host, path4, region, creds, now) {
184724
+ const amzDate = toAmzDate(now);
184725
+ const dateStamp = toDateStamp(now);
184726
+ const service = "s3";
184727
+ const scope = `${dateStamp}/${region}/${service}/aws4_request`;
184728
+ const headers = {
184729
+ host,
184730
+ "x-amz-date": amzDate,
184731
+ "x-amz-content-sha256": "UNSIGNED-PAYLOAD"
184732
+ };
184733
+ if (creds.sessionToken) {
184734
+ headers["x-amz-security-token"] = creds.sessionToken;
184735
+ }
184736
+ const signedHeaderKeys = Object.keys(headers).sort();
184737
+ const signedHeaders = signedHeaderKeys.join(";");
184738
+ const canonicalHeaders = signedHeaderKeys.map((k) => `${k}:${headers[k]}
184739
+ `).join("");
184740
+ const canonicalRequest = [
184741
+ "GET",
184742
+ path4,
184743
+ "",
184744
+ // no query string
184745
+ canonicalHeaders,
184746
+ signedHeaders,
184747
+ "UNSIGNED-PAYLOAD"
184748
+ ].join("\n");
184749
+ const stringToSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256Hex(canonicalRequest)].join("\n");
184750
+ const kDate = hmacSha256(`AWS4${creds.secretAccessKey}`, dateStamp);
184751
+ const kRegion = hmacSha256(kDate, region);
184752
+ const kService = hmacSha256(kRegion, service);
184753
+ const kSigning = hmacSha256(kService, "aws4_request");
184754
+ const signature = hmacSha256(kSigning, stringToSign).toString("hex");
184755
+ const authorization = `AWS4-HMAC-SHA256 Credential=${creds.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
184756
+ return {
184757
+ ...headers,
184758
+ Authorization: authorization
184759
+ };
184760
+ }
184761
+
184597
184762
  // src/server.ts
184598
184763
  var import_crypto16 = require("crypto");
184599
184764
  var import_express = __toESM(require_express2());
@@ -184702,9 +184867,20 @@ function startAgentServer(options) {
184702
184867
  res.json(all);
184703
184868
  }
184704
184869
  });
184705
- app.get("/v1/keys", (_req, res) => {
184870
+ app.get("/v1/keys", async (_req, res) => {
184706
184871
  if (jitMode) {
184707
- res.json(encryptedStore.getKeys());
184872
+ const artifact = encryptedStore.get();
184873
+ if (!artifact) {
184874
+ res.status(503).json({ error: "Secrets not yet loaded" });
184875
+ return;
184876
+ }
184877
+ try {
184878
+ const { values } = await decryptor.decrypt(artifact);
184879
+ res.json(Object.keys(values));
184880
+ } catch (err) {
184881
+ const message = err instanceof Error ? err.message : String(err);
184882
+ res.status(503).json({ error: "Decryption failed", detail: message });
184883
+ }
184708
184884
  } else {
184709
184885
  res.json(cache.getKeys());
184710
184886
  }
@@ -184907,7 +185083,7 @@ async function initialFetch(poller, jitMode, encryptedStore, cache, sourceDesc)
184907
185083
  await poller.fetchAndValidate();
184908
185084
  const artifact = encryptedStore.get();
184909
185085
  const { values } = await poller.getDecryptor().decrypt(artifact);
184910
- cache.swap(values, artifact.keys, artifact.revision);
185086
+ cache.swap(values, Object.keys(values), artifact.revision);
184911
185087
  } else {
184912
185088
  await poller.fetchAndDecrypt();
184913
185089
  }
@@ -184930,7 +185106,7 @@ async function initialFetch(poller, jitMode, encryptedStore, cache, sourceDesc)
184930
185106
  }
184931
185107
 
184932
185108
  // package.json
184933
- var version5 = "0.1.11-beta.62";
185109
+ var version5 = "0.1.11-beta.68";
184934
185110
 
184935
185111
  // src/main.ts
184936
185112
  var isLambda = !!process.env.AWS_LAMBDA_RUNTIME_API;
@@ -184954,7 +185130,13 @@ async function main() {
184954
185130
  });
184955
185131
  source = new VcsArtifactSource(provider, config.vcs.identity, config.vcs.environment);
184956
185132
  } else if (config.source) {
184957
- source = config.source.startsWith("http://") || config.source.startsWith("https://") ? new HttpArtifactSource(config.source) : new FileArtifactSource(config.source);
185133
+ if (isS3Url(config.source)) {
185134
+ source = new S3ArtifactSource(config.source);
185135
+ } else if (config.source.startsWith("http://") || config.source.startsWith("https://")) {
185136
+ source = new HttpArtifactSource(config.source);
185137
+ } else {
185138
+ source = new FileArtifactSource(config.source);
185139
+ }
184958
185140
  } else {
184959
185141
  throw new ConfigError("No artifact source configured.");
184960
185142
  }