@alantiller/directus-extension-stripe 1.0.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/dist/api.js +1 -0
- package/dist/app.js +1 -0
- package/package.json +49 -0
package/dist/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:crypto";const t=[{name:"stripe-hook",config:({init:e})=>{global.__stripeRawBodies||(global.__stripeRawBodies=new Map),e("middlewares.before",({app:e})=>{e.use((e,t,r)=>{const o=e.headers["stripe-signature"];if(!o)return r();const i=[];e.on("data",e=>i.push(e)),e.on("end",()=>{const t=Buffer.concat(i);global.__stripeRawBodies.set(o,{body:t,timestamp:Date.now()});const s=Date.now()-3e5;for(const[e,t]of global.__stripeRawBodies)t.timestamp<s&&global.__stripeRawBodies.delete(e);try{e.body=JSON.parse(t.toString("utf8"))}catch(t){e.body={}}e._body=!0,r()})})})}}],r=[],o=[{name:"stripe-operation",config:{id:"stripe-verify-signature",handler:({webhook_secret:t},{data:r,logger:o})=>{const i=r.$trigger,s=i?.headers?.["stripe-signature"];if(!s)throw new Error("Missing stripe-signature header on the incoming request.");if(!t)throw new Error("Webhook signing secret is required.");const n=global.__stripeRawBodies?.get(s);if(!n)throw new Error("Raw request body not found. Make sure the stripe-hook is enabled and running in this bundle.");const a=n.body.toString("utf8");global.__stripeRawBodies.delete(s);const d=s.split(","),p=d.find(e=>e.startsWith("t="))?.split("=")[1],f=d.filter(e=>e.startsWith("v1=")).map(e=>e.split("=").slice(1).join("="));if(!p||0===f.length)throw new Error("Invalid stripe-signature header format.");const l=`${p}.${a}`,h=e.createHmac("sha256",t).update(l,"utf8").digest("hex");if(!f.some(t=>{try{return e.timingSafeEqual(Buffer.from(h,"hex"),Buffer.from(t,"hex"))}catch{return!1}}))throw new Error("Stripe signature verification failed.");const c=Math.floor(Date.now()/1e3);if(Math.abs(c-parseInt(p,10))>300)throw new Error("Stripe webhook timestamp is outside the tolerance zone.");return o.info("Stripe webhook signature verified successfully."),JSON.parse(a)}}}];export{r as endpoints,t as hooks,o as operations};
|
package/dist/app.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=[],i=[],t=[],o=[],n=[],r=[],s=[{id:"stripe-verify-signature",name:"Verify Stripe Signature",icon:"verified_user",description:"Verifies the Stripe webhook signature using the raw request body and your endpoint signing secret.",overview:({webhook_secret:e})=>[{label:"Webhook Secret",text:e?"••••••••":"Not configured"}],options:[{field:"webhook_secret",name:"Webhook Signing Secret",type:"string",meta:{width:"full",interface:"input",note:"Your Stripe webhook endpoint signing secret (whsec_…). Supports dynamic values like {{$env.STRIPE_WEBHOOK_SECRET}}.",options:{masked:!0}}}]}];export{i as displays,e as interfaces,t as layouts,o as modules,s as operations,n as panels,r as themes};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alantiller/directus-extension-stripe",
|
|
3
|
+
"description": "A simple Directus extension that adds an operation to verify the Stripe webhook signature.",
|
|
4
|
+
"icon": "extension",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"directus",
|
|
8
|
+
"directus-extension",
|
|
9
|
+
"directus-extension-bundle"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"directus:extension": {
|
|
16
|
+
"type": "bundle",
|
|
17
|
+
"path": {
|
|
18
|
+
"app": "dist/app.js",
|
|
19
|
+
"api": "dist/api.js"
|
|
20
|
+
},
|
|
21
|
+
"entries": [
|
|
22
|
+
{
|
|
23
|
+
"type": "hook",
|
|
24
|
+
"name": "stripe-hook",
|
|
25
|
+
"source": "src/stripe-hook/index.js"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "operation",
|
|
29
|
+
"name": "stripe-operation",
|
|
30
|
+
"source": {
|
|
31
|
+
"app": "src/stripe-operation/app.js",
|
|
32
|
+
"api": "src/stripe-operation/api.js"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"host": "^10.10.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "directus-extension build",
|
|
40
|
+
"dev": "directus-extension build -w --no-minify",
|
|
41
|
+
"link": "directus-extension link",
|
|
42
|
+
"validate": "directus-extension validate",
|
|
43
|
+
"add": "directus-extension add"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@directus/extensions-sdk": "17.0.10",
|
|
47
|
+
"vue": "^3.5.29"
|
|
48
|
+
}
|
|
49
|
+
}
|