@chainstream-io/sdk 0.1.5 → 0.1.7

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.
Files changed (147) hide show
  1. package/README.md +46 -0
  2. package/dist/esm/index.d.ts +1 -1
  3. package/dist/esm/index.js +76 -60
  4. package/dist/esm/openapi/apis/BlockchainApi.js +61 -44
  5. package/dist/esm/openapi/apis/DefiSolanaMoonshotApi.js +67 -50
  6. package/dist/esm/openapi/apis/DefiSolanaPumpfunApi.js +38 -25
  7. package/dist/esm/openapi/apis/DexApi.js +205 -176
  8. package/dist/esm/openapi/apis/DexPoolApi.js +41 -28
  9. package/dist/esm/openapi/apis/EndpointApi.js +212 -175
  10. package/dist/esm/openapi/apis/IpfsApi.js +38 -25
  11. package/dist/esm/openapi/apis/JobsApi.js +65 -48
  12. package/dist/esm/openapi/apis/RankingApi.js +278 -249
  13. package/dist/esm/openapi/apis/RedPacketApi.js +294 -253
  14. package/dist/esm/openapi/apis/TokenApi.js +1145 -1056
  15. package/dist/esm/openapi/apis/TradeApi.js +233 -208
  16. package/dist/esm/openapi/apis/TransactionApi.js +42 -29
  17. package/dist/esm/openapi/apis/WalletApi.js +148 -123
  18. package/dist/esm/openapi/apis/WatchlistApi.js +41 -28
  19. package/dist/esm/openapi/runtime.js +81 -69
  20. package/dist/esm/stream/index.d.ts +3 -0
  21. package/dist/esm/stream/index.js +3 -0
  22. package/dist/esm/{api → stream}/stream.js +36 -29
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +75 -59
  25. package/dist/openapi/apis/BlockchainApi.js +62 -78
  26. package/dist/openapi/apis/DefiSolanaMoonshotApi.js +68 -84
  27. package/dist/openapi/apis/DefiSolanaPumpfunApi.js +39 -59
  28. package/dist/openapi/apis/DexApi.js +206 -210
  29. package/dist/openapi/apis/DexPoolApi.js +42 -62
  30. package/dist/openapi/apis/EndpointApi.js +213 -209
  31. package/dist/openapi/apis/IpfsApi.js +39 -59
  32. package/dist/openapi/apis/JobsApi.js +66 -82
  33. package/dist/openapi/apis/RankingApi.js +279 -283
  34. package/dist/openapi/apis/RedPacketApi.js +295 -287
  35. package/dist/openapi/apis/TokenApi.js +1146 -1090
  36. package/dist/openapi/apis/TradeApi.js +234 -242
  37. package/dist/openapi/apis/TransactionApi.js +43 -63
  38. package/dist/openapi/apis/WalletApi.js +149 -157
  39. package/dist/openapi/apis/WatchlistApi.js +42 -62
  40. package/dist/openapi/runtime.js +81 -69
  41. package/dist/stream/index.d.ts +3 -0
  42. package/dist/stream/index.js +19 -0
  43. package/dist/{api → stream}/stream.js +36 -29
  44. package/package.json +29 -26
  45. package/src/api/stream.fields.ts +0 -271
  46. package/src/api/stream.model.ts +0 -307
  47. package/src/api/stream.ts +0 -1086
  48. package/src/index.ts +0 -188
  49. package/src/openapi/apis/BlockchainApi.ts +0 -140
  50. package/src/openapi/apis/DefiSolanaMoonshotApi.ts +0 -145
  51. package/src/openapi/apis/DefiSolanaPumpfunApi.ts +0 -86
  52. package/src/openapi/apis/DexApi.ts +0 -490
  53. package/src/openapi/apis/DexPoolApi.ts +0 -107
  54. package/src/openapi/apis/EndpointApi.ts +0 -421
  55. package/src/openapi/apis/IpfsApi.ts +0 -66
  56. package/src/openapi/apis/JobsApi.ts +0 -135
  57. package/src/openapi/apis/RankingApi.ts +0 -939
  58. package/src/openapi/apis/RedPacketApi.ts +0 -621
  59. package/src/openapi/apis/TokenApi.ts +0 -2569
  60. package/src/openapi/apis/TradeApi.ts +0 -596
  61. package/src/openapi/apis/TransactionApi.ts +0 -95
  62. package/src/openapi/apis/WalletApi.ts +0 -365
  63. package/src/openapi/apis/WatchlistApi.ts +0 -107
  64. package/src/openapi/apis/index.ts +0 -17
  65. package/src/openapi/index.ts +0 -5
  66. package/src/openapi/models/BlockchainDTO.ts +0 -93
  67. package/src/openapi/models/BlockchainLatestBlockDTO.ts +0 -75
  68. package/src/openapi/models/BooleanResultDTO.ts +0 -66
  69. package/src/openapi/models/CalculatePnlInput.ts +0 -65
  70. package/src/openapi/models/Candle.ts +0 -130
  71. package/src/openapi/models/ClaimRedPacketInput.ts +0 -90
  72. package/src/openapi/models/CreateEndpointInput.ts +0 -121
  73. package/src/openapi/models/CreateRedPacketInput.ts +0 -124
  74. package/src/openapi/models/CreateRedPacketReply.ts +0 -75
  75. package/src/openapi/models/CreateTokenInput.ts +0 -139
  76. package/src/openapi/models/CreateTokenReply.ts +0 -75
  77. package/src/openapi/models/DexDTO.ts +0 -90
  78. package/src/openapi/models/DexPage.ts +0 -114
  79. package/src/openapi/models/DexPoolDTO.ts +0 -141
  80. package/src/openapi/models/EndpointListResponse.ts +0 -97
  81. package/src/openapi/models/EndpointOperationResponse.ts +0 -65
  82. package/src/openapi/models/EndpointResponse.ts +0 -145
  83. package/src/openapi/models/EndpointSecretResponse.ts +0 -65
  84. package/src/openapi/models/FilterCondition.ts +0 -135
  85. package/src/openapi/models/GainersAndLosersDTO.ts +0 -93
  86. package/src/openapi/models/GainersAndLosersPage.ts +0 -114
  87. package/src/openapi/models/JobDTO.ts +0 -75
  88. package/src/openapi/models/JobStreamingDTO.ts +0 -75
  89. package/src/openapi/models/Link.ts +0 -88
  90. package/src/openapi/models/MoonshotCreateTokenInput.ts +0 -182
  91. package/src/openapi/models/MoonshotCreateTokenReply.ts +0 -75
  92. package/src/openapi/models/MoonshotSubmitCreateToken200Response.ts +0 -73
  93. package/src/openapi/models/MoonshotSubmitCreateTokenInput.ts +0 -74
  94. package/src/openapi/models/PumpCreateTokenInput.ts +0 -180
  95. package/src/openapi/models/PumpCreateTokenReply.ts +0 -74
  96. package/src/openapi/models/QuoteResponse.ts +0 -105
  97. package/src/openapi/models/RedPacketClaimDTO.ts +0 -148
  98. package/src/openapi/models/RedPacketClaimsPage.ts +0 -110
  99. package/src/openapi/models/RedPacketDTO.ts +0 -229
  100. package/src/openapi/models/RedPacketReply.ts +0 -66
  101. package/src/openapi/models/RedPacketSendTxInput.ts +0 -66
  102. package/src/openapi/models/RedPacketSendTxResponse.ts +0 -66
  103. package/src/openapi/models/RedPacketsPage.ts +0 -110
  104. package/src/openapi/models/Resolution.ts +0 -61
  105. package/src/openapi/models/SendTxInput.ts +0 -93
  106. package/src/openapi/models/SendTxResponse.ts +0 -84
  107. package/src/openapi/models/SwapInput.ts +0 -157
  108. package/src/openapi/models/SwapReply.ts +0 -75
  109. package/src/openapi/models/SwapRouteInput.ts +0 -186
  110. package/src/openapi/models/SwapRouteResponse.ts +0 -101
  111. package/src/openapi/models/Token.ts +0 -251
  112. package/src/openapi/models/TokenCreationDTO.ts +0 -131
  113. package/src/openapi/models/TokenCreationPage.ts +0 -114
  114. package/src/openapi/models/TokenCreatorsDTO.ts +0 -81
  115. package/src/openapi/models/TokenExtraDTO.ts +0 -225
  116. package/src/openapi/models/TokenHolder.ts +0 -93
  117. package/src/openapi/models/TokenHolderPage.ts +0 -114
  118. package/src/openapi/models/TokenListPage.ts +0 -114
  119. package/src/openapi/models/TokenMarketData.ts +0 -190
  120. package/src/openapi/models/TokenMetadata.ts +0 -188
  121. package/src/openapi/models/TokenPage.ts +0 -122
  122. package/src/openapi/models/TokenPriceDTO.ts +0 -93
  123. package/src/openapi/models/TokenPricePage.ts +0 -114
  124. package/src/openapi/models/TokenSocialMediasDTO.ts +0 -161
  125. package/src/openapi/models/TokenStat.ts +0 -1152
  126. package/src/openapi/models/TopTradersDTO.ts +0 -164
  127. package/src/openapi/models/TopTradersPage.ts +0 -114
  128. package/src/openapi/models/TradeDetailDTO.ts +0 -282
  129. package/src/openapi/models/TradeEvent.ts +0 -184
  130. package/src/openapi/models/TradePage.ts +0 -114
  131. package/src/openapi/models/TradeType.ts +0 -53
  132. package/src/openapi/models/UpdateEndpointInput.ts +0 -129
  133. package/src/openapi/models/WalletBalanceDetailDTO.ts +0 -282
  134. package/src/openapi/models/WalletBalancesDTO.ts +0 -92
  135. package/src/openapi/models/WalletPnlDTO.ts +0 -264
  136. package/src/openapi/models/index.ts +0 -72
  137. package/src/openapi/runtime.ts +0 -432
  138. /package/dist/{api → esm/stream}/stream.d.ts +0 -0
  139. /package/dist/{api → esm/stream}/stream.fields.d.ts +0 -0
  140. /package/dist/esm/{api → stream}/stream.fields.js +0 -0
  141. /package/dist/{api → esm/stream}/stream.model.d.ts +0 -0
  142. /package/dist/esm/{api → stream}/stream.model.js +0 -0
  143. /package/dist/{esm/api → stream}/stream.d.ts +0 -0
  144. /package/dist/{esm/api → stream}/stream.fields.d.ts +0 -0
  145. /package/dist/{api → stream}/stream.fields.js +0 -0
  146. /package/dist/{esm/api → stream}/stream.model.d.ts +0 -0
  147. /package/dist/{api → stream}/stream.model.js +0 -0
@@ -11,6 +11,15 @@
11
11
  * https://openapi-generator.tech
12
12
  * Do not edit the class manually.
13
13
  */
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
14
23
  export const BASE_PATH = "https://api-dex.chainstream.io".replace(/\/+$/, "");
15
24
  export class Configuration {
16
25
  constructor(configuration = {}) {
@@ -47,7 +56,7 @@ export class Configuration {
47
56
  get accessToken() {
48
57
  const accessToken = this.configuration.accessToken;
49
58
  if (accessToken) {
50
- return typeof accessToken === 'function' ? accessToken : async () => accessToken;
59
+ return typeof accessToken === 'function' ? accessToken : () => __awaiter(this, void 0, void 0, function* () { return accessToken; });
51
60
  }
52
61
  return undefined;
53
62
  }
@@ -65,30 +74,27 @@ export const DefaultConfig = new Configuration();
65
74
  export class BaseAPI {
66
75
  constructor(configuration = DefaultConfig) {
67
76
  this.configuration = configuration;
68
- this.fetchApi = async (url, init) => {
77
+ this.fetchApi = (url, init) => __awaiter(this, void 0, void 0, function* () {
69
78
  let fetchParams = { url, init };
70
79
  for (const middleware of this.middleware) {
71
80
  if (middleware.pre) {
72
- fetchParams = await middleware.pre({
73
- fetch: this.fetchApi,
74
- ...fetchParams,
75
- }) || fetchParams;
81
+ fetchParams = (yield middleware.pre(Object.assign({ fetch: this.fetchApi }, fetchParams))) || fetchParams;
76
82
  }
77
83
  }
78
84
  let response = undefined;
79
85
  try {
80
- response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
86
+ response = yield (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
81
87
  }
82
88
  catch (e) {
83
89
  for (const middleware of this.middleware) {
84
90
  if (middleware.onError) {
85
- response = await middleware.onError({
91
+ response = (yield middleware.onError({
86
92
  fetch: this.fetchApi,
87
93
  url: fetchParams.url,
88
94
  init: fetchParams.init,
89
95
  error: e,
90
96
  response: response ? response.clone() : undefined,
91
- }) || response;
97
+ })) || response;
92
98
  }
93
99
  }
94
100
  if (response === undefined) {
@@ -102,16 +108,16 @@ export class BaseAPI {
102
108
  }
103
109
  for (const middleware of this.middleware) {
104
110
  if (middleware.post) {
105
- response = await middleware.post({
111
+ response = (yield middleware.post({
106
112
  fetch: this.fetchApi,
107
113
  url: fetchParams.url,
108
114
  init: fetchParams.init,
109
115
  response: response.clone(),
110
- }) || response;
116
+ })) || response;
111
117
  }
112
118
  }
113
119
  return response;
114
- };
120
+ });
115
121
  this.middleware = configuration.middleware;
116
122
  }
117
123
  withMiddleware(...middlewares) {
@@ -143,57 +149,55 @@ export class BaseAPI {
143
149
  }
144
150
  return BaseAPI.jsonRegex.test(mime);
145
151
  }
146
- async request(context, initOverrides) {
147
- const { url, init } = await this.createFetchParams(context, initOverrides);
148
- const response = await this.fetchApi(url, init);
149
- if (response && (response.status >= 200 && response.status < 300)) {
150
- return response;
151
- }
152
- throw new ResponseError(response, 'Response returned an error code');
153
- }
154
- async createFetchParams(context, initOverrides) {
155
- let url = this.configuration.basePath + context.path;
156
- if (context.query !== undefined && Object.keys(context.query).length !== 0) {
157
- // only add the querystring to the URL if there are query parameters.
158
- // this is done to avoid urls ending with a "?" character which buggy webservers
159
- // do not handle correctly sometimes.
160
- url += '?' + this.configuration.queryParamsStringify(context.query);
161
- }
162
- const headers = Object.assign({}, this.configuration.headers, context.headers);
163
- Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
164
- const initOverrideFn = typeof initOverrides === "function"
165
- ? initOverrides
166
- : async () => initOverrides;
167
- const initParams = {
168
- method: context.method,
169
- headers,
170
- body: context.body,
171
- credentials: this.configuration.credentials,
172
- };
173
- const overriddenInit = {
174
- ...initParams,
175
- ...(await initOverrideFn({
152
+ request(context, initOverrides) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const { url, init } = yield this.createFetchParams(context, initOverrides);
155
+ const response = yield this.fetchApi(url, init);
156
+ if (response && (response.status >= 200 && response.status < 300)) {
157
+ return response;
158
+ }
159
+ throw new ResponseError(response, 'Response returned an error code');
160
+ });
161
+ }
162
+ createFetchParams(context, initOverrides) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ let url = this.configuration.basePath + context.path;
165
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
166
+ // only add the querystring to the URL if there are query parameters.
167
+ // this is done to avoid urls ending with a "?" character which buggy webservers
168
+ // do not handle correctly sometimes.
169
+ url += '?' + this.configuration.queryParamsStringify(context.query);
170
+ }
171
+ const headers = Object.assign({}, this.configuration.headers, context.headers);
172
+ Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
173
+ const initOverrideFn = typeof initOverrides === "function"
174
+ ? initOverrides
175
+ : () => __awaiter(this, void 0, void 0, function* () { return initOverrides; });
176
+ const initParams = {
177
+ method: context.method,
178
+ headers,
179
+ body: context.body,
180
+ credentials: this.configuration.credentials,
181
+ };
182
+ const overriddenInit = Object.assign(Object.assign({}, initParams), (yield initOverrideFn({
176
183
  init: initParams,
177
184
  context,
178
- }))
179
- };
180
- let body;
181
- if (isFormData(overriddenInit.body)
182
- || (overriddenInit.body instanceof URLSearchParams)
183
- || isBlob(overriddenInit.body)) {
184
- body = overriddenInit.body;
185
- }
186
- else if (this.isJsonMime(headers['Content-Type'])) {
187
- body = JSON.stringify(overriddenInit.body);
188
- }
189
- else {
190
- body = overriddenInit.body;
191
- }
192
- const init = {
193
- ...overriddenInit,
194
- body
195
- };
196
- return { url, init };
185
+ })));
186
+ let body;
187
+ if (isFormData(overriddenInit.body)
188
+ || (overriddenInit.body instanceof URLSearchParams)
189
+ || isBlob(overriddenInit.body)) {
190
+ body = overriddenInit.body;
191
+ }
192
+ else if (this.isJsonMime(headers['Content-Type'])) {
193
+ body = JSON.stringify(overriddenInit.body);
194
+ }
195
+ else {
196
+ body = overriddenInit.body;
197
+ }
198
+ const init = Object.assign(Object.assign({}, overriddenInit), { body });
199
+ return { url, init };
200
+ });
197
201
  }
198
202
  /**
199
203
  * Create a shallow clone of `this` by constructing a new instance
@@ -290,24 +294,30 @@ export class JSONApiResponse {
290
294
  this.raw = raw;
291
295
  this.transformer = transformer;
292
296
  }
293
- async value() {
294
- return this.transformer(await this.raw.json());
297
+ value() {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ return this.transformer(yield this.raw.json());
300
+ });
295
301
  }
296
302
  }
297
303
  export class VoidApiResponse {
298
304
  constructor(raw) {
299
305
  this.raw = raw;
300
306
  }
301
- async value() {
302
- return undefined;
307
+ value() {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ return undefined;
310
+ });
303
311
  }
304
312
  }
305
313
  export class BlobApiResponse {
306
314
  constructor(raw) {
307
315
  this.raw = raw;
308
316
  }
309
- async value() {
310
- return await this.raw.blob();
317
+ value() {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ return yield this.raw.blob();
320
+ });
311
321
  }
312
322
  ;
313
323
  }
@@ -315,8 +325,10 @@ export class TextApiResponse {
315
325
  constructor(raw) {
316
326
  this.raw = raw;
317
327
  }
318
- async value() {
319
- return await this.raw.text();
328
+ value() {
329
+ return __awaiter(this, void 0, void 0, function* () {
330
+ return yield this.raw.text();
331
+ });
320
332
  }
321
333
  ;
322
334
  }
@@ -0,0 +1,3 @@
1
+ export * from './stream';
2
+ export * from './stream.fields';
3
+ export * from './stream.model';
@@ -0,0 +1,3 @@
1
+ export * from './stream';
2
+ export * from './stream.fields';
3
+ export * from './stream.model';
@@ -1,14 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { Centrifuge } from "@chainstream-io/centrifuge";
2
11
  import { replaceFilterFields } from "./stream.fields";
3
12
  export class StreamApi {
4
13
  constructor(context) {
5
14
  const realtimeEndpoint = context.streamUrl;
6
15
  this.realtimeClient = new Centrifuge(realtimeEndpoint, {
7
- getToken: async (_ctx) => {
16
+ getToken: (_ctx) => __awaiter(this, void 0, void 0, function* () {
8
17
  return typeof context.accessToken === "string"
9
18
  ? context.accessToken
10
- : await context.accessToken.getToken();
11
- },
19
+ : yield context.accessToken.getToken();
20
+ }),
12
21
  });
13
22
  this.realtimeClient
14
23
  .on("connected", () => {
@@ -79,10 +88,7 @@ export class StreamApi {
79
88
  console.log("[xrealtime] create new sub: ", channel);
80
89
  // Process filter expression with method-specific field mappings
81
90
  const processedFilter = filter && methodName ? replaceFilterFields(filter, methodName) : filter;
82
- sub = this.realtimeClient.newSubscription(channel, {
83
- delta: "fossil",
84
- ...(processedFilter && { filter: processedFilter }),
85
- });
91
+ sub = this.realtimeClient.newSubscription(channel, Object.assign({ delta: "fossil" }, (processedFilter && { filter: processedFilter })));
86
92
  sub
87
93
  .on("subscribed", () => {
88
94
  console.log("[xrealtime] subscribed", channel);
@@ -92,11 +98,11 @@ export class StreamApi {
92
98
  })
93
99
  .on("publication", (ctx) => {
94
100
  // console.log('[xrealtime] publication, ctx.data: ', ctx.data);
95
- listeners?.forEach((it) => it(ctx.data));
101
+ listeners === null || listeners === void 0 ? void 0 : listeners.forEach((it) => it(ctx.data));
96
102
  })
97
103
  .subscribe();
98
104
  }
99
- listeners?.add(fn);
105
+ listeners === null || listeners === void 0 ? void 0 : listeners.add(fn);
100
106
  return new StreamUnsubscrible(this, channel, fn);
101
107
  }
102
108
  unsubscribe(channel, fn) {
@@ -267,44 +273,45 @@ export class StreamApi {
267
273
  imageUrl: it.iu,
268
274
  description: it.de,
269
275
  socialMedia: (() => {
276
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
270
277
  const socialMedia = {};
271
- if (it.sm?.tw) {
278
+ if ((_a = it.sm) === null || _a === void 0 ? void 0 : _a.tw) {
272
279
  socialMedia.twitter = it.sm.tw;
273
280
  }
274
- if (it.sm?.tg) {
281
+ if ((_b = it.sm) === null || _b === void 0 ? void 0 : _b.tg) {
275
282
  socialMedia.telegram = it.sm.tg;
276
283
  }
277
- if (it.sm?.w) {
284
+ if ((_c = it.sm) === null || _c === void 0 ? void 0 : _c.w) {
278
285
  socialMedia.website = it.sm.w;
279
286
  }
280
- if (it.sm?.tt) {
287
+ if ((_d = it.sm) === null || _d === void 0 ? void 0 : _d.tt) {
281
288
  socialMedia.tiktok = it.sm.tt;
282
289
  }
283
- if (it.sm?.dc) {
290
+ if ((_e = it.sm) === null || _e === void 0 ? void 0 : _e.dc) {
284
291
  socialMedia.discord = it.sm.dc;
285
292
  }
286
- if (it.sm?.fb) {
293
+ if ((_f = it.sm) === null || _f === void 0 ? void 0 : _f.fb) {
287
294
  socialMedia.facebook = it.sm.fb;
288
295
  }
289
- if (it.sm?.gh) {
296
+ if ((_g = it.sm) === null || _g === void 0 ? void 0 : _g.gh) {
290
297
  socialMedia.github = it.sm.gh;
291
298
  }
292
- if (it.sm?.ig) {
299
+ if ((_h = it.sm) === null || _h === void 0 ? void 0 : _h.ig) {
293
300
  socialMedia.instagram = it.sm.ig;
294
301
  }
295
- if (it.sm?.li) {
302
+ if ((_j = it.sm) === null || _j === void 0 ? void 0 : _j.li) {
296
303
  socialMedia.linkedin = it.sm.li;
297
304
  }
298
- if (it.sm?.md) {
305
+ if ((_k = it.sm) === null || _k === void 0 ? void 0 : _k.md) {
299
306
  socialMedia.medium = it.sm.md;
300
307
  }
301
- if (it.sm?.rd) {
308
+ if ((_l = it.sm) === null || _l === void 0 ? void 0 : _l.rd) {
302
309
  socialMedia.reddit = it.sm.rd;
303
310
  }
304
- if (it.sm?.yt) {
311
+ if ((_m = it.sm) === null || _m === void 0 ? void 0 : _m.yt) {
305
312
  socialMedia.youtube = it.sm.yt;
306
313
  }
307
- if (it.sm?.bb) {
314
+ if ((_o = it.sm) === null || _o === void 0 ? void 0 : _o.bb) {
308
315
  socialMedia.bitbucket = it.sm.bb;
309
316
  }
310
317
  return socialMedia;
@@ -355,7 +362,7 @@ export class StreamApi {
355
362
  }
356
363
  subscribeRankingTokensLiquidity({ chain, channelType, callback, }) {
357
364
  const channel = `dex-ranking-token-general_stat_num-list:${chain}_${channelType}`;
358
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
365
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
359
366
  tokenAddress: it.a,
360
367
  metricType: it.t,
361
368
  value: it.v,
@@ -366,7 +373,7 @@ export class StreamApi {
366
373
  const channel = dex
367
374
  ? `dex-ranking-list:${chain}_${ranking_type}_${dex}`
368
375
  : `dex-ranking-list:${chain}_${ranking_type}`;
369
- return this.subscribe(channel, (data) => callback(data?.map((item) => {
376
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((item) => {
370
377
  const result = {};
371
378
  // TokenMetadata (t)
372
379
  if (item.t) {
@@ -721,7 +728,7 @@ export class StreamApi {
721
728
  }
722
729
  subscribeRankingTokensStats({ chain, channelType, callback, }) {
723
730
  const channel = `dex-ranking-token-stats-list:${chain}_${channelType}`;
724
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
731
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
725
732
  address: it.a,
726
733
  timestamp: it.t,
727
734
  buys1m: it.b1m,
@@ -792,7 +799,7 @@ export class StreamApi {
792
799
  }
793
800
  subscribeRankingTokensHolders({ chain, channelType, callback, }) {
794
801
  const channel = `dex-ranking-token-holding-list:${chain}_${channelType}`;
795
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
802
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
796
803
  tokenAddress: it.a,
797
804
  holders: it.h,
798
805
  top100Amount: this.formatScientificNotation(it.t100a),
@@ -806,7 +813,7 @@ export class StreamApi {
806
813
  }
807
814
  subscribeRankingTokensSupply({ chain, channelType, callback, }) {
808
815
  const channel = `dex-ranking-token-supply-list:${chain}_${channelType}`;
809
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
816
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
810
817
  tokenAddress: it.a,
811
818
  supply: it.s,
812
819
  marketCapInUsd: it.mc,
@@ -815,7 +822,7 @@ export class StreamApi {
815
822
  }
816
823
  subscribeRankingTokensBondingCurve({ chain, callback, }) {
817
824
  const channel = `dex-ranking-token-bounding-curve-list:${chain}_new`;
818
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
825
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
819
826
  tokenAddress: it.a,
820
827
  progressRatio: it.pr,
821
828
  }))));
@@ -898,7 +905,7 @@ export class StreamApi {
898
905
  }
899
906
  subscribeWalletPnlList({ chain, walletAddress, callback, }) {
900
907
  const channel = `dex-wallet-pnl-list:${chain}_${walletAddress}`;
901
- return this.subscribe(channel, (data) => callback(data?.map((it) => ({
908
+ return this.subscribe(channel, (data) => callback(data === null || data === void 0 ? void 0 : data.map((it) => ({
902
909
  walletAddress: it.a,
903
910
  buys: it.bs,
904
911
  buyAmount: it.ba,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StreamApi } from "./api/stream";
1
+ import { StreamApi } from "./stream";
2
2
  import { DexApi, Configuration, TransactionApi, DefiSolanaMoonshotApi, DefiSolanaPumpfunApi, DexPoolApi, TokenApi, RankingApi, TradeApi, WalletApi, RedPacketApi, IpfsApi, WatchlistApi, BlockchainApi, JobsApi } from "./openapi";
3
3
  export interface TokenProvider {
4
4
  getToken(): Promise<string> | string;
package/dist/index.js CHANGED
@@ -1,29 +1,42 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.DexClient = exports.LIB_VERSION = void 0;
4
- const stream_1 = require("./api/stream");
13
+ const stream_1 = require("./stream");
5
14
  const openapi_1 = require("./openapi");
6
15
  const event_source_polyfill_1 = require("event-source-polyfill");
7
16
  exports.LIB_VERSION = "0.1.5";
8
17
  class UserAgentMiddleware {
9
- async pre(context) {
10
- if (!context.init.headers) {
11
- context.init.headers = {};
12
- }
13
- if (context.init.headers instanceof Headers) {
14
- context.init.headers.set("User-Agent", `dex/${exports.LIB_VERSION}/javascript`);
15
- }
16
- else {
17
- context.init.headers["User-Agent"] = `dex/${exports.LIB_VERSION}/javascript`;
18
- }
18
+ pre(context) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ if (!context.init.headers) {
21
+ context.init.headers = {};
22
+ }
23
+ if (context.init.headers instanceof Headers) {
24
+ context.init.headers.set("User-Agent", `dex/${exports.LIB_VERSION}/javascript`);
25
+ }
26
+ else {
27
+ context.init.headers["User-Agent"] = `dex/${exports.LIB_VERSION}/javascript`;
28
+ }
29
+ });
19
30
  }
20
- async post(context) {
31
+ post(context) {
32
+ return __awaiter(this, void 0, void 0, function* () { });
21
33
  }
22
34
  }
23
35
  class DexClient {
24
36
  constructor(accessToken, options = {}) {
25
- const baseUrl = options.serverUrl ?? "https://api-dex.chainstream.io";
26
- const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
37
+ var _a, _b;
38
+ const baseUrl = (_a = options.serverUrl) !== null && _a !== void 0 ? _a : "https://api-dex.chainstream.io";
39
+ const streamUrl = (_b = options.streamUrl) !== null && _b !== void 0 ? _b : "wss://realtime-dex.chainstream.io/connection/websocket";
27
40
  const tokenProvider = typeof accessToken === "string"
28
41
  ? {
29
42
  getToken: () => accessToken,
@@ -33,14 +46,14 @@ class DexClient {
33
46
  const config = new openapi_1.Configuration({
34
47
  basePath: baseUrl,
35
48
  middleware: [new UserAgentMiddleware()],
36
- accessToken: async () => {
49
+ accessToken: () => __awaiter(this, void 0, void 0, function* () {
37
50
  return typeof accessToken === "string"
38
51
  ? accessToken
39
- : await accessToken.getToken();
40
- },
52
+ : yield accessToken.getToken();
53
+ }),
41
54
  headers: {
42
- 'User-Agent': `dex/${exports.LIB_VERSION}/javascript`
43
- }
55
+ "User-Agent": `dex/${exports.LIB_VERSION}/javascript`,
56
+ },
44
57
  });
45
58
  this._configuration = config;
46
59
  this.dex = new openapi_1.DexApi(config);
@@ -60,52 +73,55 @@ class DexClient {
60
73
  this.jobs = new openapi_1.JobsApi(config);
61
74
  this.stream.connect();
62
75
  }
63
- async waitForJob(jobId, timeout = 60000) {
64
- const accessToken = typeof this.requestCtx.accessToken === "string"
65
- ? this.requestCtx.accessToken
66
- : await this.requestCtx.accessToken.getToken();
67
- return new Promise((resolve, reject) => {
68
- const sse = new event_source_polyfill_1.EventSourcePolyfill(`${this.requestCtx.baseUrl}/jobs/${jobId}/streaming`, {
69
- headers: {
70
- Authorization: `Bearer ${accessToken}`,
71
- },
72
- });
73
- const timeoutId = setTimeout(() => {
74
- sse.close();
75
- reject(new Error(`Job ${jobId} timed out after ${timeout}ms`));
76
- }, timeout);
77
- sse.onmessage = (event) => {
78
- try {
79
- console.log("event.data: ", event.data);
80
- const data = JSON.parse(event.data);
81
- if (data.status === "error") {
82
- sse.close();
83
- reject(new Error(`Error: ${data.message}`));
76
+ waitForJob(jobId_1) {
77
+ return __awaiter(this, arguments, void 0, function* (jobId, timeout = 60000) {
78
+ const accessToken = typeof this.requestCtx.accessToken === "string"
79
+ ? this.requestCtx.accessToken
80
+ : yield this.requestCtx.accessToken.getToken();
81
+ return new Promise((resolve, reject) => {
82
+ const sse = new event_source_polyfill_1.EventSourcePolyfill(`${this.requestCtx.baseUrl}/jobs/${jobId}/streaming`, {
83
+ headers: {
84
+ Authorization: `Bearer ${accessToken}`,
85
+ },
86
+ });
87
+ const timeoutId = setTimeout(() => {
88
+ sse.close();
89
+ reject(new Error(`Job ${jobId} timed out after ${timeout}ms`));
90
+ }, timeout);
91
+ sse.onmessage = (event) => {
92
+ try {
93
+ console.log("event.data: ", event.data);
94
+ const data = JSON.parse(event.data);
95
+ if (data.status === "error") {
96
+ sse.close();
97
+ reject(new Error(`Error: ${data.message}`));
98
+ }
99
+ else if (data.status === "completed") {
100
+ clearTimeout(timeoutId);
101
+ sse.close();
102
+ resolve(data);
103
+ }
84
104
  }
85
- else if (data.status === "completed") {
105
+ catch (e) {
86
106
  clearTimeout(timeoutId);
87
107
  sse.close();
88
- resolve(data);
108
+ reject(new Error("Error parsing event data"));
109
+ }
110
+ };
111
+ sse.onopen = () => {
112
+ console.log("SSE connection opened");
113
+ };
114
+ sse.onerror = (error) => {
115
+ var _a;
116
+ if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("No activity within")) {
117
+ console.log("SSE reconnecting due to inactivity...");
118
+ return;
89
119
  }
90
- }
91
- catch (e) {
92
120
  clearTimeout(timeoutId);
93
121
  sse.close();
94
- reject(new Error("Error parsing event data"));
95
- }
96
- };
97
- sse.onopen = () => {
98
- console.log("SSE connection opened");
99
- };
100
- sse.onerror = (error) => {
101
- if (error.message?.includes("No activity within")) {
102
- console.log("SSE reconnecting due to inactivity...");
103
- return;
104
- }
105
- clearTimeout(timeoutId);
106
- sse.close();
107
- reject(new Error(`Error in SSE connection: ${error}`));
108
- };
122
+ reject(new Error(`Error in SSE connection: ${error}`));
123
+ };
124
+ });
109
125
  });
110
126
  }
111
127
  }