1
+ import * as http from 'http' ;
1
2
import { AxiosRequestConfig } from 'axios' ;
3
+ import * as WebSocket from 'ws' ;
2
4
import { operations } from './schema' ;
3
5
4
6
/**
@@ -13,23 +15,35 @@ import { operations } from './schema';
13
15
14
16
// General
15
17
16
- export class FireFlyError extends Error { }
18
+ export class FireFlyError extends Error {
19
+ constructor ( message ?: string , public originalError ?: Error , public path ?: string ) {
20
+ super ( message ) ;
21
+ }
22
+ }
23
+
24
+ export class FireFlyIdempotencyError extends FireFlyError { }
17
25
18
- export interface FireFlyGetOptions {
19
- confirm : undefined ;
26
+ interface FireFlyBaseHttpOptions {
20
27
requestConfig ?: AxiosRequestConfig ;
21
28
}
22
29
23
- export interface FireFlyCreateOptions {
30
+ export interface FireFlyGetOptions extends FireFlyBaseHttpOptions { }
31
+ export interface FireFlyUpdateOptions extends FireFlyBaseHttpOptions { }
32
+ export interface FireFlyReplaceOptions extends FireFlyBaseHttpOptions { }
33
+ export interface FireFlyDeleteOptions extends FireFlyBaseHttpOptions { }
34
+
35
+ export interface FireFlyCreateOptions extends FireFlyBaseHttpOptions {
24
36
confirm ?: boolean ;
25
- requestConfig ?: AxiosRequestConfig ;
37
+ publish ?: boolean ;
26
38
}
27
39
28
40
export interface FireFlyOptionsInput {
29
41
host : string ;
30
42
namespace ?: string ;
31
43
username ?: string ;
32
44
password ?: string ;
45
+ baseURL ?: string ;
46
+ namespaceBaseURL ?: string ;
33
47
websocket ?: {
34
48
host ?: string ;
35
49
reconnectDelay ?: number ;
@@ -47,24 +61,50 @@ export interface FireFlyOptions extends FireFlyOptionsInput {
47
61
} ;
48
62
}
49
63
64
+ export interface FireFlyWebSocketSender {
65
+ send : ( json : JSON ) => void ;
66
+ }
67
+
68
+ export interface FireFlyWebSocketConnectCallback {
69
+ ( sender : FireFlyWebSocketSender ) : void | Promise < void > ;
70
+ }
71
+
50
72
export interface FireFlyWebSocketOptions {
51
73
host : string ;
52
74
namespace : string ;
53
75
subscriptions : string [ ] ;
54
76
username ?: string ;
55
77
password ?: string ;
56
78
ephemeral ?: FireFlyEphemeralSubscription ;
57
- autoack : boolean ;
79
+ autoack ?: boolean ;
80
+ noack ?: boolean ;
58
81
reconnectDelay : number ;
59
82
heartbeatInterval : number ;
83
+ socketOptions ?: WebSocket . ClientOptions | http . ClientRequestArgs ;
84
+ afterConnect ?: FireFlyWebSocketConnectCallback ;
60
85
}
61
86
87
+ // Namespace
88
+ export type FireFlyNamespaceResponse = Required <
89
+ operations [ 'getNamespace' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
90
+ > ;
91
+
62
92
// Network
63
93
94
+ export type FireFlyIdentityFilter = operations [ 'getIdentities' ] [ 'parameters' ] [ 'query' ] ;
64
95
export type FireFlyOrganizationFilter = operations [ 'getNetworkOrgs' ] [ 'parameters' ] [ 'query' ] ;
65
96
export type FireFlyNodeFilter = operations [ 'getNetworkNodes' ] [ 'parameters' ] [ 'query' ] ;
66
97
export type FireFlyVerifierFilter = operations [ 'getVerifiers' ] [ 'parameters' ] [ 'query' ] ;
67
98
99
+ export type FireFlyIdentityRequest =
100
+ operations [ 'postNewIdentity' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
101
+
102
+ export type FireFlyIdentityResponse = Required <
103
+ operations [ 'getIdentityByID' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
104
+ > ;
105
+ export type FireFlyIdentitiesResponse = Required <
106
+ operations [ 'getIdentities' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
107
+ > ;
68
108
export type FireFlyOrganizationResponse = Required <
69
109
operations [ 'getNetworkOrg' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
70
110
> ;
@@ -108,20 +148,21 @@ export interface FireFlyEphemeralSubscription extends FireFlySubscriptionBase {
108
148
}
109
149
110
150
export interface FireFlyEnrichedEvent extends FireFlyEventResponse {
111
- blockchainEvent ?: unknown ;
112
- contractAPI ?: unknown ;
113
- contractInterface ?: unknown ;
151
+ blockchainEvent ?: FireFlyBlockchainEventResponse ;
152
+ contractAPI ?: FireFlyContractAPIResponse ;
153
+ contractInterface ?: FireFlyContractInterfaceResponse ;
114
154
datatype ?: FireFlyDatatypeResponse ;
115
- identity ?: unknown ;
155
+ identity ?: FireFlyIdentityResponse ;
116
156
message ?: FireFlyMessageResponse ;
117
- namespaceDetails ?: unknown ;
118
- tokenApproval ?: unknown ;
157
+ tokenApproval ?: FireFlyTokenApprovalResponse ;
119
158
tokenPool ?: FireFlyTokenPoolResponse ;
120
159
tokenTransfer ?: FireFlyTokenTransferResponse ;
121
160
transaction ?: FireFlyTransactionResponse ;
161
+ operation ?: FireFlyOperationResponse ;
122
162
}
123
163
124
- export interface FireFlyEventDelivery extends FireFlyEnrichedEvent {
164
+ export interface FireFlyEventDelivery extends Omit < FireFlyEnrichedEvent , 'type' > {
165
+ type : FireFlyEnrichedEvent [ 'type' ] | 'protocol_error' ;
125
166
subscription : {
126
167
id : string ;
127
168
name : string ;
@@ -145,11 +186,17 @@ export type FireFlyDataFilter = operations['getData']['parameters']['query'];
145
186
146
187
export type FireFlyDataRequest =
147
188
operations [ 'postData' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
189
+ export type FireFlyDataBlobRequest =
190
+ operations [ 'postData' ] [ 'requestBody' ] [ 'content' ] [ 'multipart/form-data' ] ;
148
191
149
192
export type FireFlyDataResponse = Required <
150
193
operations [ 'getDataByID' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
151
194
> ;
152
195
196
+ export const FireFlyDataBlobRequestDefaults : FireFlyDataBlobRequest = {
197
+ autometa : 'true' ,
198
+ } ;
199
+
153
200
// Messages
154
201
155
202
export type FireFlyMessageFilter = operations [ 'getMsgs' ] [ 'parameters' ] [ 'query' ] ;
@@ -166,6 +213,9 @@ export type FireFlyMessageResponse = Required<
166
213
export type FireFlyBatchResponse = Required <
167
214
operations [ 'getBatchByID' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
168
215
> ;
216
+ export type FireFlyGroupResponse = Required <
217
+ operations [ 'getGroupByHash' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
218
+ > ;
169
219
170
220
export interface FireFlyPrivateSendOptions extends FireFlyCreateOptions {
171
221
requestReply ?: boolean ;
@@ -184,6 +234,8 @@ export type FireFlyTokenPoolResponse = Required<
184
234
185
235
// Token Transfers
186
236
237
+ export type FireFlyTokenTransferFilter = operations [ 'getTokenTransfers' ] [ 'parameters' ] [ 'query' ] ;
238
+
187
239
export type FireFlyTokenMintRequest =
188
240
operations [ 'postTokenMint' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
189
241
export type FireFlyTokenBurnRequest =
@@ -199,9 +251,23 @@ export type FireFlyTokenTransferResponse = Required<
199
251
200
252
export type FireFlyTokenBalanceFilter = operations [ 'getTokenBalances' ] [ 'parameters' ] [ 'query' ] ;
201
253
202
- export type FireFlyTokenBalanceResponse = Required <
254
+ type BalancesList = Required <
203
255
operations [ 'getTokenBalances' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
204
256
> ;
257
+ const balances : BalancesList = [ ] ;
258
+ export type FireFlyTokenBalanceResponse = typeof balances [ 0 ] ;
259
+
260
+ // Token Approvals
261
+
262
+ export type FireFlyTokenApprovalFilter = operations [ 'getTokenApprovals' ] [ 'parameters' ] [ 'query' ] ;
263
+
264
+ export type FireFlyTokenApprovalRequest =
265
+ operations [ 'postTokenApproval' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
266
+ type ApprovalsList =
267
+ operations [ 'getTokenApprovals' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ] ;
268
+
269
+ const approvals : ApprovalsList = [ ] ;
270
+ export type FireFlyTokenApprovalResponse = typeof approvals [ 0 ] ;
205
271
206
272
// Operations + Transactions
207
273
@@ -241,3 +307,27 @@ export type FireFlyContractAPIResponse = Required<
241
307
export type FireFlyContractListenerResponse = Required <
242
308
operations [ 'getContractListenerByNameOrID' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
243
309
> ;
310
+
311
+ export type FireFlyContractInvokeRequest =
312
+ operations [ 'postContractInvoke' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
313
+ export type FireFlyContractAPIInvokeRequest =
314
+ operations [ 'postContractAPIInvoke' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
315
+ export type FireFlyContractInvokeResponse = Required <
316
+ operations [ 'postContractInvoke' ] [ 'responses' ] [ '202' ] [ 'content' ] [ 'application/json' ]
317
+ > ;
318
+
319
+ export type FireFlyContractQueryRequest =
320
+ operations [ 'postContractQuery' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
321
+ export type FireFlyContractAPIQueryRequest =
322
+ operations [ 'postContractAPIQuery' ] [ 'requestBody' ] [ 'content' ] [ 'application/json' ] ;
323
+ export type FireFlyContractQueryResponse = Required <
324
+ operations [ 'postContractQuery' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
325
+ > ;
326
+
327
+ // Blockchain Events
328
+
329
+ export type FireFlyBlockchainEventFilter = operations [ 'getBlockchainEvents' ] [ 'parameters' ] [ 'query' ] ;
330
+
331
+ export type FireFlyBlockchainEventResponse = Required <
332
+ operations [ 'getBlockchainEventByID' ] [ 'responses' ] [ '200' ] [ 'content' ] [ 'application/json' ]
333
+ > ;
0 commit comments