-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathindex.js.html
254 lines (236 loc) · 10.5 KB
/
index.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: index.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Helius = exports.Types = void 0;
const axios_1 = __importDefault(require("axios"));
const API_URL_V0 = "https://api.helius.xyz/v0";
const API_URL_V1 = "https://api.heliuys.xyz/v1";
exports.Types = __importStar(require("./types"));
/**
* This is the base level class for interfacing with all Helius API methods.
* @class
*/
class Helius {
/**
* Initializes Helius API client with an API key
* @constructor
* @param apiKey - API key generated at dev.helius.xyz
*/
constructor(apiKey) {
this.apiKey = apiKey;
}
/**
* Retrieves a list of all webhooks associated with the current API key
* @returns {Promise<Webhook[]>} a promise that resolves to an array of webhook objects
* @throws {Error} if there is an error calling the webhooks endpoint or if the response contains an error
*/
getAllWebhooks() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const { data } = yield axios_1.default.get(`${API_URL_V0}/webhooks?api-key=${this.apiKey}`);
return data;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error calling getWebhooks: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error calling getWebhooks: ${err}`);
}
}
});
}
/**
* Retrieves a single webhook by its ID, associated with the current API key
* @param {string} webhookID - the ID of the webhook to retrieve
* @returns {Promise<Webhook>} a promise that resolves to a webhook object
* @throws {Error} if there is an error calling the webhooks endpoint or if the response contains an error
*/
getWebhookByID(webhookID) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const { data } = yield axios_1.default.get(`${API_URL_V0}/webhooks/${webhookID}?api-key=${this.apiKey}`);
return data;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error during getWebhookByID: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error during getWebhookByID: ${err}`);
}
}
});
}
/**
* Creates a new webhook with the provided request
* @param {CreateWebhookRequest} createWebhookRequest - the request object containing the webhook information
* @returns {Promise<Webhook>} a promise that resolves to the created webhook object
* @throws {Error} if there is an error calling the webhooks endpoint or if the response contains an error
*/
createWebhook(createWebhookRequest) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const { data } = yield axios_1.default.post(`${API_URL_V0}/webhooks?api-key=${this.apiKey}`, Object.assign({}, createWebhookRequest));
return data;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error during createWebhook: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error during createWebhook: ${err}`);
}
}
});
}
/**
* Deletes a webhook by its ID
* @param {string} webhookID - the ID of the webhook to delete
* @returns {Promise<boolean>} a promise that resolves to true if the webhook was successfully deleted, or false otherwise
* @throws {Error} if there is an error calling the webhooks endpoint or if the response contains an error
*/
deleteWebhook(webhookID) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
yield axios_1.default.delete(`${API_URL_V0}/webhooks/${webhookID}?api-key=${this.apiKey}`);
return true;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error during deleteWebhook: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error during deleteWebhook: ${err}`);
}
}
});
}
/**
* Edits an existing webhook by its ID with the provided request
* @param {string} webhookID - the ID of the webhook to edit
* @param {EditWebhookRequest} editWebhookRequest - the request object containing the webhook information
* @returns {Promise<Webhook>} a promise that resolves to the edited webhook object
* @throws {Error} if there is an error calling the webhooks endpoint or if the response contains an error
*/
editWebhook(webhookID, editWebhookRequest) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const webhook = yield this.getWebhookByID(webhookID);
const { data } = yield axios_1.default.put(`${API_URL_V0}/webhooks/${webhookID}?api-key=${this.apiKey}`, Object.assign(Object.assign({}, webhook), editWebhookRequest));
return data;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error during editWebhook: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error during editWebhook: ${err}`);
}
}
});
}
/**
* Appends an array of addresses to an existing webhook by its ID
* @param {string} webhookID - the ID of the webhook to edit
* @param {string[]} newAccountAddresses - the array of addresses to be added to the webhook
* @returns {Promise<Webhook>} a promise that resolves to the edited webhook object
* @throws {Error} if there is an error calling the webhooks endpoint, if the response contains an error, or if the number of addresses exceeds 10,000
*/
appendAddressesToWebhook(webhookID, newAccountAddresses) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const webhook = yield this.getWebhookByID(webhookID);
const accountAddresses = webhook.accountAddresses.concat(newAccountAddresses);
webhook.accountAddresses = accountAddresses;
if (accountAddresses.length > 10000) {
throw new Error(`a single webhook cannot contain more than 10,000 addresses`);
}
const { data } = yield axios_1.default.put(`${API_URL_V0}/webhooks/${webhookID}?api-key=${this.apiKey}`, Object.assign({}, webhook));
return data;
}
catch (err) {
if (axios_1.default.isAxiosError(err)) {
throw new Error(`error during appendAddressesToWebhook: ${(_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error}`);
}
else {
throw new Error(`error during appendAddressesToWebhook: ${err}`);
}
}
});
}
}
exports.Helius = Helius;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Helius.html">Helius</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Wed Jan 25 2023 09:39:17 GMT-0500 (Eastern Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>