altair-fastify-plugin 8.2.7 → 8.2.8

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/index.d.ts CHANGED
@@ -1,24 +1,19 @@
1
1
  import { RenderOptions } from 'altair-static';
2
2
  import type { FastifyInstance } from 'fastify';
3
3
  export interface AltairFastifyPluginOptions extends RenderOptions {
4
- /**
5
- * URL to set as the server endpoint.
6
- *
7
- * By default is `/graphql`
8
- */
9
- endpointURL?: string;
10
- /**
11
- * URL to be used as a base for relative URLs and hosting needed static files.
12
- *
13
- * By default is `/altair/`
14
- */
15
- baseURL?: string;
16
4
  /**
17
5
  * Path in which Altair will be accesible.
18
6
  *
19
7
  * By default is `/altair`
20
8
  */
21
9
  path?: string;
10
+ /**
11
+ * Generates a Content Security Policy (CSP) nonce for the request.
12
+ * @param req The Fastify request object.
13
+ * @param res The Fastify response object.
14
+ * @returns The generated CSP nonce.
15
+ */
16
+ cspNonceGenerator?: (req: unknown, res: unknown) => string;
22
17
  }
23
- export declare const AltairFastify: (fastify: FastifyInstance, { path, baseURL, endpointURL, ...renderOptions }?: AltairFastifyPluginOptions) => Promise<void>;
18
+ export declare const AltairFastify: (fastify: FastifyInstance, { path, ...renderOptions }?: AltairFastifyPluginOptions) => Promise<void>;
24
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAEd,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,0BAA2B,SAAQ,aAAa;IAC/D;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAgCD,eAAO,MAAM,aAAa,YA7Bf,eAAe,qDAMrB,0BAA0B,kBA0B7B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAGd,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAE7E,MAAM,WAAW,0BAA2B,SAAQ,aAAa;IAC/D;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CAC5D;AAoCD,eAAO,MAAM,aAAa,YAjCf,eAAe,+BACgB,0BAA0B,kBAmClE,CAAC"}
package/dist/index.js CHANGED
@@ -7,19 +7,26 @@ exports.AltairFastify = void 0;
7
7
  const altair_static_1 = require("altair-static");
8
8
  const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
9
9
  const static_1 = __importDefault(require("@fastify/static"));
10
- const fastifyAltairPluginFn = async (fastify, { path = '/altair', baseURL = '/altair/', endpointURL = '/graphql', ...renderOptions } = {}) => {
10
+ const fastifyAltairPluginFn = async (fastify, { path = '/altair', ...renderOptions } = {}) => {
11
+ var _a;
11
12
  fastify.register(static_1.default, {
12
13
  root: (0, altair_static_1.getDistDirectory)(),
13
- prefix: baseURL,
14
+ prefix: (_a = renderOptions.baseURL) !== null && _a !== void 0 ? _a : '/altair/',
15
+ setHeaders: (res, path) => {
16
+ if ((0, altair_static_1.isSandboxFrame)(path)) {
17
+ // Disable CSP for the sandbox iframe
18
+ res.setHeader('Content-Security-Policy', '');
19
+ }
20
+ },
14
21
  });
15
- const altairPage = (0, altair_static_1.renderAltair)({ baseURL, endpointURL, ...renderOptions });
16
- fastify.get(path, (_req, res) => {
22
+ fastify.get(path, (req, res) => {
23
+ const altairPage = (0, altair_static_1.renderAltair)(getRequestRenderOptions(req, res, renderOptions));
17
24
  res.type('text/html').send(altairPage);
18
25
  });
19
26
  if (renderOptions.serveInitialOptionsInSeperateRequest) {
20
- const initialOptions = (0, altair_static_1.renderInitSnippet)(renderOptions);
21
27
  const initOptPath = path + '/initial_options.js';
22
- fastify.get(initOptPath, (_req, res) => {
28
+ fastify.get(initOptPath, (req, res) => {
29
+ const initialOptions = (0, altair_static_1.renderInitSnippet)(getRequestRenderOptions(req, res, renderOptions));
23
30
  res.type('application/javascript').send(initialOptions);
24
31
  });
25
32
  }
@@ -28,4 +35,16 @@ exports.AltairFastify = (0, fastify_plugin_1.default)(fastifyAltairPluginFn, {
28
35
  fastify: '>= 3.x',
29
36
  name: 'altair-fastify-plugin',
30
37
  });
38
+ function getRequestRenderOptions(req, res, opts) {
39
+ const { baseURL, cspNonceGenerator, ...renderOptions } = opts;
40
+ let cspNonce = renderOptions.cspNonce;
41
+ if (!cspNonce && cspNonceGenerator) {
42
+ cspNonce = cspNonceGenerator(req, res);
43
+ }
44
+ return {
45
+ ...opts,
46
+ baseURL: baseURL !== null && baseURL !== void 0 ? baseURL : '/altair/',
47
+ cspNonce,
48
+ };
49
+ }
31
50
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAKuB;AACvB,oEAAgC;AAChC,6DAA4C;AAyB5C,MAAM,qBAAqB,GAAG,KAAK,EACjC,OAAwB,EACxB,EACE,IAAI,GAAG,SAAS,EAChB,OAAO,GAAG,UAAU,EACpB,WAAW,GAAG,UAAU,EACxB,GAAG,aAAa,KACc,EAAE,EAClC,EAAE;IACF,OAAO,CAAC,QAAQ,CAAC,gBAAa,EAAE;QAC9B,IAAI,EAAE,IAAA,gCAAgB,GAAE;QACxB,MAAM,EAAE,OAAO;KAChB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,IAAA,4BAAY,EAAC,EAAE,OA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AG,CAAC,CAAC;IACzC,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,UAAU;QAC9B,QAAQ;KACT,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "altair-fastify-plugin",
3
3
  "description": "Fastify Plugin of Altair GraphQL Client",
4
- "version": "8.2.7",
4
+ "version": "8.2.8",
5
5
  "author": "PabloSz <pablosaez1995@gmail.com>",
6
6
  "bugs": "https://github.com/altair-graphql/altair/issues",
7
7
  "dependencies": {
8
8
  "@fastify/static": "^8.0.1",
9
9
  "fastify-plugin": "^5.0.1",
10
- "altair-static": "8.2.7"
10
+ "altair-static": "8.2.8"
11
11
  },
12
12
  "devDependencies": {
13
13
  "fastify": "^5.0.0",