graphql-http 1.14.0 → 1.15.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/README.md CHANGED
@@ -3,10 +3,12 @@
3
3
 
4
4
  <h3>graphql-http</h3>
5
5
 
6
- <h6>Simple, pluggable, zero-dependency, <a href="https://graphql.github.io/graphql-over-http">GraphQL over HTTP Protocol</a> compliant server and client.</h6>
6
+ <h6>Simple, pluggable, zero-dependency, <a href="https://graphql.github.io/graphql-over-http">GraphQL over HTTP spec</a> compliant server, client and audit suite.</h6>
7
7
 
8
8
  [![Continuous integration](https://github.com/graphql/graphql-http/workflows/Continuous%20integration/badge.svg)](https://github.com/graphql/graphql-http/actions?query=workflow%3A%22Continuous+integration%22) [![graphql-http](https://img.shields.io/npm/v/graphql-http.svg?label=graphql-http&logo=npm)](https://www.npmjs.com/package/graphql-http)
9
9
 
10
+ <i>Quickly check for compliance? Visit <b>[graphql-http.com](https://graphql-http.com)</b>!</i>
11
+
10
12
  <i>Want a full-featured server? See the <b>[servers section](#servers)</b>!</i>
11
13
 
12
14
  <i>Need subscriptions? Try <b>[graphql-ws](https://github.com/enisdenjo/graphql-ws)</b> or <b>[graphql-sse](https://github.com/enisdenjo/graphql-sse)</b> instead!</i>
@@ -1,2 +1,3 @@
1
1
  export * from './common';
2
2
  export * from './server';
3
+ export * from './render';
@@ -1,2 +1,3 @@
1
1
  export * from './common';
2
2
  export * from './server';
3
+ export * from './render';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./common"), exports);
18
18
  __exportStar(require("./server"), exports);
19
+ __exportStar(require("./render"), exports);
@@ -1,2 +1,3 @@
1
1
  export * from './common.mjs';
2
2
  export * from './server.mjs';
3
+ export * from './render.mjs';
@@ -0,0 +1,8 @@
1
+ import { AuditResult } from './common';
2
+ /**
3
+ * Renders the provided audit results to well-formatted and valid HTML.
4
+ *
5
+ * Do note that the rendered result is not an HTML document, it's rather
6
+ * just a component with results.
7
+ */
8
+ export declare function renderAuditResultsToHTML(results: AuditResult[]): Promise<string>;
@@ -0,0 +1,8 @@
1
+ import { AuditResult } from './common';
2
+ /**
3
+ * Renders the provided audit results to well-formatted and valid HTML.
4
+ *
5
+ * Do note that the rendered result is not an HTML document, it's rather
6
+ * just a component with results.
7
+ */
8
+ export declare function renderAuditResultsToHTML(results: AuditResult[]): Promise<string>;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderAuditResultsToHTML = void 0;
4
+ /**
5
+ * Renders the provided audit results to well-formatted and valid HTML.
6
+ *
7
+ * Do note that the rendered result is not an HTML document, it's rather
8
+ * just a component with results.
9
+ */
10
+ async function renderAuditResultsToHTML(results) {
11
+ const grouped = {
12
+ total: 0,
13
+ ok: [],
14
+ warn: [],
15
+ error: [],
16
+ };
17
+ for (const result of results) {
18
+ grouped.total++;
19
+ if (result.status === 'ok') {
20
+ grouped[result.status].push(result);
21
+ }
22
+ else {
23
+ grouped[result.status].push(result);
24
+ }
25
+ }
26
+ let report = '<i>* This report was auto-generated by graphql-http</i>\n';
27
+ report += '\n';
28
+ report += '<h1>GraphQL over HTTP audit report</h1>\n';
29
+ report += '\n';
30
+ report += '<ul>\n';
31
+ report += `<li><b>${grouped.total}</b> audits in total</li>\n`;
32
+ // font-family: monospace helps render native emojis in HTML
33
+ if (grouped.ok.length) {
34
+ report += `<li><span style="font-family: monospace">✅</span> <b>${grouped.ok.length}</b> pass</li>\n`;
35
+ }
36
+ if (grouped.warn.length) {
37
+ // TODO: warning sign is rendered as "⚠️" in markdown instead of the emoji
38
+ report += `<li><span style="font-family: monospace">⚠️</span> <b>${grouped.warn.length}</b> warnings (optional)</li>\n`;
39
+ }
40
+ if (grouped.error.length) {
41
+ report += `<li><span style="font-family: monospace">❌</span> <b>${grouped.error.length}</b> errors (required)</li>\n`;
42
+ }
43
+ report += '</ul>\n';
44
+ report += '\n';
45
+ if (grouped.ok.length) {
46
+ report += '<h2>Passing</h2>\n';
47
+ report += '<ol>\n';
48
+ for (const [, result] of grouped.ok.entries()) {
49
+ report += `<li><code>${result.id}</code> ${result.name}</li>\n`;
50
+ }
51
+ report += '</ol>\n';
52
+ report += '\n';
53
+ }
54
+ if (grouped.warn.length) {
55
+ report += `<h2>Warnings</h2>\n`;
56
+ report += 'The server <i>SHOULD</i> support these, but is not required.\n';
57
+ report += '<ol>\n';
58
+ for (const [, result] of grouped.warn.entries()) {
59
+ report += await printAuditFail(result);
60
+ }
61
+ report += '</ol>\n';
62
+ report += '\n';
63
+ }
64
+ if (grouped.error.length) {
65
+ report += `<h2>Errors</h2>\n`;
66
+ report += 'The server <b>MUST</b> support these.\n';
67
+ report += '<ol>\n';
68
+ for (const [, result] of grouped.error.entries()) {
69
+ report += await printAuditFail(result);
70
+ }
71
+ report += '</ol>\n';
72
+ }
73
+ return report;
74
+ }
75
+ exports.renderAuditResultsToHTML = renderAuditResultsToHTML;
76
+ async function printAuditFail(result) {
77
+ let report = '';
78
+ report += `<li><code>${result.id}</code> ${result.name}\n`;
79
+ report += '<details>\n';
80
+ report += `<summary>${truncate(result.reason)}</summary>\n`;
81
+ report += '<pre><code class="lang-json">'; // no "\n" because they count in HTML pre tags
82
+ const res = result.response;
83
+ const headers = {};
84
+ for (const [key, val] of res.headers.entries()) {
85
+ // some headers change on each run, dont report it
86
+ if (key === 'date') {
87
+ headers[key] = '<timestamp>';
88
+ }
89
+ else if (['cf-ray', 'server-timing'].includes(key)) {
90
+ headers[key] = '<omitted>';
91
+ }
92
+ else {
93
+ headers[key] = val;
94
+ }
95
+ }
96
+ let text = '', json;
97
+ try {
98
+ text = await res.text();
99
+ json = JSON.parse(text);
100
+ }
101
+ catch (_a) {
102
+ // noop
103
+ }
104
+ const stringified = JSON.stringify({
105
+ status: res.status,
106
+ statusText: res.statusText,
107
+ headers,
108
+ body: json || ((text === null || text === void 0 ? void 0 : text.length) > 5120 ? '<body is too long>' : text) || null,
109
+ }, (_k, v) => {
110
+ if (v != null && typeof v === 'object' && !Array.isArray(v)) {
111
+ // sort object fields for stable stringify
112
+ const acc = {};
113
+ return Object.keys(v)
114
+ .sort()
115
+ .reverse() // body on bottom
116
+ .reduce((acc, k) => {
117
+ acc[k] = v[k];
118
+ return acc;
119
+ }, acc);
120
+ }
121
+ return v;
122
+ }, 2);
123
+ report += stringified + '\n';
124
+ report += '</code></pre>\n';
125
+ report += '</details>\n';
126
+ report += '</li>\n';
127
+ return report;
128
+ }
129
+ function truncate(str, len = 1024) {
130
+ if (str.length > len) {
131
+ return str.substring(0, len) + '...';
132
+ }
133
+ return str;
134
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Renders the provided audit results to well-formatted and valid HTML.
3
+ *
4
+ * Do note that the rendered result is not an HTML document, it's rather
5
+ * just a component with results.
6
+ */
7
+ export async function renderAuditResultsToHTML(results) {
8
+ const grouped = {
9
+ total: 0,
10
+ ok: [],
11
+ warn: [],
12
+ error: [],
13
+ };
14
+ for (const result of results) {
15
+ grouped.total++;
16
+ if (result.status === 'ok') {
17
+ grouped[result.status].push(result);
18
+ }
19
+ else {
20
+ grouped[result.status].push(result);
21
+ }
22
+ }
23
+ let report = '<i>* This report was auto-generated by graphql-http</i>\n';
24
+ report += '\n';
25
+ report += '<h1>GraphQL over HTTP audit report</h1>\n';
26
+ report += '\n';
27
+ report += '<ul>\n';
28
+ report += `<li><b>${grouped.total}</b> audits in total</li>\n`;
29
+ // font-family: monospace helps render native emojis in HTML
30
+ if (grouped.ok.length) {
31
+ report += `<li><span style="font-family: monospace">✅</span> <b>${grouped.ok.length}</b> pass</li>\n`;
32
+ }
33
+ if (grouped.warn.length) {
34
+ // TODO: warning sign is rendered as "⚠️" in markdown instead of the emoji
35
+ report += `<li><span style="font-family: monospace">⚠️</span> <b>${grouped.warn.length}</b> warnings (optional)</li>\n`;
36
+ }
37
+ if (grouped.error.length) {
38
+ report += `<li><span style="font-family: monospace">❌</span> <b>${grouped.error.length}</b> errors (required)</li>\n`;
39
+ }
40
+ report += '</ul>\n';
41
+ report += '\n';
42
+ if (grouped.ok.length) {
43
+ report += '<h2>Passing</h2>\n';
44
+ report += '<ol>\n';
45
+ for (const [, result] of grouped.ok.entries()) {
46
+ report += `<li><code>${result.id}</code> ${result.name}</li>\n`;
47
+ }
48
+ report += '</ol>\n';
49
+ report += '\n';
50
+ }
51
+ if (grouped.warn.length) {
52
+ report += `<h2>Warnings</h2>\n`;
53
+ report += 'The server <i>SHOULD</i> support these, but is not required.\n';
54
+ report += '<ol>\n';
55
+ for (const [, result] of grouped.warn.entries()) {
56
+ report += await printAuditFail(result);
57
+ }
58
+ report += '</ol>\n';
59
+ report += '\n';
60
+ }
61
+ if (grouped.error.length) {
62
+ report += `<h2>Errors</h2>\n`;
63
+ report += 'The server <b>MUST</b> support these.\n';
64
+ report += '<ol>\n';
65
+ for (const [, result] of grouped.error.entries()) {
66
+ report += await printAuditFail(result);
67
+ }
68
+ report += '</ol>\n';
69
+ }
70
+ return report;
71
+ }
72
+ async function printAuditFail(result) {
73
+ let report = '';
74
+ report += `<li><code>${result.id}</code> ${result.name}\n`;
75
+ report += '<details>\n';
76
+ report += `<summary>${truncate(result.reason)}</summary>\n`;
77
+ report += '<pre><code class="lang-json">'; // no "\n" because they count in HTML pre tags
78
+ const res = result.response;
79
+ const headers = {};
80
+ for (const [key, val] of res.headers.entries()) {
81
+ // some headers change on each run, dont report it
82
+ if (key === 'date') {
83
+ headers[key] = '<timestamp>';
84
+ }
85
+ else if (['cf-ray', 'server-timing'].includes(key)) {
86
+ headers[key] = '<omitted>';
87
+ }
88
+ else {
89
+ headers[key] = val;
90
+ }
91
+ }
92
+ let text = '', json;
93
+ try {
94
+ text = await res.text();
95
+ json = JSON.parse(text);
96
+ }
97
+ catch (_a) {
98
+ // noop
99
+ }
100
+ const stringified = JSON.stringify({
101
+ status: res.status,
102
+ statusText: res.statusText,
103
+ headers,
104
+ body: json || ((text === null || text === void 0 ? void 0 : text.length) > 5120 ? '<body is too long>' : text) || null,
105
+ }, (_k, v) => {
106
+ if (v != null && typeof v === 'object' && !Array.isArray(v)) {
107
+ // sort object fields for stable stringify
108
+ const acc = {};
109
+ return Object.keys(v)
110
+ .sort()
111
+ .reverse() // body on bottom
112
+ .reduce((acc, k) => {
113
+ acc[k] = v[k];
114
+ return acc;
115
+ }, acc);
116
+ }
117
+ return v;
118
+ }, 2);
119
+ report += stringified + '\n';
120
+ report += '</code></pre>\n';
121
+ report += '</details>\n';
122
+ report += '</li>\n';
123
+ return report;
124
+ }
125
+ function truncate(str, len = 1024) {
126
+ if (str.length > len) {
127
+ return str.substring(0, len) + '...';
128
+ }
129
+ return str;
130
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.14.0",
4
- "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
3
+ "version": "1.15.0",
4
+ "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "client",
@@ -84,7 +84,7 @@
84
84
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
85
85
  "build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs",
86
86
  "build:cjs": "tsc -b tsconfig.cjs.json",
87
- "build:umd": "rollup --bundleConfigAsCjs --config rollup.config.ts --configPlugin typescript && gzip umd/graphql-http.min.js -c > umd/graphql-http.min.js.gz",
87
+ "build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
88
88
  "build": "yarn build:esm && yarn build:cjs && yarn build:umd",
89
89
  "release": "semantic-release"
90
90
  },
@@ -109,28 +109,31 @@
109
109
  "@types/eslint": "^8.21.0",
110
110
  "@types/express": "^4.17.17",
111
111
  "@types/glob": "^8.0.1",
112
+ "@types/html-validator": "^5.0.3",
112
113
  "@types/jest": "^29.4.0",
113
114
  "@types/koa": "^2.13.5",
114
115
  "@types/koa-mount": "^4.0.2",
115
116
  "@typescript-eslint/eslint-plugin": "^5.51.0",
116
117
  "@typescript-eslint/parser": "^5.51.0",
117
- "@whatwg-node/fetch": "^0.7.0",
118
+ "@whatwg-node/fetch": "^0.8.1",
118
119
  "babel-jest": "^29.4.2",
119
- "eslint": "^8.33.0",
120
+ "eslint": "^8.34.0",
120
121
  "eslint-config-prettier": "^8.6.0",
121
122
  "express": "^4.18.2",
122
- "fastify": "^4.12.0",
123
+ "fastify": "^4.13.0",
123
124
  "graphql": "^16.6.0",
125
+ "html-validator": "^6.0.1",
124
126
  "jest": "^29.4.2",
125
127
  "jest-jasmine2": "^29.4.2",
126
128
  "koa": "^2.14.1",
127
129
  "koa-mount": "^4.0.0",
128
130
  "node-fetch": "^3.3.0",
129
131
  "prettier": "^2.8.4",
130
- "rollup": "^3.14.0",
132
+ "rollup": "^3.15.0",
133
+ "rollup-plugin-gzip": "^3.1.0",
131
134
  "semantic-release": "^20.1.0",
132
135
  "tslib": "^2.5.0",
133
- "typedoc": "^0.23.24",
136
+ "typedoc": "^0.23.25",
134
137
  "typedoc-plugin-markdown": "^3.14.0",
135
138
  "typescript": "^4.9.5"
136
139
  },