@temporary-name/server 1.9.3-alpha.a252b3ff8cb6bf7deaa6d41dc9ac8a8d50edd80e → 1.9.3-alpha.a253b67a3639148c12f13a47295e1922182adecd

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.
Files changed (36) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -5
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -5
  3. package/dist/adapters/aws-lambda/index.mjs +4 -3
  4. package/dist/adapters/fetch/index.d.mts +4 -5
  5. package/dist/adapters/fetch/index.d.ts +4 -5
  6. package/dist/adapters/fetch/index.mjs +4 -3
  7. package/dist/adapters/node/index.d.mts +4 -5
  8. package/dist/adapters/node/index.d.ts +4 -5
  9. package/dist/adapters/node/index.mjs +4 -3
  10. package/dist/adapters/standard/index.d.mts +20 -32
  11. package/dist/adapters/standard/index.d.ts +20 -32
  12. package/dist/adapters/standard/index.mjs +5 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +54 -1194
  15. package/dist/index.d.ts +54 -1194
  16. package/dist/index.mjs +168 -1983
  17. package/dist/openapi/index.d.mts +9 -9
  18. package/dist/openapi/index.d.ts +9 -9
  19. package/dist/openapi/index.mjs +64 -133
  20. package/dist/plugins/index.d.mts +5 -83
  21. package/dist/plugins/index.d.ts +5 -83
  22. package/dist/plugins/index.mjs +17 -189
  23. package/dist/shared/{server.SLLuK6_v.d.ts → server.BR0GBxlv.d.ts} +2 -2
  24. package/dist/shared/server.C1RJffw4.mjs +30 -0
  25. package/dist/shared/{server.BeuTpcmO.d.mts → server.C7HccVwN.d.mts} +2 -2
  26. package/dist/shared/{server.CQyYNJ1H.d.ts → server.CPThlZ_E.d.ts} +6 -8
  27. package/dist/shared/server.D-DR5Z00.mjs +362 -0
  28. package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
  29. package/dist/shared/server.oy0285uM.d.mts +252 -0
  30. package/dist/shared/server.oy0285uM.d.ts +252 -0
  31. package/dist/shared/{server.CMTfy2UB.mjs → server.rZDPWnA8.mjs} +65 -124
  32. package/dist/shared/{server.C1fnTLq0.d.mts → server.y97Td78c.d.mts} +6 -8
  33. package/package.json +10 -21
  34. package/dist/shared/server.BKSOrA6h.d.mts +0 -192
  35. package/dist/shared/server.BKSOrA6h.d.ts +0 -192
  36. package/dist/shared/server.BZtKt8i8.mjs +0 -201
@@ -1,119 +1,5 @@
1
- import { runWithSpan, value, setSpanError, isAsyncIteratorObject, AsyncIteratorClass, clone, ORPCError } from '@temporary-name/shared';
2
- import { flattenHeader } from '@temporary-name/standard-server';
3
- import { parseBatchRequest, toBatchResponse } from '@temporary-name/standard-server/batch';
4
- import { toFetchHeaders } from '@temporary-name/standard-server-fetch';
5
-
6
- class BatchHandlerPlugin {
7
- maxSize;
8
- mapRequestItem;
9
- successStatus;
10
- headers;
11
- order = 5e6;
12
- constructor(options = {}) {
13
- this.maxSize = options.maxSize ?? 10;
14
- this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
15
- ...request,
16
- headers: {
17
- ...batchRequest.headers,
18
- ...request.headers
19
- }
20
- }));
21
- this.successStatus = options.successStatus ?? 207;
22
- this.headers = options.headers ?? {};
23
- }
24
- init(options) {
25
- options.rootInterceptors ??= [];
26
- options.rootInterceptors.unshift(async (options2) => {
27
- const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
28
- if (xHeader === void 0) {
29
- return options2.next();
30
- }
31
- let isParsing = false;
32
- try {
33
- return await runWithSpan({ name: "handle_batch_request" }, async (span) => {
34
- const mode = xHeader === "buffered" ? "buffered" : "streaming";
35
- isParsing = true;
36
- const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
37
- isParsing = false;
38
- span?.setAttribute("batch.mode", mode);
39
- span?.setAttribute("batch.size", parsed.length);
40
- const maxSize = await value(this.maxSize, options2);
41
- if (parsed.length > maxSize) {
42
- const message = "Batch request size exceeds the maximum allowed size";
43
- setSpanError(span, message);
44
- return {
45
- matched: true,
46
- response: {
47
- status: 413,
48
- headers: {},
49
- body: message
50
- }
51
- };
52
- }
53
- const responses = parsed.map((request, index) => {
54
- const mapped = this.mapRequestItem(request, options2);
55
- return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
56
- span?.addEvent(`response.${index}.${matched ? "success" : "not_matched"}`);
57
- if (matched) {
58
- if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
59
- return {
60
- index,
61
- status: 500,
62
- headers: {},
63
- body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
64
- };
65
- }
66
- return { ...response2, index };
67
- }
68
- return { index, status: 404, headers: {}, body: "No procedure matched" };
69
- }).catch((err) => {
70
- Promise.reject(err);
71
- return { index, status: 500, headers: {}, body: "Internal server error" };
72
- });
73
- });
74
- await Promise.race(responses);
75
- const status = await value(this.successStatus, responses, options2);
76
- const headers = await value(this.headers, responses, options2);
77
- const promises = [...responses];
78
- const response = await toBatchResponse({
79
- status,
80
- headers,
81
- mode,
82
- body: new AsyncIteratorClass(
83
- async () => {
84
- const handling = promises.filter((p) => p !== void 0);
85
- if (handling.length <= 0) {
86
- return { done: true, value: void 0 };
87
- }
88
- const value2 = await Promise.race(handling);
89
- promises[value2.index] = void 0;
90
- return { done: false, value: value2 };
91
- },
92
- async () => {
93
- }
94
- )
95
- });
96
- return {
97
- matched: true,
98
- response
99
- };
100
- });
101
- } catch (cause) {
102
- if (isParsing) {
103
- return {
104
- matched: true,
105
- response: {
106
- status: 400,
107
- headers: {},
108
- body: "Invalid batch request, this could be caused by a malformed request body or a missing header"
109
- }
110
- };
111
- }
112
- throw cause;
113
- }
114
- });
115
- }
116
- }
1
+ import { value, ORPCError } from '@temporary-name/shared';
2
+ import { maybeSetHeader } from '@temporary-name/standard-server';
117
3
 
118
4
  class CORSPlugin {
119
5
  options;
@@ -132,17 +18,13 @@ class CORSPlugin {
132
18
  options.rootInterceptors ??= [];
133
19
  options.rootInterceptors.unshift(async (interceptorOptions) => {
134
20
  if (interceptorOptions.request.method === "OPTIONS") {
135
- const resHeaders = {};
21
+ const resHeaders = new Headers();
136
22
  if (this.options.maxAge !== void 0) {
137
- resHeaders["access-control-max-age"] = this.options.maxAge.toString();
138
- }
139
- if (this.options.allowMethods?.length) {
140
- resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
141
- }
142
- const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
143
- if (typeof allowHeaders === "string" || allowHeaders?.length) {
144
- resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
23
+ resHeaders.set("access-control-max-age", this.options.maxAge.toString());
145
24
  }
25
+ maybeSetHeader(resHeaders, "access-control-allow-methods", this.options.allowMethods);
26
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers.get("access-control-request-headers");
27
+ maybeSetHeader(resHeaders, "access-control-allow-headers", allowHeaders);
146
28
  return {
147
29
  matched: true,
148
30
  response: {
@@ -159,87 +41,33 @@ class CORSPlugin {
159
41
  if (!result.matched) {
160
42
  return result;
161
43
  }
162
- const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
44
+ const origin = interceptorOptions.request.headers.get("origin") ?? "";
163
45
  const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
164
46
  const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
165
47
  if (allowedOriginArr.includes("*")) {
166
- result.response.headers["access-control-allow-origin"] = "*";
48
+ result.response.headers.set("access-control-allow-origin", "*");
167
49
  } else {
168
50
  if (allowedOriginArr.includes(origin)) {
169
- result.response.headers["access-control-allow-origin"] = origin;
51
+ result.response.headers.set("access-control-allow-origin", origin);
170
52
  }
171
- result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
53
+ result.response.headers.set("vary", interceptorOptions.request.headers.get("vary") ?? "origin");
172
54
  }
173
55
  const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
174
56
  const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
175
57
  if (allowedTimingOriginArr.includes("*")) {
176
- result.response.headers["timing-allow-origin"] = "*";
58
+ result.response.headers.set("timing-allow-origin", "*");
177
59
  } else if (allowedTimingOriginArr.includes(origin)) {
178
- result.response.headers["timing-allow-origin"] = origin;
60
+ result.response.headers.set("timing-allow-origin", origin);
179
61
  }
180
62
  if (this.options.credentials) {
181
- result.response.headers["access-control-allow-credentials"] = "true";
182
- }
183
- if (this.options.exposeHeaders?.length) {
184
- result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
63
+ result.response.headers.set("access-control-allow-credentials", "true");
185
64
  }
65
+ maybeSetHeader(result.response.headers, "access-control-expose-headers", this.options.exposeHeaders);
186
66
  return result;
187
67
  });
188
68
  }
189
69
  }
190
70
 
191
- class RequestHeadersPlugin {
192
- init(options) {
193
- options.rootInterceptors ??= [];
194
- options.rootInterceptors.push((interceptorOptions) => {
195
- const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
196
- return interceptorOptions.next({
197
- ...interceptorOptions,
198
- context: {
199
- ...interceptorOptions.context,
200
- reqHeaders
201
- }
202
- });
203
- });
204
- }
205
- }
206
-
207
- class ResponseHeadersPlugin {
208
- init(options) {
209
- options.rootInterceptors ??= [];
210
- options.rootInterceptors.push(async (interceptorOptions) => {
211
- const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
212
- const result = await interceptorOptions.next({
213
- ...interceptorOptions,
214
- context: {
215
- ...interceptorOptions.context,
216
- resHeaders
217
- }
218
- });
219
- if (!result.matched) {
220
- return result;
221
- }
222
- const responseHeaders = clone(result.response.headers);
223
- for (const [key, value] of resHeaders) {
224
- if (Array.isArray(responseHeaders[key])) {
225
- responseHeaders[key].push(value);
226
- } else if (responseHeaders[key] !== void 0) {
227
- responseHeaders[key] = [responseHeaders[key], value];
228
- } else {
229
- responseHeaders[key] = value;
230
- }
231
- }
232
- return {
233
- ...result,
234
- response: {
235
- ...result.response,
236
- headers: responseHeaders
237
- }
238
- };
239
- });
240
- }
241
- }
242
-
243
71
  const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
244
72
  class SimpleCsrfProtectionHandlerPlugin {
245
73
  headerName;
@@ -266,7 +94,7 @@ class SimpleCsrfProtectionHandlerPlugin {
266
94
  ...options2,
267
95
  context: {
268
96
  ...options2.context,
269
- [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
97
+ [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers.get(headerName) === headerValue
270
98
  }
271
99
  });
272
100
  });
@@ -285,4 +113,4 @@ class SimpleCsrfProtectionHandlerPlugin {
285
113
  }
286
114
  }
287
115
 
288
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
116
+ export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.BKSOrA6h.js';
3
- import { c as StandardHandleOptions } from './server.CQyYNJ1H.js';
2
+ import { C as Context } from './server.oy0285uM.js';
3
+ import { c as StandardHandleOptions } from './server.CPThlZ_E.js';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -0,0 +1,30 @@
1
+ import { parse, serialize } from 'cookie';
2
+
3
+ function setCookie(headers, name, value, options = {}) {
4
+ if (headers === void 0) {
5
+ return;
6
+ }
7
+ const cookieString = serialize(name, value, {
8
+ path: "/",
9
+ ...options
10
+ });
11
+ headers.append("Set-Cookie", cookieString);
12
+ }
13
+ function getCookie(headers, name, options = {}) {
14
+ if (headers === void 0) {
15
+ return void 0;
16
+ }
17
+ const cookieHeader = headers.get("cookie");
18
+ if (cookieHeader === null) {
19
+ return void 0;
20
+ }
21
+ return parse(cookieHeader, options)[name];
22
+ }
23
+ function deleteCookie(headers, name, options = {}) {
24
+ return setCookie(headers, name, "", {
25
+ ...options,
26
+ maxAge: 0
27
+ });
28
+ }
29
+
30
+ export { deleteCookie as d, getCookie as g, setCookie as s };
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.BKSOrA6h.mjs';
3
- import { c as StandardHandleOptions } from './server.C1fnTLq0.mjs';
2
+ import { C as Context } from './server.oy0285uM.mjs';
3
+ import { c as StandardHandleOptions } from './server.y97Td78c.mjs';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -1,16 +1,15 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
- import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.BKSOrA6h.js';
2
+ import { HTTPPath, StandardLazyRequest, Interceptor, StandardResponse } from '@temporary-name/shared';
3
+ import { C as Context, R as Router, N as ProcedureClientInterceptorOptions } from './server.oy0285uM.js';
5
4
 
6
5
  interface StandardHandlerPlugin<T extends Context> {
7
6
  order?: number;
8
- init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
7
+ init?(options: StandardHandlerOptions<T>, router: Router<T>): void;
9
8
  }
10
9
  declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
11
10
  protected readonly plugins: TPlugin[];
12
11
  constructor(plugins?: readonly TPlugin[]);
13
- init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
12
+ init(options: StandardHandlerOptions<T>, router: Router<T>): void;
14
13
  }
15
14
 
16
15
  interface StandardHandleOptions<T extends Context> {
@@ -41,15 +40,14 @@ interface StandardHandlerOptions<TContext extends Context> {
41
40
  *
42
41
  * Interceptors for procedure client.
43
42
  */
44
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
43
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Meta>, Promise<unknown>>[];
45
44
  }
46
45
  declare class StandardHandler<T extends Context> {
47
46
  private readonly interceptors;
48
47
  private readonly clientInterceptors;
49
48
  private readonly rootInterceptors;
50
49
  private readonly matcher;
51
- private readonly codec;
52
- constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
50
+ constructor(router: Router<T>, options: NoInfer<StandardHandlerOptions<T>>);
53
51
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
54
52
  }
55
53