@payfit/audit-log 3.16.4 → 3.17.0

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/README.md CHANGED
@@ -52,10 +52,10 @@ The SDK's transport is maintained TypeScript code. It publishes records to SQS a
52
52
  To build it, simply run
53
53
 
54
54
  ```sh
55
- npm run build
55
+ corepack yarn nx run sdk:build
56
56
  ```
57
57
 
58
- from the sdk folder (where the `package.json` is located).
58
+ from the repository root (where the workspace `package.json` is located).
59
59
 
60
60
  ### Testing
61
61
 
@@ -67,25 +67,8 @@ Could it be for testing some changes you made, or just to discover how to use th
67
67
 
68
68
  It uses the current code in the repository, not the published one, so you don't have to `npm publish` or `npm link` to make it work 🙂
69
69
 
70
- To run it, simply run from the `sdk` folder:
70
+ To run it, run from the repository root:
71
71
 
72
72
  ```sh
73
- npm run start:playground
73
+ corepack yarn workspace @payfit/audit-log start:playground
74
74
  ```
75
-
76
- ### Publishing
77
-
78
- For now, there is no automated publishing from CI, so you have to publish it manually.
79
-
80
- To do so, simply bump the `version` field in the `package.json` file, and run
81
-
82
- ```
83
- npm publish
84
- ```
85
-
86
- ## Code organisation
87
-
88
- The code is mainly split into 2 parts:
89
-
90
- - The transport part, whose only goal is to tell how to communicate with SQS, i.e. it abstracts the delivery layer.
91
- - The logic part, which tells how to build an audit log.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var w=(s,e,t)=>e in s?f(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>(w(s,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("uuid"),o=require("winston"),S=require("hot-shots"),h=require("@aws-sdk/client-sqs"),y=require("zlib"),E="audit-logs",_="@payfit/audit-log",q=()=>{const s=process.env.LOG_LEVEL;return s&&s.trim()!==""?s.trim():"info"},L=(s,e)=>o.createLogger({level:q(),silent:process.env.NODE_ENV==="test",exitOnError:!1,defaultMeta:{namespace:E,sdk:_,service:s,environment:e},format:o.format.combine(o.format.timestamp(),o.format.errors({stack:!0}),o.format.json()),transports:[new o.transports.Console]}),M="payfit.audit_logs.",p=s=>Object.entries(s).filter(([,e])=>e!==void 0&&e!=="").map(([e,t])=>`${e}:${String(t)}`);class b{constructor(){i(this,"client");this.client=new S.StatsD({prefix:M,errorHandler:()=>{},cacheDns:!0})}increment(e,t){this.client.increment(e,1,p(t))}histogram(e,t,n){this.client.histogram(e,t,p(n))}async close(){await new Promise(e=>{this.client.close(()=>e())})}}const A=()=>new b;function U(s){return y.brotliCompressSync(Buffer.from(s,"utf8")).toString("base64")}function C(s){return s instanceof Error&&s.message.includes("Message must be shorter than")}const O="eu-west-3",z={dev:"https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",staging:"https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",prod:"https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"},D={working:"staging",production:"prod",development:"dev"};class N{constructor(e,t){i(this,"environment");i(this,"logger");i(this,"client");i(this,"queueUrl");this.environment=e,this.logger=t;const n=D[e]??e;if(this.queueUrl=z[n],!this.queueUrl){t==null||t.warn("audit-logs SDK: no SQS queue URL configured for this environment, audit logs are disabled",{environment:e});return}this.client=new h.SQSClient({region:O})}async create(e){var n;if(!this.client||!this.queueUrl)return{compressed:!1};const t=JSON.stringify(e);try{return await this.send(t),{compressed:!1}}catch(c){if(!C(c))throw c;return(n=this.logger)==null||n.info("audit-log payload exceeds the SQS size limit, retrying with Brotli compression",{id:e.id,namespace:e.namespace}),await this.send(U(t)),{compressed:!0}}}async send(e){await this.client.send(new h.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:e}))}}class Q{constructor(e,t={}){i(this,"params");i(this,"transport");i(this,"logger");i(this,"metrics");this.params=e,this.logger=t.logger??L(e.service,e.environment),this.transport=t.transport??new N(e.environment,this.logger),this.metrics=t.metrics??A()}async log({scope:e,account:t,...n}){const c=v.v4(),{environment:g,service:u}=this.params,r={...n,...t,service:u,id:c,environment:g,...e&&{scope:e}},a={service:u,environment:g,namespace:r.namespace,event:r.event,target:r.target},m=Date.now();try{const{compressed:l}=await this.transport.create(r);this.metrics.increment("sent",{...a,compressed:String(l)}),this.metrics.histogram("send_duration_ms",Date.now()-m,a),this.logger.debug("audit-log sent",{id:r.id,event:r.event,target:r.target})}catch(l){this.metrics.increment("send_failed",a),this.metrics.histogram("send_duration_ms",Date.now()-m,a);const d=l.message;try{this.logger.error("audit-log write failed",{audit_log:r,error:d})}catch{this.metrics.increment("serialization_failed",a);try{this.logger.error("audit-log write failed (serialization failed)",{audit_log_meta:{id:r.id,service:r.service,environment:r.environment,namespace:r.namespace,event:r.event,target:r.target},error:d})}catch{}}}}}exports.AuditLogger=Q;
1
+ "use strict";var f=Object.defineProperty;var w=(s,e,t)=>e in s?f(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>w(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("uuid"),o=require("winston"),S=require("hot-shots"),h=require("@aws-sdk/client-sqs"),y=require("zlib"),E="audit-logs",_="@payfit/audit-log",q=()=>{const s=process.env.LOG_LEVEL;return s&&s.trim()!==""?s.trim():"info"},L=(s,e)=>o.createLogger({level:q(),silent:process.env.NODE_ENV==="test",exitOnError:!1,defaultMeta:{namespace:E,sdk:_,service:s,environment:e},format:o.format.combine(o.format.timestamp(),o.format.errors({stack:!0}),o.format.json()),transports:[new o.transports.Console]}),M="payfit.audit_logs.",p=s=>Object.entries(s).filter(([,e])=>e!==void 0&&e!=="").map(([e,t])=>`${e}:${String(t)}`);class b{constructor(){i(this,"client");this.client=new S.StatsD({prefix:M,errorHandler:()=>{},cacheDns:!0})}increment(e,t){this.client.increment(e,1,p(t))}histogram(e,t,n){this.client.histogram(e,t,p(n))}async close(){await new Promise(e=>{this.client.close(()=>e())})}}const A=()=>new b;function U(s){return y.brotliCompressSync(Buffer.from(s,"utf8")).toString("base64")}function C(s){return s instanceof Error&&s.message.includes("Message must be shorter than")}const O="eu-west-3",z={dev:"https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",staging:"https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",prod:"https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"},D={working:"staging",production:"prod",development:"dev"};class N{constructor(e,t){i(this,"environment");i(this,"logger");i(this,"client");i(this,"queueUrl");this.environment=e,this.logger=t;const n=D[e]??e;if(this.queueUrl=z[n],!this.queueUrl){t==null||t.warn("audit-logs SDK: no SQS queue URL configured for this environment, audit logs are disabled",{environment:e});return}this.client=new h.SQSClient({region:O})}async create(e){var n;if(!this.client||!this.queueUrl)return{compressed:!1};const t=JSON.stringify(e);try{return await this.send(t),{compressed:!1}}catch(c){if(!C(c))throw c;return(n=this.logger)==null||n.info("audit-log payload exceeds the SQS size limit, retrying with Brotli compression",{id:e.id,namespace:e.namespace}),await this.send(U(t)),{compressed:!0}}}async send(e){await this.client.send(new h.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:e}))}}class Q{constructor(e,t={}){i(this,"params");i(this,"transport");i(this,"logger");i(this,"metrics");this.params=e,this.logger=t.logger??L(e.service,e.environment),this.transport=t.transport??new N(e.environment,this.logger),this.metrics=t.metrics??A()}async log({scope:e,account:t,...n}){const c=v.v4(),{environment:g,service:u}=this.params,r={...n,...t,service:u,id:c,environment:g,...e&&{scope:e}},a={service:u,environment:g,namespace:r.namespace,event:r.event,target:r.target},m=Date.now();try{const{compressed:l}=await this.transport.create(r);this.metrics.increment("sent",{...a,compressed:String(l)}),this.metrics.histogram("send_duration_ms",Date.now()-m,a),this.logger.debug("audit-log sent",{id:r.id,event:r.event,target:r.target})}catch(l){this.metrics.increment("send_failed",a),this.metrics.histogram("send_duration_ms",Date.now()-m,a);const d=l.message;try{this.logger.error("audit-log write failed",{audit_log:r,error:d})}catch{this.metrics.increment("serialization_failed",a);try{this.logger.error("audit-log write failed (serialization failed)",{audit_log_meta:{id:r.id,service:r.service,environment:r.environment,namespace:r.namespace,event:r.event,target:r.target},error:d})}catch{}}}}}exports.AuditLogger=Q;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  var p = Object.defineProperty;
2
2
  var f = (s, e, t) => e in s ? p(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var i = (s, e, t) => (f(s, typeof e != "symbol" ? e + "" : e, t), t);
3
+ var i = (s, e, t) => f(s, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { v4 as w } from "uuid";
5
- import { createLogger as v, format as c, transports as S } from "winston";
5
+ import { createLogger as v, transports as S, format as c } from "winston";
6
6
  import { StatsD as E } from "hot-shots";
7
7
  import { SQSClient as _, SendMessageCommand as y } from "@aws-sdk/client-sqs";
8
8
  import { brotliCompressSync as L } from "zlib";
package/package.json CHANGED
@@ -1,25 +1,24 @@
1
1
  {
2
2
  "name": "@payfit/audit-log",
3
- "version": "3.16.4",
3
+ "version": "3.17.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/PayFit/audit-logs.git",
7
- "directory": "sdk"
7
+ "directory": "packages/sdk"
8
8
  },
9
9
  "description": "Library to handle audit logs at Payfit",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.mjs",
12
12
  "types": "dist/index.d.ts",
13
13
  "scripts": {
14
- "build": "rimraf dist && vite build",
14
+ "build": "rimraf dist && vite build && tsc --build tsconfig.app.json --emitDeclarationOnly --force",
15
15
  "prepack": "npm run build",
16
- "lint": "eslint .",
16
+ "lint": "ESLINT_USE_FLAT_CONFIG=true eslint .",
17
17
  "test": "vitest run",
18
18
  "test:watch": "vitest",
19
19
  "start:playground": "ts-node src/playground.ts",
20
20
  "format:check": "prettier --check .",
21
- "format:fix": "prettier --write .",
22
- "release": "semantic-release --noCi"
21
+ "format:fix": "prettier --write ."
23
22
  },
24
23
  "author": "",
25
24
  "license": "ISC",
@@ -31,9 +30,7 @@
31
30
  "winston": "^3.13.0"
32
31
  },
33
32
  "devDependencies": {
34
- "@payfit/browserslist-config": "1.1.1",
35
33
  "@payfit/eslint-config-node": "1.1.0",
36
- "@payfit/semantic-release-package-config": "6.13.0",
37
34
  "@rollup/plugin-typescript": "11.1.5",
38
35
  "@tsconfig/node18": "18.2.2",
39
36
  "@tsconfig/strictest": "2.0.2",
@@ -41,21 +38,21 @@
41
38
  "@types/node": "20.10.6",
42
39
  "@types/uuid": "9.0.7",
43
40
  "@typescript-eslint/eslint-plugin": "6.17.0",
41
+ "@typescript-eslint/parser": "6.17.0",
44
42
  "builtin-modules": "3.3.0",
45
43
  "eslint": "8.56.0",
46
44
  "prettier": "3.1.1",
47
45
  "rimraf": "5.0.5",
48
- "semantic-release": "22.0.12",
49
46
  "ts-node": "10.9.2",
50
47
  "typescript": "5.3.3",
51
- "vite": "4.5.1",
48
+ "vite": "^6.0.0",
52
49
  "vitest": "4.1.4"
53
50
  },
54
51
  "publishConfig": {
55
- "registry": "https://registry.npmjs.org/"
52
+ "registry": "https://registry.npmjs.org/",
53
+ "access": "public"
56
54
  },
57
55
  "files": [
58
56
  "dist"
59
- ],
60
- "packageManager": "yarn@4.14.1+sha512.64df448055b2d37ba269d7db535a469b8da93f8ef1140c25fd7a83c00a8fbaacb214ca0e02553b92a2c54cef78bb67d0b4817fab02001df0e24fac0faccc3b42"
57
+ ]
61
58
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};