stellate 2.8.2 → 2.9.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.
@@ -1 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var H=(e,r)=>{for(var t in r)f(e,t,{get:r[t],enumerable:!0})},A=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of P(r))!x.call(e,o)&&o!==t&&f(e,o,{get:()=>r[o],enumerable:!(n=w(r,o))||n.enumerable});return e};var L=e=>A(f({},"__esModule",{value:!0}),e);var T={};H(T,{createBlake3Hash:()=>c,createStellateLoggerPlugin:()=>q});module.exports=L(T);function c(e){let r=0,t=e.length;if(t===0)return r;for(let n=0;n<t;++n){let o=e.charCodeAt(n);r=(r<<5)-r+o,r&=r}return r>>>0}function m({headers:e,operation:r,method:t,start:n,operationName:o,errors:p,response:i,variables:l,sendVariablesAsHash:s,hasSetCookie:u}){let a=e.get("x-forwarded-for"),d=a?a.split(","):[];return{operation:r,operationName:o,variables:s?void 0:l,variableHash:s?c(JSON.stringify(l||{})):void 0,method:t,elapsed:Date.now()-n,ip:d[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:u,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:p,responseSize:JSON.stringify(i).length,responseHash:c(JSON.stringify(i))}}function b(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var O=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function S({fetch:e,payload:r,token:t,serviceName:n}){return e(`https://${n}.${O}/log`,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json","Stellate-Logging-Token":t}})}var q=e=>{var t;let r=(t=e.sendVariablesAsHash)!=null?t:!0;return{async requestDidStart(n){let o=Date.now(),{request:p}=n,{operationName:i,variables:l,http:s,query:u}=p;if(!s)return;let{headers:a,method:d}=s;if(!a.has("gcdn-request-id"))return{async willSendResponse(h){let{response:g,source:v}=h;if(g.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let k=g.body.singleResult,y=u||v;if(!y)return;let N=m({headers:a,operation:y,method:d,sendVariablesAsHash:r,start:o,operationName:i,errors:h.errors,response:k,variables:l,hasSetCookie:g.http.headers.has("set-cookie")});b(e.fetch);try{await S({fetch:e.fetch,payload:N,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
1
+ "use strict";var v=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var L=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},A=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of N(r))!x.call(e,o)&&o!==t&&v(e,o,{get:()=>r[o],enumerable:!(n=w(r,o))||n.enumerable});return e};var O=e=>A(v({},"__esModule",{value:!0}),e);var E={};L(E,{createBlake3Hash:()=>l,createStellateLoggerPlugin:()=>T});module.exports=O(E);function l(e){let r=0,t=e.length;if(t===0)return r;for(let n=0;n<t;++n){let o=e.charCodeAt(n);r=(r<<5)-r+o,r&=r}return r>>>0}function k({headers:e,operation:r,method:t,start:n,operationName:o,errors:m,response:c,variables:d,responseHeaders:i,sendVariablesAsHash:u,hasSetCookie:p}){let g=e.get("x-forwarded-for"),f=g?g.split(","):[],s=i&&i.get("vary"),h;if(s&&s.length){let y=s.split(",").map(a=>a&&a.trim()).sort().map(a=>{let b=a&&e.get(a);return b?`${a}:${b}`:void 0}).filter(Boolean).join(`
2
+ `);h=l(y)}return{operation:r,operationName:o,variables:u?void 0:d,variableHash:u?l(JSON.stringify(d||{})):void 0,method:t,elapsed:Date.now()-n,ip:f[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:p,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:m,responseSize:JSON.stringify(c).length,responseHash:l(JSON.stringify(c)),varyHash:h}}function H(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var q=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function P({fetch:e,payload:r,token:t,serviceName:n}){return e(`https://${n}.${q}/log`,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json","Stellate-Logging-Token":t}})}var T=e=>{var t;let r=(t=e.sendVariablesAsHash)!=null?t:!0;return{async requestDidStart(n){let o=Date.now(),{request:m}=n,{operationName:c,variables:d,http:i,query:u}=m;if(!i)return;let{headers:p,method:g}=i;if(!p.has("gcdn-request-id"))return{async willSendResponse(f){let{response:s,source:h}=f;if(s.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let S=s.body.singleResult,y=u||h;if(!y)return;let a=k({headers:p,responseHeaders:s.http.headers,operation:y,method:g,sendVariablesAsHash:r,start:o,operationName:c,errors:f.errors,response:S,variables:d,hasSetCookie:s.http.headers.has("set-cookie")});H(e.fetch);try{await P({fetch:e.fetch,payload:a,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
@@ -21,11 +21,22 @@ function extractStellatePayload({
21
21
  errors,
22
22
  response,
23
23
  variables,
24
+ responseHeaders,
24
25
  sendVariablesAsHash,
25
26
  hasSetCookie
26
27
  }) {
27
28
  const forwardedFor = headers.get("x-forwarded-for");
28
29
  const ips = forwardedFor ? forwardedFor.split(",") : [];
30
+ const vary = responseHeaders && responseHeaders.get("vary");
31
+ let varyHash = void 0;
32
+ if (vary && vary.length) {
33
+ const varyHeaders = vary.split(",").map((headerName) => headerName && headerName.trim()).sort();
34
+ const variedValues = varyHeaders.map((headerName) => {
35
+ const headerValue = headerName && headers.get(headerName);
36
+ return headerValue ? `${headerName}:${headerValue}` : void 0;
37
+ }).filter(Boolean).join("\n");
38
+ varyHash = createBlake3Hash(variedValues);
39
+ }
29
40
  return {
30
41
  operation,
31
42
  operationName,
@@ -40,7 +51,8 @@ function extractStellatePayload({
40
51
  statusCode: 200,
41
52
  errors,
42
53
  responseSize: JSON.stringify(response).length,
43
- responseHash: createBlake3Hash(JSON.stringify(response))
54
+ responseHash: createBlake3Hash(JSON.stringify(response)),
55
+ varyHash
44
56
  };
45
57
  }
46
58
  function warnFetch(fetch) {
@@ -97,6 +109,7 @@ var createStellateLoggerPlugin = (options) => {
97
109
  return;
98
110
  const stellatePayload = extractStellatePayload({
99
111
  headers,
112
+ responseHeaders: response.http.headers,
100
113
  operation: queryString,
101
114
  method,
102
115
  sendVariablesAsHash,