@digitraffic/common 2026.3.17-1 → 2026.3.26-1-beta

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 (238) hide show
  1. package/README.md +18 -1
  2. package/dist/__test__/asserter.d.ts +13 -0
  3. package/dist/__test__/asserter.js +39 -0
  4. package/dist/__test__/db-testutils.d.ts +3 -0
  5. package/dist/__test__/db-testutils.js +38 -0
  6. package/dist/__test__/dependencies.test.d.ts +1 -0
  7. package/dist/__test__/dependencies.test.js +21 -0
  8. package/dist/__test__/imports.test.d.ts +1 -0
  9. package/dist/__test__/imports.test.js +318 -0
  10. package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
  11. package/dist/__test__/infra/acl-builder.test.js +72 -0
  12. package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
  13. package/dist/__test__/infra/api/handler-factory.test.js +42 -0
  14. package/dist/__test__/infra/api/integration.test.d.ts +1 -0
  15. package/dist/__test__/infra/api/integration.test.js +162 -0
  16. package/dist/__test__/infra/api/response.test.d.ts +1 -0
  17. package/dist/__test__/infra/api/response.test.js +77 -0
  18. package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
  19. package/dist/__test__/infra/api/static-integration.test.js +35 -0
  20. package/dist/__test__/infra/documentation.test.d.ts +1 -0
  21. package/dist/__test__/infra/documentation.test.js +38 -0
  22. package/dist/__test__/infra/scheduler.test.d.ts +1 -0
  23. package/dist/__test__/infra/scheduler.test.js +23 -0
  24. package/dist/__test__/infra/security-rule.test.d.ts +1 -0
  25. package/dist/__test__/infra/security-rule.test.js +21 -0
  26. package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
  27. package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
  28. package/dist/__test__/marine/id_utils.test.d.ts +1 -0
  29. package/dist/__test__/marine/id_utils.test.js +45 -0
  30. package/dist/__test__/mock-ky.d.ts +2 -0
  31. package/dist/__test__/mock-ky.js +15 -0
  32. package/dist/__test__/promise/promise.test.d.ts +1 -0
  33. package/dist/__test__/promise/promise.test.js +126 -0
  34. package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
  35. package/dist/__test__/runtime/dt-logger.test.js +193 -0
  36. package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
  37. package/dist/__test__/secrets/secret-holder.test.js +96 -0
  38. package/dist/__test__/secrets/secret.test.d.ts +1 -0
  39. package/dist/__test__/secrets/secret.test.js +57 -0
  40. package/dist/__test__/stack/dt-function.test.d.ts +1 -0
  41. package/dist/__test__/stack/dt-function.test.js +340 -0
  42. package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
  43. package/dist/__test__/stack/rest-apis.test.js +45 -0
  44. package/dist/__test__/test/mock-ky.test.d.ts +1 -0
  45. package/dist/__test__/test/mock-ky.test.js +46 -0
  46. package/dist/__test__/testutils.d.ts +12 -0
  47. package/dist/__test__/testutils.js +32 -0
  48. package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
  49. package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
  50. package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
  51. package/dist/__test__/types/lambda-response-builder.test.js +81 -0
  52. package/dist/__test__/types/lambda-response.test.d.ts +9 -0
  53. package/dist/__test__/types/lambda-response.test.js +73 -0
  54. package/dist/__test__/utils/base64.test.d.ts +1 -0
  55. package/dist/__test__/utils/base64.test.js +38 -0
  56. package/dist/__test__/utils/date-utils.test.d.ts +1 -0
  57. package/dist/__test__/utils/date-utils.test.js +32 -0
  58. package/dist/__test__/utils/geometry.test.d.ts +1 -0
  59. package/dist/__test__/utils/geometry.test.js +25 -0
  60. package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
  61. package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
  62. package/dist/__test__/utils/logging.test.d.ts +1 -0
  63. package/dist/__test__/utils/logging.test.js +75 -0
  64. package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
  65. package/dist/__test__/utils/stop-watch.test.js +118 -0
  66. package/dist/__test__/utils/utils.test.d.ts +1 -0
  67. package/dist/__test__/utils/utils.test.js +48 -0
  68. package/dist/aws/infra/acl-builder.d.ts +53 -0
  69. package/dist/aws/infra/acl-builder.js +407 -0
  70. package/dist/aws/infra/api/handler-factory.d.ts +22 -0
  71. package/dist/aws/infra/api/handler-factory.js +68 -0
  72. package/dist/aws/infra/api/integration.d.ts +49 -0
  73. package/dist/aws/infra/api/integration.js +162 -0
  74. package/dist/aws/infra/api/response.d.ts +62 -0
  75. package/dist/aws/infra/api/response.js +132 -0
  76. package/dist/aws/infra/api/responses.d.ts +60 -0
  77. package/dist/aws/infra/api/responses.js +90 -0
  78. package/dist/aws/infra/api/static-integration.d.ts +16 -0
  79. package/dist/aws/infra/api/static-integration.js +76 -0
  80. package/dist/aws/infra/bucket-policy.d.ts +38 -0
  81. package/dist/aws/infra/bucket-policy.js +30 -0
  82. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  83. package/dist/aws/infra/canaries/canary-alarm.js +20 -0
  84. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  85. package/dist/aws/infra/canaries/canary-keys.js +4 -0
  86. package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
  87. package/dist/aws/infra/canaries/canary-parameters.js +2 -0
  88. package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
  89. package/dist/aws/infra/canaries/canary-role.js +51 -0
  90. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  91. package/dist/aws/infra/canaries/canary.js +26 -0
  92. package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
  93. package/dist/aws/infra/canaries/database-canary.js +65 -0
  94. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  95. package/dist/aws/infra/canaries/database-checker.js +119 -0
  96. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  97. package/dist/aws/infra/canaries/url-canary.js +55 -0
  98. package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
  99. package/dist/aws/infra/canaries/url-checker.js +256 -0
  100. package/dist/aws/infra/documentation.d.ts +56 -0
  101. package/dist/aws/infra/documentation.js +90 -0
  102. package/dist/aws/infra/import-util.d.ts +17 -0
  103. package/dist/aws/infra/import-util.js +41 -0
  104. package/dist/aws/infra/scheduler.d.ts +12 -0
  105. package/dist/aws/infra/scheduler.js +27 -0
  106. package/dist/aws/infra/security-rule.d.ts +12 -0
  107. package/dist/aws/infra/security-rule.js +35 -0
  108. package/dist/aws/infra/sqs-integration.d.ts +4 -0
  109. package/dist/aws/infra/sqs-integration.js +85 -0
  110. package/dist/aws/infra/sqs-queue.d.ts +19 -0
  111. package/dist/aws/infra/sqs-queue.js +145 -0
  112. package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
  113. package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
  114. package/dist/aws/infra/stack/dt-function.d.ts +124 -0
  115. package/dist/aws/infra/stack/dt-function.js +315 -0
  116. package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
  117. package/dist/aws/infra/stack/lambda-configs.js +71 -0
  118. package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
  119. package/dist/aws/infra/stack/lambda-log-group.js +24 -0
  120. package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
  121. package/dist/aws/infra/stack/monitoredfunction.js +147 -0
  122. package/dist/aws/infra/stack/parameters.d.ts +40 -0
  123. package/dist/aws/infra/stack/parameters.js +50 -0
  124. package/dist/aws/infra/stack/rest-api.d.ts +74 -0
  125. package/dist/aws/infra/stack/rest-api.js +235 -0
  126. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
  127. package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
  128. package/dist/aws/infra/stack/stack.d.ts +56 -0
  129. package/dist/aws/infra/stack/stack.js +71 -0
  130. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  131. package/dist/aws/infra/stack/subscription.js +37 -0
  132. package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
  133. package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
  134. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
  135. package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
  136. package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
  137. package/dist/aws/infra/stacks/db-stack.js +189 -0
  138. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  139. package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
  140. package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
  141. package/dist/aws/infra/stacks/network-stack.js +45 -0
  142. package/dist/aws/infra/usage-plans.d.ts +16 -0
  143. package/dist/aws/infra/usage-plans.js +38 -0
  144. package/dist/aws/runtime/apikey.d.ts +2 -0
  145. package/dist/aws/runtime/apikey.js +13 -0
  146. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  147. package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
  148. package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
  149. package/dist/aws/runtime/dt-logger-default.js +6 -0
  150. package/dist/aws/runtime/dt-logger.d.ts +117 -0
  151. package/dist/aws/runtime/dt-logger.js +159 -0
  152. package/dist/aws/runtime/environment.d.ts +5 -0
  153. package/dist/aws/runtime/environment.js +7 -0
  154. package/dist/aws/runtime/s3.d.ts +3 -0
  155. package/dist/aws/runtime/s3.js +21 -0
  156. package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
  157. package/dist/aws/runtime/secrets/dbsecret.js +26 -0
  158. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  159. package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
  160. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  161. package/dist/aws/runtime/secrets/rds-holder.js +25 -0
  162. package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
  163. package/dist/aws/runtime/secrets/secret-holder.js +81 -0
  164. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  165. package/dist/aws/runtime/secrets/secret.js +61 -0
  166. package/dist/aws/types/errors.d.ts +8 -0
  167. package/dist/aws/types/errors.js +13 -0
  168. package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
  169. package/dist/aws/types/lambda-proxy-types.js +210 -0
  170. package/dist/aws/types/lambda-response.d.ts +89 -0
  171. package/dist/aws/types/lambda-response.js +204 -0
  172. package/dist/aws/types/mediatypes.d.ts +11 -0
  173. package/dist/aws/types/mediatypes.js +14 -0
  174. package/dist/aws/types/model-with-reference.d.ts +7 -0
  175. package/dist/aws/types/model-with-reference.js +2 -0
  176. package/dist/aws/types/tags.d.ts +2 -0
  177. package/dist/aws/types/tags.js +4 -0
  178. package/dist/database/database.d.ts +27 -0
  179. package/dist/database/database.js +95 -0
  180. package/dist/database/last-updated.d.ts +15 -0
  181. package/dist/database/last-updated.js +46 -0
  182. package/dist/database/models.d.ts +6 -0
  183. package/dist/database/models.js +2 -0
  184. package/dist/index.d.ts +2 -0
  185. package/dist/index.js +2 -0
  186. package/dist/marine/id_utils.d.ts +3 -0
  187. package/dist/marine/id_utils.js +36 -0
  188. package/dist/marine/rtz.d.ts +48 -0
  189. package/dist/marine/rtz.js +2 -0
  190. package/dist/types/async-timeout-error.d.ts +3 -0
  191. package/dist/types/async-timeout-error.js +6 -0
  192. package/dist/types/either.d.ts +9 -0
  193. package/dist/types/either.js +2 -0
  194. package/dist/types/geojson.d.ts +47 -0
  195. package/dist/types/geojson.js +51 -0
  196. package/dist/types/http-error.d.ts +4 -0
  197. package/dist/types/http-error.js +8 -0
  198. package/dist/types/input-error.d.ts +2 -0
  199. package/dist/types/input-error.js +3 -0
  200. package/dist/types/language.d.ts +5 -0
  201. package/dist/types/language.js +7 -0
  202. package/dist/types/nullable.d.ts +24 -0
  203. package/dist/types/nullable.js +2 -0
  204. package/dist/types/openapi-schema.d.ts +932 -0
  205. package/dist/types/openapi-schema.js +151 -0
  206. package/dist/types/traffictype.d.ts +11 -0
  207. package/dist/types/traffictype.js +13 -0
  208. package/dist/types/urn.d.ts +1 -0
  209. package/dist/types/urn.js +2 -0
  210. package/dist/types/util-types.d.ts +11 -0
  211. package/dist/types/util-types.js +2 -0
  212. package/dist/types/validator.d.ts +4 -0
  213. package/dist/types/validator.js +9 -0
  214. package/dist/utils/api-model.d.ts +51 -0
  215. package/dist/utils/api-model.js +118 -0
  216. package/dist/utils/base64.d.ts +34 -0
  217. package/dist/utils/base64.js +53 -0
  218. package/dist/utils/date-utils.d.ts +27 -0
  219. package/dist/utils/date-utils.js +45 -0
  220. package/dist/utils/geojson-types.d.ts +14 -0
  221. package/dist/utils/geojson-types.js +15 -0
  222. package/dist/utils/geometry.d.ts +44 -0
  223. package/dist/utils/geometry.js +154 -0
  224. package/dist/utils/lambda-proxy-event.d.ts +9 -0
  225. package/dist/utils/lambda-proxy-event.js +31 -0
  226. package/dist/utils/logging.d.ts +40 -0
  227. package/dist/utils/logging.js +88 -0
  228. package/dist/utils/retry.d.ts +33 -0
  229. package/dist/utils/retry.js +135 -0
  230. package/dist/utils/slack.d.ts +5 -0
  231. package/dist/utils/slack.js +24 -0
  232. package/dist/utils/stop-watch.d.ts +46 -0
  233. package/dist/utils/stop-watch.js +114 -0
  234. package/dist/utils/utils.d.ts +95 -0
  235. package/dist/utils/utils.js +178 -0
  236. package/dist/utils/zod-utils.d.ts +27 -0
  237. package/dist/utils/zod-utils.js +57 -0
  238. package/package.json +30 -28
@@ -0,0 +1,162 @@
1
+ import { LambdaIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
2
+ import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response.js";
3
+ import { MediaType } from "../../types/mediatypes.js";
4
+ const VELOCITY_ALL_PARAMS = `#foreach($paramName in $params.keySet())
5
+ #if( ! $paramMap.containsKey("_$paramName"))
6
+ #set($tmp = $paramMap.put($paramName, $params[$paramName]))
7
+ #end
8
+ #end`;
9
+ const VELOCITY_PASS_BODY = `#set($tmp = $paramMap.put('payload', $util.base64Encode($input.body)))`;
10
+ export class DigitrafficIntegration {
11
+ lambda;
12
+ mediaType;
13
+ parameters = [];
14
+ deprecation = false;
15
+ sunset;
16
+ _passAllQueryParameters;
17
+ _passBody;
18
+ constructor(lambda, mediaType = MediaType.TEXT_PLAIN, deprecation = false, sunset) {
19
+ this.lambda = lambda;
20
+ this.mediaType = mediaType;
21
+ this.sunset = sunset;
22
+ this.deprecation = deprecation;
23
+ this._passAllQueryParameters = false;
24
+ this._passBody = false;
25
+ }
26
+ passAllQueryParameters() {
27
+ if (this.parameters.some((p) => p.type === "querystring")) {
28
+ throw new Error("Can't add query parameters with pass all");
29
+ }
30
+ this._passAllQueryParameters = true;
31
+ return this;
32
+ }
33
+ /**
34
+ * Body is passed as an base64-encoded string, so broken input should't break anything. You should
35
+ * decode, parse and validate the input in the lambda.
36
+ *
37
+ * The encoded body will be passed to handler with name payload!!
38
+ */
39
+ passBody() {
40
+ this._passBody = true;
41
+ return this;
42
+ }
43
+ addParameter(type, name) {
44
+ if (name.startsWith("_")) {
45
+ throw new Error("Parameters can't start with _");
46
+ }
47
+ this.parameters.push({ type, name });
48
+ return this;
49
+ }
50
+ addPathParameter(...names) {
51
+ names.forEach((name) => {
52
+ this.addParameter("path", name);
53
+ });
54
+ return this;
55
+ }
56
+ addQueryParameter(...names) {
57
+ if (this._passAllQueryParameters) {
58
+ throw new Error("Can't add query parameters with pass all");
59
+ }
60
+ names.forEach((name) => {
61
+ this.addParameter("querystring", name);
62
+ });
63
+ return this;
64
+ }
65
+ addMultiValueQueryParameter(...names) {
66
+ names.forEach((name) => {
67
+ this.addParameter("multivaluequerystring", name);
68
+ });
69
+ return this;
70
+ }
71
+ /**
72
+ * Note that context parameter values needs to be in json format as they will be parsed in template as json.
73
+ * See createRequestTemplates below.
74
+ * @param names for the parameters
75
+ * @returns
76
+ */
77
+ addContextParameter(...names) {
78
+ names.forEach((name) => {
79
+ this.addParameter("context", name);
80
+ });
81
+ return this;
82
+ }
83
+ /**
84
+ * Do not use Authorization header as that will be consumed by ApiGW.
85
+ * If Authorization header is needed, use lambda authorizers.
86
+ * @param names for the headers
87
+ */
88
+ addHeaderParameter(...names) {
89
+ names.forEach((name) => {
90
+ this.addParameter("header", name);
91
+ });
92
+ return this;
93
+ }
94
+ build() {
95
+ const integrationResponses = this.createResponses();
96
+ return new LambdaIntegration(this.lambda, {
97
+ proxy: false,
98
+ integrationResponses,
99
+ requestParameters: undefined,
100
+ requestTemplates: this.parameters.length === 0 && !this._passAllQueryParameters
101
+ ? undefined
102
+ : this.createRequestTemplates(),
103
+ passthroughBehavior: PassthroughBehavior.WHEN_NO_MATCH,
104
+ });
105
+ }
106
+ // noinspection JSUnusedGlobalSymbols
107
+ createRequestParameters() {
108
+ const requestParameters = {};
109
+ // filter out context parameters
110
+ this.parameters
111
+ .filter((parameter) => parameter.type !== "context")
112
+ .forEach((parameter) => {
113
+ requestParameters[`integration.request.${parameter.type.replace("multivaluequerystring", "querystring")}.${parameter.name}`] = `method.request.${parameter.type}.${parameter.name}`;
114
+ });
115
+ return requestParameters;
116
+ }
117
+ createRequestTemplates() {
118
+ const parameterAssignments = [];
119
+ this.parameters.forEach((parameter) => {
120
+ if (parameter.type === "context") {
121
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($context.${parameter.name})))`);
122
+ }
123
+ else if (parameter.type === "multivaluequerystring") {
124
+ // make multivaluequerystring values to array
125
+ parameterAssignments.push(`#set($tmp = $paramMap.put('_${parameter.name}', $method.request.multivaluequerystring.${parameter.name}))`);
126
+ }
127
+ else if (parameter.type === "path") {
128
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($input.params().path['${parameter.name}'])))`);
129
+ }
130
+ else if (parameter.type === "header") {
131
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($input.params().header['${parameter.name}'])))`);
132
+ }
133
+ else {
134
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($params['${parameter.name}'])))`);
135
+ }
136
+ });
137
+ // parameters starting with _ will be handled as multivalue querystring
138
+ return {
139
+ [MediaType.APPLICATION_JSON]: `
140
+ #set($paramMap = {})
141
+ #set($params = $input.params().get("querystring"))
142
+ ${parameterAssignments.join("\n")}
143
+ ${this._passAllQueryParameters ? VELOCITY_ALL_PARAMS : ""}
144
+ ${this._passBody ? VELOCITY_PASS_BODY : ""}
145
+ {
146
+ #foreach($paramName in $paramMap.keySet())
147
+ #if( $paramName.substring(0, 1) != '_')
148
+ "$paramName":"$paramMap.get($paramName)" #if($foreach.hasNext),\n#end
149
+ #else
150
+ "$paramName.substring(1)": [#foreach($val in $paramMap.get($paramName))"$util.escapeJavaScript($val)"#if($foreach.hasNext),#end#end] #if($foreach.hasNext),\n#end
151
+ #end
152
+ #end
153
+ }`,
154
+ };
155
+ }
156
+ createResponses() {
157
+ return [
158
+ DigitrafficIntegrationResponse.ok(this.mediaType, this.deprecation, this.sunset),
159
+ ];
160
+ }
161
+ }
162
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1,62 @@
1
+ import type { IModel, JsonSchema, MethodResponse } from "aws-cdk-lib/aws-apigateway";
2
+ import { MediaType } from "../../types/mediatypes.js";
3
+ /**
4
+ * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
5
+ * It will always return the body and status, but if status in something else than 200 OK the content-type
6
+ * will be overridden to text/plain. (it's assumed, that lambda will return error text).
7
+ *
8
+ * Body content must be base64-encoded! use LambdaResponse for this! This way you can also return
9
+ * non-textual content.
10
+ *
11
+ * If fileName is set, then Content-Disposition-header will be set to use it
12
+ * If timestamp is set, then ETag & Last-Modified headers will be set
13
+ */
14
+ export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$'))##\n#if ($inputRoot.status != 200)##\n#set ($context.responseOverride.status = $inputRoot.status)##\n#set ($context.responseOverride.header.Content-Type = 'text/plain')##\n#end##\n#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')##\n#if (\"$!inputRoot.timestamp\" != \"\")##\n#set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)##\n#end##\n#if (\"$!inputRoot.etag\" != \"\")##\n#set ($context.responseOverride.header.ETag = $inputRoot.etag)##\n#end##\n#if (\"$!inputRoot.fileName\" != \"\")##\n#set ($disposition = 'attachment; filename=\"FN\"')##\n#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))##\n#end##\n$util.base64Decode($inputRoot.body)";
15
+ /**
16
+ * Use this for deprecated integrations.
17
+ * Will add HTTP headers Deprecation and Sunset to response.
18
+ * Example:
19
+ * Deprecation: true
20
+ * Sunset: Tue, 20 Dec 2022 00:00:00 GMT
21
+ * @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
22
+ */
23
+ export declare const getDeprecatedDefaultLambdaResponse: (sunset?: string) => string;
24
+ /**
25
+ * @deprecated
26
+ */
27
+ export declare const MessageModel: {
28
+ contentType: MediaType;
29
+ modelName: string;
30
+ schema: JsonSchema;
31
+ };
32
+ export declare const NotFoundResponse: string;
33
+ /**
34
+ * @deprecated
35
+ */
36
+ export declare const BadRequestResponseTemplate: {
37
+ "application/json": string;
38
+ };
39
+ /**
40
+ * @deprecated
41
+ */
42
+ export declare const NotFoundResponseTemplate: {
43
+ "application/json": string;
44
+ };
45
+ /**
46
+ * @deprecated
47
+ */
48
+ export declare const XmlResponseTemplate: {
49
+ "application/xml": string;
50
+ };
51
+ /**
52
+ * @deprecated
53
+ */
54
+ export declare const InternalServerErrorResponseTemplate: {
55
+ "application/json": string;
56
+ };
57
+ export declare const DigitrafficMethodResponse: {
58
+ response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean, deprecation?: boolean, sunset?: boolean): MethodResponse;
59
+ response200(model: IModel, mediaType?: MediaType, deprecation?: boolean, sunset?: boolean): MethodResponse;
60
+ response500(model?: IModel, mediaType?: MediaType): MethodResponse;
61
+ response400(model?: IModel, mediaType?: MediaType): MethodResponse;
62
+ };
@@ -0,0 +1,132 @@
1
+ import { JsonSchemaType, JsonSchemaVersion, Model, } from "aws-cdk-lib/aws-apigateway";
2
+ import { dateFromIsoString } from "../../../utils/date-utils.js";
3
+ import { MediaType } from "../../types/mediatypes.js";
4
+ /**
5
+ * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
6
+ * It will always return the body and status, but if status in something else than 200 OK the content-type
7
+ * will be overridden to text/plain. (it's assumed, that lambda will return error text).
8
+ *
9
+ * Body content must be base64-encoded! use LambdaResponse for this! This way you can also return
10
+ * non-textual content.
11
+ *
12
+ * If fileName is set, then Content-Disposition-header will be set to use it
13
+ * If timestamp is set, then ETag & Last-Modified headers will be set
14
+ */
15
+ export const RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))##
16
+ #if ($inputRoot.status != 200)##
17
+ #set ($context.responseOverride.status = $inputRoot.status)##
18
+ #set ($context.responseOverride.header.Content-Type = 'text/plain')##
19
+ #end##
20
+ #set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')##
21
+ #if ("$!inputRoot.timestamp" != "")##
22
+ #set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)##
23
+ #end##
24
+ #if ("$!inputRoot.etag" != "")##
25
+ #set ($context.responseOverride.header.ETag = $inputRoot.etag)##
26
+ #end##
27
+ #if ("$!inputRoot.fileName" != "")##
28
+ #set ($disposition = 'attachment; filename="FN"')##
29
+ #set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))##
30
+ #end##
31
+ $util.base64Decode($inputRoot.body)`;
32
+ /**
33
+ * Use this for deprecated integrations.
34
+ * Will add HTTP headers Deprecation and Sunset to response.
35
+ * Example:
36
+ * Deprecation: true
37
+ * Sunset: Tue, 20 Dec 2022 00:00:00 GMT
38
+ * @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
39
+ */
40
+ export const getDeprecatedDefaultLambdaResponse = (sunset) => {
41
+ const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
42
+ ${sunset
43
+ ? `#set ($context.responseOverride.header.Sunset = '${dateFromIsoString(sunset).toUTCString()}')`
44
+ : ""}`;
45
+ return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
46
+ };
47
+ const BODY_FROM_INPUT_PATH = "$input.path('$').body";
48
+ /**
49
+ * @deprecated
50
+ */
51
+ const messageSchema = {
52
+ schema: JsonSchemaVersion.DRAFT4,
53
+ type: JsonSchemaType.OBJECT,
54
+ description: "Response with message",
55
+ properties: {
56
+ message: {
57
+ type: JsonSchemaType.STRING,
58
+ description: "Response message",
59
+ },
60
+ },
61
+ };
62
+ /**
63
+ * @deprecated
64
+ */
65
+ export const MessageModel = {
66
+ contentType: MediaType.APPLICATION_JSON,
67
+ modelName: "MessageResponseModel",
68
+ schema: messageSchema,
69
+ };
70
+ const NotFoundMessage = "Not Found";
71
+ export const NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
72
+ const InternalServerErrorMessage = "Error";
73
+ const InternalServerErrorResponse = JSON.stringify({
74
+ message: InternalServerErrorMessage,
75
+ });
76
+ const BadRequestMessage = "Bad Request";
77
+ const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
78
+ /**
79
+ * @deprecated
80
+ */
81
+ export const BadRequestResponseTemplate = {
82
+ [MediaType.APPLICATION_JSON]: BadRequestResponse,
83
+ };
84
+ /**
85
+ * @deprecated
86
+ */
87
+ export const NotFoundResponseTemplate = {
88
+ [MediaType.APPLICATION_JSON]: NotFoundResponse,
89
+ };
90
+ /**
91
+ * @deprecated
92
+ */
93
+ export const XmlResponseTemplate = {
94
+ [MediaType.APPLICATION_XML]: BODY_FROM_INPUT_PATH,
95
+ };
96
+ /**
97
+ * @deprecated
98
+ */
99
+ export const InternalServerErrorResponseTemplate = {
100
+ [MediaType.APPLICATION_JSON]: InternalServerErrorResponse,
101
+ };
102
+ export const DigitrafficMethodResponse = {
103
+ response(statusCode, model, mediaType, disableCors = false, deprecation = false, sunset = false) {
104
+ return {
105
+ statusCode,
106
+ responseModels: {
107
+ [mediaType]: model,
108
+ },
109
+ responseParameters: {
110
+ ...(!disableCors && {
111
+ "method.response.header.Access-Control-Allow-Origin": true,
112
+ }),
113
+ ...(deprecation && {
114
+ "method.response.header.Deprecation": true,
115
+ }),
116
+ ...(sunset && {
117
+ "method.response.header.Sunset": true,
118
+ }),
119
+ },
120
+ };
121
+ },
122
+ response200(model, mediaType = MediaType.APPLICATION_JSON, deprecation = false, sunset = false) {
123
+ return DigitrafficMethodResponse.response("200", model, mediaType, false, deprecation, sunset);
124
+ },
125
+ response500(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
126
+ return DigitrafficMethodResponse.response("500", model, mediaType, false);
127
+ },
128
+ response400(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
129
+ return DigitrafficMethodResponse.response("400", model, mediaType, false);
130
+ },
131
+ };
132
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1,60 @@
1
+ import type { IModel, IntegrationResponse, MethodResponse } from "aws-cdk-lib/aws-apigateway";
2
+ import { LambdaIntegration, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
3
+ import type { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
4
+ import type { MediaType } from "../../types/mediatypes.js";
5
+ /**
6
+ * @deprecated
7
+ */
8
+ export declare const RESPONSE_200_OK: IntegrationResponse;
9
+ /**
10
+ * @deprecated
11
+ */
12
+ export declare const RESPONSE_400_BAD_REQUEST: IntegrationResponse;
13
+ /**
14
+ * @deprecated
15
+ */
16
+ export declare const RESPONSE_500_SERVER_ERROR: IntegrationResponse;
17
+ /**
18
+ * @deprecated
19
+ */
20
+ export declare const RESPONSE_CORS_INTEGRATION: {
21
+ responseParameters: {
22
+ "method.response.header.Access-Control-Allow-Origin": string;
23
+ };
24
+ };
25
+ /**
26
+ * @deprecated
27
+ */
28
+ export declare const RESPONSE_404_NOT_FOUND: {
29
+ statusCode: string;
30
+ selectionPattern: string;
31
+ responseTemplates: {
32
+ "application/json": string;
33
+ };
34
+ };
35
+ /**
36
+ * @deprecated Use DigitrafficMethodResponse
37
+ */
38
+ export declare function methodResponse(status: string, contentType: MediaType, model: IModel, parameters?: Record<string, boolean>): MethodResponse;
39
+ interface IntegrationOptions {
40
+ requestParameters?: {
41
+ [dest: string]: string;
42
+ };
43
+ requestTemplates?: {
44
+ [contentType: string]: string;
45
+ };
46
+ responses?: IntegrationResponse[];
47
+ disableCors?: boolean;
48
+ xml?: boolean;
49
+ passthroughBehavior?: PassthroughBehavior;
50
+ }
51
+ /**
52
+ * Creates a default Lambda integration for a REST API resource _root_
53
+ * @param lambdaFunction The Lambda function
54
+ * @param options Options
55
+ *
56
+ * @deprecated Use DigitrafficIntegration
57
+ */
58
+ export declare function defaultIntegration(lambdaFunction: AWSFunction, options?: IntegrationOptions): LambdaIntegration;
59
+ export declare function getResponse(response: IntegrationResponse, options?: IntegrationOptions): IntegrationResponse;
60
+ export {};
@@ -0,0 +1,90 @@
1
+ import { LambdaIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
2
+ import { BAD_REQUEST_MESSAGE, ERROR_MESSAGE, NOT_FOUND_MESSAGE, } from "../../types/errors.js";
3
+ import { BadRequestResponseTemplate, InternalServerErrorResponseTemplate, NotFoundResponseTemplate, XmlResponseTemplate, } from "./response.js";
4
+ /**
5
+ * @deprecated
6
+ */
7
+ export const RESPONSE_200_OK = {
8
+ statusCode: "200",
9
+ };
10
+ /**
11
+ * @deprecated
12
+ */
13
+ export const RESPONSE_400_BAD_REQUEST = {
14
+ statusCode: "400",
15
+ selectionPattern: BAD_REQUEST_MESSAGE,
16
+ responseTemplates: BadRequestResponseTemplate,
17
+ };
18
+ /**
19
+ * @deprecated
20
+ */
21
+ export const RESPONSE_500_SERVER_ERROR = {
22
+ statusCode: "500",
23
+ selectionPattern: ERROR_MESSAGE,
24
+ responseTemplates: InternalServerErrorResponseTemplate,
25
+ };
26
+ /**
27
+ * @deprecated
28
+ */
29
+ const RESPONSE_XML = {
30
+ responseTemplates: XmlResponseTemplate,
31
+ };
32
+ /**
33
+ * @deprecated
34
+ */
35
+ export const RESPONSE_CORS_INTEGRATION = {
36
+ responseParameters: {
37
+ "method.response.header.Access-Control-Allow-Origin": "'*'",
38
+ },
39
+ };
40
+ /**
41
+ * @deprecated
42
+ */
43
+ export const RESPONSE_404_NOT_FOUND = {
44
+ statusCode: "404",
45
+ selectionPattern: NOT_FOUND_MESSAGE,
46
+ responseTemplates: NotFoundResponseTemplate,
47
+ };
48
+ /**
49
+ * @deprecated Use DigitrafficMethodResponse
50
+ */
51
+ export function methodResponse(status, contentType, model, parameters) {
52
+ return {
53
+ statusCode: status,
54
+ responseModels: {
55
+ [contentType]: model,
56
+ },
57
+ responseParameters: parameters ?? {},
58
+ };
59
+ }
60
+ /**
61
+ * Creates a default Lambda integration for a REST API resource _root_
62
+ * @param lambdaFunction The Lambda function
63
+ * @param options Options
64
+ *
65
+ * @deprecated Use DigitrafficIntegration
66
+ */
67
+ export function defaultIntegration(lambdaFunction, options) {
68
+ return new LambdaIntegration(lambdaFunction, {
69
+ proxy: false,
70
+ integrationResponses: options?.responses ?? [
71
+ getResponse(RESPONSE_200_OK, options),
72
+ getResponse(RESPONSE_400_BAD_REQUEST, options),
73
+ getResponse(RESPONSE_404_NOT_FOUND, options),
74
+ getResponse(RESPONSE_500_SERVER_ERROR, options),
75
+ ],
76
+ requestParameters: options?.requestParameters ?? {},
77
+ requestTemplates: options?.requestTemplates ?? {},
78
+ passthroughBehavior: options?.passthroughBehavior ?? PassthroughBehavior.WHEN_NO_MATCH,
79
+ });
80
+ }
81
+ export function getResponse(response, options) {
82
+ if (options?.xml) {
83
+ response = { ...response, ...RESPONSE_XML };
84
+ }
85
+ if (!options?.disableCors) {
86
+ response = { ...response, ...RESPONSE_CORS_INTEGRATION };
87
+ }
88
+ return response;
89
+ }
90
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1,16 @@
1
+ import type { IModel, IntegrationResponse, MethodResponse, Resource } from "aws-cdk-lib/aws-apigateway";
2
+ import { MockIntegration } from "aws-cdk-lib/aws-apigateway";
3
+ import { MediaType } from "../../types/mediatypes.js";
4
+ /**
5
+ * Static integration, that returns the given response with given mediaType from given resource.
6
+ *
7
+ * @param resource
8
+ * @param mediaType
9
+ * @param response
10
+ */
11
+ export declare class DigitrafficStaticIntegration extends MockIntegration {
12
+ constructor(resource: Resource, mediaType: MediaType, response: string, model: IModel, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>);
13
+ static json<K>(resource: Resource, response: K, model: IModel, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>): DigitrafficStaticIntegration;
14
+ static createIntegrationResponse(response: string, mediaType: MediaType, headers?: Record<string, string>): IntegrationResponse;
15
+ static createMethodResponse(headers: Record<string, string>, mediaType: MediaType, model: IModel): MethodResponse;
16
+ }
@@ -0,0 +1,76 @@
1
+ import { MockIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
2
+ import { MediaType } from "../../types/mediatypes.js";
3
+ const INTEGRATION_RESPONSE_200 = `{
4
+ "statusCode": 200
5
+ }`;
6
+ /**
7
+ * Static integration, that returns the given response with given mediaType from given resource.
8
+ *
9
+ * @param resource
10
+ * @param mediaType
11
+ * @param response
12
+ */
13
+ export class DigitrafficStaticIntegration extends MockIntegration {
14
+ constructor(resource, mediaType, response, model, enableCors = true, apiKeyRequired = true, headers = {}) {
15
+ if (enableCors) {
16
+ headers = { ...headers, "Access-Control-Allow-Origin": "*" };
17
+ }
18
+ const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, headers);
19
+ super({
20
+ passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
21
+ requestTemplates: {
22
+ [mediaType]: INTEGRATION_RESPONSE_200,
23
+ },
24
+ integrationResponses: [integrationResponse],
25
+ });
26
+ ["GET", "HEAD"].forEach((httpMethod) => {
27
+ resource.addMethod(httpMethod, this, {
28
+ apiKeyRequired,
29
+ methodResponses: [
30
+ DigitrafficStaticIntegration.createMethodResponse(headers, mediaType, model),
31
+ ],
32
+ });
33
+ });
34
+ }
35
+ static json(resource, response, model, enableCors = true, apiKeyRequired = true, headers = {}) {
36
+ return new DigitrafficStaticIntegration(resource, MediaType.APPLICATION_JSON, JSON.stringify(response), model, enableCors, apiKeyRequired, headers);
37
+ }
38
+ static createIntegrationResponse(response, mediaType, headers = {}) {
39
+ const params = mapRecord(headers, (entry) => [
40
+ `method.response.header.${entry[0]}`,
41
+ `'${entry[1]}'`,
42
+ ]);
43
+ return {
44
+ statusCode: "200",
45
+ responseTemplates: {
46
+ [mediaType]: response,
47
+ },
48
+ responseParameters: params,
49
+ };
50
+ }
51
+ static createMethodResponse(headers, mediaType, model) {
52
+ const allowedHeaders = Object.keys(headers);
53
+ const entries = Object.fromEntries(allowedHeaders.map((key) => [key, true]));
54
+ return {
55
+ statusCode: "200",
56
+ responseParameters: prefixKeys("method.response.header.", entries),
57
+ responseModels: {
58
+ [mediaType]: model,
59
+ },
60
+ };
61
+ }
62
+ }
63
+ function mapRecord(obj, func) {
64
+ const mappedEntries = Object.entries(obj).map((entry) => func(entry));
65
+ return Object.fromEntries(mappedEntries);
66
+ }
67
+ /**
68
+ * Create a new Record with prefix added to each of the keys.
69
+ *
70
+ * @param prefix
71
+ * @param obj
72
+ */
73
+ function prefixKeys(prefix, obj) {
74
+ return mapRecord(obj, (entry) => [prefix + entry[0], entry[1]]);
75
+ }
76
+ //# sourceMappingURL=static-integration.js.map
@@ -0,0 +1,38 @@
1
+ import { Effect } from "aws-cdk-lib/aws-iam";
2
+ import type { Bucket } from "aws-cdk-lib/aws-s3";
3
+ export interface BaseGrantConfiguration {
4
+ readonly bucket: Bucket;
5
+ /**
6
+ * Specify resources
7
+ *
8
+ * @default bucketArn + "/*"
9
+ */
10
+ readonly resources?: string[];
11
+ /**
12
+ * Specify granted actions
13
+ *
14
+ * @default ["s3:GetObject"]
15
+ */
16
+ readonly actions?: string[];
17
+ /**
18
+ * Allow or deny
19
+ *
20
+ * @default Effect.ALLOW
21
+ */
22
+ readonly effect?: Effect;
23
+ }
24
+ export interface CloudfrontGrantConfiguration extends BaseGrantConfiguration {
25
+ readonly distributionArn: string;
26
+ }
27
+ export interface CloudfrontOAIGrantConfiguration extends BaseGrantConfiguration {
28
+ readonly canonicalUserId: string;
29
+ }
30
+ /**
31
+ * Grant given cloudfront distribution rights to given bucket
32
+ */
33
+ export declare function grantOACRights(config: CloudfrontGrantConfiguration): void;
34
+ /**
35
+ * Grant given distribution OAI rights to given bucket.
36
+ * @deprecated use OAC and grantCloudfrontRights
37
+ */
38
+ export declare function grantOAIRights(config: CloudfrontOAIGrantConfiguration): void;
@@ -0,0 +1,30 @@
1
+ import { CanonicalUserPrincipal, Effect, PolicyStatement, ServicePrincipal, } from "aws-cdk-lib/aws-iam";
2
+ /**
3
+ * Grant given cloudfront distribution rights to given bucket
4
+ */
5
+ export function grantOACRights(config) {
6
+ config.bucket.addToResourcePolicy(new PolicyStatement({
7
+ effect: config.effect ?? Effect.ALLOW,
8
+ principals: [new ServicePrincipal("cloudfront.amazonaws.com")],
9
+ resources: config.resources ?? [`${config.bucket.bucketArn}/*`],
10
+ actions: config.actions ?? ["s3:GetObject"],
11
+ conditions: {
12
+ StringEquals: {
13
+ "AWS:SourceArn": config.distributionArn,
14
+ },
15
+ },
16
+ }));
17
+ }
18
+ /**
19
+ * Grant given distribution OAI rights to given bucket.
20
+ * @deprecated use OAC and grantCloudfrontRights
21
+ */
22
+ export function grantOAIRights(config) {
23
+ config.bucket.addToResourcePolicy(new PolicyStatement({
24
+ effect: config.effect ?? Effect.ALLOW,
25
+ principals: [new CanonicalUserPrincipal(config.canonicalUserId)],
26
+ resources: config.resources ?? [`${config.bucket.bucketArn}/*`],
27
+ actions: config.actions ?? ["s3:GetObject"],
28
+ }));
29
+ }
30
+ //# sourceMappingURL=bucket-policy.js.map
@@ -0,0 +1,6 @@
1
+ import type { Canary } from "aws-cdk-lib/aws-synthetics";
2
+ import type { Construct } from "constructs";
3
+ import type { CanaryParameters } from "./canary-parameters.js";
4
+ export declare class CanaryAlarm {
5
+ constructor(stack: Construct, canary: Canary, params: CanaryParameters);
6
+ }