@0xsequence/userdata 3.0.0-beta.4
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE +202 -0
- package/README.md +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/userdata.gen.d.ts +231 -0
- package/dist/userdata.gen.d.ts.map +1 -0
- package/dist/userdata.gen.js +579 -0
- package/package.json +28 -0
- package/src/index.ts +36 -0
- package/src/userdata.gen.ts +686 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// userdata v0.1.0 99a19ff0218eda6f5e544642d0fd72f66736bdaf
|
|
4
|
+
// --
|
|
5
|
+
// Code generated by Webrpc-gen@v0.30.2 with typescript generator. DO NOT EDIT.
|
|
6
|
+
//
|
|
7
|
+
// webrpc-gen -schema=userdata.ridl -target=typescript -client -out=./clients/userdata.gen.ts
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WebrpcHeaderValue = exports.WebrpcHeader = exports.webrpcErrorByCode = exports.WebrpcErrorCodes = exports.errors = exports.UnsupportedNetworkError = exports.NotFoundError = exports.QueryFailedError = exports.UnavailableError = exports.InvalidArgumentError = exports.ProjectNotFoundError = exports.RateLimitedError = exports.GeoblockedError = exports.AbortedError = exports.RequestConflictError = exports.MethodNotFoundError = exports.SessionExpiredError = exports.PermissionDeniedError = exports.UnauthorizedError = exports.WebrpcStreamFinishedError = exports.WebrpcStreamLostError = exports.WebrpcClientAbortedError = exports.WebrpcInternalErrorError = exports.WebrpcServerPanicError = exports.WebrpcBadResponseError = exports.WebrpcBadRequestError = exports.WebrpcBadMethodError = exports.WebrpcBadRouteError = exports.WebrpcRequestFailedError = exports.WebrpcEndpointError = exports.WebrpcError = exports.JsonDecode = exports.JsonEncode = exports.UserData = exports.WebrpcSchemaHash = exports.WebrpcSchemaVersion = exports.WebrpcVersion = void 0;
|
|
10
|
+
exports.VersionFromHeader = VersionFromHeader;
|
|
11
|
+
// Webrpc description and code-gen version
|
|
12
|
+
exports.WebrpcVersion = 'v1';
|
|
13
|
+
// Schema version of your RIDL schema
|
|
14
|
+
exports.WebrpcSchemaVersion = 'v0.1.0';
|
|
15
|
+
// Schema hash generated from your RIDL schema
|
|
16
|
+
exports.WebrpcSchemaHash = '99a19ff0218eda6f5e544642d0fd72f66736bdaf';
|
|
17
|
+
//
|
|
18
|
+
// Client
|
|
19
|
+
//
|
|
20
|
+
class UserData {
|
|
21
|
+
hostname;
|
|
22
|
+
fetch;
|
|
23
|
+
path = '/rpc/UserData/';
|
|
24
|
+
constructor(hostname, fetch) {
|
|
25
|
+
this.hostname = hostname.replace(/\/*$/, '');
|
|
26
|
+
this.fetch = (input, init) => fetch(input, init);
|
|
27
|
+
}
|
|
28
|
+
url(name) {
|
|
29
|
+
return this.hostname + this.path + name;
|
|
30
|
+
}
|
|
31
|
+
queryKey = {
|
|
32
|
+
getCapabilities: () => ['UserData', 'getCapabilities'],
|
|
33
|
+
getAccessToken: (req) => ['UserData', 'getAccessToken', req],
|
|
34
|
+
getIdentityToken: (req) => ['UserData', 'getIdentityToken', req],
|
|
35
|
+
};
|
|
36
|
+
getCapabilities = (headers, signal) => {
|
|
37
|
+
return this.fetch(this.url('GetCapabilities'), createHttpRequest('{}', headers, signal)).then((res) => {
|
|
38
|
+
return buildResponse(res).then((_data) => {
|
|
39
|
+
return (0, exports.JsonDecode)(_data, 'GetCapabilitiesResponse');
|
|
40
|
+
});
|
|
41
|
+
}, (error) => {
|
|
42
|
+
throw WebrpcRequestFailedError.new({
|
|
43
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
getAccessToken = (req, headers, signal) => {
|
|
48
|
+
return this.fetch(this.url('GetAccessToken'), createHttpRequest((0, exports.JsonEncode)(req, 'GetAccessTokenRequest'), headers, signal)).then((res) => {
|
|
49
|
+
return buildResponse(res).then((_data) => {
|
|
50
|
+
return (0, exports.JsonDecode)(_data, 'GetAccessTokenResponse');
|
|
51
|
+
});
|
|
52
|
+
}, (error) => {
|
|
53
|
+
throw WebrpcRequestFailedError.new({
|
|
54
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
getIdentityToken = (req, headers, signal) => {
|
|
59
|
+
return this.fetch(this.url('GetIdentityToken'), createHttpRequest((0, exports.JsonEncode)(req, 'GetIdentityTokenRequest'), headers, signal)).then((res) => {
|
|
60
|
+
return buildResponse(res).then((_data) => {
|
|
61
|
+
return (0, exports.JsonDecode)(_data, 'GetIdentityTokenResponse');
|
|
62
|
+
});
|
|
63
|
+
}, (error) => {
|
|
64
|
+
throw WebrpcRequestFailedError.new({
|
|
65
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.UserData = UserData;
|
|
71
|
+
const createHttpRequest = (body = '{}', headers = {}, signal = null) => {
|
|
72
|
+
const reqHeaders = { ...headers, 'Content-Type': 'application/json' };
|
|
73
|
+
return { method: 'POST', headers: reqHeaders, body, signal };
|
|
74
|
+
};
|
|
75
|
+
const buildResponse = (res) => {
|
|
76
|
+
return res.text().then((text) => {
|
|
77
|
+
let data;
|
|
78
|
+
try {
|
|
79
|
+
data = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw WebrpcBadResponseError.new({
|
|
83
|
+
status: res.status,
|
|
84
|
+
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
const code = typeof data.code === 'number' ? data.code : 0;
|
|
89
|
+
throw (exports.webrpcErrorByCode[code] || WebrpcError).new(data);
|
|
90
|
+
}
|
|
91
|
+
return data;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const JsonEncode = (obj, _typ = '') => {
|
|
95
|
+
return JSON.stringify(obj);
|
|
96
|
+
};
|
|
97
|
+
exports.JsonEncode = JsonEncode;
|
|
98
|
+
const JsonDecode = (data, _typ = '') => {
|
|
99
|
+
let parsed = data;
|
|
100
|
+
if (typeof data === 'string') {
|
|
101
|
+
try {
|
|
102
|
+
parsed = JSON.parse(data);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${err.message}` });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return parsed;
|
|
109
|
+
};
|
|
110
|
+
exports.JsonDecode = JsonDecode;
|
|
111
|
+
class WebrpcError extends Error {
|
|
112
|
+
code;
|
|
113
|
+
status;
|
|
114
|
+
constructor(error = {}) {
|
|
115
|
+
super(error.message);
|
|
116
|
+
this.name = error.name || 'WebrpcEndpointError';
|
|
117
|
+
this.code = typeof error.code === 'number' ? error.code : 0;
|
|
118
|
+
this.message = error.message || `endpoint error`;
|
|
119
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
120
|
+
if (error.cause !== undefined)
|
|
121
|
+
this.cause = error.cause;
|
|
122
|
+
Object.setPrototypeOf(this, WebrpcError.prototype);
|
|
123
|
+
}
|
|
124
|
+
static new(payload) {
|
|
125
|
+
return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.WebrpcError = WebrpcError;
|
|
129
|
+
class WebrpcEndpointError extends WebrpcError {
|
|
130
|
+
constructor(error = {}) {
|
|
131
|
+
super(error);
|
|
132
|
+
this.name = error.name || 'WebrpcEndpoint';
|
|
133
|
+
this.code = typeof error.code === 'number' ? error.code : 0;
|
|
134
|
+
this.message = error.message || `endpoint error`;
|
|
135
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
136
|
+
if (error.cause !== undefined)
|
|
137
|
+
this.cause = error.cause;
|
|
138
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.WebrpcEndpointError = WebrpcEndpointError;
|
|
142
|
+
class WebrpcRequestFailedError extends WebrpcError {
|
|
143
|
+
constructor(error = {}) {
|
|
144
|
+
super(error);
|
|
145
|
+
this.name = error.name || 'WebrpcRequestFailed';
|
|
146
|
+
this.code = typeof error.code === 'number' ? error.code : -1;
|
|
147
|
+
this.message = error.message || `request failed`;
|
|
148
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
149
|
+
if (error.cause !== undefined)
|
|
150
|
+
this.cause = error.cause;
|
|
151
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.WebrpcRequestFailedError = WebrpcRequestFailedError;
|
|
155
|
+
class WebrpcBadRouteError extends WebrpcError {
|
|
156
|
+
constructor(error = {}) {
|
|
157
|
+
super(error);
|
|
158
|
+
this.name = error.name || 'WebrpcBadRoute';
|
|
159
|
+
this.code = typeof error.code === 'number' ? error.code : -2;
|
|
160
|
+
this.message = error.message || `bad route`;
|
|
161
|
+
this.status = typeof error.status === 'number' ? error.status : 404;
|
|
162
|
+
if (error.cause !== undefined)
|
|
163
|
+
this.cause = error.cause;
|
|
164
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.WebrpcBadRouteError = WebrpcBadRouteError;
|
|
168
|
+
class WebrpcBadMethodError extends WebrpcError {
|
|
169
|
+
constructor(error = {}) {
|
|
170
|
+
super(error);
|
|
171
|
+
this.name = error.name || 'WebrpcBadMethod';
|
|
172
|
+
this.code = typeof error.code === 'number' ? error.code : -3;
|
|
173
|
+
this.message = error.message || `bad method`;
|
|
174
|
+
this.status = typeof error.status === 'number' ? error.status : 405;
|
|
175
|
+
if (error.cause !== undefined)
|
|
176
|
+
this.cause = error.cause;
|
|
177
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.WebrpcBadMethodError = WebrpcBadMethodError;
|
|
181
|
+
class WebrpcBadRequestError extends WebrpcError {
|
|
182
|
+
constructor(error = {}) {
|
|
183
|
+
super(error);
|
|
184
|
+
this.name = error.name || 'WebrpcBadRequest';
|
|
185
|
+
this.code = typeof error.code === 'number' ? error.code : -4;
|
|
186
|
+
this.message = error.message || `bad request`;
|
|
187
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
188
|
+
if (error.cause !== undefined)
|
|
189
|
+
this.cause = error.cause;
|
|
190
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.WebrpcBadRequestError = WebrpcBadRequestError;
|
|
194
|
+
class WebrpcBadResponseError extends WebrpcError {
|
|
195
|
+
constructor(error = {}) {
|
|
196
|
+
super(error);
|
|
197
|
+
this.name = error.name || 'WebrpcBadResponse';
|
|
198
|
+
this.code = typeof error.code === 'number' ? error.code : -5;
|
|
199
|
+
this.message = error.message || `bad response`;
|
|
200
|
+
this.status = typeof error.status === 'number' ? error.status : 500;
|
|
201
|
+
if (error.cause !== undefined)
|
|
202
|
+
this.cause = error.cause;
|
|
203
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.WebrpcBadResponseError = WebrpcBadResponseError;
|
|
207
|
+
class WebrpcServerPanicError extends WebrpcError {
|
|
208
|
+
constructor(error = {}) {
|
|
209
|
+
super(error);
|
|
210
|
+
this.name = error.name || 'WebrpcServerPanic';
|
|
211
|
+
this.code = typeof error.code === 'number' ? error.code : -6;
|
|
212
|
+
this.message = error.message || `server panic`;
|
|
213
|
+
this.status = typeof error.status === 'number' ? error.status : 500;
|
|
214
|
+
if (error.cause !== undefined)
|
|
215
|
+
this.cause = error.cause;
|
|
216
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.WebrpcServerPanicError = WebrpcServerPanicError;
|
|
220
|
+
class WebrpcInternalErrorError extends WebrpcError {
|
|
221
|
+
constructor(error = {}) {
|
|
222
|
+
super(error);
|
|
223
|
+
this.name = error.name || 'WebrpcInternalError';
|
|
224
|
+
this.code = typeof error.code === 'number' ? error.code : -7;
|
|
225
|
+
this.message = error.message || `internal error`;
|
|
226
|
+
this.status = typeof error.status === 'number' ? error.status : 500;
|
|
227
|
+
if (error.cause !== undefined)
|
|
228
|
+
this.cause = error.cause;
|
|
229
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.WebrpcInternalErrorError = WebrpcInternalErrorError;
|
|
233
|
+
class WebrpcClientAbortedError extends WebrpcError {
|
|
234
|
+
constructor(error = {}) {
|
|
235
|
+
super(error);
|
|
236
|
+
this.name = error.name || 'WebrpcClientAborted';
|
|
237
|
+
this.code = typeof error.code === 'number' ? error.code : -8;
|
|
238
|
+
this.message = error.message || `request aborted by client`;
|
|
239
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
240
|
+
if (error.cause !== undefined)
|
|
241
|
+
this.cause = error.cause;
|
|
242
|
+
Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.WebrpcClientAbortedError = WebrpcClientAbortedError;
|
|
246
|
+
class WebrpcStreamLostError extends WebrpcError {
|
|
247
|
+
constructor(error = {}) {
|
|
248
|
+
super(error);
|
|
249
|
+
this.name = error.name || 'WebrpcStreamLost';
|
|
250
|
+
this.code = typeof error.code === 'number' ? error.code : -9;
|
|
251
|
+
this.message = error.message || `stream lost`;
|
|
252
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
253
|
+
if (error.cause !== undefined)
|
|
254
|
+
this.cause = error.cause;
|
|
255
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.WebrpcStreamLostError = WebrpcStreamLostError;
|
|
259
|
+
class WebrpcStreamFinishedError extends WebrpcError {
|
|
260
|
+
constructor(error = {}) {
|
|
261
|
+
super(error);
|
|
262
|
+
this.name = error.name || 'WebrpcStreamFinished';
|
|
263
|
+
this.code = typeof error.code === 'number' ? error.code : -10;
|
|
264
|
+
this.message = error.message || `stream finished`;
|
|
265
|
+
this.status = typeof error.status === 'number' ? error.status : 200;
|
|
266
|
+
if (error.cause !== undefined)
|
|
267
|
+
this.cause = error.cause;
|
|
268
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.WebrpcStreamFinishedError = WebrpcStreamFinishedError;
|
|
272
|
+
//
|
|
273
|
+
// Schema errors
|
|
274
|
+
//
|
|
275
|
+
class UnauthorizedError extends WebrpcError {
|
|
276
|
+
constructor(error = {}) {
|
|
277
|
+
super(error);
|
|
278
|
+
this.name = error.name || 'Unauthorized';
|
|
279
|
+
this.code = typeof error.code === 'number' ? error.code : 1000;
|
|
280
|
+
this.message = error.message || `Unauthorized access`;
|
|
281
|
+
this.status = typeof error.status === 'number' ? error.status : 401;
|
|
282
|
+
if (error.cause !== undefined)
|
|
283
|
+
this.cause = error.cause;
|
|
284
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
288
|
+
class PermissionDeniedError extends WebrpcError {
|
|
289
|
+
constructor(error = {}) {
|
|
290
|
+
super(error);
|
|
291
|
+
this.name = error.name || 'PermissionDenied';
|
|
292
|
+
this.code = typeof error.code === 'number' ? error.code : 1001;
|
|
293
|
+
this.message = error.message || `Permission denied`;
|
|
294
|
+
this.status = typeof error.status === 'number' ? error.status : 403;
|
|
295
|
+
if (error.cause !== undefined)
|
|
296
|
+
this.cause = error.cause;
|
|
297
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
301
|
+
class SessionExpiredError extends WebrpcError {
|
|
302
|
+
constructor(error = {}) {
|
|
303
|
+
super(error);
|
|
304
|
+
this.name = error.name || 'SessionExpired';
|
|
305
|
+
this.code = typeof error.code === 'number' ? error.code : 1002;
|
|
306
|
+
this.message = error.message || `Session expired`;
|
|
307
|
+
this.status = typeof error.status === 'number' ? error.status : 403;
|
|
308
|
+
if (error.cause !== undefined)
|
|
309
|
+
this.cause = error.cause;
|
|
310
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
exports.SessionExpiredError = SessionExpiredError;
|
|
314
|
+
class MethodNotFoundError extends WebrpcError {
|
|
315
|
+
constructor(error = {}) {
|
|
316
|
+
super(error);
|
|
317
|
+
this.name = error.name || 'MethodNotFound';
|
|
318
|
+
this.code = typeof error.code === 'number' ? error.code : 1003;
|
|
319
|
+
this.message = error.message || `Method not found`;
|
|
320
|
+
this.status = typeof error.status === 'number' ? error.status : 404;
|
|
321
|
+
if (error.cause !== undefined)
|
|
322
|
+
this.cause = error.cause;
|
|
323
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.MethodNotFoundError = MethodNotFoundError;
|
|
327
|
+
class RequestConflictError extends WebrpcError {
|
|
328
|
+
constructor(error = {}) {
|
|
329
|
+
super(error);
|
|
330
|
+
this.name = error.name || 'RequestConflict';
|
|
331
|
+
this.code = typeof error.code === 'number' ? error.code : 1004;
|
|
332
|
+
this.message = error.message || `Conflict with target resource`;
|
|
333
|
+
this.status = typeof error.status === 'number' ? error.status : 409;
|
|
334
|
+
if (error.cause !== undefined)
|
|
335
|
+
this.cause = error.cause;
|
|
336
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
exports.RequestConflictError = RequestConflictError;
|
|
340
|
+
class AbortedError extends WebrpcError {
|
|
341
|
+
constructor(error = {}) {
|
|
342
|
+
super(error);
|
|
343
|
+
this.name = error.name || 'Aborted';
|
|
344
|
+
this.code = typeof error.code === 'number' ? error.code : 1005;
|
|
345
|
+
this.message = error.message || `Request aborted`;
|
|
346
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
347
|
+
if (error.cause !== undefined)
|
|
348
|
+
this.cause = error.cause;
|
|
349
|
+
Object.setPrototypeOf(this, AbortedError.prototype);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
exports.AbortedError = AbortedError;
|
|
353
|
+
class GeoblockedError extends WebrpcError {
|
|
354
|
+
constructor(error = {}) {
|
|
355
|
+
super(error);
|
|
356
|
+
this.name = error.name || 'Geoblocked';
|
|
357
|
+
this.code = typeof error.code === 'number' ? error.code : 1006;
|
|
358
|
+
this.message = error.message || `Geoblocked region`;
|
|
359
|
+
this.status = typeof error.status === 'number' ? error.status : 451;
|
|
360
|
+
if (error.cause !== undefined)
|
|
361
|
+
this.cause = error.cause;
|
|
362
|
+
Object.setPrototypeOf(this, GeoblockedError.prototype);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
exports.GeoblockedError = GeoblockedError;
|
|
366
|
+
class RateLimitedError extends WebrpcError {
|
|
367
|
+
constructor(error = {}) {
|
|
368
|
+
super(error);
|
|
369
|
+
this.name = error.name || 'RateLimited';
|
|
370
|
+
this.code = typeof error.code === 'number' ? error.code : 1007;
|
|
371
|
+
this.message = error.message || `Rate-limited. Please slow down.`;
|
|
372
|
+
this.status = typeof error.status === 'number' ? error.status : 429;
|
|
373
|
+
if (error.cause !== undefined)
|
|
374
|
+
this.cause = error.cause;
|
|
375
|
+
Object.setPrototypeOf(this, RateLimitedError.prototype);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.RateLimitedError = RateLimitedError;
|
|
379
|
+
class ProjectNotFoundError extends WebrpcError {
|
|
380
|
+
constructor(error = {}) {
|
|
381
|
+
super(error);
|
|
382
|
+
this.name = error.name || 'ProjectNotFound';
|
|
383
|
+
this.code = typeof error.code === 'number' ? error.code : 1008;
|
|
384
|
+
this.message = error.message || `Project not found`;
|
|
385
|
+
this.status = typeof error.status === 'number' ? error.status : 401;
|
|
386
|
+
if (error.cause !== undefined)
|
|
387
|
+
this.cause = error.cause;
|
|
388
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
exports.ProjectNotFoundError = ProjectNotFoundError;
|
|
392
|
+
class InvalidArgumentError extends WebrpcError {
|
|
393
|
+
constructor(error = {}) {
|
|
394
|
+
super(error);
|
|
395
|
+
this.name = error.name || 'InvalidArgument';
|
|
396
|
+
this.code = typeof error.code === 'number' ? error.code : 2000;
|
|
397
|
+
this.message = error.message || `Invalid argument`;
|
|
398
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
399
|
+
if (error.cause !== undefined)
|
|
400
|
+
this.cause = error.cause;
|
|
401
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
405
|
+
class UnavailableError extends WebrpcError {
|
|
406
|
+
constructor(error = {}) {
|
|
407
|
+
super(error);
|
|
408
|
+
this.name = error.name || 'Unavailable';
|
|
409
|
+
this.code = typeof error.code === 'number' ? error.code : 2002;
|
|
410
|
+
this.message = error.message || `Unavailable resource`;
|
|
411
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
412
|
+
if (error.cause !== undefined)
|
|
413
|
+
this.cause = error.cause;
|
|
414
|
+
Object.setPrototypeOf(this, UnavailableError.prototype);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
exports.UnavailableError = UnavailableError;
|
|
418
|
+
class QueryFailedError extends WebrpcError {
|
|
419
|
+
constructor(error = {}) {
|
|
420
|
+
super(error);
|
|
421
|
+
this.name = error.name || 'QueryFailed';
|
|
422
|
+
this.code = typeof error.code === 'number' ? error.code : 2003;
|
|
423
|
+
this.message = error.message || `Query failed`;
|
|
424
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
425
|
+
if (error.cause !== undefined)
|
|
426
|
+
this.cause = error.cause;
|
|
427
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
exports.QueryFailedError = QueryFailedError;
|
|
431
|
+
class NotFoundError extends WebrpcError {
|
|
432
|
+
constructor(error = {}) {
|
|
433
|
+
super(error);
|
|
434
|
+
this.name = error.name || 'NotFound';
|
|
435
|
+
this.code = typeof error.code === 'number' ? error.code : 3000;
|
|
436
|
+
this.message = error.message || `Resource not found`;
|
|
437
|
+
this.status = typeof error.status === 'number' ? error.status : 400;
|
|
438
|
+
if (error.cause !== undefined)
|
|
439
|
+
this.cause = error.cause;
|
|
440
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
exports.NotFoundError = NotFoundError;
|
|
444
|
+
class UnsupportedNetworkError extends WebrpcError {
|
|
445
|
+
constructor(error = {}) {
|
|
446
|
+
super(error);
|
|
447
|
+
this.name = error.name || 'UnsupportedNetwork';
|
|
448
|
+
this.code = typeof error.code === 'number' ? error.code : 3008;
|
|
449
|
+
this.message = error.message || `Unsupported network`;
|
|
450
|
+
this.status = typeof error.status === 'number' ? error.status : 422;
|
|
451
|
+
if (error.cause !== undefined)
|
|
452
|
+
this.cause = error.cause;
|
|
453
|
+
Object.setPrototypeOf(this, UnsupportedNetworkError.prototype);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
exports.UnsupportedNetworkError = UnsupportedNetworkError;
|
|
457
|
+
var errors;
|
|
458
|
+
(function (errors) {
|
|
459
|
+
errors["WebrpcEndpoint"] = "WebrpcEndpoint";
|
|
460
|
+
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
|
|
461
|
+
errors["WebrpcBadRoute"] = "WebrpcBadRoute";
|
|
462
|
+
errors["WebrpcBadMethod"] = "WebrpcBadMethod";
|
|
463
|
+
errors["WebrpcBadRequest"] = "WebrpcBadRequest";
|
|
464
|
+
errors["WebrpcBadResponse"] = "WebrpcBadResponse";
|
|
465
|
+
errors["WebrpcServerPanic"] = "WebrpcServerPanic";
|
|
466
|
+
errors["WebrpcInternalError"] = "WebrpcInternalError";
|
|
467
|
+
errors["WebrpcClientAborted"] = "WebrpcClientAborted";
|
|
468
|
+
errors["WebrpcStreamLost"] = "WebrpcStreamLost";
|
|
469
|
+
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
|
|
470
|
+
errors["Unauthorized"] = "Unauthorized";
|
|
471
|
+
errors["PermissionDenied"] = "PermissionDenied";
|
|
472
|
+
errors["SessionExpired"] = "SessionExpired";
|
|
473
|
+
errors["MethodNotFound"] = "MethodNotFound";
|
|
474
|
+
errors["RequestConflict"] = "RequestConflict";
|
|
475
|
+
errors["Aborted"] = "Aborted";
|
|
476
|
+
errors["Geoblocked"] = "Geoblocked";
|
|
477
|
+
errors["RateLimited"] = "RateLimited";
|
|
478
|
+
errors["ProjectNotFound"] = "ProjectNotFound";
|
|
479
|
+
errors["InvalidArgument"] = "InvalidArgument";
|
|
480
|
+
errors["Unavailable"] = "Unavailable";
|
|
481
|
+
errors["QueryFailed"] = "QueryFailed";
|
|
482
|
+
errors["NotFound"] = "NotFound";
|
|
483
|
+
errors["UnsupportedNetwork"] = "UnsupportedNetwork";
|
|
484
|
+
})(errors || (exports.errors = errors = {}));
|
|
485
|
+
var WebrpcErrorCodes;
|
|
486
|
+
(function (WebrpcErrorCodes) {
|
|
487
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcEndpoint"] = 0] = "WebrpcEndpoint";
|
|
488
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcRequestFailed"] = -1] = "WebrpcRequestFailed";
|
|
489
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRoute"] = -2] = "WebrpcBadRoute";
|
|
490
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadMethod"] = -3] = "WebrpcBadMethod";
|
|
491
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRequest"] = -4] = "WebrpcBadRequest";
|
|
492
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadResponse"] = -5] = "WebrpcBadResponse";
|
|
493
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcServerPanic"] = -6] = "WebrpcServerPanic";
|
|
494
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcInternalError"] = -7] = "WebrpcInternalError";
|
|
495
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcClientAborted"] = -8] = "WebrpcClientAborted";
|
|
496
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamLost"] = -9] = "WebrpcStreamLost";
|
|
497
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamFinished"] = -10] = "WebrpcStreamFinished";
|
|
498
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Unauthorized"] = 1000] = "Unauthorized";
|
|
499
|
+
WebrpcErrorCodes[WebrpcErrorCodes["PermissionDenied"] = 1001] = "PermissionDenied";
|
|
500
|
+
WebrpcErrorCodes[WebrpcErrorCodes["SessionExpired"] = 1002] = "SessionExpired";
|
|
501
|
+
WebrpcErrorCodes[WebrpcErrorCodes["MethodNotFound"] = 1003] = "MethodNotFound";
|
|
502
|
+
WebrpcErrorCodes[WebrpcErrorCodes["RequestConflict"] = 1004] = "RequestConflict";
|
|
503
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Aborted"] = 1005] = "Aborted";
|
|
504
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Geoblocked"] = 1006] = "Geoblocked";
|
|
505
|
+
WebrpcErrorCodes[WebrpcErrorCodes["RateLimited"] = 1007] = "RateLimited";
|
|
506
|
+
WebrpcErrorCodes[WebrpcErrorCodes["ProjectNotFound"] = 1008] = "ProjectNotFound";
|
|
507
|
+
WebrpcErrorCodes[WebrpcErrorCodes["InvalidArgument"] = 2000] = "InvalidArgument";
|
|
508
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Unavailable"] = 2002] = "Unavailable";
|
|
509
|
+
WebrpcErrorCodes[WebrpcErrorCodes["QueryFailed"] = 2003] = "QueryFailed";
|
|
510
|
+
WebrpcErrorCodes[WebrpcErrorCodes["NotFound"] = 3000] = "NotFound";
|
|
511
|
+
WebrpcErrorCodes[WebrpcErrorCodes["UnsupportedNetwork"] = 3008] = "UnsupportedNetwork";
|
|
512
|
+
})(WebrpcErrorCodes || (exports.WebrpcErrorCodes = WebrpcErrorCodes = {}));
|
|
513
|
+
exports.webrpcErrorByCode = {
|
|
514
|
+
[0]: WebrpcEndpointError,
|
|
515
|
+
[-1]: WebrpcRequestFailedError,
|
|
516
|
+
[-2]: WebrpcBadRouteError,
|
|
517
|
+
[-3]: WebrpcBadMethodError,
|
|
518
|
+
[-4]: WebrpcBadRequestError,
|
|
519
|
+
[-5]: WebrpcBadResponseError,
|
|
520
|
+
[-6]: WebrpcServerPanicError,
|
|
521
|
+
[-7]: WebrpcInternalErrorError,
|
|
522
|
+
[-8]: WebrpcClientAbortedError,
|
|
523
|
+
[-9]: WebrpcStreamLostError,
|
|
524
|
+
[-10]: WebrpcStreamFinishedError,
|
|
525
|
+
[1000]: UnauthorizedError,
|
|
526
|
+
[1001]: PermissionDeniedError,
|
|
527
|
+
[1002]: SessionExpiredError,
|
|
528
|
+
[1003]: MethodNotFoundError,
|
|
529
|
+
[1004]: RequestConflictError,
|
|
530
|
+
[1005]: AbortedError,
|
|
531
|
+
[1006]: GeoblockedError,
|
|
532
|
+
[1007]: RateLimitedError,
|
|
533
|
+
[1008]: ProjectNotFoundError,
|
|
534
|
+
[2000]: InvalidArgumentError,
|
|
535
|
+
[2002]: UnavailableError,
|
|
536
|
+
[2003]: QueryFailedError,
|
|
537
|
+
[3000]: NotFoundError,
|
|
538
|
+
[3008]: UnsupportedNetworkError,
|
|
539
|
+
};
|
|
540
|
+
//
|
|
541
|
+
// Webrpc
|
|
542
|
+
//
|
|
543
|
+
exports.WebrpcHeader = 'Webrpc';
|
|
544
|
+
exports.WebrpcHeaderValue = 'webrpc@v0.30.2;gen-typescript@v0.22.2;userdata@v0.1.0';
|
|
545
|
+
function VersionFromHeader(headers) {
|
|
546
|
+
const headerValue = headers.get(exports.WebrpcHeader);
|
|
547
|
+
if (!headerValue) {
|
|
548
|
+
return {
|
|
549
|
+
WebrpcGenVersion: '',
|
|
550
|
+
codeGenName: '',
|
|
551
|
+
codeGenVersion: '',
|
|
552
|
+
schemaName: '',
|
|
553
|
+
schemaVersion: '',
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return parseWebrpcGenVersions(headerValue);
|
|
557
|
+
}
|
|
558
|
+
function parseWebrpcGenVersions(header) {
|
|
559
|
+
const versions = header.split(';');
|
|
560
|
+
if (versions.length < 3) {
|
|
561
|
+
return {
|
|
562
|
+
WebrpcGenVersion: '',
|
|
563
|
+
codeGenName: '',
|
|
564
|
+
codeGenVersion: '',
|
|
565
|
+
schemaName: '',
|
|
566
|
+
schemaVersion: '',
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
const [_, WebrpcGenVersion] = versions[0].split('@');
|
|
570
|
+
const [codeGenName, codeGenVersion] = versions[1].split('@');
|
|
571
|
+
const [schemaName, schemaVersion] = versions[2].split('@');
|
|
572
|
+
return {
|
|
573
|
+
WebrpcGenVersion: WebrpcGenVersion ?? '',
|
|
574
|
+
codeGenName: codeGenName ?? '',
|
|
575
|
+
codeGenVersion: codeGenVersion ?? '',
|
|
576
|
+
schemaName: schemaName ?? '',
|
|
577
|
+
schemaVersion: schemaVersion ?? '',
|
|
578
|
+
};
|
|
579
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xsequence/userdata",
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
|
+
"description": "userdata sub-package for Sequence",
|
|
5
|
+
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/services/userdata",
|
|
6
|
+
"author": "Sequence Platforms Inc.",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^24.10.1",
|
|
19
|
+
"typescript": "^5.9.3",
|
|
20
|
+
"@repo/typescript-config": "^0.0.0-20251211205330"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"dev": "tsc --watch",
|
|
25
|
+
"test": "echo",
|
|
26
|
+
"typecheck": "tsc --noEmit"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from './userdata.gen'
|
|
2
|
+
|
|
3
|
+
import { UserData as UserdataRpc } from './userdata.gen'
|
|
4
|
+
|
|
5
|
+
export class SequenceUserdataClient extends UserdataRpc {
|
|
6
|
+
constructor(
|
|
7
|
+
hostname: string,
|
|
8
|
+
public projectAccessKey?: string,
|
|
9
|
+
public jwtAuth?: string,
|
|
10
|
+
) {
|
|
11
|
+
super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch)
|
|
12
|
+
this.fetch = this._fetch
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
|
|
16
|
+
// automatically include jwt and access key auth header to requests
|
|
17
|
+
// if its been set on the api client
|
|
18
|
+
const headers: { [key: string]: any } = {}
|
|
19
|
+
|
|
20
|
+
const jwtAuth = this.jwtAuth
|
|
21
|
+
const projectAccessKey = this.projectAccessKey
|
|
22
|
+
|
|
23
|
+
if (jwtAuth && jwtAuth.length > 0) {
|
|
24
|
+
headers['Authorization'] = `BEARER ${jwtAuth}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
|
28
|
+
headers['X-Access-Key'] = projectAccessKey
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// before the request is made
|
|
32
|
+
init!.headers = { ...init!.headers, ...headers }
|
|
33
|
+
|
|
34
|
+
return fetch(input, init)
|
|
35
|
+
}
|
|
36
|
+
}
|