beer-network 1.3.2 → 1.4.1

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/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { CacheManager } from './cache-manager';
1
2
  /**
2
3
  * Json 响应通用实体.
3
4
  */
@@ -24,12 +25,13 @@ export type Option = {
24
25
  * 中止信号量.
25
26
  */
26
27
  signal?: AbortSignal;
27
- /**
28
- * NextJS 缓存.
29
- */
30
- next?: {
31
- revalidate: number;
32
- };
28
+ };
29
+ type RequestHeader = Record<string, string>;
30
+ type RequestParams = Record<string, string>;
31
+ type PageTableData<T> = T[] | {
32
+ records?: T[];
33
+ currentPage?: number;
34
+ totalSize?: number;
33
35
  };
34
36
  export default class Fetch {
35
37
  /**
@@ -37,14 +39,12 @@ export default class Fetch {
37
39
  */
38
40
  private readonly pathPrefix;
39
41
  /**
40
- * 是否是NodeJS 环境.
42
+ * 缓存管理器.
41
43
  */
42
- private readonly isNode;
43
- /**
44
- * 是否支持 NextJs 框架.
45
- */
46
- private isNextJS;
44
+ private readonly cacheManager;
47
45
  constructor(pathPrefix?: string);
46
+ private appendUrlSearchParams;
47
+ private preprocessing;
48
48
  private sendBody;
49
49
  private sendForm;
50
50
  private sendFormData;
@@ -56,7 +56,7 @@ export default class Fetch {
56
56
  * @param header 头部.
57
57
  * @param option 选项.
58
58
  */
59
- post<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
59
+ post<T>(path: string, params?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
60
60
  /**
61
61
  * 发送POST/JSON 请求.
62
62
  * @param path 路径.
@@ -65,7 +65,7 @@ export default class Fetch {
65
65
  * @param header 头部.
66
66
  * @param option 选项.
67
67
  */
68
- postBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
68
+ postBody<T>(path: string, params?: RequestParams, body?: unknown, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
69
69
  /**
70
70
  * 发送POST/Form 请求.
71
71
  * @param path 路径.
@@ -74,7 +74,7 @@ export default class Fetch {
74
74
  * @param header 头部.
75
75
  * @param option 选项.
76
76
  */
77
- postForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
77
+ postForm<T>(path: string, params?: RequestParams, form?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
78
78
  /**
79
79
  * 发送POST/FormData 请求.
80
80
  * @param path 路径.
@@ -83,7 +83,7 @@ export default class Fetch {
83
83
  * @param header 头部.
84
84
  * @param option 选项.
85
85
  */
86
- postFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
86
+ postFormData<T>(path: string, params?: RequestParams, formData?: FormData, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
87
87
  /**
88
88
  * 发送PUT 请求.
89
89
  * @param path 路径.
@@ -91,7 +91,7 @@ export default class Fetch {
91
91
  * @param header 头部.
92
92
  * @param option 选项.
93
93
  */
94
- put<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
94
+ put<T>(path: string, params?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
95
95
  /**
96
96
  * 发送PUT/JSON 请求.
97
97
  * @param path 路径.
@@ -100,7 +100,7 @@ export default class Fetch {
100
100
  * @param header 头部.
101
101
  * @param option 选项.
102
102
  */
103
- putBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
103
+ putBody<T>(path: string, params?: RequestParams, body?: unknown, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
104
104
  /**
105
105
  * 发送PUT/Form 请求.
106
106
  * @param path 路径.
@@ -109,7 +109,7 @@ export default class Fetch {
109
109
  * @param header 头部.
110
110
  * @param option 选项.
111
111
  */
112
- putForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
112
+ putForm<T>(path: string, params?: RequestParams, form?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
113
113
  /**
114
114
  * 发送PUT/FormData 请求.
115
115
  * @param path 路径.
@@ -118,7 +118,7 @@ export default class Fetch {
118
118
  * @param header 头部.
119
119
  * @param option 选项.
120
120
  */
121
- putFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
121
+ putFormData<T>(path: string, params?: RequestParams, formData?: FormData, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
122
122
  /**
123
123
  * 发送DELETE 请求.
124
124
  * @param path 路径.
@@ -126,7 +126,7 @@ export default class Fetch {
126
126
  * @param header 头部.
127
127
  * @param option 选项.
128
128
  */
129
- delete<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
129
+ delete<T>(path: string, params?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
130
130
  /**
131
131
  * 发送DELETE/JSON 请求.
132
132
  * @param path 路径.
@@ -135,7 +135,7 @@ export default class Fetch {
135
135
  * @param header 头部.
136
136
  * @param option 选项.
137
137
  */
138
- deleteBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
138
+ deleteBody<T>(path: string, params?: RequestParams, body?: unknown, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
139
139
  /**
140
140
  * 发送DELETE/Form 请求.
141
141
  * @param path 路径.
@@ -144,7 +144,7 @@ export default class Fetch {
144
144
  * @param header 头部.
145
145
  * @param option 选项.
146
146
  */
147
- deleteForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
147
+ deleteForm<T>(path: string, params?: RequestParams, form?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
148
148
  /**
149
149
  * 发送DELETE/FormData 请求.
150
150
  * @param path 路径.
@@ -153,7 +153,7 @@ export default class Fetch {
153
153
  * @param header 头部.
154
154
  * @param option 选项.
155
155
  */
156
- deleteFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
156
+ deleteFormData<T>(path: string, params?: RequestParams, formData?: FormData, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
157
157
  /**
158
158
  * 发送Get 请求.
159
159
  * @param path 路径.
@@ -161,7 +161,7 @@ export default class Fetch {
161
161
  * @param header 头部.
162
162
  * @param option 选项.
163
163
  */
164
- get<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
164
+ get<T>(path: string, params?: RequestParams, header?: RequestHeader, option?: Option): Promise<JsonResponse<T>>;
165
165
  /**
166
166
  * 缓存.
167
167
  * @param key 缓存Key.
@@ -173,15 +173,15 @@ export default class Fetch {
173
173
  /**
174
174
  * 默认授权方式.
175
175
  */
176
- authorization(): Promise<{}>;
176
+ authorization(): Promise<RequestHeader>;
177
177
  /**
178
- * 尝试获取头.
178
+ * 获取缓存管理器.
179
179
  */
180
- private tryAuthorization;
180
+ createCacheManager(): CacheManager | undefined;
181
181
  /**
182
182
  * 默认请求头.
183
183
  */
184
- headers(): Promise<{}>;
184
+ headers(): Promise<Record<string, string>>;
185
185
  /**
186
186
  * 默认响应数据解析方式.
187
187
  * @param response 响应数据.
@@ -191,7 +191,25 @@ export default class Fetch {
191
191
  * 获取路径前缀.
192
192
  */
193
193
  getPathPrefix(): string;
194
- pageParams(params: any): any;
195
- pageTable<T>(response: JsonResponse<any>): Promise<Partial<RequestData<T>>>;
194
+ /**
195
+ * 分页参数.
196
+ * @param params 入参.
197
+ */
198
+ pageParams<T extends {
199
+ current?: unknown;
200
+ }>(params: T): T & {
201
+ currentPage: T['current'];
202
+ current: undefined;
203
+ };
204
+ /**
205
+ * 分页参数.
206
+ * @param response 响应.
207
+ */
208
+ pageTable<T>(response: JsonResponse<PageTableData<T>>): Promise<Partial<RequestData<T>>>;
209
+ /**
210
+ * 休眠.
211
+ * @param value 时间戳.
212
+ */
196
213
  sleep(value: number): Promise<unknown>;
197
214
  }
215
+ export {};
package/api.js CHANGED
@@ -1,117 +1,134 @@
1
1
  import Session from './session';
2
- import { getNodeHeaders } from './next-headers';
3
2
  export default class Fetch {
4
3
  /**
5
4
  * 请求地址.
6
5
  */
7
6
  pathPrefix;
8
7
  /**
9
- * 是否是NodeJS 环境.
8
+ * 缓存管理器.
10
9
  */
11
- isNode;
12
- /**
13
- * 是否支持 NextJs 框架.
14
- */
15
- isNextJS = undefined;
10
+ cacheManager;
16
11
  constructor(pathPrefix) {
17
12
  this.pathPrefix = pathPrefix || '';
18
- this.isNode = typeof process !== 'undefined' && !!process.versions?.node;
13
+ this.cacheManager = this.createCacheManager();
19
14
  }
20
- async sendBody(method, path, params, body, header, option) {
21
- const paramQuery = new URLSearchParams();
22
- Object.keys(params || {})
23
- .forEach(key => {
24
- paramQuery.append(key, params[key]);
15
+ appendUrlSearchParams(searchParams, params) {
16
+ Object.keys(params ?? {}).forEach(key => {
17
+ const value = params?.[key];
18
+ if (value === '') {
19
+ return;
20
+ }
21
+ searchParams.append(key, value ?? '');
25
22
  });
26
- const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
23
+ }
24
+ async preprocessing(method, path, params, header, body) {
25
+ const requestHeader = header ?? {};
26
+ const paramQuery = new URLSearchParams();
27
+ this.appendUrlSearchParams(paramQuery, params);
28
+ const paramQueryString = paramQuery.toString();
29
+ const { cacheManager } = this;
30
+ if (cacheManager === undefined) {
31
+ return {
32
+ paramQueryString,
33
+ requestHeader,
34
+ cacheManager,
35
+ cacheResponse: undefined
36
+ };
37
+ }
38
+ const cacheResponse = (await cacheManager.get(method, path, paramQueryString, requestHeader, body)) ?? undefined;
39
+ return {
40
+ paramQueryString,
41
+ requestHeader,
42
+ cacheManager,
43
+ cacheResponse
44
+ };
45
+ }
46
+ async sendBody(method, path, params, body, header, option) {
47
+ const { paramQueryString, requestHeader, cacheManager, cacheResponse } = await this.preprocessing(method, path, params, header, body);
48
+ if (cacheResponse !== undefined) {
49
+ return cacheResponse;
50
+ }
51
+ const response = await fetch(this.getPathPrefix() + path + (paramQueryString === '' ? '' : '?') + paramQueryString, {
27
52
  method,
28
53
  headers: {
29
54
  ...(await this.authorization()),
30
55
  ...(await this.headers()),
31
- ...(header || {}),
56
+ ...requestHeader,
32
57
  'Content-Type': 'application/json'
33
58
  },
34
- body: JSON.stringify(body || {}),
35
- signal: option?.signal || null,
36
- next: option?.next
59
+ body: JSON.stringify(body ?? {}),
60
+ signal: option?.signal ?? null
37
61
  });
38
- return this.responseJson(response);
62
+ const result = await this.responseJson(response);
63
+ if (cacheManager !== undefined) {
64
+ await cacheManager.put(method, path, paramQueryString, requestHeader, body, result);
65
+ }
66
+ return result;
39
67
  }
40
68
  async sendForm(method, path, params, form, header, option) {
41
- const paramQuery = new URLSearchParams();
42
- Object.keys(params || {})
43
- .forEach(key => {
44
- paramQuery.append(key, params[key]);
45
- });
46
- const formData = new FormData();
47
- const appendFormData = (data, parentKey = '') => {
48
- for (const key of data) {
49
- const currentKey = parentKey ? `${parentKey}[${key}]` : key;
50
- if (typeof data[key] === 'object' && data[key] !== null) {
51
- appendFormData(data[key], currentKey);
52
- }
53
- else if (Array.isArray(data[key])) {
54
- data[key].forEach((item, index) => {
55
- const arrayKey = `${currentKey}[${index}]`;
56
- appendFormData({ [arrayKey]: item });
57
- });
58
- }
59
- else {
60
- formData.append(currentKey, data[key]);
61
- }
62
- }
63
- };
64
- appendFormData(form);
65
- const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
69
+ const { paramQueryString, requestHeader, cacheManager, cacheResponse } = await this.preprocessing(method, path, params, header);
70
+ if (cacheResponse !== undefined) {
71
+ return cacheResponse;
72
+ }
73
+ const formParams = new URLSearchParams();
74
+ this.appendUrlSearchParams(formParams, form);
75
+ const response = await fetch(this.getPathPrefix() + path + (paramQueryString === '' ? '' : '?') + paramQueryString, {
66
76
  method,
67
77
  headers: {
68
78
  ...(await this.authorization()),
69
79
  ...(await this.headers()),
70
- ...(header || {}),
80
+ ...requestHeader,
71
81
  'Content-Type': 'application/x-www-form-urlencoded'
72
82
  },
73
- body: formData,
74
- signal: option?.signal || null,
75
- next: option?.next
83
+ body: formParams,
84
+ signal: option?.signal ?? null
76
85
  });
77
- return this.responseJson(response);
86
+ const result = await this.responseJson(response);
87
+ if (cacheManager !== undefined) {
88
+ await cacheManager.put(method, path, paramQueryString, requestHeader, undefined, result);
89
+ }
90
+ return result;
78
91
  }
79
92
  async sendFormData(method, path, params, formData, header, option) {
80
- const paramQuery = new URLSearchParams();
81
- Object.keys(params || {})
82
- .forEach(key => {
83
- paramQuery.append(key, params[key]);
84
- });
85
- const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
93
+ const { paramQueryString, requestHeader, cacheManager, cacheResponse } = await this.preprocessing(method, path, params, header);
94
+ if (cacheResponse !== undefined) {
95
+ return cacheResponse;
96
+ }
97
+ const response = await fetch(this.getPathPrefix() + path + (paramQueryString === '' ? '' : '?') + paramQueryString, {
86
98
  method,
87
99
  headers: {
88
100
  ...(await this.authorization()),
89
101
  ...(await this.headers()),
90
- ...(header || {})
102
+ ...requestHeader
91
103
  },
92
104
  body: formData,
93
- signal: option?.signal || null,
94
- next: option?.next
105
+ signal: option?.signal ?? null
95
106
  });
96
- return this.responseJson(response);
107
+ const result = await this.responseJson(response);
108
+ if (cacheManager !== undefined) {
109
+ await cacheManager.put(method, path, paramQueryString, requestHeader, undefined, result);
110
+ }
111
+ return result;
97
112
  }
98
113
  async send(method, path, params, header, option) {
99
- const paramQuery = new URLSearchParams();
100
- Object.keys(params || {})
101
- .forEach(key => {
102
- paramQuery.append(key, params[key]);
103
- });
104
- const response = await fetch(this.getPathPrefix() + path + '?' + paramQuery.toString(), {
114
+ const { paramQueryString, requestHeader, cacheManager, cacheResponse } = await this.preprocessing(method, path, params, header);
115
+ if (cacheResponse !== undefined) {
116
+ return cacheResponse;
117
+ }
118
+ const response = await fetch(this.getPathPrefix() + path + '?' + paramQueryString, {
105
119
  method,
106
120
  headers: {
107
121
  ...(await this.authorization()),
108
122
  ...(await this.headers()),
109
- ...(header || {})
123
+ ...requestHeader
110
124
  },
111
- signal: option?.signal || null,
112
- next: option?.next
125
+ signal: option?.signal ?? null
113
126
  });
114
- return this.responseJson(response);
127
+ const result = await this.responseJson(response);
128
+ if (cacheManager !== undefined) {
129
+ await cacheManager.put(method, path, paramQueryString, requestHeader, undefined, result);
130
+ }
131
+ return result;
115
132
  }
116
133
  /**
117
134
  * 发送POST 请求.
@@ -272,9 +289,10 @@ export default class Fetch {
272
289
  }
273
290
  }
274
291
  const response = await callback();
275
- if (response.code === '0') {
276
- response.expireTime = new Date().getTime() + 60000 * minute;
277
- localStorage.setItem(cacheKey, JSON.stringify(response));
292
+ const cacheResponse = response;
293
+ if (cacheResponse.code === '0') {
294
+ cacheResponse.expireTime = new Date().getTime() + 60000 * minute;
295
+ localStorage.setItem(cacheKey, JSON.stringify(cacheResponse));
278
296
  }
279
297
  return response;
280
298
  }
@@ -282,14 +300,6 @@ export default class Fetch {
282
300
  * 默认授权方式.
283
301
  */
284
302
  async authorization() {
285
- if (this.isNode) {
286
- // 非浏览器
287
- const bearer = await this.tryAuthorization();
288
- if (bearer === undefined || bearer === '') {
289
- return {};
290
- }
291
- return { Authorization: 'Bearer ' + bearer };
292
- }
293
303
  // 浏览器
294
304
  const bearer = Session.getBearer();
295
305
  if (bearer === undefined || bearer === '') {
@@ -298,31 +308,10 @@ export default class Fetch {
298
308
  return { Authorization: 'Bearer ' + bearer };
299
309
  }
300
310
  /**
301
- * 尝试获取头.
311
+ * 获取缓存管理器.
302
312
  */
303
- async tryAuthorization(index = 0) {
304
- if (index > 2) {
305
- return undefined;
306
- }
307
- if (this.isNextJS === true) {
308
- const nodeHeaders = await getNodeHeaders();
309
- return nodeHeaders.get('x-access-token')
310
- ?? nodeHeaders.get('access-token')
311
- ?? nodeHeaders.get('authorization')
312
- ?? nodeHeaders.get('AccessToken')
313
- ?? nodeHeaders.get('Authorization')
314
- ?? '';
315
- }
316
- if (this.isNextJS === undefined) {
317
- try {
318
- await getNodeHeaders();
319
- this.isNextJS = true;
320
- }
321
- catch {
322
- this.isNextJS = false;
323
- }
324
- }
325
- return this.tryAuthorization(index + 1);
313
+ createCacheManager() {
314
+ return undefined;
326
315
  }
327
316
  /**
328
317
  * 默认请求头.
@@ -341,7 +330,7 @@ export default class Fetch {
341
330
  }
342
331
  const redirect = encodeURIComponent(window.location.href);
343
332
  if (result?.code === '401') {
344
- const link = (window?.authLogin || '/auth/login') + '?redirect=' + redirect;
333
+ const link = (window.authLogin || '/auth/login') + '?redirect=' + redirect;
345
334
  setTimeout(() => window.location.replace(link), 500);
346
335
  return result;
347
336
  }
@@ -353,6 +342,10 @@ export default class Fetch {
353
342
  getPathPrefix() {
354
343
  return this.pathPrefix || '';
355
344
  }
345
+ /**
346
+ * 分页参数.
347
+ * @param params 入参.
348
+ */
356
349
  pageParams(params) {
357
350
  return {
358
351
  ...params,
@@ -360,12 +353,18 @@ export default class Fetch {
360
353
  current: undefined
361
354
  };
362
355
  }
356
+ /**
357
+ * 分页参数.
358
+ * @param response 响应.
359
+ */
363
360
  async pageTable(response) {
364
361
  if (response.success) {
362
+ const responseData = response.data;
363
+ const records = Array.isArray(responseData) ? responseData : responseData.records || [];
365
364
  return {
366
- data: response.data.records || response.data,
367
- page: response.data.currentPage || 1,
368
- total: response.data.totalSize || response.data.length,
365
+ data: records,
366
+ page: Array.isArray(responseData) ? 1 : responseData.currentPage || 1,
367
+ total: Array.isArray(responseData) ? responseData.length : responseData.totalSize || records.length,
369
368
  success: true
370
369
  };
371
370
  }
@@ -376,6 +375,10 @@ export default class Fetch {
376
375
  success: true
377
376
  };
378
377
  }
378
+ /**
379
+ * 休眠.
380
+ * @param value 时间戳.
381
+ */
379
382
  async sleep(value) {
380
383
  return new Promise((resolve) => {
381
384
  setTimeout(() => {
@@ -0,0 +1,23 @@
1
+ import type { JsonResponse } from './api';
2
+ export interface CacheManager {
3
+ /**
4
+ * 读取缓存.
5
+ * @param method 方法.
6
+ * @param path 路径.
7
+ * @param params 参数.
8
+ * @param header 头部参数.
9
+ * @param body 请求体.
10
+ * @returns 缓存数据.
11
+ */
12
+ get<T>(method: string, path: string, params: string, header: Record<string, string>, body?: unknown): Promise<JsonResponse<T>>;
13
+ /**
14
+ * 写入缓存.
15
+ * @param method 方法.
16
+ * @param path 路径.
17
+ * @param params 参数.
18
+ * @param header 头部参数.
19
+ * @param body 请求体.
20
+ * @param data 缓存数据.
21
+ */
22
+ put<T>(method: string, path: string, params: string, header: Record<string, string>, body: unknown, data: JsonResponse<T>): Promise<JsonResponse<T>>;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "beer-network",
3
3
  "private": false,
4
- "version": "1.3.2",
4
+ "version": "1.4.1",
5
5
  "scripts": {
6
6
  "pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist",
7
7
  "pub-m": "tsc && cp package.json ./dist/package.json && npm publish ./dist"
package/next-headers.d.ts DELETED
@@ -1,13 +0,0 @@
1
- type HeadersLike = {
2
- get(name: string): string | null;
3
- };
4
- type CookiesLike = {
5
- get(name: string): {
6
- value: string;
7
- } | undefined;
8
- getAll?: () => Array<any>;
9
- has?: (name: string) => boolean;
10
- };
11
- export declare function getNodeHeaders(): Promise<HeadersLike>;
12
- export declare function getNodeCookies(): CookiesLike;
13
- export {};
package/next-headers.js DELETED
@@ -1,45 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable no-eval */
3
- function loadNextHeadersModule() {
4
- try {
5
- const req = eval('require');
6
- return req('next/headers');
7
- }
8
- catch {
9
- return null;
10
- }
11
- }
12
- function emptyHeaders() {
13
- return {
14
- get() {
15
- return null;
16
- }
17
- };
18
- }
19
- function emptyCookies() {
20
- return {
21
- get() {
22
- return undefined;
23
- },
24
- getAll() {
25
- return [];
26
- },
27
- has() {
28
- return false;
29
- }
30
- };
31
- }
32
- export async function getNodeHeaders() {
33
- const mod = loadNextHeadersModule();
34
- if (mod?.headers) {
35
- return mod.headers();
36
- }
37
- return emptyHeaders();
38
- }
39
- export function getNodeCookies() {
40
- const mod = loadNextHeadersModule();
41
- if (mod?.cookies) {
42
- return mod.cookies();
43
- }
44
- return emptyCookies();
45
- }