stellate 2.11.1 → 2.12.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,2 +1,2 @@
1
- "use strict";var b=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of q(t))!E.call(e,r)&&r!==n&&b(e,r,{get:()=>t[r],enumerable:!(o=A(t,r))||o.enumerable});return e};var R=e=>D(b({},"__esModule",{value:!0}),e);var J={};C(J,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>$});module.exports=R(J);function g(e){let t=0,n=e.length;if(n===0)return t;for(let o=0;o<n;++o){let r=e.charCodeAt(o);t=(t<<5)-t+r,t&=t}return t>>>0}function T({headers:e,operation:t,method:n,start:o,operationName:r,errors:m,response:d,variables:u,responseHeaders:s,sendVariablesAsHash:l,hasSetCookie:p}){let h=e.get("x-forwarded-for"),y=h?h.split(","):[],c=s&&s.get("vary"),f;if(c&&c.length){let v=c.split(",").map(a=>a&&a.trim()).sort().map(a=>{let i=a&&e.get(a);return i?`${a}:${i}`:void 0}).filter(Boolean).join(`
2
- `);f=g(v)}return{operation:t,operationName:r,variables:l?void 0:u,variableHash:l?g(JSON.stringify(u||{})):void 0,method:n,elapsed:Date.now()-o,ip:y[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(d).length,responseHash:g(JSON.stringify(d)),varyHash:f}}function P(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var k=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function L({fetch:e,payload:t,token:n,serviceName:o}){return e(`https://${o}.${k}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var N=require("graphql");var $=e=>{var d,u;let t=(d=e.sendVariablesAsHash)!=null?d:!0,n=(u=e.schemaSyncing)!=null?u:!0,o=!1,r,m=async s=>{if(n){let l=(0,N.introspectionFromSchema)(s),p=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{if(r=null,!o)try{e.fetch(`https://${e.serviceName}.${k}/schema`,{method:"POST",body:JSON.stringify({schema:l}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},p)}};return{async serverWillStart(){return{schemaDidLoadOrUpdate({apiSchema:s}){m(s)},async serverWillStop(){o=!0,r&&clearTimeout(r)}}},async requestDidStart(s){let l=Date.now(),{request:p}=s,{operationName:h,variables:y,http:c,query:f}=p;if(!c)return;let{headers:S,method:v}=c;if(!S.has("gcdn-request-id"))return{async willSendResponse(a){let{response:i,source:w}=a;if(i.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let O=i.body.singleResult,H=f||w;if(!H)return;let x=T({headers:S,responseHeaders:i.http.headers,operation:H,method:v,sendVariablesAsHash:t,start:l,operationName:h,errors:a.errors,response:O,variables:y,hasSetCookie:i.http.headers.has("set-cookie")});P(e.fetch);try{await L({fetch:e.fetch,payload:x,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
1
+ "use strict";var q=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of D(t))!R.call(e,r)&&r!==n&&q(e,r,{get:()=>t[r],enumerable:!(a=V(t,r))||a.enumerable});return e};var B=e=>J(q({},"__esModule",{value:!0}),e);var G={};$(G,{createBlake3Hash:()=>h,createStellateLoggerPlugin:()=>F});module.exports=B(G);function h(e){let t=0,n=e.length;if(n===0)return t;for(let a=0;a<n;++a){let r=e.charCodeAt(a);t=(t<<5)-t+r,t&=t}return t>>>0}function x({headers:e,operation:t,method:n,start:a,operationName:r,errors:S,response:p,variables:u,responseHeaders:s,sendVariablesAsHash:l,hasSetCookie:i,graphqlClientName:f,graphqlClientVersion:v}){let g=e.get("x-forwarded-for"),b=g?g.split(","):[],c=s&&s.get("vary"),m;if(c&&c.length){let d=c.split(",").map(o=>o&&o.trim()).sort().map(o=>{let y=o&&e.get(o);return y?`${o}:${y}`:void 0}).filter(Boolean).join(`
2
+ `);m=h(d)}return{graphqlClientName:f,graphqlClientVersion:v,operation:t,operationName:r,variables:l?void 0:u,variableHash:l?h(JSON.stringify(u||{})):void 0,method:n,elapsed:Date.now()-a,ip:b[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:i,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:S,responseSize:JSON.stringify(p).length,responseHash:h(JSON.stringify(p)),varyHash:m}}function L(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var H=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function w({fetch:e,payload:t,token:n,serviceName:a}){return e(`https://${a}.${H}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var C=require("graphql");var F=e=>{var p,u;let t=(p=e.sendVariablesAsHash)!=null?p:!0,n=(u=e.schemaSyncing)!=null?u:!0,a=!1,r,S=async s=>{if(n){let l=(0,C.introspectionFromSchema)(s),i=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{if(r=null,!a)try{e.fetch(`https://${e.serviceName}.${H}/schema`,{method:"POST",body:JSON.stringify({schema:l}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},i)}};return{async serverWillStart(){return{schemaDidLoadOrUpdate({apiSchema:s}){S(s)},async serverWillStop(){a=!0,r&&clearTimeout(r)}}},async requestDidStart(s){let l=Date.now(),{request:i}=s,{operationName:f,variables:v,http:g,query:b}=i;if(!g)return;let{headers:c,method:m}=g;if(!c.has("gcdn-request-id"))return{async willSendResponse(k){var T,P;let{response:d,source:o}=k;if(d.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let y=d.body.singleResult,N=b||o;if(!N)return;let O=((T=i.http)==null?void 0:T.headers.get("x-graphql-client-name"))||void 0,A=((P=i.http)==null?void 0:P.headers.get("x-graphql-client-version"))||void 0,E=x({headers:c,responseHeaders:d.http.headers,operation:N,method:m,sendVariablesAsHash:t,start:l,operationName:f,errors:k.errors,response:y,variables:v,hasSetCookie:d.http.headers.has("set-cookie"),graphqlClientName:O,graphqlClientVersion:A});L(e.fetch);try{await w({fetch:e.fetch,payload:E,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
@@ -23,7 +23,9 @@ function extractStellatePayload({
23
23
  variables,
24
24
  responseHeaders,
25
25
  sendVariablesAsHash,
26
- hasSetCookie
26
+ hasSetCookie,
27
+ graphqlClientName,
28
+ graphqlClientVersion
27
29
  }) {
28
30
  const forwardedFor = headers.get("x-forwarded-for");
29
31
  const ips = forwardedFor ? forwardedFor.split(",") : [];
@@ -38,6 +40,8 @@ function extractStellatePayload({
38
40
  varyHash = createBlake3Hash(variedValues);
39
41
  }
40
42
  return {
43
+ graphqlClientName,
44
+ graphqlClientVersion,
41
45
  operation,
42
46
  operationName,
43
47
  variables: sendVariablesAsHash ? void 0 : variables,
@@ -139,6 +143,7 @@ var createStellateLoggerPlugin = (options) => {
139
143
  return;
140
144
  return {
141
145
  async willSendResponse(respContext) {
146
+ var _a2, _b2;
142
147
  const { response, source } = respContext;
143
148
  if (response.body.kind !== "single") {
144
149
  console.warn(
@@ -150,6 +155,8 @@ var createStellateLoggerPlugin = (options) => {
150
155
  const queryString = query || source;
151
156
  if (!queryString)
152
157
  return;
158
+ const graphqlClientName = ((_a2 = request.http) == null ? void 0 : _a2.headers.get("x-graphql-client-name")) || void 0;
159
+ const graphqlClientVersion = ((_b2 = request.http) == null ? void 0 : _b2.headers.get("x-graphql-client-version")) || void 0;
153
160
  const stellatePayload = extractStellatePayload({
154
161
  headers,
155
162
  responseHeaders: response.http.headers,
@@ -161,7 +168,9 @@ var createStellateLoggerPlugin = (options) => {
161
168
  errors: respContext.errors,
162
169
  response: respBody,
163
170
  variables,
164
- hasSetCookie: response.http.headers.has("set-cookie")
171
+ hasSetCookie: response.http.headers.has("set-cookie"),
172
+ graphqlClientName,
173
+ graphqlClientVersion
165
174
  });
166
175
  warnFetch(options.fetch);
167
176
  try {
package/dist/bin.js CHANGED
@@ -1094,7 +1094,7 @@ Try running "stellate pull" first if your service has been created already.`);le
1094
1094
 
1095
1095
  -s, --service Name of the service
1096
1096
  -b, --browser Automatically open the preview UI with the default browser
1097
- `);var hs=De(sn());var rv=De(sn());var mD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.11.1"}help(e){if(e)throw new pn(`
1097
+ `);var hs=De(sn());var rv=De(sn());var mD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.12.0"}help(e){if(e)throw new pn(`
1098
1098
  ${rv.default.bold.red("!")} ${e}
1099
1099
  ${mD.help}`);return mD.help}},d1=mD;d1.help=Mi(`
1100
1100
  Print current version of Stellate
@@ -1392,7 +1392,7 @@ Try running "stellate pull" first if your service has been created already.`);le
1392
1392
  value
1393
1393
  }
1394
1394
  }
1395
- `,u=await Cn();a=(await new Xi(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,dJ.default)();o.use("/",(0,fJ.createProxyMiddleware)({target:s,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,n=(0,dJ.default)();n.use("/",(0,fJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Ih.default.existsSync(ic)||Ih.default.mkdirSync(ic)}getCache(){try{this.ensureConfig();let e=Ih.default.readFileSync(TS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Ih.default.readFileSync(TS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return $fr(JSON.stringify(e)+"2.11.1")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},Ih.default.writeFileSync(TS,JSON.stringify(i))}writeCache(e,r,i){let n=this.getCache();if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return n[e]={checksum:this.getChecksum(r),envName:i},Ih.default.writeFileSync(TS,JSON.stringify(n)),n[e]}},tw=hJ;tw.help=Mi(`
1395
+ `,u=await Cn();a=(await new Xi(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,dJ.default)();o.use("/",(0,fJ.createProxyMiddleware)({target:s,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,n=(0,dJ.default)();n.use("/",(0,fJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Ih.default.existsSync(ic)||Ih.default.mkdirSync(ic)}getCache(){try{this.ensureConfig();let e=Ih.default.readFileSync(TS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Ih.default.readFileSync(TS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return $fr(JSON.stringify(e)+"2.12.0")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},Ih.default.writeFileSync(TS,JSON.stringify(i))}writeCache(e,r,i){let n=this.getCache();if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return n[e]={checksum:this.getChecksum(r),envName:i},Ih.default.writeFileSync(TS,JSON.stringify(n)),n[e]}},tw=hJ;tw.help=Mi(`
1396
1396
  (BETA) - Use a local backend with Stellate\u2019s GraphQL Edge Cache.
1397
1397
 
1398
1398
  ${yv.default.bold("Usage")}
package/dist/envelop.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!O.call(e,o)&&o!==r&&m(e,o,{get:()=>t[o],enumerable:!(n=P(t,o))||n.enumerable});return e};var q=e=>E(m({},"__esModule",{value:!0}),e);var R={};C(R,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>A});module.exports=q(R);var h=require("graphql"),L=require("@envelop/core");function g(e){let t=0,r=e.length;if(r===0)return t;for(let n=0;n<r;++n){let o=e.charCodeAt(n);t=(t<<5)-t+o,t&=t}return t>>>0}function w({headers:e,operation:t,method:r,start:n,operationName:o,errors:u,response:i,variables:a,responseHeaders:c,sendVariablesAsHash:s,hasSetCookie:p}){let d=e.get("x-forwarded-for"),b=d?d.split(","):[],f=c&&c.get("vary"),v;if(f&&f.length){let N=f.split(",").map(l=>l&&l.trim()).sort().map(l=>{let k=l&&e.get(l);return k?`${l}:${k}`:void 0}).filter(Boolean).join(`
2
- `);v=g(N)}return{operation:t,operationName:o,variables:s?void 0:a,variableHash:s?g(JSON.stringify(a||{})):void 0,method:r,elapsed:Date.now()-n,ip:b[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:u,responseSize:JSON.stringify(i).length,responseHash:g(JSON.stringify(i)),varyHash:v}}function x(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var y=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function H({fetch:e,payload:t,token:r,serviceName:n}){return e(`https://${n}.${y}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":r}})}var S=class{constructor(t){this.headers=Object.keys(t).reduce((r,n)=>(r[n.trim().toLowerCase()]=t[n],r),{})}get(t){return this.headers[t.trim().toLowerCase()]}has(t){return!!this.headers[t.trim().toLowerCase()]}},A=e=>{var n;let t=(n=e.schemaSyncing)!=null?n:!0,r;return{onSchemaChange(o){if(t){let u=o.schema,i=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{r=null;try{let a=(0,h.introspectionFromSchema)(u);e.fetch(`https://${e.serviceName}.${y}/schema`,{method:"POST",body:JSON.stringify({schema:a}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},i)}},onExecute(o){var a;let u=(a=e.sendVariablesAsHash)!=null?a:!0,i=Date.now();return{async onExecuteDone({result:c}){if((0,L.isAsyncIterable)(c)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:s}=o.args.contextValue.request,{method:p}=o.args.contextValue.request;if(typeof s.get!="function"&&(s=new S(s)),s.has("gcdn-request-id"))return;let d=w({headers:s,operation:(0,h.print)(o.args.document),method:p,sendVariablesAsHash:u,start:i,operationName:o.args.operationName,errors:c.errors,response:c});x(e.fetch);try{await H({fetch:e.fetch,payload:d,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
1
+ "use strict";var f=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var r in t)f(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of q(t))!O.call(e,a)&&a!==r&&f(e,a,{get:()=>t[a],enumerable:!(n=T(t,a))||n.enumerable});return e};var V=e=>A(f({},"__esModule",{value:!0}),e);var $={};E($,{createBlake3Hash:()=>u,createStellateLoggerPlugin:()=>R});module.exports=V($);var d=require("graphql"),L=require("@envelop/core");function u(e){let t=0,r=e.length;if(r===0)return t;for(let n=0;n<r;++n){let a=e.charCodeAt(n);t=(t<<5)-t+a,t&=t}return t>>>0}function N({headers:e,operation:t,method:r,start:n,operationName:a,errors:g,response:i,variables:s,responseHeaders:c,sendVariablesAsHash:o,hasSetCookie:h,graphqlClientName:p,graphqlClientVersion:b}){let v=e.get("x-forwarded-for"),C=v?v.split(","):[],m=c&&c.get("vary"),k;if(m&&m.length){let P=m.split(",").map(l=>l&&l.trim()).sort().map(l=>{let w=l&&e.get(l);return w?`${l}:${w}`:void 0}).filter(Boolean).join(`
2
+ `);k=u(P)}return{graphqlClientName:p,graphqlClientVersion:b,operation:t,operationName:a,variables:o?void 0:s,variableHash:o?u(JSON.stringify(s||{})):void 0,method:r,elapsed:Date.now()-n,ip:C[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:h,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:g,responseSize:JSON.stringify(i).length,responseHash:u(JSON.stringify(i)),varyHash:k}}function x(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var y=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function H({fetch:e,payload:t,token:r,serviceName:n}){return e(`https://${n}.${y}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":r}})}var S=class{constructor(t){this.headers=Object.keys(t).reduce((r,n)=>(r[n.trim().toLowerCase()]=t[n],r),{})}get(t){return this.headers[t.trim().toLowerCase()]}has(t){return!!this.headers[t.trim().toLowerCase()]}},R=e=>{var n;let t=(n=e.schemaSyncing)!=null?n:!0,r;return{onSchemaChange(a){if(t){let g=a.schema,i=Math.random()*5e3;r&&clearTimeout(r),r=setTimeout(async()=>{r=null;try{let s=(0,d.introspectionFromSchema)(g);e.fetch(`https://${e.serviceName}.${y}/schema`,{method:"POST",body:JSON.stringify({schema:s}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{})}catch{}},i)}},onExecute(a){var s;let g=(s=e.sendVariablesAsHash)!=null?s:!0,i=Date.now();return{async onExecuteDone({result:c}){if((0,L.isAsyncIterable)(c)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:o}=a.args.contextValue.request,{method:h}=a.args.contextValue.request;if(typeof o.get!="function"&&(o=new S(o)),o.has("gcdn-request-id"))return;let p=N({headers:o,operation:(0,d.print)(a.args.document),method:h,sendVariablesAsHash:g,start:i,operationName:a.args.operationName,errors:c.errors,response:c});x(e.fetch);try{await H({fetch:e.fetch,payload:p,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
package/dist/envelop.mjs CHANGED
@@ -27,7 +27,9 @@ function extractStellatePayload({
27
27
  variables,
28
28
  responseHeaders,
29
29
  sendVariablesAsHash,
30
- hasSetCookie
30
+ hasSetCookie,
31
+ graphqlClientName,
32
+ graphqlClientVersion
31
33
  }) {
32
34
  const forwardedFor = headers.get("x-forwarded-for");
33
35
  const ips = forwardedFor ? forwardedFor.split(",") : [];
@@ -42,6 +44,8 @@ function extractStellatePayload({
42
44
  varyHash = createBlake3Hash(variedValues);
43
45
  }
44
46
  return {
47
+ graphqlClientName,
48
+ graphqlClientVersion,
45
49
  operation,
46
50
  operationName,
47
51
  variables: sendVariablesAsHash ? void 0 : variables,
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!w.call(e,r)&&r!==n&&m(e,r,{get:()=>t[r],enumerable:!(a=T(t,r))||a.enumerable});return e};var A=e=>E(m({},"__esModule",{value:!0}),e);var q={};O(q,{createBlake3Hash:()=>g,createStellateLoggerPlugin:()=>C});module.exports=A(q);var p=require("graphql"),N=require("graphql-yoga");function g(e){let t=0,n=e.length;if(n===0)return t;for(let a=0;a<n;++a){let r=e.charCodeAt(a);t=(t<<5)-t+r,t&=t}return t>>>0}function k({headers:e,operation:t,method:n,start:a,operationName:r,errors:l,response:s,variables:o,responseHeaders:i,sendVariablesAsHash:u,hasSetCookie:h}){let d=e.get("x-forwarded-for"),S=d?d.split(","):[],f=i&&i.get("vary"),b;if(f&&f.length){let P=f.split(",").map(c=>c&&c.trim()).sort().map(c=>{let v=c&&e.get(c);return v?`${c}:${v}`:void 0}).filter(Boolean).join(`
2
- `);b=g(P)}return{operation:t,operationName:r,variables:u?void 0:o,variableHash:u?g(JSON.stringify(o||{})):void 0,method:n,elapsed:Date.now()-a,ip:S[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:h,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:l,responseSize:JSON.stringify(s).length,responseHash:g(JSON.stringify(s)),varyHash:b}}function x(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var y=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function H({fetch:e,payload:t,token:n,serviceName:a}){return e(`https://${a}.${y}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var C=e=>{var a;let t=(a=e.schemaSyncing)!=null?a:!0,n;return{onSchemaChange(r){if(t){let l=r.schema,s=Math.random()*5e3;n&&clearTimeout(n),n=setTimeout(async()=>{n=null;try{let o=(0,p.introspectionFromSchema)(l);e.fetch(`https://${e.serviceName}.${y}/schema`,{method:"POST",body:JSON.stringify({schema:o}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{}).catch(()=>{})}catch{}},s)}},onExecute(r){var o;let l=(o=e.sendVariablesAsHash)!=null?o:!0,s=Date.now();return{async onExecuteDone({result:i}){if((0,N.isAsyncIterable)(i)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:u,method:h}=r.args.contextValue.request;if(u.has("gcdn-request-id"))return;let d=k({headers:u,operation:(0,p.print)(r.args.document),method:h,sendVariablesAsHash:l,start:s,operationName:r.args.operationName,errors:i.errors,response:i});x(e.fetch);try{await H({fetch:e.fetch,payload:d,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
1
+ "use strict";var S=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)S(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!w.call(e,r)&&r!==n&&S(e,r,{get:()=>t[r],enumerable:!(a=C(t,r))||a.enumerable});return e};var A=e=>E(S({},"__esModule",{value:!0}),e);var $={};O($,{createBlake3Hash:()=>p,createStellateLoggerPlugin:()=>V});module.exports=A($);var h=require("graphql"),T=require("graphql-yoga");function p(e){let t=0,n=e.length;if(n===0)return t;for(let a=0;a<n;++a){let r=e.charCodeAt(a);t=(t<<5)-t+r,t&=t}return t>>>0}function k({headers:e,operation:t,method:n,start:a,operationName:r,errors:g,response:i,variables:o,responseHeaders:l,sendVariablesAsHash:s,hasSetCookie:d,graphqlClientName:m,graphqlClientVersion:f}){let u=e.get("x-forwarded-for"),v=u?u.split(","):[],y=l&&l.get("vary"),x;if(y&&y.length){let q=y.split(",").map(c=>c&&c.trim()).sort().map(c=>{let N=c&&e.get(c);return N?`${c}:${N}`:void 0}).filter(Boolean).join(`
2
+ `);x=p(q)}return{graphqlClientName:m,graphqlClientVersion:f,operation:t,operationName:r,variables:s?void 0:o,variableHash:s?p(JSON.stringify(o||{})):void 0,method:n,elapsed:Date.now()-a,ip:v[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:d,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:g,responseSize:JSON.stringify(i).length,responseHash:p(JSON.stringify(i)),varyHash:x}}function H(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var b=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function P({fetch:e,payload:t,token:n,serviceName:a}){return e(`https://${a}.${b}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":n}})}var V=e=>{var a;let t=(a=e.schemaSyncing)!=null?a:!0,n;return{onSchemaChange(r){if(t){let g=r.schema,i=Math.random()*5e3;n&&clearTimeout(n),n=setTimeout(async()=>{n=null;try{let o=(0,h.introspectionFromSchema)(g);e.fetch(`https://${e.serviceName}.${b}/schema`,{method:"POST",body:JSON.stringify({schema:o}),headers:{"Content-Type":"application/json","Stellate-Schema-Token":e.token}}).then(()=>{}).catch(()=>{})}catch{}},i)}},onExecute(r){var o;let g=(o=e.sendVariablesAsHash)!=null?o:!0,i=Date.now();return{async onExecuteDone({result:l}){if((0,T.isAsyncIterable)(l)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:s,method:d}=r.args.contextValue.request;if(s.has("gcdn-request-id"))return;let m=s.get("x-graphql-client-name")||void 0,f=s.get("x-graphql-client-version")||void 0,u=k({graphqlClientName:m,graphqlClientVersion:f,headers:s,operation:(0,h.print)(r.args.document),method:d,sendVariablesAsHash:g,start:i,operationName:r.args.operationName,errors:l.errors,response:l});H(e.fetch);try{await P({fetch:e.fetch,payload:u,token:e.token,serviceName:e.serviceName})}catch{}}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
@@ -27,7 +27,9 @@ function extractStellatePayload({
27
27
  variables,
28
28
  responseHeaders,
29
29
  sendVariablesAsHash,
30
- hasSetCookie
30
+ hasSetCookie,
31
+ graphqlClientName,
32
+ graphqlClientVersion
31
33
  }) {
32
34
  const forwardedFor = headers.get("x-forwarded-for");
33
35
  const ips = forwardedFor ? forwardedFor.split(",") : [];
@@ -42,6 +44,8 @@ function extractStellatePayload({
42
44
  varyHash = createBlake3Hash(variedValues);
43
45
  }
44
46
  return {
47
+ graphqlClientName,
48
+ graphqlClientVersion,
45
49
  operation,
46
50
  operationName,
47
51
  variables: sendVariablesAsHash ? void 0 : variables,
@@ -132,7 +136,11 @@ var createStellateLoggerPlugin = (options) => {
132
136
  const { headers, method } = payload.args.contextValue.request;
133
137
  if (headers.has("gcdn-request-id"))
134
138
  return;
139
+ const graphqlClientName = headers.get("x-graphql-client-name") || void 0;
140
+ const graphqlClientVersion = headers.get("x-graphql-client-version") || void 0;
135
141
  const stellatePayload = extractStellatePayload({
142
+ graphqlClientName,
143
+ graphqlClientVersion,
136
144
  headers,
137
145
  operation: print(payload.args.document),
138
146
  method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stellate",
3
- "version": "2.11.1",
3
+ "version": "2.12.0",
4
4
  "engines": {
5
5
  "node": ">=16"
6
6
  },