@sly_ai/sdk 0.1.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/README.md +346 -0
- package/dist/a2a.d.mts +108 -0
- package/dist/a2a.d.ts +108 -0
- package/dist/a2a.js +173 -0
- package/dist/a2a.js.map +1 -0
- package/dist/a2a.mjs +171 -0
- package/dist/a2a.mjs.map +1 -0
- package/dist/acp.d.mts +201 -0
- package/dist/acp.d.ts +201 -0
- package/dist/acp.js +143 -0
- package/dist/acp.js.map +1 -0
- package/dist/acp.mjs +141 -0
- package/dist/acp.mjs.map +1 -0
- package/dist/ap2.d.mts +188 -0
- package/dist/ap2.d.ts +188 -0
- package/dist/ap2.js +135 -0
- package/dist/ap2.js.map +1 -0
- package/dist/ap2.mjs +133 -0
- package/dist/ap2.mjs.map +1 -0
- package/dist/cards.d.mts +750 -0
- package/dist/cards.d.ts +750 -0
- package/dist/cards.js +373 -0
- package/dist/cards.js.map +1 -0
- package/dist/cards.mjs +369 -0
- package/dist/cards.mjs.map +1 -0
- package/dist/client-Cwe2CLU7.d.mts +41 -0
- package/dist/client-CyJe3uWO.d.ts +41 -0
- package/dist/index.d.mts +662 -0
- package/dist/index.d.ts +662 -0
- package/dist/index.js +2709 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2700 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain.d.mts +11 -0
- package/dist/langchain.d.ts +11 -0
- package/dist/langchain.js +25 -0
- package/dist/langchain.js.map +1 -0
- package/dist/langchain.mjs +23 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/types-df1EICn_.d.mts +165 -0
- package/dist/types-df1EICn_.d.ts +165 -0
- package/dist/ucp.d.mts +844 -0
- package/dist/ucp.d.ts +844 -0
- package/dist/ucp.js +616 -0
- package/dist/ucp.js.map +1 -0
- package/dist/ucp.mjs +614 -0
- package/dist/ucp.mjs.map +1 -0
- package/dist/vercel.d.mts +178 -0
- package/dist/vercel.d.ts +178 -0
- package/dist/vercel.js +143 -0
- package/dist/vercel.js.map +1 -0
- package/dist/vercel.mjs +138 -0
- package/dist/vercel.mjs.map +1 -0
- package/dist/x402.d.mts +209 -0
- package/dist/x402.d.ts +209 -0
- package/dist/x402.js +476 -0
- package/dist/x402.js.map +1 -0
- package/dist/x402.mjs +471 -0
- package/dist/x402.mjs.map +1 -0
- package/package.json +118 -0
package/dist/ucp.js
ADDED
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/protocols/ucp/client.ts
|
|
4
|
+
var profileCache = /* @__PURE__ */ new Map();
|
|
5
|
+
var PROFILE_CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
6
|
+
var UCPClient = class {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
// ===========================================================================
|
|
11
|
+
// Discovery
|
|
12
|
+
// ===========================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Discover a UCP merchant's capabilities
|
|
15
|
+
*
|
|
16
|
+
* Fetches and caches the merchant's UCP profile from /.well-known/ucp
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const merchant = await payos.ucp.discover('https://shop.example.com');
|
|
21
|
+
* console.log(merchant.ucp.version);
|
|
22
|
+
* console.log(merchant.payment?.handlers);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
async discover(merchantUrl) {
|
|
26
|
+
const baseUrl = merchantUrl.replace(/\/$/, "");
|
|
27
|
+
const profileUrl = `${baseUrl}/.well-known/ucp`;
|
|
28
|
+
const cached = profileCache.get(profileUrl);
|
|
29
|
+
if (cached && Date.now() - cached.fetchedAt < PROFILE_CACHE_TTL_MS) {
|
|
30
|
+
return cached.profile;
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(profileUrl, {
|
|
33
|
+
headers: {
|
|
34
|
+
Accept: "application/json",
|
|
35
|
+
"User-Agent": "PayOS-SDK/1.0"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Failed to discover UCP profile: ${response.status} ${response.statusText}`);
|
|
40
|
+
}
|
|
41
|
+
const profile = await response.json();
|
|
42
|
+
if (!profile.ucp?.version) {
|
|
43
|
+
throw new Error("Invalid UCP profile: missing ucp.version");
|
|
44
|
+
}
|
|
45
|
+
profileCache.set(profileUrl, {
|
|
46
|
+
profile,
|
|
47
|
+
fetchedAt: Date.now()
|
|
48
|
+
});
|
|
49
|
+
return profile;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get PayOS's own UCP profile
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const profile = await payos.ucp.getProfile();
|
|
57
|
+
* console.log(profile.payment?.handlers);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async getProfile() {
|
|
61
|
+
return this.client.request("/.well-known/ucp");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get available settlement corridors
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const corridors = await payos.ucp.getCorridors();
|
|
69
|
+
* console.log(corridors.find(c => c.rail === 'pix'));
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async getCorridors() {
|
|
73
|
+
const response = await this.client.request(
|
|
74
|
+
"/v1/ucp/corridors"
|
|
75
|
+
);
|
|
76
|
+
return response.corridors;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get UCP handler info
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const info = await payos.ucp.getHandlerInfo();
|
|
84
|
+
* console.log(info.handler.name); // com.payos.latam_settlement
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
async getHandlerInfo() {
|
|
88
|
+
return this.client.request("/v1/ucp/info");
|
|
89
|
+
}
|
|
90
|
+
// ===========================================================================
|
|
91
|
+
// Quotes
|
|
92
|
+
// ===========================================================================
|
|
93
|
+
/**
|
|
94
|
+
* Get an FX quote for a settlement corridor
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const quote = await payos.ucp.getQuote({
|
|
99
|
+
* corridor: 'pix',
|
|
100
|
+
* amount: 100,
|
|
101
|
+
* currency: 'USD',
|
|
102
|
+
* });
|
|
103
|
+
* console.log(`${quote.from_amount} USD = ${quote.to_amount} BRL`);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
async getQuote(request) {
|
|
107
|
+
return this.client.request("/v1/ucp/quote", {
|
|
108
|
+
method: "POST",
|
|
109
|
+
body: JSON.stringify(request)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// ===========================================================================
|
|
113
|
+
// Token Acquisition (Payment Handler flow)
|
|
114
|
+
// ===========================================================================
|
|
115
|
+
/**
|
|
116
|
+
* Acquire a settlement token for completing a UCP checkout
|
|
117
|
+
*
|
|
118
|
+
* Tokens are valid for 15 minutes and lock in the FX rate.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const token = await payos.ucp.acquireToken({
|
|
123
|
+
* corridor: 'pix',
|
|
124
|
+
* amount: 100,
|
|
125
|
+
* currency: 'USD',
|
|
126
|
+
* recipient: {
|
|
127
|
+
* type: 'pix',
|
|
128
|
+
* pix_key: '12345678901',
|
|
129
|
+
* pix_key_type: 'cpf',
|
|
130
|
+
* name: 'Maria Silva',
|
|
131
|
+
* },
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* console.log(token.token); // ucp_tok_...
|
|
135
|
+
* console.log(token.quote.to_amount); // 595.00 BRL
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async acquireToken(request) {
|
|
139
|
+
return this.client.request("/v1/ucp/tokens", {
|
|
140
|
+
method: "POST",
|
|
141
|
+
body: JSON.stringify(request)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// ===========================================================================
|
|
145
|
+
// Settlement Execution
|
|
146
|
+
// ===========================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Complete settlement using a previously acquired token
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const settlement = await payos.ucp.settle({
|
|
153
|
+
* token: 'ucp_tok_...',
|
|
154
|
+
* idempotency_key: 'checkout_12345',
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* console.log(settlement.status); // pending
|
|
158
|
+
* console.log(settlement.id); // Use this to track status
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
async settle(request) {
|
|
162
|
+
return this.client.request("/v1/ucp/settle", {
|
|
163
|
+
method: "POST",
|
|
164
|
+
body: JSON.stringify(request)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get settlement status by ID
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const settlement = await payos.ucp.getSettlement('uuid');
|
|
173
|
+
* if (settlement.status === 'completed') {
|
|
174
|
+
* console.log(`Completed at ${settlement.completed_at}`);
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
async getSettlement(settlementId) {
|
|
179
|
+
return this.client.request(`/v1/ucp/settlements/${settlementId}`);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* List settlements with optional filtering
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const { data, pagination } = await payos.ucp.listSettlements({
|
|
187
|
+
* status: 'completed',
|
|
188
|
+
* corridor: 'pix',
|
|
189
|
+
* limit: 50,
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async listSettlements(options = {}) {
|
|
194
|
+
const params = new URLSearchParams();
|
|
195
|
+
if (options.status) params.append("status", options.status);
|
|
196
|
+
if (options.corridor) params.append("corridor", options.corridor);
|
|
197
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
198
|
+
if (options.offset) params.append("offset", options.offset.toString());
|
|
199
|
+
const queryString = params.toString();
|
|
200
|
+
const path = queryString ? `/v1/ucp/settlements?${queryString}` : "/v1/ucp/settlements";
|
|
201
|
+
return this.client.request(path);
|
|
202
|
+
}
|
|
203
|
+
// ===========================================================================
|
|
204
|
+
// Checkout (Consuming UCP Merchants)
|
|
205
|
+
// ===========================================================================
|
|
206
|
+
/**
|
|
207
|
+
* Create a checkout session with a UCP merchant
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const checkout = await payos.ucp.createCheckout('https://shop.example.com', {
|
|
212
|
+
* line_items: [
|
|
213
|
+
* { product_id: 'prod_123', quantity: 2 },
|
|
214
|
+
* ],
|
|
215
|
+
* buyer: { email: 'buyer@example.com' },
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* console.log(checkout.totals.total);
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
async createCheckout(merchantUrl, request) {
|
|
222
|
+
const profile = await this.discover(merchantUrl);
|
|
223
|
+
if (!profile.checkout?.endpoint) {
|
|
224
|
+
throw new Error("Merchant does not support UCP checkout");
|
|
225
|
+
}
|
|
226
|
+
const response = await fetch(profile.checkout.endpoint, {
|
|
227
|
+
method: "POST",
|
|
228
|
+
headers: {
|
|
229
|
+
"Content-Type": "application/json",
|
|
230
|
+
"User-Agent": "PayOS-SDK/1.0"
|
|
231
|
+
},
|
|
232
|
+
body: JSON.stringify(request)
|
|
233
|
+
});
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
const error = await response.json().catch(() => ({}));
|
|
236
|
+
throw new Error(`Failed to create checkout: ${response.status} - ${JSON.stringify(error)}`);
|
|
237
|
+
}
|
|
238
|
+
return await response.json();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Complete a checkout with PayOS LATAM settlement
|
|
242
|
+
*
|
|
243
|
+
* This is a convenience method that:
|
|
244
|
+
* 1. Acquires a settlement token
|
|
245
|
+
* 2. Completes the checkout with the merchant
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const order = await payos.ucp.completeCheckout(
|
|
250
|
+
* 'https://shop.example.com',
|
|
251
|
+
* checkout.id,
|
|
252
|
+
* {
|
|
253
|
+
* corridor: 'pix',
|
|
254
|
+
* recipient: {
|
|
255
|
+
* type: 'pix',
|
|
256
|
+
* pix_key: '12345678901',
|
|
257
|
+
* pix_key_type: 'cpf',
|
|
258
|
+
* name: 'Maria Silva',
|
|
259
|
+
* },
|
|
260
|
+
* }
|
|
261
|
+
* );
|
|
262
|
+
*
|
|
263
|
+
* console.log(order.id);
|
|
264
|
+
* console.log(order.payment.settlement_id);
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
async completeCheckout(merchantUrl, checkoutId, settlement) {
|
|
268
|
+
const profile = await this.discover(merchantUrl);
|
|
269
|
+
if (!profile.checkout?.endpoint) {
|
|
270
|
+
throw new Error("Merchant does not support UCP checkout");
|
|
271
|
+
}
|
|
272
|
+
const checkoutResponse = await fetch(`${profile.checkout.endpoint}/${checkoutId}`, {
|
|
273
|
+
headers: {
|
|
274
|
+
"User-Agent": "PayOS-SDK/1.0"
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
if (!checkoutResponse.ok) {
|
|
278
|
+
throw new Error(`Failed to fetch checkout: ${checkoutResponse.status}`);
|
|
279
|
+
}
|
|
280
|
+
const checkout = await checkoutResponse.json();
|
|
281
|
+
const token = await this.acquireToken({
|
|
282
|
+
corridor: settlement.corridor,
|
|
283
|
+
amount: checkout.totals.total,
|
|
284
|
+
currency: checkout.totals.currency,
|
|
285
|
+
recipient: settlement.recipient
|
|
286
|
+
});
|
|
287
|
+
const completeRequest = {
|
|
288
|
+
payment_handler: "payos_latam",
|
|
289
|
+
payment_data: {
|
|
290
|
+
token: token.token
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const completeResponse = await fetch(`${profile.checkout.endpoint}/${checkoutId}/complete`, {
|
|
294
|
+
method: "POST",
|
|
295
|
+
headers: {
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
"User-Agent": "PayOS-SDK/1.0"
|
|
298
|
+
},
|
|
299
|
+
body: JSON.stringify(completeRequest)
|
|
300
|
+
});
|
|
301
|
+
if (!completeResponse.ok) {
|
|
302
|
+
const error = await completeResponse.json().catch(() => ({}));
|
|
303
|
+
throw new Error(`Failed to complete checkout: ${completeResponse.status} - ${JSON.stringify(error)}`);
|
|
304
|
+
}
|
|
305
|
+
return await completeResponse.json();
|
|
306
|
+
}
|
|
307
|
+
// ===========================================================================
|
|
308
|
+
// Utilities
|
|
309
|
+
// ===========================================================================
|
|
310
|
+
/**
|
|
311
|
+
* Clear the profile cache (useful for testing)
|
|
312
|
+
*/
|
|
313
|
+
clearCache() {
|
|
314
|
+
profileCache.clear();
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Check if PayOS supports a specific corridor
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```typescript
|
|
321
|
+
* if (await payos.ucp.supportsCorridors('USD', 'BRL', 'pix')) {
|
|
322
|
+
* // Can settle via Pix
|
|
323
|
+
* }
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
async supportsCorridor(sourceCurrency, destinationCurrency, rail) {
|
|
327
|
+
const corridors = await this.getCorridors();
|
|
328
|
+
return corridors.some(
|
|
329
|
+
(c) => c.source_currency === sourceCurrency && c.destination_currency === destinationCurrency && c.rail === rail
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Create Pix recipient helper
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* const recipient = payos.ucp.createPixRecipient({
|
|
338
|
+
* pix_key: '12345678901',
|
|
339
|
+
* pix_key_type: 'cpf',
|
|
340
|
+
* name: 'Maria Silva',
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
createPixRecipient(params) {
|
|
345
|
+
return {
|
|
346
|
+
type: "pix",
|
|
347
|
+
...params
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Create SPEI recipient helper
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const recipient = payos.ucp.createSpeiRecipient({
|
|
356
|
+
* clabe: '012345678901234567',
|
|
357
|
+
* name: 'Juan Garcia',
|
|
358
|
+
* });
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
createSpeiRecipient(params) {
|
|
362
|
+
return {
|
|
363
|
+
type: "spei",
|
|
364
|
+
...params
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
// ===========================================================================
|
|
368
|
+
// PayOS-Hosted Checkout Sessions (Phase 2)
|
|
369
|
+
// ===========================================================================
|
|
370
|
+
/**
|
|
371
|
+
* Create a PayOS-hosted checkout session
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* const checkout = await payos.ucp.checkouts.create({
|
|
376
|
+
* currency: 'USD',
|
|
377
|
+
* line_items: [
|
|
378
|
+
* { id: 'item_1', name: 'Product', quantity: 1, unit_price: 1000, total_price: 1000, currency: 'USD' }
|
|
379
|
+
* ],
|
|
380
|
+
* buyer: { email: 'buyer@example.com' },
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
get checkouts() {
|
|
385
|
+
return {
|
|
386
|
+
create: async (request) => {
|
|
387
|
+
return this.client.request("/v1/ucp/checkouts", {
|
|
388
|
+
method: "POST",
|
|
389
|
+
body: JSON.stringify(request)
|
|
390
|
+
});
|
|
391
|
+
},
|
|
392
|
+
get: async (checkoutId) => {
|
|
393
|
+
return this.client.request(`/v1/ucp/checkouts/${checkoutId}`);
|
|
394
|
+
},
|
|
395
|
+
update: async (checkoutId, request) => {
|
|
396
|
+
return this.client.request(`/v1/ucp/checkouts/${checkoutId}`, {
|
|
397
|
+
method: "PUT",
|
|
398
|
+
body: JSON.stringify(request)
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
complete: async (checkoutId) => {
|
|
402
|
+
return this.client.request(`/v1/ucp/checkouts/${checkoutId}/complete`, {
|
|
403
|
+
method: "POST"
|
|
404
|
+
});
|
|
405
|
+
},
|
|
406
|
+
cancel: async (checkoutId) => {
|
|
407
|
+
return this.client.request(`/v1/ucp/checkouts/${checkoutId}/cancel`, {
|
|
408
|
+
method: "POST"
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
addPaymentInstrument: async (checkoutId, instrument) => {
|
|
412
|
+
return this.client.request(`/v1/ucp/checkouts/${checkoutId}/instruments`, {
|
|
413
|
+
method: "POST",
|
|
414
|
+
body: JSON.stringify(instrument)
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
// ===========================================================================
|
|
420
|
+
// PayOS Orders (Phase 3)
|
|
421
|
+
// ===========================================================================
|
|
422
|
+
/**
|
|
423
|
+
* Manage PayOS orders
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const order = await payos.ucp.orders.get('ord_123');
|
|
428
|
+
* const orders = await payos.ucp.orders.list({ status: 'processing' });
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
get orders() {
|
|
432
|
+
return {
|
|
433
|
+
get: async (orderId) => {
|
|
434
|
+
return this.client.request(`/v1/ucp/orders/${orderId}`);
|
|
435
|
+
},
|
|
436
|
+
list: async (options = {}) => {
|
|
437
|
+
const params = new URLSearchParams();
|
|
438
|
+
if (options.status) params.append("status", options.status);
|
|
439
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
440
|
+
if (options.offset) params.append("offset", options.offset.toString());
|
|
441
|
+
const queryString = params.toString();
|
|
442
|
+
const path = queryString ? `/v1/ucp/orders?${queryString}` : "/v1/ucp/orders";
|
|
443
|
+
return this.client.request(path);
|
|
444
|
+
},
|
|
445
|
+
updateStatus: async (orderId, status) => {
|
|
446
|
+
return this.client.request(`/v1/ucp/orders/${orderId}/status`, {
|
|
447
|
+
method: "PUT",
|
|
448
|
+
body: JSON.stringify({ status })
|
|
449
|
+
});
|
|
450
|
+
},
|
|
451
|
+
cancel: async (orderId, reason) => {
|
|
452
|
+
return this.client.request(`/v1/ucp/orders/${orderId}/cancel`, {
|
|
453
|
+
method: "POST",
|
|
454
|
+
body: JSON.stringify({ reason })
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
addExpectation: async (orderId, expectation) => {
|
|
458
|
+
return this.client.request(`/v1/ucp/orders/${orderId}/expectations`, {
|
|
459
|
+
method: "POST",
|
|
460
|
+
body: JSON.stringify(expectation)
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
updateExpectation: async (orderId, expectationId, updates) => {
|
|
464
|
+
return this.client.request(
|
|
465
|
+
`/v1/ucp/orders/${orderId}/expectations/${expectationId}`,
|
|
466
|
+
{
|
|
467
|
+
method: "PUT",
|
|
468
|
+
body: JSON.stringify(updates)
|
|
469
|
+
}
|
|
470
|
+
);
|
|
471
|
+
},
|
|
472
|
+
addEvent: async (orderId, event) => {
|
|
473
|
+
return this.client.request(`/v1/ucp/orders/${orderId}/events`, {
|
|
474
|
+
method: "POST",
|
|
475
|
+
body: JSON.stringify(event)
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
getEvents: async (orderId) => {
|
|
479
|
+
return this.client.request(
|
|
480
|
+
`/v1/ucp/orders/${orderId}/events`
|
|
481
|
+
);
|
|
482
|
+
},
|
|
483
|
+
addAdjustment: async (orderId, adjustment) => {
|
|
484
|
+
return this.client.request(`/v1/ucp/orders/${orderId}/adjustments`, {
|
|
485
|
+
method: "POST",
|
|
486
|
+
body: JSON.stringify(adjustment)
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
// ===========================================================================
|
|
492
|
+
// Identity Linking (Phase 4)
|
|
493
|
+
// ===========================================================================
|
|
494
|
+
/**
|
|
495
|
+
* OAuth 2.0 identity linking for AI agents/platforms
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
499
|
+
* // Register an OAuth client
|
|
500
|
+
* const { client, client_secret } = await payos.ucp.identity.registerClient({
|
|
501
|
+
* name: 'My AI Agent',
|
|
502
|
+
* redirect_uris: ['https://myagent.com/callback'],
|
|
503
|
+
* });
|
|
504
|
+
*
|
|
505
|
+
* // List linked accounts
|
|
506
|
+
* const accounts = await payos.ucp.identity.listLinkedAccounts({ buyer_id: 'buyer_123' });
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
get identity() {
|
|
510
|
+
return {
|
|
511
|
+
/**
|
|
512
|
+
* Register an OAuth client (platform/agent)
|
|
513
|
+
*/
|
|
514
|
+
registerClient: async (request) => {
|
|
515
|
+
return this.client.request("/v1/ucp/identity/clients", {
|
|
516
|
+
method: "POST",
|
|
517
|
+
body: JSON.stringify(request)
|
|
518
|
+
});
|
|
519
|
+
},
|
|
520
|
+
/**
|
|
521
|
+
* Get authorization info for consent screen
|
|
522
|
+
*/
|
|
523
|
+
getAuthorizationInfo: async (params) => {
|
|
524
|
+
const searchParams = new URLSearchParams();
|
|
525
|
+
searchParams.append("response_type", params.response_type);
|
|
526
|
+
searchParams.append("client_id", params.client_id);
|
|
527
|
+
searchParams.append("redirect_uri", params.redirect_uri);
|
|
528
|
+
searchParams.append("scope", params.scope);
|
|
529
|
+
searchParams.append("state", params.state);
|
|
530
|
+
if (params.code_challenge) {
|
|
531
|
+
searchParams.append("code_challenge", params.code_challenge);
|
|
532
|
+
}
|
|
533
|
+
if (params.code_challenge_method) {
|
|
534
|
+
searchParams.append("code_challenge_method", params.code_challenge_method);
|
|
535
|
+
}
|
|
536
|
+
return this.client.request(
|
|
537
|
+
`/v1/ucp/identity/authorize?${searchParams.toString()}`
|
|
538
|
+
);
|
|
539
|
+
},
|
|
540
|
+
/**
|
|
541
|
+
* Submit consent decision (after user authenticates)
|
|
542
|
+
*/
|
|
543
|
+
submitConsent: async (request) => {
|
|
544
|
+
return this.client.request("/v1/ucp/identity/authorize/consent", {
|
|
545
|
+
method: "POST",
|
|
546
|
+
body: JSON.stringify(request)
|
|
547
|
+
});
|
|
548
|
+
},
|
|
549
|
+
/**
|
|
550
|
+
* Exchange authorization code for tokens
|
|
551
|
+
*/
|
|
552
|
+
exchangeCode: async (params) => {
|
|
553
|
+
return this.client.request("/v1/ucp/identity/token", {
|
|
554
|
+
method: "POST",
|
|
555
|
+
body: JSON.stringify({
|
|
556
|
+
grant_type: "authorization_code",
|
|
557
|
+
...params
|
|
558
|
+
})
|
|
559
|
+
});
|
|
560
|
+
},
|
|
561
|
+
/**
|
|
562
|
+
* Refresh tokens
|
|
563
|
+
*/
|
|
564
|
+
refreshTokens: async (params) => {
|
|
565
|
+
return this.client.request("/v1/ucp/identity/token", {
|
|
566
|
+
method: "POST",
|
|
567
|
+
body: JSON.stringify({
|
|
568
|
+
grant_type: "refresh_token",
|
|
569
|
+
...params
|
|
570
|
+
})
|
|
571
|
+
});
|
|
572
|
+
},
|
|
573
|
+
/**
|
|
574
|
+
* Revoke a token
|
|
575
|
+
*/
|
|
576
|
+
revokeToken: async (params) => {
|
|
577
|
+
return this.client.request("/v1/ucp/identity/revoke", {
|
|
578
|
+
method: "POST",
|
|
579
|
+
body: JSON.stringify(params)
|
|
580
|
+
});
|
|
581
|
+
},
|
|
582
|
+
/**
|
|
583
|
+
* List linked accounts
|
|
584
|
+
*/
|
|
585
|
+
listLinkedAccounts: async (params) => {
|
|
586
|
+
const searchParams = new URLSearchParams();
|
|
587
|
+
if (params.buyer_id) searchParams.append("buyer_id", params.buyer_id);
|
|
588
|
+
if (params.platform_id) searchParams.append("platform_id", params.platform_id);
|
|
589
|
+
if (params.limit) searchParams.append("limit", params.limit.toString());
|
|
590
|
+
if (params.offset) searchParams.append("offset", params.offset.toString());
|
|
591
|
+
return this.client.request(
|
|
592
|
+
`/v1/ucp/identity/linked-accounts?${searchParams.toString()}`
|
|
593
|
+
);
|
|
594
|
+
},
|
|
595
|
+
/**
|
|
596
|
+
* Unlink an account
|
|
597
|
+
*/
|
|
598
|
+
unlinkAccount: async (accountId, buyerId) => {
|
|
599
|
+
return this.client.request(
|
|
600
|
+
`/v1/ucp/identity/linked-accounts/${accountId}?buyer_id=${buyerId}`,
|
|
601
|
+
{ method: "DELETE" }
|
|
602
|
+
);
|
|
603
|
+
},
|
|
604
|
+
/**
|
|
605
|
+
* Get available scopes
|
|
606
|
+
*/
|
|
607
|
+
getScopes: async () => {
|
|
608
|
+
return this.client.request("/v1/ucp/identity/scopes");
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
exports.UCPClient = UCPClient;
|
|
615
|
+
//# sourceMappingURL=ucp.js.map
|
|
616
|
+
//# sourceMappingURL=ucp.js.map
|