-
Couldn't load subscription status.
- Fork 5.5k
[Component] AfterShip - new source shipment status updated #18768
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
WalkthroughAdds AfterShip webhook infrastructure and a concrete “shipment status updated” source. Introduces a common webhook handler with deploy hook, signature validation, and event emission, plus a specific source implementing event naming and metadata. Updates package version and dependencies, adding crypto and upgrading @pipedream/platform. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor AfterShip as AfterShip
participant HTTP as HTTP Endpoint
participant Source as Webhook Source (common)
participant App as AfterShip App API
participant Runtime as Platform Runtime
note over Source,App: Deploy phase
Source->>Source: Validate webhookSecret
alt secret missing
Source->>Runtime: Throw ConfigurationError
else secret present
Source->>App: listTrackings(limit=25, page=1)
App-->>Source: Trackings[]
loop reverse iterate trackings
Source->>Source: processResource(resource)
Source->>Runtime: $emit(resource, generateMeta)
end
end
rect rgba(230,245,255,0.4)
note over AfterShip,HTTP: Runtime webhook delivery
AfterShip->>HTTP: POST /webhook (body, aftership-hmac-sha256)
HTTP->>Source: run({ body, bodyRaw, headers })
Source->>Source: isSignatureValid(bodyRaw, headerSig)
alt invalid signature
Source-->>HTTP: 401 Unauthorized (customResponse)
else valid signature
Source->>Source: processResource(body)
Source->>Runtime: $emit(body, generateMeta)
Source-->>HTTP: 200 OK (customResponse)
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (4)
components/aftership/sources/common/webhook.mjs (4)
25-42: Minor: redundant slice and inconsistent timestamp units.
slice(0, 25)is redundant withlimit: 25.tshere uses seconds, whilegenerateMetareturns milliseconds. Prefer consistency (ms in meta is standard; consider removingtsfrom payload or making both ms).- trackings - .slice(0, 25) + trackings .reverse() .forEach((tracking) => { this.processResource({ event: this.getEventName(), event_id: tracking.id, msg: tracking, - ts: Date.parse(tracking.updated_at) / 1000, + // Consider removing or making ms to match meta.ts + ts: Math.floor(Date.parse(tracking.updated_at) / 1000), }); });
20-23: Nit: message says “skipping deployment” but code throws.Either skip without throwing, or adjust the message to reflect a hard failure.
- console.log("No webhook secret was provided, skipping deployment"); - throw new ConfigurationError("No webhook secret was provided, skipping deployment"); + const msg = "A webhook secret is required to deploy this source"; + console.log(msg); + throw new ConfigurationError(msg);
52-62: Optional: timing-safe compare for HMAC.Use
crypto.timingSafeEqualto avoid subtle timing leaks on signature mismatch.- const hash = createHmac("sha256", webhookSecret) - .update(bodyRaw) - .digest("base64"); - return hash === signature; + const digest = createHmac("sha256", webhookSecret).update(bodyRaw).digest("base64"); + if (!signature) return false; + const a = Buffer.from(digest); + const b = Buffer.from(signature); + return a.length === b.length && crypto.timingSafeEqual(a, b);
5-17: Consider documenting how to obtain the webhook secret.Good description; add a short note that deployment will fail without it (align with hook behavior).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
components/aftership/package.json(2 hunks)components/aftership/sources/common/webhook.mjs(1 hunks)components/aftership/sources/shipment-status-updated/shipment-status-updated.mjs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
- GitHub Check: Verify TypeScript components
🔇 Additional comments (3)
components/aftership/sources/shipment-status-updated/shipment-status-updated.mjs (1)
3-10: Confirm second trigger (“New Added Shipment”) is included.The issue requests both “New Added Shipment” and “Updating Shipment.” This file covers status updates. Please confirm the “New Added Shipment” source exists in this PR or will follow.
components/aftership/package.json (1)
16-16: Manual verification needed: Cannot confirm API usage in components/aftership.The script search returned no matches for
ConfigurationErrororcustomResponsein the codebase. This prevents definitively verifying whether these APIs are actually used by the aftership component or if they're compatible with v3.1.0.To proceed, verify:
- Whether the aftership component actually uses
$.interface.httpwithcustomResponse: trueor throwsConfigurationError- If these APIs are not used, the version constraint
^3.1.0may still be valid, but compatibility cannot be confirmed without code inspection#!/bin/bash # Search specifically within aftership component for $.interface.http and ConfigurationError usage find components/aftership -type f \( -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" -o -name "*.mjs" \) -exec grep -l "interface\.http\|customResponse\|ConfigurationError" {} \;components/aftership/sources/common/webhook.mjs (1)
70-77: No change needed for signature header
Tracking webhooks useaftership-hmac-sha256per official docs, so the existing header key is correct.
components/aftership/sources/shipment-status-updated/shipment-status-updated.mjs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Ready for QA!
WHY
Resolves #18711
Summary by CodeRabbit
New Features
Chores