View as Markdown

Embeds · Guide

Show a run's proposals

When your agent meets an agent run by another company, that agent may propose something other than what was asked: a later flight, a cheaper plan. <provenance-counter-offers> shows each proposal of one run and how it was answered, on your own pages. It is read only: the person answers on their own approval page or app, as described in counter-offers.

The API calls a proposal a counter_offer. On screen it reads Proposal.

Before you begin: a publishable key (see embeds) and a secret key with the mandate scope. The embed needs Pro or the Free trial. The run result shows the same section, so a page that already embeds a run needs nothing more.

export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x

1. Mint a session on your server

Your server mints a short session for one run with POST /v1/embed/tokens, widget: "counter_offers" and the run's ID. Put it behind a route your page calls, after your own sign-in check:

curl -s -X POST $PROVENANCE_API/v1/embed/tokens \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "widget": "counter_offers", "object_id": "run_01M7KR2Y8QW5TZ0D9H3XNB4C6E", "ttl": 900 }'
FieldWhat it does
object_idOne run (run_…) of your account. Another kind of ID is 400 embed_object_kind_mismatch; another account's is 404.
ttlSeconds, up to 900 (15 minutes).

A key without the mandate scope gets 403 insufficient_scope. A copied session opens only this run's proposals, and only until it expires.

2. Drop the element in your page

npm install @provenance/embed
<script type="module" src="https://unpkg.com/@provenance/embed"></script>

<provenance-counter-offers base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se" theme="inherit"></provenance-counter-offers>

<script>
  const el = document.querySelector("provenance-counter-offers");
  el.getToken = async () => (await (await fetch("/account/provenance/session?run=run_01M7KR2Y8QW5TZ0D9H3XNB4C6E")).json()).token;
</script>

The element calls getToken() on load and one minute before each session ends, and swaps the new session in place. It takes your theme like every other element. A run with no proposals draws nothing, so you can place the element on every run's page.

In React:

import { ProvenanceCounterOffers } from "@provenance/embed/react";

<ProvenanceCounterOffers
  baseUrl={process.env.NEXT_PUBLIC_PROVENANCE_API!}
  publishableKey="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  getToken={async () => (await (await fetch(`/account/provenance/session?run=${runId}`)).json()).token}
/>;

What it shows

Each proposal is one card, with one line per row:

RowExampleFrom
HeadKestrel Broadband support · Accepted · 2:10 pmThe outside agent's display name, one status word and when the proposal arrived
OfferFibre 100 for 12 monthsThe names of the option's lines
PriceThe amount, in the offer's currencyThe option's total
DateThu 3 Dec, 2:10 pmThe start of the option's dates, when it has any
ProofSigned, or Reported by the agentSigned when the outside agent signed every option
AskedCancel home internetWhat your agent asked for, when it shared the request (share: true on the brief)
Also offeredHome internet at 50% off for 12 months, with its priceEvery other option, one line each
AnswerAccepted · Passkey · 2:12 pmThe result, how a person answered, and when

The status is one word: Challenged while the proposal waits on the person, Accepted once it is accepted, and Proposal otherwise. The answer leads with one word too: Accepted, Declined, No answer or Waiting. An answer the grant's own limits allowed reads Accepted · Within the grant. A proposal the agent took back reads Withdrawn.

What stays out

The element reads the shared view of each proposal's exchange record, the part both companies can read. Your side's private part stays on your server:

  • The person's limit, the differences from what was asked and the reason a rule asked.
  • The person's note to their agent and any change they asked for.
  • Who the person is. An answer carries its method (Passkey, App, Link or Console) and its time.
  • Every ID, offer hash and signed token, and the outside agent's web address and key.
  • Any location or device.

To see exactly what the element gets, call GET /v1/embed/counter_offers with the session.

While a proposal is open or waiting, the element reads it again every 15 seconds. Proposals that can't be read show as unavailable; nothing is shown in their place.

Events

EventWhenDetail
pv:readyThe session openedwidget, object_id, mode
pv:resultFirst read, and whenever a proposal changeskind: "counter_offers", count, status (the newest proposal's)
pv:token_refresh_failedgetToken() couldn't renew the sessionwidget
pv:errorThe element couldn't startcode, message

Errors you might see

SymptomCauseFix
400 embed_object_kind_mismatchThe ID isn't a runPass the run_… ID.
403 insufficient_scopeThe key has no mandate scopeMint with a Mandate key.
401 embed_token_invalidThe session expired or is for another widgetMint a new one, or give the element getToken().
503 embed_result_unavailableThe proposals couldn't be readRetry shortly.

See also