@fastaar/nextjs 0.1.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.
- package/README.md +159 -0
- package/dist/actions.cjs +36 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +10 -0
- package/dist/actions.d.ts +10 -0
- package/dist/actions.js +12 -0
- package/dist/actions.js.map +1 -0
- package/dist/client.cjs +145 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +61 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.js +119 -0
- package/dist/client.js.map +1 -0
- package/dist/components.cjs +37 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +21 -0
- package/dist/components.d.ts +21 -0
- package/dist/components.js +13 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +17 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +129 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook.cjs +79 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +28 -0
- package/dist/webhook.d.ts +28 -0
- package/dist/webhook.js +44 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhook.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport { WebhookEvent } from './types';\n\n/**\n * Verify the X-Fastaar-Signature header (`t=<ts>,v1=<hmac>`) against the\n * raw request body using your merchant webhook secret.\n *\n * @param secret Your merchant webhook secret\n * @param rawBody The raw request body string or Buffer\n * @param signatureHeader The value of the X-Fastaar-Signature header\n * @param toleranceSeconds Allowed drift in seconds. Defaults to 300 (5 minutes).\n * @returns boolean\n */\nexport function verifyWebhookSignature(\n secret: string,\n rawBody: string | Buffer,\n signatureHeader: string | null | undefined,\n toleranceSeconds = 300\n): boolean {\n const match = /^t=(\\d+),v1=([a-f0-9]{64})$/.exec(signatureHeader ?? '');\n\n if (!match) {\n return false;\n }\n\n const timestamp = Number(match[1]);\n\n if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) {\n return false;\n }\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(`${timestamp}.${rawBody}`)\n .digest('hex');\n\n try {\n return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(match[2]));\n } catch {\n return false;\n }\n}\n\n/**\n * Verifies and parses a webhook event request from a Next.js App Router Route Handler.\n * It automatically reads the request's raw text body, verifies the signature, and\n * returns the parsed event object.\n *\n * @param req The Request (or NextRequest) object from the Route Handler\n * @param secret The webhook secret. Defaults to process.env.FASTAAR_WEBHOOK_SECRET.\n * @returns {Promise<{ isValid: boolean; event: WebhookEvent | null }>}\n */\nexport async function verifyNextWebhook(\n req: Request,\n secret?: string\n): Promise<{ isValid: boolean; event: WebhookEvent | null }> {\n const webhookSecret = secret ?? process.env.FASTAAR_WEBHOOK_SECRET;\n if (!webhookSecret) {\n throw new Error('Fastaar webhook secret is required for verification.');\n }\n\n const signature = req.headers.get('x-fastaar-signature') || req.headers.get('X-Fastaar-Signature');\n if (!signature) {\n return { isValid: false, event: null };\n }\n\n try {\n // Clone the request to avoid locking the stream if accessed again\n const clonedReq = req.clone();\n const rawBody = await clonedReq.text();\n\n const isValid = verifyWebhookSignature(webhookSecret, rawBody, signature);\n if (!isValid) {\n return { isValid: false, event: null };\n }\n\n const event = JSON.parse(rawBody) as WebhookEvent;\n return { isValid: true, event };\n } catch {\n return { isValid: false, event: null };\n }\n}\n"],"mappings":"AAAA,OAAO,YAAY;AAaZ,SAAS,uBACd,QACA,SACA,iBACA,mBAAmB,KACV;AACT,QAAM,QAAQ,8BAA8B,KAAK,mBAAmB,EAAE;AAEtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,MAAM,CAAC,CAAC;AAEjC,MAAI,KAAK,IAAI,KAAK,IAAI,IAAI,MAAO,SAAS,IAAI,kBAAkB;AAC9D,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,OACd,WAAW,UAAU,MAAM,EAC3B,OAAO,GAAG,SAAS,IAAI,OAAO,EAAE,EAChC,OAAO,KAAK;AAEf,MAAI;AACF,WAAO,OAAO,gBAAgB,OAAO,KAAK,QAAQ,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC;AAAA,EAC5E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAWA,eAAsB,kBACpB,KACA,QAC2D;AAC3D,QAAM,gBAAgB,UAAU,QAAQ,IAAI;AAC5C,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB,KAAK,IAAI,QAAQ,IAAI,qBAAqB;AACjG,MAAI,CAAC,WAAW;AACd,WAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,EACvC;AAEA,MAAI;AAEF,UAAM,YAAY,IAAI,MAAM;AAC5B,UAAM,UAAU,MAAM,UAAU,KAAK;AAErC,UAAM,UAAU,uBAAuB,eAAe,SAAS,SAAS;AACxE,QAAI,CAAC,SAAS;AACZ,aAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,IACvC;AAEA,UAAM,QAAQ,KAAK,MAAM,OAAO;AAChC,WAAO,EAAE,SAAS,MAAM,MAAM;AAAA,EAChC,QAAQ;AACN,WAAO,EAAE,SAAS,OAAO,OAAO,KAAK;AAAA,EACvC;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fastaar/nextjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Next.js React Server Components & Route Handlers integration for Fastaar payment gateway",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"dev": "tsup --watch",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"next": ">=13.0.0",
|
|
30
|
+
"react": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^20.11.0",
|
|
34
|
+
"@types/react": "^18.2.48",
|
|
35
|
+
"next": "^14.1.0",
|
|
36
|
+
"react": "^18.2.0",
|
|
37
|
+
"tsup": "^8.0.1",
|
|
38
|
+
"typescript": "^5.3.3"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"fastaar",
|
|
42
|
+
"bkash",
|
|
43
|
+
"nagad",
|
|
44
|
+
"payments",
|
|
45
|
+
"bangladesh",
|
|
46
|
+
"nextjs",
|
|
47
|
+
"server-components",
|
|
48
|
+
"react-server-components"
|
|
49
|
+
]
|
|
50
|
+
}
|