Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

examples: add stripe-link-fraud demo (Stripe Link + SIE risk gate)

Filip Makraduli55b802e59fa4
diff --git a/examples/README.md b/examples/README.md
index cb92870ec..b1e424528 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -18,6 +18,7 @@ service keys.
| [Build a multimodal wine recommender with OCR](./wine-recommender) | Combining preference-based retrieval with OCR-driven label detection in one UI | `encode`, `score`, `extract` | Docker Compose app plus local SIE endpoint; API key optional for unauthenticated SIE | Runnable demo |
| [Build a multi-modal product classifier with embeddings](./taxonomy-classification) | Evaluating text, image, NLI, and reranking approaches for hierarchical product taxonomy classification | `extract`, `encode`, `score` | SIE endpoint, Shopify dataset prep via `uv run` scripts, standalone `uv` project | Runnable evaluation example |
| [Swap an OCR model with one identifier change](./document-ocr) | Driving recognition (VLM-OCR), structured extraction (Donut), and zero-shot NER (GLiNER) through the same `extract` call by swapping the model ID | `extract` | Docker Compose plus Node UI, no API key required, hosted version on [Hugging Face Spaces](https://huggingface.co/spaces/superlinked/document-ocr) | Runnable demo |
+| [A Stripe Link checkout with an SIE fraud-risk gate](./stripe-link-fraud) | Wiring all three SIE primitives into a pre-authorization fraud-risk gate that runs in the same round-trip as the Stripe PaymentIntent | `extract`, `encode`, `score` | Docker Compose plus Node UI; Stripe test-mode keys optional (runs in mock mode without them) | Runnable demo |
For docs publishing, lead with the quickest runnable demos, then use the
benchmark and evaluation examples for deeper technical users.
diff --git a/examples/stripe-link-fraud/.env.example b/examples/stripe-link-fraud/.env.example
new file mode 100644
index 000000000..2325475c3
--- /dev/null
+++ b/examples/stripe-link-fraud/.env.example
@@ -0,0 +1,13 @@
+# Stripe test-mode keys. Get yours at https://dashboard.stripe.com/test/apikeys
+# If left blank, the demo runs in mock mode: the SIE risk-scoring panel still
+# works, but the Stripe Link checkout shows a banner instead of a real
+# payment form.
+STRIPE_PUBLISHABLE_KEY=
+STRIPE_SECRET_KEY=
+
+# SIE
+SIE_URL=http://localhost:8080
+SIE_API_KEY=
+
+# UI server
+PORT=3033
diff --git a/examples/stripe-link-fraud/.gitignore b/examples/stripe-link-fraud/.gitignore
new file mode 100644
index 000000000..52d9175c4
--- /dev/null
+++ b/examples/stripe-link-fraud/.gitignore
@@ -0,0 +1,4 @@
+node_modules/
+.env
+*.log
+data/risk_index.json
diff --git a/examples/stripe-link-fraud/README.md b/examples/stripe-link-fraud/README.md
new file mode 100644
index 000000000..888acc458
--- /dev/null
+++ b/examples/stripe-link-fraud/README.md
@@ -0,0 +1,349 @@
+# stripe-link-fraud
+
+**A Stripe Link checkout with an SIE-driven fraud-risk gate in one round-trip.**
+
+Three SIE primitives (`extract`, `encode`, `score`) score every order
+against a corpus of past fraud patterns before a Stripe PaymentIntent is
+created. The risk band that comes out the other side annotates the
+Stripe Link payment button, in the same UI, in the same request.
+
+![architecture](docs/architecture.svg)
+
+![demo screenshot](docs/screenshot.png)
+
+> Built on [SIE](https://github.com/superlinked/sie), the open-source
+> inference engine from Superlinked, plus
+> [Stripe.js + Stripe Link](https://stripe.com/payments/link). Apache 2.0.
+> Run it locally with `docker compose up` + `npm start`.
+
+---
+
+## What this demo actually shows
+
+Imagine you run a small e-commerce shop. You added Stripe Link to your
+checkout because the one-click experience for returning shoppers really
+does lift conversion. Three months in, the chargebacks start. Not from
+the returning Link customers (those are golden); from the brand-new
+signups: a brand-new email opens an account, adds a gift card, pays with
+Link, the card is stolen, and twenty days later the issuer claws the
+money back. You eat the loss and the fee.
+
+The natural reaction is to bolt on a fraud-scoring SaaS. That works.
+It also adds a third auth flow, a fourth SDK, a fifth vendor that needs
+to see your customer's email and shipping address, and a compliance
+review that takes two months.
+
+This demo shows the other path: **the fraud scoring runs against the
+same SIE server your search and embeddings already run against**. Three
+SIE primitives, three lines of code:
+
+```ts
+// 1. Extract typed signals from the order context
+const entities = await client.extract(
+ "urchade/gliner_multi-v2.1",
+ { text: orderSummary },
+ { labels: ["product", "shipping_address", "email_domain", "amount"] },
+);
+
+// 2. Encode the context into a dense vector
+const { dense } = await client.encode(
+ "sentence-transformers/all-MiniLM-L6-v2",
+ { text: orderSummary },
+);
+
+// 3. Rerank top-K fraud patterns (cosine retrieval picked the candidates)
+const { scores } = await client.score(
+ "BAAI/bge-reranker-base",
+ { text: orderSummary },
+ topKFraudPatterns,
+);
+```
+
+The output is a low / medium / high band. The Stripe Link
+PaymentElement reflects that band: the button stays "Pay with Link" for
+low risk, flips to "Hold for review" for high risk. The actual
+authorization still goes through Stripe; the risk band just tells the
+UI (and your downstream operations team) how much trust to give this
+one transaction.
+
+---
+
+## How this relates to Stripe Link specifically
+
+Stripe Link is the saved-payment-method wallet that powers one-click
+checkout across Stripe-using merchants. Conversion-wise it's a huge
+win: a returning shopper sees their card pre-filled and a "Pay" button,
+done. But that same low-friction surface is exactly where account
+takeover and synthetic-identity fraud likes to hide. The customer looks
+like a returning Link shopper because their *email* matches a Link
+account; meanwhile their *behavior* (new device, new shipping address,
+velocity spike) does not match.
+
+This demo's pipeline runs at the moment a `PaymentIntent` is being
+created with Link enabled (`automatic_payment_methods: { enabled: true }`).
+The order context, the customer's Link status, their geography, and the
+cart shape are all fed into the SIE pipeline. The risk band is written
+onto the PaymentIntent as `metadata.sie_risk_band`; what you do with
+that downstream (Stripe Radar rules, your own ops queue, a webhook into
+a fraud tool) is up to you. Downstream in this demo:
+
+- a **low** band lets the Stripe Link Element mount normally and the
+ customer pays with one click;
+- a **medium** band still authorizes but tags the intent for review
+ inside Stripe Dashboard (or your own ops tool) via
+ `metadata.sie_risk_band`;
+- a **high** band keeps the PaymentElement disabled with a "Hold for
+ review" CTA, so a human checks the order before the charge goes
+ through.
+
+The Link flow is not bypassed and not duplicated. The risk gate is
+purely advisory and informational. The same SIE server that runs this
+fraud-scoring also runs the merchant's search, product embeddings, and
+any other ML in the stack, so there is no second inference vendor to
+onboard.
+
+---
+
+## Run it locally
+
+```bash
+git clone https://github.com/superlinked/sie
+cd sie/examples/stripe-link-fraud
+cp .env.example .env
+npm install
+npm start
+```
+
+`npm start` runs `docker compose up -d` (boots
+`ghcr.io/superlinked/sie-server:latest-cpu-default`, preloads the three
+small models, ~440 MB total) and starts a Node UI server at
+<http://localhost:3033>.
+
+- **First start**: ~3-5 minutes (one-time image + model download).
+- **Subsequent restarts**: ~30-60 seconds. Weights cache in the
+ `sie-cache` Docker volume.
+- **Per-click runtime**: ~1 second once the models are hot.
+
+### Plugging in your Stripe Link keys
+
+The demo runs **without** Stripe keys: the SIE risk panel is fully
+functional, and the right-hand checkout panel shows a mock "Pay with
+Link" button. To switch on the real Stripe.js + Link flow, drop your
+test-mode keys in `.env`:
+
+```bash
+STRIPE_PUBLISHABLE_KEY=pk_test_...
+STRIPE_SECRET_KEY=sk_test_...
+```
+
+Grab them at <https://dashboard.stripe.com/test/apikeys>. With keys set,
+the backend calls
+`stripe.paymentIntents.create({ automatic_payment_methods: { enabled: true } })`,
+which is the same call you make in production: Stripe decides whether
+to expose Link, card, Apple Pay, etc. based on your account and the
+customer.
+
+Test card numbers live at <https://docs.stripe.com/testing#cards>.
+`4242 4242 4242 4242` always succeeds; `4000 0025 0000 3155` triggers
+3D Secure.
+
+---
+
+## Specific things to try in the UI
+
+The left panel ships five sample orders that exercise the pipeline:
+
+| Order | Customer profile | Expected band |
+|---|---|---|
+| Normal subscription renewal | Returning Link customer, 12 months of history | **low** |
+| Returning customer, apparel reorder | Repeat shopper, normal cart size | **low** |
+| Brand-new email, gift cards only | New account, mailinator email, IP=RU | **medium** (matches `gift_card_resale`) |
+| First order, high value, overnight to reshipper | New account, $489 single SKU, freight forwarder shipping | **high** (matches `high_value_first_purchase_express_shipping`) |
+| Established account, sudden velocity spike | Long-standing customer, 4 orders in 30 min | low (subtle; cosine misses) |
+
+Click each in turn and watch the right panel react. The "velocity spike"
+case intentionally misses because cosine + cross-encoder over a small
+corpus catches obvious fraud-pattern matches but does not replace
+velocity feature engineering. A production stack would combine SIE's
+similarity signal with traditional rules.
+
+---
+
+## What the numbers in the UI mean
+
+The risk panel shows three numeric scores. Here is what each one is:
+
+1. **GLiNER confidence (next to each extracted entity).** The model's
+ confidence (0 to 1) that the highlighted span really is an instance
+ of the labeled entity type (`product`, `shipping_address`, etc.).
+ GLiNER is doing zero-shot NER, so this is genuine confidence and
+ not a softmax over a fixed label set.
+2. **Cosine top score (in the risk band).** Cosine similarity between
+ the order-context embedding and the nearest fraud-pattern embedding
+ in the corpus. Range 0 to 1, where 1 would mean the order's vector
+ is identical to a fraud pattern. This is the value the band
+ thresholds are applied to.
+3. **Reranker score (right of each candidate).** Cross-encoder
+ relevance score from `BAAI/bge-reranker-base` for *this* order paired
+ with *this* candidate fraud pattern. The model returns a 0 to 1
+ score. The top-3 candidates from cosine retrieval are reranked and
+ reordered by this value, which is sharper than cosine for close-call
+ cases.
+
+Bands are derived from the cosine top score, not the reranker score,
+because cosine has a wider usable spread for this kind of semantic
+similarity. The reranker is used to order the displayed candidates,
+not to threshold the band. Both thresholds live in `src/config.ts`:
+
+```ts
+risk: {
+ blockThreshold: 0.47,
+ reviewThreshold: 0.52,
+ topKRerank: 3,
+}
+```
+
+When you swap in real fraud data, expect to re-tune both thresholds by
+sampling the cosine distribution on a held-out set.
+
+---
+
+## Model lineup
+
+| Stage | Model | Size | Role |
+|---|---|---|---|
+| Extract | `urchade/gliner_multi-v2.1` | 280 MB | zero-shot NER on the order summary |
+| Encode | `sentence-transformers/all-MiniLM-L6-v2` | 80 MB | 384-dim dense encoder for cosine retrieval |
+| Score | `BAAI/bge-reranker-base` | 280 MB | cross-encoder reranker on the top-K candidates |
+
+All three live in SIE's `default` bundle and ship with the
+`latest-cpu-default` Docker image. To swap any of them, edit
+`src/config.ts` (the model IDs) and the preload list in `compose.yml`.
+
+---
+
+## SIE features used
+
+- `extract` for zero-shot NER on the order context
+- `encode` for dense retrieval against the fraud-pattern corpus
+- `score` for cross-encoder reranking of the top-K candidates
+
+---
+
+## Why SIE specifically for this
+
+You could build this gate with three SaaS services: a hosted NER API, a
+hosted embeddings API, a hosted reranking API. That works. It also adds:
+
+- **Three vendors that see your order data.** Email addresses, billing
+ details, cart contents. Each one a separate data-processing agreement
+ for your legal team to negotiate.
+- **Three auth flows, three rate-limit budgets, three SDKs.** Each with
+ its own retry semantics and outage stories.
+- **A second inference stack** alongside whatever you already run for
+ product search and recommendations.
+
+SIE collapses all of that into one process:
+
+- **One server, three primitives.** `extract`, `encode`, `score`. The
+ same server can power your product search and your fraud gate from
+ the same process; you don't pay double.
+- **One SDK call shape.** `client.<primitive>(model_id, item)` is the
+ whole API. Swap a model ID in `src/config.ts` to try a different
+ encoder or reranker without touching any application code.
+- **Open source, runs in your VPC.** Customer order data never leaves
+ the host running this compose. Compliance teams stop blocking you.
+- **Same code laptop to Kubernetes.** SIE ships a Helm chart, KEDA
+ autoscaling, and Terraform modules for GKE/EKS. This demo's code
+ runs unchanged against a production cluster; only the URL changes.
+
+---
+
+## What's in the box
+
+```
+src/
+ config.ts SIE + Stripe config, model IDs, risk thresholds
+ events.ts typed SSE events streamed to the browser
+ risk.ts extract → encode → score pipeline
+ index-build.ts one-time corpus encoder
+ types.ts order, customer, fraud-pattern, index types
+
+data/
+ fraud_patterns.json 12 synthetic historical fraud patterns
+ sample_orders.json 5 sample carts + customer profiles
+
+web/
+ server.ts Node http server, /api/run SSE, /api/payment-intent
+ public/ index.html, style.css, app.js, architecture.svg
+
+compose.yml local docker compose up
+.env.example Stripe test keys + SIE URL
+docs/architecture.svg diagram you saw at the top of this README
+docs/screenshot.png UI screenshot
+```
+
+About 1,400 lines total. No bundler, no React, no build step. The UI
+is vanilla HTML + CSS + JavaScript driven by `EventSource` for the SSE
+stream from the Node server.
+
+---
+
+## Extend it
+
+- **Swap the corpus.** Replace `data/fraud_patterns.json` with your own
+ historical chargebacks, then `npm run index` to re-encode. Threshold
+ values in `src/config.ts` will need re-tuning on a held-out set.
+- **Try a different encoder.** All three model IDs live in
+ `src/config.ts`. Drop in `intfloat/e5-small-v2` for encoder, or
+ `mixedbread-ai/mxbai-rerank-large-v2` for a stronger cross-encoder.
+ No code change.
+- **Push the band into Stripe Radar.** The demo writes the band as
+ `metadata.sie_risk_band` on the PaymentIntent; a Radar rule like
+ `:metadata['sie_risk_band']: == 'high'` can `block` or `review`
+ inside Stripe's existing pipeline.
+- **Add a second signal.** Combine the cosine band with traditional
+ velocity / device-fingerprint rules. The SIE primitives compose; an
+ agentic harness sitting in front can call `score` for the similarity
+ gate and `extract` again for IP geolocation parsing in the same
+ round-trip.
+
+---
+
+## Honest scope and known limits
+
+- **The fraud-pattern corpus is synthetic and tiny** (~12 patterns).
+ Real systems use thousands and tag patterns by industry and merchant
+ vertical. SIE supports re-indexing live; the demo just doesn't show
+ it.
+- **Subtle patterns are missed.** Velocity, device fingerprinting, and
+ behavioral anomalies need feature engineering beyond text similarity.
+ The demo intentionally lets one "velocity spike" sample miss to make
+ this honest.
+- **Stripe test mode only.** Don't point this at live keys; the risk
+ band is informational and does not currently gate
+ `PaymentIntent.create`. Production wiring would either block the
+ intent above a threshold or push the band into Stripe Radar via
+ metadata.
+- **Apple Silicon performance is poor** because the SIE Docker image is
+ `linux/amd64` only and runs through Rosetta. On Linux x86_64, the
+ whole `extract+encode+score` chain completes in ~200 ms.
+
+---
+
+## Built with
+
+- [SIE](https://github.com/superlinked/sie) (Apache 2.0): the inference
+ engine that hosts all three model classes
+- [Stripe Link](https://stripe.com/payments/link) via
+ [Stripe.js + Elements](https://docs.stripe.com/payments/elements)
+ (test mode by default)
+- [GLiNER](https://huggingface.co/urchade/gliner_multi-v2.1) (Apache 2.0):
+ zero-shot NER
+- [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
+ (Apache 2.0): 22M-param dense encoder
+- [BAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base)
+ (MIT): general-purpose cross-encoder
+
+Star [superlinked/sie](https://github.com/superlinked/sie) if this was
+useful.
diff --git a/examples/stripe-link-fraud/compose.yml b/examples/stripe-link-fraud/compose.yml
new file mode 100644
index 000000000..60cc813b4
--- /dev/null
+++ b/examples/stripe-link-fraud/compose.yml
@@ -0,0 +1,27 @@
+services:
+ sie:
+ image: ghcr.io/superlinked/sie-server:latest-cpu-default
+ platform: linux/amd64
+ command:
+ - serve
+ - --port
+ - "8080"
+ # All three models live in the `default` SIE bundle. Combined ~440 MB.
+ - --preload
+ - urchade/gliner_multi-v2.1,sentence-transformers/all-MiniLM-L6-v2,BAAI/bge-reranker-base
+ ports:
+ - "8080:8080"
+ restart: unless-stopped
+ healthcheck:
+ test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
+ interval: 5s
+ timeout: 3s
+ retries: 60
+ start_period: 240s
+ volumes:
+ - sie-cache:/app/.cache/huggingface
+
+volumes:
+ sie-cache:
+ name: sie-cache
+ external: false
diff --git a/examples/stripe-link-fraud/data/fraud_patterns.json b/examples/stripe-link-fraud/data/fraud_patterns.json
new file mode 100644
index 000000000..c2944d5f0
--- /dev/null
+++ b/examples/stripe-link-fraud/data/fraud_patterns.json
@@ -0,0 +1,86 @@
+[
+ {
+ "id": "fp_001",
+ "label": "card_testing_microtransactions",
+ "summary": "Multiple authorizations under $5 from a single email on a new account, hitting different SKUs in rapid succession. Card testing pattern; the buyer is probing stolen card numbers.",
+ "outcome": "blocked",
+ "loss_usd": 0
+ },
+ {
+ "id": "fp_002",
+ "label": "high_value_first_purchase_express_shipping",
+ "summary": "First-ever order on a brand-new email, single high-margin SKU above $400, customer demands overnight shipping to a residential reshipper address. Classic chargeback profile.",
+ "outcome": "chargeback",
+ "loss_usd": 489
+ },
+ {
+ "id": "fp_003",
+ "label": "billing_shipping_mismatch_high_risk_country",
+ "summary": "Billing address in one country, shipping to a freight forwarder in a high-risk fraud destination. Card BIN does not match billing country.",
+ "outcome": "chargeback",
+ "loss_usd": 1340
+ },
+ {
+ "id": "fp_004",
+ "label": "velocity_same_card_multiple_emails",
+ "summary": "Same payment card used across five different customer accounts within an hour, all shipping to slightly varied addresses on the same block.",
+ "outcome": "blocked",
+ "loss_usd": 0
+ },
+ {
+ "id": "fp_005",
+ "label": "disposable_email_domain",
+ "summary": "Customer signs up with a disposable email provider (mailinator, guerrillamail, tempmail). Order is electronics or gift cards.",
+ "outcome": "chargeback",
+ "loss_usd": 220
+ },
+ {
+ "id": "fp_006",
+ "label": "gift_card_resale",
+ "summary": "Cart consists exclusively of digital gift cards or store credit, paid with a new card on a new account.",
+ "outcome": "chargeback",
+ "loss_usd": 500
+ },
+ {
+ "id": "fp_007",
+ "label": "ip_geo_billing_mismatch",
+ "summary": "Buyer's IP geolocates to a country thousands of miles from the billing address, no prior order history, paying with a freshly added card.",
+ "outcome": "review_then_chargeback",
+ "loss_usd": 612
+ },
+ {
+ "id": "fp_008",
+ "label": "stolen_link_credentials",
+ "summary": "Stripe Link account with established history suddenly orders shipped to a never-before-seen address, payment method updated minutes earlier.",
+ "outcome": "chargeback",
+ "loss_usd": 980
+ },
+ {
+ "id": "fp_009",
+ "label": "promo_code_abuse_multiple_accounts",
+ "summary": "Same shipping address receives orders from many different email accounts, each one using a first-order promo code.",
+ "outcome": "promo_reversed",
+ "loss_usd": 60
+ },
+ {
+ "id": "fp_010",
+ "label": "synthetic_identity_new_email",
+ "summary": "Brand-new email created today, billing name and shipping name do not match, paying with a card issued less than 30 days ago.",
+ "outcome": "blocked",
+ "loss_usd": 0
+ },
+ {
+ "id": "fp_011",
+ "label": "high_velocity_existing_account",
+ "summary": "Established Link customer suddenly places 4 high-value orders in a 30-minute window, each to a different shipping address.",
+ "outcome": "account_takeover",
+ "loss_usd": 1850
+ },
+ {
+ "id": "fp_012",
+ "label": "subscription_signup_disposable_card",
+ "summary": "New subscription signup using a virtual one-time-use card number, cancellation initiated minutes after the first charge succeeds.",
+ "outcome": "refunded",
+ "loss_usd": 0
+ }
+]
diff --git a/examples/stripe-link-fraud/data/sample_orders.json b/examples/stripe-link-fraud/data/sample_orders.json
new file mode 100644
index 000000000..0269d3060
--- /dev/null
+++ b/examples/stripe-link-fraud/data/sample_orders.json
@@ -0,0 +1,98 @@
+[
+ {
+ "id": "ord_clean_subscription",
+ "label": "Normal subscription renewal",
+ "description": "Returning Link customer (12 months of history), small recurring charge, billing and shipping addresses match.",
+ "cart": [
+ { "sku": "PRO-SEAT-MO", "name": "Pro plan seat (monthly)", "qty": 1, "unit_price_usd": 24 }
+ ],
+ "customer": {
+ "email": "[email protected]",
+ "name": "Samira Bose",
+ "account_age_days": 412,
+ "prior_orders": 13,
+ "link_returning": true,
+ "billing_country": "US",
+ "shipping_country": "US",
+ "shipping_address": "1620 Lombard St, San Francisco, CA 94123",
+ "ip_country": "US"
+ }
+ },
+ {
+ "id": "ord_clean_apparel",
+ "label": "Returning customer, apparel reorder",
+ "description": "Customer has bought apparel three times before; this order matches her usual cart size and shipping address.",
+ "cart": [
+ { "sku": "TEE-NAVY-M", "name": "Heavyweight tee, navy (M)", "qty": 2, "unit_price_usd": 32 },
+ { "sku": "SOCK-PAIR", "name": "Ribbed crew socks", "qty": 1, "unit_price_usd": 14 }
+ ],
+ "customer": {
+ "email": "[email protected]",
+ "name": "Daniel Wolfe",
+ "account_age_days": 220,
+ "prior_orders": 3,
+ "link_returning": true,
+ "billing_country": "US",
+ "shipping_country": "US",
+ "shipping_address": "412 Pine Street, Apt 5, Portland, OR 97204",
+ "ip_country": "US"
+ }
+ },
+ {
+ "id": "ord_suspicious_giftcards",
+ "label": "Brand-new email, gift cards only",
+ "description": "Account created today, single payment method just added, cart is two $250 digital gift cards.",
+ "cart": [
+ { "sku": "GIFTCARD-250", "name": "Digital gift card ($250)", "qty": 2, "unit_price_usd": 250 }
+ ],
+ "customer": {
+ "email": "[email protected]",
+ "name": "K Doe",
+ "account_age_days": 0,
+ "prior_orders": 0,
+ "link_returning": false,
+ "billing_country": "US",
+ "shipping_country": "US",
+ "shipping_address": "n/a (digital delivery)",
+ "ip_country": "RU"
+ }
+ },
+ {
+ "id": "ord_suspicious_overnight",
+ "label": "First order, high value, overnight to reshipper",
+ "description": "First-ever order from this email. Single high-margin electronics SKU, overnight shipping to a known package-forwarder address.",
+ "cart": [
+ { "sku": "HEADPHONES-PRO", "name": "Studio Pro headphones", "qty": 1, "unit_price_usd": 489 }
+ ],
+ "customer": {
+ "email": "[email protected]",
+ "name": "Alex Buyer",
+ "account_age_days": 0,
+ "prior_orders": 0,
+ "link_returning": false,
+ "billing_country": "GB",
+ "shipping_country": "US",
+ "shipping_address": "8400 NW 25th St, Doral, FL 33122 (Suite 4471)",
+ "ip_country": "NG"
+ }
+ },
+ {
+ "id": "ord_review_velocity",
+ "label": "Established account, sudden velocity spike",
+ "description": "Long-standing Link customer placing 4 orders in 30 minutes to 4 different addresses, each on a different state. Password was updated yesterday.",
+ "cart": [
+ { "sku": "HEADPHONES-PRO", "name": "Studio Pro headphones", "qty": 1, "unit_price_usd": 489 }
+ ],
+ "customer": {
+ "email": "[email protected]",
+ "name": "Amelia Brooks",
+ "account_age_days": 600,
+ "prior_orders": 24,
+ "link_returning": true,
+ "billing_country": "US",
+ "shipping_country": "US",
+ "shipping_address": "915 Elm Ave, Apt 12, Newark, NJ 07103",
+ "ip_country": "US"
+ }
+ }
+]
diff --git a/examples/stripe-link-fraud/docs/architecture.svg b/examples/stripe-link-fraud/docs/architecture.svg
new file mode 100644
index 000000000..7a92a2677
--- /dev/null
+++ b/examples/stripe-link-fraud/docs/architecture.svg
@@ -0,0 +1,118 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 920 360" role="img" aria-label="stripe-link-fraud architecture diagram">
+ <defs>
+ <style><![CDATA[
+ .bg { fill: #0e1014; }
+ .card { fill: #161a22; stroke: #232936; stroke-width: 1; rx: 10; ry: 10; }
+ .head { fill: #1c2230; }
+ .label { font: 600 12px "Inter", system-ui, sans-serif; fill: #e6e8ec; }
+ .sub { font: 400 11px "Inter", system-ui, sans-serif; fill: #8b94a7; }
+ .mono { font: 11px ui-monospace, "JetBrains Mono", monospace; fill: #c89cff; }
+ .accent { fill: #7c5dff; }
+ .info { fill: #62b6ff; }
+ .succ { fill: #5fd28b; }
+ .stroke-accent { stroke: #7c5dff; stroke-width: 1.5; fill: none; }
+ .stroke-info { stroke: #62b6ff; stroke-width: 1.5; fill: none; }
+ .stroke-succ { stroke: #5fd28b; stroke-width: 1.5; fill: none; }
+ .stroke-mute { stroke: #232936; stroke-width: 1.5; fill: none; }
+ .pill-bg-accent { fill: rgba(124,93,255,0.15); }
+ .pill-bg-info { fill: rgba(98,182,255,0.15); }
+ .pill-bg-succ { fill: rgba(95,210,139,0.15); }
+ ]]></style>
+ <marker id="arrow" markerWidth="10" markerHeight="10" refX="6" refY="3" orient="auto" markerUnits="strokeWidth">
+ <path d="M0,0 L0,6 L6,3 z" fill="#8b94a7" />
+ </marker>
+ <marker id="arrow-accent" markerWidth="10" markerHeight="10" refX="6" refY="3" orient="auto" markerUnits="strokeWidth">
+ <path d="M0,0 L0,6 L6,3 z" fill="#7c5dff" />
+ </marker>
+ </defs>
+
+ <rect class="bg" x="0" y="0" width="920" height="360" />
+
+ <!-- Step 1: checkout context -->
+ <g transform="translate(40,140)">
+ <rect class="card" width="180" height="80" rx="10" />
+ <rect class="head" x="0" y="0" width="180" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="180" height="10" />
+ <text class="label" x="14" y="16">checkout context</text>
+ <text class="sub" x="14" y="42">cart</text>
+ <text class="sub" x="14" y="58">customer profile</text>
+ <text class="sub" x="14" y="72">Link history + geo</text>
+ <circle class="info" cx="166" cy="11" r="4" />
+ </g>
+
+ <!-- Step 2: SIE server -->
+ <g transform="translate(280,80)">
+ <rect class="card" width="360" height="200" rx="10" />
+ <rect class="head" x="0" y="0" width="360" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="360" height="10" />
+ <text class="label" x="14" y="16">one SIE server</text>
+ <text class="sub" x="338" y="16" text-anchor="end">3 primitives, 1 round-trip</text>
+ <circle class="accent" cx="350" cy="11" r="3" />
+
+ <!-- 3 primitives inside SIE -->
+ <g transform="translate(20,40)">
+ <rect class="pill-bg-info" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">extract</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">GLiNER</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">signals</text>
+ </g>
+ <g transform="translate(130,40)">
+ <rect class="pill-bg-accent" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">encode</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">MiniLM-L6</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">dense 384-d</text>
+ </g>
+ <g transform="translate(240,40)">
+ <rect class="pill-bg-succ" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">score</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">BGE-reranker</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">top-K rerank</text>
+ </g>
+
+ <!-- corpus -->
+ <g transform="translate(60,118)">
+ <rect class="card" width="240" height="60" rx="8" />
+ <text class="label" x="120" y="22" text-anchor="middle">fraud_patterns.json</text>
+ <text class="sub" x="120" y="40" text-anchor="middle">12 past patterns, pre-encoded</text>
+ <text class="mono" x="120" y="54" text-anchor="middle">cosine top-3 → reranker</text>
+ </g>
+ </g>
+
+ <!-- Step 3: risk band -->
+ <g transform="translate(700,80)">
+ <rect class="card" width="180" height="200" rx="10" />
+ <rect class="head" x="0" y="0" width="180" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="180" height="10" />
+ <text class="label" x="14" y="16">risk band</text>
+ <circle class="succ" cx="166" cy="11" r="4" />
+
+ <g transform="translate(16,36)">
+ <rect class="pill-bg-succ" width="148" height="34" rx="6" />
+ <text class="label succ" x="14" y="22">low</text>
+ <text class="sub" x="50" y="22">cosine &lt; 0.47</text>
+ </g>
+ <g transform="translate(16,76)">
+ <rect width="148" height="34" rx="6" fill="rgba(247,201,72,0.18)" />
+ <text class="label" x="14" y="22" fill="#f7c948">medium</text>
+ <text class="sub" x="68" y="22">0.47-0.52</text>
+ </g>
+ <g transform="translate(16,116)">
+ <rect width="148" height="34" rx="6" fill="rgba(255,107,107,0.18)" />
+ <text class="label" x="14" y="22" fill="#ff6b6b">high</text>
+ <text class="sub" x="56" y="22">&gt; 0.52</text>
+ </g>
+ <g transform="translate(16,164)">
+ <text class="sub" x="0" y="0">→ PaymentIntent.metadata</text>
+ <text class="sub" x="0" y="14">→ Link Element CTA</text>
+ </g>
+ </g>
+
+ <!-- Arrows -->
+ <line class="stroke-mute" x1="220" y1="180" x2="278" y2="180" marker-end="url(#arrow)" />
+ <line class="stroke-mute" x1="640" y1="180" x2="698" y2="180" marker-end="url(#arrow)" />
+
+ <!-- Footer / title -->
+ <text class="label" x="460" y="40" text-anchor="middle">stripe-link-fraud</text>
+ <text class="sub" x="460" y="56" text-anchor="middle">pre-authorization fraud-risk gate, three SIE primitives in one round-trip</text>
+ <text class="sub" x="460" y="334" text-anchor="middle">Apache 2.0 · runs locally with docker compose · hosted on Hugging Face Spaces</text>
+</svg>
diff --git a/examples/stripe-link-fraud/docs/screenshot.png b/examples/stripe-link-fraud/docs/screenshot.png
new file mode 100644
index 000000000..8b7b94b76
Binary files /dev/null and b/examples/stripe-link-fraud/docs/screenshot.png differ
diff --git a/examples/stripe-link-fraud/package-lock.json b/examples/stripe-link-fraud/package-lock.json
new file mode 100644
index 000000000..cee3677a2
--- /dev/null
+++ b/examples/stripe-link-fraud/package-lock.json
@@ -0,0 +1,868 @@
+{
+ "name": "stripe-link-fraud",
+ "version": "0.1.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "stripe-link-fraud",
+ "version": "0.1.0",
+ "dependencies": {
+ "@superlinked/sie-sdk": "^0.3.1",
+ "stripe": "^17.4.0"
+ },
+ "devDependencies": {
+ "@types/node": "^22.10.0",
+ "tsx": "^4.21.0",
+ "typescript": "^5.7.2"
+ },
+ "engines": {
+ "node": ">=22"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.0.tgz",
+ "integrity": "sha512-lhRUCeuOyJQURhTxl4WkpFTjIsbDayJHih5kZC1giwE+MhIzAb7mEsQMqMf18rHLsrb5qI1tafG20mLxEWcWlA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.0.tgz",
+ "integrity": "sha512-wqh0ByljabXLKHeWXYLqoJ5jKC4XBaw6Hk08OfMrCRd2nP2ZQ5eleDZC41XHyCNgktBGYMbqnrJKq/K/lzPMSQ==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.0.tgz",
+ "integrity": "sha512-+WzIXQOSaGs33tLEgYPYe/yQHf0WTU0X42Jca3y8NWMbUVhp7rUnw+vAsRC/QiDrdD31IszMrZy+qwPOPjd+rw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.0.tgz",
+ "integrity": "sha512-+VJggoaKhk2VNNqVL7f6S189UzShHC/mR9EE8rDdSkdpN0KflSwWY/gWjDrNxxisg8Fp1ZCD9jLMo4m0OUfeUA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.0.tgz",
+ "integrity": "sha512-0T+A9WZm+bZ84nZBtk1ckYsOvyA3x7e2Acj1KdVfV4/2tdG4fzUp91YHx+GArWLtwqp77pBXVCPn2We7Letr0Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.0.tgz",
+ "integrity": "sha512-fyzLm/DLDl/84OCfp2f/XQ4flmORsjU7VKt8HLjvIXChJoFFOIL6pLJPH4Yhd1n1gGFF9mPwtlN5Wf82DZs+LQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-l9GeW5UZBT9k9brBYI+0WDffcRxgHQD8ShN2Ur4xWq/NFzUKm3k5lsH4PdaRgb2w7mI9u61nr2gI2mLI27Nh3Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.0.tgz",
+ "integrity": "sha512-BXoQai/A0wPO6Es3yFJ7APCiKGc1tdAEOgeTNy3SsB491S3aHn4S4r3e976eUnPdU+NbdtmBuLncYir2tMU9Nw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.0.tgz",
+ "integrity": "sha512-CjaaREJagqJp7iTaNQjjidaNbCKYcd4IDkzbwwxtSvjI7NZm79qiHc8HqciMddQ6CKvJT6aBd8lO9kN/ZudLlw==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.0.tgz",
+ "integrity": "sha512-RVyzfb3FWsGA55n6WY0MEIEPURL1FcbhFE6BffZEMEekfCzCIMtB5yyDcFnVbTnwk+CLAgTujmV/Lgvih56W+A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.0.tgz",
+ "integrity": "sha512-KBnSTt1kxl9x70q+ydterVdl+Cn0H18ngRMRCEQfrbqdUuntQQ0LoMZv47uB97NljZFzY6HcfqEZ2SAyIUTQBQ==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.0.tgz",
+ "integrity": "sha512-zpSlUce1mnxzgBADvxKXX5sl8aYQHo2ezvMNI8I0lbblJtp8V4odlm3Yzlj7gPyt3T8ReksE6bK+pT3WD+aJRg==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.0.tgz",
+ "integrity": "sha512-2jIfP6mmjkdmeTlsX/9vmdmhBmKADrWqN7zcdtHIeNSCH1SqIoNI63cYsjQR8J+wGa4Y5izRcSHSm8K3QWmk3w==",
+ "cpu": [
+ "mips64el"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.0.tgz",
+ "integrity": "sha512-bc0FE9wWeC0WBm49IQMPSPILRocGTQt3j5KPCA8os6VprfuJ7KD+5PzESSrJ6GmPIPJK965ZJHTUlSA6GNYEhg==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.0.tgz",
+ "integrity": "sha512-SQPZOwoTTT/HXFXQJG/vBX8sOFagGqvZyXcgLA3NhIqcBv1BJU1d46c0rGcrij2B56Z2rNiSLaZOYW5cUk7yLQ==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.0.tgz",
+ "integrity": "sha512-SCfR0HN8CEEjnYnySJTd2cw0k9OHB/YFzt5zgJEwa+wL/T/raGWYMBqwDNAC6dqFKmJYZoQBRfHjgwLHGSrn3Q==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.0.tgz",
+ "integrity": "sha512-us0dSb9iFxIi8srnpl931Nvs65it/Jd2a2K3qs7fz2WfGPHqzfzZTfec7oxZJRNPXPnNYZtanmRc4AL/JwVzHQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-CR/RYotgtCKwtftMwJlUU7xCVNg3lMYZ0RzTmAHSfLCXw3NtZtNpswLEj/Kkf6kEL3Gw+BpOekRX0BYCtklhUw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.0.tgz",
+ "integrity": "sha512-nU1yhmYutL+fQ71Kxnhg8uEOdC0pwEW9entHykTgEbna2pw2dkbFSMeqjjyHZoCmt8SBkOSvV+yNmm94aUrrqw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-cXb5vApOsRsxsEl4mcZ1XY3D4DzcoMxR/nnc4IyqYs0rTI8ZKmW6kyyg+11Z8yvgMfAEldKzP7AdP64HnSC/6g==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.0.tgz",
+ "integrity": "sha512-8wZM2qqtv9UP3mzy7HiGYNH/zjTA355mpeuA+859TyR+e+Tc08IHYpLJuMsfpDJwoLo1ikIJI8jC3GFjnRClzA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.0.tgz",
+ "integrity": "sha512-FLGfyizszcef5C3YtoyQDACyg95+dndv79i2EekILBofh5wpCa1KuBqOWKrEHZg3zrL3t5ouE5jgr94vA+Wb2w==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.0.tgz",
+ "integrity": "sha512-1ZgjUoEdHZZl/YlV76TSCz9Hqj9h9YmMGAgAPYd+q4SicWNX3G5GCyx9uhQWSLcbvPW8Ni7lj4gDa1T40akdlw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.0.tgz",
+ "integrity": "sha512-Q9StnDmQ/enxnpxCCLSg0oo4+34B9TdXpuyPeTedN/6+iXBJ4J+zwfQI28u/Jl40nOYAxGoNi7mFP40RUtkmUA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.0.tgz",
+ "integrity": "sha512-zF3ag/gfiCe6U2iczcRzSYJKH1DCI+ByzSENHlM2FcDbEeo5Zd2C86Aq0tKUYAJJ1obRP84ymxIAksZUcdztHA==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.0.tgz",
+ "integrity": "sha512-pEl1bO9mfAmIC+tW5btTmrKaujg3zGtUmWNdCw/xs70FBjwAL3o9OEKNHvNmnyylD6ubxUERiEhdsL0xBQ9efw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@msgpack/msgpack": {
+ "version": "3.1.3",
+ "resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-3.1.3.tgz",
+ "integrity": "sha512-47XIizs9XZXvuJgoaJUIE2lFoID8ugvc0jzSHP+Ptfk8nTbnR8g788wv48N03Kx0UkAv559HWRQ3yzOgzlRNUA==",
+ "license": "ISC",
+ "engines": {
+ "node": ">= 18"
+ }
+ },
+ "node_modules/@superlinked/sie-sdk": {
+ "version": "0.3.4",
+ "resolved": "https://registry.npmjs.org/@superlinked/sie-sdk/-/sie-sdk-0.3.4.tgz",
+ "integrity": "sha512-VA0OZ1IcsjVWNKsHAa/gate9dYXVM1nrAdhIb6guLmfEzzu2XeTZOntqnr9I1CYVJRNKNeOlV1UQsY+5e//CqQ==",
+ "license": "MIT",
+ "dependencies": {
+ "@msgpack/msgpack": "^3.0.0"
+ },
+ "engines": {
+ "node": ">=22.0.0"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "22.19.19",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.19.tgz",
+ "integrity": "sha512-dyh/xO2Fh5bYrfWaaqGrRQQGkNdmYw6AmaAUvYeUMNTWQtvb796ikLdmTchRmOlOiIJ1TDXfWgVx1QkUlQ6Hew==",
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/call-bind-apply-helpers": {
+ "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==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/call-bound": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
+ "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "get-intrinsic": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/dunder-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
+ "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "gopd": "^1.2.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-define-property": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-errors": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-object-atoms": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
+ "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.0.tgz",
+ "integrity": "sha512-sNR9MHpXSUV/XB4zmsFKN+QgVG82Cc7+/aaxJ8Adi8hyOac+EXptIp45QBPaVyX3N70664wRbTcLTOemCAnyqw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.28.0",
+ "@esbuild/android-arm": "0.28.0",
+ "@esbuild/android-arm64": "0.28.0",
+ "@esbuild/android-x64": "0.28.0",
+ "@esbuild/darwin-arm64": "0.28.0",
+ "@esbuild/darwin-x64": "0.28.0",
+ "@esbuild/freebsd-arm64": "0.28.0",
+ "@esbuild/freebsd-x64": "0.28.0",
+ "@esbuild/linux-arm": "0.28.0",
+ "@esbuild/linux-arm64": "0.28.0",
+ "@esbuild/linux-ia32": "0.28.0",
+ "@esbuild/linux-loong64": "0.28.0",
+ "@esbuild/linux-mips64el": "0.28.0",
+ "@esbuild/linux-ppc64": "0.28.0",
+ "@esbuild/linux-riscv64": "0.28.0",
+ "@esbuild/linux-s390x": "0.28.0",
+ "@esbuild/linux-x64": "0.28.0",
+ "@esbuild/netbsd-arm64": "0.28.0",
+ "@esbuild/netbsd-x64": "0.28.0",
+ "@esbuild/openbsd-arm64": "0.28.0",
+ "@esbuild/openbsd-x64": "0.28.0",
+ "@esbuild/openharmony-arm64": "0.28.0",
+ "@esbuild/sunos-x64": "0.28.0",
+ "@esbuild/win32-arm64": "0.28.0",
+ "@esbuild/win32-ia32": "0.28.0",
+ "@esbuild/win32-x64": "0.28.0"
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/function-bind": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
+ "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-intrinsic": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
+ "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "es-define-property": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "es-object-atoms": "^1.1.1",
+ "function-bind": "^1.1.2",
+ "get-proto": "^1.0.1",
+ "gopd": "^1.2.0",
+ "has-symbols": "^1.1.0",
+ "hasown": "^2.0.2",
+ "math-intrinsics": "^1.1.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
+ "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
+ "license": "MIT",
+ "dependencies": {
+ "dunder-proto": "^1.0.1",
+ "es-object-atoms": "^1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/gopd": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/has-symbols": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
+ "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/hasown": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
+ "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
+ "license": "MIT",
+ "dependencies": {
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/math-intrinsics": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
+ "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/object-inspect": {
+ "version": "1.13.4",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
+ "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/qs": {
+ "version": "6.15.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz",
+ "integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "side-channel": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
+ "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3",
+ "side-channel-list": "^1.0.0",
+ "side-channel-map": "^1.0.1",
+ "side-channel-weakmap": "^1.0.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-list": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
+ "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.4"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-map": {
+ "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==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-weakmap": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
+ "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3",
+ "side-channel-map": "^1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/stripe": {
+ "version": "17.7.0",
+ "resolved": "https://registry.npmjs.org/stripe/-/stripe-17.7.0.tgz",
+ "integrity": "sha512-aT2BU9KkizY9SATf14WhhYVv2uOapBWX0OFWF4xvcj1mPaNotlSc2CsxpS4DS46ZueSppmCF5BX1sNYBtwBvfw==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/node": ">=8.1.0",
+ "qs": "^6.11.0"
+ },
+ "engines": {
+ "node": ">=12.*"
+ }
+ },
+ "node_modules/tsx": {
+ "version": "4.22.4",
+ "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz",
+ "integrity": "sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "esbuild": "~0.28.0"
+ },
+ "bin": {
+ "tsx": "dist/cli.mjs"
+ },
+ "engines": {
+ "node": ">=18.0.0"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ }
+ },
+ "node_modules/typescript": {
+ "version": "5.9.3",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
+ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ },
+ "node_modules/undici-types": {
+ "version": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "license": "MIT"
+ }
+ }
+}
diff --git a/examples/stripe-link-fraud/package.json b/examples/stripe-link-fraud/package.json
new file mode 100644
index 000000000..afc01be73
--- /dev/null
+++ b/examples/stripe-link-fraud/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "stripe-link-fraud",
+ "version": "0.1.0",
+ "private": true,
+ "type": "module",
+ "engines": {
+ "node": ">=22"
+ },
+ "scripts": {
+ "start": "docker compose up -d && tsx web/server.ts",
+ "ui": "tsx web/server.ts",
+ "index": "tsx src/index-build.ts",
+ "typecheck": "tsc -p tsconfig.json --noEmit"
+ },
+ "dependencies": {
+ "@superlinked/sie-sdk": "^0.3.1",
+ "stripe": "^17.4.0"
+ },
+ "devDependencies": {
+ "@types/node": "^22.10.0",
+ "tsx": "^4.21.0",
+ "typescript": "^5.7.2"
+ }
+}
diff --git a/examples/stripe-link-fraud/src/config.ts b/examples/stripe-link-fraud/src/config.ts
new file mode 100644
index 000000000..645494caa
--- /dev/null
+++ b/examples/stripe-link-fraud/src/config.ts
@@ -0,0 +1,44 @@
+export const config = {
+ sieUrl: process.env.SIE_URL ?? "http://localhost:8080",
+ sieApiKey: process.env.SIE_API_KEY,
+
+ stripe: {
+ publishableKey: process.env.STRIPE_PUBLISHABLE_KEY ?? "",
+ secretKey: process.env.STRIPE_SECRET_KEY ?? "",
+ apiVersion: "2025-02-24.acacia" as const,
+ },
+
+ models: {
+ extractor: "urchade/gliner_multi-v2.1",
+ encoder: "sentence-transformers/all-MiniLM-L6-v2",
+ reranker: "BAAI/bge-reranker-base",
+ },
+
+ extractLabels: ["product", "shipping_address", "email_domain", "amount"],
+
+ risk: {
+ // Thresholds are tuned for the bundled synthetic fraud-pattern corpus
+ // (MiniLM-L6 cosine similarities). Below blockThreshold => low. Between
+ // block and review => medium. Above reviewThreshold => high. Stripe
+ // Link still authorizes in every case; the demo just shows the band.
+ blockThreshold: 0.47,
+ reviewThreshold: 0.52,
+ topKRerank: 3,
+ },
+
+ paths: {
+ fraudPatterns: "data/fraud_patterns.json",
+ sampleOrders: "data/sample_orders.json",
+ index: "data/risk_index.json",
+ },
+
+ port: Number(process.env.PORT ?? 3033),
+} as const;
+
+export type RiskBand = "low" | "medium" | "high";
+
+export function riskBand(score: number): RiskBand {
+ if (score >= config.risk.reviewThreshold) return "high";
+ if (score >= config.risk.blockThreshold) return "medium";
+ return "low";
+}
diff --git a/examples/stripe-link-fraud/src/events.ts b/examples/stripe-link-fraud/src/events.ts
new file mode 100644
index 000000000..37f83f811
--- /dev/null
+++ b/examples/stripe-link-fraud/src/events.ts
@@ -0,0 +1,35 @@
+// Typed SSE events streamed to the browser during a risk-score run.
+
+export type RiskEvent =
+ | { type: "models"; data: { encoder: string; reranker: string; extractor: string } }
+ | { type: "extracting" }
+ | { type: "extracted"; data: { entities: ExtractedEntity[]; ms: number } }
+ | { type: "encoding" }
+ | { type: "encoded"; data: { dim: number; ms: number } }
+ | { type: "scoring" }
+ | {
+ type: "scored";
+ data: {
+ hits: RiskHit[];
+ topScore: number;
+ band: "low" | "medium" | "high";
+ ms: number;
+ };
+ }
+ | { type: "done"; data: { totalMs: number } }
+ | { type: "error"; data: { stage: string; message: string } };
+
+export interface ExtractedEntity {
+ label: string;
+ text: string;
+ score: number;
+}
+
+export interface RiskHit {
+ id: string;
+ label: string;
+ summary: string;
+ outcome: string;
+ loss_usd: number;
+ score: number;
+}
diff --git a/examples/stripe-link-fraud/src/index-build.ts b/examples/stripe-link-fraud/src/index-build.ts
new file mode 100644
index 000000000..4a23ba6aa
--- /dev/null
+++ b/examples/stripe-link-fraud/src/index-build.ts
@@ -0,0 +1,41 @@
+// One-time index build: encode the fraud-pattern corpus into dense vectors
+// and dump to data/risk_index.json. Re-run with `npm run index` after
+// editing data/fraud_patterns.json.
+import fs from "node:fs";
+import path from "node:path";
+import { SIEClient } from "@superlinked/sie-sdk";
+import { config } from "./config.js";
+import type { FraudPattern, IndexRecord } from "./types.js";
+
+async function main(): Promise<void> {
+ const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
+ const inPath = path.join(root, config.paths.fraudPatterns);
+ const outPath = path.join(root, config.paths.index);
+
+ const patterns: FraudPattern[] = JSON.parse(fs.readFileSync(inPath, "utf8"));
+ console.log(`encoding ${patterns.length} fraud patterns`);
+
+ const client = new SIEClient(config.sieUrl, {
+ apiKey: config.sieApiKey,
+ timeout: 600_000,
+ waitForCapacity: true,
+ provisionTimeout: 900_000,
+ });
+
+ const items = patterns.map((p) => ({ id: p.id, text: `${p.label}. ${p.summary}` }));
+ const results = await client.encode(config.models.encoder, items);
+
+ const records: IndexRecord[] = patterns.map((p, i) => {
+ const single = results[i];
+ if (!single?.dense) throw new Error(`encoder returned no dense vector for ${p.id}`);
+ return { id: p.id, vector: Array.from(single.dense) };
+ });
+
+ fs.writeFileSync(outPath, JSON.stringify(records, null, 2));
+ console.log(`wrote ${outPath} (${records.length} vectors, dim=${records[0]?.vector.length})`);
+}
+
+main().catch((err) => {
+ console.error(err);
+ process.exit(1);
+});
diff --git a/examples/stripe-link-fraud/src/risk.ts b/examples/stripe-link-fraud/src/risk.ts
new file mode 100644
index 000000000..0a580d104
--- /dev/null
+++ b/examples/stripe-link-fraud/src/risk.ts
@@ -0,0 +1,167 @@
+// SIE-driven fraud risk scoring for a Stripe Link checkout.
+//
+// Pipeline:
+// 1. Build a natural-language summary of the order context (cart + customer).
+// 2. Extract entities with GLiNER (used to surface signals to the UI; not
+// directly fed into the score).
+// 3. Encode the summary with a small dense encoder (MiniLM).
+// 4. Cosine-rank against a pre-encoded fraud-pattern corpus.
+// 5. Rerank the top K with a cross-encoder for a sharper final score.
+// 6. Map the top reranker score to a low/medium/high band.
+
+import fs from "node:fs";
+import path from "node:path";
+import { SIEClient } from "@superlinked/sie-sdk";
+import { config, riskBand } from "./config.js";
+import type { RiskEvent } from "./events.js";
+import type { CartItem, Customer, FraudPattern, IndexRecord, SampleOrder } from "./types.js";
+
+const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
+
+function loadJson<T>(rel: string): T {
+ return JSON.parse(fs.readFileSync(path.join(ROOT, rel), "utf8")) as T;
+}
+
+export function buildOrderSummary(
+ cart: CartItem[],
+ customer: Customer,
+ context?: string,
+): string {
+ const total = cart.reduce((s, i) => s + i.qty * i.unit_price_usd, 0);
+ const skus = cart.map((i) => `${i.qty}x ${i.name} ($${i.unit_price_usd})`).join(", ");
+ const linkStatus = customer.link_returning
+ ? "returning Link customer"
+ : "new Link signup (no prior history)";
+ const geo =
+ customer.billing_country === customer.shipping_country &&
+ customer.shipping_country === customer.ip_country
+ ? `all signals from ${customer.billing_country}`
+ : `billing=${customer.billing_country} shipping=${customer.shipping_country} ip=${customer.ip_country}`;
+ return [
+ `Order total $${total} for ${customer.name} (${customer.email}).`,
+ `Cart: ${skus}.`,
+ `Shipping to: ${customer.shipping_address}.`,
+ `Customer: account age ${customer.account_age_days} days, ${customer.prior_orders} prior orders, ${linkStatus}.`,
+ `Geography: ${geo}.`,
+ context ? `Context: ${context}` : "",
+ ]
+ .filter(Boolean)
+ .join(" ");
+}
+
+function cosine(a: number[], b: number[]): number {
+ let dot = 0;
+ let na = 0;
+ let nb = 0;
+ for (let i = 0; i < a.length; i++) {
+ const x = a[i]!;
+ const y = b[i]!;
+ dot += x * y;
+ na += x * x;
+ nb += y * y;
+ }
+ const denom = Math.sqrt(na) * Math.sqrt(nb);
+ return denom === 0 ? 0 : dot / denom;
+}
+
+export interface RiskInput {
+ cart: CartItem[];
+ customer: Customer;
+ context?: string;
+}
+
+export interface RiskRunDeps {
+ client: SIEClient;
+ emit: (event: RiskEvent) => void;
+}
+
+export async function runRisk(input: RiskInput, deps: RiskRunDeps): Promise<void> {
+ const { client, emit } = deps;
+ const start = Date.now();
+
+ emit({
+ type: "models",
+ data: {
+ encoder: config.models.encoder,
+ reranker: config.models.reranker,
+ extractor: config.models.extractor,
+ },
+ });
+
+ const summary = buildOrderSummary(input.cart, input.customer, input.context);
+
+ // 1. Extract entities (surface signals to the UI; not fed into the score).
+ emit({ type: "extracting" });
+ const tEx = Date.now();
+ const extractOut = await client.extract(
+ config.models.extractor,
+ { text: summary },
+ { labels: [...config.extractLabels] },
+ );
+ const entities = (extractOut.entities ?? []).map((e) => ({
+ label: e.label ?? "",
+ text: e.text ?? "",
+ score: Number(e.score ?? 0),
+ }));
+ emit({ type: "extracted", data: { entities, ms: Date.now() - tEx } });
+
+ // 2. Encode the summary.
+ emit({ type: "encoding" });
+ const tEn = Date.now();
+ const enc = await client.encode(config.models.encoder, { text: summary });
+ const queryVec = enc.dense;
+ if (!queryVec) throw new Error("encoder returned no dense vector for the order");
+ emit({
+ type: "encoded",
+ data: { dim: queryVec.length, ms: Date.now() - tEn },
+ });
+
+ // 3. Cosine-rank the corpus to pick the top-K candidates.
+ const patterns: FraudPattern[] = loadJson(config.paths.fraudPatterns);
+ const index: IndexRecord[] = loadJson(config.paths.index);
+ const byId = new Map(patterns.map((p) => [p.id, p]));
+ const cosineRanked = index
+ .map((rec) => ({ id: rec.id, score: cosine(Array.from(queryVec), rec.vector) }))
+ .sort((a, b) => b.score - a.score)
+ .slice(0, config.risk.topKRerank);
+ const cosineById = new Map(cosineRanked.map((c) => [c.id, c.score]));
+
+ // 4. Rerank with the cross-encoder. The reranker output orders the top-K
+ // for display; the band signal stays on cosine because the cosine score
+ // has a usable 0-1 spread, whereas raw cross-encoder logits cluster near
+ // zero for this kind of "order-vs-fraud-pattern" similarity.
+ emit({ type: "scoring" });
+ const tSc = Date.now();
+ const docs = cosineRanked.map((c) => {
+ const p = byId.get(c.id);
+ return { id: c.id, text: p ? `${p.label}. ${p.summary}` : "" };
+ });
+ const score = await client.score(config.models.reranker, { text: summary }, docs);
+ const rerankById = new Map<string, number>();
+ for (const s of score.scores ?? []) rerankById.set(s.itemId, s.score);
+ const hits = cosineRanked.map((c) => {
+ const p = byId.get(c.id)!;
+ return {
+ id: p.id,
+ label: p.label,
+ summary: p.summary,
+ outcome: p.outcome,
+ loss_usd: p.loss_usd,
+ // Reranker score is the display-time order; cosine drives the band.
+ score: rerankById.get(c.id) ?? 0,
+ };
+ });
+ hits.sort((a, b) => b.score - a.score);
+ const topScore = cosineById.get(cosineRanked[0]?.id ?? "") ?? 0;
+ const band = riskBand(topScore);
+ emit({
+ type: "scored",
+ data: { hits, topScore, band, ms: Date.now() - tSc },
+ });
+
+ emit({ type: "done", data: { totalMs: Date.now() - start } });
+}
+
+export function loadSampleOrders(): SampleOrder[] {
+ return loadJson<SampleOrder[]>(config.paths.sampleOrders);
+}
diff --git a/examples/stripe-link-fraud/src/types.ts b/examples/stripe-link-fraud/src/types.ts
new file mode 100644
index 000000000..d9e468c79
--- /dev/null
+++ b/examples/stripe-link-fraud/src/types.ts
@@ -0,0 +1,39 @@
+export interface FraudPattern {
+ id: string;
+ label: string;
+ summary: string;
+ outcome: string;
+ loss_usd: number;
+}
+
+export interface CartItem {
+ sku: string;
+ name: string;
+ qty: number;
+ unit_price_usd: number;
+}
+
+export interface Customer {
+ email: string;
+ name: string;
+ account_age_days: number;
+ prior_orders: number;
+ link_returning: boolean;
+ billing_country: string;
+ shipping_country: string;
+ shipping_address: string;
+ ip_country: string;
+}
+
+export interface SampleOrder {
+ id: string;
+ label: string;
+ description: string;
+ cart: CartItem[];
+ customer: Customer;
+}
+
+export interface IndexRecord {
+ id: string;
+ vector: number[];
+}
diff --git a/examples/stripe-link-fraud/tsconfig.json b/examples/stripe-link-fraud/tsconfig.json
new file mode 100644
index 000000000..73e0dbb74
--- /dev/null
+++ b/examples/stripe-link-fraud/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "ESNext",
+ "moduleResolution": "Bundler",
+ "strict": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "resolveJsonModule": true,
+ "allowImportingTsExtensions": false,
+ "noEmit": true,
+ "lib": ["ES2022", "DOM"],
+ "types": ["node"]
+ },
+ "include": ["src/**/*.ts", "web/**/*.ts"]
+}
diff --git a/examples/stripe-link-fraud/web/public/app.js b/examples/stripe-link-fraud/web/public/app.js
new file mode 100644
index 000000000..78cc187c1
--- /dev/null
+++ b/examples/stripe-link-fraud/web/public/app.js
@@ -0,0 +1,346 @@
+// stripe-link-fraud frontend: SSE-driven risk panel + Stripe Elements (Link)
+// checkout. No build step; vanilla JS.
+
+const els = {
+ badge: document.getElementById("badge"),
+ sieState: document.getElementById("sie-state"),
+ stripeState: document.getElementById("stripe-state"),
+ sieUrl: document.getElementById("sie-url"),
+ orders: document.getElementById("orders"),
+ risk: document.getElementById("risk"),
+ riskMeta: document.getElementById("risk-meta"),
+ checkout: document.getElementById("checkout"),
+ checkoutMeta: document.getElementById("checkout-meta"),
+ timings: document.getElementById("timings"),
+};
+
+let stripe = null;
+let elements = null;
+let activeOrder = null;
+let currentRisk = null;
+let stripeMode = "mock";
+let stripePk = null;
+
+function setBadge(text, cls) {
+ els.badge.textContent = text;
+ els.badge.className = "badge" + (cls ? " " + cls : "");
+}
+
+function fmtMs(ms) {
+ if (ms < 1000) return `${ms} ms`;
+ return `${(ms / 1000).toFixed(2)} s`;
+}
+
+function fmtUsd(n) {
+ return `$${n.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}`;
+}
+
+function escapeHtml(s) {
+ return String(s)
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;")
+ .replace(/"/g, "&quot;");
+}
+
+function renderOrders(samples) {
+ if (!samples?.length) {
+ els.orders.innerHTML = '<p class="hint">no samples</p>';
+ return;
+ }
+ els.orders.innerHTML = samples
+ .map((s) => {
+ const total = s.cart.reduce((acc, i) => acc + i.qty * i.unit_price_usd, 0);
+ return `
+ <div class="order" data-id="${s.id}">
+ <div class="order-head">
+ <span class="order-label">${escapeHtml(s.label)}</span>
+ <span class="order-total">${fmtUsd(total)}</span>
+ </div>
+ <div class="order-desc">${escapeHtml(s.description)}</div>
+ <div class="order-meta">
+ <span class="pill">${escapeHtml(s.customer.email)}</span>
+ <span class="pill">${s.customer.link_returning ? "Link returning" : "Link new"}</span>
+ <span class="pill">${escapeHtml(s.customer.billing_country)}/${escapeHtml(s.customer.ip_country)}</span>
+ </div>
+ </div>`;
+ })
+ .join("");
+ for (const node of els.orders.querySelectorAll(".order")) {
+ node.addEventListener("click", () => {
+ for (const o of els.orders.querySelectorAll(".order")) o.classList.remove("active");
+ node.classList.add("active");
+ const id = node.dataset.id;
+ activeOrder = samples.find((s) => s.id === id);
+ runRisk(id);
+ });
+ }
+}
+
+function renderRiskPanelStart() {
+ els.risk.innerHTML = `
+ <div class="risk-stages">
+ <div class="stage" data-key="extract"><span class="stage-dot"></span> extract</div>
+ <div class="stage" data-key="encode"><span class="stage-dot"></span> encode</div>
+ <div class="stage" data-key="score"><span class="stage-dot"></span> score</div>
+ </div>
+ <div class="risk-body"></div>`;
+ els.riskMeta.textContent = "";
+ els.timings.textContent = "";
+}
+
+function setStage(key, state) {
+ const node = els.risk.querySelector(`.stage[data-key="${key}"]`);
+ if (node) node.dataset.state = state;
+}
+
+function renderEntities(entities) {
+ if (!entities?.length) return '<p class="hint">no entities extracted</p>';
+ return entities
+ .map(
+ (e) => `
+ <span class="entity-group" title="GLiNER confidence: ${e.score.toFixed(3)}">
+ <span class="ekey">${escapeHtml(e.label)}</span>
+ <span class="eval">${escapeHtml(e.text)}</span>
+ <span class="econf">${e.score.toFixed(2)}</span>
+ </span>`,
+ )
+ .join("");
+}
+
+function renderHits(hits, topScore, band) {
+ const bandWhy = {
+ low: "below the block threshold (cosine &lt; 0.47). Proceed with normal Link checkout.",
+ medium: "between block and review thresholds (0.47 - 0.52). Authorize but flag for analyst review.",
+ high: "above the review threshold (cosine &gt; 0.52). Hold for review before clearing.",
+ }[band];
+ return `
+ <div class="risk-band band-${band}">
+ <div class="band-label">SIE risk band</div>
+ <div class="band-value">${band.toUpperCase()}</div>
+ <div class="band-score" title="Cosine similarity of the order embedding to the closest fraud pattern in the corpus.">
+ top cosine ${topScore.toFixed(3)}
+ </div>
+ </div>
+ <p class="band-why">${bandWhy}</p>
+ <div class="score-legend">
+ Each row below shows a candidate fraud pattern. The number on the right is the
+ <strong>cross-encoder reranker score</strong> for this order against that pattern
+ (higher = more semantically similar). The top-3 cosine candidates are reranked
+ and reordered by this score.
+ </div>
+ <div class="hits">
+ ${hits
+ .map(
+ (h) => `
+ <div class="hit">
+ <div class="hit-head">
+ <span class="hit-label">${escapeHtml(h.label)}</span>
+ <span class="hit-score" title="Cross-encoder relevance score (BGE-reranker-base), 0-1 range. Higher = more semantically similar to this fraud pattern.">${h.score.toFixed(3)}</span>
+ </div>
+ <div class="hit-summary">${escapeHtml(h.summary)}</div>
+ <div class="hit-meta">
+ <span class="pill outcome-${h.outcome}">${escapeHtml(h.outcome)}</span>
+ <span class="pill">${fmtUsd(h.loss_usd)} historical loss</span>
+ </div>
+ </div>`,
+ )
+ .join("")}
+ </div>`;
+}
+
+async function runRisk(id) {
+ setBadge("running", "running");
+ renderRiskPanelStart();
+ els.checkout.innerHTML = '<p class="hint">Risk pipeline running...</p>';
+ const evt = new EventSource(`/api/run?id=${encodeURIComponent(id)}`);
+ const body = els.risk.querySelector(".risk-body");
+ const ts = { extract: 0, encode: 0, score: 0, total: 0 };
+
+ evt.addEventListener("extracting", () => setStage("extract", "running"));
+ evt.addEventListener("extracted", (e) => {
+ setStage("extract", "done");
+ const data = JSON.parse(e.data);
+ ts.extract = data.ms;
+ body.insertAdjacentHTML(
+ "beforeend",
+ `<div class="risk-section">
+ <div class="risk-section-head">Extracted signals · ${fmtMs(data.ms)}</div>
+ <div class="hint" style="margin-bottom:8px">
+ GLiNER zero-shot NER pulls typed entities out of the order summary.
+ The number next to each label is the model's confidence (0-1) for that span.
+ </div>
+ <div class="entities">${renderEntities(data.entities)}</div>
+ </div>`,
+ );
+ });
+ evt.addEventListener("encoding", () => setStage("encode", "running"));
+ evt.addEventListener("encoded", (e) => {
+ setStage("encode", "done");
+ const data = JSON.parse(e.data);
+ ts.encode = data.ms;
+ body.insertAdjacentHTML(
+ "beforeend",
+ `<div class="risk-section">
+ <div class="risk-section-head">Encoded order context · ${fmtMs(data.ms)}</div>
+ <div class="hint">
+ MiniLM-L6 turns the order summary into a dense ${data.dim}-dimensional vector.
+ Cosine similarity against pre-encoded fraud-pattern vectors picks the top-3 candidates for reranking.
+ </div>
+ </div>`,
+ );
+ });
+ evt.addEventListener("scoring", () => setStage("score", "running"));
+ evt.addEventListener("scored", (e) => {
+ setStage("score", "done");
+ const data = JSON.parse(e.data);
+ ts.score = data.ms;
+ body.insertAdjacentHTML(
+ "beforeend",
+ `<div class="risk-section">
+ <div class="risk-section-head">Reranked top matches · ${fmtMs(data.ms)}</div>
+ ${renderHits(data.hits, data.topScore, data.band)}
+ </div>`,
+ );
+ currentRisk = { band: data.band, topScore: data.topScore };
+ mountCheckout();
+ });
+ evt.addEventListener("done", (e) => {
+ const data = JSON.parse(e.data);
+ ts.total = data.totalMs;
+ setBadge("done", "green");
+ els.timings.textContent = `extract ${fmtMs(ts.extract)} · encode ${fmtMs(ts.encode)} · score ${fmtMs(ts.score)} · total ${fmtMs(ts.total)}`;
+ evt.close();
+ });
+ evt.addEventListener("error", (e) => {
+ setBadge("error", "red");
+ let msg = "stream error";
+ try {
+ const data = JSON.parse(e.data);
+ msg = `${data.stage}: ${data.message}`;
+ } catch {
+ /* network error event has no payload */
+ }
+ body.insertAdjacentHTML("beforeend", `<div class="error">${escapeHtml(msg)}</div>`);
+ evt.close();
+ });
+}
+
+async function mountCheckout() {
+ if (!activeOrder) return;
+ const total = activeOrder.cart.reduce((s, i) => s + i.qty * i.unit_price_usd, 0);
+ if (stripeMode === "mock") {
+ els.checkout.innerHTML = `
+ <div class="mock-checkout">
+ <div class="mock-banner">
+ Stripe keys not set. The risk pipeline above runs against real SIE;
+ set <code>STRIPE_PUBLISHABLE_KEY</code> and <code>STRIPE_SECRET_KEY</code>
+ in <code>.env</code> (test mode) to mount a real Link payment form.
+ </div>
+ <div class="mock-cart">
+ <div class="mock-cart-head">
+ <span>Cart</span>
+ <span>${fmtUsd(total)}</span>
+ </div>
+ ${activeOrder.cart
+ .map(
+ (i) => `
+ <div class="mock-cart-row">
+ <span>${escapeHtml(i.name)} × ${i.qty}</span>
+ <span>${fmtUsd(i.qty * i.unit_price_usd)}</span>
+ </div>`,
+ )
+ .join("")}
+ </div>
+ <div class="mock-link-button" data-band="${currentRisk?.band ?? "low"}">
+ ${currentRisk?.band === "high" ? "Hold for review" : "Pay with Link"}
+ </div>
+ </div>`;
+ els.checkoutMeta.textContent = `mock · risk ${currentRisk?.band ?? ""}`;
+ return;
+ }
+
+ els.checkout.innerHTML = '<p class="hint">Creating PaymentIntent...</p>';
+ try {
+ const r = await fetch("/api/payment-intent", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ cart: activeOrder.cart,
+ customer: activeOrder.customer,
+ riskBand: currentRisk?.band ?? "unknown",
+ }),
+ });
+ const j = await r.json();
+ if (j.mode !== "live") throw new Error("server returned mock mode");
+ els.checkout.innerHTML = `
+ <div class="cart-summary">
+ <div class="cart-head"><span>Cart</span><span>${fmtUsd(total)}</span></div>
+ ${activeOrder.cart
+ .map(
+ (i) => `
+ <div class="cart-row">
+ <span>${escapeHtml(i.name)} × ${i.qty}</span>
+ <span>${fmtUsd(i.qty * i.unit_price_usd)}</span>
+ </div>`,
+ )
+ .join("")}
+ </div>
+ <div id="payment-element"></div>
+ <button id="pay-btn" class="pay-btn band-${currentRisk?.band ?? "low"}">
+ ${currentRisk?.band === "high" ? "Hold for review" : "Pay with Link"}
+ </button>
+ <div id="pay-msg" class="pay-msg"></div>`;
+ stripe = stripe ?? Stripe(j.publishableKey ?? stripePk);
+ elements = stripe.elements({ clientSecret: j.clientSecret });
+ const payEl = elements.create("payment", { layout: "tabs" });
+ payEl.mount("#payment-element");
+ const btn = document.getElementById("pay-btn");
+ const msg = document.getElementById("pay-msg");
+ btn.addEventListener("click", async () => {
+ btn.disabled = true;
+ msg.textContent = "";
+ const { error } = await stripe.confirmPayment({
+ elements,
+ confirmParams: { return_url: window.location.href },
+ });
+ if (error) {
+ msg.textContent = error.message ?? "payment failed";
+ msg.className = "pay-msg error";
+ btn.disabled = false;
+ }
+ });
+ els.checkoutMeta.textContent = `live · risk ${currentRisk?.band ?? ""}`;
+ } catch (e) {
+ els.checkout.innerHTML = `<div class="error">${escapeHtml(e?.message ?? String(e))}</div>`;
+ }
+}
+
+async function init() {
+ els.sieUrl.textContent = "...";
+ try {
+ const r = await fetch("/api/health");
+ const j = await r.json();
+ els.sieUrl.textContent = j.sieUrl;
+ els.sieState.textContent = j.sie
+ ? `SIE healthy · ${j.registeredModels} models`
+ : "SIE not reachable yet";
+ stripeMode = j.stripe;
+ stripePk = j.publishableKey;
+ els.stripeState.textContent =
+ stripeMode === "live"
+ ? "Stripe: live (test keys detected)"
+ : "Stripe: mock (no keys set)";
+ } catch {
+ els.sieState.textContent = "could not reach the local server";
+ }
+ try {
+ const r = await fetch("/api/samples");
+ const samples = await r.json();
+ renderOrders(samples);
+ } catch {
+ els.orders.innerHTML = '<p class="hint">failed to load samples</p>';
+ }
+}
+
+init();
diff --git a/examples/stripe-link-fraud/web/public/architecture.svg b/examples/stripe-link-fraud/web/public/architecture.svg
new file mode 100644
index 000000000..7a92a2677
--- /dev/null
+++ b/examples/stripe-link-fraud/web/public/architecture.svg
@@ -0,0 +1,118 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 920 360" role="img" aria-label="stripe-link-fraud architecture diagram">
+ <defs>
+ <style><![CDATA[
+ .bg { fill: #0e1014; }
+ .card { fill: #161a22; stroke: #232936; stroke-width: 1; rx: 10; ry: 10; }
+ .head { fill: #1c2230; }
+ .label { font: 600 12px "Inter", system-ui, sans-serif; fill: #e6e8ec; }
+ .sub { font: 400 11px "Inter", system-ui, sans-serif; fill: #8b94a7; }
+ .mono { font: 11px ui-monospace, "JetBrains Mono", monospace; fill: #c89cff; }
+ .accent { fill: #7c5dff; }
+ .info { fill: #62b6ff; }
+ .succ { fill: #5fd28b; }
+ .stroke-accent { stroke: #7c5dff; stroke-width: 1.5; fill: none; }
+ .stroke-info { stroke: #62b6ff; stroke-width: 1.5; fill: none; }
+ .stroke-succ { stroke: #5fd28b; stroke-width: 1.5; fill: none; }
+ .stroke-mute { stroke: #232936; stroke-width: 1.5; fill: none; }
+ .pill-bg-accent { fill: rgba(124,93,255,0.15); }
+ .pill-bg-info { fill: rgba(98,182,255,0.15); }
+ .pill-bg-succ { fill: rgba(95,210,139,0.15); }
+ ]]></style>
+ <marker id="arrow" markerWidth="10" markerHeight="10" refX="6" refY="3" orient="auto" markerUnits="strokeWidth">
+ <path d="M0,0 L0,6 L6,3 z" fill="#8b94a7" />
+ </marker>
+ <marker id="arrow-accent" markerWidth="10" markerHeight="10" refX="6" refY="3" orient="auto" markerUnits="strokeWidth">
+ <path d="M0,0 L0,6 L6,3 z" fill="#7c5dff" />
+ </marker>
+ </defs>
+
+ <rect class="bg" x="0" y="0" width="920" height="360" />
+
+ <!-- Step 1: checkout context -->
+ <g transform="translate(40,140)">
+ <rect class="card" width="180" height="80" rx="10" />
+ <rect class="head" x="0" y="0" width="180" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="180" height="10" />
+ <text class="label" x="14" y="16">checkout context</text>
+ <text class="sub" x="14" y="42">cart</text>
+ <text class="sub" x="14" y="58">customer profile</text>
+ <text class="sub" x="14" y="72">Link history + geo</text>
+ <circle class="info" cx="166" cy="11" r="4" />
+ </g>
+
+ <!-- Step 2: SIE server -->
+ <g transform="translate(280,80)">
+ <rect class="card" width="360" height="200" rx="10" />
+ <rect class="head" x="0" y="0" width="360" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="360" height="10" />
+ <text class="label" x="14" y="16">one SIE server</text>
+ <text class="sub" x="338" y="16" text-anchor="end">3 primitives, 1 round-trip</text>
+ <circle class="accent" cx="350" cy="11" r="3" />
+
+ <!-- 3 primitives inside SIE -->
+ <g transform="translate(20,40)">
+ <rect class="pill-bg-info" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">extract</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">GLiNER</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">signals</text>
+ </g>
+ <g transform="translate(130,40)">
+ <rect class="pill-bg-accent" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">encode</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">MiniLM-L6</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">dense 384-d</text>
+ </g>
+ <g transform="translate(240,40)">
+ <rect class="pill-bg-succ" width="100" height="56" rx="6" />
+ <text class="label" x="50" y="22" text-anchor="middle">score</text>
+ <text class="sub" x="50" y="40" text-anchor="middle">BGE-reranker</text>
+ <text class="sub" x="50" y="52" text-anchor="middle">top-K rerank</text>
+ </g>
+
+ <!-- corpus -->
+ <g transform="translate(60,118)">
+ <rect class="card" width="240" height="60" rx="8" />
+ <text class="label" x="120" y="22" text-anchor="middle">fraud_patterns.json</text>
+ <text class="sub" x="120" y="40" text-anchor="middle">12 past patterns, pre-encoded</text>
+ <text class="mono" x="120" y="54" text-anchor="middle">cosine top-3 → reranker</text>
+ </g>
+ </g>
+
+ <!-- Step 3: risk band -->
+ <g transform="translate(700,80)">
+ <rect class="card" width="180" height="200" rx="10" />
+ <rect class="head" x="0" y="0" width="180" height="22" rx="10" />
+ <rect class="head" x="0" y="12" width="180" height="10" />
+ <text class="label" x="14" y="16">risk band</text>
+ <circle class="succ" cx="166" cy="11" r="4" />
+
+ <g transform="translate(16,36)">
+ <rect class="pill-bg-succ" width="148" height="34" rx="6" />
+ <text class="label succ" x="14" y="22">low</text>
+ <text class="sub" x="50" y="22">cosine &lt; 0.47</text>
+ </g>
+ <g transform="translate(16,76)">
+ <rect width="148" height="34" rx="6" fill="rgba(247,201,72,0.18)" />
+ <text class="label" x="14" y="22" fill="#f7c948">medium</text>
+ <text class="sub" x="68" y="22">0.47-0.52</text>
+ </g>
+ <g transform="translate(16,116)">
+ <rect width="148" height="34" rx="6" fill="rgba(255,107,107,0.18)" />
+ <text class="label" x="14" y="22" fill="#ff6b6b">high</text>
+ <text class="sub" x="56" y="22">&gt; 0.52</text>
+ </g>
+ <g transform="translate(16,164)">
+ <text class="sub" x="0" y="0">→ PaymentIntent.metadata</text>
+ <text class="sub" x="0" y="14">→ Link Element CTA</text>
+ </g>
+ </g>
+
+ <!-- Arrows -->
+ <line class="stroke-mute" x1="220" y1="180" x2="278" y2="180" marker-end="url(#arrow)" />
+ <line class="stroke-mute" x1="640" y1="180" x2="698" y2="180" marker-end="url(#arrow)" />
+
+ <!-- Footer / title -->
+ <text class="label" x="460" y="40" text-anchor="middle">stripe-link-fraud</text>
+ <text class="sub" x="460" y="56" text-anchor="middle">pre-authorization fraud-risk gate, three SIE primitives in one round-trip</text>
+ <text class="sub" x="460" y="334" text-anchor="middle">Apache 2.0 · runs locally with docker compose · hosted on Hugging Face Spaces</text>
+</svg>
diff --git a/examples/stripe-link-fraud/web/public/index.html b/examples/stripe-link-fraud/web/public/index.html
new file mode 100644
index 000000000..d607a939e
--- /dev/null
+++ b/examples/stripe-link-fraud/web/public/index.html
@@ -0,0 +1,83 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <title>stripe-link-fraud</title>
+ <link rel="preconnect" href="https://rsms.me/" />
+ <link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
+ <link rel="stylesheet" href="/static/style.css" />
+ <script src="https://js.stripe.com/v3/"></script>
+ </head>
+ <body>
+ <header>
+ <div class="title">
+ <span class="logo">🔒</span>
+ <h1>stripe-link-fraud</h1>
+ <span class="badge" id="badge">idle</span>
+ </div>
+ <div class="meta" id="sie-state">checking SIE...</div>
+ <div class="meta" id="stripe-state">Stripe: ...</div>
+ <div class="cta-row">
+ <a class="cta" href="https://github.com/superlinked/brave-new-demos/tree/main/stripe-link-fraud" target="_blank" rel="noopener">
+ <span>↗</span> Source
+ </a>
+ <a class="cta" href="https://github.com/superlinked/sie" target="_blank" rel="noopener">
+ <span>★</span> SIE repo
+ </a>
+ </div>
+ </header>
+
+ <section class="hero">
+ <div class="hero-text">
+ <p>
+ When a checkout lands, the merchant has seconds to decide:
+ authorize, hold for review, or block. SIE collapses that decision
+ into <strong>one server call</strong>: <em>extract</em> signals from
+ the order context, <em>encode</em> them, and <em>score</em> against
+ a corpus of past fraud patterns. Click a sample order on the left
+ to see the pipeline run, then watch the
+ <strong>Stripe Link</strong> payment form on the right react to the
+ risk band.
+ </p>
+ </div>
+ <div class="hero-diagram">
+ <img src="/static/architecture.svg" alt="stripe-link-fraud architecture" class="diagram-svg" />
+ </div>
+ </section>
+
+ <main>
+ <section class="panel" id="panel-orders">
+ <header><h2>Sample orders</h2></header>
+ <div class="list" id="orders">loading...</div>
+ </section>
+
+ <section class="panel" id="panel-risk">
+ <header>
+ <h2>SIE risk pipeline</h2>
+ <span class="hint" id="risk-meta"></span>
+ </header>
+ <div class="risk" id="risk">
+ <p class="hint">Click a sample order on the left.</p>
+ </div>
+ </section>
+
+ <section class="panel" id="panel-checkout">
+ <header>
+ <h2>Stripe Link checkout</h2>
+ <span class="hint" id="checkout-meta"></span>
+ </header>
+ <div class="checkout" id="checkout">
+ <p class="hint">A Stripe Elements PaymentElement (with Link enabled) mounts here once a risk score is computed.</p>
+ </div>
+ </section>
+ </main>
+
+ <footer>
+ <span id="footer">SIE on <code id="sie-url">http://localhost:8080</code></span>
+ <span id="timings"></span>
+ </footer>
+
+ <script src="/static/app.js"></script>
+ </body>
+</html>
diff --git a/examples/stripe-link-fraud/web/public/style.css b/examples/stripe-link-fraud/web/public/style.css
new file mode 100644
index 000000000..3f36e3801
--- /dev/null
+++ b/examples/stripe-link-fraud/web/public/style.css
@@ -0,0 +1,337 @@
+:root {
+ --background: hsl(240 10% 3.9%);
+ --foreground: hsl(0 0% 98%);
+ --card: hsl(240 8% 6%);
+ --card-elevated: hsl(240 8% 7.5%);
+ --border: hsl(240 3.7% 15.9%);
+ --border-strong: hsl(240 4% 22%);
+ --secondary: hsl(240 3.7% 15.9%);
+ --muted-foreground: hsl(240 5% 64.9%);
+ --accent: hsl(245 60% 65%);
+ --accent-subtle: hsl(245 60% 65% / 0.12);
+ --accent-strong: hsl(245 75% 75%);
+ --info: hsl(208 80% 65%);
+ --info-subtle: hsl(208 80% 65% / 0.14);
+ --magenta: hsl(275 75% 75%);
+ --success: hsl(142 65% 60%);
+ --success-subtle: hsl(142 65% 60% / 0.15);
+ --warn: hsl(38 90% 62%);
+ --warn-subtle: hsl(38 90% 62% / 0.15);
+ --destructive: hsl(0 75% 65%);
+ --destructive-subtle: hsl(0 75% 65% / 0.15);
+ --radius: 0.625rem;
+ --radius-sm: 0.375rem;
+ --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.25);
+ --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
+ --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
+}
+
+* { box-sizing: border-box; }
+html, body {
+ margin: 0; padding: 0;
+ background: var(--background); color: var(--foreground);
+ font-family: var(--font-sans);
+ font-size: 14px; line-height: 1.5;
+ min-height: 100%;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
+body { display: flex; flex-direction: column; min-height: 100vh; }
+
+header {
+ display: flex; align-items: center; gap: 16px;
+ padding: 14px 24px;
+ border-bottom: 1px solid var(--border);
+ flex-wrap: wrap;
+}
+.title { display: flex; align-items: center; gap: 12px; }
+.logo {
+ display: inline-flex; align-items: center; justify-content: center;
+ width: 28px; height: 28px;
+ border-radius: var(--radius-sm);
+ background: var(--accent-subtle);
+ color: var(--accent-strong);
+ font-size: 15px;
+}
+h1 {
+ font-size: 15px; margin: 0; font-weight: 600;
+ font-family: var(--font-mono);
+}
+.badge {
+ display: inline-flex; align-items: center; gap: 6px;
+ padding: 3px 9px; border-radius: 999px;
+ background: var(--secondary);
+ color: var(--muted-foreground);
+ font-size: 11px; font-weight: 500;
+ border: 1px solid var(--border);
+}
+.badge::before {
+ content: ""; width: 5px; height: 5px; border-radius: 999px;
+ background: currentColor; opacity: 0.7;
+}
+.badge.running { background: var(--info-subtle); color: var(--info); border-color: transparent; }
+.badge.green { background: var(--success-subtle); color: var(--success); border-color: transparent; }
+.badge.red { background: var(--destructive-subtle); color: var(--destructive); border-color: transparent; }
+
+.meta { color: var(--muted-foreground); font-size: 12px; }
+.meta code { font-family: var(--font-mono); }
+
+.cta-row { margin-left: auto; display: flex; gap: 8px; }
+.cta {
+ display: inline-flex; align-items: center; gap: 6px;
+ padding: 5px 10px; border-radius: var(--radius-sm);
+ background: var(--secondary); color: var(--info);
+ font-size: 11px; text-decoration: none;
+ border: 1px solid transparent;
+ transition: border-color 0.1s;
+}
+.cta:hover { border-color: var(--border-strong); }
+
+.hero {
+ padding: 18px 24px;
+ background: radial-gradient(60% 80% at 20% 0%, var(--accent-subtle), transparent 70%);
+ border-bottom: 1px solid var(--border);
+ display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; align-items: center;
+}
+.hero-text p { margin: 0; color: var(--muted-foreground); line-height: 1.65; }
+.hero-text strong { color: var(--foreground); }
+.hero-text em { color: var(--accent-strong); font-style: normal; font-weight: 600; }
+
+.diagram-svg {
+ display: block; width: 100%; height: auto;
+ border-radius: var(--radius-sm);
+ border: 1px solid var(--border);
+ background: var(--card);
+}
+
+main {
+ flex: 1; display: grid;
+ grid-template-columns: 0.95fr 1.3fr 1.2fr;
+ gap: 16px; padding: 16px 24px 20px; overflow: hidden;
+ min-height: 520px;
+}
+
+.panel {
+ display: flex; flex-direction: column;
+ background: var(--card);
+ border: 1px solid var(--border);
+ border-radius: var(--radius);
+ overflow: hidden; min-height: 0;
+ box-shadow: var(--shadow-sm);
+}
+.panel header {
+ padding: 12px 16px;
+ background: var(--card-elevated);
+ border-bottom: 1px solid var(--border);
+ display: flex; justify-content: space-between; align-items: center;
+}
+.panel h2 {
+ font-size: 12px; font-weight: 600; margin: 0; color: var(--foreground);
+ text-transform: none;
+}
+#panel-orders h2::before, #panel-risk h2::before, #panel-checkout h2::before {
+ content: ""; display: inline-block; width: 6px; height: 6px;
+ border-radius: 999px; margin-right: 8px; vertical-align: middle;
+}
+#panel-orders h2::before { background: var(--accent); }
+#panel-risk h2::before { background: var(--info); }
+#panel-checkout h2::before { background: var(--magenta); }
+
+.hint { color: var(--muted-foreground); font-size: 12px; }
+
+.list, .risk, .checkout { flex: 1; overflow: auto; padding: 12px; margin: 0; }
+
+.order {
+ padding: 12px;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-sm);
+ margin-bottom: 8px; cursor: pointer;
+ transition: border-color 0.15s ease, background-color 0.15s ease;
+ background: var(--card);
+}
+.order:hover { border-color: var(--border-strong); background: var(--card-elevated); }
+.order.active { border-color: var(--accent); background: var(--accent-subtle); }
+.order-head {
+ display: flex; justify-content: space-between; align-items: baseline;
+}
+.order-label { font-weight: 600; }
+.order-total { font-family: var(--font-mono); color: var(--success); }
+.order-desc { color: var(--muted-foreground); font-size: 12px; margin-top: 4px; line-height: 1.5; }
+.order-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
+
+.pill {
+ padding: 2px 8px; border-radius: 999px;
+ font-size: 11px; font-weight: 500;
+ background: var(--secondary);
+ color: var(--muted-foreground);
+ border: 1px solid var(--border);
+}
+
+.risk-stages {
+ display: flex; gap: 8px; margin-bottom: 12px;
+}
+.stage {
+ display: inline-flex; align-items: center; gap: 6px;
+ padding: 4px 10px; border-radius: 999px;
+ background: var(--secondary); border: 1px solid var(--border);
+ color: var(--muted-foreground); font-size: 11px;
+}
+.stage-dot {
+ width: 6px; height: 6px; border-radius: 999px;
+ background: var(--muted-foreground);
+}
+.stage[data-state="running"] { color: var(--info); border-color: var(--info); background: var(--info-subtle); }
+.stage[data-state="running"] .stage-dot { background: var(--info); animation: pulse 1s ease-in-out infinite; }
+.stage[data-state="done"] { color: var(--success); border-color: transparent; background: var(--success-subtle); }
+.stage[data-state="done"] .stage-dot { background: var(--success); }
+@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }
+
+.risk-section {
+ margin-bottom: 14px;
+ padding-bottom: 12px;
+ border-bottom: 1px solid var(--border);
+}
+.risk-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
+.risk-section-head {
+ font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
+ color: var(--muted-foreground); margin-bottom: 8px; font-weight: 500;
+}
+.entities { display: flex; flex-wrap: wrap; gap: 6px; }
+.entity-group {
+ display: inline-flex; align-items: center; gap: 6px;
+ padding: 4px 9px; border-radius: var(--radius-sm);
+ background: var(--secondary); border: 1px solid var(--border);
+ font-size: 11.5px; font-family: var(--font-mono);
+}
+.entity-group .ekey {
+ text-transform: uppercase; color: var(--muted-foreground);
+ font-size: 10px; font-weight: 600;
+}
+.entity-group .eval { color: var(--info); }
+.entity-group .econf {
+ color: var(--muted-foreground); font-size: 10px;
+ padding: 0 4px; border-left: 1px solid var(--border); margin-left: 2px;
+}
+
+.risk-band {
+ display: grid; grid-template-columns: auto auto auto; gap: 8px 16px;
+ align-items: baseline;
+ padding: 12px 14px; border-radius: var(--radius-sm);
+ margin-bottom: 12px;
+ border: 1px solid var(--border);
+}
+.risk-band .band-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-foreground); }
+.risk-band .band-value { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; font-family: var(--font-mono); }
+.risk-band .band-score { font-size: 11px; color: var(--muted-foreground); }
+.risk-band.band-low { background: var(--success-subtle); border-color: transparent; }
+.risk-band.band-low .band-value { color: var(--success); }
+.risk-band.band-medium { background: var(--warn-subtle); border-color: transparent; }
+.risk-band.band-medium .band-value { color: var(--warn); }
+.risk-band.band-high { background: var(--destructive-subtle); border-color: transparent; }
+.risk-band.band-high .band-value { color: var(--destructive); }
+
+.band-why {
+ margin: 0 0 12px 0;
+ font-size: 12px; line-height: 1.55;
+ color: var(--muted-foreground);
+}
+.score-legend {
+ margin-bottom: 10px;
+ padding: 8px 10px;
+ border-radius: var(--radius-sm);
+ background: var(--card-elevated);
+ border: 1px solid var(--border);
+ font-size: 11.5px; line-height: 1.5;
+ color: var(--muted-foreground);
+}
+.score-legend strong { color: var(--foreground); font-weight: 600; }
+
+.hits { display: flex; flex-direction: column; gap: 8px; }
+.hit {
+ padding: 10px 12px;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-sm);
+ background: var(--card);
+}
+.hit-head { display: flex; justify-content: space-between; align-items: baseline; }
+.hit-label { font-weight: 600; font-size: 12.5px; }
+.hit-score { color: var(--info); font-size: 11.5px; font-family: var(--font-mono); }
+.hit-summary { margin-top: 4px; color: var(--muted-foreground); font-size: 12px; line-height: 1.55; }
+.hit-meta { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
+
+.outcome-chargeback, .outcome-review_then_chargeback, .outcome-account_takeover {
+ background: var(--destructive-subtle); color: var(--destructive); border-color: transparent;
+}
+.outcome-blocked, .outcome-refunded, .outcome-promo_reversed {
+ background: var(--success-subtle); color: var(--success); border-color: transparent;
+}
+
+.mock-checkout, .checkout > .cart-summary,
+.checkout #payment-element, .checkout .pay-btn, .checkout .pay-msg {
+ margin-bottom: 12px;
+}
+.mock-banner {
+ padding: 10px 12px; border-radius: var(--radius-sm);
+ background: var(--info-subtle); border: 1px solid hsl(208 80% 65% / 0.3);
+ color: var(--foreground); font-size: 12px; line-height: 1.5;
+}
+.mock-banner code { background: var(--secondary); padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); }
+.mock-cart, .cart-summary {
+ padding: 12px; border-radius: var(--radius-sm);
+ background: var(--card-elevated); border: 1px solid var(--border);
+ font-size: 13px;
+}
+.mock-cart-head, .cart-head {
+ display: flex; justify-content: space-between; font-weight: 600;
+ padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid var(--border);
+}
+.mock-cart-row, .cart-row {
+ display: flex; justify-content: space-between; padding: 4px 0;
+ color: var(--muted-foreground);
+}
+.mock-cart-row span:last-child, .cart-row span:last-child { color: var(--foreground); font-family: var(--font-mono); }
+
+.mock-link-button, .pay-btn {
+ display: block; width: 100%;
+ padding: 12px; text-align: center;
+ border-radius: var(--radius-sm); border: 0;
+ font-family: var(--font-sans); font-weight: 600; font-size: 14px;
+ cursor: pointer;
+ background: hsl(160 95% 47%);
+ color: hsl(160 100% 12%);
+ transition: filter 0.15s ease;
+}
+.mock-link-button:hover, .pay-btn:hover { filter: brightness(1.05); }
+.pay-btn:disabled { opacity: 0.6; cursor: not-allowed; }
+.mock-link-button[data-band="high"], .pay-btn.band-high {
+ background: var(--destructive-subtle); color: var(--destructive);
+}
+.mock-link-button[data-band="medium"], .pay-btn.band-medium {
+ background: var(--warn-subtle); color: var(--warn);
+}
+.pay-msg { font-size: 12px; color: var(--muted-foreground); }
+.pay-msg.error { color: var(--destructive); }
+
+.error {
+ padding: 10px 12px; border-radius: var(--radius-sm);
+ background: var(--destructive-subtle); border: 1px solid hsl(0 75% 65% / 0.3);
+ color: var(--destructive); font-size: 12px; line-height: 1.5;
+}
+
+footer {
+ padding: 12px 24px;
+ border-top: 1px solid var(--border);
+ color: var(--muted-foreground); font-size: 12px;
+ display: flex; justify-content: space-between; gap: 12px;
+}
+footer code { font-family: var(--font-mono); }
+code {
+ background: var(--secondary); padding: 1px 7px; border-radius: var(--radius-sm);
+ font-family: var(--font-mono); font-size: 0.92em;
+}
+
+@media (max-width: 1000px) {
+ .hero { grid-template-columns: 1fr; }
+ main { grid-template-columns: 1fr; }
+ .cta-row { margin-left: 0; }
+}
diff --git a/examples/stripe-link-fraud/web/server.ts b/examples/stripe-link-fraud/web/server.ts
new file mode 100644
index 000000000..a45cb2021
--- /dev/null
+++ b/examples/stripe-link-fraud/web/server.ts
@@ -0,0 +1,261 @@
+import fs from "node:fs";
+import http from "node:http";
+import path from "node:path";
+import { spawnSync } from "node:child_process";
+import { fileURLToPath } from "node:url";
+import { SIEClient } from "@superlinked/sie-sdk";
+import Stripe from "stripe";
+import { config } from "../src/config.js";
+import type { RiskEvent } from "../src/events.js";
+import { loadSampleOrders, runRisk } from "../src/risk.js";
+import type { CartItem, Customer } from "../src/types.js";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const ROOT = path.resolve(__dirname, "..");
+const PUBLIC_DIR = path.join(ROOT, "web", "public");
+const INDEX_PATH = path.join(ROOT, config.paths.index);
+
+const STRIPE_ENABLED =
+ config.stripe.publishableKey.startsWith("pk_") && config.stripe.secretKey.startsWith("sk_");
+
+const stripe: Stripe | null = STRIPE_ENABLED
+ ? new Stripe(config.stripe.secretKey, { apiVersion: config.stripe.apiVersion })
+ : null;
+
+function send(
+ res: http.ServerResponse,
+ status: number,
+ body: string | Buffer,
+ contentType = "text/plain",
+): void {
+ res.writeHead(status, { "content-type": contentType });
+ res.end(body);
+ return;
+}
+
+function serveFile(res: http.ServerResponse, file: string): void {
+ if (!fs.existsSync(file)) return send(res, 404, "not found");
+ const ext = path.extname(file).toLowerCase();
+ const ct =
+ {
+ ".html": "text/html",
+ ".css": "text/css",
+ ".js": "text/javascript",
+ ".json": "application/json",
+ ".png": "image/png",
+ ".svg": "image/svg+xml",
+ }[ext] ?? "application/octet-stream";
+ res.writeHead(200, { "content-type": ct });
+ fs.createReadStream(file).pipe(res);
+}
+
+function setupSse(res: http.ServerResponse) {
+ res.writeHead(200, {
+ "content-type": "text/event-stream",
+ "cache-control": "no-cache",
+ connection: "keep-alive",
+ });
+ return (event: RiskEvent) => {
+ res.write(`event: ${event.type}\n`);
+ const payload = "data" in event ? event.data : null;
+ res.write(`data: ${JSON.stringify(payload)}\n\n`);
+ };
+}
+
+async function ensureIndex(): Promise<void> {
+ if (fs.existsSync(INDEX_PATH)) return;
+ console.log("building fraud-pattern index...");
+ const result = spawnSync(
+ process.execPath,
+ [
+ path.join(ROOT, "node_modules/.bin/tsx"),
+ path.join(ROOT, "src/index-build.ts"),
+ ],
+ { cwd: ROOT, encoding: "utf8", stdio: "inherit" },
+ );
+ if (result.status !== 0) throw new Error("index-build failed");
+}
+
+async function checkSie(): Promise<boolean> {
+ try {
+ const r = await fetch(`${config.sieUrl}/healthz`, {
+ signal: AbortSignal.timeout(2000),
+ });
+ return r.ok;
+ } catch {
+ return false;
+ }
+}
+
+async function fetchRegistered(): Promise<{ ok: boolean; names: string[] }> {
+ try {
+ const r = await fetch(`${config.sieUrl}/v1/models`, { signal: AbortSignal.timeout(3000) });
+ if (!r.ok) return { ok: false, names: [] };
+ const json = (await r.json()) as { models?: { name: string }[] };
+ return { ok: true, names: (json.models ?? []).map((m) => m.name) };
+ } catch {
+ return { ok: false, names: [] };
+ }
+}
+
+async function readBody(req: http.IncomingMessage): Promise<string> {
+ const chunks: Buffer[] = [];
+ for await (const chunk of req) chunks.push(chunk as Buffer);
+ return Buffer.concat(chunks).toString("utf8");
+}
+
+async function handleRun(
+ _req: http.IncomingMessage,
+ res: http.ServerResponse,
+ orderId: string,
+): Promise<void> {
+ const push = setupSse(res);
+ const samples = loadSampleOrders();
+ const order = samples.find((s) => s.id === orderId);
+ if (!order) {
+ push({ type: "error", data: { stage: "lookup", message: `unknown order id: ${orderId}` } });
+ res.end();
+ return;
+ }
+
+ const sieOk = await checkSie();
+ if (!sieOk) {
+ push({
+ type: "error",
+ data: { stage: "sie", message: `SIE not reachable at ${config.sieUrl}` },
+ });
+ res.end();
+ return;
+ }
+
+ try {
+ await ensureIndex();
+ } catch (e) {
+ push({
+ type: "error",
+ data: { stage: "index", message: e instanceof Error ? e.message : String(e) },
+ });
+ res.end();
+ return;
+ }
+
+ const client = new SIEClient(config.sieUrl, {
+ apiKey: config.sieApiKey,
+ timeout: 600_000,
+ waitForCapacity: true,
+ provisionTimeout: 900_000,
+ });
+
+ try {
+ await runRisk(
+ { cart: order.cart, customer: order.customer, context: order.description },
+ { client, emit: push },
+ );
+ } catch (e) {
+ push({
+ type: "error",
+ data: { stage: "pipeline", message: e instanceof Error ? e.message : String(e) },
+ });
+ } finally {
+ res.end();
+ }
+}
+
+async function handlePaymentIntent(
+ req: http.IncomingMessage,
+ res: http.ServerResponse,
+): Promise<void> {
+ if (!stripe) {
+ return send(
+ res,
+ 200,
+ JSON.stringify({ mode: "mock", reason: "STRIPE_*_KEY not set" }),
+ "application/json",
+ );
+ }
+ type Body = { cart: CartItem[]; customer: Customer; riskBand?: string };
+ let body: Body;
+ try {
+ body = JSON.parse(await readBody(req));
+ } catch {
+ return send(res, 400, "invalid json");
+ }
+ const amount = body.cart.reduce((s, i) => s + i.qty * i.unit_price_usd, 0) * 100;
+ const intent = await stripe.paymentIntents.create({
+ amount: Math.round(amount),
+ currency: "usd",
+ automatic_payment_methods: { enabled: true },
+ metadata: {
+ sie_risk_band: body.riskBand ?? "unknown",
+ customer_email: body.customer.email,
+ },
+ receipt_email: body.customer.email,
+ });
+ return send(
+ res,
+ 200,
+ JSON.stringify({
+ mode: "live",
+ clientSecret: intent.client_secret,
+ publishableKey: config.stripe.publishableKey,
+ }),
+ "application/json",
+ );
+}
+
+const server = http.createServer(async (req, res) => {
+ const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
+ const p = url.pathname;
+
+ if (p === "/" || p === "/index.html") return serveFile(res, path.join(PUBLIC_DIR, "index.html"));
+ if (p.startsWith("/static/")) return serveFile(res, path.join(PUBLIC_DIR, p.slice("/static/".length)));
+
+ if (p === "/api/health") {
+ const { ok, names } = await fetchRegistered();
+ return send(
+ res,
+ 200,
+ JSON.stringify({
+ sie: ok,
+ sieUrl: config.sieUrl,
+ registeredModels: names.length,
+ registered: names,
+ stripe: STRIPE_ENABLED ? "live" : "mock",
+ publishableKey: STRIPE_ENABLED ? config.stripe.publishableKey : null,
+ }),
+ "application/json",
+ );
+ }
+
+ if (p === "/api/samples") {
+ return send(res, 200, JSON.stringify(loadSampleOrders()), "application/json");
+ }
+
+ if (p === "/api/run") {
+ const id = url.searchParams.get("id");
+ if (!id) return send(res, 400, "missing id");
+ return handleRun(req, res, id);
+ }
+
+ if (p === "/api/payment-intent" && req.method === "POST") {
+ return handlePaymentIntent(req, res);
+ }
+
+ return send(res, 404, "not found");
+});
+
+server.listen(config.port, () => {
+ const url = `http://localhost:${config.port}`;
+ console.log(`stripe-link-fraud ui: ${url}`);
+ console.log(`stripe mode: ${STRIPE_ENABLED ? "live (test keys detected)" : "mock (no keys set)"}`);
+ if (process.env.OPEN_BROWSER !== "0") {
+ const opener =
+ process.platform === "darwin"
+ ? "open"
+ : process.platform === "win32"
+ ? "start"
+ : "xdg-open";
+ spawnSync(opener, [url], { stdio: "ignore" });
+ }
+});