@beesolve/cdk-constructs 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -210,4 +210,35 @@ interface SqsWithDlqLambdaInputProps extends SqsWithDlqProps {
210
210
  readonly disabled?: boolean;
211
211
  }
212
212
  type BatchingConfig = Pick<SqsEventSourceProps, "batchSize" | "maxBatchingWindow" | "reportBatchItemFailures" | "maxConcurrency">;
213
- export { SqsWithDlqProps, SqsWithDlqLambdaInputProps, SqsWithDlq, EmailAlarms, CloudFrontAccessLoggingSettingsProps, CloudFrontAccessLoggingSettings };
213
+ import { Architecture, Function as Function3, LoggingFormat, Runtime } from "aws-cdk-lib/aws-lambda";
214
+ import { NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
215
+ import { LogGroupProps } from "aws-cdk-lib/aws-logs";
216
+ import { Construct as Construct4 } from "constructs";
217
+ type Nodejs24FunctionProps = Omit<NodejsFunctionProps, "runtime" | "architecture" | "logGroup" | "entry" | "handler" | "code" | "bundling" | "awsSdkConnectionReuse"> & {
218
+ entry: `${string}.ts`;
219
+ logGroupProps?: LogGroupProps;
220
+ loggingFormat?: LoggingFormat;
221
+ runtime?: typeof Runtime.NODEJS_24_X;
222
+ architecture?: typeof Architecture.ARM_64;
223
+ handler?: string;
224
+ /**
225
+ * When function is being built the source maps are bundled without content for better performance.
226
+ * You should provide revision which is added to the description automatically for easier debugging.
227
+ *
228
+ * You can use cached `getRevision()` function which is exported in this file in order to get git commit id.
229
+ */
230
+ revision: string;
231
+ };
232
+ /**
233
+ * This construct provides easy way of deploying Node.js function with opinionated defaults.
234
+ *
235
+ * You need to provide `entry` - TypeScript file which exports `handler` function.
236
+ *
237
+ * Entry file is being transpiled by `esbuild` to ESM format compatible with Node.js 24.
238
+ *
239
+ */
240
+ declare class Nodejs24Function extends Function3 {
241
+ constructor(scope: Construct4, id: string, props: Nodejs24FunctionProps);
242
+ }
243
+ declare function getRevision(enforceGit: boolean): string;
244
+ export { getRevision, SqsWithDlqProps, SqsWithDlqLambdaInputProps, SqsWithDlq, Nodejs24Function, EmailAlarms, CloudFrontAccessLoggingSettingsProps, CloudFrontAccessLoggingSettings };
package/dist/index.js CHANGED
@@ -240,8 +240,125 @@ class SqsWithDlq extends Construct3 {
240
240
  return sqs;
241
241
  }
242
242
  }
243
+ // packages/cdk-constructs/src/nodejsFunction.ts
244
+ import { RemovalPolicy } from "aws-cdk-lib";
245
+ import {
246
+ Architecture,
247
+ Code,
248
+ Function,
249
+ LoggingFormat,
250
+ Runtime
251
+ } from "aws-cdk-lib/aws-lambda";
252
+ import {
253
+ Charset
254
+ } from "aws-cdk-lib/aws-lambda-nodejs";
255
+ import {
256
+ LogGroup,
257
+ RetentionDays
258
+ } from "aws-cdk-lib/aws-logs";
259
+ import { buildSync } from "esbuild";
260
+ import { execSync } from "node:child_process";
261
+ var __dirname = "/Users/ivan/data/work/github.com/beesolve/p/packages/packages/cdk-constructs/src";
262
+
263
+ class Nodejs24Function extends Function {
264
+ constructor(scope, id, props) {
265
+ const {
266
+ entry,
267
+ handler,
268
+ description = "",
269
+ logGroupProps = {
270
+ retention: RetentionDays.TWO_WEEKS,
271
+ removalPolicy: RemovalPolicy.DESTROY
272
+ },
273
+ loggingFormat = LoggingFormat.JSON,
274
+ revision = true,
275
+ ...rest
276
+ } = props;
277
+ const outDir = `${__dirname}/cdk.out/bundling.${id}.beesolve-nodejs.${Date.now()}`;
278
+ const buildResult = buildSync({
279
+ entryPoints: [entry],
280
+ banner: {
281
+ js: `/* CommonJS polyfills */import { fileURLToPath } from 'node:url';import { createRequire } from 'node:module';const __filename = fileURLToPath(import.meta.url);const __dirname = fileURLToPath(new URL('.', import.meta.url));const require = createRequire(import.meta.url);/* end of CommonJS polyfills */`
282
+ },
283
+ charset: Charset.UTF8,
284
+ bundle: true,
285
+ external: [],
286
+ format: "esm",
287
+ keepNames: true,
288
+ mainFields: ["module", "main"],
289
+ minify: true,
290
+ sourcemap: "external",
291
+ target: "node24",
292
+ platform: "node",
293
+ resolveExtensions: [".ts", ".js", ".mjs", ".json"],
294
+ legalComments: "none",
295
+ splitting: true,
296
+ treeShaking: true,
297
+ outdir: outDir
298
+ });
299
+ if (buildResult.errors.length !== 0) {
300
+ throw new BuildError(buildResult.errors);
301
+ }
302
+ const fileName = entry.split("/").at(-1)?.replace(".ts", "");
303
+ const handlerName = `${fileName}.${handler ?? "handler"}`;
304
+ super(scope, id, {
305
+ ...rest,
306
+ code: Code.fromAsset(outDir),
307
+ architecture: Architecture.ARM_64,
308
+ runtime: Runtime.NODEJS_24_X,
309
+ handler: handlerName,
310
+ logGroup: new LogGroup(scope, `${id}LogGroup`, logGroupProps),
311
+ loggingFormat,
312
+ description: `${description} (${revision})`
313
+ });
314
+ }
315
+ }
316
+
317
+ class BuildError extends Error {
318
+ constructor(messages) {
319
+ super(`Couldn't build the code.
320
+
321
+ ${messages.map((message) => message.text).join(`
322
+ `)}`);
323
+ }
324
+ }
325
+ var revisionCache;
326
+ function getRevision(enforceGit) {
327
+ if (revisionCache == null) {
328
+ revisionCache = _getRevision();
329
+ }
330
+ return revisionCache;
331
+ function _getRevision() {
332
+ try {
333
+ const buffer = execSync("git rev-parse --short HEAD");
334
+ const shortCommitId = buffer.toString("utf-8").trim();
335
+ return `${shortCommitId}${isDirty() ? " - dirty" : ""}`;
336
+ } catch (error) {
337
+ if (enforceGit) {
338
+ throw new NotAGitRepositoryError;
339
+ }
340
+ return "cannot parse revision";
341
+ }
342
+ }
343
+ function isDirty() {
344
+ try {
345
+ execSync("git diff --quiet && git diff --cached --quiet");
346
+ return false;
347
+ } catch (error) {
348
+ return true;
349
+ }
350
+ }
351
+ }
352
+
353
+ class NotAGitRepositoryError extends Error {
354
+ constructor() {
355
+ super(`Cannot deploy without using git.`);
356
+ }
357
+ }
243
358
  export {
359
+ getRevision,
244
360
  SqsWithDlq,
361
+ Nodejs24Function,
245
362
  EmailAlarms,
246
363
  CloudFrontAccessLoggingSettings
247
364
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beesolve/cdk-constructs",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/beesolve/packages/tree/main/packages/cdk-constructs#readme",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "type-check": "tsc --noEmit"
16
16
  },
17
17
  "peerDependencies": {
18
- "typescript": "^5.9.3"
18
+ "typescript": "catalog:"
19
19
  },
20
20
  "peerDependenciesMeta": {
21
21
  "typescript": {
@@ -23,9 +23,10 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "aws-cdk-lib": "^2.236.0",
27
- "constructs": "^10.4.5",
28
- "@beesolve/helpers": "0.1.1"
26
+ "@beesolve/helpers": "workspace:*",
27
+ "aws-cdk-lib": "catalog:",
28
+ "constructs": "catalog:",
29
+ "esbuild": "^0.27.3"
29
30
  },
30
31
  "type": "module",
31
32
  "exports": {