next-sanity 5.2.3 → 5.2.5
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/webhook.cjs.map +1 -1
- package/dist/webhook.d.ts +15 -18
- package/dist/webhook.js.map +1 -1
- package/package.json +12 -11
- package/src/webhook/parseBody.ts +10 -13
package/dist/webhook.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.cjs","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\nimport type {NextRequest} from 'next/server'\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type
|
|
1
|
+
{"version":3,"file":"webhook.cjs","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\nimport type {NextRequest} from 'next/server'\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T\n}\n\n/** @public */\nexport type ParseBody<Body = SanityDocument> = ParsedBody<Body>\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextApiRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true,\n): Promise<ParseBody<Body>> {\n let signature = req.headers[SIGNATURE_HEADER_NAME]!\n if (Array.isArray(signature)) {\n signature = signature[0]\n }\n\n const body = await readBody(req)\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n\n/** @public */\nexport type ParseAppBody<Body = SanityDocument> = ParsedBody<Body>\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseAppBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true,\n): Promise<ParseAppBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)!\n\n const body = await req.text()\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n"],"names":["config","api","bodyParser","runtime","_readBody","readable","chunks","chunk","push","Buffer","from","concat","toString","parseBody","req","secret","waitForContentLakeEventualConsistency","arguments","length","undefined","signature","headers","SIGNATURE_HEADER_NAME","Array","isArray","body","readBody","validSignature","isValidSignature","trim","Promise","resolve","setTimeout","JSON","parse","parseAppBody","get","text"],"mappings":";;;;;;AAMO,MAAMA,MAAqB,GAAA;EAChCC,GAAK,EAAA;IAAA;AAAA;AAAA;IAIHC,UAAY,EAAA;EACd,CAAA;EAAA;AAAA;AAAA;EAIAC,OAAS,EAAA;AACX,CAAA;ACdA,eAAsBC,UAAUC,QAA2C,EAAA;EACzE,MAAMC,SAAS,EAAC;EAChB,WAAA,MAAiBC,SAASF,QAAU,EAAA;IAC3BC,MAAA,CAAAE,IAAA,CAAK,OAAOD,KAAU,KAAA,QAAA,GAAWE,OAAOC,IAAK,CAAAH,KAAK,IAAIA,KAAK,CAAA;EACpE;EACA,OAAOE,MAAO,CAAAE,MAAA,CAAOL,MAAM,CAAA,CAAEM,SAAS,MAAM,CAAA;AAC9C;ACcA,eAAsBC,SACpBA,CAAAC,GAAA,EACAC,MACA,EAC0B;EAAA,IAD1BC,qCAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAiD,IACvB;EACtB,IAAAG,SAAA,GAAYN,GAAI,CAAAO,OAAA,CAAQC,OAAqB,CAAAA,qBAAA,CAAA;EAC7C,IAAAC,KAAA,CAAMC,OAAQ,CAAAJ,SAAS,CAAG,EAAA;IAC5BA,SAAA,GAAYA,UAAU,CAAC,CAAA;EACzB;EAEM,MAAAK,IA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
|
|
|
10
10
|
export declare const config: PageConfig
|
|
11
11
|
|
|
12
12
|
/** @public */
|
|
13
|
-
export declare type ParseAppBody =
|
|
14
|
-
/**
|
|
15
|
-
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
16
|
-
*/
|
|
17
|
-
isValidSignature: boolean | null
|
|
18
|
-
body: SanityDocument
|
|
19
|
-
}
|
|
13
|
+
export declare type ParseAppBody<Body = SanityDocument> = ParsedBody<Body>
|
|
20
14
|
|
|
21
15
|
/**
|
|
22
16
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
23
17
|
* without worrying about getting stale data.
|
|
24
18
|
* @public
|
|
25
19
|
*/
|
|
26
|
-
export declare function parseAppBody(
|
|
20
|
+
export declare function parseAppBody<Body = SanityDocument>(
|
|
27
21
|
req: NextRequest,
|
|
28
22
|
secret?: string,
|
|
29
23
|
waitForContentLakeEventualConsistency?: boolean,
|
|
30
|
-
): Promise<ParseAppBody
|
|
24
|
+
): Promise<ParseAppBody<Body>>
|
|
31
25
|
|
|
32
26
|
/** @public */
|
|
33
|
-
export declare type ParseBody =
|
|
34
|
-
/**
|
|
35
|
-
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
36
|
-
*/
|
|
37
|
-
isValidSignature: boolean | null
|
|
38
|
-
body: SanityDocument
|
|
39
|
-
}
|
|
27
|
+
export declare type ParseBody<Body = SanityDocument> = ParsedBody<Body>
|
|
40
28
|
|
|
41
29
|
/**
|
|
42
30
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
43
31
|
* without worrying about getting stale data.
|
|
44
32
|
* @public
|
|
45
33
|
*/
|
|
46
|
-
export declare function parseBody(
|
|
34
|
+
export declare function parseBody<Body = SanityDocument>(
|
|
47
35
|
req: NextApiRequest,
|
|
48
36
|
secret?: string,
|
|
49
37
|
waitForContentLakeEventualConsistency?: boolean,
|
|
50
|
-
): Promise<ParseBody
|
|
38
|
+
): Promise<ParseBody<Body>>
|
|
39
|
+
|
|
40
|
+
/** @public */
|
|
41
|
+
export declare type ParsedBody<T> = {
|
|
42
|
+
/**
|
|
43
|
+
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
44
|
+
*/
|
|
45
|
+
isValidSignature: boolean | null
|
|
46
|
+
body: T
|
|
47
|
+
}
|
|
51
48
|
|
|
52
49
|
export {}
|
package/dist/webhook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.js","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\nimport type {NextRequest} from 'next/server'\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type
|
|
1
|
+
{"version":3,"file":"webhook.js","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\nimport type {NextRequest} from 'next/server'\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T\n}\n\n/** @public */\nexport type ParseBody<Body = SanityDocument> = ParsedBody<Body>\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextApiRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true,\n): Promise<ParseBody<Body>> {\n let signature = req.headers[SIGNATURE_HEADER_NAME]!\n if (Array.isArray(signature)) {\n signature = signature[0]\n }\n\n const body = await readBody(req)\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n\n/** @public */\nexport type ParseAppBody<Body = SanityDocument> = ParsedBody<Body>\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseAppBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true,\n): Promise<ParseAppBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)!\n\n const body = await req.text()\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n"],"names":["config","api","bodyParser","runtime","_readBody","readable","chunks","chunk","push","Buffer","from","concat","toString","parseBody","req","secret","waitForContentLakeEventualConsistency","arguments","length","undefined","signature","headers","SIGNATURE_HEADER_NAME","Array","isArray","body","readBody","validSignature","isValidSignature","trim","Promise","resolve","setTimeout","JSON","parse","parseAppBody","get","text"],"mappings":";AAMO,MAAMA,MAAqB,GAAA;EAChCC,GAAK,EAAA;IAAA;AAAA;AAAA;IAIHC,UAAY,EAAA;EACd,CAAA;EAAA;AAAA;AAAA;EAIAC,OAAS,EAAA;AACX,CAAA;ACdA,eAAsBC,UAAUC,QAA2C,EAAA;EACzE,MAAMC,SAAS,EAAC;EAChB,WAAA,MAAiBC,SAASF,QAAU,EAAA;IAC3BC,MAAA,CAAAE,IAAA,CAAK,OAAOD,KAAU,KAAA,QAAA,GAAWE,OAAOC,IAAK,CAAAH,KAAK,IAAIA,KAAK,CAAA;EACpE;EACA,OAAOE,MAAO,CAAAE,MAAA,CAAOL,MAAM,CAAA,CAAEM,SAAS,MAAM,CAAA;AAC9C;ACcA,eAAsBC,SACpBA,CAAAC,GAAA,EACAC,MACA,EAC0B;EAAA,IAD1BC,qCAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAiD,IACvB;EACtB,IAAAG,SAAA,GAAYN,GAAI,CAAAO,OAAA,CAAQC,qBAAqB,CAAA;EAC7C,IAAAC,KAAA,CAAMC,OAAQ,CAAAJ,SAAS,CAAG,EAAA;IAC5B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2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.5",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -160,23 +160,24 @@
|
|
|
160
160
|
"singleQuote": true
|
|
161
161
|
},
|
|
162
162
|
"dependencies": {
|
|
163
|
-
"@sanity/preview-kit": "2.4.
|
|
163
|
+
"@sanity/preview-kit": "2.4.11",
|
|
164
164
|
"@sanity/webhook": "2.0.0",
|
|
165
165
|
"groq": "^3.0.0"
|
|
166
166
|
},
|
|
167
167
|
"devDependencies": {
|
|
168
|
+
"@next/bundle-analyzer": "^13.4.13",
|
|
168
169
|
"@next/eslint-plugin-next": "13.4.13",
|
|
169
170
|
"@rollup/plugin-url": "^8.0.1",
|
|
170
|
-
"@sanity/client": "6.4.
|
|
171
|
+
"@sanity/client": "6.4.5",
|
|
171
172
|
"@sanity/eslint-config-studio": "^3.0.0",
|
|
172
173
|
"@sanity/image-url": "^1.0.2",
|
|
173
|
-
"@sanity/pkg-utils": "^2.4.
|
|
174
|
+
"@sanity/pkg-utils": "^2.4.5",
|
|
174
175
|
"@sanity/semantic-release-preset": "^4.1.3",
|
|
175
176
|
"@sanity/ui": "^1.7.4",
|
|
176
|
-
"@sanity/vision": "3.
|
|
177
|
+
"@sanity/vision": "3.15.1",
|
|
177
178
|
"@types/eventsource": "^1.1.11",
|
|
178
179
|
"@types/jest": "^29.5.3",
|
|
179
|
-
"@types/react": "^18.2.
|
|
180
|
+
"@types/react": "^18.2.20",
|
|
180
181
|
"@types/react-dom": "^18.2.7",
|
|
181
182
|
"@types/styled-components": "^5.1.26",
|
|
182
183
|
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
|
@@ -187,7 +188,7 @@
|
|
|
187
188
|
"eslint-gitignore": "^0.1.0",
|
|
188
189
|
"eslint-plugin-prettier": "^5.0.0",
|
|
189
190
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
190
|
-
"groqd": "^0.15.
|
|
191
|
+
"groqd": "^0.15.8",
|
|
191
192
|
"jest": "^29.6.2",
|
|
192
193
|
"jest-environment-jsdom": "^29.6.2",
|
|
193
194
|
"ls-engines": "^0.9.0",
|
|
@@ -195,19 +196,19 @@
|
|
|
195
196
|
"postcss": "^8.4.27",
|
|
196
197
|
"prettier": "^3.0.1",
|
|
197
198
|
"prettier-plugin-packagejson": "^2.4.5",
|
|
198
|
-
"prettier-plugin-tailwindcss": "^0.
|
|
199
|
+
"prettier-plugin-tailwindcss": "^0.5.1",
|
|
199
200
|
"react": "^18.2.0",
|
|
200
201
|
"react-dom": "^18.2.0",
|
|
201
202
|
"react-is": "^18.2.0",
|
|
202
|
-
"rollup": "^3.
|
|
203
|
-
"sanity": "3.
|
|
203
|
+
"rollup": "^3.28.0",
|
|
204
|
+
"sanity": "3.15.1",
|
|
204
205
|
"styled-components": "^5.3.11",
|
|
205
206
|
"tailwindcss": "^3.3.3",
|
|
206
207
|
"typescript": "^5.1.6",
|
|
207
208
|
"url-loader": "^4.1.1"
|
|
208
209
|
},
|
|
209
210
|
"peerDependencies": {
|
|
210
|
-
"@sanity/client": "^6.4.
|
|
211
|
+
"@sanity/client": "^6.4.5",
|
|
211
212
|
"@sanity/icons": "^2.0.0",
|
|
212
213
|
"@sanity/types": "^3.0.0",
|
|
213
214
|
"@sanity/ui": "^1.0.0",
|
package/src/webhook/parseBody.ts
CHANGED
|
@@ -6,23 +6,26 @@ import type {NextRequest} from 'next/server'
|
|
|
6
6
|
import {_readBody as readBody} from './readBody'
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
|
-
export type
|
|
9
|
+
export type ParsedBody<T> = {
|
|
10
10
|
/**
|
|
11
11
|
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
12
12
|
*/
|
|
13
13
|
isValidSignature: boolean | null
|
|
14
|
-
body:
|
|
14
|
+
body: T
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
18
|
+
export type ParseBody<Body = SanityDocument> = ParsedBody<Body>
|
|
16
19
|
/**
|
|
17
20
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
18
21
|
* without worrying about getting stale data.
|
|
19
22
|
* @public
|
|
20
23
|
*/
|
|
21
|
-
export async function parseBody(
|
|
24
|
+
export async function parseBody<Body = SanityDocument>(
|
|
22
25
|
req: NextApiRequest,
|
|
23
26
|
secret?: string,
|
|
24
27
|
waitForContentLakeEventualConsistency: boolean = true,
|
|
25
|
-
): Promise<ParseBody
|
|
28
|
+
): Promise<ParseBody<Body>> {
|
|
26
29
|
let signature = req.headers[SIGNATURE_HEADER_NAME]!
|
|
27
30
|
if (Array.isArray(signature)) {
|
|
28
31
|
signature = signature[0]
|
|
@@ -42,23 +45,17 @@ export async function parseBody(
|
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/** @public */
|
|
45
|
-
export type ParseAppBody =
|
|
46
|
-
/**
|
|
47
|
-
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
48
|
-
*/
|
|
49
|
-
isValidSignature: boolean | null
|
|
50
|
-
body: SanityDocument
|
|
51
|
-
}
|
|
48
|
+
export type ParseAppBody<Body = SanityDocument> = ParsedBody<Body>
|
|
52
49
|
/**
|
|
53
50
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
54
51
|
* without worrying about getting stale data.
|
|
55
52
|
* @public
|
|
56
53
|
*/
|
|
57
|
-
export async function parseAppBody(
|
|
54
|
+
export async function parseAppBody<Body = SanityDocument>(
|
|
58
55
|
req: NextRequest,
|
|
59
56
|
secret?: string,
|
|
60
57
|
waitForContentLakeEventualConsistency: boolean = true,
|
|
61
|
-
): Promise<ParseAppBody
|
|
58
|
+
): Promise<ParseAppBody<Body>> {
|
|
62
59
|
const signature = req.headers.get(SIGNATURE_HEADER_NAME)!
|
|
63
60
|
|
|
64
61
|
const body = await req.text()
|