canopycms-cdk 0.1.0-int.115 → 0.2.0-int.119
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/constructs/asset-support.d.ts +9 -5
- package/dist/constructs/asset-support.js +12 -4
- package/dist/constructs/cms-service.js +4 -2
- package/dist/constructs/worker-units.d.ts +1 -1
- package/dist/constructs/worker-units.js +1 -1
- package/lambda/asset-transform/dist/handler.js +106 -33
- package/package.json +4 -4
- package/worker/dist/index.js +28 -10
- package/worker/dist/index.js.sha256 +1 -1
|
@@ -37,9 +37,7 @@ export interface AssetSupportProps {
|
|
|
37
37
|
* bucket) instead of creating one. The caller owns that bucket's
|
|
38
38
|
* lifecycle rules and CORS configuration in this mode: `IBucket` (an
|
|
39
39
|
* imported bucket reference) has no CDK-level `addLifecycleRule`/
|
|
40
|
-
* `addCorsRule` - only a bucket this construct creates itself does.
|
|
41
|
-
* `.claude/future-tasks/docs-site-assets-wiring.md` for the BYO-mode
|
|
42
|
-
* wiring this is designed for.
|
|
40
|
+
* `addCorsRule` - only a bucket this construct creates itself does.
|
|
43
41
|
*
|
|
44
42
|
* @default - a new private bucket is created (standalone mode)
|
|
45
43
|
*/
|
|
@@ -491,8 +489,14 @@ export declare class AssetSupport extends Construct {
|
|
|
491
489
|
*
|
|
492
490
|
* - put on `asset-staging/` (presigned POST + proxied `writeStaging`)
|
|
493
491
|
* - get on `asset-staging/` + `asset-originals/` + `asset-meta/` + `assets/`
|
|
494
|
-
* - put on `asset-originals/` + `asset-meta/` + `assets/`
|
|
495
|
-
* - delete on `asset-staging/` + `asset-
|
|
492
|
+
* - put on `asset-originals/` + `asset-meta/` + `asset-hidden/` + `assets/`
|
|
493
|
+
* - delete on `asset-staging/` + `asset-hidden/` (restoring a file removed from the library)
|
|
494
|
+
*
|
|
495
|
+
* Hidden markers are only listed, written and deleted, never read; the bucket-wide
|
|
496
|
+
* `s3:ListBucket` the read grants carry covers their listing.
|
|
497
|
+
*
|
|
498
|
+
* No delete on `asset-meta/`: meta is never deleted, since every transform not yet stored is
|
|
499
|
+
* computed from it.
|
|
496
500
|
*/
|
|
497
501
|
grantUploadAccess(grantee: iam.IGrantable): void;
|
|
498
502
|
}
|
|
@@ -29,7 +29,7 @@ const transformAssetDir = path.join(__dirname, '..', '..', 'lambda', 'asset-tran
|
|
|
29
29
|
*/
|
|
30
30
|
const DEPLOYABLE_MARKER = '.deployable';
|
|
31
31
|
/**
|
|
32
|
-
* The
|
|
32
|
+
* The S3 key prefixes the asset system uses. Source of truth is
|
|
33
33
|
* `packages/canopycms/src/assets/asset-prefixes.ts`; these are copied as
|
|
34
34
|
* literals rather than imported so this construct synths in a consumer CDK app
|
|
35
35
|
* that has no `canopycms` resolvable. (The transform Lambda does import them -
|
|
@@ -39,6 +39,7 @@ const PREFIXES = {
|
|
|
39
39
|
originals: 'asset-originals',
|
|
40
40
|
staging: 'asset-staging',
|
|
41
41
|
meta: 'asset-meta',
|
|
42
|
+
hidden: 'asset-hidden',
|
|
42
43
|
public: 'assets',
|
|
43
44
|
transform: 'assets/t',
|
|
44
45
|
};
|
|
@@ -924,8 +925,14 @@ export class AssetSupport extends Construct {
|
|
|
924
925
|
*
|
|
925
926
|
* - put on `asset-staging/` (presigned POST + proxied `writeStaging`)
|
|
926
927
|
* - get on `asset-staging/` + `asset-originals/` + `asset-meta/` + `assets/`
|
|
927
|
-
* - put on `asset-originals/` + `asset-meta/` + `assets/`
|
|
928
|
-
* - delete on `asset-staging/` + `asset-
|
|
928
|
+
* - put on `asset-originals/` + `asset-meta/` + `asset-hidden/` + `assets/`
|
|
929
|
+
* - delete on `asset-staging/` + `asset-hidden/` (restoring a file removed from the library)
|
|
930
|
+
*
|
|
931
|
+
* Hidden markers are only listed, written and deleted, never read; the bucket-wide
|
|
932
|
+
* `s3:ListBucket` the read grants carry covers their listing.
|
|
933
|
+
*
|
|
934
|
+
* No delete on `asset-meta/`: meta is never deleted, since every transform not yet stored is
|
|
935
|
+
* computed from it.
|
|
929
936
|
*/
|
|
930
937
|
grantUploadAccess(grantee) {
|
|
931
938
|
this.bucket.grantPut(grantee, `${PREFIXES.staging}/*`);
|
|
@@ -935,8 +942,9 @@ export class AssetSupport extends Construct {
|
|
|
935
942
|
this.bucket.grantRead(grantee, `${PREFIXES.public}/*`);
|
|
936
943
|
this.bucket.grantPut(grantee, `${PREFIXES.originals}/*`);
|
|
937
944
|
this.bucket.grantPut(grantee, `${PREFIXES.meta}/*`);
|
|
945
|
+
this.bucket.grantPut(grantee, `${PREFIXES.hidden}/*`);
|
|
938
946
|
this.bucket.grantPut(grantee, `${PREFIXES.public}/*`);
|
|
939
947
|
this.bucket.grantDelete(grantee, `${PREFIXES.staging}/*`);
|
|
940
|
-
this.bucket.grantDelete(grantee, `${PREFIXES.
|
|
948
|
+
this.bucket.grantDelete(grantee, `${PREFIXES.hidden}/*`);
|
|
941
949
|
}
|
|
942
950
|
}
|
|
@@ -12,7 +12,7 @@ import { CANOPY_INSPECT, EFS_MOUNT_PATH, GATEWAY_LOG, GATEWAY_LOG_DIR, GATEWAY_U
|
|
|
12
12
|
* Duplicated rather than imported so a CONSTRUCT-only consumer does not pay for
|
|
13
13
|
* the core package's module graph. Whether that still justifies duplicating is
|
|
14
14
|
* an open question, tracked alongside the same question about the S3 prefix
|
|
15
|
-
* constants in
|
|
15
|
+
* constants in safeinsights/canopycms#608.
|
|
16
16
|
*
|
|
17
17
|
* Drift between the two copies is caught by a test, not by this comment:
|
|
18
18
|
* cms-deploy.test.ts drives both this construct and the runtime predicate over
|
|
@@ -963,6 +963,7 @@ export class CanopyCmsService extends Construct {
|
|
|
963
963
|
staging: 'asset-staging',
|
|
964
964
|
originals: 'asset-originals',
|
|
965
965
|
meta: 'asset-meta',
|
|
966
|
+
hidden: 'asset-hidden',
|
|
966
967
|
public: 'assets',
|
|
967
968
|
};
|
|
968
969
|
props.assetBucket.grantPut(this.lambdaFunction, `${prefixes.staging}/*`);
|
|
@@ -972,9 +973,10 @@ export class CanopyCmsService extends Construct {
|
|
|
972
973
|
props.assetBucket.grantRead(this.lambdaFunction, `${prefixes.public}/*`);
|
|
973
974
|
props.assetBucket.grantPut(this.lambdaFunction, `${prefixes.originals}/*`);
|
|
974
975
|
props.assetBucket.grantPut(this.lambdaFunction, `${prefixes.meta}/*`);
|
|
976
|
+
props.assetBucket.grantPut(this.lambdaFunction, `${prefixes.hidden}/*`);
|
|
975
977
|
props.assetBucket.grantPut(this.lambdaFunction, `${prefixes.public}/*`);
|
|
976
978
|
props.assetBucket.grantDelete(this.lambdaFunction, `${prefixes.staging}/*`);
|
|
977
|
-
props.assetBucket.grantDelete(this.lambdaFunction, `${prefixes.
|
|
979
|
+
props.assetBucket.grantDelete(this.lambdaFunction, `${prefixes.hidden}/*`);
|
|
978
980
|
}
|
|
979
981
|
const workerSg = new ec2.SecurityGroup(this, 'WorkerSg', {
|
|
980
982
|
vpc: this.vpc,
|
|
@@ -72,7 +72,7 @@ export declare const INSPECT_RC = "/opt/canopy-worker/inspect.rc";
|
|
|
72
72
|
* `canopy-inspect`: run one command (or, with `--interactive`, a shell) as the worker's user,
|
|
73
73
|
* inside exactly the worker's sandbox, so a hostile repository on EFS reaches only what the
|
|
74
74
|
* worker reaches. `--interactive` relays the sandbox's terminal raw, and the worker can reach its
|
|
75
|
-
* pty (
|
|
75
|
+
* pty (safeinsights/canopycms#604). Run as root. Nothing after `--` is composed by a shell
|
|
76
76
|
* outside the sandbox: inspect-checks runs its assertions, then execs the command.
|
|
77
77
|
*/
|
|
78
78
|
export declare function canopyInspectScript(): string[];
|
|
@@ -288,7 +288,7 @@ function shellWord(value) {
|
|
|
288
288
|
* `canopy-inspect`: run one command (or, with `--interactive`, a shell) as the worker's user,
|
|
289
289
|
* inside exactly the worker's sandbox, so a hostile repository on EFS reaches only what the
|
|
290
290
|
* worker reaches. `--interactive` relays the sandbox's terminal raw, and the worker can reach its
|
|
291
|
-
* pty (
|
|
291
|
+
* pty (safeinsights/canopycms#604). Run as root. Nothing after `--` is composed by a shell
|
|
292
292
|
* outside the sandbox: inspect-checks runs its assertions, then execs the command.
|
|
293
293
|
*/
|
|
294
294
|
export function canopyInspectScript() {
|
|
@@ -354,6 +354,8 @@ var ASSET_PREFIXES = {
|
|
|
354
354
|
originals: "asset-originals",
|
|
355
355
|
staging: "asset-staging",
|
|
356
356
|
meta: "asset-meta",
|
|
357
|
+
/** One marker per file removed from the media library; its meta stays (see `hideAsset`). */
|
|
358
|
+
hidden: "asset-hidden",
|
|
357
359
|
public: "assets",
|
|
358
360
|
/** Transform-output prefix; directive-aware key building lives in transform-directives.ts. */
|
|
359
361
|
transform: "assets/t"
|
|
@@ -368,11 +370,13 @@ function createKeyBuilders(prefixes = ASSET_PREFIXES) {
|
|
|
368
370
|
stagingKey: (uuid) => `${prefixes.staging}/${uuid}`,
|
|
369
371
|
metaKey: (hash32) => `${prefixes.meta}/${hash32}.json`,
|
|
370
372
|
metaPrefix: () => `${prefixes.meta}/`,
|
|
373
|
+
hiddenKey: (hash32) => `${prefixes.hidden}/${hash32}.json`,
|
|
374
|
+
hiddenPrefix: () => `${prefixes.hidden}/`,
|
|
371
375
|
publicKey: (hash32, slug, ext) => `${prefixes.public}/${hash32}/${slug}.${ext}`
|
|
372
376
|
};
|
|
373
377
|
}
|
|
374
378
|
var keyBuilders = createKeyBuilders();
|
|
375
|
-
var { originalKey, stagingKey, metaKey, publicKey } = keyBuilders;
|
|
379
|
+
var { originalKey, stagingKey, metaKey, hiddenKey, publicKey } = keyBuilders;
|
|
376
380
|
var { originalPrefix, metaPrefix } = keyBuilders;
|
|
377
381
|
|
|
378
382
|
// ../canopycms/src/assets/store-local.ts
|
|
@@ -381,6 +385,12 @@ var DEFAULT_LIST_LIMIT = 24;
|
|
|
381
385
|
var HEADERS_SIDECAR_SUFFIX = ".headers.json";
|
|
382
386
|
var TEMP_DIR = ".asset-tmp";
|
|
383
387
|
var ORIGINAL_EXT_RE = /^[a-z0-9]+$/;
|
|
388
|
+
var HIDDEN_MARKER_RE = /^([a-f0-9]{32})\.json$/;
|
|
389
|
+
function compareNewestFirst(a, b) {
|
|
390
|
+
if (a.uploadedAt !== b.uploadedAt) return a.uploadedAt < b.uploadedAt ? 1 : -1;
|
|
391
|
+
if (a.hash32 === b.hash32) return 0;
|
|
392
|
+
return a.hash32 < b.hash32 ? 1 : -1;
|
|
393
|
+
}
|
|
384
394
|
var LocalAssetStore = class {
|
|
385
395
|
constructor(options) {
|
|
386
396
|
this.capabilities = { directUpload: false };
|
|
@@ -448,11 +458,12 @@ var LocalAssetStore = class {
|
|
|
448
458
|
}
|
|
449
459
|
}
|
|
450
460
|
/**
|
|
451
|
-
* Create-only write of a blob and its headers sidecar. Each is written
|
|
452
|
-
* `link()`ed into place, which fails with EEXIST rather than replacing
|
|
453
|
-
* The sidecar is linked first, so a reader never finds a blob without
|
|
454
|
-
* already there was linked by an earlier writer of this key and is kept,
|
|
455
|
-
* first writer's headers win, as on S3 (a static's Content-Disposition names
|
|
461
|
+
* Create-only write of a blob and, when `headers` is given, its headers sidecar. Each is written
|
|
462
|
+
* whole to a temp file, then `link()`ed into place, which fails with EEXIST rather than replacing
|
|
463
|
+
* (see docs/concurrency.md). The sidecar is linked first, so a reader never finds a blob without
|
|
464
|
+
* its headers. A sidecar already there was linked by an earlier writer of this key and is kept,
|
|
465
|
+
* as the blob is: the first writer's headers win, as on S3 (a static's Content-Disposition names
|
|
466
|
+
* its uploaded file).
|
|
456
467
|
*/
|
|
457
468
|
async createExclusive(key, data, headers) {
|
|
458
469
|
const filePath = this.resolveKey(key);
|
|
@@ -465,8 +476,10 @@ var LocalAssetStore = class {
|
|
|
465
476
|
const tempHeaders = import_node_path2.default.join(tempDir, (0, import_node_crypto.randomUUID)());
|
|
466
477
|
try {
|
|
467
478
|
await import_promises2.default.writeFile(tempBlob, data);
|
|
468
|
-
|
|
469
|
-
|
|
479
|
+
if (headers) {
|
|
480
|
+
await import_promises2.default.writeFile(tempHeaders, JSON.stringify(headers), "utf-8");
|
|
481
|
+
await this.linkIfAbsent(tempHeaders, this.headersSidecarPath(filePath));
|
|
482
|
+
}
|
|
470
483
|
return await this.linkIfAbsent(tempBlob, filePath) ? "created" : "already-exists";
|
|
471
484
|
} finally {
|
|
472
485
|
await Promise.all([tempBlob, tempHeaders].map((temp) => import_promises2.default.unlink(temp).catch(() => {
|
|
@@ -592,6 +605,11 @@ var LocalAssetStore = class {
|
|
|
592
605
|
throw err2;
|
|
593
606
|
}
|
|
594
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* The cursor names the last item returned, and the next page starts after it in sort order, so a
|
|
610
|
+
* page boundary holds when that item is hidden in between: its meta is never deleted, and the
|
|
611
|
+
* comparison needs only its place, not its presence in the filtered list.
|
|
612
|
+
*/
|
|
595
613
|
async listMeta(input) {
|
|
596
614
|
const limit = input?.limit ?? DEFAULT_LIST_LIMIT;
|
|
597
615
|
const dir = this.resolveKey(ASSET_PREFIXES.meta);
|
|
@@ -613,27 +631,41 @@ var LocalAssetStore = class {
|
|
|
613
631
|
}
|
|
614
632
|
}
|
|
615
633
|
}
|
|
616
|
-
all.sort(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
});
|
|
634
|
+
all.sort(compareNewestFirst);
|
|
635
|
+
const hidden = await this.hiddenHashes();
|
|
636
|
+
const listed = input?.includeHidden ? all.map((meta) => hidden.has(meta.hash32) ? { ...meta, hidden: true } : meta) : all.filter((meta) => !hidden.has(meta.hash32));
|
|
620
637
|
let startIndex = 0;
|
|
621
638
|
if (input?.cursor) {
|
|
622
639
|
const afterHash32 = Buffer.from(input.cursor, "base64").toString("utf-8");
|
|
623
|
-
const
|
|
624
|
-
|
|
640
|
+
const anchor = all.find((m) => m.hash32 === afterHash32);
|
|
641
|
+
if (anchor) {
|
|
642
|
+
const after = listed.findIndex((m) => compareNewestFirst(m, anchor) > 0);
|
|
643
|
+
startIndex = after === -1 ? listed.length : after;
|
|
644
|
+
}
|
|
625
645
|
}
|
|
626
|
-
const items =
|
|
627
|
-
const hasMore = startIndex + limit <
|
|
646
|
+
const items = listed.slice(startIndex, startIndex + limit);
|
|
647
|
+
const hasMore = startIndex + limit < listed.length;
|
|
628
648
|
const nextCursor = hasMore ? Buffer.from(items[items.length - 1].hash32, "utf-8").toString("base64") : void 0;
|
|
629
649
|
return { items, nextCursor };
|
|
630
650
|
}
|
|
631
|
-
async
|
|
632
|
-
const filePath = this.resolveKey(metaKey(hash32));
|
|
651
|
+
async hiddenHashes() {
|
|
633
652
|
try {
|
|
634
|
-
await import_promises2.default.
|
|
653
|
+
const names = await import_promises2.default.readdir(this.resolveKey(ASSET_PREFIXES.hidden));
|
|
654
|
+
return new Set(names.flatMap((name) => HIDDEN_MARKER_RE.exec(name)?.[1] ?? []));
|
|
635
655
|
} catch (err2) {
|
|
636
|
-
if (isNotFoundError(err2)) return;
|
|
656
|
+
if (isNotFoundError(err2)) return /* @__PURE__ */ new Set();
|
|
657
|
+
throw err2;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
async hideAsset(hash32, marker) {
|
|
661
|
+
return this.createExclusive(hiddenKey(hash32), new TextEncoder().encode(JSON.stringify(marker)));
|
|
662
|
+
}
|
|
663
|
+
async unhideAsset(hash32) {
|
|
664
|
+
try {
|
|
665
|
+
await import_promises2.default.unlink(this.resolveKey(hiddenKey(hash32)));
|
|
666
|
+
return true;
|
|
667
|
+
} catch (err2) {
|
|
668
|
+
if (isNotFoundError(err2)) return false;
|
|
637
669
|
throw err2;
|
|
638
670
|
}
|
|
639
671
|
}
|
|
@@ -646,6 +678,7 @@ var import_s3_presigned_post = require("@aws-sdk/s3-presigned-post");
|
|
|
646
678
|
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
647
679
|
init_sanitize_href();
|
|
648
680
|
var DEFAULT_MAX_UPLOAD_BYTES2 = 50 * 1024 * 1024;
|
|
681
|
+
var JSON_SUFFIX = ".json";
|
|
649
682
|
var PRESIGN_EXPIRY_SECONDS = 15 * 60;
|
|
650
683
|
var PRESIGNED_READ_EXPIRY_SECONDS = 5 * 60;
|
|
651
684
|
function matchesAwsError(err2, name, httpStatusCode) {
|
|
@@ -851,7 +884,10 @@ var S3AssetStore = class {
|
|
|
851
884
|
throw err2;
|
|
852
885
|
}
|
|
853
886
|
}
|
|
854
|
-
|
|
887
|
+
listPublicObjectKeys(prefix) {
|
|
888
|
+
return this.listKeys(prefix);
|
|
889
|
+
}
|
|
890
|
+
async *listKeys(prefix) {
|
|
855
891
|
const pages = (0, import_client_s3.paginateListObjectsV2)(
|
|
856
892
|
{ client: this.client },
|
|
857
893
|
{ Bucket: this.bucket, Prefix: prefix }
|
|
@@ -881,21 +917,33 @@ var S3AssetStore = class {
|
|
|
881
917
|
if (!bytes) return null;
|
|
882
918
|
return JSON.parse(Buffer.from(bytes).toString("utf-8"));
|
|
883
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* One page of meta keys, filtered by a full listing of the hidden markers: few files are hidden,
|
|
922
|
+
* and a listing needs only `s3:ListBucket`. A hidden file's meta is fetched only for
|
|
923
|
+
* `includeHidden`.
|
|
924
|
+
*/
|
|
884
925
|
async listMeta(input) {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
926
|
+
const metaPrefix2 = this.keys.metaPrefix();
|
|
927
|
+
const [listed, hidden] = await Promise.all([
|
|
928
|
+
this.client.send(
|
|
929
|
+
new import_client_s3.ListObjectsV2Command({
|
|
930
|
+
Bucket: this.bucket,
|
|
931
|
+
Prefix: metaPrefix2,
|
|
932
|
+
MaxKeys: input?.limit,
|
|
933
|
+
ContinuationToken: input?.cursor
|
|
934
|
+
})
|
|
935
|
+
),
|
|
936
|
+
this.listHiddenHashes()
|
|
937
|
+
]);
|
|
893
938
|
const objectKeys = (listed.Contents ?? []).map((obj) => obj.Key).filter((key) => Boolean(key));
|
|
894
939
|
const fetched = await Promise.all(
|
|
895
940
|
objectKeys.map(async (key) => {
|
|
941
|
+
const isHidden = hidden.has(key.slice(metaPrefix2.length, -JSON_SUFFIX.length));
|
|
942
|
+
if (isHidden && !input?.includeHidden) return null;
|
|
896
943
|
const bytes = await this.getObjectBytes(key);
|
|
897
944
|
if (!bytes) return null;
|
|
898
|
-
|
|
945
|
+
const meta = JSON.parse(Buffer.from(bytes).toString("utf-8"));
|
|
946
|
+
return isHidden ? { ...meta, hidden: true } : meta;
|
|
899
947
|
})
|
|
900
948
|
);
|
|
901
949
|
return {
|
|
@@ -903,10 +951,35 @@ var S3AssetStore = class {
|
|
|
903
951
|
nextCursor: listed.IsTruncated ? listed.NextContinuationToken : void 0
|
|
904
952
|
};
|
|
905
953
|
}
|
|
906
|
-
async
|
|
907
|
-
|
|
908
|
-
|
|
954
|
+
async listHiddenHashes() {
|
|
955
|
+
const prefix = this.keys.hiddenPrefix();
|
|
956
|
+
const hashes = /* @__PURE__ */ new Set();
|
|
957
|
+
for await (const key of this.listKeys(prefix)) {
|
|
958
|
+
if (key.endsWith(JSON_SUFFIX)) hashes.add(key.slice(prefix.length, -JSON_SUFFIX.length));
|
|
959
|
+
}
|
|
960
|
+
return hashes;
|
|
961
|
+
}
|
|
962
|
+
async hideAsset(hash32, marker) {
|
|
963
|
+
return this.putIfAbsent({
|
|
964
|
+
Key: this.keys.hiddenKey(hash32),
|
|
965
|
+
Body: JSON.stringify(marker),
|
|
966
|
+
ContentType: "application/json"
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Lists before deleting: a DELETE of an absent key writes a delete marker on a versioned bucket.
|
|
971
|
+
* The listing needs only `s3:ListBucket` covering `asset-hidden/` (a bucket-wide grant does; a
|
|
972
|
+
* policy scoping it by prefix must name this one), no object permission, so finalize can call
|
|
973
|
+
* this on every re-upload under a role that has never hidden a file.
|
|
974
|
+
*/
|
|
975
|
+
async unhideAsset(hash32) {
|
|
976
|
+
const key = this.keys.hiddenKey(hash32);
|
|
977
|
+
const listed = await this.client.send(
|
|
978
|
+
new import_client_s3.ListObjectsV2Command({ Bucket: this.bucket, Prefix: key, MaxKeys: 1 })
|
|
909
979
|
);
|
|
980
|
+
if (listed.Contents?.[0]?.Key !== key) return false;
|
|
981
|
+
await this.client.send(new import_client_s3.DeleteObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
982
|
+
return true;
|
|
910
983
|
}
|
|
911
984
|
async getObject(key) {
|
|
912
985
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canopycms-cdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-int.119",
|
|
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.
|
|
37
|
+
"canopycms": "0.2.0-int.119"
|
|
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
|
|
64
|
-
"canopycms": "0.
|
|
63
|
+
"canopycms": "0.2.0-int.119",
|
|
64
|
+
"canopycms-auth-clerk": "0.2.0-int.119"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"build": "rm -rf dist && tsc && node ../../scripts/add-js-extensions.mjs dist",
|
package/worker/dist/index.js
CHANGED
|
@@ -73162,6 +73162,7 @@ import os from "node:os";
|
|
|
73162
73162
|
import path31 from "node:path";
|
|
73163
73163
|
|
|
73164
73164
|
// ../canopycms/src/utils/debug.ts
|
|
73165
|
+
var envFlag = (name2) => typeof process !== "undefined" && process.env[name2] === "true";
|
|
73165
73166
|
var LOG_LEVELS = {
|
|
73166
73167
|
DEBUG: 0,
|
|
73167
73168
|
INFO: 1,
|
|
@@ -73174,7 +73175,7 @@ var DebugLogger = class {
|
|
|
73174
73175
|
this.options = options;
|
|
73175
73176
|
}
|
|
73176
73177
|
shouldLog(level) {
|
|
73177
|
-
const enabled = this.options.enabled ??
|
|
73178
|
+
const enabled = this.options.enabled ?? envFlag("CANOPYCMS_DEBUG");
|
|
73178
73179
|
if (!enabled) return false;
|
|
73179
73180
|
const minLevel = this.options.minLevel ?? "DEBUG";
|
|
73180
73181
|
return LOG_LEVELS[level] >= LOG_LEVELS[minLevel];
|
|
@@ -73252,7 +73253,7 @@ function createDebugLogger(options) {
|
|
|
73252
73253
|
return new DebugLogger(options);
|
|
73253
73254
|
}
|
|
73254
73255
|
var testLogger = createDebugLogger({
|
|
73255
|
-
enabled:
|
|
73256
|
+
enabled: envFlag("E2E_DEBUG"),
|
|
73256
73257
|
prefix: "E2E",
|
|
73257
73258
|
throwOnError: false
|
|
73258
73259
|
});
|
|
@@ -73630,7 +73631,7 @@ function resolveWorkerGitHubAuth(config) {
|
|
|
73630
73631
|
// key does not expire, and `@octokit/auth-app`'s own cache mints a new
|
|
73631
73632
|
// installation token when the old one expires. A rotated key or an
|
|
73632
73633
|
// early-revoked token is NOT recovered here — see
|
|
73633
|
-
//
|
|
73634
|
+
// safeinsights/canopycms#894.
|
|
73634
73635
|
refreshCredential: async () => {
|
|
73635
73636
|
}
|
|
73636
73637
|
};
|
|
@@ -78839,9 +78840,24 @@ var STALE_LEASE_REASON = "stale info";
|
|
|
78839
78840
|
function isStaleLeaseRejection(message2) {
|
|
78840
78841
|
return message2.includes(REJECTED_MARKER) && message2.includes(STALE_LEASE_REASON);
|
|
78841
78842
|
}
|
|
78842
|
-
var
|
|
78843
|
+
var WORKFLOW_REFUSAL_LEADS = ["refusing to allow a ", "refusing to allow an "];
|
|
78844
|
+
var WORKFLOW_REFUSAL_TAIL = " to create or update workflow ";
|
|
78843
78845
|
function workflowPushRefusalFile(message2) {
|
|
78844
|
-
|
|
78846
|
+
for (const line of message2.split("\n")) {
|
|
78847
|
+
const spans = line.split("`");
|
|
78848
|
+
for (let i10 = 0; i10 + 2 < spans.length; i10++) {
|
|
78849
|
+
const span = spans[i10];
|
|
78850
|
+
const file = spans[i10 + 1];
|
|
78851
|
+
if (file === "" || !span.endsWith(WORKFLOW_REFUSAL_TAIL)) continue;
|
|
78852
|
+
const head = span.slice(0, -WORKFLOW_REFUSAL_TAIL.length);
|
|
78853
|
+
const named = WORKFLOW_REFUSAL_LEADS.some((lead) => {
|
|
78854
|
+
const at = head.indexOf(lead);
|
|
78855
|
+
return at !== -1 && at + lead.length < head.length;
|
|
78856
|
+
});
|
|
78857
|
+
if (named) return file;
|
|
78858
|
+
}
|
|
78859
|
+
}
|
|
78860
|
+
return null;
|
|
78845
78861
|
}
|
|
78846
78862
|
async function resolveGitDir(repoPath) {
|
|
78847
78863
|
const dotGit = path5.join(repoPath, ".git");
|
|
@@ -80571,7 +80587,7 @@ var GitHubMirror = class {
|
|
|
80571
80587
|
* Clear what a killed gateway left, before any git runs: finish or undo an interrupted rebuild,
|
|
80572
80588
|
* then every lock and temporary in the mirror. Nothing in this process writes it yet:
|
|
80573
80589
|
* maintenance starts only after a session. A git a stopped dev worker left running is not
|
|
80574
|
-
* covered (
|
|
80590
|
+
* covered (safeinsights/canopycms#907).
|
|
80575
80591
|
*/
|
|
80576
80592
|
async sweepAtStart() {
|
|
80577
80593
|
await fs9.mkdir(this.stateDirectory, { recursive: true, mode: 448 });
|
|
@@ -81996,7 +82012,7 @@ var LocalGitHubGateway = class {
|
|
|
81996
82012
|
* branch first. The mirror kills its git when `signal` aborts, and GitHub moves the ref only
|
|
81997
82013
|
* after receiving the whole pack, so a killed push changes nothing or is found already done by
|
|
81998
82014
|
* the re-run, unless git's transport child outlives it
|
|
81999
|
-
* (
|
|
82015
|
+
* (safeinsights/canopycms#907).
|
|
82000
82016
|
*/
|
|
82001
82017
|
async pushInSession(mirror, credential, request, received, signal) {
|
|
82002
82018
|
const { branch, sha } = request;
|
|
@@ -82475,7 +82491,7 @@ init_error();
|
|
|
82475
82491
|
init_worker_status();
|
|
82476
82492
|
|
|
82477
82493
|
// ../canopycms/src/version.ts
|
|
82478
|
-
var CANOPYCMS_VERSION = "0.
|
|
82494
|
+
var CANOPYCMS_VERSION = "0.2.0-int.119";
|
|
82479
82495
|
|
|
82480
82496
|
// ../canopycms/src/worker/schema-gate.ts
|
|
82481
82497
|
import fs14 from "node:fs/promises";
|
|
@@ -83684,6 +83700,7 @@ var SHAPE_REFUSALS = /* @__PURE__ */ new Set([400, 411, 413, 415, 431]);
|
|
|
83684
83700
|
function refusedRequestError(message2, status) {
|
|
83685
83701
|
return status !== void 0 && SHAPE_REFUSALS.has(status) ? new GatewayRequestRefusedError(message2, status) : new GitHubGatewayProtocolError(message2);
|
|
83686
83702
|
}
|
|
83703
|
+
var NOT_AN_ERROR_MESSAGE = "The GitHub gateway failed with a value that is not an Error";
|
|
83687
83704
|
function encodeError(err) {
|
|
83688
83705
|
const text = (value) => redactEgress(value).slice(0, MAX_MESSAGE_LENGTH);
|
|
83689
83706
|
if (err instanceof GatewayRefusalError) {
|
|
@@ -83703,7 +83720,8 @@ function encodeError(err) {
|
|
|
83703
83720
|
return { kind: "transient", code: err.code, message: text(err.message) };
|
|
83704
83721
|
}
|
|
83705
83722
|
if (!(err instanceof Error)) {
|
|
83706
|
-
|
|
83723
|
+
gatewayLogWarn("Answered a thrown value that is not an Error:", text(String(err)));
|
|
83724
|
+
return { kind: "error", name: "Error", message: NOT_AN_ERROR_MESSAGE };
|
|
83707
83725
|
}
|
|
83708
83726
|
const status = err.status;
|
|
83709
83727
|
if (typeof status === "number" && Number.isInteger(status)) {
|
|
@@ -87370,7 +87388,7 @@ var CmsWorker = class {
|
|
|
87370
87388
|
* and GitHub calls are killed and the task is released to pending with no
|
|
87371
87389
|
* retry spent; a sync's bundle, unbundle, ref update and settings push
|
|
87372
87390
|
* are killed. The gateway's GitHub fetches and mirror maintenance run on
|
|
87373
|
-
* (
|
|
87391
|
+
* (safeinsights/canopycms#907). A branch rebase
|
|
87374
87392
|
* is never aborted, because a rebase killed mid-branch is recovered
|
|
87375
87393
|
* lossily; anything still unsettled after a short grace is abandoned to
|
|
87376
87394
|
* the process exit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
8a7b7063f59c69ec21cd138b5543e669a5905966b38b21bcb9ed7a497ad91622 index.js
|