@resistdesign/voltra 3.0.0-alpha.3 → 3.0.0-alpha.4

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.
Files changed (225) hide show
  1. package/README.md +75 -0
  2. package/SearchTypes-DjN6YQzE.d.ts +577 -0
  3. package/Types-C7XjUjoF.d.ts +240 -0
  4. package/Validation-CFP59oIP.d.ts +226 -0
  5. package/api/index.d.ts +6 -0
  6. package/api/index.js +7968 -0
  7. package/app/index.d.ts +5 -0
  8. package/app/index.js +810 -0
  9. package/common/Testing/CLI.js +432 -0
  10. package/common/index.d.ts +4 -0
  11. package/common/index.js +1760 -0
  12. package/iac/index.d.ts +2 -0
  13. package/iac/index.js +1661 -0
  14. package/iac/packs/index.d.ts +1 -0
  15. package/iac/packs/index.js +1620 -0
  16. package/index-BkFZlfit.d.ts +112 -0
  17. package/index-C3-iD9Mh.d.ts +690 -0
  18. package/index-DZ2BB4iX.d.ts +5357 -0
  19. package/{src/iac/types/IaCTypes.d.ts → index-DcvJOZ_c.d.ts} +1018 -23
  20. package/index-IokxSNxm.d.ts +745 -0
  21. package/index.d.ts +13 -0
  22. package/index.js +10973 -0
  23. package/package.json +40 -41
  24. package/src/api/DataAccessControl.d.ts +0 -85
  25. package/src/api/DataAccessControl.js +0 -159
  26. package/src/api/ORM/DACUtils.d.ts +0 -60
  27. package/src/api/ORM/DACUtils.js +0 -197
  28. package/src/api/ORM/ListItemUtils.d.ts +0 -7
  29. package/src/api/ORM/ListItemUtils.js +0 -22
  30. package/src/api/ORM/ORMRouteMap.d.ts +0 -19
  31. package/src/api/ORM/ORMRouteMap.js +0 -82
  32. package/src/api/ORM/TypeInfoORMService.d.ts +0 -103
  33. package/src/api/ORM/TypeInfoORMService.js +0 -581
  34. package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.d.ts +0 -63
  35. package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.js +0 -2
  36. package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.d.ts +0 -36
  37. package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.js +0 -282
  38. package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.d.ts +0 -90
  39. package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.js +0 -2
  40. package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.d.ts +0 -45
  41. package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.js +0 -127
  42. package/src/api/ORM/drivers/S3FileItemDBDriver.d.ts +0 -44
  43. package/src/api/ORM/drivers/S3FileItemDBDriver.js +0 -182
  44. package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.d.ts +0 -12
  45. package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.js +0 -20
  46. package/src/api/ORM/drivers/common/Types.d.ts +0 -77
  47. package/src/api/ORM/drivers/common/Types.js +0 -14
  48. package/src/api/ORM/drivers/common/index.d.ts +0 -2
  49. package/src/api/ORM/drivers/common/index.js +0 -18
  50. package/src/api/ORM/drivers/index.d.ts +0 -3
  51. package/src/api/ORM/drivers/index.js +0 -19
  52. package/src/api/ORM/index.d.ts +0 -4
  53. package/src/api/ORM/index.js +0 -43
  54. package/src/api/Router/AWS.d.ts +0 -26
  55. package/src/api/Router/AWS.js +0 -76
  56. package/src/api/Router/Auth.d.ts +0 -2
  57. package/src/api/Router/Auth.js +0 -9
  58. package/src/api/Router/CORS.d.ts +0 -6
  59. package/src/api/Router/CORS.js +0 -27
  60. package/src/api/Router/Types.d.ts +0 -71
  61. package/src/api/Router/Types.js +0 -2
  62. package/src/api/Router/index.d.ts +0 -18
  63. package/src/api/Router/index.js +0 -145
  64. package/src/api/index.d.ts +0 -3
  65. package/src/api/index.js +0 -39
  66. package/src/app/index.d.ts +0 -1
  67. package/src/app/index.js +0 -37
  68. package/src/app/utils/ApplicationState.d.ts +0 -52
  69. package/src/app/utils/ApplicationState.js +0 -86
  70. package/src/app/utils/ApplicationStateLoader.d.ts +0 -46
  71. package/src/app/utils/ApplicationStateLoader.js +0 -57
  72. package/src/app/utils/Controller.d.ts +0 -4
  73. package/src/app/utils/Controller.js +0 -47
  74. package/src/app/utils/Debug.d.ts +0 -4
  75. package/src/app/utils/Debug.js +0 -30
  76. package/src/app/utils/EasyLayout.d.ts +0 -49
  77. package/src/app/utils/EasyLayout.js +0 -122
  78. package/src/app/utils/Route.d.ts +0 -28
  79. package/src/app/utils/Route.js +0 -102
  80. package/src/app/utils/Service.d.ts +0 -12
  81. package/src/app/utils/Service.js +0 -34
  82. package/src/app/utils/TypeInfoORMAPIUtils.d.ts +0 -20
  83. package/src/app/utils/TypeInfoORMAPIUtils.js +0 -62
  84. package/src/app/utils/TypeInfoORMClient.d.ts +0 -24
  85. package/src/app/utils/TypeInfoORMClient.js +0 -69
  86. package/src/app/utils/index.d.ts +0 -8
  87. package/src/app/utils/index.js +0 -24
  88. package/src/common/CommandLine/collectRequiredEnvironmentVariables.d.ts +0 -1
  89. package/src/common/CommandLine/collectRequiredEnvironmentVariables.js +0 -16
  90. package/src/common/HelperTypes.d.ts +0 -3
  91. package/src/common/HelperTypes.js +0 -2
  92. package/src/common/IdGeneration/getSimpleId.d.ts +0 -4
  93. package/src/common/IdGeneration/getSimpleId.js +0 -16
  94. package/src/common/IdGeneration/index.d.ts +0 -1
  95. package/src/common/IdGeneration/index.js +0 -17
  96. package/src/common/ItemRelationshipInfoTypes.d.ts +0 -46
  97. package/src/common/ItemRelationshipInfoTypes.js +0 -20
  98. package/src/common/ItemRelationships/ItemRelationshipValidation.d.ts +0 -10
  99. package/src/common/ItemRelationships/ItemRelationshipValidation.js +0 -43
  100. package/src/common/ItemRelationships/index.d.ts +0 -1
  101. package/src/common/ItemRelationships/index.js +0 -17
  102. package/src/common/Logging/Utils.d.ts +0 -10
  103. package/src/common/Logging/Utils.js +0 -33
  104. package/src/common/Logging/index.d.ts +0 -1
  105. package/src/common/Logging/index.js +0 -17
  106. package/src/common/Routing.d.ts +0 -25
  107. package/src/common/Routing.js +0 -102
  108. package/src/common/SearchTypes.d.ts +0 -98
  109. package/src/common/SearchTypes.js +0 -39
  110. package/src/common/SearchUtils.d.ts +0 -22
  111. package/src/common/SearchUtils.js +0 -134
  112. package/src/common/SearchValidation.d.ts +0 -17
  113. package/src/common/SearchValidation.js +0 -90
  114. package/src/common/Storyboarding/Types.d.ts +0 -25
  115. package/src/common/Storyboarding/Types.js +0 -2
  116. package/src/common/StringTransformers.d.ts +0 -17
  117. package/src/common/StringTransformers.js +0 -36
  118. package/src/common/Testing/CLI.d.ts +0 -2
  119. package/src/common/Testing/CLI.js +0 -56
  120. package/src/common/Testing/Types.d.ts +0 -117
  121. package/src/common/Testing/Types.js +0 -19
  122. package/src/common/Testing/Utils.d.ts +0 -48
  123. package/src/common/Testing/Utils.js +0 -334
  124. package/src/common/Testing/index.d.ts +0 -2
  125. package/src/common/Testing/index.js +0 -18
  126. package/src/common/TypeInfoDataItemUtils.d.ts +0 -10
  127. package/src/common/TypeInfoDataItemUtils.js +0 -55
  128. package/src/common/TypeInfoORM/Types.d.ts +0 -76
  129. package/src/common/TypeInfoORM/Types.js +0 -55
  130. package/src/common/TypeInfoORM/index.d.ts +0 -1
  131. package/src/common/TypeInfoORM/index.js +0 -17
  132. package/src/common/TypeParsing/Constants.d.ts +0 -1
  133. package/src/common/TypeParsing/Constants.js +0 -4
  134. package/src/common/TypeParsing/ParsingUtils/Constants.d.ts +0 -5
  135. package/src/common/TypeParsing/ParsingUtils/Constants.js +0 -8
  136. package/src/common/TypeParsing/ParsingUtils/checkType.d.ts +0 -8
  137. package/src/common/TypeParsing/ParsingUtils/checkType.js +0 -46
  138. package/src/common/TypeParsing/ParsingUtils/checkUnionType.d.ts +0 -6
  139. package/src/common/TypeParsing/ParsingUtils/checkUnionType.js +0 -15
  140. package/src/common/TypeParsing/ParsingUtils/extractCommentTags.d.ts +0 -2
  141. package/src/common/TypeParsing/ParsingUtils/extractCommentTags.js +0 -105
  142. package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.d.ts +0 -6
  143. package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.js +0 -42
  144. package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.d.ts +0 -8
  145. package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.js +0 -14
  146. package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.d.ts +0 -5
  147. package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.js +0 -27
  148. package/src/common/TypeParsing/ParsingUtils/getTypeInfo.d.ts +0 -3
  149. package/src/common/TypeParsing/ParsingUtils/getTypeInfo.js +0 -27
  150. package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.d.ts +0 -3
  151. package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.js +0 -44
  152. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.d.ts +0 -4
  153. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.js +0 -28
  154. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.d.ts +0 -4
  155. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.js +0 -105
  156. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.d.ts +0 -4
  157. package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.js +0 -20
  158. package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.d.ts +0 -3
  159. package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.js +0 -17
  160. package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.d.ts +0 -4
  161. package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.js +0 -49
  162. package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.d.ts +0 -2
  163. package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.js +0 -24
  164. package/src/common/TypeParsing/TypeInfo.d.ts +0 -142
  165. package/src/common/TypeParsing/TypeInfo.js +0 -13
  166. package/src/common/TypeParsing/TypeMapping.d.ts +0 -9
  167. package/src/common/TypeParsing/TypeMapping.js +0 -32
  168. package/src/common/TypeParsing/TypeParsing.d.ts +0 -5
  169. package/src/common/TypeParsing/TypeParsing.js +0 -39
  170. package/src/common/TypeParsing/Utils.d.ts +0 -21
  171. package/src/common/TypeParsing/Utils.js +0 -94
  172. package/src/common/TypeParsing/Validation.d.ts +0 -92
  173. package/src/common/TypeParsing/Validation.js +0 -340
  174. package/src/common/TypeParsing/index.d.ts +0 -5
  175. package/src/common/TypeParsing/index.js +0 -44
  176. package/src/common/index.d.ts +0 -11
  177. package/src/common/index.js +0 -47
  178. package/src/iac/SimpleCFT.d.ts +0 -48
  179. package/src/iac/SimpleCFT.js +0 -82
  180. package/src/iac/index.d.ts +0 -9
  181. package/src/iac/index.js +0 -48
  182. package/src/iac/packs/auth/user-management.d.ts +0 -14
  183. package/src/iac/packs/auth/user-management.js +0 -302
  184. package/src/iac/packs/auth.d.ts +0 -19
  185. package/src/iac/packs/auth.js +0 -47
  186. package/src/iac/packs/build/utils.d.ts +0 -100
  187. package/src/iac/packs/build/utils.js +0 -23
  188. package/src/iac/packs/build.d.ts +0 -29
  189. package/src/iac/packs/build.js +0 -217
  190. package/src/iac/packs/cdn.d.ts +0 -12
  191. package/src/iac/packs/cdn.js +0 -126
  192. package/src/iac/packs/cloud-function.d.ts +0 -17
  193. package/src/iac/packs/cloud-function.js +0 -69
  194. package/src/iac/packs/database.d.ts +0 -29
  195. package/src/iac/packs/database.js +0 -27
  196. package/src/iac/packs/dns.d.ts +0 -13
  197. package/src/iac/packs/dns.js +0 -26
  198. package/src/iac/packs/file-storage.d.ts +0 -14
  199. package/src/iac/packs/file-storage.js +0 -71
  200. package/src/iac/packs/gateway.d.ts +0 -27
  201. package/src/iac/packs/gateway.js +0 -342
  202. package/src/iac/packs/index.d.ts +0 -11
  203. package/src/iac/packs/index.js +0 -27
  204. package/src/iac/packs/repo.d.ts +0 -10
  205. package/src/iac/packs/repo.js +0 -34
  206. package/src/iac/packs/ssl-certificate.d.ts +0 -10
  207. package/src/iac/packs/ssl-certificate.js +0 -36
  208. package/src/iac/types/CloudFormationResourceSpecification.d.ts +0 -2
  209. package/src/iac/types/Constants.d.ts +0 -9
  210. package/src/iac/types/Constants.js +0 -20
  211. package/src/iac/types/IaCTypes.js +0 -14
  212. package/src/iac/types/Renderers.d.ts +0 -12
  213. package/src/iac/types/Renderers.js +0 -112
  214. package/src/iac/types/Types.d.ts +0 -37
  215. package/src/iac/types/Types.js +0 -2
  216. package/src/iac/types/Utils.d.ts +0 -2
  217. package/src/iac/types/Utils.js +0 -60
  218. package/src/iac/types/generate.d.ts +0 -1
  219. package/src/iac/types/generate.js +0 -31
  220. package/src/iac/utils/index.d.ts +0 -36
  221. package/src/iac/utils/index.js +0 -105
  222. package/src/iac/utils/patch-utils.d.ts +0 -15
  223. package/src/iac/utils/patch-utils.js +0 -62
  224. package/src/index.d.ts +0 -178
  225. package/src/index.js +0 -214
@@ -0,0 +1,1620 @@
1
+ import YAML from 'yaml';
2
+
3
+ // src/iac/utils/patch-utils.ts
4
+ var DEFAULT_MERGE_STRATEGY = "transpose";
5
+ var getValuePathString = (valuePathArray = []) => valuePathArray.map((p) => encodeURIComponent(p)).join("/");
6
+ var isConstructedFrom = (value, constructorReference) => value !== null && typeof value === "object" && "constructor" in value && value.constructor === constructorReference;
7
+ var mergeValues = (valuePathArray = [], existingValue, newValue, mergeStrategyMap = {}) => {
8
+ const valuePathString = getValuePathString(valuePathArray);
9
+ const arrayIndexWildcardValuePathString = getValuePathString(
10
+ valuePathArray.map((p) => typeof p === "number" ? "#" : p)
11
+ );
12
+ const {
13
+ [valuePathString]: {
14
+ strategy: specificKeyMergeStrategy = DEFAULT_MERGE_STRATEGY,
15
+ data: specificKeyMergeStrategyData = void 0
16
+ } = {},
17
+ [arrayIndexWildcardValuePathString]: {
18
+ strategy: arrayIndexWildcardMergeStrategy = DEFAULT_MERGE_STRATEGY,
19
+ data: arrayIndexWildcardMergeStrategyData = void 0
20
+ } = {}
21
+ } = mergeStrategyMap;
22
+ const mergeStrategy = valuePathString in mergeStrategyMap ? specificKeyMergeStrategy : arrayIndexWildcardMergeStrategy;
23
+ const mergeStrategyData = valuePathString in mergeStrategyMap ? specificKeyMergeStrategyData : arrayIndexWildcardMergeStrategyData;
24
+ let mergedValue = typeof newValue !== "undefined" ? newValue : existingValue;
25
+ if (mergeStrategy !== "replace") {
26
+ if (isConstructedFrom(existingValue, Array) && isConstructedFrom(newValue, Array)) {
27
+ if (mergeStrategy === "accumulate") {
28
+ mergedValue = [...existingValue, ...newValue];
29
+ } else if (mergeStrategy === "accumulate-unique") {
30
+ mergedValue = [
31
+ ...existingValue,
32
+ ...newValue.filter(
33
+ (item) => existingValue.indexOf(item) === -1
34
+ )
35
+ ];
36
+ } else if (mergeStrategy === "accumulate-unique-by") {
37
+ const existingItemMap = {};
38
+ const newItemMap = {};
39
+ for (let i = 0; i < existingValue.length; i++) {
40
+ const existingItem = existingValue[i];
41
+ if (existingItem && typeof existingItem === "object") {
42
+ const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(existingItem) : existingItem[mergeStrategyData];
43
+ existingItemMap[identifier] = existingItem;
44
+ }
45
+ }
46
+ for (let j = 0; j < newValue.length; j++) {
47
+ const newItem = newValue[j];
48
+ if (newItem && typeof newItem === "object") {
49
+ const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(newItem) : newItem[mergeStrategyData];
50
+ newItemMap[identifier] = newItem;
51
+ }
52
+ }
53
+ mergedValue = Object.keys({
54
+ ...existingItemMap,
55
+ ...newItemMap
56
+ }).map(
57
+ (id, index) => mergeValues(
58
+ [...valuePathArray, index],
59
+ existingItemMap[id],
60
+ newItemMap[id],
61
+ mergeStrategyMap
62
+ )
63
+ );
64
+ } else if (mergeStrategy === "transpose") {
65
+ const fullLength = Math.max(existingValue.length, newValue.length);
66
+ mergedValue = [...new Array(fullLength)].map(
67
+ (_empty, index) => mergeValues(
68
+ [...valuePathArray, index],
69
+ existingValue[index],
70
+ newValue[index],
71
+ mergeStrategyMap
72
+ )
73
+ );
74
+ }
75
+ } else if (isConstructedFrom(existingValue, Object) && isConstructedFrom(newValue, Object)) {
76
+ mergedValue = Object.keys({ ...existingValue, ...newValue }).reduce(
77
+ (acc, k) => ({
78
+ ...acc,
79
+ [k]: mergeValues(
80
+ [...valuePathArray, k],
81
+ existingValue[k],
82
+ newValue[k],
83
+ mergeStrategyMap
84
+ )
85
+ }),
86
+ {}
87
+ );
88
+ }
89
+ }
90
+ return mergedValue;
91
+ };
92
+
93
+ // src/iac/utils/index.ts
94
+ var addParameter = (parameterInfo, template) => {
95
+ const { ParameterId, Parameter, Label, Group } = parameterInfo;
96
+ const {
97
+ Parameters,
98
+ Metadata: {
99
+ "AWS::CloudFormation::Interface": {
100
+ ParameterGroups = [],
101
+ ParameterLabels = {}
102
+ } = {}
103
+ } = {}
104
+ } = template;
105
+ let NewParameterGroups = ParameterGroups;
106
+ if (Group) {
107
+ const GroupObject = ParameterGroups.filter(
108
+ (g) => g.Label?.default === Group
109
+ )[0];
110
+ NewParameterGroups = GroupObject ? ParameterGroups.map(
111
+ (g) => g.Label?.default === Group ? {
112
+ ...g,
113
+ Parameters: [...g.Parameters || [], ParameterId]
114
+ } : g
115
+ ) : [
116
+ ...ParameterGroups,
117
+ {
118
+ Label: {
119
+ default: Group
120
+ },
121
+ Parameters: [ParameterId]
122
+ }
123
+ ];
124
+ }
125
+ return {
126
+ ...template,
127
+ Parameters: {
128
+ ...Parameters,
129
+ [ParameterId]: Parameter
130
+ },
131
+ Metadata: {
132
+ ...template.Metadata,
133
+ "AWS::CloudFormation::Interface": {
134
+ ...template?.Metadata?.["AWS::CloudFormation::Interface"],
135
+ ParameterGroups: NewParameterGroups,
136
+ ParameterLabels: {
137
+ ...ParameterLabels,
138
+ [ParameterId]: {
139
+ default: Label
140
+ }
141
+ }
142
+ }
143
+ }
144
+ };
145
+ };
146
+ var addParameters = (parameters, template) => parameters.reduce((acc, p) => addParameter(p, acc), template);
147
+ var patchTemplate = (patch, template) => mergeValues([], template, patch, {
148
+ [getValuePathString([
149
+ // Parameter Groups
150
+ "Metadata",
151
+ "AWS::CloudFormation::Interface",
152
+ "ParameterGroups"
153
+ ])]: {
154
+ strategy: "accumulate-unique-by",
155
+ data: (pG) => pG?.Label?.default
156
+ },
157
+ [getValuePathString([
158
+ // Parameter Group Parameter Ids
159
+ "Metadata",
160
+ "AWS::CloudFormation::Interface",
161
+ "ParameterGroups",
162
+ "#",
163
+ "Parameters"
164
+ ])]: {
165
+ strategy: "accumulate-unique"
166
+ }
167
+ });
168
+ var createResourcePack = (creator) => (params, template) => {
169
+ const patch = creator(params);
170
+ return patchTemplate(patch, template);
171
+ };
172
+
173
+ // src/iac/packs/auth/user-management.ts
174
+ var addUserManagement = createResourcePack(
175
+ ({
176
+ id,
177
+ authRoleName,
178
+ unauthRoleName,
179
+ domainName,
180
+ hostedZoneId,
181
+ sslCertificateArn,
182
+ callbackUrls,
183
+ logoutUrls,
184
+ baseDomainRecordAliasTargetDNSName,
185
+ apiGatewayRESTAPIId,
186
+ apiStageName
187
+ }) => {
188
+ const apiRoleConfig = apiGatewayRESTAPIId && apiStageName ? {
189
+ [`${id}IdentityPoolRoles`]: {
190
+ Type: "AWS::Cognito::IdentityPoolRoleAttachment",
191
+ Properties: {
192
+ IdentityPoolId: {
193
+ Ref: `${id}IdentityPool`
194
+ },
195
+ Roles: {
196
+ authenticated: {
197
+ "Fn::GetAtt": [`${id}AuthRole`, "Arn"]
198
+ },
199
+ unauthenticated: {
200
+ "Fn::GetAtt": [`${id}UnauthRole`, "Arn"]
201
+ }
202
+ }
203
+ }
204
+ },
205
+ [`${id}AuthRole`]: {
206
+ Type: "AWS::IAM::Role",
207
+ Properties: {
208
+ RoleName: authRoleName,
209
+ Path: "/",
210
+ AssumeRolePolicyDocument: {
211
+ Version: "2012-10-17",
212
+ Statement: [
213
+ {
214
+ Effect: "Allow",
215
+ Principal: {
216
+ Federated: "cognito-identity.amazonaws.com"
217
+ },
218
+ Action: ["sts:AssumeRoleWithWebIdentity"],
219
+ Condition: {
220
+ StringEquals: {
221
+ "cognito-identity.amazonaws.com:aud": {
222
+ Ref: `${id}IdentityPool`
223
+ }
224
+ },
225
+ "ForAnyValue:StringLike": {
226
+ "cognito-identity.amazonaws.com:amr": "authenticated"
227
+ }
228
+ }
229
+ }
230
+ ]
231
+ },
232
+ Policies: [
233
+ {
234
+ PolicyName: "CognitoAuthorizedPolicy",
235
+ PolicyDocument: {
236
+ Version: "2012-10-17",
237
+ Statement: [
238
+ {
239
+ Effect: "Allow",
240
+ Action: [
241
+ "mobileanalytics:PutEvents",
242
+ "cognito-sync:*",
243
+ "cognito-identity:*"
244
+ ],
245
+ Resource: "*"
246
+ },
247
+ {
248
+ Effect: "Allow",
249
+ Action: ["execute-api:Invoke"],
250
+ Resource: {
251
+ "Fn::Sub": [
252
+ "arn:aws:execute-api:${Region}:${AccountId}:${APIID}/${StageName}/${HTTPVerb}/api/*",
253
+ {
254
+ Region: {
255
+ Ref: "AWS::Region"
256
+ },
257
+ AccountId: {
258
+ Ref: "AWS::AccountId"
259
+ },
260
+ APIID: apiGatewayRESTAPIId,
261
+ StageName: apiStageName,
262
+ HTTPVerb: "*"
263
+ }
264
+ ]
265
+ }
266
+ }
267
+ ]
268
+ }
269
+ }
270
+ ]
271
+ }
272
+ },
273
+ [`${id}UnauthRole`]: {
274
+ Type: "AWS::IAM::Role",
275
+ Properties: {
276
+ RoleName: unauthRoleName,
277
+ Path: "/",
278
+ AssumeRolePolicyDocument: {
279
+ Version: "2012-10-17",
280
+ Statement: [
281
+ {
282
+ Effect: "Allow",
283
+ Principal: {
284
+ Federated: "cognito-identity.amazonaws.com"
285
+ },
286
+ Action: ["sts:AssumeRoleWithWebIdentity"],
287
+ Condition: {
288
+ StringEquals: {
289
+ "cognito-identity.amazonaws.com:aud": {
290
+ Ref: `${id}IdentityPool`
291
+ }
292
+ },
293
+ "ForAnyValue:StringLike": {
294
+ "cognito-identity.amazonaws.com:amr": "unauthenticated"
295
+ }
296
+ }
297
+ }
298
+ ]
299
+ },
300
+ Policies: [
301
+ {
302
+ PolicyName: "CognitoUnauthorizedPolicy",
303
+ PolicyDocument: {
304
+ Version: "2012-10-17",
305
+ Statement: [
306
+ {
307
+ Effect: "Allow",
308
+ Action: [
309
+ "mobileanalytics:PutEvents",
310
+ "cognito-sync:*",
311
+ "cognito-identity:*"
312
+ ],
313
+ Resource: "*"
314
+ }
315
+ ]
316
+ }
317
+ }
318
+ ]
319
+ }
320
+ }
321
+ } : {};
322
+ return {
323
+ Resources: {
324
+ [id]: {
325
+ Type: "AWS::Cognito::UserPool",
326
+ Properties: {
327
+ UserPoolName: {
328
+ "Fn::Sub": [`\${AWS::StackName}${id}`, {}]
329
+ },
330
+ AccountRecoverySetting: {
331
+ RecoveryMechanisms: [
332
+ {
333
+ Name: "verified_email",
334
+ Priority: 1
335
+ }
336
+ ]
337
+ },
338
+ AdminCreateUserConfig: {
339
+ AllowAdminCreateUserOnly: false,
340
+ UnusedAccountValidityDays: 365
341
+ },
342
+ AutoVerifiedAttributes: ["email"],
343
+ AliasAttributes: ["phone_number", "email", "preferred_username"],
344
+ Schema: [
345
+ {
346
+ Name: "email",
347
+ Required: true,
348
+ Mutable: true
349
+ },
350
+ {
351
+ Name: "given_name",
352
+ Required: true,
353
+ Mutable: true
354
+ },
355
+ {
356
+ Name: "family_name",
357
+ Required: true,
358
+ Mutable: true
359
+ },
360
+ {
361
+ Name: "phone_number",
362
+ Required: true,
363
+ Mutable: true
364
+ }
365
+ ],
366
+ DeviceConfiguration: {
367
+ ChallengeRequiredOnNewDevice: true,
368
+ DeviceOnlyRememberedOnUserPrompt: false
369
+ },
370
+ UsernameConfiguration: {
371
+ CaseSensitive: false
372
+ }
373
+ }
374
+ },
375
+ [`${id}BaseDomainRecord`]: !!baseDomainRecordAliasTargetDNSName ? {
376
+ Type: "AWS::Route53::RecordSet",
377
+ DeletionPolicy: "Delete",
378
+ Properties: {
379
+ HostedZoneId: hostedZoneId,
380
+ Type: "A",
381
+ Name: domainName,
382
+ AliasTarget: {
383
+ HostedZoneId: "Z2FDTNDATAQYW2",
384
+ DNSName: baseDomainRecordAliasTargetDNSName
385
+ }
386
+ }
387
+ } : void 0,
388
+ [`${id}DomainRecord`]: {
389
+ Type: "AWS::Route53::RecordSet",
390
+ DeletionPolicy: "Delete",
391
+ Properties: {
392
+ HostedZoneId: hostedZoneId,
393
+ Type: "A",
394
+ Name: {
395
+ "Fn::Sub": [
396
+ "auth.${BaseDomainName}",
397
+ {
398
+ BaseDomainName: domainName
399
+ }
400
+ ]
401
+ },
402
+ AliasTarget: {
403
+ HostedZoneId: "Z2FDTNDATAQYW2",
404
+ DNSName: {
405
+ "Fn::GetAtt": [`${id}Domain`, "CloudFrontDistribution"]
406
+ }
407
+ }
408
+ }
409
+ },
410
+ [`${id}Domain`]: {
411
+ Type: "AWS::Cognito::UserPoolDomain",
412
+ DependsOn: !!baseDomainRecordAliasTargetDNSName ? `${id}BaseDomainRecord` : void 0,
413
+ Properties: {
414
+ Domain: {
415
+ "Fn::Sub": [
416
+ "auth.${BaseDomainName}",
417
+ {
418
+ BaseDomainName: domainName
419
+ }
420
+ ]
421
+ },
422
+ UserPoolId: {
423
+ Ref: id
424
+ },
425
+ CustomDomainConfig: {
426
+ CertificateArn: sslCertificateArn
427
+ }
428
+ }
429
+ },
430
+ [`${id}Client`]: {
431
+ Type: "AWS::Cognito::UserPoolClient",
432
+ Properties: {
433
+ ClientName: {
434
+ "Fn::Sub": [`\${AWS::StackName}${id}Client`, {}]
435
+ },
436
+ UserPoolId: {
437
+ Ref: id
438
+ },
439
+ AllowedOAuthFlowsUserPoolClient: true,
440
+ AllowedOAuthFlows: ["code", "implicit"],
441
+ AllowedOAuthScopes: [
442
+ "openid",
443
+ "email",
444
+ "phone",
445
+ "profile",
446
+ "aws.cognito.signin.user.admin"
447
+ ],
448
+ CallbackURLs: callbackUrls,
449
+ LogoutURLs: logoutUrls,
450
+ EnableTokenRevocation: true,
451
+ PreventUserExistenceErrors: "ENABLED",
452
+ SupportedIdentityProviders: ["COGNITO"]
453
+ }
454
+ },
455
+ [`${id}IdentityPool`]: {
456
+ Type: "AWS::Cognito::IdentityPool",
457
+ Properties: {
458
+ IdentityPoolName: {
459
+ "Fn::Sub": [`\${AWS::StackName}${id}IdentityPool`, {}]
460
+ },
461
+ AllowUnauthenticatedIdentities: false,
462
+ CognitoIdentityProviders: [
463
+ {
464
+ ClientId: {
465
+ Ref: `${id}Client`
466
+ },
467
+ ProviderName: {
468
+ "Fn::GetAtt": [id, "ProviderName"]
469
+ },
470
+ ServerSideTokenCheck: true
471
+ }
472
+ ]
473
+ }
474
+ },
475
+ ...apiRoleConfig
476
+ }
477
+ };
478
+ }
479
+ );
480
+ var SimpleCFT = class {
481
+ /**
482
+ * Create a SimpleCFT template wrapper.
483
+ *
484
+ * @param template - Initial CloudFormation template.
485
+ */
486
+ constructor(template = {
487
+ AWSTemplateFormatVersion: "2010-09-09"
488
+ }) {
489
+ this.template = template;
490
+ }
491
+ /**
492
+ * Apply a pack with configuration to the stack template.
493
+ * @see {@link IaC} for an example.
494
+ * */
495
+ applyPack = (pack, params) => {
496
+ this.template = pack(params, this.template);
497
+ return this;
498
+ };
499
+ /**
500
+ * Apply a patch to the stack template.
501
+ *
502
+ * @param patch - Template patch to merge.
503
+ * */
504
+ patch = (patch) => {
505
+ this.template = patchTemplate(patch, this.template);
506
+ return this;
507
+ };
508
+ /**
509
+ * Add a stack parameter including its descriptive info and an optional parameter group.
510
+ *
511
+ * @param parameter - Parameter definition and metadata.
512
+ * */
513
+ addParameter = (parameter) => {
514
+ this.template = addParameter(parameter, this.template);
515
+ return this;
516
+ };
517
+ /**
518
+ * Add a group of stack parameters including their descriptive info and an optional parameter group.
519
+ *
520
+ * @param group - Parameter group definition.
521
+ * */
522
+ addParameterGroup = ({ Label: Group, Parameters }) => {
523
+ const parameterIds = Object.keys(Parameters);
524
+ const parameterList = parameterIds.map((ParameterId) => {
525
+ const { Label, ...Parameter } = Parameters[ParameterId];
526
+ return {
527
+ Group,
528
+ ParameterId,
529
+ Label,
530
+ Parameter
531
+ };
532
+ });
533
+ this.template = addParameters(parameterList, this.template);
534
+ return this;
535
+ };
536
+ /**
537
+ * Use a modification to dynamically apply various changes at once.
538
+ *
539
+ * @param modification - Modification callback to apply.
540
+ * */
541
+ modify = (modification) => {
542
+ modification(this);
543
+ return this;
544
+ };
545
+ /**
546
+ * Convert the stack template to a string.
547
+ *
548
+ * @returns JSON string representation of the template.
549
+ * */
550
+ toString = () => JSON.stringify(this.template, null, 2);
551
+ /**
552
+ * Convert the stack template to a JSON object.
553
+ *
554
+ * @returns Template JSON object.
555
+ * */
556
+ toJSON = () => this.template;
557
+ /**
558
+ * Convert the stack template to a YAML string.
559
+ *
560
+ * @returns YAML string representation of the template.
561
+ * */
562
+ toYAML = () => YAML.stringify(this.template, {
563
+ aliasDuplicateObjects: false
564
+ });
565
+ };
566
+
567
+ // src/iac/packs/auth.ts
568
+ var addAuth = createResourcePack(
569
+ ({
570
+ userManagementId,
571
+ authRoleName,
572
+ unauthRoleName,
573
+ hostedZoneIdParameterName,
574
+ domainNameParameterName,
575
+ sslCertificateId,
576
+ callbackUrls,
577
+ logoutUrls,
578
+ mainCDNCloudFrontId,
579
+ apiCloudFunctionGatewayId,
580
+ apiStageName,
581
+ adminGroupId,
582
+ userManagementAdminGroupName
583
+ }) => new SimpleCFT().applyPack(addUserManagement, {
584
+ id: userManagementId,
585
+ authRoleName,
586
+ unauthRoleName,
587
+ domainName: {
588
+ Ref: domainNameParameterName
589
+ },
590
+ hostedZoneId: {
591
+ Ref: hostedZoneIdParameterName
592
+ },
593
+ sslCertificateArn: {
594
+ Ref: sslCertificateId
595
+ },
596
+ callbackUrls,
597
+ logoutUrls,
598
+ baseDomainRecordAliasTargetDNSName: {
599
+ "Fn::GetAtt": [mainCDNCloudFrontId, "DomainName"]
600
+ },
601
+ apiGatewayRESTAPIId: {
602
+ Ref: apiCloudFunctionGatewayId
603
+ },
604
+ apiStageName
605
+ }).patch({
606
+ Resources: {
607
+ [adminGroupId]: {
608
+ Type: "AWS::Cognito::UserPoolGroup",
609
+ Properties: {
610
+ GroupName: userManagementAdminGroupName,
611
+ UserPoolId: {
612
+ Ref: userManagementId
613
+ },
614
+ Description: "Application admin group."
615
+ }
616
+ }
617
+ }
618
+ }).template
619
+ );
620
+
621
+ // src/iac/packs/build.ts
622
+ var DEFAULT_BUILD_PIPELINE_REPO_PROVIDER = "GitHub";
623
+ var addBuildPipeline = createResourcePack(
624
+ ({
625
+ id,
626
+ buildSpec,
627
+ dependsOn,
628
+ environmentVariables,
629
+ timeoutInMinutes = 10,
630
+ environmentType = "LINUX_CONTAINER",
631
+ environmentComputeType = "BUILD_GENERAL1_SMALL",
632
+ environmentImage = "aws/codebuild/nodejs:10.14.1",
633
+ repoConfig: {
634
+ provider = DEFAULT_BUILD_PIPELINE_REPO_PROVIDER,
635
+ owner,
636
+ repo,
637
+ branch,
638
+ oauthToken
639
+ }
640
+ }) => ({
641
+ Resources: {
642
+ [`${id}CodeBuildRole`]: {
643
+ Type: "AWS::IAM::Role",
644
+ Properties: {
645
+ AssumeRolePolicyDocument: {
646
+ Statement: [
647
+ {
648
+ Effect: "Allow",
649
+ Principal: {
650
+ Service: ["codebuild.amazonaws.com"]
651
+ },
652
+ Action: ["sts:AssumeRole"]
653
+ }
654
+ ]
655
+ },
656
+ Path: "/",
657
+ Policies: [
658
+ {
659
+ PolicyName: "codebuild-service",
660
+ PolicyDocument: {
661
+ Statement: [
662
+ {
663
+ Effect: "Allow",
664
+ Action: "*",
665
+ Resource: "*"
666
+ }
667
+ ],
668
+ Version: "2012-10-17"
669
+ }
670
+ }
671
+ ]
672
+ }
673
+ },
674
+ [`${id}CodePipelineRole`]: {
675
+ Type: "AWS::IAM::Role",
676
+ Properties: {
677
+ AssumeRolePolicyDocument: {
678
+ Statement: [
679
+ {
680
+ Effect: "Allow",
681
+ Principal: {
682
+ Service: ["codepipeline.amazonaws.com"]
683
+ },
684
+ Action: ["sts:AssumeRole"]
685
+ }
686
+ ]
687
+ },
688
+ Path: "/",
689
+ Policies: [
690
+ {
691
+ PolicyName: "codepipeline-service",
692
+ PolicyDocument: {
693
+ Statement: [
694
+ {
695
+ Action: ["codebuild:*"],
696
+ Resource: "*",
697
+ Effect: "Allow"
698
+ },
699
+ {
700
+ Action: [
701
+ "s3:GetObject",
702
+ "s3:GetObjectVersion",
703
+ "s3:GetBucketVersioning"
704
+ ],
705
+ Resource: "*",
706
+ Effect: "Allow"
707
+ },
708
+ {
709
+ Action: ["s3:PutObject"],
710
+ Resource: ["arn:aws:s3:::codepipeline*"],
711
+ Effect: "Allow"
712
+ },
713
+ {
714
+ Action: ["s3:*", "cloudformation:*", "iam:PassRole"],
715
+ Resource: "*",
716
+ Effect: "Allow"
717
+ }
718
+ ],
719
+ Version: "2012-10-17"
720
+ }
721
+ }
722
+ ]
723
+ }
724
+ },
725
+ [`${id}PipelineBucket`]: {
726
+ Type: "AWS::S3::Bucket",
727
+ DeletionPolicy: "Delete",
728
+ Properties: {
729
+ BucketEncryption: {
730
+ ServerSideEncryptionConfiguration: [
731
+ {
732
+ ServerSideEncryptionByDefault: {
733
+ SSEAlgorithm: "AES256"
734
+ }
735
+ }
736
+ ]
737
+ },
738
+ PublicAccessBlockConfiguration: {
739
+ BlockPublicAcls: true,
740
+ BlockPublicPolicy: true,
741
+ IgnorePublicAcls: true,
742
+ RestrictPublicBuckets: true
743
+ }
744
+ }
745
+ },
746
+ [`${id}CodeBuildAndDeploy`]: {
747
+ Type: "AWS::CodeBuild::Project",
748
+ DependsOn: dependsOn,
749
+ Properties: {
750
+ Name: {
751
+ "Fn::Sub": `\${AWS::StackName}-${id}CodeBuildAndDeploy`
752
+ },
753
+ Description: "Deploy site to S3",
754
+ ServiceRole: {
755
+ "Fn::GetAtt": [`${id}CodeBuildRole`, "Arn"]
756
+ },
757
+ Artifacts: {
758
+ Type: "CODEPIPELINE"
759
+ },
760
+ Environment: {
761
+ Type: environmentType,
762
+ ComputeType: environmentComputeType,
763
+ Image: environmentImage,
764
+ EnvironmentVariables: environmentVariables
765
+ },
766
+ Source: {
767
+ Type: "CODEPIPELINE",
768
+ BuildSpec: buildSpec
769
+ },
770
+ TimeoutInMinutes: timeoutInMinutes
771
+ }
772
+ },
773
+ [`${id}Pipeline`]: {
774
+ Type: "AWS::CodePipeline::Pipeline",
775
+ DependsOn: `${id}CodeBuildAndDeploy`,
776
+ Properties: {
777
+ RoleArn: {
778
+ "Fn::GetAtt": [`${id}CodePipelineRole`, "Arn"]
779
+ },
780
+ Stages: [
781
+ {
782
+ Name: "Acquire-Source",
783
+ Actions: [
784
+ {
785
+ InputArtifacts: [],
786
+ Name: "Source",
787
+ ActionTypeId: {
788
+ Category: "Source",
789
+ Owner: "ThirdParty",
790
+ Version: "1",
791
+ Provider: provider
792
+ },
793
+ OutputArtifacts: [
794
+ {
795
+ Name: "SourceOutput"
796
+ }
797
+ ],
798
+ Configuration: {
799
+ Owner: owner,
800
+ Repo: repo,
801
+ Branch: branch,
802
+ OAuthToken: oauthToken
803
+ },
804
+ RunOrder: 1
805
+ }
806
+ ]
807
+ },
808
+ {
809
+ Name: "Build-And-Deploy",
810
+ Actions: [
811
+ {
812
+ Name: "Artifact",
813
+ ActionTypeId: {
814
+ Category: "Build",
815
+ Owner: "AWS",
816
+ Version: "1",
817
+ Provider: "CodeBuild"
818
+ },
819
+ InputArtifacts: [
820
+ {
821
+ Name: "SourceOutput"
822
+ }
823
+ ],
824
+ OutputArtifacts: [
825
+ {
826
+ Name: "DeployOutput"
827
+ }
828
+ ],
829
+ Configuration: {
830
+ ProjectName: {
831
+ Ref: `${id}CodeBuildAndDeploy`
832
+ }
833
+ },
834
+ RunOrder: 1
835
+ }
836
+ ]
837
+ }
838
+ ],
839
+ ArtifactStore: {
840
+ Type: "S3",
841
+ Location: {
842
+ Ref: `${id}PipelineBucket`
843
+ }
844
+ }
845
+ }
846
+ }
847
+ }
848
+ })
849
+ );
850
+ var COMMAND_HELPERS = {
851
+ updateFunction: ({
852
+ cloudFunctionArn,
853
+ codeZipFilePath
854
+ }) => `aws lambda update-function-code --function-name "${cloudFunctionArn}" --zip-file "fileb://${codeZipFilePath}"`,
855
+ copyDirectoryToS3: ({
856
+ s3Domain,
857
+ directoryPath
858
+ }) => `aws s3 cp --recursive --acl public-read ${directoryPath} s3://${s3Domain}/`,
859
+ cloudFrontInvalidation: ({
860
+ cloudFrontDistributionId,
861
+ pathsToInvalidate = ["/*"]
862
+ }) => `aws cloudfront create-invalidation --distribution-id "${cloudFrontDistributionId}" --paths "${pathsToInvalidate.join('" "')}"`,
863
+ addNPMTokenWithNPMRC: ({ npmToken }) => `echo '//registry.npmjs.org/:_authToken=${npmToken}' > .npmrc`
864
+ };
865
+ var createBuildSpec = ({ version = 0.2, phases }) => YAML.stringify(
866
+ // TRICKY: Removed all keys with a value of `undefined`.
867
+ JSON.parse(
868
+ JSON.stringify({
869
+ version,
870
+ phases
871
+ })
872
+ )
873
+ );
874
+
875
+ // src/iac/packs/cdn.ts
876
+ var addCDN = createResourcePack(
877
+ ({
878
+ id,
879
+ hostedZoneId,
880
+ domainName,
881
+ certificateArn,
882
+ fileStorageId
883
+ }) => {
884
+ const oacId = `${id}OriginAccessControl`;
885
+ return {
886
+ Resources: {
887
+ [oacId]: {
888
+ Type: "AWS::CloudFront::OriginAccessControl",
889
+ Properties: {
890
+ OriginAccessControlConfig: {
891
+ Name: oacId,
892
+ OriginAccessControlOriginType: "s3",
893
+ SigningBehavior: "always",
894
+ SigningProtocol: "sigv4"
895
+ }
896
+ }
897
+ },
898
+ [id]: {
899
+ Type: "AWS::CloudFront::Distribution",
900
+ DependsOn: fileStorageId,
901
+ Properties: {
902
+ DistributionConfig: {
903
+ Aliases: [domainName],
904
+ ViewerCertificate: {
905
+ AcmCertificateArn: certificateArn,
906
+ SslSupportMethod: "sni-only",
907
+ MinimumProtocolVersion: "TLSv1.1_2016"
908
+ },
909
+ DefaultCacheBehavior: {
910
+ ForwardedValues: {
911
+ QueryString: false
912
+ },
913
+ TargetOriginId: {
914
+ "Fn::Sub": [
915
+ "S3-${S3BucketName}",
916
+ {
917
+ S3BucketName: domainName
918
+ }
919
+ ]
920
+ },
921
+ ViewerProtocolPolicy: "redirect-to-https"
922
+ },
923
+ DefaultRootObject: "index.html",
924
+ Enabled: true,
925
+ IPV6Enabled: false,
926
+ HttpVersion: "http2",
927
+ Origins: [
928
+ {
929
+ DomainName: {
930
+ "Fn::Sub": [
931
+ "${S3BucketName}.s3.amazonaws.com",
932
+ {
933
+ S3BucketName: domainName
934
+ }
935
+ ]
936
+ },
937
+ Id: {
938
+ "Fn::Sub": [
939
+ "S3-${S3BucketName}",
940
+ {
941
+ S3BucketName: domainName
942
+ }
943
+ ]
944
+ },
945
+ OriginAccessControlId: { Ref: oacId },
946
+ S3OriginConfig: {
947
+ OriginAccessIdentity: ""
948
+ }
949
+ }
950
+ ],
951
+ CustomErrorResponses: [
952
+ {
953
+ ErrorCachingMinTTL: 300,
954
+ ErrorCode: 404,
955
+ ResponseCode: 200,
956
+ ResponsePagePath: "/index.html"
957
+ },
958
+ {
959
+ ErrorCachingMinTTL: 300,
960
+ ErrorCode: 403,
961
+ ResponseCode: 200,
962
+ ResponsePagePath: "/index.html"
963
+ }
964
+ ],
965
+ PriceClass: "PriceClass_All"
966
+ }
967
+ }
968
+ },
969
+ [`${id}Route53Record`]: {
970
+ Type: "AWS::Route53::RecordSet",
971
+ DependsOn: [id],
972
+ Properties: {
973
+ HostedZoneId: hostedZoneId,
974
+ Type: "A",
975
+ Name: {
976
+ "Fn::Sub": [
977
+ "${DomainName}.",
978
+ {
979
+ DomainName: domainName
980
+ }
981
+ ]
982
+ },
983
+ AliasTarget: {
984
+ HostedZoneId: "Z2FDTNDATAQYW2",
985
+ DNSName: {
986
+ "Fn::Sub": [
987
+ "${DomainName}.",
988
+ {
989
+ DomainName: {
990
+ "Fn::GetAtt": [id, "DomainName"]
991
+ }
992
+ }
993
+ ]
994
+ }
995
+ }
996
+ }
997
+ }
998
+ }
999
+ };
1000
+ }
1001
+ );
1002
+
1003
+ // src/iac/packs/cloud-function.ts
1004
+ var PLACEHOLDER_FUNCTION_CODE = {
1005
+ ZipFile: `module.exports = {handler: async () => ({
1006
+ statusCode: 200,
1007
+ headers: {'Content-Type': 'application/json'},
1008
+ body: '"You did it!"'
1009
+ })};
1010
+ `
1011
+ };
1012
+ var addCloudFunction = createResourcePack(
1013
+ ({
1014
+ id,
1015
+ code = PLACEHOLDER_FUNCTION_CODE,
1016
+ environment = {
1017
+ Variables: {
1018
+ NODE_ENV: "production"
1019
+ }
1020
+ },
1021
+ handler = "index.handler",
1022
+ runtime = "nodejs26.x",
1023
+ timeout = 30,
1024
+ policies = [
1025
+ {
1026
+ PolicyName: "lambda-parameter-store",
1027
+ PolicyDocument: {
1028
+ Version: "2012-10-17",
1029
+ Statement: [
1030
+ {
1031
+ Effect: "Allow",
1032
+ Action: ["*"],
1033
+ Resource: "*"
1034
+ }
1035
+ ]
1036
+ }
1037
+ }
1038
+ ]
1039
+ }) => {
1040
+ return {
1041
+ Resources: {
1042
+ [`${id}Role`]: {
1043
+ Type: "AWS::IAM::Role",
1044
+ Properties: {
1045
+ ManagedPolicyArns: [
1046
+ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
1047
+ ],
1048
+ AssumeRolePolicyDocument: {
1049
+ Version: "2012-10-17",
1050
+ Statement: [
1051
+ {
1052
+ Action: ["sts:AssumeRole"],
1053
+ Effect: "Allow",
1054
+ Principal: {
1055
+ Service: ["lambda.amazonaws.com"]
1056
+ }
1057
+ }
1058
+ ]
1059
+ },
1060
+ Policies: policies
1061
+ }
1062
+ },
1063
+ [id]: {
1064
+ Type: "AWS::Lambda::Function",
1065
+ Properties: {
1066
+ Timeout: timeout,
1067
+ Code: code,
1068
+ Environment: environment,
1069
+ Handler: handler,
1070
+ Role: {
1071
+ "Fn::GetAtt": [`${id}Role`, "Arn"]
1072
+ },
1073
+ Runtime: runtime
1074
+ }
1075
+ }
1076
+ }
1077
+ };
1078
+ }
1079
+ );
1080
+
1081
+ // src/iac/packs/database.ts
1082
+ var addDatabase = createResourcePack(
1083
+ ({
1084
+ tableId,
1085
+ tableName,
1086
+ keys,
1087
+ attributes,
1088
+ billingMode = "PAY_PER_REQUEST"
1089
+ }) => new SimpleCFT().patch({
1090
+ Resources: {
1091
+ [tableId]: {
1092
+ Type: "AWS::DynamoDB::Table",
1093
+ Properties: {
1094
+ TableName: tableName,
1095
+ AttributeDefinitions: Object.keys(attributes).map(
1096
+ (attributeName) => ({
1097
+ AttributeName: attributeName,
1098
+ AttributeType: attributes[attributeName]
1099
+ })
1100
+ ),
1101
+ KeySchema: Object.keys(keys).map((keyName) => ({
1102
+ AttributeName: keyName,
1103
+ KeyType: keys[keyName]
1104
+ })),
1105
+ BillingMode: billingMode
1106
+ }
1107
+ }
1108
+ }
1109
+ }).template
1110
+ );
1111
+
1112
+ // src/iac/packs/dns.ts
1113
+ var addDNS = createResourcePack(
1114
+ ({
1115
+ id,
1116
+ hostedZoneId,
1117
+ domainName,
1118
+ resourceRecords,
1119
+ recordType = "A"
1120
+ }) => {
1121
+ let cft = new SimpleCFT().patch({
1122
+ Resources: {
1123
+ [id]: {
1124
+ Type: "AWS::Route53::RecordSet",
1125
+ Properties: {
1126
+ HostedZoneId: hostedZoneId,
1127
+ Type: recordType,
1128
+ Name: domainName,
1129
+ ResourceRecords: resourceRecords,
1130
+ TTL: "300"
1131
+ }
1132
+ }
1133
+ }
1134
+ });
1135
+ return cft.template;
1136
+ }
1137
+ );
1138
+
1139
+ // src/iac/packs/file-storage.ts
1140
+ var addSecureFileStorage = createResourcePack(
1141
+ ({
1142
+ id,
1143
+ bucketName,
1144
+ shouldDelete = true,
1145
+ blockPublicAccess = true,
1146
+ cors = false,
1147
+ accessControl = void 0,
1148
+ allowACLs = false
1149
+ }) => {
1150
+ return {
1151
+ Resources: {
1152
+ [id]: {
1153
+ Type: "AWS::S3::Bucket",
1154
+ DeletionPolicy: shouldDelete ? "Delete" : "Retain",
1155
+ Properties: {
1156
+ BucketName: bucketName,
1157
+ AccessControl: accessControl,
1158
+ OwnershipControls: allowACLs ? {
1159
+ Rules: [
1160
+ {
1161
+ ObjectOwnership: "ObjectWriter"
1162
+ }
1163
+ ]
1164
+ } : void 0,
1165
+ CorsConfiguration: typeof cors === "object" ? cors : cors === true ? {
1166
+ CorsRules: [
1167
+ {
1168
+ AllowedHeaders: ["*"],
1169
+ AllowedMethods: [
1170
+ "GET",
1171
+ "PUT",
1172
+ "POST",
1173
+ "DELETE",
1174
+ "HEAD"
1175
+ ],
1176
+ AllowedOrigins: ["*"]
1177
+ }
1178
+ ]
1179
+ } : void 0,
1180
+ BucketEncryption: {
1181
+ ServerSideEncryptionConfiguration: [
1182
+ {
1183
+ ServerSideEncryptionByDefault: {
1184
+ SSEAlgorithm: "AES256"
1185
+ }
1186
+ }
1187
+ ]
1188
+ },
1189
+ PublicAccessBlockConfiguration: blockPublicAccess ? {
1190
+ BlockPublicAcls: true,
1191
+ BlockPublicPolicy: true,
1192
+ IgnorePublicAcls: true,
1193
+ RestrictPublicBuckets: true
1194
+ } : {
1195
+ BlockPublicAcls: false,
1196
+ BlockPublicPolicy: false,
1197
+ IgnorePublicAcls: false,
1198
+ RestrictPublicBuckets: false
1199
+ }
1200
+ }
1201
+ }
1202
+ }
1203
+ };
1204
+ }
1205
+ );
1206
+
1207
+ // src/iac/packs/gateway.ts
1208
+ var DEFAULT_AUTH_TYPE = "COGNITO_USER_POOLS";
1209
+ var addGateway = createResourcePack(
1210
+ ({
1211
+ id,
1212
+ hostedZoneId,
1213
+ domainName,
1214
+ certificateArn,
1215
+ cloudFunction: {
1216
+ id: cloudFunctionId,
1217
+ region: cloudFunctionRegion = "${AWS::Region}"
1218
+ },
1219
+ stageName = "production",
1220
+ authorizer,
1221
+ deploymentSuffix = ""
1222
+ }) => {
1223
+ const cloudFunctionUri = {
1224
+ "Fn::Sub": `arn:aws:apigateway:${cloudFunctionRegion}:lambda:path/2015-03-31/functions/\${${cloudFunctionId}.Arn}/invocations`
1225
+ };
1226
+ const {
1227
+ scopes: authScopes = ["phone", "email", "openid", "profile"],
1228
+ type: authType = "COGNITO_USER_POOLS",
1229
+ providerARNs,
1230
+ identitySource = "method.request.header.authorization"
1231
+ } = !!authorizer && typeof authorizer === "object" ? authorizer : {};
1232
+ const authorizerId = `${id}CustomAuthorizer`;
1233
+ const authProps = !!authorizer ? {
1234
+ AuthorizationScopes: authScopes,
1235
+ AuthorizationType: authType === DEFAULT_AUTH_TYPE ? DEFAULT_AUTH_TYPE : "CUSTOM",
1236
+ AuthorizerId: {
1237
+ Ref: authorizerId
1238
+ }
1239
+ } : {
1240
+ AuthorizationType: "NONE"
1241
+ };
1242
+ const fullDeploymentId = `${id}GatewayRESTAPIDeployment${deploymentSuffix}`;
1243
+ return new SimpleCFT().patch({
1244
+ Resources: {
1245
+ // REST API
1246
+ [id]: {
1247
+ Type: "AWS::ApiGateway::RestApi",
1248
+ Properties: {
1249
+ Name: {
1250
+ "Fn::Sub": `\${AWS::StackName}-${id}GatewayRESTAPI`
1251
+ },
1252
+ EndpointConfiguration: {
1253
+ Types: ["EDGE"]
1254
+ }
1255
+ }
1256
+ },
1257
+ [`${id}GatewayRESTAPIResource`]: {
1258
+ Type: "AWS::ApiGateway::Resource",
1259
+ DependsOn: id,
1260
+ Properties: {
1261
+ ParentId: {
1262
+ "Fn::GetAtt": [id, "RootResourceId"]
1263
+ },
1264
+ PathPart: "{proxy+}",
1265
+ RestApiId: {
1266
+ Ref: id
1267
+ }
1268
+ }
1269
+ },
1270
+ [`${id}GatewayRESTAPIMethod`]: {
1271
+ Type: "AWS::ApiGateway::Method",
1272
+ DependsOn: `${id}GatewayRESTAPIResource`,
1273
+ Properties: {
1274
+ ...authProps,
1275
+ HttpMethod: "ANY",
1276
+ ResourceId: {
1277
+ Ref: `${id}GatewayRESTAPIResource`
1278
+ },
1279
+ RestApiId: {
1280
+ Ref: id
1281
+ },
1282
+ Integration: {
1283
+ Type: "AWS_PROXY",
1284
+ IntegrationHttpMethod: "POST",
1285
+ Uri: cloudFunctionUri
1286
+ }
1287
+ }
1288
+ },
1289
+ [`${id}GatewayRESTAPIRootMethod`]: {
1290
+ Type: "AWS::ApiGateway::Method",
1291
+ DependsOn: `${id}GatewayRESTAPIResource`,
1292
+ Properties: {
1293
+ ...authProps,
1294
+ HttpMethod: "ANY",
1295
+ ResourceId: {
1296
+ "Fn::GetAtt": [id, "RootResourceId"]
1297
+ },
1298
+ RestApiId: {
1299
+ Ref: id
1300
+ },
1301
+ Integration: {
1302
+ Type: "AWS_PROXY",
1303
+ IntegrationHttpMethod: "POST",
1304
+ Uri: cloudFunctionUri
1305
+ }
1306
+ }
1307
+ }
1308
+ }
1309
+ }).patch({
1310
+ Resources: {
1311
+ // CORS
1312
+ [`${id}GatewayRESTAPIOPTIONSMethod`]: {
1313
+ Type: "AWS::ApiGateway::Method",
1314
+ DependsOn: `${id}GatewayRESTAPIResource`,
1315
+ Properties: {
1316
+ AuthorizationType: "NONE",
1317
+ HttpMethod: "OPTIONS",
1318
+ ResourceId: {
1319
+ Ref: `${id}GatewayRESTAPIResource`
1320
+ },
1321
+ RestApiId: {
1322
+ Ref: id
1323
+ },
1324
+ Integration: {
1325
+ Type: "AWS_PROXY",
1326
+ IntegrationHttpMethod: "POST",
1327
+ Uri: cloudFunctionUri
1328
+ }
1329
+ }
1330
+ },
1331
+ [`${id}GatewayRESTAPIRootOPTIONSMethod`]: {
1332
+ Type: "AWS::ApiGateway::Method",
1333
+ DependsOn: `${id}GatewayRESTAPIResource`,
1334
+ Properties: {
1335
+ AuthorizationType: "NONE",
1336
+ HttpMethod: "OPTIONS",
1337
+ ResourceId: {
1338
+ "Fn::GetAtt": [id, "RootResourceId"]
1339
+ },
1340
+ RestApiId: {
1341
+ Ref: id
1342
+ },
1343
+ Integration: {
1344
+ Type: "AWS_PROXY",
1345
+ IntegrationHttpMethod: "POST",
1346
+ Uri: cloudFunctionUri
1347
+ }
1348
+ }
1349
+ },
1350
+ [`${id}GatewayResponseDefault4XX`]: {
1351
+ Type: "AWS::ApiGateway::GatewayResponse",
1352
+ Properties: {
1353
+ ResponseParameters: {
1354
+ // Not authorized, so just allow the current origin by mapping it into the header.
1355
+ "gatewayresponse.header.Access-Control-Allow-Origin": "method.request.header.origin",
1356
+ "gatewayresponse.header.Access-Control-Allow-Credentials": "'true'",
1357
+ "gatewayresponse.header.Access-Control-Allow-Headers": "'*'"
1358
+ },
1359
+ ResponseType: "DEFAULT_4XX",
1360
+ RestApiId: {
1361
+ Ref: id
1362
+ }
1363
+ }
1364
+ }
1365
+ }
1366
+ }).patch({
1367
+ Resources: {
1368
+ // SUPPORTING RESOURCES
1369
+ [fullDeploymentId]: {
1370
+ Type: "AWS::ApiGateway::Deployment",
1371
+ DependsOn: [
1372
+ `${id}GatewayRESTAPIResource`,
1373
+ `${id}GatewayRESTAPIMethod`,
1374
+ `${id}GatewayRESTAPIRootMethod`,
1375
+ id,
1376
+ cloudFunctionId
1377
+ ],
1378
+ Properties: {
1379
+ RestApiId: {
1380
+ Ref: id
1381
+ }
1382
+ }
1383
+ },
1384
+ [`${id}CloudWatch`]: {
1385
+ Type: "AWS::Logs::LogGroup",
1386
+ Properties: {
1387
+ LogGroupName: {
1388
+ "Fn::Sub": `\${AWS::StackName}-${id}GatewayLogs`
1389
+ }
1390
+ }
1391
+ },
1392
+ [`${id}CloudWatchRole`]: {
1393
+ Type: "AWS::IAM::Role",
1394
+ Properties: {
1395
+ AssumeRolePolicyDocument: {
1396
+ Version: "2012-10-17",
1397
+ Statement: [
1398
+ {
1399
+ Effect: "Allow",
1400
+ Principal: {
1401
+ Service: ["apigateway.amazonaws.com"]
1402
+ },
1403
+ Action: "sts:AssumeRole"
1404
+ }
1405
+ ]
1406
+ },
1407
+ Path: "/",
1408
+ ManagedPolicyArns: [
1409
+ "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
1410
+ ]
1411
+ }
1412
+ },
1413
+ [`${id}CloudWatchAccount`]: {
1414
+ Type: "AWS::ApiGateway::Account",
1415
+ Properties: {
1416
+ CloudWatchRoleArn: {
1417
+ "Fn::GetAtt": [`${id}CloudWatchRole`, "Arn"]
1418
+ }
1419
+ }
1420
+ },
1421
+ [`${id}GatewayRESTAPIEnvironment`]: {
1422
+ Type: "AWS::ApiGateway::Stage",
1423
+ DependsOn: [`${id}CloudWatchAccount`, fullDeploymentId],
1424
+ Properties: {
1425
+ AccessLogSetting: {
1426
+ DestinationArn: {
1427
+ "Fn::GetAtt": [`${id}CloudWatch`, "Arn"]
1428
+ },
1429
+ Format: '{"requestId":"$context.requestId","ip":"$context.identity.sourceIp","caller":"$context.identity.caller","user":"$context.identity.user","requestTime":"$context.requestTime","httpMethod":"$context.httpMethod","resourcePath":"$context.resourcePath","status":"$context.status","protocol":"$context.protocol","responseLength":"$context.responseLength","apiGatewayErrorMessage":"$context.error.message"}'
1430
+ },
1431
+ DeploymentId: {
1432
+ Ref: fullDeploymentId
1433
+ },
1434
+ RestApiId: {
1435
+ Ref: id
1436
+ },
1437
+ StageName: stageName
1438
+ }
1439
+ }
1440
+ }
1441
+ }).patch({
1442
+ Resources: {
1443
+ // DNS
1444
+ [`${id}DomainName`]: {
1445
+ Type: "AWS::ApiGateway::DomainName",
1446
+ Properties: {
1447
+ CertificateArn: certificateArn,
1448
+ DomainName: domainName,
1449
+ EndpointConfiguration: {
1450
+ Types: ["EDGE"]
1451
+ }
1452
+ }
1453
+ },
1454
+ [`${id}DomainNameBasePathMapping`]: {
1455
+ Type: "AWS::ApiGateway::BasePathMapping",
1456
+ DependsOn: [
1457
+ id,
1458
+ `${id}GatewayRESTAPIEnvironment`,
1459
+ `${id}DomainName`
1460
+ ],
1461
+ Properties: {
1462
+ DomainName: domainName,
1463
+ RestApiId: {
1464
+ Ref: id
1465
+ },
1466
+ Stage: stageName
1467
+ }
1468
+ },
1469
+ [`${id}Route53Record`]: {
1470
+ Type: "AWS::Route53::RecordSet",
1471
+ DependsOn: `${id}DomainName`,
1472
+ Properties: {
1473
+ HostedZoneId: hostedZoneId,
1474
+ Type: "A",
1475
+ Name: {
1476
+ "Fn::Sub": [
1477
+ "${DomainName}.",
1478
+ {
1479
+ DomainName: domainName
1480
+ }
1481
+ ]
1482
+ },
1483
+ AliasTarget: {
1484
+ HostedZoneId: "Z2FDTNDATAQYW2",
1485
+ DNSName: {
1486
+ "Fn::Sub": [
1487
+ "${DomainName}.",
1488
+ {
1489
+ DomainName: {
1490
+ "Fn::GetAtt": [
1491
+ `${id}DomainName`,
1492
+ "DistributionDomainName"
1493
+ ]
1494
+ }
1495
+ }
1496
+ ]
1497
+ }
1498
+ }
1499
+ }
1500
+ }
1501
+ }
1502
+ }).patch({
1503
+ Resources: {
1504
+ // PERMISSIONS
1505
+ [`${id}CloudFunctionANYResourcePermission`]: {
1506
+ Type: "AWS::Lambda::Permission",
1507
+ Properties: {
1508
+ Action: "lambda:InvokeFunction",
1509
+ Principal: "apigateway.amazonaws.com",
1510
+ FunctionName: {
1511
+ "Fn::GetAtt": [cloudFunctionId, "Arn"]
1512
+ },
1513
+ SourceArn: {
1514
+ "Fn::Sub": [
1515
+ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
1516
+ {
1517
+ __Stage__: stageName,
1518
+ __ApiId__: {
1519
+ Ref: id
1520
+ }
1521
+ }
1522
+ ]
1523
+ }
1524
+ }
1525
+ }
1526
+ }
1527
+ }).patch(
1528
+ !!authorizer ? {
1529
+ Resources: {
1530
+ // AUTHORIZER
1531
+ [`${id}CustomAuthorizer`]: {
1532
+ Type: "AWS::ApiGateway::Authorizer",
1533
+ Properties: {
1534
+ IdentitySource: identitySource,
1535
+ Name: `${id}CustomAuthorizer`,
1536
+ ProviderARNs: providerARNs,
1537
+ RestApiId: {
1538
+ Ref: id
1539
+ },
1540
+ Type: "COGNITO_USER_POOLS"
1541
+ }
1542
+ }
1543
+ }
1544
+ } : {}
1545
+ ).template;
1546
+ }
1547
+ );
1548
+
1549
+ // src/iac/packs/repo.ts
1550
+ var addRepo = createResourcePack(
1551
+ ({
1552
+ repoOwnerParameterName,
1553
+ repoNameParameterName,
1554
+ repoBranchParameterName,
1555
+ repoTokenParameterName
1556
+ }) => new SimpleCFT().addParameterGroup({
1557
+ Label: "Repository",
1558
+ Parameters: {
1559
+ [repoOwnerParameterName]: {
1560
+ Label: "RepoOwner",
1561
+ Type: "String",
1562
+ Description: "The owner of the repository"
1563
+ },
1564
+ [repoNameParameterName]: {
1565
+ Label: "RepoName",
1566
+ Type: "String",
1567
+ Description: "The name of the repository"
1568
+ },
1569
+ [repoBranchParameterName]: {
1570
+ Label: "RepoBranch",
1571
+ Type: "String",
1572
+ Description: "The branch of the repository"
1573
+ },
1574
+ [repoTokenParameterName]: {
1575
+ Label: "RepoToken",
1576
+ Type: "String",
1577
+ Description: "The token of the repository",
1578
+ NoEcho: true
1579
+ }
1580
+ }
1581
+ }).template
1582
+ );
1583
+
1584
+ // src/iac/packs/ssl-certificate.ts
1585
+ var addSSLCertificate = createResourcePack(
1586
+ ({
1587
+ id,
1588
+ domainName,
1589
+ hostedZoneId,
1590
+ includeWildCard = true
1591
+ }) => ({
1592
+ Resources: {
1593
+ [id]: {
1594
+ Type: "AWS::CertificateManager::Certificate",
1595
+ Properties: {
1596
+ DomainName: domainName,
1597
+ ValidationMethod: "DNS",
1598
+ DomainValidationOptions: [
1599
+ {
1600
+ DomainName: domainName,
1601
+ HostedZoneId: hostedZoneId
1602
+ }
1603
+ ],
1604
+ SubjectAlternativeNames: includeWildCard ? [
1605
+ {
1606
+ "Fn::Sub": [
1607
+ "*.${BaseDomainName}",
1608
+ {
1609
+ BaseDomainName: domainName
1610
+ }
1611
+ ]
1612
+ }
1613
+ ] : void 0
1614
+ }
1615
+ }
1616
+ }
1617
+ })
1618
+ );
1619
+
1620
+ export { COMMAND_HELPERS, DEFAULT_AUTH_TYPE, DEFAULT_BUILD_PIPELINE_REPO_PROVIDER, PLACEHOLDER_FUNCTION_CODE, addAuth, addBuildPipeline, addCDN, addCloudFunction, addDNS, addDatabase, addGateway, addRepo, addSSLCertificate, addSecureFileStorage, createBuildSpec };