@alytegen/sdk 0.6.0 → 0.7.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/QUICKSTART.md +8 -0
- package/README.md +67 -2
- package/dist/access.d.ts +106 -0
- package/dist/access.js +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/merchant.d.ts +3 -0
- package/dist/merchant.js +5 -0
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/QUICKSTART.md
CHANGED
|
@@ -31,6 +31,14 @@ const { tier } = await alyte.createTier({ eventId: event.id, title: 'GA', priceM
|
|
|
31
31
|
|
|
32
32
|
Money is **integer minor units** everywhere (`4900` = €49.00). Floats are refused.
|
|
33
33
|
|
|
34
|
+
SDK 0.7.0 also includes `alyte.accessRules` and `alyte.memberships` for
|
|
35
|
+
merchant-controlled early access: save a draft, preview, schedule or cancel, and attest or
|
|
36
|
+
revoke membership. They require a server at or after sandbox revision `alyte-sandbox-00133-v77`.
|
|
37
|
+
See [the access-rule workflow](./README.md#access-rules-and-membership)
|
|
38
|
+
for request identities, explicit-offset windows and revision checks.
|
|
39
|
+
Membership uses the `buyerId` returned by `buyerSessions.mint`; retain its mapping to
|
|
40
|
+
your own customer ID rather than passing your internal customer ID to `memberships.upsert`.
|
|
41
|
+
|
|
34
42
|
## Plugging in YOUR auth + user database (required for buyer flows)
|
|
35
43
|
|
|
36
44
|
Your customers already have accounts with you — Alyte does not replace that.
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ npm install @alytegen/sdk
|
|
|
23
23
|
| `createWebhookHandler` / `verifyWebhookSignature` | webhook secret | your server | signed, at-least-once purchase events with typed dispatch |
|
|
24
24
|
| `exchangeBuyerSession` / `createBuyerClient` / `openConsent` from `@alytegen/sdk/browser` | bounded buyer bearer | partner browser/chat | isolated consent, then buy/watch/list/revoke within existing authority |
|
|
25
25
|
|
|
26
|
-
The browser entry arrived in 0.4.0; 0.
|
|
26
|
+
The browser entry arrived in 0.4.0; 0.7.0 is the current release. See [the chat integration](./BROWSER.md) for setup,
|
|
27
27
|
cookie-independent consent, reconnecting and handling uncertain purchases.
|
|
28
28
|
|
|
29
29
|
## Merchant: onboard in four calls
|
|
@@ -91,6 +91,69 @@ with `catalog_too_large` if any source relation exceeds 2,000 rows, including pr
|
|
|
91
91
|
eligibility rows. `listLocations` has a separate 2,000-row bound. Neither returns a
|
|
92
92
|
truncated result.
|
|
93
93
|
|
|
94
|
+
## Access rules and membership
|
|
95
|
+
|
|
96
|
+
Available since SDK 0.7.0; requires a server at or after sandbox revision
|
|
97
|
+
`alyte-sandbox-00133-v77`. Use a backend credential with `merchant:read` and
|
|
98
|
+
`merchant:write`. The console exposes the same flow to account owners.
|
|
99
|
+
|
|
100
|
+
An access rule grants an early window before a tier's general-sale opening. Create a
|
|
101
|
+
draft, review its current impact, then schedule it:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const { program } = await alyte.memberships.createProgram(merchant.id, {
|
|
105
|
+
requestId: crypto.randomUUID(), name: 'Members', levels: ['Gold', 'Platinum'],
|
|
106
|
+
});
|
|
107
|
+
const { rule } = await alyte.accessRules.createDraft(merchant.id, {
|
|
108
|
+
requestId: crypto.randomUUID(), offerId: tier.id, name: 'Member presale',
|
|
109
|
+
audience: { kind: 'membership', programId: program.id, levels: ['Gold', 'Platinum'] },
|
|
110
|
+
opensAt: '2027-05-01T09:00:00+01:00',
|
|
111
|
+
closesAt: '2027-05-01T10:00:00+01:00', // must end by the tier's general-sale opening
|
|
112
|
+
});
|
|
113
|
+
const preview = await alyte.accessRules.preview(merchant.id, rule.id);
|
|
114
|
+
// Show preview.impact, preview.timeZone and the window to the operator for review.
|
|
115
|
+
const publication = {
|
|
116
|
+
requestId: crypto.randomUUID(), expectedRevision: rule.revision, previewId: preview.id,
|
|
117
|
+
};
|
|
118
|
+
// Persist publication before dispatch; reuse exactly this input after an uncertain response.
|
|
119
|
+
const scheduled = await alyte.accessRules.schedule(merchant.id, rule.id, publication);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Persist **each** mutation's request UUID and input before dispatch. Exact replays are safe;
|
|
123
|
+
changed input requires a new UUID. `access_conflict` means refresh and review again.
|
|
124
|
+
Drafts remain inactive. To cancel, call `preview(shopId, ruleId, 'cancel')`, then
|
|
125
|
+
`cancel` with that preview ID, the current rule revision and a new request UUID.
|
|
126
|
+
Published rules cannot be edited.
|
|
127
|
+
|
|
128
|
+
The merchant supplies verified membership for the **Alyte buyer ID** returned as
|
|
129
|
+
`buyerId` by `buyerSessions.mint`. Store a mapping from your authenticated customer's
|
|
130
|
+
internal ID to this returned value, scoped to the Alyte account. Passing your own customer
|
|
131
|
+
ID directly will not match the buyer's Alyte agent. Obtain the identity during your existing
|
|
132
|
+
signed-in hand-off; never derive or guess it from an email address.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const session = await alyte.buyerSessions.mint({
|
|
136
|
+
merchantId: merchant.id, email: user.email,
|
|
137
|
+
});
|
|
138
|
+
const evidence = {
|
|
139
|
+
requestId: crypto.randomUUID(), sourceRevision: 1, level: 'Gold',
|
|
140
|
+
validFrom: '2027-01-01T00:00:00Z', validUntil: '2028-01-01T00:00:00Z',
|
|
141
|
+
evidenceRef: 'membership-system:record-123', revoked: false,
|
|
142
|
+
};
|
|
143
|
+
await alyte.memberships.upsert(merchant.id, program.id, session.buyerId, evidence);
|
|
144
|
+
// Revoke using a new requestId, a strictly greater sourceRevision, and revoked: true.
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Levels are explicit, with no implied hierarchy. Membership does not grant payment permission.
|
|
148
|
+
Other audiences are `{ kind: 'everyone' }` and
|
|
149
|
+
`{ kind: 'scheme', schemes: ['amex'] }`; card eligibility uses the actual saved instrument.
|
|
150
|
+
Issuer claims and free-text loyalty claims are not accepted. All times require explicit offsets.
|
|
151
|
+
Impact counts are observations of access, not stock forecasts or guaranteed queue positions.
|
|
152
|
+
|
|
153
|
+
Deleting an offer archives its rules in the read API. `accessRules.list` omits them, so
|
|
154
|
+
they do not consume the active list's limit. `accessRules.get` still returns their historical
|
|
155
|
+
definition and revision with `status: 'archived'`; archived rules cannot be edited or published.
|
|
156
|
+
|
|
94
157
|
## Hand a signed-in customer to their agent
|
|
95
158
|
|
|
96
159
|
Your users already have accounts with you. Your server attests one of them and redirects;
|
|
@@ -151,7 +214,9 @@ the buyer's mandate said no: surface it, don't retry.
|
|
|
151
214
|
|
|
152
215
|
## Current API and console capabilities
|
|
153
216
|
|
|
154
|
-
SDK **0.
|
|
217
|
+
SDK **0.7.0** adds merchant-controlled early access: `accessRules` (`list`, `get`,
|
|
218
|
+
`createDraft`, `updateDraft`, `preview`, `schedule`, `cancel`) and `memberships`
|
|
219
|
+
(`createProgram`, `upsert`). **0.6.0** added inventory management: shared pools (`createPool`, `listPools`, `updatePool`),
|
|
155
220
|
optional venue locations with pinned versions (`createLocation`, `listLocations`, `updateLocation`,
|
|
156
221
|
`getSlot`, `setSlotLocation`, `createEvent({ location })`) and a read-only `inventoryCatalog`
|
|
157
222
|
observation. **0.5.0** typed the merchant-attested mint (`merchantAttested: true`), alongside the browser
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Transport } from './http.js';
|
|
2
|
+
export type AccessAudience = {
|
|
3
|
+
kind: 'everyone';
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'membership';
|
|
6
|
+
programId: string;
|
|
7
|
+
levels: string[];
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'scheme';
|
|
10
|
+
schemes: Array<'visa' | 'mastercard' | 'amex'>;
|
|
11
|
+
};
|
|
12
|
+
export interface AccessDraftInput {
|
|
13
|
+
requestId: string;
|
|
14
|
+
offerId: string;
|
|
15
|
+
name: string;
|
|
16
|
+
audience?: AccessAudience;
|
|
17
|
+
opensAt?: string;
|
|
18
|
+
closesAt?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AccessRule extends Omit<AccessDraftInput, 'requestId'> {
|
|
21
|
+
id: string;
|
|
22
|
+
revision: number;
|
|
23
|
+
status: 'draft' | 'scheduled' | 'cancelled' | 'archived';
|
|
24
|
+
}
|
|
25
|
+
export interface MembershipProgram {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
levels: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface AccessPreview {
|
|
31
|
+
id: string;
|
|
32
|
+
rule: AccessRule;
|
|
33
|
+
action: 'schedule' | 'cancel';
|
|
34
|
+
expiresAt: string;
|
|
35
|
+
observedAt: string;
|
|
36
|
+
impact: {
|
|
37
|
+
total: number;
|
|
38
|
+
earlier: number;
|
|
39
|
+
later: number;
|
|
40
|
+
unchanged: number;
|
|
41
|
+
};
|
|
42
|
+
timeZone: string;
|
|
43
|
+
generalSaleAt: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface AccessCommitInput {
|
|
46
|
+
requestId: string;
|
|
47
|
+
expectedRevision: number;
|
|
48
|
+
previewId: string;
|
|
49
|
+
}
|
|
50
|
+
export interface MembershipEvidence {
|
|
51
|
+
requestId: string;
|
|
52
|
+
sourceRevision: number;
|
|
53
|
+
level: string;
|
|
54
|
+
validFrom: string;
|
|
55
|
+
validUntil: string;
|
|
56
|
+
evidenceRef: string;
|
|
57
|
+
revoked: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Backend-only merchant access control. Save each request UUID before dispatch and
|
|
60
|
+
* reuse it only for the exact same operation. No mutation is retried automatically. */
|
|
61
|
+
export declare class MerchantAccessRules {
|
|
62
|
+
private readonly t;
|
|
63
|
+
constructor(t: Transport);
|
|
64
|
+
list(shop: string): Promise<{
|
|
65
|
+
rules: AccessRule[];
|
|
66
|
+
programs: MembershipProgram[];
|
|
67
|
+
}>;
|
|
68
|
+
get(shop: string, id: string): Promise<{
|
|
69
|
+
rule: AccessRule;
|
|
70
|
+
}>;
|
|
71
|
+
createDraft(shop: string, input: AccessDraftInput): Promise<{
|
|
72
|
+
rule: AccessRule;
|
|
73
|
+
}>;
|
|
74
|
+
updateDraft(shop: string, id: string, input: AccessDraftInput & {
|
|
75
|
+
expectedRevision: number;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
rule: AccessRule;
|
|
78
|
+
}>;
|
|
79
|
+
preview(shop: string, id: string, action?: 'schedule' | 'cancel'): Promise<AccessPreview>;
|
|
80
|
+
schedule(shop: string, id: string, input: AccessCommitInput): Promise<{
|
|
81
|
+
rule: AccessRule;
|
|
82
|
+
}>;
|
|
83
|
+
cancel(shop: string, id: string, input: AccessCommitInput): Promise<{
|
|
84
|
+
rule: AccessRule;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
/** A merchant attests membership in its own program, not payment permission. */
|
|
88
|
+
export declare class MerchantMemberships {
|
|
89
|
+
private readonly t;
|
|
90
|
+
constructor(t: Transport);
|
|
91
|
+
createProgram(shop: string, input: {
|
|
92
|
+
requestId: string;
|
|
93
|
+
name: string;
|
|
94
|
+
levels: string[];
|
|
95
|
+
}): Promise<{
|
|
96
|
+
program: MembershipProgram;
|
|
97
|
+
}>;
|
|
98
|
+
upsert(shop: string, programId: string, buyerId: string, input: MembershipEvidence): Promise<{
|
|
99
|
+
membership: {
|
|
100
|
+
programId: string;
|
|
101
|
+
buyerId: string;
|
|
102
|
+
sourceRevision: number;
|
|
103
|
+
revoked: boolean;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
}
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const base = (shop) => `/v1/integration/merchants/${encodeURIComponent(shop)}/access`;
|
|
2
|
+
/** Backend-only merchant access control. Save each request UUID before dispatch and
|
|
3
|
+
* reuse it only for the exact same operation. No mutation is retried automatically. */
|
|
4
|
+
export class MerchantAccessRules {
|
|
5
|
+
t;
|
|
6
|
+
constructor(t) {
|
|
7
|
+
this.t = t;
|
|
8
|
+
}
|
|
9
|
+
list(shop) { return this.t.request('GET', base(shop)); }
|
|
10
|
+
get(shop, id) { return this.t.request('GET', `${base(shop)}/rules/${encodeURIComponent(id)}`); }
|
|
11
|
+
createDraft(shop, input) { return this.t.request('POST', `${base(shop)}/rules`, input); }
|
|
12
|
+
updateDraft(shop, id, input) { return this.t.request('PUT', `${base(shop)}/rules/${encodeURIComponent(id)}`, input); }
|
|
13
|
+
preview(shop, id, action = 'schedule') { return this.t.request('POST', `${base(shop)}/rules/${encodeURIComponent(id)}/preview`, { action }); }
|
|
14
|
+
schedule(shop, id, input) { return this.t.request('POST', `${base(shop)}/rules/${encodeURIComponent(id)}/schedule`, input); }
|
|
15
|
+
cancel(shop, id, input) { return this.t.request('POST', `${base(shop)}/rules/${encodeURIComponent(id)}/cancel`, input); }
|
|
16
|
+
}
|
|
17
|
+
/** A merchant attests membership in its own program, not payment permission. */
|
|
18
|
+
export class MerchantMemberships {
|
|
19
|
+
t;
|
|
20
|
+
constructor(t) {
|
|
21
|
+
this.t = t;
|
|
22
|
+
}
|
|
23
|
+
createProgram(shop, input) { return this.t.request('POST', `${base(shop)}/programs`, input); }
|
|
24
|
+
upsert(shop, programId, buyerId, input) {
|
|
25
|
+
return this.t.request('PUT', `${base(shop)}/programs/${encodeURIComponent(programId)}/members/${encodeURIComponent(buyerId)}`, input);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { AlyteApiError, type ClientOptions } from './http.js';
|
|
|
4
4
|
export { verifyWebhookSignature } from './webhookVerify.js';
|
|
5
5
|
export { handleWebhook, createWebhookHandler, type AlyteEventEnvelope, type PaymentSettled, type WatchFailed, type WebhookTest, type PurchaseHandlers, type OnPurchaseOptions, type WebhookResult, } from './onPurchase.js';
|
|
6
6
|
export type * from './types.js';
|
|
7
|
+
export type { AccessAudience, AccessDraftInput, AccessRule, AccessPreview, AccessCommitInput, MembershipProgram, MembershipEvidence } from './access.js';
|
package/dist/merchant.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ClientOptions } from './http.js';
|
|
2
|
+
import { MerchantAccessRules, MerchantMemberships } from './access.js';
|
|
2
3
|
import type { BuyerSessionMint, CatalogMerchant, Merchant, EventItem, MerchantPspLink, Tier, TierKind, FeeBearer, Scheme, PaymentRow, WebhookEndpoint, MerchantInsights, InventoryCatalog, InventoryLocation, InventoryLocationBinding, InventoryOccurrence, InventoryPool } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Merchant integration client — drives the `/v1/integration/*` surface with a
|
|
@@ -14,6 +15,8 @@ import type { BuyerSessionMint, CatalogMerchant, Merchant, EventItem, MerchantPs
|
|
|
14
15
|
*/
|
|
15
16
|
export declare class AlyteMerchant {
|
|
16
17
|
private readonly t;
|
|
18
|
+
readonly accessRules: MerchantAccessRules;
|
|
19
|
+
readonly memberships: MerchantMemberships;
|
|
17
20
|
constructor(opts: ClientOptions);
|
|
18
21
|
/** Your tenant's full catalog: shops → events → tiers (with restriction fields). */
|
|
19
22
|
catalog(): Promise<{
|
package/dist/merchant.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Transport } from './http.js';
|
|
2
|
+
import { MerchantAccessRules, MerchantMemberships } from './access.js';
|
|
2
3
|
/**
|
|
3
4
|
* Merchant integration client — drives the `/v1/integration/*` surface with a
|
|
4
5
|
* console-minted API token (`merchant:read` / `merchant:write` scopes; `merchant:admin` for
|
|
@@ -13,8 +14,12 @@ import { Transport } from './http.js';
|
|
|
13
14
|
*/
|
|
14
15
|
export class AlyteMerchant {
|
|
15
16
|
t;
|
|
17
|
+
accessRules;
|
|
18
|
+
memberships;
|
|
16
19
|
constructor(opts) {
|
|
17
20
|
this.t = new Transport(opts);
|
|
21
|
+
this.accessRules = new MerchantAccessRules(this.t);
|
|
22
|
+
this.memberships = new MerchantMemberships(this.t);
|
|
18
23
|
}
|
|
19
24
|
/** Your tenant's full catalog: shops → events → tiers (with restriction fields). */
|
|
20
25
|
catalog() {
|
package/dist/types.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export interface DiscoveredTier extends Tier {
|
|
|
58
58
|
authorizeUrl?: string;
|
|
59
59
|
}
|
|
60
60
|
export interface DiscoveredEvent extends EventItem {
|
|
61
|
+
/** Pinned venue display metadata. Null = unknown; absent on older servers. */
|
|
62
|
+
location?: {
|
|
63
|
+
name: string;
|
|
64
|
+
timeZone: string;
|
|
65
|
+
} | null;
|
|
61
66
|
tiers: DiscoveredTier[];
|
|
62
67
|
}
|
|
63
68
|
/** A price snapshot locked at quote time; the charge must match it. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alytegen/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|