[Feature] Adding special information for function invoking by backend triggers.
- Dominant language
- TypeScript
- Stars
- 7.6k
- Forks
- 670
- PR merge metrics
- No merged PRs in 30d
Description
### Search before asking
- [X] I had searched in the [issues](https://github.com/labring/laf/issues?q=is%3Aissue) and found no similar issues.
### Feature Request
I have a `__interceptor__` function to check signature from front-end (shown below). But when the triggers invoke function from back-end, it will be intercepted because of no signature.
i hope to have special mark for the invoking by triggers, or just skip `__interceptor__` like `cloud.invoke()` does.
Here is the code of my `__interceptor__` function, it will print "invalid sign" when triggers calling.
```js
import cloud from '@lafjs/cloud'
import CryptoJS from 'crypto-js';
// 检查签名是否有效
function verifySign(signKey: string, data: string, signature: string) {
// 使用HMAC-SHA256算法进行验证
const isValid = CryptoJS.HmacSHA256(data, signKey).toString() === signature;
return isValid;
}
function compareDateStrings(dateString1: string, dateString2: string, n: number): boolean {
const date1 = new Date(dateString1);
const date2 = new Date(dateString2);
const diffInSeconds = Math.abs((date1.getTime() - date2.getTime()) / 1000);
return diffInSeconds <= n;
}
export async function main(ctx: FunctionContext) {
let signKey = cloud.env.SIGN_KEY;
if (!signKey) {
// 没有开启
return true;
}
const { signdata, signstr } = ctx.headers;
const isValid = verifySign(signKey, signdata, signstr);
if (!isValid) {
console.log("invalid sign");
return false;
}
// 检查时间
const now = new Date().toISOString();
const threshold = 30; // 秒
const timeCheck = compareDateStrings(now, signdata, threshold);
if (!timeCheck) {
console.log("time check failed", now, signdata);
return false;
}
return true;
}
```
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Research direction
No files or entry points are named. Start by tracing how backend triggers invoke functions and how __interceptor__ is applied, then compare that path with cloud.invoke(). Done means trigger-originated calls have the intended special handling without disabling signature checks for frontend requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100