canopycms-cdk 0.2.0-int.119 → 0.2.0-int.121

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.
@@ -680,7 +680,9 @@ init_sanitize_href();
680
680
  var DEFAULT_MAX_UPLOAD_BYTES2 = 50 * 1024 * 1024;
681
681
  var JSON_SUFFIX = ".json";
682
682
  var PRESIGN_EXPIRY_SECONDS = 15 * 60;
683
- var PRESIGNED_READ_EXPIRY_SECONDS = 5 * 60;
683
+ var PRESIGNED_READ_WINDOW_SECONDS = 60 * 60;
684
+ var PRESIGNED_READ_EXPIRY_SECONDS = 2 * PRESIGNED_READ_WINDOW_SECONDS;
685
+ var CREDENTIAL_EXPIRY_MARGIN_SECONDS = 60;
684
686
  function matchesAwsError(err2, name, httpStatusCode) {
685
687
  if (!(err2 instanceof Error)) return false;
686
688
  const shaped = err2;
@@ -898,12 +900,27 @@ var S3AssetStore = class {
898
900
  }
899
901
  }
900
902
  }
901
- /** HEADs first: signing is local and succeeds for a missing key too. */
903
+ /**
904
+ * HEADs first: signing is local and succeeds for a missing key too. A URL signed with temporary
905
+ * credentials dies when they expire, whatever its own expiry, so `maxAgeSeconds` also stops short
906
+ * of the credentials' `expiration` when the provider reports one.
907
+ */
902
908
  async presignPublicObjectRead(key) {
903
909
  if (!await this.hasPublicObject(key)) return null;
904
- return (0, import_s3_request_presigner.getSignedUrl)(this.client, new import_client_s3.GetObjectCommand({ Bucket: this.bucket, Key: key }), {
905
- expiresIn: PRESIGNED_READ_EXPIRY_SECONDS
906
- });
910
+ const { expiration } = await this.client.config.credentials();
911
+ const nowSeconds = Math.floor(Date.now() / 1e3);
912
+ const windowStart = nowSeconds - nowSeconds % PRESIGNED_READ_WINDOW_SECONDS;
913
+ const url = await (0, import_s3_request_presigner.getSignedUrl)(
914
+ this.client,
915
+ new import_client_s3.GetObjectCommand({ Bucket: this.bucket, Key: key }),
916
+ { expiresIn: PRESIGNED_READ_EXPIRY_SECONDS, signingDate: new Date(windowStart * 1e3) }
917
+ );
918
+ let maxAgeSeconds = windowStart + PRESIGNED_READ_WINDOW_SECONDS - nowSeconds;
919
+ if (expiration) {
920
+ const credentialSeconds = Math.floor(expiration.getTime() / 1e3) - nowSeconds;
921
+ maxAgeSeconds = Math.min(maxAgeSeconds, credentialSeconds - CREDENTIAL_EXPIRY_MARGIN_SECONDS);
922
+ }
923
+ return { url, maxAgeSeconds: Math.max(0, maxAgeSeconds) };
907
924
  }
908
925
  async putMetaIfAbsent(hash32, meta) {
909
926
  return this.putIfAbsent({
@@ -1162,7 +1179,11 @@ async function applyTransform(input, directives) {
1162
1179
  var TRANSFORM_CACHE_CONTROL = "public, max-age=31536000, immutable";
1163
1180
  var LAZY_TRANSFORM_TAG = { key: "canopy-transform", value: "lazy" };
1164
1181
  async function storeTransform(store2, parsed, key, options = {}) {
1165
- const meta = await store2.getMeta(parsed.hash32);
1182
+ const { source } = options;
1183
+ if (source && source.meta.hash32 !== parsed.hash32) {
1184
+ throw new Error(`source is asset ${source.meta.hash32}, not ${parsed.hash32}`);
1185
+ }
1186
+ const meta = source?.meta ?? await store2.getMeta(parsed.hash32);
1166
1187
  if (!meta) {
1167
1188
  return { ok: false, status: 404, error: `Asset ${parsed.hash32} has no meta in the store` };
1168
1189
  }
@@ -1180,7 +1201,7 @@ async function storeTransform(store2, parsed, key, options = {}) {
1180
1201
  if (requestedFormat === void 0 && parsed.ext !== meta.ext) {
1181
1202
  return { ok: false, status: 400, error: "Extension does not match the source format" };
1182
1203
  }
1183
- const original = await store2.readOriginal(parsed.hash32, meta.ext);
1204
+ const original = source ? { data: source.data, ext: meta.ext } : await store2.readOriginal(parsed.hash32, meta.ext);
1184
1205
  if (!original) {
1185
1206
  return { ok: false, status: 404, error: `Asset ${parsed.hash32} has no original in the store` };
1186
1207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopycms-cdk",
3
- "version": "0.2.0-int.119",
3
+ "version": "0.2.0-int.121",
4
4
  "description": "AWS CDK constructs and EC2 worker for CanopyCMS deployment",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "peerDependencies": {
35
35
  "aws-cdk-lib": "^2.260.0",
36
36
  "constructs": "^10.0.0",
37
- "canopycms": "0.2.0-int.119"
37
+ "canopycms": "0.2.0-int.121"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "aws-cdk-lib": {
@@ -60,8 +60,8 @@
60
60
  "tsx": "^4.19.0",
61
61
  "typescript": "^5.6.3",
62
62
  "vitest": "^4.1.0",
63
- "canopycms": "0.2.0-int.119",
64
- "canopycms-auth-clerk": "0.2.0-int.119"
63
+ "canopycms-auth-clerk": "0.2.0-int.121",
64
+ "canopycms": "0.2.0-int.121"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "rm -rf dist && tsc && node ../../scripts/add-js-extensions.mjs dist",
@@ -82491,7 +82491,7 @@ init_error();
82491
82491
  init_worker_status();
82492
82492
 
82493
82493
  // ../canopycms/src/version.ts
82494
- var CANOPYCMS_VERSION = "0.2.0-int.119";
82494
+ var CANOPYCMS_VERSION = "0.2.0-int.121";
82495
82495
 
82496
82496
  // ../canopycms/src/worker/schema-gate.ts
82497
82497
  import fs14 from "node:fs/promises";
@@ -1 +1 @@
1
- 8a7b7063f59c69ec21cd138b5543e669a5905966b38b21bcb9ed7a497ad91622 index.js
1
+ b819cdeaa615cddf220a82198cb6e069d33073ddae11b0a764e49e46cc986696 index.js