@zyphe-sdk/core 0.1.12 → 0.1.14
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/index.d.ts +409 -805
- package/dist/index.js +1068 -0
- package/dist/index.js.map +1 -1
- package/dist/openapi.d.ts +139 -2
- package/dist/openapi.json +209 -4
- package/package.json +17 -11
- package/.turbo/turbo-build.log +0 -22
- package/dist/index.cjs +0 -181
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1685
- package/docs/express.md +0 -45
- package/docs/fastify.md +0 -85
- package/docs/hono.md +0 -32
- package/public/openapi.d.ts +0 -959
- package/public/openapi.json +0 -3094
- package/scripts/generate-openapi.ts +0 -70
- package/src/client.ts +0 -10
- package/src/constants.ts +0 -29
- package/src/index.ts +0 -4
- package/src/types.ts +0 -82
- package/src/verification-session.ts +0 -94
- package/src/webhook.ts +0 -104
- package/tsconfig.json +0 -32
- package/tsup.config.ts +0 -11
package/docs/express.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# Integrate with ExpressJs
|
|
2
|
-
|
|
3
|
-
```typescript
|
|
4
|
-
import express from "express";
|
|
5
|
-
import { expressWebhookSignatureVerifierMiddleware } from "@zyphe-sdk/core/webhook/middlewares/express";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
|
-
|
|
8
|
-
dotenv.config();
|
|
9
|
-
const app = express();
|
|
10
|
-
const port = 3001;
|
|
11
|
-
const secretHex = process.env.WEBHOOK_SECRET ?? "";
|
|
12
|
-
|
|
13
|
-
// Use the webhook signature verification middleware
|
|
14
|
-
app.post(
|
|
15
|
-
"/webhook",
|
|
16
|
-
express.raw({ type: "application/json" }), // Make sure you extract the raw body that is required for proper signature validation
|
|
17
|
-
expressWebhookSignatureVerifierMiddleware({
|
|
18
|
-
secretHex,
|
|
19
|
-
signatureHeader: "x-signature",
|
|
20
|
-
}),
|
|
21
|
-
(req, res) => {
|
|
22
|
-
// At this point, the webhook signature has been verified
|
|
23
|
-
// and the request body is available as req.body (parsed JSON)
|
|
24
|
-
// and req.rawBody (raw string) if exposeRawBody is true (default)
|
|
25
|
-
|
|
26
|
-
console.log("Webhook received with a valid signature");
|
|
27
|
-
|
|
28
|
-
res.json({
|
|
29
|
-
success: true,
|
|
30
|
-
message: "Webhook processed successfully",
|
|
31
|
-
receivedData: req.body,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// Health check endpoint
|
|
37
|
-
app.get("/health", (req, res) => {
|
|
38
|
-
res.json({ status: "ok", service: "express-webhook-example" });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
app.listen(port, () => {
|
|
42
|
-
console.log(`Express server is running on http://localhost:${port}`);
|
|
43
|
-
console.log(`Send POST requests to http://localhost:${port}/webhook`);
|
|
44
|
-
console.log(`Health check available at http://localhost:${port}/health`);
|
|
45
|
-
});
|
package/docs/fastify.md
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Integrate with FastifyJs
|
|
2
|
-
|
|
3
|
-
```typescript
|
|
4
|
-
import Fastify from "fastify";
|
|
5
|
-
import fastifyWebhookSignatureVerifierPlugin from "@zyphe-sdk/core/webhook/middlewares/fastify";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
|
-
|
|
8
|
-
dotenv.config();
|
|
9
|
-
const secretHex = process.env.WEBHOOK_SECRET ?? "";
|
|
10
|
-
console.log("Starting with secret:", secretHex);
|
|
11
|
-
|
|
12
|
-
// Extend FastifyRequest interface to include rawBody
|
|
13
|
-
declare module "fastify" {
|
|
14
|
-
interface FastifyRequest {
|
|
15
|
-
rawBody?: string;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const fastify = Fastify({
|
|
20
|
-
logger: true,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Register the webhook signature verification plugin
|
|
24
|
-
await fastify.register(fastifyWebhookSignatureVerifierPlugin, {
|
|
25
|
-
secretHex,
|
|
26
|
-
signatureHeader: "x-signature",
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Webhook endpoint
|
|
30
|
-
fastify.post("/webhook", async (request, reply) => {
|
|
31
|
-
// At this point, the webhook signature has been verified
|
|
32
|
-
// and the request body is available as request.body (parsed JSON)
|
|
33
|
-
// and request.rawBody (raw string) if exposeRawBody is true (default)
|
|
34
|
-
|
|
35
|
-
fastify.log.info("Webhook received:", request.body);
|
|
36
|
-
fastify.log.info("Raw body:", request.rawBody);
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
success: true,
|
|
40
|
-
message: "Webhook processed successfully",
|
|
41
|
-
receivedData: request.body,
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Health check endpoint
|
|
46
|
-
fastify.get("/health", async (request, reply) => {
|
|
47
|
-
return { status: "ok", service: "fastify-webhook-example" };
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Start the server
|
|
51
|
-
try {
|
|
52
|
-
await fastify.listen({ port: 3001, host: "0.0.0.0" });
|
|
53
|
-
console.log("Fastify server is running on http://localhost:3000");
|
|
54
|
-
console.log("Send POST requests to http://localhost:3000/webhook");
|
|
55
|
-
console.log("Health check available at http://localhost:3000/health");
|
|
56
|
-
} catch (err) {
|
|
57
|
-
fastify.log.error(err);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Features
|
|
63
|
-
|
|
64
|
-
- Automatic webhook signature verification
|
|
65
|
-
- Raw body access for request processing
|
|
66
|
-
- Customizable unauthorized handler
|
|
67
|
-
- Support for route-specific middleware application
|
|
68
|
-
- TypeScript support out of the box
|
|
69
|
-
|
|
70
|
-
## Configuration Options
|
|
71
|
-
|
|
72
|
-
The webhook verifier plugin accepts the following options:
|
|
73
|
-
|
|
74
|
-
- `secretHex` (required): The hex-encoded secret key used to verify the signature
|
|
75
|
-
- `signatureHeader` (optional): The name of the header containing the signature (defaults to "x-signature")
|
|
76
|
-
- `exposeRawBody` (optional): Whether to make the raw body available on request.rawBody (defaults to true)
|
|
77
|
-
- `onUnauthorized` (optional): Custom function to handle unauthorized requests
|
|
78
|
-
|
|
79
|
-
## Security Notes
|
|
80
|
-
|
|
81
|
-
- Always use a strong, randomly generated secret key
|
|
82
|
-
- Keep your secret key secure and never expose it in client-side code
|
|
83
|
-
- The middleware uses constant-time comparison to prevent timing attacks
|
|
84
|
-
- The raw body is preserved for signature verification before any parsing occurs
|
|
85
|
-
|
package/docs/hono.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Integrate with Hono
|
|
2
|
-
|
|
3
|
-
```typescript
|
|
4
|
-
import { serve } from "@hono/node-server";
|
|
5
|
-
import { Hono } from "hono";
|
|
6
|
-
import { honoWebhookSignatureVerifierMiddleware } from "@zyphe-sdk/core/webhook/middlewares/hono";
|
|
7
|
-
import dotenv from "dotenv";
|
|
8
|
-
|
|
9
|
-
dotenv.config();
|
|
10
|
-
const secretHex = process.env.WEBHOOK_SECRET ?? "";
|
|
11
|
-
console.log("Starting with secret:", secretHex);
|
|
12
|
-
|
|
13
|
-
const app = new Hono();
|
|
14
|
-
|
|
15
|
-
app.post(
|
|
16
|
-
"/webhook",
|
|
17
|
-
honoWebhookSignatureVerifierMiddleware({
|
|
18
|
-
secretHex,
|
|
19
|
-
signatureHeader: "x-signature",
|
|
20
|
-
}),
|
|
21
|
-
async (c) => c.text("Hello Hono!")
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
serve(
|
|
25
|
-
{
|
|
26
|
-
fetch: app.fetch,
|
|
27
|
-
port: 3001,
|
|
28
|
-
},
|
|
29
|
-
(info) => {
|
|
30
|
-
console.log(`Server is running on http://localhost:${info.port}`);
|
|
31
|
-
}
|
|
32
|
-
);
|