@digitraffic/common 2025.6.27-2 → 2025.7.30-1

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.
@@ -8,11 +8,6 @@ describe("logging-test", () => {
8
8
  logException(logger, error, includeStack);
9
9
  }, expected);
10
10
  }
11
- function assertAxiosError(error, expected) {
12
- assertWrite((logger) => {
13
- logException(logger, error);
14
- }, expected);
15
- }
16
11
  function assertWrite(writeFunction, expected) {
17
12
  const logged = [];
18
13
  const writeStream = new Writable({
@@ -63,16 +58,5 @@ describe("logging-test", () => {
63
58
  stack: true,
64
59
  }, true);
65
60
  });
66
- test("log error - AxiosError", () => {
67
- const ERROR = new Error("ErrorFromAxios");
68
- ERROR.code = "12";
69
- assertAxiosError(ERROR, {
70
- type: "Error",
71
- method: TEST_METHODNAME,
72
- message: `${TEST_METHODNAME} error=${ERROR.message} type=Error code=12`,
73
- level: "ERROR",
74
- code: ERROR.code,
75
- });
76
- });
77
61
  });
78
62
  //# sourceMappingURL=logging.test.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
@@ -18,10 +18,8 @@ export declare function createExceptionLogger(logger?: DtLogger | undefined, inc
18
18
  /**
19
19
  * Log given exception with level ERROR to given logger.
20
20
  *
21
- * Supports AxiosError, Error and string
22
- *
23
21
  * @param logger - DtLogger to use
24
- * @param error - AxiosError, Error or string to log
22
+ * @param error - Error or string to log
25
23
  * @param [includeStack=true] - Include stack in the message, default false
26
24
  * @returns Logs the error without rethrowing
27
25
  * @see {@link DtLogger.log}
@@ -31,10 +31,8 @@ export function createExceptionLogger(logger = undefined, includeStack = false)
31
31
  /**
32
32
  * Log given exception with level ERROR to given logger.
33
33
  *
34
- * Supports AxiosError, Error and string
35
- *
36
34
  * @param logger - DtLogger to use
37
- * @param error - AxiosError, Error or string to log
35
+ * @param error - Error or string to log
38
36
  * @param [includeStack=true] - Include stack in the message, default false
39
37
  * @returns Logs the error without rethrowing
40
38
  * @see {@link DtLogger.log}
@@ -49,25 +47,11 @@ export function logException(logger, error, includeStack = false) {
49
47
  const stack = error instanceof Error && includeStack
50
48
  ? error.stack
51
49
  : undefined;
52
- // In case error is AxiosError, log the custom code property.
53
- // eslint-disable-next-line dot-notation
54
- const customCode = error["code"];
55
- if (customCode) {
56
- logger.error({
57
- type: "Error",
58
- method: `${functionName}.logException`,
59
- message: `error=${message}`,
60
- customCode,
61
- stack,
62
- });
63
- }
64
- else {
65
- logger.error({
66
- type: "Error",
67
- method: `${functionName}.logException`,
68
- message: `error=${message}`,
69
- stack,
70
- });
71
- }
50
+ logger.error({
51
+ type: "Error",
52
+ method: `${functionName}.logException`,
53
+ message: `error=${message}`,
54
+ stack,
55
+ });
72
56
  }
73
57
  //# sourceMappingURL=logging.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2025.6.27-2",
3
+ "version": "2025.7.30-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {