@query-farm/vgi-rpc 0.6.2 → 0.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@query-farm/vgi-rpc",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://vgi-rpc-typescript.query.farm",
6
6
  "repository": {
@@ -42,6 +42,7 @@ export function createHttpHandler(
42
42
  const signingKey = options?.signingKey ?? randomBytes(32);
43
43
  const tokenTtl = options?.tokenTtl ?? 3600;
44
44
  const corsOrigins = options?.corsOrigins;
45
+ const corsMaxAge = options?.corsMaxAge === undefined ? 7200 : options.corsMaxAge;
45
46
  const maxRequestBytes = options?.maxRequestBytes;
46
47
  const maxStreamResponseBytes = options?.maxStreamResponseBytes;
47
48
  const serverId = options?.serverId ?? crypto.randomUUID().replace(/-/g, "").slice(0, 12);
@@ -81,12 +82,15 @@ export function createHttpHandler(
81
82
  externalLocation,
82
83
  };
83
84
 
84
- function addCorsHeaders(headers: Headers): void {
85
+ function addCorsHeaders(headers: Headers, isOptions = false): void {
85
86
  if (corsOrigins) {
86
87
  headers.set("Access-Control-Allow-Origin", corsOrigins);
87
88
  headers.set("Access-Control-Allow-Methods", "POST, OPTIONS");
88
89
  headers.set("Access-Control-Allow-Headers", "Content-Type, Authorization");
89
- headers.set("Access-Control-Expose-Headers", "WWW-Authenticate, X-Request-ID");
90
+ headers.set("Access-Control-Expose-Headers", "WWW-Authenticate, X-Request-ID, X-VGI-Content-Encoding");
91
+ if (isOptions && corsMaxAge != null) {
92
+ headers.set("Access-Control-Max-Age", String(corsMaxAge));
93
+ }
90
94
  }
91
95
  }
92
96
 
@@ -132,7 +136,7 @@ export function createHttpHandler(
132
136
  if (request.method === "OPTIONS") {
133
137
  if (path === `${prefix}/__capabilities__`) {
134
138
  const headers = new Headers();
135
- addCorsHeaders(headers);
139
+ addCorsHeaders(headers, true);
136
140
  if (maxRequestBytes != null) {
137
141
  headers.set("VGI-Max-Request-Bytes", String(maxRequestBytes));
138
142
  }
@@ -141,7 +145,7 @@ export function createHttpHandler(
141
145
 
142
146
  if (corsOrigins) {
143
147
  const headers = new Headers();
144
- addCorsHeaders(headers);
148
+ addCorsHeaders(headers, true);
145
149
  return new Response(null, { status: 204, headers });
146
150
  }
147
151
 
package/src/http/types.ts CHANGED
@@ -15,6 +15,8 @@ export interface HttpHandlerOptions {
15
15
  tokenTtl?: number;
16
16
  /** CORS allowed origins. If set, CORS headers are added to all responses. */
17
17
  corsOrigins?: string;
18
+ /** Access-Control-Max-Age value in seconds for preflight OPTIONS responses. Default: 7200 (2 hours). null omits the header. */
19
+ corsMaxAge?: number | null;
18
20
  /** Maximum request body size in bytes. Advertised via VGI-Max-Request-Bytes header. */
19
21
  maxRequestBytes?: number;
20
22
  /** Maximum bytes before a producer stream emits a continuation token. */