@go-to-k/cdkd 0.23.1 → 0.23.2

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.
Binary file
package/dist/index.js CHANGED
@@ -6691,13 +6691,11 @@ var CustomResourceProvider = class _CustomResourceProvider {
6691
6691
  );
6692
6692
  }
6693
6693
  try {
6694
- const requestId = `cdkd-${Date.now()}-${Math.random().toString(36).substring(7)}`;
6695
- const responseKey = this.getResponseKey(requestId);
6696
- const responseURL = await this.generateResponseURL(responseKey);
6694
+ const invocation = await this.prepareInvocation();
6697
6695
  const request = {
6698
6696
  RequestType: "Create",
6699
- RequestId: requestId,
6700
- ResponseURL: responseURL,
6697
+ RequestId: invocation.requestId,
6698
+ ResponseURL: invocation.responseURL,
6701
6699
  ResourceType: resourceType,
6702
6700
  LogicalResourceId: logicalId,
6703
6701
  StackId: `arn:aws:cloudformation:us-east-1:000000000000:stack/cdkd-${logicalId}/cdkd`,
@@ -6707,7 +6705,7 @@ var CustomResourceProvider = class _CustomResourceProvider {
6707
6705
  const cfnResponse = await this.sendRequest(
6708
6706
  serviceToken,
6709
6707
  request,
6710
- responseKey,
6708
+ invocation.responseKey,
6711
6709
  logicalId,
6712
6710
  "Create"
6713
6711
  );
@@ -6746,13 +6744,11 @@ var CustomResourceProvider = class _CustomResourceProvider {
6746
6744
  );
6747
6745
  }
6748
6746
  try {
6749
- const requestId = `cdkd-${Date.now()}-${Math.random().toString(36).substring(7)}`;
6750
- const responseKey = this.getResponseKey(requestId);
6751
- const responseURL = await this.generateResponseURL(responseKey);
6747
+ const invocation = await this.prepareInvocation();
6752
6748
  const request = {
6753
6749
  RequestType: "Update",
6754
- RequestId: requestId,
6755
- ResponseURL: responseURL,
6750
+ RequestId: invocation.requestId,
6751
+ ResponseURL: invocation.responseURL,
6756
6752
  ResourceType: resourceType,
6757
6753
  LogicalResourceId: logicalId,
6758
6754
  PhysicalResourceId: physicalId,
@@ -6764,7 +6760,7 @@ var CustomResourceProvider = class _CustomResourceProvider {
6764
6760
  const cfnResponse = await this.sendRequest(
6765
6761
  serviceToken,
6766
6762
  request,
6767
- responseKey,
6763
+ invocation.responseKey,
6768
6764
  logicalId,
6769
6765
  "Update"
6770
6766
  );
@@ -6808,13 +6804,11 @@ var CustomResourceProvider = class _CustomResourceProvider {
6808
6804
  return;
6809
6805
  }
6810
6806
  try {
6811
- const requestId = `cdkd-${Date.now()}-${Math.random().toString(36).substring(7)}`;
6812
- const responseKey = this.getResponseKey(requestId);
6813
- const responseURL = await this.generateResponseURL(responseKey);
6807
+ const invocation = await this.prepareInvocation();
6814
6808
  const request = {
6815
6809
  RequestType: "Delete",
6816
- RequestId: requestId,
6817
- ResponseURL: responseURL,
6810
+ RequestId: invocation.requestId,
6811
+ ResponseURL: invocation.responseURL,
6818
6812
  ResourceType: resourceType,
6819
6813
  LogicalResourceId: logicalId,
6820
6814
  PhysicalResourceId: physicalId,
@@ -6825,7 +6819,7 @@ var CustomResourceProvider = class _CustomResourceProvider {
6825
6819
  const cfnResponse = await this.sendRequest(
6826
6820
  serviceToken,
6827
6821
  request,
6828
- responseKey,
6822
+ invocation.responseKey,
6829
6823
  logicalId,
6830
6824
  "Delete"
6831
6825
  );
@@ -6944,6 +6938,28 @@ var CustomResourceProvider = class _CustomResourceProvider {
6944
6938
  const timeoutMs = isAsyncPattern ? this.asyncResponseTimeoutMs : this.SYNC_RESPONSE_TIMEOUT_MS;
6945
6939
  return await this.pollS3Response(responseKey, logicalId, operation, timeoutMs, isAsyncPattern);
6946
6940
  }
6941
+ /**
6942
+ * Prepare a single Custom Resource invocation: generate the request id,
6943
+ * derive the S3 response key from it, sign the pre-signed PUT URL for that
6944
+ * key, and return all three together.
6945
+ *
6946
+ * **The request id, response key, and response URL must all be derived from
6947
+ * the SAME generation step.** Previously these were generated by separate
6948
+ * calls inside `create` / `update` / `delete`, which made it possible for a
6949
+ * future refactor (e.g. wrapping URL signing in a retry that re-rolls the
6950
+ * id) to silently break the invariant — the Lambda would write to one S3
6951
+ * key while cdkd polled a different one, hanging the deploy until the
6952
+ * polling timeout (up to 1 hour). See issue #90.
6953
+ *
6954
+ * Centralising this in one helper makes that invariant impossible to
6955
+ * violate at the call sites.
6956
+ */
6957
+ async prepareInvocation() {
6958
+ const requestId = `cdkd-${Date.now()}-${Math.random().toString(36).substring(7)}`;
6959
+ const responseKey = this.getResponseKey(requestId);
6960
+ const responseURL = await this.generateResponseURL(responseKey);
6961
+ return { requestId, responseKey, responseURL };
6962
+ }
6947
6963
  /**
6948
6964
  * Generate a pre-signed S3 PUT URL for Lambda to send its response
6949
6965
  */