naystack 1.5.33 → 1.5.34

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.
@@ -57,26 +57,18 @@ function getCorsHeaders(origin, allowedOrigins) {
57
57
  }
58
58
  function withCors(handler, allowedOrigins) {
59
59
  if (!allowedOrigins?.length) return handler;
60
- return ((req) => {
61
- return handler(req).then((response) => {
62
- if (!response) return response;
63
- const corsHeaders = getCorsHeaders(
64
- req.headers.get("origin"),
65
- allowedOrigins
66
- );
67
- if (corsHeaders) {
68
- const newResponse = new import_server.NextResponse(response.body, {
69
- status: response.status,
70
- statusText: response.statusText,
71
- headers: new Headers(response.headers)
72
- });
73
- Object.entries(corsHeaders).forEach(([key, value]) => {
74
- newResponse.headers.set(key, value);
75
- });
76
- return newResponse;
77
- }
78
- return response;
60
+ return (async (req) => {
61
+ const origin = req.headers.get("origin");
62
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
63
+ if (origin && !corsHeaders) {
64
+ return new import_server.NextResponse(null, { status: 403 });
65
+ }
66
+ const response = await handler(req);
67
+ if (!response || !corsHeaders) return response;
68
+ Object.entries(corsHeaders).forEach(([key, value]) => {
69
+ response.headers.set(key, value);
79
70
  });
71
+ return response;
80
72
  });
81
73
  }
82
74
 
@@ -20,26 +20,18 @@ function getCorsHeaders(origin, allowedOrigins) {
20
20
  }
21
21
  function withCors(handler, allowedOrigins) {
22
22
  if (!allowedOrigins?.length) return handler;
23
- return ((req) => {
24
- return handler(req).then((response) => {
25
- if (!response) return response;
26
- const corsHeaders = getCorsHeaders(
27
- req.headers.get("origin"),
28
- allowedOrigins
29
- );
30
- if (corsHeaders) {
31
- const newResponse = new NextResponse(response.body, {
32
- status: response.status,
33
- statusText: response.statusText,
34
- headers: new Headers(response.headers)
35
- });
36
- Object.entries(corsHeaders).forEach(([key, value]) => {
37
- newResponse.headers.set(key, value);
38
- });
39
- return newResponse;
40
- }
41
- return response;
23
+ return (async (req) => {
24
+ const origin = req.headers.get("origin");
25
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
26
+ if (origin && !corsHeaders) {
27
+ return new NextResponse(null, { status: 403 });
28
+ }
29
+ const response = await handler(req);
30
+ if (!response || !corsHeaders) return response;
31
+ Object.entries(corsHeaders).forEach(([key, value]) => {
32
+ response.headers.set(key, value);
42
33
  });
34
+ return response;
43
35
  });
44
36
  }
45
37
 
@@ -63,26 +63,18 @@ function getCorsHeaders(origin, allowedOrigins) {
63
63
  }
64
64
  function withCors(handler, allowedOrigins) {
65
65
  if (!allowedOrigins?.length) return handler;
66
- return ((req) => {
67
- return handler(req).then((response) => {
68
- if (!response) return response;
69
- const corsHeaders = getCorsHeaders(
70
- req.headers.get("origin"),
71
- allowedOrigins
72
- );
73
- if (corsHeaders) {
74
- const newResponse = new import_server.NextResponse(response.body, {
75
- status: response.status,
76
- statusText: response.statusText,
77
- headers: new Headers(response.headers)
78
- });
79
- Object.entries(corsHeaders).forEach(([key, value]) => {
80
- newResponse.headers.set(key, value);
81
- });
82
- return newResponse;
83
- }
84
- return response;
66
+ return (async (req) => {
67
+ const origin = req.headers.get("origin");
68
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
69
+ if (origin && !corsHeaders) {
70
+ return new import_server.NextResponse(null, { status: 403 });
71
+ }
72
+ const response = await handler(req);
73
+ if (!response || !corsHeaders) return response;
74
+ Object.entries(corsHeaders).forEach(([key, value]) => {
75
+ response.headers.set(key, value);
85
76
  });
77
+ return response;
86
78
  });
87
79
  }
88
80
 
@@ -20,26 +20,18 @@ function getCorsHeaders(origin, allowedOrigins) {
20
20
  }
21
21
  function withCors(handler, allowedOrigins) {
22
22
  if (!allowedOrigins?.length) return handler;
23
- return ((req) => {
24
- return handler(req).then((response) => {
25
- if (!response) return response;
26
- const corsHeaders = getCorsHeaders(
27
- req.headers.get("origin"),
28
- allowedOrigins
29
- );
30
- if (corsHeaders) {
31
- const newResponse = new NextResponse(response.body, {
32
- status: response.status,
33
- statusText: response.statusText,
34
- headers: new Headers(response.headers)
35
- });
36
- Object.entries(corsHeaders).forEach(([key, value]) => {
37
- newResponse.headers.set(key, value);
38
- });
39
- return newResponse;
40
- }
41
- return response;
23
+ return (async (req) => {
24
+ const origin = req.headers.get("origin");
25
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
26
+ if (origin && !corsHeaders) {
27
+ return new NextResponse(null, { status: 403 });
28
+ }
29
+ const response = await handler(req);
30
+ if (!response || !corsHeaders) return response;
31
+ Object.entries(corsHeaders).forEach(([key, value]) => {
32
+ response.headers.set(key, value);
42
33
  });
34
+ return response;
43
35
  });
44
36
  }
45
37
 
@@ -645,26 +645,18 @@ function getCorsHeaders(origin, allowedOrigins) {
645
645
  }
646
646
  function withCors(handler, allowedOrigins) {
647
647
  if (!allowedOrigins?.length) return handler;
648
- return ((req) => {
649
- return handler(req).then((response) => {
650
- if (!response) return response;
651
- const corsHeaders = getCorsHeaders(
652
- req.headers.get("origin"),
653
- allowedOrigins
654
- );
655
- if (corsHeaders) {
656
- const newResponse = new import_server.NextResponse(response.body, {
657
- status: response.status,
658
- statusText: response.statusText,
659
- headers: new Headers(response.headers)
660
- });
661
- Object.entries(corsHeaders).forEach(([key, value]) => {
662
- newResponse.headers.set(key, value);
663
- });
664
- return newResponse;
665
- }
666
- return response;
648
+ return (async (req) => {
649
+ const origin = req.headers.get("origin");
650
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
651
+ if (origin && !corsHeaders) {
652
+ return new import_server.NextResponse(null, { status: 403 });
653
+ }
654
+ const response = await handler(req);
655
+ if (!response || !corsHeaders) return response;
656
+ Object.entries(corsHeaders).forEach(([key, value]) => {
657
+ response.headers.set(key, value);
667
658
  });
659
+ return response;
668
660
  });
669
661
  }
670
662
 
@@ -751,18 +743,10 @@ async function initGraphQLServer({
751
743
  return {
752
744
  GET: withCors((request) => handler(request), allowedOrigins),
753
745
  POST: withCors((request) => handler(request), allowedOrigins),
754
- ...allowedOrigins?.length ? {
755
- OPTIONS: (req) => {
756
- const corsHeaders = getCorsHeaders(
757
- req.headers.get("origin"),
758
- allowedOrigins
759
- );
760
- return new import_server5.NextResponse(null, {
761
- status: 204,
762
- headers: corsHeaders ?? void 0
763
- });
764
- }
765
- } : {}
746
+ OPTIONS: withCors(
747
+ () => new import_server5.NextResponse(null, { status: 204 }),
748
+ allowedOrigins
749
+ )
766
750
  };
767
751
  }
768
752
 
@@ -632,26 +632,18 @@ function getCorsHeaders(origin, allowedOrigins) {
632
632
  }
633
633
  function withCors(handler, allowedOrigins) {
634
634
  if (!allowedOrigins?.length) return handler;
635
- return ((req) => {
636
- return handler(req).then((response) => {
637
- if (!response) return response;
638
- const corsHeaders = getCorsHeaders(
639
- req.headers.get("origin"),
640
- allowedOrigins
641
- );
642
- if (corsHeaders) {
643
- const newResponse = new NextResponse(response.body, {
644
- status: response.status,
645
- statusText: response.statusText,
646
- headers: new Headers(response.headers)
647
- });
648
- Object.entries(corsHeaders).forEach(([key, value]) => {
649
- newResponse.headers.set(key, value);
650
- });
651
- return newResponse;
652
- }
653
- return response;
635
+ return (async (req) => {
636
+ const origin = req.headers.get("origin");
637
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
638
+ if (origin && !corsHeaders) {
639
+ return new NextResponse(null, { status: 403 });
640
+ }
641
+ const response = await handler(req);
642
+ if (!response || !corsHeaders) return response;
643
+ Object.entries(corsHeaders).forEach(([key, value]) => {
644
+ response.headers.set(key, value);
654
645
  });
646
+ return response;
655
647
  });
656
648
  }
657
649
 
@@ -738,18 +730,10 @@ async function initGraphQLServer({
738
730
  return {
739
731
  GET: withCors((request) => handler(request), allowedOrigins),
740
732
  POST: withCors((request) => handler(request), allowedOrigins),
741
- ...allowedOrigins?.length ? {
742
- OPTIONS: (req) => {
743
- const corsHeaders = getCorsHeaders(
744
- req.headers.get("origin"),
745
- allowedOrigins
746
- );
747
- return new NextResponse4(null, {
748
- status: 204,
749
- headers: corsHeaders ?? void 0
750
- });
751
- }
752
- } : {}
733
+ OPTIONS: withCors(
734
+ () => new NextResponse4(null, { status: 204 }),
735
+ allowedOrigins
736
+ )
753
737
  };
754
738
  }
755
739
 
@@ -98,26 +98,18 @@ function getCorsHeaders(origin, allowedOrigins) {
98
98
  }
99
99
  function withCors(handler, allowedOrigins) {
100
100
  if (!allowedOrigins?.length) return handler;
101
- return ((req) => {
102
- return handler(req).then((response) => {
103
- if (!response) return response;
104
- const corsHeaders = getCorsHeaders(
105
- req.headers.get("origin"),
106
- allowedOrigins
107
- );
108
- if (corsHeaders) {
109
- const newResponse = new import_server.NextResponse(response.body, {
110
- status: response.status,
111
- statusText: response.statusText,
112
- headers: new Headers(response.headers)
113
- });
114
- Object.entries(corsHeaders).forEach(([key, value]) => {
115
- newResponse.headers.set(key, value);
116
- });
117
- return newResponse;
118
- }
119
- return response;
101
+ return (async (req) => {
102
+ const origin = req.headers.get("origin");
103
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
104
+ if (origin && !corsHeaders) {
105
+ return new import_server.NextResponse(null, { status: 403 });
106
+ }
107
+ const response = await handler(req);
108
+ if (!response || !corsHeaders) return response;
109
+ Object.entries(corsHeaders).forEach(([key, value]) => {
110
+ response.headers.set(key, value);
120
111
  });
112
+ return response;
121
113
  });
122
114
  }
123
115
 
@@ -204,18 +196,10 @@ async function initGraphQLServer({
204
196
  return {
205
197
  GET: withCors((request) => handler(request), allowedOrigins),
206
198
  POST: withCors((request) => handler(request), allowedOrigins),
207
- ...allowedOrigins?.length ? {
208
- OPTIONS: (req) => {
209
- const corsHeaders = getCorsHeaders(
210
- req.headers.get("origin"),
211
- allowedOrigins
212
- );
213
- return new import_server5.NextResponse(null, {
214
- status: 204,
215
- headers: corsHeaders ?? void 0
216
- });
217
- }
218
- } : {}
199
+ OPTIONS: withCors(
200
+ () => new import_server5.NextResponse(null, { status: 204 }),
201
+ allowedOrigins
202
+ )
219
203
  };
220
204
  }
221
205
  // Annotate the CommonJS export names for ESM import in node:
@@ -42,9 +42,9 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
42
42
  getContext?: (req: NextRequest) => Promise<any> | any;
43
43
  allowedOrigins?: string[];
44
44
  }): Promise<{
45
- OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
46
45
  GET: (request: NextRequest) => Promise<Response>;
47
46
  POST: (request: NextRequest) => Promise<Response>;
47
+ OPTIONS: () => NextResponse<unknown>;
48
48
  }>;
49
49
 
50
50
  export { initGraphQLServer };
@@ -42,9 +42,9 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
42
42
  getContext?: (req: NextRequest) => Promise<any> | any;
43
43
  allowedOrigins?: string[];
44
44
  }): Promise<{
45
- OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
46
45
  GET: (request: NextRequest) => Promise<Response>;
47
46
  POST: (request: NextRequest) => Promise<Response>;
47
+ OPTIONS: () => NextResponse<unknown>;
48
48
  }>;
49
49
 
50
50
  export { initGraphQLServer };
@@ -79,26 +79,18 @@ function getCorsHeaders(origin, allowedOrigins) {
79
79
  }
80
80
  function withCors(handler, allowedOrigins) {
81
81
  if (!allowedOrigins?.length) return handler;
82
- return ((req) => {
83
- return handler(req).then((response) => {
84
- if (!response) return response;
85
- const corsHeaders = getCorsHeaders(
86
- req.headers.get("origin"),
87
- allowedOrigins
88
- );
89
- if (corsHeaders) {
90
- const newResponse = new NextResponse(response.body, {
91
- status: response.status,
92
- statusText: response.statusText,
93
- headers: new Headers(response.headers)
94
- });
95
- Object.entries(corsHeaders).forEach(([key, value]) => {
96
- newResponse.headers.set(key, value);
97
- });
98
- return newResponse;
99
- }
100
- return response;
82
+ return (async (req) => {
83
+ const origin = req.headers.get("origin");
84
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
85
+ if (origin && !corsHeaders) {
86
+ return new NextResponse(null, { status: 403 });
87
+ }
88
+ const response = await handler(req);
89
+ if (!response || !corsHeaders) return response;
90
+ Object.entries(corsHeaders).forEach(([key, value]) => {
91
+ response.headers.set(key, value);
101
92
  });
93
+ return response;
102
94
  });
103
95
  }
104
96
 
@@ -185,18 +177,10 @@ async function initGraphQLServer({
185
177
  return {
186
178
  GET: withCors((request) => handler(request), allowedOrigins),
187
179
  POST: withCors((request) => handler(request), allowedOrigins),
188
- ...allowedOrigins?.length ? {
189
- OPTIONS: (req) => {
190
- const corsHeaders = getCorsHeaders(
191
- req.headers.get("origin"),
192
- allowedOrigins
193
- );
194
- return new NextResponse4(null, {
195
- status: 204,
196
- headers: corsHeaders ?? void 0
197
- });
198
- }
199
- } : {}
180
+ OPTIONS: withCors(
181
+ () => new NextResponse4(null, { status: 204 }),
182
+ allowedOrigins
183
+ )
200
184
  };
201
185
  }
202
186
  export {
@@ -41,26 +41,18 @@ function getCorsHeaders(origin, allowedOrigins) {
41
41
  }
42
42
  function withCors(handler, allowedOrigins) {
43
43
  if (!allowedOrigins?.length) return handler;
44
- return ((req) => {
45
- return handler(req).then((response) => {
46
- if (!response) return response;
47
- const corsHeaders = getCorsHeaders(
48
- req.headers.get("origin"),
49
- allowedOrigins
50
- );
51
- if (corsHeaders) {
52
- const newResponse = new import_server.NextResponse(response.body, {
53
- status: response.status,
54
- statusText: response.statusText,
55
- headers: new Headers(response.headers)
56
- });
57
- Object.entries(corsHeaders).forEach(([key, value]) => {
58
- newResponse.headers.set(key, value);
59
- });
60
- return newResponse;
61
- }
62
- return response;
44
+ return (async (req) => {
45
+ const origin = req.headers.get("origin");
46
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
47
+ if (origin && !corsHeaders) {
48
+ return new import_server.NextResponse(null, { status: 403 });
49
+ }
50
+ const response = await handler(req);
51
+ if (!response || !corsHeaders) return response;
52
+ Object.entries(corsHeaders).forEach(([key, value]) => {
53
+ response.headers.set(key, value);
63
54
  });
55
+ return response;
64
56
  });
65
57
  }
66
58
  // Annotate the CommonJS export names for ESM import in node:
@@ -6,6 +6,6 @@ declare function getCorsHeaders(origin: string | null, allowedOrigins: string[])
6
6
  "Access-Control-Allow-Headers": string;
7
7
  "Access-Control-Allow-Credentials": string;
8
8
  } | null;
9
- declare function withCors<T extends (req: NextRequest) => Promise<NextResponse | Response | undefined>>(handler: T, allowedOrigins?: string[]): T;
9
+ declare function withCors<T extends (req: NextRequest) => Promise<NextResponse | Response | undefined> | NextResponse | Response | undefined>(handler: T, allowedOrigins?: string[]): T;
10
10
 
11
11
  export { getCorsHeaders, withCors };
@@ -6,6 +6,6 @@ declare function getCorsHeaders(origin: string | null, allowedOrigins: string[])
6
6
  "Access-Control-Allow-Headers": string;
7
7
  "Access-Control-Allow-Credentials": string;
8
8
  } | null;
9
- declare function withCors<T extends (req: NextRequest) => Promise<NextResponse | Response | undefined>>(handler: T, allowedOrigins?: string[]): T;
9
+ declare function withCors<T extends (req: NextRequest) => Promise<NextResponse | Response | undefined> | NextResponse | Response | undefined>(handler: T, allowedOrigins?: string[]): T;
10
10
 
11
11
  export { getCorsHeaders, withCors };
@@ -16,26 +16,18 @@ function getCorsHeaders(origin, allowedOrigins) {
16
16
  }
17
17
  function withCors(handler, allowedOrigins) {
18
18
  if (!allowedOrigins?.length) return handler;
19
- return ((req) => {
20
- return handler(req).then((response) => {
21
- if (!response) return response;
22
- const corsHeaders = getCorsHeaders(
23
- req.headers.get("origin"),
24
- allowedOrigins
25
- );
26
- if (corsHeaders) {
27
- const newResponse = new NextResponse(response.body, {
28
- status: response.status,
29
- statusText: response.statusText,
30
- headers: new Headers(response.headers)
31
- });
32
- Object.entries(corsHeaders).forEach(([key, value]) => {
33
- newResponse.headers.set(key, value);
34
- });
35
- return newResponse;
36
- }
37
- return response;
19
+ return (async (req) => {
20
+ const origin = req.headers.get("origin");
21
+ const corsHeaders = getCorsHeaders(origin, allowedOrigins);
22
+ if (origin && !corsHeaders) {
23
+ return new NextResponse(null, { status: 403 });
24
+ }
25
+ const response = await handler(req);
26
+ if (!response || !corsHeaders) return response;
27
+ Object.entries(corsHeaders).forEach(([key, value]) => {
28
+ response.headers.set(key, value);
38
29
  });
30
+ return response;
39
31
  });
40
32
  }
41
33
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.5.33",
3
+ "version": "1.5.34",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",