-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat: Add Status Change Source #20156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ooi2018
wants to merge
11
commits into
PipedreamHQ:master
Choose a base branch
from
ooi2018:add-source-statuschange
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−13
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e26c931
feat: Add Status Change Source
ooi2018 b98f2e7
Update status_change.mjs
ooi2018 3da4be2
Update status_change.mjs
ooi2018 cb81c9b
Update status_change.mjs
ooi2018 5849e3d
Update status_change.mjs
ooi2018 728fad2
move api request methods to app file
michelle0927 e6fc5c3
update folder/file names
michelle0927 31f39dc
update name, add getter/setter methods, updates
michelle0927 28338de
pnpm-lock.yaml
michelle0927 9448778
versions
michelle0927 2619e04
Merge remote-tracking branch 'upstream/master' into add-source-status…
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
components/fraudlabs_pro/sources/status_changed/status_change.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import fraudlabsProApp from "../../fraudlabs_pro.app.mjs"; | ||
|
|
||
| export default { | ||
| name: "FraudLabs Pro Status Change Trigger", | ||
| description: "Trigger to receive data from FraudLabs Pro Screen Order API if the status changed match to your setting.", | ||
| version: "0.0.1", | ||
| key: "fraudlabspro_status_change", | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type: "source", | ||
| props: { | ||
| fraudlabsProApp, | ||
| db: "$.service.db", | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: true, | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| // 1. Check if a webhook already exists in the DB to prevent duplicates | ||
| const existingHookId = this.db.get("hookId"); | ||
| if (existingHookId) { | ||
| console.log(`Webhook already active with ID: ${existingHookId}`); | ||
| return; | ||
| } | ||
|
|
||
| const urlWithAuth = `https://www.fraudlabspro.com/pipedream-webhook-subscribe?key=${encodeURIComponent(this.$auth.api_key)}`; | ||
|
|
||
| const response = await fetch(urlWithAuth, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| url: this.http.endpoint, | ||
| event: "status_changed", | ||
| description: "Pipedream Workflow Trigger" | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| throw new Error(`Activation failed (${response.status}): ${errorText}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| // Store the ID returned by FraudLabs Pro | ||
| if (data && data.id) { | ||
| this.db.set("hookId", data.id); | ||
| } | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| async deactivate() { | ||
| const hookId = this.db.get("hookId"); | ||
| if (!hookId) return; | ||
|
|
||
| const baseUrl = `https://www.fraudlabspro.com/pipedream-webhook-unsubscribe`; | ||
| const params = new URLSearchParams({ | ||
| key: this.$auth.api_key, | ||
| id: hookId | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseUrl}?${params.toString()}`, { | ||
| method: "GET", | ||
| }); | ||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| throw new Error(`Deactivation failed (${response.status}): ${errorText}`); | ||
| } | ||
|
|
||
| // Clear the DB so it can be re-activated later | ||
| this.db.set("hookId", null); | ||
| }, | ||
| }, | ||
| async run(event) { | ||
| // 2. Capture the incoming POST data from the API | ||
| const body = event.body; | ||
| if (!body || typeof body !== "object") { | ||
| this.http.respond({ | ||
| status: 400, | ||
| body: { message: "Invalid payload" }, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Emit the data so it can be used in workflow steps | ||
| // We use fields like order_id as the primary ID for deduplication in Pipedream | ||
| this.$emit(body, { | ||
| summary: `New Status: ${body.flp_status} for Order #${body.order_id}`, | ||
| id: `${body.order_id}-${body.flp_status}-${body.updated_at ?? body.timestamp ?? Date.now()}`, | ||
| ts: Date.now(), | ||
| }); | ||
|
|
||
| // Acknowledge the receipt to FraudLabs Pro | ||
| this.http.respond({ | ||
| status: 200, | ||
| body: { message: "Success" }, | ||
| }); | ||
| }, | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.