@payfit/audit-log 3.7.0 → 3.8.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/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var m=(r,e,t)=>e in r?d(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(m(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("uuid"),i=require("@aws-sdk/client-sqs"),h="eu-west-3",p={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"};class S{constructor(e){n(this,"environment");n(this,"client");n(this,"queueUrl");this.environment=e;const t=p[e];if(!t)throw new Error(`audit-logs SDK: no SQS queue URL configured for environment "${e}"`);this.queueUrl=t,this.client=new i.SQSClient({region:h})}async create(e){await this.client.send(new i.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:JSON.stringify(e)}))}}class v{constructor(e){n(this,"params");n(this,"transport");this.params=e,this.transport=new S(e.environment)}async log({scope:e,account:t,...o}){const u=w.v4(),{environment:c,service:g}=this.params,s={...o,...t,service:g,id:u,environment:c,...e&&{scope:e}};try{await this.transport.create(s)}catch(l){const a=l.message;try{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed",audit_log:s,error:a}))}catch{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed (serialization failed)",audit_log_meta:{id:s.id,service:s.service,environment:s.environment,namespace:s.namespace,event:s.event,target:s.target},error:a}))}}}}exports.AuditLogger=v;
1
+ "use strict";var d=Object.defineProperty;var m=(r,e,t)=>e in r?d(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(m(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("uuid"),i=require("@aws-sdk/client-sqs"),p="eu-west-3",S={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"},h={working:"staging",production:"prod"};class v{constructor(e){n(this,"environment");n(this,"client");n(this,"queueUrl");this.environment=e;const t=h[e]??e,o=S[t];if(!o)throw new Error(`audit-logs SDK: no SQS queue URL configured for environment "${e}"`);this.queueUrl=o,this.client=new i.SQSClient({region:p})}async create(e){await this.client.send(new i.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:JSON.stringify(e)}))}}class q{constructor(e){n(this,"params");n(this,"transport");this.params=e,this.transport=new v(e.environment)}async log({scope:e,account:t,...o}){const c=w.v4(),{environment:u,service:g}=this.params,s={...o,...t,service:g,id:c,environment:u,...e&&{scope:e}};try{await this.transport.create(s)}catch(l){const a=l.message;try{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed",audit_log:s,error:a}))}catch{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed (serialization failed)",audit_log_meta:{id:s.id,service:s.service,environment:s.environment,namespace:s.namespace,event:s.event,target:s.target},error:a}))}}}}exports.AuditLogger=q;
package/dist/index.mjs CHANGED
@@ -1,23 +1,26 @@
1
1
  var l = Object.defineProperty;
2
- var m = (r, e, t) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var a = (r, e, t) => (m(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { v4 as d } from "uuid";
2
+ var d = (r, e, t) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var o = (r, e, t) => (d(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { v4 as m } from "uuid";
5
5
  import { SQSClient as p, SendMessageCommand as w } from "@aws-sdk/client-sqs";
6
- const h = "eu-west-3", v = {
6
+ const h = "eu-west-3", S = {
7
7
  dev: "https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",
8
8
  staging: "https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",
9
9
  prod: "https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"
10
+ }, v = {
11
+ working: "staging",
12
+ production: "prod"
10
13
  };
11
14
  class f {
12
15
  constructor(e) {
13
- a(this, "environment");
14
- a(this, "client");
15
- a(this, "queueUrl");
16
+ o(this, "environment");
17
+ o(this, "client");
18
+ o(this, "queueUrl");
16
19
  this.environment = e;
17
- const t = v[e];
18
- if (!t)
20
+ const t = v[e] ?? e, a = S[t];
21
+ if (!a)
19
22
  throw new Error(`audit-logs SDK: no SQS queue URL configured for environment "${e}"`);
20
- this.queueUrl = t, this.client = new p({ region: h });
23
+ this.queueUrl = a, this.client = new p({ region: h });
21
24
  }
22
25
  async create(e) {
23
26
  await this.client.send(new w({
@@ -26,32 +29,32 @@ class f {
26
29
  }));
27
30
  }
28
31
  }
29
- class y {
32
+ class E {
30
33
  constructor(e) {
31
- a(this, "params");
32
- a(this, "transport");
34
+ o(this, "params");
35
+ o(this, "transport");
33
36
  this.params = e, this.transport = new f(e.environment);
34
37
  }
35
- async log({ scope: e, account: t, ...n }) {
36
- const i = d(), { environment: c, service: u } = this.params, s = {
37
- ...n,
38
+ async log({ scope: e, account: t, ...a }) {
39
+ const i = m(), { environment: c, service: g } = this.params, s = {
40
+ ...a,
38
41
  ...t,
39
- service: u,
42
+ service: g,
40
43
  id: i,
41
44
  environment: c,
42
45
  ...e && { scope: e }
43
46
  };
44
47
  try {
45
48
  await this.transport.create(s);
46
- } catch (g) {
47
- const o = g.message;
49
+ } catch (u) {
50
+ const n = u.message;
48
51
  try {
49
52
  console.error(JSON.stringify({
50
53
  status: "error",
51
54
  namespace: "audit-logs",
52
55
  message: "audit-log write failed",
53
56
  audit_log: s,
54
- error: o
57
+ error: n
55
58
  }));
56
59
  } catch {
57
60
  console.error(JSON.stringify({
@@ -66,12 +69,12 @@ class y {
66
69
  event: s.event,
67
70
  target: s.target
68
71
  },
69
- error: o
72
+ error: n
70
73
  }));
71
74
  }
72
75
  }
73
76
  }
74
77
  }
75
78
  export {
76
- y as AuditLogger
79
+ E as AuditLogger
77
80
  };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payfit/audit-log",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/PayFit/audit-logs.git",