@pear-protocol/core-sdk 1.6.0 → 1.8.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/dist/admin/index.d.ts +1 -0
- package/dist/auth/index.d.ts +34 -2
- package/dist/auth/index.js +40 -0
- package/dist/core/index.d.ts +155 -8
- package/dist/core/index.js +6 -0
- package/dist/external/kalshi.js +4 -2
- package/dist/external/polymarket.js +4 -2
- package/dist/http.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/types.d.ts +9 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +3 -3
package/dist/admin/index.d.ts
CHANGED
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpTypes } from '@pear-protocol/types';
|
|
2
2
|
import { HttpClient } from '../http.js';
|
|
3
3
|
import { ClientHeaders } from '../types.js';
|
|
4
|
+
import '@pear-protocol/utils';
|
|
4
5
|
|
|
5
6
|
declare class Auth {
|
|
6
7
|
private client;
|
|
@@ -14,7 +15,7 @@ declare class Auth {
|
|
|
14
15
|
id: string;
|
|
15
16
|
role: "basic" | "pro" | "admin";
|
|
16
17
|
providerId: string | null;
|
|
17
|
-
loginMethod: "email" | "evm_wallet";
|
|
18
|
+
loginMethod: "email" | "evm_wallet" | "oauth";
|
|
18
19
|
};
|
|
19
20
|
}>;
|
|
20
21
|
requestNonce(body: HttpTypes.RequestNonceRequest, headers?: ClientHeaders): Promise<{
|
|
@@ -28,7 +29,7 @@ declare class Auth {
|
|
|
28
29
|
id: string;
|
|
29
30
|
role: "basic" | "pro" | "admin";
|
|
30
31
|
providerId: string | null;
|
|
31
|
-
loginMethod: "email" | "evm_wallet";
|
|
32
|
+
loginMethod: "email" | "evm_wallet" | "oauth";
|
|
32
33
|
}>;
|
|
33
34
|
apiKeyMe(headers?: ClientHeaders): Promise<{
|
|
34
35
|
id: string;
|
|
@@ -49,6 +50,37 @@ declare class Auth {
|
|
|
49
50
|
changePassword(body: HttpTypes.ChangePasswordRequest, headers?: ClientHeaders): Promise<void>;
|
|
50
51
|
forgotPassword(body: HttpTypes.ForgotPasswordRequest, headers?: ClientHeaders): Promise<void>;
|
|
51
52
|
resetPassword(body: HttpTypes.ResetPasswordRequest, headers?: ClientHeaders): Promise<void>;
|
|
53
|
+
getInteractionDetails(uid: string, headers?: ClientHeaders): Promise<{
|
|
54
|
+
uid: string;
|
|
55
|
+
prompt: {
|
|
56
|
+
name: string;
|
|
57
|
+
details: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
params: Record<string, unknown>;
|
|
60
|
+
client: {
|
|
61
|
+
clientId: string;
|
|
62
|
+
redirectUris: string[];
|
|
63
|
+
clientName?: string | undefined;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
submitInteractionLogin(uid: string, body: HttpTypes.LoginRequest, headers?: ClientHeaders): Promise<{
|
|
67
|
+
returnTo: string;
|
|
68
|
+
}>;
|
|
69
|
+
confirmInteraction(uid: string, body: HttpTypes.OauthInteractionConfirmRequest, headers?: ClientHeaders): Promise<{
|
|
70
|
+
returnTo: string;
|
|
71
|
+
}>;
|
|
72
|
+
abortInteraction(uid: string, headers?: ClientHeaders): Promise<{
|
|
73
|
+
returnTo: string;
|
|
74
|
+
}>;
|
|
75
|
+
listOauthGrants(headers?: ClientHeaders): Promise<{
|
|
76
|
+
grants: {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
scopes: string[];
|
|
80
|
+
connectedAt: string;
|
|
81
|
+
}[];
|
|
82
|
+
}>;
|
|
83
|
+
revokeOauthGrant(id: string, headers?: ClientHeaders): Promise<void>;
|
|
52
84
|
}
|
|
53
85
|
|
|
54
86
|
export { Auth };
|
package/dist/auth/index.js
CHANGED
|
@@ -111,6 +111,46 @@ class Auth {
|
|
|
111
111
|
body
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
+
// --- OAuth interaction (login + consent), keyed by uid in the URL, served by apps/auth ---
|
|
115
|
+
async getInteractionDetails(uid, headers) {
|
|
116
|
+
return await this.client.fetch(`/interaction/${uid}`, {
|
|
117
|
+
method: "GET",
|
|
118
|
+
headers
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async submitInteractionLogin(uid, body, headers) {
|
|
122
|
+
return await this.client.fetch(`/interaction/${uid}/login`, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers,
|
|
125
|
+
body
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async confirmInteraction(uid, body, headers) {
|
|
129
|
+
return await this.client.fetch(`/interaction/${uid}/confirm`, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers,
|
|
132
|
+
body
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async abortInteraction(uid, headers) {
|
|
136
|
+
return await this.client.fetch(`/interaction/${uid}/abort`, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// --- OAuth grants (the user's active authorizations), served by apps/auth ---
|
|
142
|
+
async listOauthGrants(headers) {
|
|
143
|
+
return await this.client.fetch(`/oauth2/grants`, {
|
|
144
|
+
method: "GET",
|
|
145
|
+
headers
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async revokeOauthGrant(id, headers) {
|
|
149
|
+
return await this.client.fetch(`/oauth2/grants/${id}`, {
|
|
150
|
+
method: "DELETE",
|
|
151
|
+
headers
|
|
152
|
+
});
|
|
153
|
+
}
|
|
114
154
|
}
|
|
115
155
|
|
|
116
156
|
export { Auth };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpTypes } from '@pear-protocol/types';
|
|
2
2
|
import { HttpClient } from '../http.js';
|
|
3
3
|
import { ClientHeaders } from '../types.js';
|
|
4
|
+
import '@pear-protocol/utils';
|
|
4
5
|
|
|
5
6
|
declare class Core {
|
|
6
7
|
private client;
|
|
@@ -204,7 +205,6 @@ declare class Core {
|
|
|
204
205
|
executions: {
|
|
205
206
|
list: (query: HttpTypes.ExecutionListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
206
207
|
limit: number;
|
|
207
|
-
nextCursor: string | undefined;
|
|
208
208
|
executions: ({
|
|
209
209
|
id: string;
|
|
210
210
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -348,6 +348,152 @@ declare class Core {
|
|
|
348
348
|
filledPrice?: string | undefined;
|
|
349
349
|
}[] | undefined;
|
|
350
350
|
})[];
|
|
351
|
+
nextCursor?: string | undefined;
|
|
352
|
+
}>;
|
|
353
|
+
get: (id: string, headers?: ClientHeaders) => Promise<{
|
|
354
|
+
execution: {
|
|
355
|
+
id: string;
|
|
356
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
357
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
358
|
+
createdAt: string;
|
|
359
|
+
updatedAt: string;
|
|
360
|
+
intent: "OPEN";
|
|
361
|
+
orderType: "MARKET";
|
|
362
|
+
legs: [{
|
|
363
|
+
symbol: string;
|
|
364
|
+
side: "BUY" | "SELL";
|
|
365
|
+
mode: "QUANTITY" | "USD";
|
|
366
|
+
amount: string;
|
|
367
|
+
reduceOnly: boolean;
|
|
368
|
+
}, ...{
|
|
369
|
+
symbol: string;
|
|
370
|
+
side: "BUY" | "SELL";
|
|
371
|
+
mode: "QUANTITY" | "USD";
|
|
372
|
+
amount: string;
|
|
373
|
+
reduceOnly: boolean;
|
|
374
|
+
}[]];
|
|
375
|
+
error?: string | undefined;
|
|
376
|
+
orders?: {
|
|
377
|
+
id: string;
|
|
378
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
379
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
380
|
+
createdAt: string;
|
|
381
|
+
updatedAt: string;
|
|
382
|
+
type: "MARKET";
|
|
383
|
+
symbol: string;
|
|
384
|
+
side: "BUY" | "SELL";
|
|
385
|
+
reduceOnly: boolean;
|
|
386
|
+
leverage: number;
|
|
387
|
+
quantity: string;
|
|
388
|
+
price: string;
|
|
389
|
+
filledQuantity: string;
|
|
390
|
+
error?: string | undefined;
|
|
391
|
+
filledPrice?: string | undefined;
|
|
392
|
+
}[] | undefined;
|
|
393
|
+
} | {
|
|
394
|
+
id: string;
|
|
395
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
396
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
397
|
+
createdAt: string;
|
|
398
|
+
updatedAt: string;
|
|
399
|
+
intent: "ADJUST";
|
|
400
|
+
orderType: "MARKET";
|
|
401
|
+
position: {
|
|
402
|
+
id: string;
|
|
403
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
404
|
+
};
|
|
405
|
+
legs: [{
|
|
406
|
+
symbol: string;
|
|
407
|
+
side: "BUY" | "SELL";
|
|
408
|
+
mode: "QUANTITY" | "USD";
|
|
409
|
+
amount: string;
|
|
410
|
+
reduceOnly: boolean;
|
|
411
|
+
}, ...{
|
|
412
|
+
symbol: string;
|
|
413
|
+
side: "BUY" | "SELL";
|
|
414
|
+
mode: "QUANTITY" | "USD";
|
|
415
|
+
amount: string;
|
|
416
|
+
reduceOnly: boolean;
|
|
417
|
+
}[]];
|
|
418
|
+
error?: string | undefined;
|
|
419
|
+
orders?: {
|
|
420
|
+
id: string;
|
|
421
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
422
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
423
|
+
createdAt: string;
|
|
424
|
+
updatedAt: string;
|
|
425
|
+
type: "MARKET";
|
|
426
|
+
symbol: string;
|
|
427
|
+
side: "BUY" | "SELL";
|
|
428
|
+
reduceOnly: boolean;
|
|
429
|
+
leverage: number;
|
|
430
|
+
quantity: string;
|
|
431
|
+
price: string;
|
|
432
|
+
filledQuantity: string;
|
|
433
|
+
error?: string | undefined;
|
|
434
|
+
filledPrice?: string | undefined;
|
|
435
|
+
}[] | undefined;
|
|
436
|
+
} | {
|
|
437
|
+
id: string;
|
|
438
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
439
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
440
|
+
createdAt: string;
|
|
441
|
+
updatedAt: string;
|
|
442
|
+
intent: "CLOSE";
|
|
443
|
+
orderType: "MARKET";
|
|
444
|
+
position: {
|
|
445
|
+
id: string;
|
|
446
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
447
|
+
};
|
|
448
|
+
error?: string | undefined;
|
|
449
|
+
orders?: {
|
|
450
|
+
id: string;
|
|
451
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
452
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
453
|
+
createdAt: string;
|
|
454
|
+
updatedAt: string;
|
|
455
|
+
type: "MARKET";
|
|
456
|
+
symbol: string;
|
|
457
|
+
side: "BUY" | "SELL";
|
|
458
|
+
reduceOnly: boolean;
|
|
459
|
+
leverage: number;
|
|
460
|
+
quantity: string;
|
|
461
|
+
price: string;
|
|
462
|
+
filledQuantity: string;
|
|
463
|
+
error?: string | undefined;
|
|
464
|
+
filledPrice?: string | undefined;
|
|
465
|
+
}[] | undefined;
|
|
466
|
+
} | {
|
|
467
|
+
id: string;
|
|
468
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
469
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
470
|
+
createdAt: string;
|
|
471
|
+
updatedAt: string;
|
|
472
|
+
intent: "REVERSE";
|
|
473
|
+
orderType: "MARKET";
|
|
474
|
+
position: {
|
|
475
|
+
id: string;
|
|
476
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
477
|
+
};
|
|
478
|
+
error?: string | undefined;
|
|
479
|
+
orders?: {
|
|
480
|
+
id: string;
|
|
481
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
482
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
483
|
+
createdAt: string;
|
|
484
|
+
updatedAt: string;
|
|
485
|
+
type: "MARKET";
|
|
486
|
+
symbol: string;
|
|
487
|
+
side: "BUY" | "SELL";
|
|
488
|
+
reduceOnly: boolean;
|
|
489
|
+
leverage: number;
|
|
490
|
+
quantity: string;
|
|
491
|
+
price: string;
|
|
492
|
+
filledQuantity: string;
|
|
493
|
+
error?: string | undefined;
|
|
494
|
+
filledPrice?: string | undefined;
|
|
495
|
+
}[] | undefined;
|
|
496
|
+
};
|
|
351
497
|
}>;
|
|
352
498
|
};
|
|
353
499
|
fills: {
|
|
@@ -379,7 +525,6 @@ declare class Core {
|
|
|
379
525
|
}>;
|
|
380
526
|
list: (query: HttpTypes.FillListParams, headers?: ClientHeaders) => Promise<{
|
|
381
527
|
limit: number;
|
|
382
|
-
nextCursor: string | undefined;
|
|
383
528
|
fills: {
|
|
384
529
|
id: string;
|
|
385
530
|
status: "PROVISIONAL" | "CONFIRMED" | "RECONCILED";
|
|
@@ -404,6 +549,7 @@ declare class Core {
|
|
|
404
549
|
quantity: string;
|
|
405
550
|
} | undefined;
|
|
406
551
|
}[];
|
|
552
|
+
nextCursor?: string | undefined;
|
|
407
553
|
}>;
|
|
408
554
|
provisionals: (headers?: ClientHeaders) => Promise<{
|
|
409
555
|
fills: {
|
|
@@ -426,7 +572,6 @@ declare class Core {
|
|
|
426
572
|
ladders: {
|
|
427
573
|
list: (query: HttpTypes.LadderListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
428
574
|
limit: number;
|
|
429
|
-
nextCursor: string | undefined;
|
|
430
575
|
ladders: {
|
|
431
576
|
id: string;
|
|
432
577
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -859,6 +1004,7 @@ declare class Core {
|
|
|
859
1004
|
createdAt: string;
|
|
860
1005
|
updatedAt: string;
|
|
861
1006
|
}[];
|
|
1007
|
+
nextCursor?: string | undefined;
|
|
862
1008
|
}>;
|
|
863
1009
|
create: (body: HttpTypes.CreateLadder, headers?: ClientHeaders) => Promise<{
|
|
864
1010
|
ladder: {
|
|
@@ -1893,7 +2039,6 @@ declare class Core {
|
|
|
1893
2039
|
positions: {
|
|
1894
2040
|
list: (query: HttpTypes.PositionListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
1895
2041
|
limit: number;
|
|
1896
|
-
nextCursor: string | undefined;
|
|
1897
2042
|
positions: {
|
|
1898
2043
|
id: string;
|
|
1899
2044
|
tradeAccountId: string;
|
|
@@ -1903,11 +2048,13 @@ declare class Core {
|
|
|
1903
2048
|
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
1904
2049
|
totalFundingPayment: Record<string, `-${string}` | `+${string}`>;
|
|
1905
2050
|
initialExposureUSD: Record<string, `-${string}` | `+${string}`>;
|
|
2051
|
+
entryPrices: Record<string, string>;
|
|
1906
2052
|
createdAt: string;
|
|
1907
2053
|
updatedAt: string;
|
|
1908
2054
|
closedReason?: "USER" | "NETTED" | "LIQUIDATED" | null | undefined;
|
|
1909
2055
|
closedAt?: string | null | undefined;
|
|
1910
2056
|
}[];
|
|
2057
|
+
nextCursor?: string | undefined;
|
|
1911
2058
|
}>;
|
|
1912
2059
|
openLite: (headers?: ClientHeaders) => Promise<{
|
|
1913
2060
|
positions: {
|
|
@@ -2115,7 +2262,6 @@ declare class Core {
|
|
|
2115
2262
|
auto: {
|
|
2116
2263
|
list: (query?: HttpTypes.AutoRebalanceListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2117
2264
|
limit: number;
|
|
2118
|
-
nextCursor: string | undefined;
|
|
2119
2265
|
items: {
|
|
2120
2266
|
id: string;
|
|
2121
2267
|
positionId: string;
|
|
@@ -2126,6 +2272,7 @@ declare class Core {
|
|
|
2126
2272
|
updatedAt: string;
|
|
2127
2273
|
timeframe?: "1d" | "1h" | "4h" | undefined;
|
|
2128
2274
|
}[];
|
|
2275
|
+
nextCursor?: string | undefined;
|
|
2129
2276
|
}>;
|
|
2130
2277
|
create: (body: HttpTypes.CreateAutoRebalanceConfig, headers?: ClientHeaders) => Promise<{
|
|
2131
2278
|
config: {
|
|
@@ -2155,7 +2302,6 @@ declare class Core {
|
|
|
2155
2302
|
};
|
|
2156
2303
|
listEvents: (positionId: string, query?: HttpTypes.RebalanceEventListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2157
2304
|
limit: number;
|
|
2158
|
-
nextCursor: string | undefined;
|
|
2159
2305
|
items: {
|
|
2160
2306
|
id: string;
|
|
2161
2307
|
autoRebalanceConfigId: string;
|
|
@@ -2168,6 +2314,7 @@ declare class Core {
|
|
|
2168
2314
|
createdAt: string;
|
|
2169
2315
|
error?: string | undefined;
|
|
2170
2316
|
}[];
|
|
2317
|
+
nextCursor?: string | undefined;
|
|
2171
2318
|
}>;
|
|
2172
2319
|
};
|
|
2173
2320
|
savedBaskets: {
|
|
@@ -2227,7 +2374,6 @@ declare class Core {
|
|
|
2227
2374
|
schedules: {
|
|
2228
2375
|
list: (query: HttpTypes.ScheduleListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2229
2376
|
limit: number;
|
|
2230
|
-
nextCursor: string | undefined;
|
|
2231
2377
|
schedules: ({
|
|
2232
2378
|
id: string;
|
|
2233
2379
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -2323,6 +2469,7 @@ declare class Core {
|
|
|
2323
2469
|
} | undefined;
|
|
2324
2470
|
}[] | undefined;
|
|
2325
2471
|
})[];
|
|
2472
|
+
nextCursor?: string | undefined;
|
|
2326
2473
|
}>;
|
|
2327
2474
|
create: (body: HttpTypes.CreateSchedule, headers?: ClientHeaders) => Promise<{
|
|
2328
2475
|
schedule: {
|
|
@@ -3179,7 +3326,6 @@ declare class Core {
|
|
|
3179
3326
|
triggers: {
|
|
3180
3327
|
list: (query: HttpTypes.TriggerListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
3181
3328
|
limit: number;
|
|
3182
|
-
nextCursor: string | undefined;
|
|
3183
3329
|
triggers: ({
|
|
3184
3330
|
id: string;
|
|
3185
3331
|
tradeAccountId: string;
|
|
@@ -3598,6 +3744,7 @@ declare class Core {
|
|
|
3598
3744
|
stopBreachedAt?: number | undefined;
|
|
3599
3745
|
} | undefined;
|
|
3600
3746
|
})[];
|
|
3747
|
+
nextCursor?: string | undefined;
|
|
3601
3748
|
}>;
|
|
3602
3749
|
open: (body: HttpTypes.CreateTriggerOpen, headers?: ClientHeaders) => Promise<{
|
|
3603
3750
|
trigger: {
|
package/dist/core/index.js
CHANGED
package/dist/external/kalshi.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { proxyFetch } from '@pear-protocol/utils';
|
|
2
|
+
|
|
1
3
|
const BASE_URL = "https://api.elections.kalshi.com";
|
|
2
4
|
const BATCH_SIZE = 100;
|
|
3
5
|
async function fetchKalshiMarketNames(tickers) {
|
|
@@ -7,7 +9,7 @@ async function fetchKalshiMarketNames(tickers) {
|
|
|
7
9
|
const url = new URL(`${BASE_URL}/trade-api/v2/markets`);
|
|
8
10
|
url.searchParams.set("tickers", batch.join(","));
|
|
9
11
|
url.searchParams.set("limit", String(BATCH_SIZE));
|
|
10
|
-
const response = await
|
|
12
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
11
13
|
if (!response.ok) throw new Error(`Kalshi API error: ${response.status} ${response.statusText}`);
|
|
12
14
|
const data = await response.json();
|
|
13
15
|
for (const m of data.markets ?? []) result.set(m.ticker, m.title);
|
|
@@ -22,7 +24,7 @@ async function searchKalshiTriggers(params = {}) {
|
|
|
22
24
|
if (params.category) url.searchParams.set("category", params.category);
|
|
23
25
|
if (params.search) url.searchParams.set("query", params.search);
|
|
24
26
|
if (params.cursor) url.searchParams.set("cursor", params.cursor);
|
|
25
|
-
const response = await
|
|
27
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
26
28
|
if (!response.ok) return { triggers: [], nextCursor: null };
|
|
27
29
|
const data = await response.json();
|
|
28
30
|
return {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { proxyFetch } from '@pear-protocol/utils';
|
|
2
|
+
|
|
1
3
|
const BASE_URL = "https://gamma-api.polymarket.com";
|
|
2
4
|
const BATCH_SIZE = 100;
|
|
3
5
|
async function fetchPolymarketMarketNames(ids) {
|
|
@@ -7,7 +9,7 @@ async function fetchPolymarketMarketNames(ids) {
|
|
|
7
9
|
const url = new URL(`${BASE_URL}/markets`);
|
|
8
10
|
for (const id of batch) url.searchParams.append("id", id);
|
|
9
11
|
url.searchParams.set("limit", String(BATCH_SIZE));
|
|
10
|
-
const response = await
|
|
12
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
11
13
|
if (!response.ok) throw new Error(`Polymarket API error: ${response.status} ${response.statusText}`);
|
|
12
14
|
const data = await response.json();
|
|
13
15
|
for (const m of data) result.set(m.id, m.question ?? m.groupItemTitle ?? "");
|
|
@@ -23,7 +25,7 @@ async function searchPolymarketTriggers(params = {}) {
|
|
|
23
25
|
if (params.search) url.searchParams.set("title_search", params.search);
|
|
24
26
|
if (params.category) url.searchParams.set("tag_slug", params.category);
|
|
25
27
|
if (params.cursor) url.searchParams.set("after_cursor", params.cursor);
|
|
26
|
-
const response = await
|
|
28
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
27
29
|
if (!response.ok) return { triggers: [], nextCursor: null };
|
|
28
30
|
const data = await response.json();
|
|
29
31
|
const events = data.events ?? [];
|
package/dist/http.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { External } from './external/index.js';
|
|
|
5
5
|
import { SDKConfig } from './types.js';
|
|
6
6
|
export { ExternalTrigger, ExternalTriggerSource, HttpTypes, SearchTriggersParams, SearchTriggersResponse, TriggerOutcome } from '@pear-protocol/types';
|
|
7
7
|
export * from '@pear-protocol/utils';
|
|
8
|
+
export { FetchError } from './utils.js';
|
|
8
9
|
import './http.js';
|
|
9
10
|
|
|
10
11
|
declare class PearSDK {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { configureProxy } from '@pear-protocol/utils';
|
|
2
|
+
export * from '@pear-protocol/utils';
|
|
1
3
|
import { Admin } from './admin';
|
|
2
4
|
import { Auth } from './auth';
|
|
3
5
|
import { Core } from './core';
|
|
@@ -5,7 +7,7 @@ import { External } from './external';
|
|
|
5
7
|
export { External } from './external';
|
|
6
8
|
import { HttpClient } from './http';
|
|
7
9
|
import { FetchError } from './utils';
|
|
8
|
-
export
|
|
10
|
+
export { FetchError } from './utils';
|
|
9
11
|
|
|
10
12
|
const SESSION_REFRESH_PATH = "/auth/session/refresh";
|
|
11
13
|
const SESSION_REFRESH_TIMEOUT_MS = 15e3;
|
|
@@ -35,6 +37,7 @@ class PearSDK {
|
|
|
35
37
|
core;
|
|
36
38
|
external;
|
|
37
39
|
constructor(config) {
|
|
40
|
+
if (config.proxy) configureProxy(config.proxy);
|
|
38
41
|
const authMode = config.auth?.type ?? "session";
|
|
39
42
|
const logger = config.logger ?? {
|
|
40
43
|
error: console.error,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpTypes } from '@pear-protocol/types';
|
|
2
|
+
import { ProxyConfig } from '@pear-protocol/utils';
|
|
2
3
|
|
|
3
4
|
type AuthMode = 'session' | 'bearer' | 'apikey';
|
|
4
5
|
type SDKConfig = {
|
|
@@ -88,6 +89,14 @@ type SDKConfig = {
|
|
|
88
89
|
* Example: true
|
|
89
90
|
*/
|
|
90
91
|
debug?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Optional forward-proxy for the SDK's external HTTP calls (prediction-market data). When
|
|
94
|
+
* enabled, requests are re-pointed at `proxy.url` with the original host in `X-Proxy-Target`.
|
|
95
|
+
* Injected here because the SDK also runs in the browser, where env vars are unavailable.
|
|
96
|
+
*
|
|
97
|
+
* Example: { enabled: true, url: 'http://proxy.internal:8080' }
|
|
98
|
+
*/
|
|
99
|
+
proxy?: ProxyConfig;
|
|
91
100
|
};
|
|
92
101
|
type Logger = {
|
|
93
102
|
error: (...messages: string[]) => void;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FetchArgs, AuthMode } from './types.js';
|
|
2
2
|
import '@pear-protocol/types';
|
|
3
|
+
import '@pear-protocol/utils';
|
|
3
4
|
|
|
4
5
|
declare function getBaseUrl(passedBaseUrl: string): string;
|
|
5
6
|
declare function normalizeRequest(init: FetchArgs | undefined, headers: Headers, authMode: AuthMode): RequestInit | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/core-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Pear Protocol Core SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"typecheck": "tsc --noEmit"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pear-protocol/types": "^1.
|
|
31
|
-
"@pear-protocol/utils": "^0.
|
|
30
|
+
"@pear-protocol/types": "^1.11.0",
|
|
31
|
+
"@pear-protocol/utils": "^0.2.0",
|
|
32
32
|
"qs": "^6.14.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|