@wishknish/knishio-client-js 0.4.44 → 0.4.45
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/dist/client.umd.js +19 -19
- package/package.json +18 -20
- package/src/KnishIOClient.js +3 -3
- package/src/Molecule.js +1 -1
- package/src/{libraries/ApolloLink/EchoLink.js → TokenUnit.js} +50 -57
- package/src/Wallet.js +5 -16
- package/src/httpClient/ApolloClient.js +10 -7
- package/src/libraries/ApolloLink/Client.js +33 -7
- package/src/libraries/ApolloLink/PusherLink.js +226 -0
- package/src/response/ResponseWalletList.js +6 -1
- package/src/test/Test.js +38 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wishknish/knishio-client-js",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.45",
|
|
4
4
|
"productName": "Knish.IO Javascript SDK Client",
|
|
5
5
|
"description": "JavaScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs.",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"main": "dist/client.umd.js",
|
|
30
30
|
"module": "dist/client.esm.js",
|
|
31
31
|
"commonjs": "dist/client.cjs.js",
|
|
32
|
-
"unpkg": "dist/client.min.js",
|
|
33
32
|
"keywords": [
|
|
34
33
|
"wishknish",
|
|
35
34
|
"knishio",
|
|
@@ -39,21 +38,21 @@
|
|
|
39
38
|
"graphql"
|
|
40
39
|
],
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"@apollo/client": "^3.
|
|
43
|
-
"@stablelib/base64": "^1.0.
|
|
44
|
-
"@stablelib/utf8": "^1.0.
|
|
45
|
-
"base-x": "^
|
|
46
|
-
"big-integer": "^1.6.
|
|
41
|
+
"@apollo/client": "^3.5.10",
|
|
42
|
+
"@stablelib/base64": "^1.0.1",
|
|
43
|
+
"@stablelib/utf8": "^1.0.1",
|
|
44
|
+
"base-x": "^4.0.0",
|
|
45
|
+
"big-integer": "^1.6.51",
|
|
47
46
|
"buffer": "^6.0.3",
|
|
48
47
|
"core-js": "3.21.1",
|
|
49
48
|
"get-random-values": "^1.2.2",
|
|
50
|
-
"graphql": "^
|
|
49
|
+
"graphql": "^16.3.0",
|
|
51
50
|
"isomorphic-fetch": "^3.0.0",
|
|
52
51
|
"js-sha3": "^0.8.0",
|
|
53
|
-
"
|
|
54
|
-
"socket.io-client": "^2.4.0",
|
|
52
|
+
"pusher-js": "^7.0.6",
|
|
55
53
|
"tweetnacl": "^1.0.3",
|
|
56
|
-
"tweetnacl-sealedbox-js": "^1.2.0"
|
|
54
|
+
"tweetnacl-sealedbox-js": "^1.2.0",
|
|
55
|
+
"uri-js": "^4.4.1"
|
|
57
56
|
},
|
|
58
57
|
"files": [
|
|
59
58
|
"/src"
|
|
@@ -89,21 +88,21 @@
|
|
|
89
88
|
"@babel/preset-env": "^7.12.13",
|
|
90
89
|
"@babel/runtime": "^7.12.13",
|
|
91
90
|
"@rollup/plugin-babel": "^5.2.3",
|
|
92
|
-
"@rollup/plugin-commonjs": "^
|
|
91
|
+
"@rollup/plugin-commonjs": "^21.0.3",
|
|
93
92
|
"@rollup/plugin-inject": "^4.0.4",
|
|
94
93
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
95
94
|
"@rollup/plugin-replace": "^4.0.0",
|
|
96
|
-
"babel-loader": "^8.2.
|
|
97
|
-
"eslint": "^
|
|
98
|
-
"eslint-plugin-vue": "^
|
|
95
|
+
"babel-loader": "^8.2.4",
|
|
96
|
+
"eslint": "^8.12.0",
|
|
97
|
+
"eslint-plugin-vue": "^8.6.0",
|
|
99
98
|
"nodemon": "^2.0.15",
|
|
100
99
|
"rollup": "^2.70.1",
|
|
101
100
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
102
101
|
"rollup-plugin-terser": "^7.0.2",
|
|
103
102
|
"uglify-js": "^3.15.3",
|
|
104
|
-
"webpack": "^5.
|
|
105
|
-
"webpack-cli": "^4.
|
|
106
|
-
"webpack-merge": "^5.
|
|
103
|
+
"webpack": "^5.71.0",
|
|
104
|
+
"webpack-cli": "^4.9.2",
|
|
105
|
+
"webpack-merge": "^5.8.0"
|
|
107
106
|
},
|
|
108
107
|
"browserslist": [
|
|
109
108
|
"> 1%",
|
|
@@ -111,8 +110,7 @@
|
|
|
111
110
|
"not ie <= 8"
|
|
112
111
|
],
|
|
113
112
|
"scripts": {
|
|
114
|
-
"build": "yarn build:
|
|
115
|
-
"build:browser": "rollup --config build/rollup.config.browser.js",
|
|
113
|
+
"build": "yarn build:es && yarn build:umd && yarn build:cjs",
|
|
116
114
|
"build:es": "rollup --config build/rollup.config.es.js",
|
|
117
115
|
"build:umd": "rollup --config build/rollup.config.umd.js",
|
|
118
116
|
"build:cjs": "rollup --config build/rollup.config.cjs.js",
|
package/src/KnishIOClient.js
CHANGED
|
@@ -590,15 +590,15 @@ export default class KnishIOClient {
|
|
|
590
590
|
/**
|
|
591
591
|
* @param {string|null} bundle
|
|
592
592
|
* @param {function} closure
|
|
593
|
-
* @return {string}
|
|
593
|
+
* @return {Promise<string>}
|
|
594
594
|
*/
|
|
595
|
-
subscribeCreateMolecule ( {
|
|
595
|
+
async subscribeCreateMolecule ( {
|
|
596
596
|
bundle,
|
|
597
597
|
closure
|
|
598
598
|
} ) {
|
|
599
599
|
const subscribe = this.createSubscribe( CreateMoleculeSubscribe );
|
|
600
600
|
|
|
601
|
-
return subscribe.execute( {
|
|
601
|
+
return await subscribe.execute( {
|
|
602
602
|
variables: {
|
|
603
603
|
bundle: bundle || this.getBundle()
|
|
604
604
|
},
|
package/src/Molecule.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
/*
|
|
2
3
|
(
|
|
3
4
|
(/(
|
|
@@ -45,90 +46,82 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
46
|
|
|
46
47
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
48
|
*/
|
|
48
|
-
import {
|
|
49
|
-
ApolloLink
|
|
50
|
-
} from '@apollo/client/core';
|
|
51
|
-
import Echo from 'laravel-echo';
|
|
52
|
-
import createRequestHandler from './handler';
|
|
53
|
-
import io from 'socket.io-client';
|
|
54
49
|
|
|
55
50
|
/**
|
|
56
|
-
*
|
|
51
|
+
* AuthToken class
|
|
57
52
|
*/
|
|
58
|
-
|
|
53
|
+
export default class TokenUnit {
|
|
54
|
+
|
|
59
55
|
/**
|
|
60
|
-
*
|
|
56
|
+
*
|
|
57
|
+
* @param data
|
|
58
|
+
* @returns {*}
|
|
61
59
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
static createFromGraphQL( data ) {
|
|
61
|
+
let metas = data[ 'metas' ] || {};
|
|
62
|
+
if ( metas.length ) {
|
|
63
|
+
metas = JSON.parse( metas );
|
|
64
|
+
if ( !metas.length ) { // set an empty object instead of an array
|
|
65
|
+
metas = {};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return new TokenUnit(
|
|
69
|
+
data[ 'id' ],
|
|
70
|
+
data[ 'name' ],
|
|
71
|
+
metas
|
|
72
|
+
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
*
|
|
76
|
-
* @
|
|
77
|
+
* @param data
|
|
78
|
+
* @returns {TokenUnit}
|
|
77
79
|
*/
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
+
static createFromDB( data ) {
|
|
81
|
+
return new TokenUnit(
|
|
82
|
+
data[ 0 ],
|
|
83
|
+
data[ 1 ],
|
|
84
|
+
data.length > 2 ? data[ 2 ] : {}
|
|
85
|
+
);
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
/**
|
|
83
|
-
*
|
|
89
|
+
*
|
|
90
|
+
* @param id
|
|
91
|
+
* @param name
|
|
92
|
+
* @param metas
|
|
84
93
|
*/
|
|
85
|
-
|
|
86
|
-
this.
|
|
94
|
+
constructor( id, name, metas ) {
|
|
95
|
+
this.id = id;
|
|
96
|
+
this.name = name;
|
|
97
|
+
this.metas = metas;
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
/**
|
|
90
|
-
*
|
|
101
|
+
*
|
|
102
|
+
* @returns {*|null}
|
|
91
103
|
*/
|
|
92
|
-
|
|
93
|
-
return this.
|
|
104
|
+
getFragmentZone() {
|
|
105
|
+
return this.metas[ 'fragmentZone' ] || null;
|
|
94
106
|
}
|
|
95
107
|
|
|
96
108
|
/**
|
|
97
|
-
* @
|
|
109
|
+
* @return array
|
|
98
110
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
console.log( `Connecting to socket endpoint ${ socketUri }...` );
|
|
102
|
-
|
|
103
|
-
this.socketUri = socketUri;
|
|
104
|
-
this.echo = new Echo( {
|
|
105
|
-
broadcaster: 'socket.io',
|
|
106
|
-
client: io,
|
|
107
|
-
authEndpoint: 'graphql/subscriptions/auth',
|
|
108
|
-
host: this.getSocketUri(),
|
|
109
|
-
transports: [ 'websocket' ],
|
|
110
|
-
auth: {
|
|
111
|
-
headers: {
|
|
112
|
-
'X-Auth-Token': this.getAuthToken(),
|
|
113
|
-
Accept: 'application/json'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
} );
|
|
111
|
+
toData() {
|
|
112
|
+
return [ this.id, this.name, this.metas, ];
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
/**
|
|
120
116
|
*
|
|
121
|
-
* @
|
|
122
|
-
* @param {NextLink} forward
|
|
123
|
-
* @return {*}
|
|
117
|
+
* @returns {{metas: string, name: *, id: *}}
|
|
124
118
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
toGraphQLResponse() {
|
|
120
|
+
return {
|
|
121
|
+
id: this.id,
|
|
122
|
+
name: this.name,
|
|
123
|
+
metas: JSON.stringify( this.metas )
|
|
124
|
+
};
|
|
130
125
|
}
|
|
131
126
|
|
|
132
127
|
}
|
|
133
|
-
|
|
134
|
-
export default EchoLink;
|
package/src/Wallet.js
CHANGED
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
hashShare
|
|
63
63
|
} from './libraries/crypto';
|
|
64
64
|
import BaseX from './libraries/BaseX';
|
|
65
|
+
import TokenUnit from './TokenUnit';
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* Wallet class represents the set of public and private
|
|
@@ -164,32 +165,20 @@ export default class Wallet {
|
|
|
164
165
|
static getTokenUnits ( unitsData ) {
|
|
165
166
|
let result = [];
|
|
166
167
|
unitsData.forEach( unitData => {
|
|
167
|
-
result.push(
|
|
168
|
-
id: unitData.shift(),
|
|
169
|
-
name: unitData.shift(),
|
|
170
|
-
metas: unitData
|
|
171
|
-
} );
|
|
168
|
+
result.push( TokenUnit.createFromDB( unitData ) );
|
|
172
169
|
} );
|
|
173
170
|
return result;
|
|
174
171
|
}
|
|
175
172
|
|
|
176
|
-
/**
|
|
177
|
-
* Has token units?
|
|
178
|
-
* @return {boolean}
|
|
179
|
-
*/
|
|
180
|
-
hasTokenUnits () {
|
|
181
|
-
return !!this.tokenUnits && this.tokenUnits.length > 0;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
173
|
/**
|
|
185
174
|
* @return string|null
|
|
186
175
|
*/
|
|
187
176
|
tokenUnitsJson () {
|
|
188
177
|
|
|
189
|
-
if ( this.
|
|
178
|
+
if ( this.tokenUnits.length ) {
|
|
190
179
|
const result = [];
|
|
191
180
|
this.tokenUnits.forEach( tokenUnit => {
|
|
192
|
-
result.push(
|
|
181
|
+
result.push( tokenUnit.toData() );
|
|
193
182
|
} );
|
|
194
183
|
return JSON.stringify( result );
|
|
195
184
|
}
|
|
@@ -206,7 +195,7 @@ export default class Wallet {
|
|
|
206
195
|
* @param recipientWallet
|
|
207
196
|
*/
|
|
208
197
|
splitUnits (
|
|
209
|
-
units,
|
|
198
|
+
units, // Array: token unit IDs
|
|
210
199
|
remainderWallet,
|
|
211
200
|
recipientWallet = null
|
|
212
201
|
) {
|
|
@@ -83,14 +83,13 @@ export default class ApolloClient {
|
|
|
83
83
|
} );
|
|
84
84
|
|
|
85
85
|
if ( this.$__client ) {
|
|
86
|
-
|
|
87
|
-
this.unsubscribeAll();
|
|
88
|
-
|
|
89
86
|
client.setAuthData( {
|
|
90
87
|
token: this.$__client.getAuthToken(),
|
|
91
88
|
pubkey: this.$__client.getPubKey(),
|
|
92
89
|
wallet: this.$__client.getWallet()
|
|
93
90
|
} );
|
|
91
|
+
|
|
92
|
+
this.socketDisconnect();
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
this.$__client = client;
|
|
@@ -114,8 +113,9 @@ export default class ApolloClient {
|
|
|
114
113
|
* @param {string} operationName
|
|
115
114
|
*/
|
|
116
115
|
unsubscribe ( operationName ) {
|
|
117
|
-
if ( this.$__subscribers
|
|
116
|
+
if ( this.$__subscribers.hasOwnProperty( operationName ) ) {
|
|
118
117
|
this.$__subscribers[ operationName ].unsubscribe();
|
|
118
|
+
this.$__client.unsubscribeFromChannel( operationName );
|
|
119
119
|
delete this.$__subscribers[ operationName ];
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -125,12 +125,15 @@ export default class ApolloClient {
|
|
|
125
125
|
*/
|
|
126
126
|
unsubscribeAll () {
|
|
127
127
|
for ( let subscribe in this.$__subscribers ) {
|
|
128
|
-
|
|
129
|
-
this.unsubscribe( subscribe );
|
|
130
|
-
}
|
|
128
|
+
this.unsubscribe( subscribe );
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
|
|
132
|
+
socketDisconnect() {
|
|
133
|
+
this.$__client.socketDisconnect();
|
|
134
|
+
this.$__subscribers = {};
|
|
135
|
+
}
|
|
136
|
+
|
|
134
137
|
/**
|
|
135
138
|
* @param {Operation} request
|
|
136
139
|
* @param {function} closure
|
|
@@ -55,7 +55,8 @@ import { InMemoryCache } from '@apollo/client/cache';
|
|
|
55
55
|
import { onError } from '@apollo/client/link/error';
|
|
56
56
|
|
|
57
57
|
import HttpLink from './HttpLink';
|
|
58
|
-
import
|
|
58
|
+
import PusherLink from './PusherLink';
|
|
59
|
+
import { parse } from 'uri-js';
|
|
59
60
|
import AuthLink from './AuthLink';
|
|
60
61
|
import { errorHandler } from './handler';
|
|
61
62
|
import CipherLink from './CipherLink';
|
|
@@ -82,7 +83,7 @@ class Client extends ApolloClient {
|
|
|
82
83
|
const auth = new AuthLink();
|
|
83
84
|
|
|
84
85
|
let cipher = null;
|
|
85
|
-
let
|
|
86
|
+
let socket = null;
|
|
86
87
|
|
|
87
88
|
links.push( auth );
|
|
88
89
|
|
|
@@ -92,8 +93,12 @@ class Client extends ApolloClient {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
if ( socketUri ) {
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const path = parse( serverUri );
|
|
97
|
+
socket = new PusherLink( {
|
|
98
|
+
socketUri: socketUri,
|
|
99
|
+
authEndpoint: `${ path.scheme }://${ path.host }/graphql/subscriptions/auth`
|
|
100
|
+
} );
|
|
101
|
+
links.push( socket );
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
links.push( concat( onError( errorHandler ), http ) );
|
|
@@ -125,7 +130,12 @@ class Client extends ApolloClient {
|
|
|
125
130
|
this.__serverUri = serverUri;
|
|
126
131
|
this.__socketUri = socketUri;
|
|
127
132
|
this.__authLink = auth;
|
|
128
|
-
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @type {PusherLink}
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
138
|
+
this.__socket = socket;
|
|
129
139
|
this.__cipherLink = cipher;
|
|
130
140
|
|
|
131
141
|
this.__pubkey = null;
|
|
@@ -169,8 +179,8 @@ class Client extends ApolloClient {
|
|
|
169
179
|
this.__pubkey = pubkey;
|
|
170
180
|
this.__authLink.setAuthToken( token );
|
|
171
181
|
|
|
172
|
-
if ( this.
|
|
173
|
-
this.
|
|
182
|
+
if ( this.__socket ) {
|
|
183
|
+
this.__socket.setAuthToken( token );
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
if ( this.__cipherLink ) {
|
|
@@ -179,6 +189,22 @@ class Client extends ApolloClient {
|
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
|
|
192
|
+
socketDisconnect() {
|
|
193
|
+
if ( this.__socket ) {
|
|
194
|
+
this.__socket.disconnect();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
*
|
|
200
|
+
* @param {string} channel
|
|
201
|
+
*/
|
|
202
|
+
unsubscribeFromChannel( channel ) {
|
|
203
|
+
if ( this.__socket ) {
|
|
204
|
+
this.__socket.unsubscribeFromChannel( channel );
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
182
208
|
/**
|
|
183
209
|
* @return {string}
|
|
184
210
|
*/
|
|
@@ -0,0 +1,226 @@
|
|
|
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
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
import { ApolloLink, Observable } from '@apollo/client/core';
|
|
49
|
+
import Pusher from 'pusher-js';
|
|
50
|
+
import { parse } from 'uri-js';
|
|
51
|
+
import CodeException from '../../exception/CodeException';
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class PusherLink extends ApolloLink {
|
|
55
|
+
|
|
56
|
+
// constructor( options ) {
|
|
57
|
+
constructor( { socketUri, authEndpoint, appKey = 'app-key' } ) {
|
|
58
|
+
console.log( 'PusherLink::constructor()...' );
|
|
59
|
+
super();
|
|
60
|
+
|
|
61
|
+
this.socketUri = socketUri;
|
|
62
|
+
this.authEndpoint = authEndpoint;
|
|
63
|
+
this.appKey = appKey;
|
|
64
|
+
|
|
65
|
+
this.setAuthToken( '' );
|
|
66
|
+
this.setTransport( this.getSocketUri() );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {string} socketUri
|
|
72
|
+
*/
|
|
73
|
+
setTransport ( socketUri ) {
|
|
74
|
+
|
|
75
|
+
console.log( `Connecting to socket endpoint ${ socketUri }...` );
|
|
76
|
+
|
|
77
|
+
const wsPath = parse( socketUri );
|
|
78
|
+
|
|
79
|
+
if ( ![ 'ws', 'wss' ].includes( wsPath.scheme ) ) {
|
|
80
|
+
throw new CodeException( 'Incorrect scheme for the socket' );
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.transport = new Pusher( this.appKey, {
|
|
84
|
+
auth: {
|
|
85
|
+
headers: {
|
|
86
|
+
'X-Auth-Token': this.getAuthToken(),
|
|
87
|
+
Accept: 'application/json'
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
wsHost: wsPath.host,
|
|
91
|
+
wsPort: wsPath.port,
|
|
92
|
+
forceTLS: wsPath.scheme === 'wss',
|
|
93
|
+
encrypted: true,
|
|
94
|
+
enabledTransports: [ wsPath.scheme ],
|
|
95
|
+
authEndpoint: this.authEndpoint
|
|
96
|
+
} );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
disconnect() {
|
|
100
|
+
this.transport.disconnect();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param {string} name
|
|
106
|
+
* @returns {Channel|null}
|
|
107
|
+
*/
|
|
108
|
+
channel( name ) {
|
|
109
|
+
return this.transport.channel( name ) || null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @return {string}
|
|
115
|
+
*/
|
|
116
|
+
getAuthToken () {
|
|
117
|
+
return this.auth;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {string} auth
|
|
122
|
+
*/
|
|
123
|
+
setAuthToken ( auth ) {
|
|
124
|
+
this.auth = auth;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @return {string|null}
|
|
129
|
+
*/
|
|
130
|
+
getSocketUri () {
|
|
131
|
+
return this.socketUri;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
request( operation, forward ) {
|
|
135
|
+
this.transport.config.auth.headers[ 'X-Auth-Token' ] = this.getAuthToken();
|
|
136
|
+
|
|
137
|
+
const subscribeObservable = new Observable( ( _observer ) => {
|
|
138
|
+
//
|
|
139
|
+
} );
|
|
140
|
+
|
|
141
|
+
// Capture the super method
|
|
142
|
+
const prevSubscribe = subscribeObservable.subscribe.bind( subscribeObservable );
|
|
143
|
+
|
|
144
|
+
// Override subscribe to return an `unsubscribe` object, see
|
|
145
|
+
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L182-L212
|
|
146
|
+
subscribeObservable.subscribe = ( observerOrNext, onError, onComplete ) => {
|
|
147
|
+
prevSubscribe( observerOrNext, onError, onComplete );
|
|
148
|
+
|
|
149
|
+
const observer = getObserver( observerOrNext, onError, onComplete );
|
|
150
|
+
|
|
151
|
+
let subscriptionChannel;
|
|
152
|
+
|
|
153
|
+
forward( operation ).subscribe({
|
|
154
|
+
next: ( data ) => {
|
|
155
|
+
// If the operation has the subscription channel, it's a subscription
|
|
156
|
+
subscriptionChannel = data?.extensions?.lighthouse_subscriptions.channel ?? null;
|
|
157
|
+
|
|
158
|
+
// No subscription found in the response, pipe data through
|
|
159
|
+
if ( !subscriptionChannel ) {
|
|
160
|
+
observer.next( data );
|
|
161
|
+
observer.complete();
|
|
162
|
+
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.subscribeToChannel( subscriptionChannel, observer );
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Return an object that will unsubscribe_if the query was a subscription
|
|
171
|
+
return {
|
|
172
|
+
closed: false,
|
|
173
|
+
unsubscribe: () => {
|
|
174
|
+
subscriptionChannel &&
|
|
175
|
+
this.unsubscribeFromChannel( subscriptionChannel );
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return subscribeObservable;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
subscribeToChannel( subscriptionChannel, observer ) {
|
|
184
|
+
this.transport
|
|
185
|
+
.subscribe( subscriptionChannel )
|
|
186
|
+
.bind('lighthouse-subscription', ( payload ) => {
|
|
187
|
+
if ( !payload.more ) {
|
|
188
|
+
this.unsubscribeFromChannel( subscriptionChannel );
|
|
189
|
+
|
|
190
|
+
observer.complete();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const result = payload.result;
|
|
194
|
+
|
|
195
|
+
if (result) {
|
|
196
|
+
observer.next( result );
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
unsubscribeFromChannel( subscriptionChannel ) {
|
|
202
|
+
this.transport.unsubscribe( subscriptionChannel );
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Turn `subscribe` arguments into an observer-like thing, see getObserver
|
|
207
|
+
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L329-L343
|
|
208
|
+
function getObserver( observerOrNext, onError, onComplete ) {
|
|
209
|
+
if ( typeof observerOrNext === 'function' ) {
|
|
210
|
+
// Duck-type an observer
|
|
211
|
+
return {
|
|
212
|
+
next: ( v ) => observerOrNext( v ),
|
|
213
|
+
error: ( e ) => onError && onError( e ),
|
|
214
|
+
complete: () => onComplete && onComplete()
|
|
215
|
+
};
|
|
216
|
+
} else {
|
|
217
|
+
// Make an object that calls to the given object, with safety checks
|
|
218
|
+
return {
|
|
219
|
+
next: ( v ) => observerOrNext.next && observerOrNext.next( v ),
|
|
220
|
+
error: ( e ) => observerOrNext.error && observerOrNext.error( e ),
|
|
221
|
+
complete: () => observerOrNext.complete && observerOrNext.complete()
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export default PusherLink;
|
|
@@ -48,6 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
|
48
48
|
import Response from './Response';
|
|
49
49
|
import Query from '../query/Query';
|
|
50
50
|
import Wallet from '../Wallet';
|
|
51
|
+
import TokenUnit from '../TokenUnit';
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* Response for Wallet List query
|
|
@@ -110,7 +111,11 @@ export default class ResponseWalletList extends Response {
|
|
|
110
111
|
wallet.tokenFungibility = data.token.fungibility;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
if ( data.tokenUnits.length ) {
|
|
115
|
+
for ( let tokenUnitData of data.tokenUnits ) {
|
|
116
|
+
wallet.tokenUnits.push( TokenUnit.createFromGraphQL( tokenUnitData ) );
|
|
117
|
+
}
|
|
118
|
+
}
|
|
114
119
|
wallet.molecules = data.molecules;
|
|
115
120
|
wallet.balance = Number( data.amount );
|
|
116
121
|
wallet.pubkey = data.pubkey;
|