@webiny/sdk 6.4.0-beta.7 → 6.4.1-beta.0
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.
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
export interface WebhookSignPayloadHeaders {
|
|
3
|
+
"webhook-id": string;
|
|
4
|
+
"webhook-timestamp": string;
|
|
5
|
+
"webhook-signature": string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createVerifyWebhookPayload: (secret: string | undefined) => <T>(rawBody: string | Buffer, headers: WebhookSignPayloadHeaders) => Promise<Result<never, any> | Result<T, never>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Webhook } from "standardwebhooks";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
if ("u" < typeof process || void 0 === process.versions?.node) throw new Error("@webiny/sdk/webhooks is only available in Node.js environments.");
|
|
4
|
+
const createVerifyWebhookPayload = (secret)=>{
|
|
5
|
+
if (!secret) return async ()=>{
|
|
6
|
+
throw new Error("Signing secret is not defined.");
|
|
7
|
+
};
|
|
8
|
+
return async (rawBody, headers)=>{
|
|
9
|
+
try {
|
|
10
|
+
const wh = new Webhook(secret);
|
|
11
|
+
const payload = wh.verify(rawBody, headers);
|
|
12
|
+
return Result.ok(payload);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return Result.fail(error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export { createVerifyWebhookPayload };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=verifyWebhookPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods/webhooks/verifyWebhookPayload.js","sources":["../../../src/methods/webhooks/verifyWebhookPayload.ts"],"sourcesContent":["/*\n * This is a node only file, as it uses the \"standardwebhooks\" package which is not compatible with browsers.\n * NEVER import into UI or export alongside ui-facing code.\n */\nif (typeof process === \"undefined\" || typeof process.versions?.node === \"undefined\") {\n throw new Error(\"@webiny/sdk/webhooks is only available in Node.js environments.\");\n}\n\nimport { Webhook } from \"standardwebhooks\";\nimport { Result } from \"~/Result.js\";\n\nexport interface WebhookSignPayloadHeaders {\n \"webhook-id\": string;\n \"webhook-timestamp\": string;\n \"webhook-signature\": string;\n}\n\nexport const createVerifyWebhookPayload = (secret: string | undefined) => {\n if (!secret) {\n return async () => {\n throw new Error(\"Signing secret is not defined.\");\n };\n }\n\n return async <T>(rawBody: string | Buffer, headers: WebhookSignPayloadHeaders) => {\n try {\n const wh = new Webhook(secret);\n const payload = wh.verify(rawBody, headers) as T;\n return Result.ok<T>(payload);\n } catch (error) {\n return Result.fail(error);\n }\n };\n};\n"],"names":["process","Error","createVerifyWebhookPayload","secret","rawBody","headers","wh","Webhook","payload","Result","error"],"mappings":";;AAIA,IAAI,AAAmB,MAAnB,OAAOA,WAA2B,AAAkC,WAA3BA,QAAQ,QAAQ,EAAE,MAC3D,MAAM,IAAIC,MAAM;AAYb,MAAMC,6BAA6B,CAACC;IACvC,IAAI,CAACA,QACD,OAAO;QACH,MAAM,IAAIF,MAAM;IACpB;IAGJ,OAAO,OAAUG,SAA0BC;QACvC,IAAI;YACA,MAAMC,KAAK,IAAIC,QAAQJ;YACvB,MAAMK,UAAUF,GAAG,MAAM,CAACF,SAASC;YACnC,OAAOI,OAAO,EAAE,CAAID;QACxB,EAAE,OAAOE,OAAO;YACZ,OAAOD,OAAO,IAAI,CAACC;QACvB;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/sdk",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.1-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./index.js"
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./webhooks": "./methods/webhooks/verifyWebhookPayload.js"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"p-map": "7.0.4",
|
|
14
15
|
"p-retry": "8.0.0",
|
|
16
|
+
"standardwebhooks": "1.0.0",
|
|
15
17
|
"zod": "4.4.3"
|
|
16
18
|
},
|
|
17
19
|
"author": "Webiny",
|
|
18
20
|
"license": "MIT",
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"@webiny/build-tools": "6.4.
|
|
22
|
+
"@webiny/build-tools": "6.4.1-beta.0",
|
|
21
23
|
"typescript": "6.0.3",
|
|
22
24
|
"vitest": "4.1.7"
|
|
23
25
|
},
|