diff --git a/pledge-now-pay-later/package-lock.json b/pledge-now-pay-later/package-lock.json index 0a06b1f..d4eb338 100644 --- a/pledge-now-pay-later/package-lock.json +++ b/pledge-now-pay-later/package-lock.json @@ -28,9 +28,11 @@ "qrcode": "^1.5.4", "react": "^18", "react-dom": "^18", + "resend": "^6.9.3", "sharp": "^0.34.5", "stripe": "^20.4.0", "tailwind-merge": "^3.5.0", + "twilio": "^5.12.2", "zod": "^4.3.6" }, "devDependencies": { @@ -1788,6 +1790,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@stablelib/base64": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stablelib/base64/-/base64-1.0.1.tgz", + "integrity": "sha512-1bnPQqSxSuc3Ii6MhBysoWCg58j97aUjuCSZrGSmDxNqtytIi0k8utUenAwTZN4V5mXXYGsVUI9zeBqy+jBOSQ==", + "license": "MIT" + }, "node_modules/@standard-schema/spec": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", @@ -2493,6 +2501,18 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/ajv": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", @@ -2756,6 +2776,12 @@ "node": ">= 0.4" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2791,6 +2817,17 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.6.tgz", + "integrity": "sha512-ChTCHMouEe2kn713WHbQGcuYrr6fXTBiu460OTwWrWob16g1bXn4vtz07Ope7ewMozJAnEquLk5lWQWtBig9DQ==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.11", + "form-data": "^4.0.5", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz", @@ -2854,6 +2891,12 @@ "node": ">=8" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -2953,7 +2996,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -2967,7 +3009,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -3197,6 +3238,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -3342,11 +3395,16 @@ "url": "https://github.com/sponsors/kossnocorp" } }, + "node_modules/dayjs": { + "version": "1.11.19", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.19.tgz", + "integrity": "sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==", + "license": "MIT" + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -3427,6 +3485,15 @@ "integrity": "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==", "license": "MIT" }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/denque": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", @@ -3500,7 +3567,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.1", @@ -3518,6 +3584,15 @@ "dev": true, "license": "MIT" }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/effect": { "version": "3.18.4", "resolved": "https://registry.npmjs.org/effect/-/effect-3.18.4.tgz", @@ -3617,7 +3692,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -3627,7 +3701,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -3665,7 +3738,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0" @@ -3678,7 +3750,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -4311,6 +4382,12 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-sha256": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-sha256/-/fast-sha256-1.3.0.tgz", + "integrity": "sha512-n11RGP/lrWEFI/bWdygLxhI+pVeo1ZYIVwvvPkW7azl/rOy+F3HYRZ2K5zeE9mmkhQppyv9sQFx0JM9UabnpPQ==", + "license": "Unlicense" + }, "node_modules/fastq": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz", @@ -4386,6 +4463,26 @@ "dev": true, "license": "ISC" }, + "node_modules/follow-redirects": { + "version": "1.15.11", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", + "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz", @@ -4418,6 +4515,22 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -4444,7 +4557,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -4513,7 +4625,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -4544,7 +4655,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "dev": true, "license": "MIT", "dependencies": { "dunder-proto": "^1.0.1", @@ -4702,7 +4812,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -4792,7 +4901,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -4805,7 +4913,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -4821,7 +4928,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -4846,6 +4952,19 @@ "integrity": "sha512-RJ8XvFvpPM/Dmc5SV+dC4y5PCeOhT3x1Hq0NU3rjGeg5a/CqlhZ7uudknPwZFz4aeAXDcbAyaeP7GAo9lvngtA==", "license": "MIT" }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/iconv-lite": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", @@ -5496,6 +5615,28 @@ "json5": "lib/cli.js" } }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "license": "MIT", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, "node_modules/jsx-ast-utils": { "version": "3.3.5", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz", @@ -5512,6 +5653,27 @@ "node": ">=4.0" } }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -5598,6 +5760,42 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "license": "MIT" }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "license": "MIT" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -5605,6 +5803,12 @@ "dev": true, "license": "MIT" }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, "node_modules/long": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", @@ -5658,7 +5862,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -5688,6 +5891,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", @@ -5725,7 +5949,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/mysql2": { @@ -6039,7 +6262,6 @@ "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6537,6 +6759,12 @@ "node": ">= 0.4" } }, + "node_modules/postal-mime": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/postal-mime/-/postal-mime-2.7.3.tgz", + "integrity": "sha512-MjhXadAJaWgYzevi46+3kLak8y6gbg0ku14O1gO/LNOuay8dO+1PtcSGvAdgDR0DoIsSaiIA8y/Ddw6MnrO0Tw==", + "license": "MIT-0" + }, "node_modules/postcss": { "version": "8.5.6", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", @@ -6874,6 +7102,12 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "license": "ISC" }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -6917,6 +7151,21 @@ "node": ">=10.13.0" } }, + "node_modules/qs": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", + "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -7079,6 +7328,27 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "license": "ISC" }, + "node_modules/resend": { + "version": "6.9.3", + "resolved": "https://registry.npmjs.org/resend/-/resend-6.9.3.tgz", + "integrity": "sha512-GRXjH9XZBJA+daH7bBVDuTShr22iWCxXA8P7t495G4dM/RC+d+3gHBK/6bz9K6Vpcq11zRQKmD+B+jECwQlyGQ==", + "license": "MIT", + "dependencies": { + "postal-mime": "2.7.3", + "svix": "1.84.1" + }, + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "@react-email/render": "*" + }, + "peerDependenciesMeta": { + "@react-email/render": { + "optional": true + } + } + }, "node_modules/resolve": { "version": "1.22.11", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.11.tgz", @@ -7223,6 +7493,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/safe-push-apply": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/safe-push-apply/-/safe-push-apply-1.0.0.tgz", @@ -7273,6 +7563,13 @@ "loose-envify": "^1.1.0" } }, + "node_modules/scmp": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/scmp/-/scmp-2.1.0.tgz", + "integrity": "sha512-o/mRQGk9Rcer/jEEw/yw4mwo3EU/NvYvp577/Btqrym9Qy5/MdWGBqipbALgd2lrdWTJ5/gqDusxfnQBxOxT2Q==", + "deprecated": "Just use Node.js's crypto.timingSafeEqual()", + "license": "BSD-3-Clause" + }, "node_modules/semver": { "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", @@ -7414,7 +7711,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -7434,7 +7730,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -7451,7 +7746,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -7470,7 +7764,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "dev": true, "license": "MIT", "dependencies": { "call-bound": "^1.0.2", @@ -7532,6 +7825,16 @@ "dev": true, "license": "MIT" }, + "node_modules/standardwebhooks": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/standardwebhooks/-/standardwebhooks-1.0.0.tgz", + "integrity": "sha512-BbHGOQK9olHPMvQNHWul6MYlrRTAOKn03rOe4A8O3CLWhNf4YHBqq2HJKKC+sfqpxiBY52pNeesD6jIiLDz8jg==", + "license": "MIT", + "dependencies": { + "@stablelib/base64": "^1.0.0", + "fast-sha256": "^1.3.0" + } + }, "node_modules/std-env": { "version": "3.10.0", "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", @@ -7881,6 +8184,29 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/svix": { + "version": "1.84.1", + "resolved": "https://registry.npmjs.org/svix/-/svix-1.84.1.tgz", + "integrity": "sha512-K8DPPSZaW/XqXiz1kEyzSHYgmGLnhB43nQCMeKjWGCUpLIpAMMM8kx3rVVOSm6Bo6EHyK1RQLPT4R06skM/MlQ==", + "license": "MIT", + "dependencies": { + "standardwebhooks": "1.0.0", + "uuid": "^10.0.0" + } + }, + "node_modules/svix/node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/tailwind-merge": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.5.0.tgz", @@ -8090,6 +8416,24 @@ "fsevents": "~2.3.3" } }, + "node_modules/twilio": { + "version": "5.12.2", + "resolved": "https://registry.npmjs.org/twilio/-/twilio-5.12.2.tgz", + "integrity": "sha512-yjTH04Ig0Z3PAxIXhwrto0IJC4Gv7lBDQQ9f4/P9zJhnxVdd+3tENqBMJOtdmmRags3X0jl2IGKEQefCEpJE9g==", + "license": "MIT", + "dependencies": { + "axios": "^1.12.0", + "dayjs": "^1.11.9", + "https-proxy-agent": "^5.0.0", + "jsonwebtoken": "^9.0.2", + "qs": "^6.14.1", + "scmp": "^2.1.0", + "xmlbuilder": "^13.0.2" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -8537,6 +8881,15 @@ "dev": true, "license": "ISC" }, + "node_modules/xmlbuilder": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-13.0.2.tgz", + "integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==", + "license": "MIT", + "engines": { + "node": ">=6.0" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/pledge-now-pay-later/package.json b/pledge-now-pay-later/package.json index 985e6ad..f0517dc 100644 --- a/pledge-now-pay-later/package.json +++ b/pledge-now-pay-later/package.json @@ -29,9 +29,11 @@ "qrcode": "^1.5.4", "react": "^18", "react-dom": "^18", + "resend": "^6.9.3", "sharp": "^0.34.5", "stripe": "^20.4.0", "tailwind-merge": "^3.5.0", + "twilio": "^5.12.2", "zod": "^4.3.6" }, "devDependencies": { diff --git a/pledge-now-pay-later/prisma/schema.prisma b/pledge-now-pay-later/prisma/schema.prisma index 81e5f01..c7296f1 100644 --- a/pledge-now-pay-later/prisma/schema.prisma +++ b/pledge-now-pay-later/prisma/schema.prisma @@ -25,6 +25,14 @@ model Organization { gcEnvironment String @default("sandbox") stripeSecretKey String? stripeWebhookSecret String? + emailProvider String? // resend, sendgrid, smtp + emailApiKey String? + emailFromAddress String? // e.g. donations@mymosque.org + emailFromName String? // e.g. "Al Furqan Mosque" + smsProvider String? // twilio + smsAccountSid String? + smsAuthToken String? + smsFromNumber String? // e.g. +447123456789 whatsappConnected Boolean @default(false) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/pledge-now-pay-later/src/app/api/messaging/status/route.ts b/pledge-now-pay-later/src/app/api/messaging/status/route.ts new file mode 100644 index 0000000..4db90d8 --- /dev/null +++ b/pledge-now-pay-later/src/app/api/messaging/status/route.ts @@ -0,0 +1,31 @@ +import { NextResponse } from "next/server" +import { getOrgChannels, getChannelStats, getMessageHistory, getPendingReminders } from "@/lib/messaging" +import { getOrgId } from "@/lib/session" + +/** + * GET /api/messaging/status + * + * Returns everything the Automations dashboard needs: + * - Channel availability (which channels are live) + * - Stats (messages sent/failed per channel, last 7 days) + * - Message history (recent 50) + * - Pending reminders (next 20 scheduled) + */ +export async function GET(request: Request) { + try { + const orgId = await getOrgId(request.headers.get("x-org-id")) + if (!orgId) return NextResponse.json({ error: "Org not found" }, { status: 404 }) + + const [channels, stats, history, pending] = await Promise.all([ + getOrgChannels(orgId), + getChannelStats(orgId, 7), + getMessageHistory(orgId, 50), + getPendingReminders(orgId, 20), + ]) + + return NextResponse.json({ channels, stats, history, pending }) + } catch (error) { + console.error("Messaging status error:", error) + return NextResponse.json({ error: "Internal error" }, { status: 500 }) + } +} diff --git a/pledge-now-pay-later/src/app/api/messaging/test/route.ts b/pledge-now-pay-later/src/app/api/messaging/test/route.ts new file mode 100644 index 0000000..aee0110 --- /dev/null +++ b/pledge-now-pay-later/src/app/api/messaging/test/route.ts @@ -0,0 +1,55 @@ +import { NextRequest, NextResponse } from "next/server" +import { sendToDonor, getOrgChannels } from "@/lib/messaging" +import { getUser } from "@/lib/session" + +/** + * POST /api/messaging/test + * + * Send a test message to the admin's own phone/email + * to verify channel configuration. + */ +export async function POST(request: NextRequest) { + try { + const user = await getUser() + if (!user) return NextResponse.json({ error: "Not authenticated" }, { status: 401 }) + + const body = await request.json() + const { channel } = body // "whatsapp", "email", "sms", or "auto" + + const channels = await getOrgChannels(user.orgId) + + // Determine test destination + const testPhone = body.phone || "" + const testEmail = body.email || user.email + + const testMsg = `๐Ÿงช Test from ${user.orgName || "PNPL"}\n\nThis is a test message to confirm your ${channel || "messaging"} integration is working.\n\nIf you received this, you're all set! ๐ŸŽ‰` + + const result = await sendToDonor({ + donorPhone: channel === "email" ? null : testPhone, + donorEmail: channel === "sms" || channel === "whatsapp" ? null : testEmail, + donorName: user.name || "Test", + whatsappOptIn: true, + emailOptIn: true, + messageType: "test", + subject: `Test message from ${user.orgName || "PNPL"}`, + whatsappText: testMsg, + emailText: testMsg, + smsText: `Test from ${user.orgName || "PNPL"}: Your messaging integration is working! ๐ŸŽ‰`, + orgId: user.orgId, + }) + + return NextResponse.json({ + success: result.success, + channel: result.channel, + error: result.error, + channelsAvailable: { + whatsapp: channels.whatsapp, + email: !!channels.email, + sms: !!channels.sms, + }, + }) + } catch (error) { + console.error("Test message error:", error) + return NextResponse.json({ error: "Internal error" }, { status: 500 }) + } +} diff --git a/pledge-now-pay-later/src/app/api/settings/route.ts b/pledge-now-pay-later/src/app/api/settings/route.ts index 1017d89..2224306 100644 --- a/pledge-now-pay-later/src/app/api/settings/route.ts +++ b/pledge-now-pay-later/src/app/api/settings/route.ts @@ -27,6 +27,14 @@ export async function GET(request: NextRequest) { gcEnvironment: org.gcEnvironment, stripeSecretKey: org.stripeSecretKey ? "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข" : "", stripeWebhookSecret: org.stripeWebhookSecret ? "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข" : "", + emailProvider: org.emailProvider || "", + emailApiKey: org.emailApiKey ? "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข" : "", + emailFromAddress: org.emailFromAddress || "", + emailFromName: org.emailFromName || "", + smsProvider: org.smsProvider || "", + smsAccountSid: org.smsAccountSid ? "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข" : "", + smsAuthToken: org.smsAuthToken ? "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข" : "", + smsFromNumber: org.smsFromNumber || "", orgType: org.orgType || "charity", }) } catch (error) { @@ -87,7 +95,7 @@ export async function PATCH(request: NextRequest) { if (!orgId) return NextResponse.json({ error: "Org not found" }, { status: 404 }) const body = await request.json() - const stringKeys = ["name", "bankName", "bankSortCode", "bankAccountNo", "bankAccountName", "refPrefix", "primaryColor", "logo", "gcAccessToken", "gcEnvironment", "stripeSecretKey", "stripeWebhookSecret"] + const stringKeys = ["name", "bankName", "bankSortCode", "bankAccountNo", "bankAccountName", "refPrefix", "primaryColor", "logo", "gcAccessToken", "gcEnvironment", "stripeSecretKey", "stripeWebhookSecret", "emailProvider", "emailApiKey", "emailFromAddress", "emailFromName", "smsProvider", "smsAccountSid", "smsAuthToken", "smsFromNumber"] // eslint-disable-next-line @typescript-eslint/no-explicit-any const data: Record = {} for (const key of stringKeys) { diff --git a/pledge-now-pay-later/src/app/dashboard/automations/page.tsx b/pledge-now-pay-later/src/app/dashboard/automations/page.tsx new file mode 100644 index 0000000..e510424 --- /dev/null +++ b/pledge-now-pay-later/src/app/dashboard/automations/page.tsx @@ -0,0 +1,426 @@ +"use client" + +import { useState, useEffect, useCallback } from "react" +import { formatPence } from "@/lib/utils" +import { + Loader2, MessageCircle, Mail, Smartphone, Check, X, Clock, + ChevronDown, Send, Zap, AlertTriangle, Radio +} from "lucide-react" +import Link from "next/link" + +/** + * /dashboard/automations โ€” "Is it working? What's being sent?" + * + * THIS IS THE STAR OF THE SHOW. + * + * The entire product is an automation engine. Without it, PNPL is + * just a spreadsheet. This page makes the engine VISIBLE. + * + * Aaisha's questions: + * 1. "Are messages actually being sent?" โ†’ Live channel status + * 2. "What did Ahmed receive?" โ†’ Message feed with previews + * 3. "What happens after someone pledges?" โ†’ Visual pipeline + * 4. "Is everything working?" โ†’ Delivery stats + * 5. "What's coming up next?" โ†’ Scheduled reminders + * + * The page has 4 sections: + * A. Hero stats bar (dark) โ€” messages this week, delivery rate + * B. Live channels โ€” which pipes are active + * C. The Pipeline โ€” visual "what happens after a pledge" + * D. Message feed โ€” recent messages with status + */ + +interface ChannelStatus { + whatsapp: boolean + email: { provider: string; fromAddress: string } | null + sms: { provider: string; fromNumber: string } | null +} + +interface ChannelStats { + whatsapp: { sent: number; failed: number } + email: { sent: number; failed: number } + sms: { sent: number; failed: number } + total: number + deliveryRate: number +} + +interface MessageEntry { + id: string; channel: string; messageType: string + donorName: string | null; success: boolean + error: string | null; createdAt: string +} + +interface PendingReminder { + id: string; donorName: string | null; amountPence: number + step: number; channel: string; scheduledAt: string +} + +const CHANNEL_ICONS: Record = { + whatsapp: MessageCircle, email: Mail, sms: Smartphone, +} +const CHANNEL_COLORS: Record = { + whatsapp: "#25D366", email: "#1E40AF", sms: "#F59E0B", +} +const MSG_LABELS: Record = { + receipt: "Receipt", + reminder_1: "Reminder 1", + reminder_2: "Reminder 2", + reminder_3: "Reminder 3", + reminder_4: "Final reminder", + overdue_notice: "Overdue notice", + payment_confirmed: "Payment confirmed", + test: "Test message", +} + +const PIPELINE_STEPS = [ + { + trigger: "Someone pledges", + title: "Receipt", + desc: "Bank details, reference, confirmation", + timing: "Instantly", + messageType: "receipt", + }, + { + trigger: "Day 2", + title: "Gentle reminder", + desc: "\"Just a quick reminder about your pledge...\"", + timing: "If not paid", + messageType: "reminder_1", + }, + { + trigger: "Day 7", + title: "Impact nudge", + desc: "\"Your ยฃX helps fund...\" โ€” why it matters", + timing: "If not paid", + messageType: "reminder_2", + }, + { + trigger: "Day 14", + title: "Final reminder", + desc: "\"This is our final message\" โ€” reply PAID/CANCEL", + timing: "Marks overdue if no response", + messageType: "reminder_3", + }, +] + +export default function AutomationsPage() { + const [loading, setLoading] = useState(true) + const [channels, setChannels] = useState(null) + const [stats, setStats] = useState(null) + const [history, setHistory] = useState([]) + const [pending, setPending] = useState([]) + const [pipelineOpen, setPipelineOpen] = useState(false) + + const load = useCallback(async () => { + try { + const res = await fetch("/api/messaging/status") + const data = await res.json() + if (data.channels) setChannels(data.channels) + if (data.stats) setStats(data.stats) + if (data.history) setHistory(data.history) + if (data.pending) setPending(data.pending) + } catch { /* */ } + setLoading(false) + }, []) + + useEffect(() => { load() }, [load]) + + if (loading) return
+ + const activeChannels = [ + channels?.whatsapp ? "WhatsApp" : null, + channels?.email ? "Email" : null, + channels?.sms ? "SMS" : null, + ].filter(Boolean) + + const noChannels = activeChannels.length === 0 + + return ( +
+ + {/* โ”€โ”€ Header โ”€โ”€ */} +
+

Pledge follow-up engine

+

Automations

+
+ + {/* โ”€โ”€ A. Hero stats (dark) โ”€โ”€ */} +
+

Last 7 days

+
+ {[ + { value: String(stats?.whatsapp.sent || 0), label: "WhatsApp", color: "text-[#25D366]" }, + { value: String(stats?.email.sent || 0), label: "Email", color: "text-[#60A5FA]" }, + { value: String(stats?.sms.sent || 0), label: "SMS", color: "text-[#FBBF24]" }, + { value: String(stats?.total || 0), label: "Total messages", color: "text-white" }, + { value: `${stats?.deliveryRate || 0}%`, label: "Delivered", color: (stats?.deliveryRate || 0) >= 90 ? "text-[#4ADE80]" : "text-[#FBBF24]" }, + ].map(s => ( +
+

{s.value}

+

{s.label}

+
+ ))} +
+
+ + {/* โ”€โ”€ B. Live channels โ”€โ”€ */} +
+
+

Channels

+ + Configure in Settings โ†’ + +
+ + {noChannels ? ( +
+ +

No channels connected

+

Connect WhatsApp, Email, or SMS in Settings to start sending automatic receipts and reminders.

+ + Go to Settings + +
+ ) : ( +
+ {/* WhatsApp */} + + {/* Email */} + + {/* SMS */} + +
+ )} +
+ + {/* โ”€โ”€ C. The Pipeline โ€” what happens after a pledge โ”€โ”€ */} +
+ + + {pipelineOpen && ( +
+ {PIPELINE_STEPS.map((step, i) => ( +
+ {/* Timeline */} +
+
+ {i + 1} +
+ {i < PIPELINE_STEPS.length - 1 && ( +
+ )} +
+ + {/* Content */} +
+
+ {step.trigger} + {step.timing} +
+

{step.title}

+

{step.desc}

+
+ {activeChannels.map((ch, ci) => { + const key = ch!.toLowerCase() as keyof typeof CHANNEL_COLORS + return ( + + {ch} + + ) + })} + {activeChannels.length > 1 && ( + waterfall + )} +
+
+
+ ))} + +
+ Messages try WhatsApp first, then fall back to SMS, then Email. Donors who reply PAID skip all future reminders. +
+
+ )} +
+ + {/* โ”€โ”€ D. Upcoming reminders โ”€โ”€ */} + {pending.length > 0 && ( +
+
+

+ Scheduled ({pending.length}) +

+
+
+ {pending.slice(0, 8).map(r => { + const when = new Date(r.scheduledAt) + const isToday = when.toDateString() === new Date().toDateString() + const isTomorrow = when.toDateString() === new Date(Date.now() + 86400000).toDateString() + const label = isToday ? "Today" : isTomorrow ? "Tomorrow" : when.toLocaleDateString("en-GB", { day: "numeric", month: "short" }) + const stepLabels = ["Receipt", "Reminder 1", "Reminder 2", "Final"] + + return ( +
+
+
+

+ {r.donorName || "Anonymous"} ยท {formatPence(r.amountPence)} ยท {stepLabels[r.step] || `Step ${r.step}`} +

+
+ {label} +
+ ) + })} +
+
+ )} + + {/* โ”€โ”€ E. Recent messages โ”€โ”€ */} +
+
+

+ Recent messages +

+
+ + {history.length === 0 ? ( +
+ +

No messages sent yet. Messages will appear here when donors start pledging.

+
+ ) : ( +
+ {history.map(msg => { + const ChannelIcon = CHANNEL_ICONS[msg.channel] || Mail + const color = CHANNEL_COLORS[msg.channel] || "#999" + const ago = getTimeAgo(new Date(msg.createdAt)) + + return ( +
+ {/* Channel icon */} +
+ +
+ + {/* Content */} +
+

+ {msg.donorName || "Anonymous"} + ยท + {MSG_LABELS[msg.messageType] || msg.messageType} +

+
+ + {/* Status */} + {msg.success ? ( + + ) : ( + + )} + + {/* Time */} + {ago} +
+ ) + })} +
+ )} +
+
+ ) +} + + +// โ”€โ”€โ”€ Channel row โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +function ChannelRow({ name, icon: Icon, color, active, detail, stats, features }: { + name: string; icon: typeof MessageCircle; color: string + active: boolean; detail: string + stats?: { sent: number; failed: number } + features: string[] +}) { + return ( +
+
+
+ +
+
+
+

{name}

+ {active && ( + + Live + + )} +
+

{detail}

+
+ {stats && active && ( +
+

{stats.sent}

+

sent this week

+
+ )} +
+ + {active && ( +
+ {features.map((f, i) => ( + + {f} + + ))} +
+ )} +
+ ) +} + + +// โ”€โ”€โ”€ Helpers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +function getTimeAgo(date: Date): string { + const s = Math.floor((Date.now() - date.getTime()) / 1000) + if (s < 60) return "just now" + if (s < 3600) return `${Math.floor(s / 60)}m ago` + if (s < 86400) return `${Math.floor(s / 3600)}h ago` + if (s < 604800) return `${Math.floor(s / 86400)}d ago` + return date.toLocaleDateString("en-GB", { day: "numeric", month: "short" }) +} diff --git a/pledge-now-pay-later/src/app/dashboard/layout.tsx b/pledge-now-pay-later/src/app/dashboard/layout.tsx index fddb384..136dcae 100644 --- a/pledge-now-pay-later/src/app/dashboard/layout.tsx +++ b/pledge-now-pay-later/src/app/dashboard/layout.tsx @@ -4,7 +4,7 @@ import Link from "next/link" import { usePathname } from "next/navigation" import { useSession, signOut } from "next-auth/react" import { useState, useEffect } from "react" -import { Home, Megaphone, Banknote, FileText, Settings, Plus, LogOut, Shield, AlertTriangle, MessageCircle, Users } from "lucide-react" +import { Home, Megaphone, Banknote, FileText, Settings, Plus, LogOut, Shield, AlertTriangle, MessageCircle, Users, Zap } from "lucide-react" import { cn } from "@/lib/utils" /** @@ -17,6 +17,7 @@ const adminNavItems = [ { href: "/dashboard", label: "Home", icon: Home }, { href: "/dashboard/collect", label: "Collect", icon: Megaphone }, { href: "/dashboard/money", label: "Money", icon: Banknote }, + { href: "/dashboard/automations", label: "Automations", icon: Zap }, { href: "/dashboard/reports", label: "Reports", icon: FileText }, { href: "/dashboard/settings", label: "Settings", icon: Settings }, ] @@ -44,6 +45,7 @@ export default function DashboardLayout({ children }: { children: React.ReactNod if (href === "/dashboard/community") return pathname === "/dashboard/community" || pathname === "/dashboard" if (href === "/dashboard/collect") return pathname.startsWith("/dashboard/collect") || pathname.startsWith("/dashboard/events") if (href === "/dashboard/money") return pathname.startsWith("/dashboard/money") || pathname.startsWith("/dashboard/pledges") || pathname.startsWith("/dashboard/reconcile") + if (href === "/dashboard/automations") return pathname.startsWith("/dashboard/automations") if (href === "/dashboard/reports") return pathname.startsWith("/dashboard/reports") || pathname.startsWith("/dashboard/exports") return pathname.startsWith(href) } diff --git a/pledge-now-pay-later/src/app/dashboard/settings/page.tsx b/pledge-now-pay-later/src/app/dashboard/settings/page.tsx index a36a753..eabc851 100644 --- a/pledge-now-pay-later/src/app/dashboard/settings/page.tsx +++ b/pledge-now-pay-later/src/app/dashboard/settings/page.tsx @@ -6,7 +6,7 @@ import { Check, Loader2, AlertCircle, MessageCircle, Radio, RefreshCw, Smartphone, Wifi, WifiOff, UserPlus, Trash2, Copy, Users, Crown, Eye, Building2, CreditCard, Palette, ChevronRight, - Zap, Pencil + Zap, Pencil, Mail } from "lucide-react" /** @@ -48,6 +48,8 @@ interface OrgSettings { bankAccountName: string; refPrefix: string; primaryColor: string gcAccessToken: string; gcEnvironment: string; orgType: string stripeSecretKey: string; stripeWebhookSecret: string + emailProvider: string; emailApiKey: string; emailFromAddress: string; emailFromName: string + smsProvider: string; smsAccountSid: string; smsAuthToken: string; smsFromNumber: string } interface TeamMember { @@ -364,6 +366,85 @@ export default function SettingsPage() {
+ {/* โ–ธ Email โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */} + } + title="Email" + summary={settings.emailApiKey ? `${settings.emailProvider || "Resend"} ยท ${settings.emailFromAddress}` : "Send receipts and reminders by email"} + isOpen={open === "email"} + onToggle={() => toggle("email")} + optional + saving={saving === "email"} + saved={saved === "email"} + > +
+
+ Send receipts and reminders to donors who don't have WhatsApp. Connect your own email provider โ€” messages come from your domain. +
+
+ +
+ {["resend", "sendgrid"].map(p => ( + + ))} +
+ {(settings.emailProvider || "resend") === "resend" && !settings.emailApiKey && ( +

Free: 3,000 emails/month at resend.com

+ )} +
+ update("emailApiKey", v)} placeholder={settings.emailProvider === "sendgrid" ? "SG.xxxxx" : "re_xxxxx"} type="password" /> +
+ update("emailFromAddress", v)} placeholder="donations@mymosque.org" /> + update("emailFromName", v)} placeholder="Al Furqan Mosque" /> +
+ save("email", { emailProvider: settings.emailProvider || "resend", emailApiKey: settings.emailApiKey || "", emailFromAddress: settings.emailFromAddress || "", emailFromName: settings.emailFromName || "" })} + onCancel={() => setOpen(null)} + /> +
+
+ + {/* โ–ธ SMS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */} + } + title="SMS" + summary={settings.smsAccountSid ? `Twilio ยท ${settings.smsFromNumber}` : "Text reminders for donors without WhatsApp"} + isOpen={open === "sms"} + onToggle={() => toggle("sms")} + optional + saving={saving === "sms"} + saved={saved === "sms"} + > +
+
+ Send SMS reminders via Twilio. Reaches donors who don't have WhatsApp and haven't provided an email. Pay-as-you-go (~3p per SMS). +
+ {!settings.smsAccountSid && ( +
+

Get your Twilio credentials

+
    +
  1. Sign up at twilio.com
  2. +
  3. Copy your Account SID and Auth Token from the dashboard
  4. +
  5. Buy a phone number (or use the trial number)
  6. +
+
+ )} + update("smsAccountSid", v)} placeholder="ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> + update("smsAuthToken", v)} placeholder="Your auth token" type="password" /> + update("smsFromNumber", v)} placeholder="+447123456789" /> + save("sms", { smsProvider: "twilio", smsAccountSid: settings.smsAccountSid || "", smsAuthToken: settings.smsAuthToken || "", smsFromNumber: settings.smsFromNumber || "" })} + onCancel={() => setOpen(null)} + /> +
+
+ {/* โ–ธ Team โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */} {isAdmin && ( { + if (!config.apiKey || !config.fromAddress) { + return { success: false, error: "Email not configured" } + } + + try { + if (config.provider === "resend") { + return await sendViaResend(config, to, subject, text, html) + } + if (config.provider === "sendgrid") { + return await sendViaSendGrid(config, to, subject, text, html) + } + return { success: false, error: `Unknown provider: ${config.provider}` } + } catch (err) { + console.error("[EMAIL]", err) + return { success: false, error: String(err) } + } +} + +async function sendViaResend( + config: EmailConfig, to: string, subject: string, text: string, html?: string +): Promise { + const resend = new Resend(config.apiKey) + const result = await resend.emails.send({ + from: `${config.fromName} <${config.fromAddress}>`, + to: [to], + subject, + text, + html: html || textToHtml(text), + }) + + if (result.error) { + return { success: false, error: result.error.message } + } + return { success: true, messageId: result.data?.id } +} + +async function sendViaSendGrid( + config: EmailConfig, to: string, subject: string, text: string, html?: string +): Promise { + const res = await fetch("https://api.sendgrid.com/v3/mail/send", { + method: "POST", + headers: { + "Authorization": `Bearer ${config.apiKey}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + personalizations: [{ to: [{ email: to }] }], + from: { email: config.fromAddress, name: config.fromName }, + subject, + content: [ + { type: "text/plain", value: text }, + { type: "text/html", value: html || textToHtml(text) }, + ], + }), + }) + + if (res.ok || res.status === 202) { + return { success: true, messageId: res.headers.get("x-message-id") || undefined } + } + const err = await res.text().catch(() => "Unknown error") + return { success: false, error: err } +} + +/** + * Convert plain text to simple HTML email. + */ +function textToHtml(text: string): string { + const escaped = text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/\n/g, "
") + .replace(/\*(.+?)\*/g, "$1") + .replace(/`(.+?)`/g, "$1") + + return `${escaped}` +} diff --git a/pledge-now-pay-later/src/lib/messaging.ts b/pledge-now-pay-later/src/lib/messaging.ts new file mode 100644 index 0000000..54bc5c5 --- /dev/null +++ b/pledge-now-pay-later/src/lib/messaging.ts @@ -0,0 +1,307 @@ +/** + * Unified Messaging Layer + * + * The BRAIN of the automation engine. Routes messages to donors + * across channels with intelligent fallback: + * + * WhatsApp (free, instant, 2-way) + * โ†“ fallback + * SMS (paid, instant, 1-way) + * โ†“ fallback + * Email (free/cheap, delayed, 1-way) + * + * Each message attempt is logged to AnalyticsEvent for the + * Automations dashboard to display. + */ + +import { sendWhatsAppMessage, isWhatsAppReady } from "@/lib/whatsapp" +import { sendEmail } from "@/lib/email" +import { sendSms } from "@/lib/sms" +import prisma from "@/lib/prisma" + +export type Channel = "whatsapp" | "sms" | "email" +export type MessageType = + | "receipt" + | "reminder_1" + | "reminder_2" + | "reminder_3" + | "reminder_4" + | "overdue_notice" + | "payment_confirmed" + | "test" + +interface OrgChannels { + whatsapp: boolean + email: { provider: string; apiKey: string; fromAddress: string; fromName: string } | null + sms: { provider: string; accountSid: string; authToken: string; fromNumber: string } | null +} + +interface SendOptions { + donorPhone?: string | null + donorEmail?: string | null + donorName?: string | null + whatsappOptIn?: boolean + emailOptIn?: boolean + messageType: MessageType + subject?: string + whatsappText: string + emailText: string + smsText: string + orgId: string + pledgeId?: string + eventId?: string +} + +interface SendResult { + channel: Channel | "none" + success: boolean + messageId?: string + error?: string + fallbackAttempted?: Channel +} + +/** + * Get the org's configured channels. + */ +export async function getOrgChannels(orgId: string): Promise { + if (!prisma) return { whatsapp: false, email: null, sms: null } + + const org = await prisma.organization.findUnique({ + where: { id: orgId }, + select: { + whatsappConnected: true, + emailProvider: true, emailApiKey: true, emailFromAddress: true, emailFromName: true, name: true, + smsProvider: true, smsAccountSid: true, smsAuthToken: true, smsFromNumber: true, + }, + }) + + if (!org) return { whatsapp: false, email: null, sms: null } + + const waReady = org.whatsappConnected && await isWhatsAppReady() + + return { + whatsapp: waReady, + email: org.emailProvider && org.emailApiKey && org.emailFromAddress + ? { provider: org.emailProvider, apiKey: org.emailApiKey, fromAddress: org.emailFromAddress, fromName: org.emailFromName || org.name } + : null, + sms: org.smsProvider && org.smsAccountSid && org.smsAuthToken && org.smsFromNumber + ? { provider: org.smsProvider, accountSid: org.smsAccountSid, authToken: org.smsAuthToken, fromNumber: org.smsFromNumber } + : null, + } +} + +/** + * Send a message to a donor via the best available channel. + * + * Priority: WhatsApp โ†’ SMS โ†’ Email + * Respects donor consent flags. + * Logs every attempt to AnalyticsEvent. + */ +export async function sendToDonor(opts: SendOptions): Promise { + const channels = await getOrgChannels(opts.orgId) + + // Build priority list based on what's available AND what the donor has + const attempts: Array<{ channel: Channel; canSend: boolean }> = [ + { + channel: "whatsapp", + canSend: channels.whatsapp && !!opts.donorPhone && opts.whatsappOptIn !== false, + }, + { + channel: "sms", + canSend: !!channels.sms && !!opts.donorPhone, + }, + { + channel: "email", + canSend: !!channels.email && !!opts.donorEmail && opts.emailOptIn !== false, + }, + ] + + let result: SendResult = { channel: "none", success: false, error: "No channel available" } + + for (const attempt of attempts) { + if (!attempt.canSend) continue + + try { + if (attempt.channel === "whatsapp") { + const wa = await sendWhatsAppMessage(opts.donorPhone!, opts.whatsappText) + result = { channel: "whatsapp", success: wa.success, messageId: wa.messageId, error: wa.error } + } else if (attempt.channel === "sms" && channels.sms) { + const smsResult = await sendSms(channels.sms, opts.donorPhone!, opts.smsText) + result = { channel: "sms", success: smsResult.success, messageId: smsResult.messageId, error: smsResult.error } + } else if (attempt.channel === "email" && channels.email) { + const emailResult = await sendEmail( + channels.email, + opts.donorEmail!, + opts.subject || "Pledge update", + opts.emailText + ) + result = { channel: "email", success: emailResult.success, messageId: emailResult.messageId, error: emailResult.error } + } + + // Log the attempt + await logMessage(opts, attempt.channel, result.success, result.error) + + if (result.success) return result + + // Failed โ€” try next channel (add fallback note) + result.fallbackAttempted = attempt.channel + } catch (err) { + await logMessage(opts, attempt.channel, false, String(err)) + result = { channel: attempt.channel, success: false, error: String(err) } + } + } + + // All channels exhausted + if (!result.success) { + await logMessage(opts, "none" as Channel, false, "All channels exhausted") + } + + return result +} + +/** + * Log a message attempt to AnalyticsEvent. + */ +async function logMessage( + opts: SendOptions, + channel: Channel | string, + success: boolean, + error?: string +) { + if (!prisma) return + try { + await prisma.analyticsEvent.create({ + data: { + eventType: `message.${channel}.${opts.messageType}.${success ? "sent" : "failed"}`, + pledgeId: opts.pledgeId || null, + eventId: opts.eventId || null, + metadata: { + channel, + messageType: opts.messageType, + donorName: opts.donorName, + donorPhone: opts.donorPhone ? opts.donorPhone.slice(-4) : null, // privacy: last 4 digits + donorEmail: opts.donorEmail ? opts.donorEmail.replace(/(.{2}).*@/, "$1***@") : null, + success, + error: error || undefined, + orgId: opts.orgId, + }, + }, + }) + } catch (e) { + console.error("[MESSAGING] Log failed:", e) + } +} + +/** + * Get message history for the automations dashboard. + */ +export async function getMessageHistory(orgId: string, limit = 50): Promise> { + if (!prisma) return [] + + const events = await prisma.analyticsEvent.findMany({ + where: { + eventType: { startsWith: "message." }, + metadata: { path: ["orgId"], equals: orgId }, + }, + orderBy: { createdAt: "desc" }, + take: limit, + }) + + return events.map(e => { + const m = e.metadata as Record || {} + return { + id: e.id, + channel: String(m.channel || "unknown"), + messageType: String(m.messageType || "unknown"), + donorName: m.donorName as string | null, + success: m.success === true, + error: m.error as string | null, + createdAt: e.createdAt, + } + }) +} + +/** + * Get channel stats for the automations dashboard. + */ +export async function getChannelStats(orgId: string, days = 7): Promise<{ + whatsapp: { sent: number; failed: number } + email: { sent: number; failed: number } + sms: { sent: number; failed: number } + total: number + deliveryRate: number +}> { + if (!prisma) return { whatsapp: { sent: 0, failed: 0 }, email: { sent: 0, failed: 0 }, sms: { sent: 0, failed: 0 }, total: 0, deliveryRate: 0 } + + const since = new Date(Date.now() - days * 86400000) + + const events = await prisma.analyticsEvent.findMany({ + where: { + eventType: { startsWith: "message." }, + metadata: { path: ["orgId"], equals: orgId }, + createdAt: { gte: since }, + }, + select: { eventType: true }, + }) + + const stats = { whatsapp: { sent: 0, failed: 0 }, email: { sent: 0, failed: 0 }, sms: { sent: 0, failed: 0 } } + + for (const e of events) { + const parts = e.eventType.split(".") + const channel = parts[1] as keyof typeof stats + const status = parts[3] + if (stats[channel]) { + if (status === "sent") stats[channel].sent++ + else if (status === "failed") stats[channel].failed++ + } + } + + const total = stats.whatsapp.sent + stats.email.sent + stats.sms.sent + stats.whatsapp.failed + stats.email.failed + stats.sms.failed + const sent = stats.whatsapp.sent + stats.email.sent + stats.sms.sent + const deliveryRate = total > 0 ? Math.round((sent / total) * 100) : 0 + + return { ...stats, total, deliveryRate } +} + +/** + * Get scheduled/pending reminders for the automations dashboard. + */ +export async function getPendingReminders(orgId: string, limit = 20): Promise> { + if (!prisma) return [] + + const reminders = await prisma.reminder.findMany({ + where: { + status: "pending", + pledge: { organizationId: orgId, status: { notIn: ["paid", "cancelled"] } }, + }, + include: { + pledge: { select: { donorName: true, amountPence: true } }, + }, + orderBy: { scheduledAt: "asc" }, + take: limit, + }) + + return reminders.map(r => ({ + id: r.id, + donorName: r.pledge.donorName, + amountPence: r.pledge.amountPence, + step: r.step, + channel: r.channel, + scheduledAt: r.scheduledAt, + })) +} diff --git a/pledge-now-pay-later/src/lib/sms.ts b/pledge-now-pay-later/src/lib/sms.ts new file mode 100644 index 0000000..d18d829 --- /dev/null +++ b/pledge-now-pay-later/src/lib/sms.ts @@ -0,0 +1,77 @@ +/** + * SMS sending โ€” per-org, bring your own key. + * + * Supported providers: + * - Twilio + * + * Each charity pastes their Twilio credentials in Settings. + * SMS comes from THEIR number. + */ + +interface SmsConfig { + provider: string + accountSid: string + authToken: string + fromNumber: string +} + +interface SendResult { + success: boolean + messageId?: string + error?: string +} + +/** + * Send an SMS using the org's configured provider. + */ +export async function sendSms( + config: SmsConfig, + to: string, + body: string +): Promise { + if (!config.accountSid || !config.authToken || !config.fromNumber) { + return { success: false, error: "SMS not configured" } + } + + try { + if (config.provider === "twilio") { + return await sendViaTwilio(config, to, body) + } + return { success: false, error: `Unknown provider: ${config.provider}` } + } catch (err) { + console.error("[SMS]", err) + return { success: false, error: String(err) } + } +} + +async function sendViaTwilio( + config: SmsConfig, to: string, body: string +): Promise { + // Normalize UK number + let phone = to.replace(/[\s\-\(\)]/g, "") + if (phone.startsWith("0")) phone = "+44" + phone.slice(1) + if (!phone.startsWith("+")) phone = "+" + phone + + const url = `https://api.twilio.com/2010-04-01/Accounts/${config.accountSid}/Messages.json` + const auth = Buffer.from(`${config.accountSid}:${config.authToken}`).toString("base64") + + const res = await fetch(url, { + method: "POST", + headers: { + "Authorization": `Basic ${auth}`, + "Content-Type": "application/x-www-form-urlencoded", + }, + body: new URLSearchParams({ + To: phone, + From: config.fromNumber, + Body: body, + }), + }) + + const data = await res.json() + + if (data.sid) { + return { success: true, messageId: data.sid } + } + return { success: false, error: data.message || "Twilio error" } +} diff --git a/temp_files/v4/fix_tabs.py b/temp_files/v4/fix_tabs.py new file mode 100644 index 0000000..f8e6755 --- /dev/null +++ b/temp_files/v4/fix_tabs.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import os + +BASE = '/home/forge/app.charityright.org.uk' + +pages = { + 'app/Filament/Resources/CustomerResource/Pages/ListCustomers.php': 'all', + 'app/Filament/Resources/DonationResource/Pages/ListDonations.php': 'today', + 'app/Filament/Resources/AppealResource/Pages/ListAppeals.php': 'live', + 'app/Filament/Resources/ApprovalQueueResource/Pages/ListApprovalQueues.php': 'pending', + 'app/Filament/Resources/ScheduledGivingDonationResource/Pages/ListScheduledGivingDonations.php': 'active', +} + +for rel_path, default_tab in pages.items(): + path = os.path.join(BASE, rel_path) + with open(path, 'r') as f: + c = f.read() + + if 'getDefaultActiveTab' not in c: + method = "\n public function getDefaultActiveTab(): string | int | null\n {\n return '" + default_tab + "';\n }\n" + last_brace = c.rstrip().rfind('}') + c = c[:last_brace] + method + '}\n' + + with open(path, 'w') as f: + f.write(c) + print('Added default tab "' + default_tab + '" to ' + os.path.basename(path)) + else: + print('Already has default tab: ' + os.path.basename(path)) + +print('Done')