@resistdesign/voltra 3.0.0-alpha.40 → 3.0.0-alpha.41

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.
@@ -63,7 +63,7 @@ export type AddGatewayConfig = {
63
63
  */
64
64
  authorizer?: AddGatewayAuthorizerConfig | boolean;
65
65
  /**
66
- * Suffix to ensure unique deployment ids.
66
+ * Optional manual suffix appended after the deterministic deployment hash.
67
67
  */
68
68
  deploymentSuffix?: string;
69
69
  };
@@ -950,6 +950,31 @@ var addSecureFileStorage = createResourcePack(
950
950
  );
951
951
 
952
952
  // src/iac/packs/gateway.ts
953
+ var canonicalizeHashableValue = (value) => {
954
+ if (Array.isArray(value)) {
955
+ return value.map((item) => canonicalizeHashableValue(item));
956
+ }
957
+ if (value && typeof value === "object") {
958
+ const output = {};
959
+ Object.keys(value).sort().forEach((key) => {
960
+ output[key] = canonicalizeHashableValue(
961
+ value[key]
962
+ );
963
+ });
964
+ return output;
965
+ }
966
+ return value;
967
+ };
968
+ var getDeterministicHash = (value) => {
969
+ const canonical = JSON.stringify(canonicalizeHashableValue(value));
970
+ let hash = 2166136261;
971
+ for (let i = 0; i < canonical.length; i += 1) {
972
+ hash ^= canonical.charCodeAt(i);
973
+ hash = Math.imul(hash, 16777619);
974
+ hash >>>= 0;
975
+ }
976
+ return hash.toString(16).toUpperCase().padStart(8, "0");
977
+ };
953
978
  var DEFAULT_AUTH_TYPE = "COGNITO_USER_POOLS";
954
979
  var addGateway = createResourcePack(
955
980
  ({
@@ -974,6 +999,27 @@ var addGateway = createResourcePack(
974
999
  providerARNs,
975
1000
  identitySource = "method.request.header.Authorization"
976
1001
  } = !!authorizer && typeof authorizer === "object" ? authorizer : {};
1002
+ const cloudFunctionIntegration = {
1003
+ Type: "AWS_PROXY",
1004
+ IntegrationHttpMethod: "POST",
1005
+ Uri: cloudFunctionUri
1006
+ };
1007
+ const gatewayResponseParameters = {
1008
+ "gatewayresponse.header.Access-Control-Allow-Origin": "method.request.header.origin",
1009
+ "gatewayresponse.header.Access-Control-Allow-Credentials": "'true'",
1010
+ "gatewayresponse.header.Access-Control-Allow-Headers": "'*'"
1011
+ };
1012
+ const cloudFunctionPermissionSourceArn = {
1013
+ "Fn::Sub": [
1014
+ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
1015
+ {
1016
+ __Stage__: stageName,
1017
+ __ApiId__: {
1018
+ Ref: id
1019
+ }
1020
+ }
1021
+ ]
1022
+ };
977
1023
  const authorizerId = `${id}CustomAuthorizer`;
978
1024
  const authProps = !!authorizer ? {
979
1025
  AuthorizationScopes: authScopes,
@@ -984,7 +1030,33 @@ var addGateway = createResourcePack(
984
1030
  } : {
985
1031
  AuthorizationType: "NONE"
986
1032
  };
987
- const fullDeploymentId = `${id}GatewayRESTAPIDeployment${deploymentSuffix}`;
1033
+ const gatewayDeploymentFingerprint = {
1034
+ restApiEndpointTypes: ["EDGE"],
1035
+ proxyPathPart: "{proxy+}",
1036
+ anyMethod: {
1037
+ ...authProps,
1038
+ HttpMethod: "ANY",
1039
+ Integration: cloudFunctionIntegration
1040
+ },
1041
+ optionsMethod: {
1042
+ AuthorizationType: "NONE",
1043
+ HttpMethod: "OPTIONS",
1044
+ Integration: cloudFunctionIntegration
1045
+ },
1046
+ gatewayResponseDefault4XX: {
1047
+ ResponseParameters: gatewayResponseParameters,
1048
+ ResponseType: "DEFAULT_4XX"
1049
+ },
1050
+ stageName,
1051
+ cloudFunctionPermissionSourceArn,
1052
+ authorizer: !!authorizer ? {
1053
+ IdentitySource: identitySource,
1054
+ ProviderARNs: providerARNs,
1055
+ Type: "COGNITO_USER_POOLS"
1056
+ } : null
1057
+ };
1058
+ const deploymentHash = getDeterministicHash(gatewayDeploymentFingerprint);
1059
+ const fullDeploymentId = `${id}GatewayRESTAPIDeployment${deploymentHash}${deploymentSuffix}`;
988
1060
  return new SimpleCFT().patch({
989
1061
  Resources: {
990
1062
  // REST API
@@ -1025,9 +1097,7 @@ var addGateway = createResourcePack(
1025
1097
  Ref: id
1026
1098
  },
1027
1099
  Integration: {
1028
- Type: "AWS_PROXY",
1029
- IntegrationHttpMethod: "POST",
1030
- Uri: cloudFunctionUri
1100
+ ...cloudFunctionIntegration
1031
1101
  }
1032
1102
  }
1033
1103
  },
@@ -1044,9 +1114,7 @@ var addGateway = createResourcePack(
1044
1114
  Ref: id
1045
1115
  },
1046
1116
  Integration: {
1047
- Type: "AWS_PROXY",
1048
- IntegrationHttpMethod: "POST",
1049
- Uri: cloudFunctionUri
1117
+ ...cloudFunctionIntegration
1050
1118
  }
1051
1119
  }
1052
1120
  }
@@ -1067,9 +1135,7 @@ var addGateway = createResourcePack(
1067
1135
  Ref: id
1068
1136
  },
1069
1137
  Integration: {
1070
- Type: "AWS_PROXY",
1071
- IntegrationHttpMethod: "POST",
1072
- Uri: cloudFunctionUri
1138
+ ...cloudFunctionIntegration
1073
1139
  }
1074
1140
  }
1075
1141
  },
@@ -1086,21 +1152,15 @@ var addGateway = createResourcePack(
1086
1152
  Ref: id
1087
1153
  },
1088
1154
  Integration: {
1089
- Type: "AWS_PROXY",
1090
- IntegrationHttpMethod: "POST",
1091
- Uri: cloudFunctionUri
1155
+ ...cloudFunctionIntegration
1092
1156
  }
1093
1157
  }
1094
1158
  },
1095
1159
  [`${id}GatewayResponseDefault4XX`]: {
1096
1160
  Type: "AWS::ApiGateway::GatewayResponse",
1097
1161
  Properties: {
1098
- ResponseParameters: {
1099
- // Not authorized, so just allow the current origin by mapping it into the header.
1100
- "gatewayresponse.header.Access-Control-Allow-Origin": "method.request.header.origin",
1101
- "gatewayresponse.header.Access-Control-Allow-Credentials": "'true'",
1102
- "gatewayresponse.header.Access-Control-Allow-Headers": "'*'"
1103
- },
1162
+ // Not authorized, so just allow the current origin by mapping it into the header.
1163
+ ResponseParameters: gatewayResponseParameters,
1104
1164
  ResponseType: "DEFAULT_4XX",
1105
1165
  RestApiId: {
1106
1166
  Ref: id
@@ -1256,15 +1316,7 @@ var addGateway = createResourcePack(
1256
1316
  "Fn::GetAtt": [cloudFunctionId, "Arn"]
1257
1317
  },
1258
1318
  SourceArn: {
1259
- "Fn::Sub": [
1260
- "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
1261
- {
1262
- __Stage__: stageName,
1263
- __ApiId__: {
1264
- Ref: id
1265
- }
1266
- }
1267
- ]
1319
+ ...cloudFunctionPermissionSourceArn
1268
1320
  }
1269
1321
  }
1270
1322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resistdesign/voltra",
3
- "version": "3.0.0-alpha.40",
3
+ "version": "3.0.0-alpha.41",
4
4
  "description": "With our powers combined!",
5
5
  "homepage": "https://voltra.app",
6
6
  "repository": "git@github.com:resistdesign/voltra.git",