stellate 2.4.0 → 2.5.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/apollo-server.d.ts +1 -1
- package/dist/apollo-server.js +1 -1
- package/dist/apollo-server.mjs +74 -33
- package/dist/bin.js +18 -18
- package/dist/envelop.d.ts +1 -1
- package/dist/envelop.js +1 -1
- package/dist/envelop.mjs +74 -30
- package/dist/graphql-yoga.d.ts +1 -1
- package/dist/graphql-yoga.js +1 -1
- package/dist/graphql-yoga.mjs +73 -31
- package/dist/index.d.ts +21 -9
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/apollo-server.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ interface Options {
|
|
|
6
6
|
fetch: typeof fetch;
|
|
7
7
|
sendVariablesAsHash?: boolean;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
declare function createBlake3Hash(str: string): number;
|
|
10
|
+
|
|
11
11
|
declare const createStellateLoggerPlugin: (options: Options) => ApolloServerPlugin;
|
|
12
12
|
|
|
13
13
|
export { createBlake3Hash, createStellateLoggerPlugin };
|
package/dist/apollo-server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var w=(e,r)=>{for(var t in r)f(e,t,{get:r[t],enumerable:!0})},P=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of k(r))!N.call(e,s)&&s!==t&&f(e,s,{get:()=>r[s],enumerable:!(n=v(r,s))||n.enumerable});return e};var H=e=>P(f({},"__esModule",{value:!0}),e);var L={};w(L,{createBlake3Hash:()=>p,createStellateLoggerPlugin:()=>A});module.exports=H(L);function p(e){let r=0,t=e.length;if(t===0)return r;for(let n=0;n<t;++n){let s=e.charCodeAt(n);r=(r<<5)-r+s,r&=r}return r>>>0}function h({headers:e,operation:r,method:t,start:n,operationName:s,errors:g,response:o,variables:i,sendVariablesAsHash:a,hasSetCookie:l}){let c=e.get("x-forwarded-for"),d=c?c.split(","):[];return{operation:r,operationName:s,variables:a?void 0:i,variableHash:a?p(JSON.stringify(i||{})):void 0,method:t,elapsed:Date.now()-n,ip:d[0]||e.get("true-client-ip")||e.get("x-real-ip")||void 0,hasSetCookie:l,referer:e.get("referer")||void 0,userAgent:e.get("user-agent")||void 0,statusCode:200,errors:g,responseSize:JSON.stringify(o).length,responseHash:p(JSON.stringify(o))}}function y(e){if(typeof e!="function"){console.warn("Stellate logger plugin requires a fetch function to be provided as an option.");return}}var x=process.env.STELLATE_ENDPOINT==="local"||process.env.STELLATE_ENDPOINT==="staging"?"stellate.dev":"stellate.sh";async function m({fetch:e,payload:r,token:t,serviceName:n}){return e(`https://${n}.${x}/log`,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json","Stellate-Logging-Token":t}})}var A=e=>{let r=e.sendVariablesAsHash!=null?e.sendVariablesAsHash:!1;return{async requestDidStart(t){let n=Date.now(),{request:s}=t,{operationName:g,query:o,variables:i,http:a}=s;if(!a||!o)return;let{headers:l,method:c}=a;if(!l.has("gcdn-request-id"))return{async willSendResponse(d){let{response:u}=d;if(u.body.kind!=="single"){console.warn("Stellate does not currently support logging incremental results.");return}let b=u.body.singleResult,S=h({headers:l,operation:o,method:c,sendVariablesAsHash:r,start:n,operationName:g,errors:d.errors,response:b,variables:i,hasSetCookie:u.http.headers.has("set-cookie")});y(e.fetch),await m({fetch:e.fetch,payload:S,token:e.token,serviceName:e.serviceName})}}}}};0&&(module.exports={createBlake3Hash,createStellateLoggerPlugin});
|
package/dist/apollo-server.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
const require = createRequire(import.meta.url);
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/server-plugins-shared.ts
|
|
5
5
|
function createBlake3Hash(str) {
|
|
6
6
|
let val = 0;
|
|
7
7
|
const strlen = str.length;
|
|
@@ -15,6 +15,63 @@ function createBlake3Hash(str) {
|
|
|
15
15
|
}
|
|
16
16
|
return val >>> 0;
|
|
17
17
|
}
|
|
18
|
+
function extractStellatePayload({
|
|
19
|
+
headers,
|
|
20
|
+
operation,
|
|
21
|
+
method,
|
|
22
|
+
start,
|
|
23
|
+
operationName,
|
|
24
|
+
errors,
|
|
25
|
+
response,
|
|
26
|
+
variables,
|
|
27
|
+
sendVariablesAsHash,
|
|
28
|
+
hasSetCookie
|
|
29
|
+
}) {
|
|
30
|
+
const forwardedFor = headers.get("x-forwarded-for");
|
|
31
|
+
const ips = forwardedFor ? forwardedFor.split(",") : [];
|
|
32
|
+
return {
|
|
33
|
+
operation,
|
|
34
|
+
operationName,
|
|
35
|
+
variables: sendVariablesAsHash ? void 0 : variables,
|
|
36
|
+
variableHash: sendVariablesAsHash ? createBlake3Hash(JSON.stringify(variables || {})) : void 0,
|
|
37
|
+
method,
|
|
38
|
+
elapsed: Date.now() - start,
|
|
39
|
+
ip: ips[0] || headers.get("true-client-ip") || headers.get("x-real-ip") || void 0,
|
|
40
|
+
hasSetCookie,
|
|
41
|
+
referer: headers.get("referer") || void 0,
|
|
42
|
+
userAgent: headers.get("user-agent") || void 0,
|
|
43
|
+
statusCode: 200,
|
|
44
|
+
errors,
|
|
45
|
+
responseSize: JSON.stringify(response).length,
|
|
46
|
+
responseHash: createBlake3Hash(JSON.stringify(response))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function warnFetch(fetch) {
|
|
50
|
+
if (typeof fetch !== "function") {
|
|
51
|
+
console.warn(
|
|
52
|
+
`Stellate logger plugin requires a fetch function to be provided as an option.`
|
|
53
|
+
);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var hostname = process.env.STELLATE_ENDPOINT === "local" || process.env.STELLATE_ENDPOINT === "staging" ? "stellate.dev" : "stellate.sh";
|
|
58
|
+
async function logRequest({
|
|
59
|
+
fetch: fetchFn,
|
|
60
|
+
payload,
|
|
61
|
+
token,
|
|
62
|
+
serviceName
|
|
63
|
+
}) {
|
|
64
|
+
return fetchFn(`https://${serviceName}.${hostname}/log`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify(payload),
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"Stellate-Logging-Token": token
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/apollo-server.ts
|
|
18
75
|
var createStellateLoggerPlugin = (options) => {
|
|
19
76
|
const sendVariablesAsHash = options.sendVariablesAsHash != null ? options.sendVariablesAsHash : false;
|
|
20
77
|
return {
|
|
@@ -37,41 +94,25 @@ var createStellateLoggerPlugin = (options) => {
|
|
|
37
94
|
return;
|
|
38
95
|
}
|
|
39
96
|
const respBody = response.body.singleResult;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const payload = {
|
|
97
|
+
const stellatePayload = extractStellatePayload({
|
|
98
|
+
headers,
|
|
43
99
|
operation: query,
|
|
44
|
-
operationName,
|
|
45
|
-
variables: sendVariablesAsHash ? void 0 : variables,
|
|
46
|
-
variableHash: sendVariablesAsHash ? createBlake3Hash(JSON.stringify(variables)) : void 0,
|
|
47
|
-
hasSetCookie: response.http.headers.has("set-cookie"),
|
|
48
100
|
method,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
userAgent: headers.get("user-agent"),
|
|
53
|
-
statusCode: response.http.status || 200,
|
|
101
|
+
sendVariablesAsHash,
|
|
102
|
+
start,
|
|
103
|
+
operationName,
|
|
54
104
|
errors: respContext.errors,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
method: "POST",
|
|
68
|
-
body: JSON.stringify(payload),
|
|
69
|
-
headers: {
|
|
70
|
-
"Content-Type": "application/json",
|
|
71
|
-
"Stellate-Logging-Token": options.token
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
);
|
|
105
|
+
response: respBody,
|
|
106
|
+
variables,
|
|
107
|
+
hasSetCookie: response.http.headers.has("set-cookie")
|
|
108
|
+
});
|
|
109
|
+
warnFetch(options.fetch);
|
|
110
|
+
await logRequest({
|
|
111
|
+
fetch: options.fetch,
|
|
112
|
+
payload: stellatePayload,
|
|
113
|
+
token: options.token,
|
|
114
|
+
serviceName: options.serviceName
|
|
115
|
+
});
|
|
75
116
|
}
|
|
76
117
|
};
|
|
77
118
|
}
|