feat: eBay affiliate link builder (Option B — user-configurable, CF fallback)
- _affiliate_url() helper appends EPN params when EBAY_AFFILIATE_CAMPAIGN_ID set - Clean /itm/ URLs by default (no affiliate tracking without explicit opt-in) - affiliate_active flag in search response drives frontend disclosure - SearchView shows 'Links may include an affiliate code' when active - .env.example documents EBAY_AFFILIATE_CAMPAIGN_ID with EPN registration link - Closes #19
This commit is contained in:
parent
0617fc8256
commit
0430454dad
4 changed files with 38 additions and 1 deletions
|
|
@ -47,6 +47,13 @@ SNIPE_DB=data/snipe.db
|
||||||
# HEIMDALL_URL=https://license.circuitforge.tech
|
# HEIMDALL_URL=https://license.circuitforge.tech
|
||||||
# HEIMDALL_ADMIN_TOKEN=
|
# HEIMDALL_ADMIN_TOKEN=
|
||||||
|
|
||||||
|
# ── eBay Affiliate (optional) ─────────────────────────────────────────────────
|
||||||
|
# Set to your eBay Partner Network (EPN) campaign ID to earn commissions on
|
||||||
|
# listing click-throughs. Leave blank for clean /itm/ URLs (no tracking).
|
||||||
|
# Register at https://partnernetwork.ebay.com — self-hosted users can use their
|
||||||
|
# own ID; the CF cloud instance uses CF's campaign ID (disclosed in the UI).
|
||||||
|
# EBAY_AFFILIATE_CAMPAIGN_ID=
|
||||||
|
|
||||||
# ── In-app feedback (beta) ────────────────────────────────────────────────────
|
# ── In-app feedback (beta) ────────────────────────────────────────────────────
|
||||||
# When set, a feedback FAB appears in the UI and routes submissions to Forgejo.
|
# When set, a feedback FAB appears in the UI and routes submissions to Forgejo.
|
||||||
# Leave unset to silently hide the button (demo/offline deployments).
|
# Leave unset to silently hide the button (demo/offline deployments).
|
||||||
|
|
|
||||||
24
api/main.py
24
api/main.py
|
|
@ -69,6 +69,22 @@ def _ebay_creds() -> tuple[str, str, str]:
|
||||||
client_secret = (os.environ.get("EBAY_CERT_ID") or os.environ.get("EBAY_CLIENT_SECRET", "")).strip()
|
client_secret = (os.environ.get("EBAY_CERT_ID") or os.environ.get("EBAY_CLIENT_SECRET", "")).strip()
|
||||||
return client_id, client_secret, env
|
return client_id, client_secret, env
|
||||||
|
|
||||||
|
def _affiliate_url(url: str) -> str:
|
||||||
|
"""Append EPN affiliate params when EBAY_AFFILIATE_CAMPAIGN_ID is configured.
|
||||||
|
|
||||||
|
If the env var is absent or blank, the original URL is returned unchanged.
|
||||||
|
Params follow the standard EPN deep-link format; siteid=0 = US.
|
||||||
|
"""
|
||||||
|
campaign_id = os.environ.get("EBAY_AFFILIATE_CAMPAIGN_ID", "").strip()
|
||||||
|
if not campaign_id:
|
||||||
|
return url
|
||||||
|
sep = "&" if "?" in url else "?"
|
||||||
|
return (
|
||||||
|
f"{url}{sep}mkcid=1&mkrid=711-53200-19255-0"
|
||||||
|
f"&siteid=0&campid={campaign_id}&toolid=10001&mkevt=1"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(title="Snipe API", version="0.1.0", lifespan=_lifespan)
|
app = FastAPI(title="Snipe API", version="0.1.0", lifespan=_lifespan)
|
||||||
app.include_router(ebay_webhook_router)
|
app.include_router(ebay_webhook_router)
|
||||||
|
|
||||||
|
|
@ -395,12 +411,18 @@ def search(
|
||||||
and shared_store.get_seller("ebay", listing.seller_platform_id)
|
and shared_store.get_seller("ebay", listing.seller_platform_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _serialize_listing(l: object) -> dict:
|
||||||
|
d = dataclasses.asdict(l)
|
||||||
|
d["url"] = _affiliate_url(d["url"])
|
||||||
|
return d
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"listings": [dataclasses.asdict(l) for l in listings],
|
"listings": [_serialize_listing(l) for l in listings],
|
||||||
"trust_scores": trust_map,
|
"trust_scores": trust_map,
|
||||||
"sellers": seller_map,
|
"sellers": seller_map,
|
||||||
"market_price": market_price,
|
"market_price": market_price,
|
||||||
"adapter_used": adapter_used,
|
"adapter_used": adapter_used,
|
||||||
|
"affiliate_active": bool(os.environ.get("EBAY_AFFILIATE_CAMPAIGN_ID", "").strip()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ export const useSearchStore = defineStore('search', () => {
|
||||||
)
|
)
|
||||||
const marketPrice = ref<number | null>(cached?.marketPrice ?? null)
|
const marketPrice = ref<number | null>(cached?.marketPrice ?? null)
|
||||||
const adapterUsed = ref<'api' | 'scraper' | null>(cached?.adapterUsed ?? null)
|
const adapterUsed = ref<'api' | 'scraper' | null>(cached?.adapterUsed ?? null)
|
||||||
|
const affiliateActive = ref<boolean>(false)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
|
@ -164,6 +165,7 @@ export const useSearchStore = defineStore('search', () => {
|
||||||
sellers: Record<string, Seller>
|
sellers: Record<string, Seller>
|
||||||
market_price: number | null
|
market_price: number | null
|
||||||
adapter_used: 'api' | 'scraper'
|
adapter_used: 'api' | 'scraper'
|
||||||
|
affiliate_active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
results.value = data.listings ?? []
|
results.value = data.listings ?? []
|
||||||
|
|
@ -171,6 +173,7 @@ export const useSearchStore = defineStore('search', () => {
|
||||||
sellers.value = new Map(Object.entries(data.sellers ?? {}))
|
sellers.value = new Map(Object.entries(data.sellers ?? {}))
|
||||||
marketPrice.value = data.market_price ?? null
|
marketPrice.value = data.market_price ?? null
|
||||||
adapterUsed.value = data.adapter_used ?? null
|
adapterUsed.value = data.adapter_used ?? null
|
||||||
|
affiliateActive.value = data.affiliate_active ?? false
|
||||||
saveCache({
|
saveCache({
|
||||||
query: q,
|
query: q,
|
||||||
results: results.value,
|
results: results.value,
|
||||||
|
|
@ -225,6 +228,7 @@ export const useSearchStore = defineStore('search', () => {
|
||||||
sellers,
|
sellers,
|
||||||
marketPrice,
|
marketPrice,
|
||||||
adapterUsed,
|
adapterUsed,
|
||||||
|
affiliateActive,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
search,
|
search,
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,9 @@
|
||||||
<span v-if="hiddenCount > 0" class="results-hidden">
|
<span v-if="hiddenCount > 0" class="results-hidden">
|
||||||
· {{ hiddenCount }} hidden by filters
|
· {{ hiddenCount }} hidden by filters
|
||||||
</span>
|
</span>
|
||||||
|
<span v-if="store.affiliateActive" class="affiliate-disclosure">
|
||||||
|
· Links may include an affiliate code
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<div class="toolbar-actions">
|
<div class="toolbar-actions">
|
||||||
<label for="sort-select" class="sr-only">Sort by</label>
|
<label for="sort-select" class="sr-only">Sort by</label>
|
||||||
|
|
@ -1029,6 +1032,7 @@ async function onSearch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
.results-hidden { color: var(--color-warning); }
|
.results-hidden { color: var(--color-warning); }
|
||||||
|
.affiliate-disclosure { color: var(--color-text-muted, #8b949e); font-size: 0.8em; }
|
||||||
|
|
||||||
.toolbar-actions {
|
.toolbar-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue