@0xsequence/builder 0.0.0-20241216114019
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +219 -0
- package/README.md +4 -0
- package/dist/0xsequence-builder.cjs.d.ts +2 -0
- package/dist/0xsequence-builder.cjs.dev.js +492 -0
- package/dist/0xsequence-builder.cjs.js +7 -0
- package/dist/0xsequence-builder.cjs.prod.js +492 -0
- package/dist/0xsequence-builder.esm.js +454 -0
- package/dist/declarations/src/builder.gen.d.ts +222 -0
- package/dist/declarations/src/index.d.ts +7 -0
- package/package.json +22 -0
- package/src/builder.gen.ts +713 -0
- package/src/index.ts +30 -0
@@ -0,0 +1,454 @@
|
|
1
|
+
function _extends() {
|
2
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
4
|
+
var source = arguments[i];
|
5
|
+
for (var key in source) {
|
6
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
7
|
+
target[key] = source[key];
|
8
|
+
}
|
9
|
+
}
|
10
|
+
}
|
11
|
+
return target;
|
12
|
+
};
|
13
|
+
return _extends.apply(this, arguments);
|
14
|
+
}
|
15
|
+
|
16
|
+
/* eslint-disable */
|
17
|
+
// NOTE: this is just a subset of the builder api to scope down the
|
18
|
+
// surface area of the client.
|
19
|
+
//
|
20
|
+
// In the future we can include additional interfaces as needed.
|
21
|
+
const WebrpcHeader = 'Webrpc';
|
22
|
+
const WebrpcHeaderValue = 'webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-builder@v0.1.0';
|
23
|
+
|
24
|
+
// WebRPC description and code-gen version
|
25
|
+
const WebRPCVersion = 'v1';
|
26
|
+
|
27
|
+
// Schema version of your RIDL schema
|
28
|
+
const WebRPCSchemaVersion = 'v0.1.0';
|
29
|
+
|
30
|
+
// Schema hash generated from your RIDL schema
|
31
|
+
const WebRPCSchemaHash = '5b580e1afeb26e0b4a8ee026271e2466760da0aa';
|
32
|
+
function VersionFromHeader(headers) {
|
33
|
+
const headerValue = headers.get(WebrpcHeader);
|
34
|
+
if (!headerValue) {
|
35
|
+
return {
|
36
|
+
webrpcGenVersion: '',
|
37
|
+
codeGenName: '',
|
38
|
+
codeGenVersion: '',
|
39
|
+
schemaName: '',
|
40
|
+
schemaVersion: ''
|
41
|
+
};
|
42
|
+
}
|
43
|
+
return parseWebrpcGenVersions(headerValue);
|
44
|
+
}
|
45
|
+
function parseWebrpcGenVersions(header) {
|
46
|
+
const versions = header.split(';');
|
47
|
+
if (versions.length < 3) {
|
48
|
+
return {
|
49
|
+
webrpcGenVersion: '',
|
50
|
+
codeGenName: '',
|
51
|
+
codeGenVersion: '',
|
52
|
+
schemaName: '',
|
53
|
+
schemaVersion: ''
|
54
|
+
};
|
55
|
+
}
|
56
|
+
const [_, webrpcGenVersion] = versions[0].split('@');
|
57
|
+
const [codeGenName, codeGenVersion] = versions[1].split('@');
|
58
|
+
const [schemaName, schemaVersion] = versions[2].split('@');
|
59
|
+
return {
|
60
|
+
webrpcGenVersion,
|
61
|
+
codeGenName,
|
62
|
+
codeGenVersion,
|
63
|
+
schemaName,
|
64
|
+
schemaVersion
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
//
|
69
|
+
// Types
|
70
|
+
//
|
71
|
+
|
72
|
+
//
|
73
|
+
// Client
|
74
|
+
//
|
75
|
+
class Builder {
|
76
|
+
constructor(hostname, fetch) {
|
77
|
+
this.hostname = void 0;
|
78
|
+
this.fetch = void 0;
|
79
|
+
this.path = '/rpc/Builder/';
|
80
|
+
this.ping = (headers, signal) => {
|
81
|
+
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(res => {
|
82
|
+
return buildResponse(res).then(_data => {
|
83
|
+
return {
|
84
|
+
status: _data.status
|
85
|
+
};
|
86
|
+
});
|
87
|
+
}, error => {
|
88
|
+
throw WebrpcRequestFailedError.new({
|
89
|
+
cause: `fetch(): ${error.message || ''}`
|
90
|
+
});
|
91
|
+
});
|
92
|
+
};
|
93
|
+
this.registerAudienceContact = (args, headers, signal) => {
|
94
|
+
return this.fetch(this.url('RegisterAudienceContact'), createHTTPRequest(args, headers, signal)).then(res => {
|
95
|
+
return buildResponse(res).then(_data => {
|
96
|
+
return {
|
97
|
+
ok: _data.ok
|
98
|
+
};
|
99
|
+
});
|
100
|
+
}, error => {
|
101
|
+
throw WebrpcRequestFailedError.new({
|
102
|
+
cause: `fetch(): ${error.message || ''}`
|
103
|
+
});
|
104
|
+
});
|
105
|
+
};
|
106
|
+
this.getRegisteredAudienceContact = (args, headers, signal) => {
|
107
|
+
return this.fetch(this.url('GetRegisteredAudienceContact'), createHTTPRequest(args, headers, signal)).then(res => {
|
108
|
+
return buildResponse(res).then(_data => {
|
109
|
+
return {
|
110
|
+
contact: _data.contact
|
111
|
+
};
|
112
|
+
});
|
113
|
+
}, error => {
|
114
|
+
throw WebrpcRequestFailedError.new({
|
115
|
+
cause: `fetch(): ${error.message || ''}`
|
116
|
+
});
|
117
|
+
});
|
118
|
+
};
|
119
|
+
this.getAudienceRegistrationPublicStatus = (args, headers, signal) => {
|
120
|
+
return this.fetch(this.url('GetAudienceRegistrationPublicStatus'), createHTTPRequest(args, headers, signal)).then(res => {
|
121
|
+
return buildResponse(res).then(_data => {
|
122
|
+
return {
|
123
|
+
status: _data.status
|
124
|
+
};
|
125
|
+
});
|
126
|
+
}, error => {
|
127
|
+
throw WebrpcRequestFailedError.new({
|
128
|
+
cause: `fetch(): ${error.message || ''}`
|
129
|
+
});
|
130
|
+
});
|
131
|
+
};
|
132
|
+
this.isAudienceContactRegistered = (args, headers, signal) => {
|
133
|
+
return this.fetch(this.url('IsAudienceContactRegistered'), createHTTPRequest(args, headers, signal)).then(res => {
|
134
|
+
return buildResponse(res).then(_data => {
|
135
|
+
return {
|
136
|
+
registered: _data.registered
|
137
|
+
};
|
138
|
+
});
|
139
|
+
}, error => {
|
140
|
+
throw WebrpcRequestFailedError.new({
|
141
|
+
cause: `fetch(): ${error.message || ''}`
|
142
|
+
});
|
143
|
+
});
|
144
|
+
};
|
145
|
+
this.hostname = hostname.replace(/\/*$/, '');
|
146
|
+
this.fetch = (input, init) => fetch(input, init);
|
147
|
+
}
|
148
|
+
url(name) {
|
149
|
+
return this.hostname + this.path + name;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
const createHTTPRequest = (body = {}, headers = {}, signal = null) => {
|
153
|
+
const reqHeaders = _extends({}, headers, {
|
154
|
+
'Content-Type': 'application/json'
|
155
|
+
});
|
156
|
+
reqHeaders[WebrpcHeader] = WebrpcHeaderValue;
|
157
|
+
return {
|
158
|
+
method: 'POST',
|
159
|
+
headers: reqHeaders,
|
160
|
+
body: JSON.stringify(body || {}),
|
161
|
+
signal
|
162
|
+
};
|
163
|
+
};
|
164
|
+
const buildResponse = res => {
|
165
|
+
return res.text().then(text => {
|
166
|
+
let data;
|
167
|
+
try {
|
168
|
+
data = JSON.parse(text);
|
169
|
+
} catch (error) {
|
170
|
+
let message = '';
|
171
|
+
if (error instanceof Error) {
|
172
|
+
message = error.message;
|
173
|
+
}
|
174
|
+
throw WebrpcBadResponseError.new({
|
175
|
+
status: res.status,
|
176
|
+
cause: `JSON.parse(): ${message}: response text: ${text}`
|
177
|
+
});
|
178
|
+
}
|
179
|
+
if (!res.ok) {
|
180
|
+
const code = typeof data.code === 'number' ? data.code : 0;
|
181
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data);
|
182
|
+
}
|
183
|
+
return data;
|
184
|
+
});
|
185
|
+
};
|
186
|
+
|
187
|
+
//
|
188
|
+
// Errors
|
189
|
+
//
|
190
|
+
|
191
|
+
class WebrpcError extends Error {
|
192
|
+
constructor(name, code, message, status, cause) {
|
193
|
+
super(message);
|
194
|
+
this.name = void 0;
|
195
|
+
this.code = void 0;
|
196
|
+
this.message = void 0;
|
197
|
+
this.status = void 0;
|
198
|
+
this.cause = void 0;
|
199
|
+
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
|
200
|
+
this.msg = void 0;
|
201
|
+
this.name = name || 'WebrpcError';
|
202
|
+
this.code = typeof code === 'number' ? code : 0;
|
203
|
+
this.message = message || `endpoint error ${this.code}`;
|
204
|
+
this.msg = this.message;
|
205
|
+
this.status = typeof status === 'number' ? status : 0;
|
206
|
+
this.cause = cause;
|
207
|
+
Object.setPrototypeOf(this, WebrpcError.prototype);
|
208
|
+
}
|
209
|
+
static new(payload) {
|
210
|
+
return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
// Webrpc errors
|
215
|
+
|
216
|
+
class WebrpcEndpointError extends WebrpcError {
|
217
|
+
constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) {
|
218
|
+
super(name, code, message, status, cause);
|
219
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
class WebrpcRequestFailedError extends WebrpcError {
|
223
|
+
constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) {
|
224
|
+
super(name, code, message, status, cause);
|
225
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
class WebrpcBadRouteError extends WebrpcError {
|
229
|
+
constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) {
|
230
|
+
super(name, code, message, status, cause);
|
231
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
|
232
|
+
}
|
233
|
+
}
|
234
|
+
class WebrpcBadMethodError extends WebrpcError {
|
235
|
+
constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) {
|
236
|
+
super(name, code, message, status, cause);
|
237
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
class WebrpcBadRequestError extends WebrpcError {
|
241
|
+
constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) {
|
242
|
+
super(name, code, message, status, cause);
|
243
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
class WebrpcBadResponseError extends WebrpcError {
|
247
|
+
constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) {
|
248
|
+
super(name, code, message, status, cause);
|
249
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
|
250
|
+
}
|
251
|
+
}
|
252
|
+
class WebrpcServerPanicError extends WebrpcError {
|
253
|
+
constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) {
|
254
|
+
super(name, code, message, status, cause);
|
255
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
class WebrpcInternalErrorError extends WebrpcError {
|
259
|
+
constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) {
|
260
|
+
super(name, code, message, status, cause);
|
261
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
class WebrpcClientDisconnectedError extends WebrpcError {
|
265
|
+
constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) {
|
266
|
+
super(name, code, message, status, cause);
|
267
|
+
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
class WebrpcStreamLostError extends WebrpcError {
|
271
|
+
constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) {
|
272
|
+
super(name, code, message, status, cause);
|
273
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
class WebrpcStreamFinishedError extends WebrpcError {
|
277
|
+
constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) {
|
278
|
+
super(name, code, message, status, cause);
|
279
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
// Schema errors
|
284
|
+
|
285
|
+
class UnauthorizedError extends WebrpcError {
|
286
|
+
constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) {
|
287
|
+
super(name, code, message, status, cause);
|
288
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
class PermissionDeniedError extends WebrpcError {
|
292
|
+
constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) {
|
293
|
+
super(name, code, message, status, cause);
|
294
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype);
|
295
|
+
}
|
296
|
+
}
|
297
|
+
class SessionExpiredError extends WebrpcError {
|
298
|
+
constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) {
|
299
|
+
super(name, code, message, status, cause);
|
300
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
301
|
+
}
|
302
|
+
}
|
303
|
+
class MethodNotFoundError extends WebrpcError {
|
304
|
+
constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) {
|
305
|
+
super(name, code, message, status, cause);
|
306
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
class RequestConflictError extends WebrpcError {
|
310
|
+
constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) {
|
311
|
+
super(name, code, message, status, cause);
|
312
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
class ServiceDisabledError extends WebrpcError {
|
316
|
+
constructor(name = 'ServiceDisabled', code = 1005, message = 'Service disabled', status = 0, cause) {
|
317
|
+
super(name, code, message, status, cause);
|
318
|
+
Object.setPrototypeOf(this, ServiceDisabledError.prototype);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
class TimeoutError extends WebrpcError {
|
322
|
+
constructor(name = 'Timeout', code = 2000, message = 'Request timed out', status = 0, cause) {
|
323
|
+
super(name, code, message, status, cause);
|
324
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
class InvalidArgumentError extends WebrpcError {
|
328
|
+
constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) {
|
329
|
+
super(name, code, message, status, cause);
|
330
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
class NotFoundError extends WebrpcError {
|
334
|
+
constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) {
|
335
|
+
super(name, code, message, status, cause);
|
336
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
337
|
+
}
|
338
|
+
}
|
339
|
+
class UserNotFoundError extends WebrpcError {
|
340
|
+
constructor(name = 'UserNotFound', code = 3001, message = 'User not found', status = 0, cause) {
|
341
|
+
super(name, code, message, status, cause);
|
342
|
+
Object.setPrototypeOf(this, UserNotFoundError.prototype);
|
343
|
+
}
|
344
|
+
}
|
345
|
+
class ProjectNotFoundError extends WebrpcError {
|
346
|
+
constructor(name = 'ProjectNotFound', code = 3002, message = 'Project not found', status = 0, cause) {
|
347
|
+
super(name, code, message, status, cause);
|
348
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
class AlreadyCollaboratorError extends WebrpcError {
|
352
|
+
constructor(name = 'AlreadyCollaborator', code = 4001, message = 'Already a collaborator', status = 0, cause) {
|
353
|
+
super(name, code, message, status, cause);
|
354
|
+
Object.setPrototypeOf(this, AlreadyCollaboratorError.prototype);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
let errors = /*#__PURE__*/function (errors) {
|
358
|
+
errors["WebrpcEndpoint"] = "WebrpcEndpoint";
|
359
|
+
errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
|
360
|
+
errors["WebrpcBadRoute"] = "WebrpcBadRoute";
|
361
|
+
errors["WebrpcBadMethod"] = "WebrpcBadMethod";
|
362
|
+
errors["WebrpcBadRequest"] = "WebrpcBadRequest";
|
363
|
+
errors["WebrpcBadResponse"] = "WebrpcBadResponse";
|
364
|
+
errors["WebrpcServerPanic"] = "WebrpcServerPanic";
|
365
|
+
errors["WebrpcInternalError"] = "WebrpcInternalError";
|
366
|
+
errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected";
|
367
|
+
errors["WebrpcStreamLost"] = "WebrpcStreamLost";
|
368
|
+
errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
|
369
|
+
errors["Unauthorized"] = "Unauthorized";
|
370
|
+
errors["PermissionDenied"] = "PermissionDenied";
|
371
|
+
errors["SessionExpired"] = "SessionExpired";
|
372
|
+
errors["MethodNotFound"] = "MethodNotFound";
|
373
|
+
errors["RequestConflict"] = "RequestConflict";
|
374
|
+
errors["ServiceDisabled"] = "ServiceDisabled";
|
375
|
+
errors["Timeout"] = "Timeout";
|
376
|
+
errors["InvalidArgument"] = "InvalidArgument";
|
377
|
+
errors["NotFound"] = "NotFound";
|
378
|
+
errors["UserNotFound"] = "UserNotFound";
|
379
|
+
errors["ProjectNotFound"] = "ProjectNotFound";
|
380
|
+
return errors;
|
381
|
+
}({});
|
382
|
+
let WebrpcErrorCodes = /*#__PURE__*/function (WebrpcErrorCodes) {
|
383
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcEndpoint"] = 0] = "WebrpcEndpoint";
|
384
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcRequestFailed"] = -1] = "WebrpcRequestFailed";
|
385
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRoute"] = -2] = "WebrpcBadRoute";
|
386
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadMethod"] = -3] = "WebrpcBadMethod";
|
387
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRequest"] = -4] = "WebrpcBadRequest";
|
388
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadResponse"] = -5] = "WebrpcBadResponse";
|
389
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcServerPanic"] = -6] = "WebrpcServerPanic";
|
390
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcInternalError"] = -7] = "WebrpcInternalError";
|
391
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcClientDisconnected"] = -8] = "WebrpcClientDisconnected";
|
392
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamLost"] = -9] = "WebrpcStreamLost";
|
393
|
+
WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamFinished"] = -10] = "WebrpcStreamFinished";
|
394
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Unauthorized"] = 1000] = "Unauthorized";
|
395
|
+
WebrpcErrorCodes[WebrpcErrorCodes["PermissionDenied"] = 1001] = "PermissionDenied";
|
396
|
+
WebrpcErrorCodes[WebrpcErrorCodes["SessionExpired"] = 1002] = "SessionExpired";
|
397
|
+
WebrpcErrorCodes[WebrpcErrorCodes["MethodNotFound"] = 1003] = "MethodNotFound";
|
398
|
+
WebrpcErrorCodes[WebrpcErrorCodes["RequestConflict"] = 1004] = "RequestConflict";
|
399
|
+
WebrpcErrorCodes[WebrpcErrorCodes["ServiceDisabled"] = 1005] = "ServiceDisabled";
|
400
|
+
WebrpcErrorCodes[WebrpcErrorCodes["Timeout"] = 2000] = "Timeout";
|
401
|
+
WebrpcErrorCodes[WebrpcErrorCodes["InvalidArgument"] = 2001] = "InvalidArgument";
|
402
|
+
WebrpcErrorCodes[WebrpcErrorCodes["NotFound"] = 3000] = "NotFound";
|
403
|
+
WebrpcErrorCodes[WebrpcErrorCodes["UserNotFound"] = 3001] = "UserNotFound";
|
404
|
+
WebrpcErrorCodes[WebrpcErrorCodes["ProjectNotFound"] = 3002] = "ProjectNotFound";
|
405
|
+
return WebrpcErrorCodes;
|
406
|
+
}({});
|
407
|
+
const webrpcErrorByCode = {
|
408
|
+
[0]: WebrpcEndpointError,
|
409
|
+
[-1]: WebrpcRequestFailedError,
|
410
|
+
[-2]: WebrpcBadRouteError,
|
411
|
+
[-3]: WebrpcBadMethodError,
|
412
|
+
[-4]: WebrpcBadRequestError,
|
413
|
+
[-5]: WebrpcBadResponseError,
|
414
|
+
[-6]: WebrpcServerPanicError,
|
415
|
+
[-7]: WebrpcInternalErrorError,
|
416
|
+
[-8]: WebrpcClientDisconnectedError,
|
417
|
+
[-9]: WebrpcStreamLostError,
|
418
|
+
[-10]: WebrpcStreamFinishedError,
|
419
|
+
[1000]: UnauthorizedError,
|
420
|
+
[1001]: PermissionDeniedError,
|
421
|
+
[1002]: SessionExpiredError,
|
422
|
+
[1003]: MethodNotFoundError,
|
423
|
+
[1004]: RequestConflictError,
|
424
|
+
[1005]: ServiceDisabledError,
|
425
|
+
[2000]: TimeoutError,
|
426
|
+
[2001]: InvalidArgumentError,
|
427
|
+
[3000]: NotFoundError,
|
428
|
+
[3001]: UserNotFoundError,
|
429
|
+
[3002]: ProjectNotFoundError
|
430
|
+
};
|
431
|
+
|
432
|
+
class SequenceBuilderClient extends Builder {
|
433
|
+
constructor(projectAccessKey, apiUrl) {
|
434
|
+
const hostname = apiUrl != null ? apiUrl : 'https://api.sequence.build';
|
435
|
+
super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch);
|
436
|
+
this.projectAccessKey = projectAccessKey;
|
437
|
+
this._fetch = (input, init) => {
|
438
|
+
// automatically include access key auth header to requests
|
439
|
+
// if its been set on the api client
|
440
|
+
const headers = {};
|
441
|
+
const projectAccessKey = this.projectAccessKey;
|
442
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
443
|
+
headers['X-Access-Key'] = projectAccessKey;
|
444
|
+
}
|
445
|
+
|
446
|
+
// before the request is made
|
447
|
+
init.headers = _extends({}, init.headers, headers);
|
448
|
+
return fetch(input, init);
|
449
|
+
};
|
450
|
+
this.fetch = this._fetch;
|
451
|
+
}
|
452
|
+
}
|
453
|
+
|
454
|
+
export { AlreadyCollaboratorError, Builder, InvalidArgumentError, MethodNotFoundError, NotFoundError, PermissionDeniedError, ProjectNotFoundError, RequestConflictError, SequenceBuilderClient, ServiceDisabledError, SessionExpiredError, TimeoutError, UnauthorizedError, UserNotFoundError, VersionFromHeader, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion, WebrpcBadMethodError, WebrpcBadRequestError, WebrpcBadResponseError, WebrpcBadRouteError, WebrpcClientDisconnectedError, WebrpcEndpointError, WebrpcError, WebrpcErrorCodes, WebrpcHeader, WebrpcHeaderValue, WebrpcInternalErrorError, WebrpcRequestFailedError, WebrpcServerPanicError, WebrpcStreamFinishedError, WebrpcStreamLostError, errors, webrpcErrorByCode };
|
@@ -0,0 +1,222 @@
|
|
1
|
+
export declare const WebrpcHeader = "Webrpc";
|
2
|
+
export declare const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-builder@v0.1.0";
|
3
|
+
export declare const WebRPCVersion = "v1";
|
4
|
+
export declare const WebRPCSchemaVersion = "v0.1.0";
|
5
|
+
export declare const WebRPCSchemaHash = "5b580e1afeb26e0b4a8ee026271e2466760da0aa";
|
6
|
+
type WebrpcGenVersions = {
|
7
|
+
webrpcGenVersion: string;
|
8
|
+
codeGenName: string;
|
9
|
+
codeGenVersion: string;
|
10
|
+
schemaName: string;
|
11
|
+
schemaVersion: string;
|
12
|
+
};
|
13
|
+
export declare function VersionFromHeader(headers: Headers): WebrpcGenVersions;
|
14
|
+
export interface AudienceContact {
|
15
|
+
id?: number;
|
16
|
+
audienceId: number;
|
17
|
+
name?: string;
|
18
|
+
address: string;
|
19
|
+
email?: string;
|
20
|
+
userIp?: string;
|
21
|
+
stage?: number;
|
22
|
+
createdAt?: string;
|
23
|
+
updatedAt?: string;
|
24
|
+
}
|
25
|
+
export interface AudienceRegistrationStatus {
|
26
|
+
totalCount: number;
|
27
|
+
}
|
28
|
+
export interface WalletProof {
|
29
|
+
address: string;
|
30
|
+
message: string;
|
31
|
+
signature: string;
|
32
|
+
chainId: number;
|
33
|
+
}
|
34
|
+
export interface Builder {
|
35
|
+
ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>;
|
36
|
+
registerAudienceContact(args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<RegisterAudienceContactReturn>;
|
37
|
+
getRegisteredAudienceContact(args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<GetRegisteredAudienceContactReturn>;
|
38
|
+
getAudienceRegistrationPublicStatus(args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal): Promise<GetAudienceRegistrationPublicStatusReturn>;
|
39
|
+
isAudienceContactRegistered(args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal): Promise<IsAudienceContactRegisteredReturn>;
|
40
|
+
}
|
41
|
+
export interface PingArgs {
|
42
|
+
}
|
43
|
+
export interface PingReturn {
|
44
|
+
status: boolean;
|
45
|
+
}
|
46
|
+
export interface RegisterAudienceContactArgs {
|
47
|
+
projectId: number;
|
48
|
+
audienceId: number;
|
49
|
+
contact: AudienceContact;
|
50
|
+
walletProof: WalletProof;
|
51
|
+
}
|
52
|
+
export interface RegisterAudienceContactReturn {
|
53
|
+
ok: boolean;
|
54
|
+
}
|
55
|
+
export interface GetRegisteredAudienceContactArgs {
|
56
|
+
projectId: number;
|
57
|
+
audienceId: number;
|
58
|
+
walletProof: WalletProof;
|
59
|
+
}
|
60
|
+
export interface GetRegisteredAudienceContactReturn {
|
61
|
+
contact: AudienceContact;
|
62
|
+
}
|
63
|
+
export interface GetAudienceRegistrationPublicStatusArgs {
|
64
|
+
projectId: number;
|
65
|
+
audienceId: number;
|
66
|
+
}
|
67
|
+
export interface GetAudienceRegistrationPublicStatusReturn {
|
68
|
+
status: AudienceRegistrationStatus;
|
69
|
+
}
|
70
|
+
export interface IsAudienceContactRegisteredArgs {
|
71
|
+
projectId: number;
|
72
|
+
audienceId: number;
|
73
|
+
walletAddress: string;
|
74
|
+
}
|
75
|
+
export interface IsAudienceContactRegisteredReturn {
|
76
|
+
registered: boolean;
|
77
|
+
}
|
78
|
+
export declare class Builder implements Builder {
|
79
|
+
protected hostname: string;
|
80
|
+
protected fetch: Fetch;
|
81
|
+
protected path: string;
|
82
|
+
constructor(hostname: string, fetch: Fetch);
|
83
|
+
private url;
|
84
|
+
ping: (headers?: object, signal?: AbortSignal) => Promise<PingReturn>;
|
85
|
+
registerAudienceContact: (args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal) => Promise<RegisterAudienceContactReturn>;
|
86
|
+
getRegisteredAudienceContact: (args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal) => Promise<GetRegisteredAudienceContactReturn>;
|
87
|
+
getAudienceRegistrationPublicStatus: (args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal) => Promise<GetAudienceRegistrationPublicStatusReturn>;
|
88
|
+
isAudienceContactRegistered: (args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal) => Promise<IsAudienceContactRegisteredReturn>;
|
89
|
+
}
|
90
|
+
export declare class WebrpcError extends Error {
|
91
|
+
name: string;
|
92
|
+
code: number;
|
93
|
+
message: string;
|
94
|
+
status: number;
|
95
|
+
cause?: string;
|
96
|
+
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
|
97
|
+
msg: string;
|
98
|
+
constructor(name: string, code: number, message: string, status: number, cause?: string);
|
99
|
+
static new(payload: any): WebrpcError;
|
100
|
+
}
|
101
|
+
export declare class WebrpcEndpointError extends WebrpcError {
|
102
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
103
|
+
}
|
104
|
+
export declare class WebrpcRequestFailedError extends WebrpcError {
|
105
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
106
|
+
}
|
107
|
+
export declare class WebrpcBadRouteError extends WebrpcError {
|
108
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
109
|
+
}
|
110
|
+
export declare class WebrpcBadMethodError extends WebrpcError {
|
111
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
112
|
+
}
|
113
|
+
export declare class WebrpcBadRequestError extends WebrpcError {
|
114
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
115
|
+
}
|
116
|
+
export declare class WebrpcBadResponseError extends WebrpcError {
|
117
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
118
|
+
}
|
119
|
+
export declare class WebrpcServerPanicError extends WebrpcError {
|
120
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
121
|
+
}
|
122
|
+
export declare class WebrpcInternalErrorError extends WebrpcError {
|
123
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
124
|
+
}
|
125
|
+
export declare class WebrpcClientDisconnectedError extends WebrpcError {
|
126
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
127
|
+
}
|
128
|
+
export declare class WebrpcStreamLostError extends WebrpcError {
|
129
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
130
|
+
}
|
131
|
+
export declare class WebrpcStreamFinishedError extends WebrpcError {
|
132
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
133
|
+
}
|
134
|
+
export declare class UnauthorizedError extends WebrpcError {
|
135
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
136
|
+
}
|
137
|
+
export declare class PermissionDeniedError extends WebrpcError {
|
138
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
139
|
+
}
|
140
|
+
export declare class SessionExpiredError extends WebrpcError {
|
141
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
142
|
+
}
|
143
|
+
export declare class MethodNotFoundError extends WebrpcError {
|
144
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
145
|
+
}
|
146
|
+
export declare class RequestConflictError extends WebrpcError {
|
147
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
148
|
+
}
|
149
|
+
export declare class ServiceDisabledError extends WebrpcError {
|
150
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
151
|
+
}
|
152
|
+
export declare class TimeoutError extends WebrpcError {
|
153
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
154
|
+
}
|
155
|
+
export declare class InvalidArgumentError extends WebrpcError {
|
156
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
157
|
+
}
|
158
|
+
export declare class NotFoundError extends WebrpcError {
|
159
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
160
|
+
}
|
161
|
+
export declare class UserNotFoundError extends WebrpcError {
|
162
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
163
|
+
}
|
164
|
+
export declare class ProjectNotFoundError extends WebrpcError {
|
165
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
166
|
+
}
|
167
|
+
export declare class AlreadyCollaboratorError extends WebrpcError {
|
168
|
+
constructor(name?: string, code?: number, message?: string, status?: number, cause?: string);
|
169
|
+
}
|
170
|
+
export declare enum errors {
|
171
|
+
WebrpcEndpoint = "WebrpcEndpoint",
|
172
|
+
WebrpcRequestFailed = "WebrpcRequestFailed",
|
173
|
+
WebrpcBadRoute = "WebrpcBadRoute",
|
174
|
+
WebrpcBadMethod = "WebrpcBadMethod",
|
175
|
+
WebrpcBadRequest = "WebrpcBadRequest",
|
176
|
+
WebrpcBadResponse = "WebrpcBadResponse",
|
177
|
+
WebrpcServerPanic = "WebrpcServerPanic",
|
178
|
+
WebrpcInternalError = "WebrpcInternalError",
|
179
|
+
WebrpcClientDisconnected = "WebrpcClientDisconnected",
|
180
|
+
WebrpcStreamLost = "WebrpcStreamLost",
|
181
|
+
WebrpcStreamFinished = "WebrpcStreamFinished",
|
182
|
+
Unauthorized = "Unauthorized",
|
183
|
+
PermissionDenied = "PermissionDenied",
|
184
|
+
SessionExpired = "SessionExpired",
|
185
|
+
MethodNotFound = "MethodNotFound",
|
186
|
+
RequestConflict = "RequestConflict",
|
187
|
+
ServiceDisabled = "ServiceDisabled",
|
188
|
+
Timeout = "Timeout",
|
189
|
+
InvalidArgument = "InvalidArgument",
|
190
|
+
NotFound = "NotFound",
|
191
|
+
UserNotFound = "UserNotFound",
|
192
|
+
ProjectNotFound = "ProjectNotFound"
|
193
|
+
}
|
194
|
+
export declare enum WebrpcErrorCodes {
|
195
|
+
WebrpcEndpoint = 0,
|
196
|
+
WebrpcRequestFailed = -1,
|
197
|
+
WebrpcBadRoute = -2,
|
198
|
+
WebrpcBadMethod = -3,
|
199
|
+
WebrpcBadRequest = -4,
|
200
|
+
WebrpcBadResponse = -5,
|
201
|
+
WebrpcServerPanic = -6,
|
202
|
+
WebrpcInternalError = -7,
|
203
|
+
WebrpcClientDisconnected = -8,
|
204
|
+
WebrpcStreamLost = -9,
|
205
|
+
WebrpcStreamFinished = -10,
|
206
|
+
Unauthorized = 1000,
|
207
|
+
PermissionDenied = 1001,
|
208
|
+
SessionExpired = 1002,
|
209
|
+
MethodNotFound = 1003,
|
210
|
+
RequestConflict = 1004,
|
211
|
+
ServiceDisabled = 1005,
|
212
|
+
Timeout = 2000,
|
213
|
+
InvalidArgument = 2001,
|
214
|
+
NotFound = 3000,
|
215
|
+
UserNotFound = 3001,
|
216
|
+
ProjectNotFound = 3002
|
217
|
+
}
|
218
|
+
export declare const webrpcErrorByCode: {
|
219
|
+
[code: number]: any;
|
220
|
+
};
|
221
|
+
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
222
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export * from "./builder.gen.js";
|
2
|
+
import { Builder as BuilderRpc } from "./builder.gen.js";
|
3
|
+
export declare class SequenceBuilderClient extends BuilderRpc {
|
4
|
+
projectAccessKey: string;
|
5
|
+
constructor(projectAccessKey: string, apiUrl?: string);
|
6
|
+
_fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
7
|
+
}
|