@alytegen/sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BROWSER.md +43 -9
- package/QUICKSTART.md +5 -1
- package/README.md +32 -0
- package/dist/browser.d.ts +1 -1
- package/dist/merchant.d.ts +7 -1
- package/dist/merchant.js +2 -1
- package/dist/types.d.ts +2 -1
- package/examples/merchant-onboard.ts +1 -1
- package/package.json +1 -1
package/BROWSER.md
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
# Buyer purchases inside your chat
|
|
2
2
|
|
|
3
|
-
Available
|
|
4
|
-
stays on your backend. Your chat receives a short-lived bounded
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Available since SDK 0.4.0 with Alyte's Model 1 browser endpoints (0.5.0 types the attested
|
|
4
|
+
mint). The merchant token stays on your backend. Your chat receives a short-lived bounded
|
|
5
|
+
buyer bearer. How a permission gets created depends on the session you minted:
|
|
6
|
+
**merchant-attested** (enabled merchants, within staff-set ceilings) — Alyte's iframe creates
|
|
7
|
+
it on your attestation, no code; **ordinary** — the iframe asks the buyer to confirm a code
|
|
8
|
+
Alyte emails them. Either way the verification happens inside Alyte's iframe, and the full
|
|
9
|
+
verification bearer stays there. No raw agent credential reaches your chat.
|
|
10
|
+
Your pages and your backend must never call the step-up endpoints or handle the
|
|
11
|
+
buyer's verification code; the iframe does that. A code entered anywhere in your own
|
|
12
|
+
UI is a defect in the integration. The step-up endpoints refuse browser calls from
|
|
13
|
+
partner origins; that refusal is a browser boundary, not a substitute for this rule.
|
|
14
|
+
|
|
15
|
+
Prerequisite: this flow is offered to merchants onboarded under an Alyte contract,
|
|
16
|
+
which carries the rule above. Alyte is invite-onboarded and production keys need
|
|
17
|
+
Alyte's go-live approval; the contract is checked at those steps, not by the
|
|
18
|
+
minting or exchange endpoints themselves.
|
|
19
|
+
|
|
20
|
+
## Availability and contracted attestation
|
|
21
|
+
|
|
22
|
+
The separately enabled merchant-attested path can grant within staff-set
|
|
23
|
+
ceilings without the emailed code. Mint that session on your backend with an
|
|
24
|
+
attest-only key and `merchantAttested: true`, then exchange it and call
|
|
25
|
+
`openConsent` as below. Published SDK 0.4.0 lacks the TypeScript mint field;
|
|
26
|
+
use the [REST example](https://alyte.mintlify.site/guides/console-api-keys).
|
|
27
|
+
The API key never belongs in the browser. Removing staff enablement or revoking
|
|
28
|
+
the key removes the session's attestation exception.
|
|
29
|
+
|
|
30
|
+
The proposed emailed-link confirmation flow is not enabled yet. The current
|
|
31
|
+
verification-code flow remains in use. `openConsent`'s signature and result
|
|
32
|
+
are planned to stay compatible when the new Alyte surfaces ship; 0.4.0 has no
|
|
33
|
+
pending-consent client methods.
|
|
34
|
+
[Follow availability](https://alyte.mintlify.site/guides/consent-confirmation).
|
|
7
35
|
|
|
8
36
|
## Register and attest
|
|
9
37
|
|
|
@@ -11,8 +39,10 @@ Register your exact HTTPS chat origin in the shop's `embedOrigin` (multiple orig
|
|
|
11
39
|
are comma-separated). This controls both framing and buyer CORS. New registrations
|
|
12
40
|
can take up to 30 seconds to reach preflight caches. Local HTTP development is supported.
|
|
13
41
|
On your backend, authenticate your own user, derive their email from that session,
|
|
14
|
-
then call `merchant.buyerSessions.mint({ merchantId, email })
|
|
15
|
-
|
|
42
|
+
then call `merchant.buyerSessions.mint({ merchantId, email })` — or, on a `mandates:attest`
|
|
43
|
+
key for an enabled merchant, `mint({ merchantId, email, merchantAttested: true })` so the
|
|
44
|
+
buyer can create a permission within your ceilings without the emailed code. Return only the
|
|
45
|
+
`token` query value extracted from `new URL(session.redeemPath, ALYTE_URL)` to that user's
|
|
16
46
|
browser. Do not navigate the redeem link too: either consumer uses the token once.
|
|
17
47
|
The mint endpoint must not accept an arbitrary browser-supplied email as identity.
|
|
18
48
|
|
|
@@ -28,7 +58,7 @@ const { agentId, mandateId } = await openConsent({
|
|
|
28
58
|
baseUrl: ALYTE_URL, merchantId, bearer: connection.bearer,
|
|
29
59
|
container: document.querySelector<HTMLElement>('#alyte-consent')!,
|
|
30
60
|
signal: controller.signal, lang: 'en',
|
|
31
|
-
theme: { accent: '#006466',
|
|
61
|
+
theme: { accent: '#006466', radius: 8, scheme: 'light' },
|
|
32
62
|
});
|
|
33
63
|
```
|
|
34
64
|
|
|
@@ -39,7 +69,8 @@ Cookie login endpoints are not available to the parent chat.
|
|
|
39
69
|
|
|
40
70
|
The iframe lets the buyer choose an existing usable Alyte agent/permission or
|
|
41
71
|
create one. Selecting an existing permission needs no new email verification.
|
|
42
|
-
Creating authority does
|
|
72
|
+
Creating authority does, except for an enabled merchant-attested session within
|
|
73
|
+
its ceilings. Completion returns IDs only and removes the iframe.
|
|
43
74
|
Cancellation/abort rejects with `AlyteConsentError.code = 'consent_cancelled'`;
|
|
44
75
|
an initial handshake timeout uses `consent_unavailable`. Server errors retain their
|
|
45
76
|
code. `readyTimeoutMs` defaults to 15 seconds and never limits code-entry time.
|
|
@@ -48,6 +79,9 @@ Optional `returnUrl` must belong to the chat origin. `onNavigate(url)` decides h
|
|
|
48
79
|
your chat handles the Back link. The SDK does not navigate the host automatically.
|
|
49
80
|
Themes accept only `accent`, `background`, `surface`, `text`, `font`, `radius`, `scheme`.
|
|
50
81
|
Colours are opaque hex; font is system/sans/serif, radius is 0–16, scheme light/dark.
|
|
82
|
+
Omit `font` to keep Alyte's self-hosted Hanken Grotesk. Explicit `system`, `sans` and
|
|
83
|
+
`serif` select system UI, Arial and Georgia respectively. Secondary text and dividers
|
|
84
|
+
are derived automatically from the palette while preserving readable contrast.
|
|
51
85
|
If contrast fails, all four colours fall back to scheme defaults; they are not
|
|
52
86
|
adjusted. Permission terms, errors and disabled controls keep fixed readable colours.
|
|
53
87
|
Provider card inputs keep their provider styling.
|
|
@@ -77,7 +111,7 @@ Other methods: `me()`, `catalog()`, `agents()`, `instruments()`, `instrumentCaps
|
|
|
77
111
|
`watches()`, `watch({ agentId, tierId, quantity, expiresInDays? })`,
|
|
78
112
|
`cancelWatch(id)`, `revokeMandate(id)`. Revocation is immediate and server-enforced.
|
|
79
113
|
Every buy/watch still depends on the buyer's current mandate, card evidence and
|
|
80
|
-
live availability.
|
|
114
|
+
live availability. An ordinary bounded bearer cannot create or widen spending authority.
|
|
81
115
|
|
|
82
116
|
Your backend still fulfills from verified settlement webhooks, idempotently.
|
|
83
117
|
Browser completion messages are presentation state, not fulfillment evidence.
|
package/QUICKSTART.md
CHANGED
|
@@ -4,7 +4,7 @@ Choose the credential for the runtime:
|
|
|
4
4
|
|
|
5
5
|
| Client | Credential | Runs | Does |
|
|
6
6
|
|---|---|---|---|
|
|
7
|
-
| `AlyteMerchant` | API token (console → API keys, `merchant:read`/`merchant:write`) | **your server only** | catalog CRUD, PSP links, payments visibility, buyer-session mint |
|
|
7
|
+
| `AlyteMerchant` | API token (console → API keys, `merchant:read`/`merchant:write`; `merchant:admin` for creating or deleting shops and linking a PSP) | **your server only** | catalog CRUD, PSP links, payments visibility, buyer-session mint |
|
|
8
8
|
| `AlyteAgent` | agent JWT | your agent runtime | discover → quote → hold → confirm |
|
|
9
9
|
| `@alytegen/sdk/browser` | bounded buyer bearer | your chat page | embedded consent and purchases using the buyer's Alyte agent |
|
|
10
10
|
|
|
@@ -45,6 +45,10 @@ const s = await alyte.buyerSessions.mint({
|
|
|
45
45
|
res.redirect(ALYTE_URL + s.redeemPath); // single-use, 15-min TTL
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
Merchants that Alyte staff have enabled under contract can mint with `merchantAttested: true`
|
|
49
|
+
on a key holding only `mandates:attest`: the buyer then creates a permission within your
|
|
50
|
+
shop's ceilings without the emailed code (see the README's hand-off section).
|
|
51
|
+
|
|
48
52
|
Embedding in a chat? Follow [BROWSER.md](./BROWSER.md) to exchange the single-use
|
|
49
53
|
token and launch consent without third-party cookies. Directly framing the full
|
|
50
54
|
authorize page is also supported, but its cookie session depends on browser policy.
|
package/README.md
CHANGED
|
@@ -54,6 +54,25 @@ const s = await alyte.buyerSessions.mint({ merchantId: merchant.id, email: user.
|
|
|
54
54
|
res.redirect(ALYTE_URL + s.redeemPath); // single-use, 15-minute link
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
Two kinds of session, decided by how you mint:
|
|
58
|
+
|
|
59
|
+
- **Ordinary** (above): the buyer can act inside permission they already granted. Creating or
|
|
60
|
+
widening permission asks them to confirm a 6-digit code Alyte emails them, typed into Alyte's
|
|
61
|
+
own screen — never into yours.
|
|
62
|
+
- **Merchant-attested** — for merchants Alyte staff have enabled under contract — lets the buyer
|
|
63
|
+
create a permission **without the code**, within the ceilings staff set for your shop, because
|
|
64
|
+
you vouch for your signed-in, email-verified customer. It needs a key holding only
|
|
65
|
+
`mandates:attest` (the console offers **attest verified customers only** once enabled):
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const attesting = new AlyteMerchant({ baseUrl: ALYTE_URL, token: process.env.ALYTE_ATTEST_KEY! });
|
|
69
|
+
const s = await attesting.buyerSessions.mint({ merchantId: merchant.id, email: user.email, merchantAttested: true });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The buyer sees "Set up by {your shop}" on that agent and can revoke it. A grant outside the
|
|
73
|
+
ceilings answers `403 merchant_consent_ceiling_exceeded` and Alyte's screen falls back to the
|
|
74
|
+
buyer's own code; without the enablement, the mint answers `403 merchant_consent_not_enabled`.
|
|
75
|
+
|
|
57
76
|
## Receive purchases
|
|
58
77
|
|
|
59
78
|
```ts
|
|
@@ -82,6 +101,19 @@ const out = await agent.confirm(hold.id,
|
|
|
82
101
|
No amount is passed at confirm — the charge is the locked quote. A spend-cap refusal means
|
|
83
102
|
the buyer's mandate said no: surface it, don't retry.
|
|
84
103
|
|
|
104
|
+
## Current API and console capabilities
|
|
105
|
+
|
|
106
|
+
SDK **0.5.0** types the merchant-attested mint (`merchantAttested: true`), alongside the browser
|
|
107
|
+
entry point and the typed tier-create restrictions (`onSaleStart`, `onSaleEnd`, `maxQtyPerPurchase`,
|
|
108
|
+
`sellable`, `allowedGeos`, `allowedSchemes` — put them in the initial `createTier` call so a
|
|
109
|
+
scheduled tier is never briefly on sale).
|
|
110
|
+
|
|
111
|
+
The console offers **attest verified customers only** while Alyte staff have enabled contracted
|
|
112
|
+
consent for your organization; that key holds only `mandates:attest`, and a read/write key does
|
|
113
|
+
not include it. Permission creation for everyone else goes through Alyte's consent screen with the
|
|
114
|
+
emailed code — there is no API for your code to create or widen a buyer's spending authority, by
|
|
115
|
+
design. Alyte's server runs Node 22; this SDK supports Node 18 and later.
|
|
116
|
+
|
|
85
117
|
## Learn more
|
|
86
118
|
|
|
87
119
|
- [QUICKSTART.md](./QUICKSTART.md) — the walkthrough with every call explained.
|
package/dist/browser.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface BuyerWatch {
|
|
|
54
54
|
merchantId: string;
|
|
55
55
|
tierId: string;
|
|
56
56
|
quantity: number;
|
|
57
|
-
status: 'queued' | 'firing' | 'fired' | 'failed' | 'cancelled' | 'expired';
|
|
57
|
+
status: 'queued' | 'paused' | 'firing' | 'fired' | 'failed' | 'cancelled' | 'expired';
|
|
58
58
|
result?: Record<string, unknown>;
|
|
59
59
|
expiresAt?: string;
|
|
60
60
|
createdAt: string;
|
package/dist/merchant.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { type ClientOptions } from './http.js';
|
|
|
2
2
|
import type { BuyerSessionMint, CatalogMerchant, Merchant, EventItem, MerchantPspLink, Tier, TierKind, FeeBearer, Scheme, PaymentRow, WebhookEndpoint, MerchantInsights } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Merchant integration client — drives the `/v1/integration/*` surface with a
|
|
5
|
-
* console-minted API token (`merchant:read` / `merchant:write` scopes
|
|
5
|
+
* console-minted API token (`merchant:read` / `merchant:write` scopes; `merchant:admin` for
|
|
6
|
+
* creating or deleting shops and linking a PSP — the "full" console preset).
|
|
6
7
|
*
|
|
7
8
|
* SERVER-SIDE ONLY: the API token is a secret. Never ship it to a browser.
|
|
8
9
|
*
|
|
@@ -166,6 +167,11 @@ export declare class AlyteMerchant {
|
|
|
166
167
|
/** The buyer's language on YOUR site (BCP-47, e.g. "de" or "de-AT"), so Alyte's
|
|
167
168
|
* pages open in the same language. Presentation only. */
|
|
168
169
|
lang?: string;
|
|
170
|
+
/** Attest this customer's consent yourself: the session may then create a permission
|
|
171
|
+
* without Alyte's emailed code, within your account's limits. Requires a key with the
|
|
172
|
+
* `mandates:attest` scope and merchant-attested consent enabled for your account by Alyte
|
|
173
|
+
* (a contract is in place). The permission records that YOU attested it. */
|
|
174
|
+
merchantAttested?: true;
|
|
169
175
|
}) => Promise<BuyerSessionMint>;
|
|
170
176
|
};
|
|
171
177
|
}
|
package/dist/merchant.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Transport } from './http.js';
|
|
2
2
|
/**
|
|
3
3
|
* Merchant integration client — drives the `/v1/integration/*` surface with a
|
|
4
|
-
* console-minted API token (`merchant:read` / `merchant:write` scopes
|
|
4
|
+
* console-minted API token (`merchant:read` / `merchant:write` scopes; `merchant:admin` for
|
|
5
|
+
* creating or deleting shops and linking a PSP — the "full" console preset).
|
|
5
6
|
*
|
|
6
7
|
* SERVER-SIDE ONLY: the API token is a secret. Never ship it to a browser.
|
|
7
8
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface Merchant {
|
|
|
19
19
|
/** Public discovery opt-in (default false) — see AlyteMerchant.updateShopDiscovery. */
|
|
20
20
|
discoverable?: boolean;
|
|
21
21
|
imageUrl?: string;
|
|
22
|
-
/**
|
|
22
|
+
/** Up to three partner origins (space- or comma-separated) allowed to embed the authorize page and call the buyer API from a browser (G14, L2). */
|
|
23
23
|
embedOrigin?: string;
|
|
24
24
|
}
|
|
25
25
|
export interface EventItem {
|
|
@@ -180,6 +180,7 @@ export interface MerchantInsights {
|
|
|
180
180
|
tierTitle: string;
|
|
181
181
|
eventTitle: string;
|
|
182
182
|
queued: number;
|
|
183
|
+
paused: number;
|
|
183
184
|
fired: number;
|
|
184
185
|
failed: number;
|
|
185
186
|
cancelled: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Merchant onboarding, end to end: shop → PSP → event → tier → your user shopping.
|
|
3
3
|
*
|
|
4
4
|
* ALYTE_BASE_URL=https://alyte-sandbox-….run.app \
|
|
5
|
-
* ALYTE_API_TOKEN=<console-minted, merchant:read+merchant:write> \
|
|
5
|
+
* ALYTE_API_TOKEN=<console-minted, the "full" preset: merchant:read+merchant:write+merchant:admin> \
|
|
6
6
|
* npx tsx merchant-onboard.ts
|
|
7
7
|
*/
|
|
8
8
|
import { AlyteMerchant } from '@alytegen/sdk';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alytegen/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Alyte client SDK \u2014 merchant integration (catalog, PSP links, buyer sessions, payments visibility) and the agent buy path (discover \u2192 quote \u2192 hold \u2192 confirm).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|