stellate 2.9.0 → 2.10.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.
@@ -5,6 +5,7 @@ interface Options {
5
5
  token: string;
6
6
  fetch: typeof fetch;
7
7
  sendVariablesAsHash?: boolean;
8
+ schemaSyncing?: boolean;
8
9
  }
9
10
  declare function createBlake3Hash(str: string): number;
10
11
 
@@ -1,2 +1,2 @@
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});
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});
@@ -81,10 +81,53 @@ async function logRequest({
81
81
  }
82
82
 
83
83
  // src/apollo-server.ts
84
+ import { introspectionFromSchema } from "graphql";
84
85
  var createStellateLoggerPlugin = (options) => {
85
- var _a;
86
+ var _a, _b;
86
87
  const sendVariablesAsHash = (_a = options.sendVariablesAsHash) != null ? _a : true;
88
+ const shouldSyncSchema = (_b = options.schemaSyncing) != null ? _b : true;
89
+ let stopped = false, timeout;
90
+ const sendSchema = async (apiSchema) => {
91
+ if (shouldSyncSchema) {
92
+ const introspection = introspectionFromSchema(apiSchema);
93
+ const randomTimeout = Math.random() * 5e3;
94
+ if (timeout)
95
+ clearTimeout(timeout);
96
+ timeout = setTimeout(async () => {
97
+ timeout = null;
98
+ if (!stopped) {
99
+ try {
100
+ options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
101
+ method: "POST",
102
+ body: JSON.stringify({
103
+ schema: introspection
104
+ }),
105
+ headers: {
106
+ "Content-Type": "application/json",
107
+ "Stellate-Schema-Token": options.token
108
+ }
109
+ }).then(() => {
110
+ });
111
+ } catch (e) {
112
+ }
113
+ }
114
+ }, randomTimeout);
115
+ }
116
+ };
87
117
  return {
118
+ async serverWillStart() {
119
+ return {
120
+ schemaDidLoadOrUpdate({ apiSchema }) {
121
+ sendSchema(apiSchema);
122
+ },
123
+ async serverWillStop() {
124
+ stopped = true;
125
+ if (timeout) {
126
+ clearTimeout(timeout);
127
+ }
128
+ }
129
+ };
130
+ },
88
131
  async requestDidStart(requestCtx) {
89
132
  const start = Date.now();
90
133
  const { request } = requestCtx;
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 ms=Ae(sn());var vv=Ae(sn());var RD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.9.0"}help(e){if(e)throw new pn(`
1097
+ `);var ms=Ae(sn());var vv=Ae(sn());var RD=class{async parse(e){return ji(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.10.1"}help(e){if(e)throw new pn(`
1098
1098
  ${vv.default.bold.red("!")} ${e}
1099
1099
  ${RD.help}`);return RD.help}},Py=RD;Py.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,GJ.default)();o.use("/",(0,WJ.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,GJ.default)();n.use("/",(0,WJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Wh.default.existsSync(lc)||Wh.default.mkdirSync(lc)}getCache(){try{this.ensureConfig();let e=Wh.default.readFileSync(BS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Wh.default.readFileSync(BS,"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 zdr(JSON.stringify(e)+"2.9.0")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},Wh.default.writeFileSync(BS,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},Wh.default.writeFileSync(BS,JSON.stringify(n)),n[e]}},Tw=zJ;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,GJ.default)();o.use("/",(0,WJ.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,GJ.default)();n.use("/",(0,WJ.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),n.listen(r)}ensureConfig(){Wh.default.existsSync(lc)||Wh.default.mkdirSync(lc)}getCache(){try{this.ensureConfig();let e=Wh.default.readFileSync(BS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=Wh.default.readFileSync(BS,"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 zdr(JSON.stringify(e)+"2.10.1")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},Wh.default.writeFileSync(BS,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},Wh.default.writeFileSync(BS,JSON.stringify(n)),n[e]}},Tw=zJ;Tw.help=Mi(`
1396
1396
  (BETA) - Use a local backend with Stellate\u2019s GraphQL Edge Cache.
1397
1397
 
1398
1398
  ${kv.default.bold("Usage")}
@@ -1467,7 +1467,7 @@ Try running "stellate pull" first if your service has been created already.`);if
1467
1467
  `);var Kc=Ae(sn()),$De=Ae(zc()),KDe=Ae(require("fs/promises"));var jN=class{async parse(e){let r=ji(e,{"--service":String,"--env":String,"--org":String,"--help":Boolean,"--dry":Boolean,"-e":"--env","-o":"--org","-h":"--help","--app":"--service"},!1);if(r["--help"])return this.help();if(r["--env"]&&r["--service"])throw new Error("Please only specify --env or --service.");let i=r._[0];if(!i)throw new Error("Please specify an action.");if(i!=="push")throw new Error("The only supported action currently is push.");let n=r._[1];if(!n||!n.endsWith(".json"))throw new Error('Please specify a ".json" file with persisted operations.');let s=await Cn(),a=r["--env"],o=await ea(a),l=Sl(o,r["--service"]);if(a&&!o)throw new Error(`Could not find configuration for environment "${a}".
1468
1468
  Either remove the --env (-e) flag or add configuration for this environment.`);if(!o)throw new Error(`Could not find stellate configuration file.
1469
1469
  Try running "stellate pull" first if your service has been created already.`);let u=new Xi(s),c=await KDe.default.readFile(n,"utf-8").then(m=>{try{return JSON.parse(m)}catch{throw new Error(`The file at "${n}" is not a valid JSON file.`)}}),p;typeof c=="object"&&c.operations?p=c.operations.map(m=>({hash:m.id,query:m.body})):typeof c=="object"?p=Object.keys(c).map(m=>({hash:m,query:c[m]})):p=[],p.length===0&&(console.warn(`${Kc.default.yellow("!")} No persisted operations found in the provided file.`),process.exit(0));let d=(0,$De.default)(`Pushing ${p.length} operations to ${Kc.default.bold(o.name)}`).start(),{service:f}=await u.query(`
1470
- query ServiceByNameCli($name: ServiceName) {
1470
+ query ServiceByNameCli($name: ServiceName!) {
1471
1471
  service(name: $name) {
1472
1472
  id
1473
1473
  organization {
package/dist/envelop.d.ts CHANGED
@@ -5,6 +5,7 @@ interface Options {
5
5
  token: string;
6
6
  fetch: typeof fetch;
7
7
  sendVariablesAsHash?: boolean;
8
+ schemaSyncing?: boolean;
8
9
  }
9
10
  declare function createBlake3Hash(str: string): number;
10
11
 
package/dist/envelop.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},q=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of N(e))!O.call(t,s)&&s!==r&&f(t,s,{get:()=>e[s],enumerable:!(n=P(e,s))||n.enumerable});return t};var A=t=>q(f({},"__esModule",{value:!0}),t);var R={};E(R,{createBlake3Hash:()=>l,createStellateLoggerPlugin:()=>T});module.exports=A(R);var k=require("graphql"),S=require("@envelop/core");function l(t){let e=0,r=t.length;if(r===0)return e;for(let n=0;n<r;++n){let s=t.charCodeAt(n);e=(e<<5)-e+s,e&=e}return e>>>0}function b({headers:t,operation:e,method:r,start:n,operationName:s,errors:i,response:o,variables:c,responseHeaders:u,sendVariablesAsHash:g,hasSetCookie:H}){let h=t.get("x-forwarded-for"),x=h?h.split(","):[],d=u&&u.get("vary"),m;if(d&&d.length){let L=d.split(",").map(a=>a&&a.trim()).sort().map(a=>{let y=a&&t.get(a);return y?`${a}:${y}`:void 0}).filter(Boolean).join(`
2
- `);m=l(L)}return{operation:e,operationName:s,variables:g?void 0:c,variableHash:g?l(JSON.stringify(c||{})):void 0,method:r,elapsed:Date.now()-n,ip:x[0]||t.get("true-client-ip")||t.get("x-real-ip")||void 0,hasSetCookie:H,referer:t.get("referer")||void 0,userAgent:t.get("user-agent")||void 0,statusCode:200,errors:i,responseSize:JSON.stringify(o).length,responseHash:l(JSON.stringify(o)),varyHash:m}}function v(t){if(typeof t!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var C=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function w({fetch:t,payload:e,token:r,serviceName:n}){return t(`https://${n}.${C}/log`,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json","Stellate-Logging-Token":r}})}var p=class{constructor(e){this.headers=Object.keys(e).reduce((r,n)=>(r[n.trim().toLowerCase()]=e[n],r),{})}get(e){return this.headers[e.trim().toLowerCase()]}has(e){return!!this.headers[e.trim().toLowerCase()]}},T=t=>({onExecute(e){var s;let r=(s=t.sendVariablesAsHash)!=null?s:!0,n=Date.now();return{async onExecuteDone({result:i}){if((0,S.isAsyncIterable)(i)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:o}=e.args.contextValue.request,{method:c}=e.args.contextValue.request;if(typeof o.get!="function"&&(o=new p(o)),o.has("gcdn-request-id"))return;let u=b({headers:o,operation:(0,k.print)(e.args.document),method:c,sendVariablesAsHash:r,start:n,operationName:e.args.operationName,errors:i.errors,response:i});v(t.fetch);try{await w({fetch:t.fetch,payload:u,token:t.token,serviceName:t.serviceName})}catch{}}}}});0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
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});
package/dist/envelop.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/envelop.ts
2
- import { print } from "graphql";
2
+ import { introspectionFromSchema, print } from "graphql";
3
3
  import { isAsyncIterable } from "@envelop/core";
4
4
 
5
5
  // src/server-plugins-shared.ts
@@ -99,52 +99,83 @@ var FauxHeaders = class {
99
99
  return !!this.headers[key.trim().toLowerCase()];
100
100
  }
101
101
  };
102
- var createStellateLoggerPlugin = (options) => ({
103
- onExecute(payload) {
104
- var _a;
105
- const sendVariablesAsHash = (_a = options.sendVariablesAsHash) != null ? _a : true;
106
- const start = Date.now();
107
- return {
108
- async onExecuteDone({ result }) {
109
- if (isAsyncIterable(result)) {
110
- console.warn(
111
- `Stellate does not currently support logging incremental results.`
112
- );
113
- return;
114
- }
115
- let { headers } = payload.args.contextValue.request;
116
- const { method } = payload.args.contextValue.request;
117
- if (typeof headers.get !== "function") {
118
- headers = new FauxHeaders(
119
- headers
120
- );
121
- }
122
- if (headers.has("gcdn-request-id"))
123
- return;
124
- const stellatePayload = extractStellatePayload({
125
- headers,
126
- operation: print(payload.args.document),
127
- method,
128
- sendVariablesAsHash,
129
- start,
130
- operationName: payload.args.operationName,
131
- errors: result.errors,
132
- response: result
133
- });
134
- warnFetch(options.fetch);
135
- try {
136
- await logRequest({
137
- fetch: options.fetch,
138
- payload: stellatePayload,
139
- token: options.token,
140
- serviceName: options.serviceName
102
+ var createStellateLoggerPlugin = (options) => {
103
+ var _a;
104
+ const shouldSyncSchema = (_a = options.schemaSyncing) != null ? _a : true;
105
+ let timeout;
106
+ return {
107
+ onSchemaChange(opts) {
108
+ if (shouldSyncSchema) {
109
+ const apiSchema = opts.schema;
110
+ const randomTimeout = Math.random() * 5e3;
111
+ if (timeout)
112
+ clearTimeout(timeout);
113
+ timeout = setTimeout(async () => {
114
+ timeout = null;
115
+ try {
116
+ const introspection = introspectionFromSchema(apiSchema);
117
+ options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
118
+ method: "POST",
119
+ body: JSON.stringify({
120
+ schema: introspection
121
+ }),
122
+ headers: {
123
+ "Content-Type": "application/json",
124
+ "Stellate-Schema-Token": options.token
125
+ }
126
+ }).then(() => {
127
+ });
128
+ } catch (e) {
129
+ }
130
+ }, randomTimeout);
131
+ }
132
+ },
133
+ onExecute(payload) {
134
+ var _a2;
135
+ const sendVariablesAsHash = (_a2 = options.sendVariablesAsHash) != null ? _a2 : true;
136
+ const start = Date.now();
137
+ return {
138
+ async onExecuteDone({ result }) {
139
+ if (isAsyncIterable(result)) {
140
+ console.warn(
141
+ `Stellate does not currently support logging incremental results.`
142
+ );
143
+ return;
144
+ }
145
+ let { headers } = payload.args.contextValue.request;
146
+ const { method } = payload.args.contextValue.request;
147
+ if (typeof headers.get !== "function") {
148
+ headers = new FauxHeaders(
149
+ headers
150
+ );
151
+ }
152
+ if (headers.has("gcdn-request-id"))
153
+ return;
154
+ const stellatePayload = extractStellatePayload({
155
+ headers,
156
+ operation: print(payload.args.document),
157
+ method,
158
+ sendVariablesAsHash,
159
+ start,
160
+ operationName: payload.args.operationName,
161
+ errors: result.errors,
162
+ response: result
141
163
  });
142
- } catch (e) {
164
+ warnFetch(options.fetch);
165
+ try {
166
+ await logRequest({
167
+ fetch: options.fetch,
168
+ payload: stellatePayload,
169
+ token: options.token,
170
+ serviceName: options.serviceName
171
+ });
172
+ } catch (e) {
173
+ }
143
174
  }
144
- }
145
- };
146
- }
147
- });
175
+ };
176
+ }
177
+ };
178
+ };
148
179
  export {
149
180
  createBlake3Hash,
150
181
  createStellateLoggerPlugin
@@ -5,6 +5,7 @@ interface Options {
5
5
  token: string;
6
6
  fetch: typeof fetch;
7
7
  sendVariablesAsHash?: boolean;
8
+ schemaSyncing?: boolean;
8
9
  }
9
10
  declare function createBlake3Hash(str: string): number;
10
11
 
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},O=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of w(t))!L.call(e,o)&&o!==r&&p(e,o,{get:()=>t[o],enumerable:!(n=N(t,o))||n.enumerable});return e};var A=e=>O(p({},"__esModule",{value:!0}),e);var C={};E(C,{createBlake3Hash:()=>l,createStellateLoggerPlugin:()=>q});module.exports=A(C);var S=require("graphql"),H=require("graphql-yoga");function l(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 y({headers:e,operation:t,method:r,start:n,operationName:o,errors:s,response:i,variables:c,responseHeaders:g,sendVariablesAsHash:u,hasSetCookie:k}){let f=e.get("x-forwarded-for"),x=f?f.split(","):[],d=g&&g.get("vary"),h;if(d&&d.length){let P=d.split(",").map(a=>a&&a.trim()).sort().map(a=>{let m=a&&e.get(a);return m?`${a}:${m}`:void 0}).filter(Boolean).join(`
2
- `);h=l(P)}return{operation:t,operationName:o,variables:u?void 0:c,variableHash:u?l(JSON.stringify(c||{})):void 0,method:r,elapsed:Date.now()-n,ip:x[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:k,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:s,responseSize:JSON.stringify(i).length,responseHash:l(JSON.stringify(i)),varyHash:h}}function b(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var T=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function v({fetch:e,payload:t,token:r,serviceName:n}){return e(`https://${n}.${T}/log`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Stellate-Logging-Token":r}})}var q=e=>({onExecute(t){var o;let r=(o=e.sendVariablesAsHash)!=null?o:!0,n=Date.now();return{async onExecuteDone({result:s}){if((0,H.isAsyncIterable)(s)){console.warn("Stellate does not currently support logging incremental results.");return}let{headers:i,method:c}=t.args.contextValue.request;if(i.has("gcdn-request-id"))return;let g=y({headers:i,operation:(0,S.print)(t.args.document),method:c,sendVariablesAsHash:r,start:n,operationName:t.args.operationName,errors:s.errors,response:s});b(e.fetch);try{await v({fetch:e.fetch,payload:g,token:e.token,serviceName:e.serviceName})}catch{}}}}});0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
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,5 +1,5 @@
1
1
  // src/graphql-yoga.ts
2
- import { print } from "graphql";
2
+ import { print, introspectionFromSchema } from "graphql";
3
3
  import { isAsyncIterable } from "graphql-yoga";
4
4
 
5
5
  // src/server-plugins-shared.ts
@@ -85,46 +85,78 @@ async function logRequest({
85
85
  }
86
86
 
87
87
  // src/graphql-yoga.ts
88
- var createStellateLoggerPlugin = (options) => ({
89
- onExecute(payload) {
90
- var _a;
91
- const sendVariablesAsHash = (_a = options.sendVariablesAsHash) != null ? _a : true;
92
- const start = Date.now();
93
- return {
94
- async onExecuteDone({ result }) {
95
- if (isAsyncIterable(result)) {
96
- console.warn(
97
- `Stellate does not currently support logging incremental results.`
98
- );
99
- return;
100
- }
101
- const { headers, method } = payload.args.contextValue.request;
102
- if (headers.has("gcdn-request-id"))
103
- return;
104
- const stellatePayload = extractStellatePayload({
105
- headers,
106
- operation: print(payload.args.document),
107
- method,
108
- sendVariablesAsHash,
109
- start,
110
- operationName: payload.args.operationName,
111
- errors: result.errors,
112
- response: result
113
- });
114
- warnFetch(options.fetch);
115
- try {
116
- await logRequest({
117
- fetch: options.fetch,
118
- payload: stellatePayload,
119
- token: options.token,
120
- serviceName: options.serviceName
88
+ var createStellateLoggerPlugin = (options) => {
89
+ var _a;
90
+ const shouldSyncSchema = (_a = options.schemaSyncing) != null ? _a : true;
91
+ let timeout;
92
+ return {
93
+ onSchemaChange(opts) {
94
+ if (shouldSyncSchema) {
95
+ const apiSchema = opts.schema;
96
+ const randomTimeout = Math.random() * 5e3;
97
+ if (timeout)
98
+ clearTimeout(timeout);
99
+ timeout = setTimeout(async () => {
100
+ timeout = null;
101
+ try {
102
+ const introspection = introspectionFromSchema(apiSchema);
103
+ options.fetch(`https://${options.serviceName}.${hostname}/schema`, {
104
+ method: "POST",
105
+ body: JSON.stringify({
106
+ schema: introspection
107
+ }),
108
+ headers: {
109
+ "Content-Type": "application/json",
110
+ "Stellate-Schema-Token": options.token
111
+ }
112
+ }).then(() => {
113
+ }).catch(() => {
114
+ });
115
+ } catch (e) {
116
+ }
117
+ }, randomTimeout);
118
+ }
119
+ },
120
+ onExecute(payload) {
121
+ var _a2;
122
+ const sendVariablesAsHash = (_a2 = options.sendVariablesAsHash) != null ? _a2 : true;
123
+ const start = Date.now();
124
+ return {
125
+ async onExecuteDone({ result }) {
126
+ if (isAsyncIterable(result)) {
127
+ console.warn(
128
+ `Stellate does not currently support logging incremental results.`
129
+ );
130
+ return;
131
+ }
132
+ const { headers, method } = payload.args.contextValue.request;
133
+ if (headers.has("gcdn-request-id"))
134
+ return;
135
+ const stellatePayload = extractStellatePayload({
136
+ headers,
137
+ operation: print(payload.args.document),
138
+ method,
139
+ sendVariablesAsHash,
140
+ start,
141
+ operationName: payload.args.operationName,
142
+ errors: result.errors,
143
+ response: result
121
144
  });
122
- } catch (e) {
145
+ warnFetch(options.fetch);
146
+ try {
147
+ await logRequest({
148
+ fetch: options.fetch,
149
+ payload: stellatePayload,
150
+ token: options.token,
151
+ serviceName: options.serviceName
152
+ });
153
+ } catch (e) {
154
+ }
123
155
  }
124
- }
125
- };
126
- }
127
- });
156
+ };
157
+ }
158
+ };
159
+ };
128
160
  export {
129
161
  createBlake3Hash,
130
162
  createStellateLoggerPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stellate",
3
- "version": "2.9.0",
3
+ "version": "2.10.1",
4
4
  "engines": {
5
5
  "node": ">=16"
6
6
  },
@@ -44,7 +44,7 @@
44
44
  "vitest": "^0.29.7",
45
45
  "ws": "8.11.0",
46
46
  "yaml": "^1.10.2",
47
- "@gcdn/configuration": "1.30.1"
47
+ "@gcdn/configuration": "1.30.2"
48
48
  },
49
49
  "bin": {
50
50
  "stellate": "dist/bin.js",
@@ -113,7 +113,7 @@
113
113
  "date-fns": "^3.2.0",
114
114
  "esbuild": "^0.17.7",
115
115
  "express": "^4.17.1",
116
- "http-proxy-middleware": "^2.0.1",
116
+ "http-proxy-middleware": "^2.0.6",
117
117
  "is-ci": "^3.0.1",
118
118
  "lz-string": "1.5.0",
119
119
  "random-words": "^1.1.1",