@wishknish/knishio-client-js 0.5.2 → 0.6.1

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.
Files changed (133) hide show
  1. package/README.md +207 -274
  2. package/dist/client.iife.js +533 -0
  3. package/package.json +37 -79
  4. package/src/.babelrc +0 -22
  5. package/src/Atom.js +171 -132
  6. package/src/AtomMeta.js +76 -50
  7. package/src/AuthToken.js +38 -47
  8. package/src/KnishIOClient.js +934 -987
  9. package/src/Meta.js +15 -17
  10. package/src/Molecule.js +423 -494
  11. package/src/PolicyMeta.js +32 -41
  12. package/src/TokenUnit.js +30 -32
  13. package/src/Wallet.js +275 -265
  14. package/src/exception/AtomIndexException.js +4 -8
  15. package/src/exception/AtomsMissingException.js +4 -6
  16. package/src/exception/AuthorizationRejectedException.js +4 -5
  17. package/src/exception/BalanceInsufficientException.js +4 -8
  18. package/src/exception/BaseException.js +6 -8
  19. package/src/exception/BatchIdException.js +5 -7
  20. package/src/exception/CodeException.js +4 -8
  21. package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
  22. package/src/exception/InvalidResponseException.js +4 -5
  23. package/src/exception/MetaMissingException.js +4 -6
  24. package/src/exception/MolecularHashMismatchException.js +4 -6
  25. package/src/exception/MolecularHashMissingException.js +4 -5
  26. package/src/exception/NegativeAmountException.js +4 -5
  27. package/src/exception/PolicyInvalidException.js +4 -4
  28. package/src/exception/SignatureMalformedException.js +4 -5
  29. package/src/exception/SignatureMismatchException.js +4 -5
  30. package/src/exception/StackableUnitAmountException.js +4 -5
  31. package/src/exception/StackableUnitDecimalsException.js +4 -5
  32. package/src/exception/TransferBalanceException.js +4 -5
  33. package/src/exception/TransferMalformedException.js +4 -5
  34. package/src/exception/TransferMismatchedException.js +4 -5
  35. package/src/exception/TransferRemainderException.js +4 -5
  36. package/src/exception/TransferToSelfException.js +4 -5
  37. package/src/exception/TransferUnbalancedException.js +4 -5
  38. package/src/exception/UnauthenticatedException.js +4 -5
  39. package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
  40. package/src/exception/WalletShadowException.js +4 -5
  41. package/src/exception/WrongTokenTypeException.js +4 -5
  42. package/src/exception/index.js +26 -26
  43. package/src/index.js +8 -10
  44. package/src/instance/Rules/Callback.js +91 -93
  45. package/src/instance/Rules/Condition.js +21 -23
  46. package/src/instance/Rules/Meta.js +13 -14
  47. package/src/instance/Rules/Rule.js +39 -43
  48. package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
  49. package/src/libraries/CheckMolecule.js +253 -232
  50. package/src/libraries/Decimal.js +13 -17
  51. package/src/libraries/Dot.js +74 -48
  52. package/src/libraries/Hex.js +49 -54
  53. package/src/libraries/array.js +50 -41
  54. package/src/libraries/crypto.js +20 -27
  55. package/src/libraries/strings.js +58 -91
  56. package/src/libraries/urql/UrqlClientWrapper.js +166 -0
  57. package/src/mutation/Mutation.js +44 -25
  58. package/src/mutation/MutationActiveSession.js +12 -12
  59. package/src/mutation/MutationClaimShadowWallet.js +15 -17
  60. package/src/mutation/MutationCreateIdentifier.js +11 -12
  61. package/src/mutation/MutationCreateMeta.js +11 -12
  62. package/src/mutation/MutationCreateRule.js +11 -12
  63. package/src/mutation/MutationCreateToken.js +18 -13
  64. package/src/mutation/MutationCreateWallet.js +9 -11
  65. package/src/mutation/MutationDepositBufferToken.js +7 -9
  66. package/src/mutation/MutationLinkIdentifier.js +12 -14
  67. package/src/mutation/MutationProposeMolecule.js +24 -25
  68. package/src/mutation/MutationRequestAuthorization.js +9 -10
  69. package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
  70. package/src/mutation/MutationRequestTokens.js +11 -14
  71. package/src/mutation/MutationTransferTokens.js +11 -14
  72. package/src/mutation/MutationWithdrawBufferToken.js +7 -10
  73. package/src/query/Query.js +62 -36
  74. package/src/query/QueryActiveSession.js +11 -13
  75. package/src/query/QueryAtom.js +75 -76
  76. package/src/query/QueryBalance.js +11 -12
  77. package/src/query/QueryBatch.js +17 -14
  78. package/src/query/QueryBatchHistory.js +16 -13
  79. package/src/query/QueryContinuId.js +13 -10
  80. package/src/query/QueryMetaType.js +45 -57
  81. package/src/query/QueryMetaTypeViaAtom.js +49 -57
  82. package/src/query/QueryPolicy.js +11 -12
  83. package/src/query/QueryToken.js +11 -13
  84. package/src/query/QueryUserActivity.js +11 -13
  85. package/src/query/QueryWalletBundle.js +15 -47
  86. package/src/query/QueryWalletList.js +15 -16
  87. package/src/response/Response.js +29 -34
  88. package/src/response/ResponseActiveSession.js +6 -6
  89. package/src/response/ResponseAtom.js +29 -30
  90. package/src/response/ResponseAuthorizationGuest.js +17 -18
  91. package/src/response/ResponseBalance.js +12 -13
  92. package/src/response/ResponseClaimShadowWallet.js +1 -1
  93. package/src/response/ResponseContinuId.js +21 -22
  94. package/src/response/ResponseCreateIdentifier.js +1 -1
  95. package/src/response/ResponseCreateMeta.js +1 -1
  96. package/src/response/ResponseCreateRule.js +1 -1
  97. package/src/response/ResponseCreateToken.js +1 -1
  98. package/src/response/ResponseCreateWallet.js +1 -1
  99. package/src/response/ResponseLinkIdentifier.js +9 -10
  100. package/src/response/ResponseMetaBatch.js +6 -8
  101. package/src/response/ResponseMetaType.js +19 -20
  102. package/src/response/ResponseMetaTypeViaAtom.js +19 -19
  103. package/src/response/ResponsePolicy.js +14 -15
  104. package/src/response/ResponseProposeMolecule.js +27 -30
  105. package/src/response/ResponseQueryActiveSession.js +20 -23
  106. package/src/response/ResponseQueryUserActivity.js +11 -12
  107. package/src/response/ResponseRequestAuthorization.js +11 -16
  108. package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
  109. package/src/response/ResponseRequestTokens.js +1 -1
  110. package/src/response/ResponseTransferTokens.js +8 -9
  111. package/src/response/ResponseWalletBundle.js +16 -17
  112. package/src/response/ResponseWalletList.js +44 -47
  113. package/src/subscribe/ActiveSessionSubscribe.js +5 -6
  114. package/src/subscribe/ActiveWalletSubscribe.js +5 -6
  115. package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
  116. package/src/subscribe/Subscribe.js +26 -26
  117. package/src/subscribe/WalletStatusSubscribe.js +5 -6
  118. package/src/versions/HashAtom.js +78 -0
  119. package/src/versions/Version4.js +34 -0
  120. package/src/versions/index.js +5 -0
  121. package/dist/client.umd.js +0 -453
  122. package/src/httpClient/ApolloClient.js +0 -245
  123. package/src/libraries/ApolloLink/CipherLink.js +0 -117
  124. package/src/libraries/ApolloLink/Client.js +0 -231
  125. package/src/libraries/ApolloLink/PusherLink.js +0 -234
  126. package/src/libraries/ApolloLink/handler.js +0 -106
  127. package/src/libraries/Base58.js +0 -71
  128. package/src/libraries/Base64.js +0 -40
  129. package/src/libraries/BaseX.js +0 -91
  130. package/src/libraries/Soda.js +0 -93
  131. package/src/query/QueryMetaInstance.js +0 -99
  132. package/src/test/Test.js +0 -670
  133. package/src/test/TestTokenUnit.js +0 -340
package/src/PolicyMeta.js CHANGED
@@ -46,87 +46,78 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
46
46
  License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
47
  */
48
48
 
49
- import {
50
- diff
51
- } from './libraries/array';
52
-
49
+ import { diff } from './libraries/array'
53
50
 
54
51
  /**
55
52
  *
56
53
  */
57
54
  export default class PolicyMeta {
58
-
59
55
  /**
60
56
  *
61
57
  * @param policy
62
- * @returns {{}}
58
+ * @param metaKeys
63
59
  */
64
- static normalizePolicy( policy = {} ) {
65
- let policyMeta = {};
66
- for ( const [ policyKey, value ] of Object.entries( policy ) ) {
67
- if ( value !== null && [ 'read', 'write' ].includes( policyKey ) ) {
68
-
69
- policyMeta[ policyKey ] = {};
70
- for ( const [ key, content ] of Object.entries( value ) ) {
71
- policyMeta[ policyKey ][ key ] = content;
72
- }
73
- }
74
- }
75
- return policyMeta;
60
+ constructor (policy = {}, metaKeys = {}) {
61
+ this.policy = PolicyMeta.normalizePolicy(policy)
62
+ this.fillDefault(metaKeys)
76
63
  }
77
64
 
78
65
  /**
79
66
  *
80
67
  * @param policy
81
- * @param metaKeys
68
+ * @returns {{}}
82
69
  */
83
- constructor( policy = {}, metaKeys = {} ) {
84
- this.policy = PolicyMeta.normalizePolicy( policy );
85
- this.fillDefault( metaKeys );
70
+ static normalizePolicy (policy = {}) {
71
+ const policyMeta = {}
72
+ for (const [policyKey, value] of Object.entries(policy)) {
73
+ if (value !== null && ['read', 'write'].includes(policyKey)) {
74
+ policyMeta[policyKey] = {}
75
+ for (const [key, content] of Object.entries(value)) {
76
+ policyMeta[policyKey][key] = content
77
+ }
78
+ }
79
+ }
80
+ return policyMeta
86
81
  }
87
82
 
88
83
  /**
89
84
  *
90
85
  */
91
- fillDefault( metaKeys = {} ) {
92
- const readPolicy = Array.from( this.policy ).filter( item => item.action === 'read' );
93
- const writePolicy = Array.from( this.policy ).filter( item => item.action === 'write' );
86
+ fillDefault (metaKeys = {}) {
87
+ const readPolicy = Array.from(this.policy).filter(item => item.action === 'read')
88
+ const writePolicy = Array.from(this.policy).filter(item => item.action === 'write')
94
89
 
95
- for ( const [ type, value ] of Object.entries( {
90
+ for (const [type, value] of Object.entries({
96
91
  read: readPolicy,
97
92
  write: writePolicy
98
- } ) ) {
93
+ })) {
94
+ const policyKey = value.map(item => item.key)
99
95
 
100
- const policyKey = value.map( item => item.key );
101
-
102
- if ( !this.policy[ type ] ) {
103
- this.policy[ type ] = {};
96
+ if (!this.policy[type]) {
97
+ this.policy[type] = {}
104
98
  }
105
99
 
106
- for ( const key of diff( metaKeys, policyKey ) ) {
107
- if ( !this.policy[ type ][ key ] ) {
108
- this.policy[ type ][ key ] = ( type === 'write' && ![ 'characters', 'pubkey' ].includes( key ) ) ? [ 'self' ] : [ 'all' ];
100
+ for (const key of diff(metaKeys, policyKey)) {
101
+ if (!this.policy[type][key]) {
102
+ this.policy[type][key] = (type === 'write' && !['characters', 'pubkey'].includes(key)) ? ['self'] : ['all']
109
103
  }
110
104
  }
111
105
  }
112
106
  }
113
107
 
114
-
115
108
  /**
116
109
  *
117
110
  * @returns {{}|*}
118
111
  */
119
- get() {
120
- return this.policy;
112
+ get () {
113
+ return this.policy
121
114
  }
122
115
 
123
-
124
116
  /**
125
117
  *
126
118
  * @returns {string}
127
119
  */
128
- toJson() {
129
- return JSON.stringify( this.get() );
120
+ toJson () {
121
+ return JSON.stringify(this.get())
130
122
  }
131
-
132
123
  }
package/src/TokenUnit.js CHANGED
@@ -50,25 +50,36 @@ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
50
50
  * AuthToken class
51
51
  */
52
52
  export default class TokenUnit {
53
+ /**
54
+ *
55
+ * @param id
56
+ * @param name
57
+ * @param metas
58
+ */
59
+ constructor (id, name, metas) {
60
+ this.id = id
61
+ this.name = name
62
+ this.metas = metas || {}
63
+ }
53
64
 
54
65
  /**
55
66
  *
56
67
  * @param data
57
68
  * @returns {*}
58
69
  */
59
- static createFromGraphQL ( data ) {
60
- let metas = data[ 'metas' ] || {};
61
- if ( metas.length ) {
62
- metas = JSON.parse( metas );
63
- if ( !metas ) { // set an empty object instead of an array
64
- metas = {};
70
+ static createFromGraphQL (data) {
71
+ let metas = data.metas || {}
72
+ if (metas.length) {
73
+ metas = JSON.parse(metas)
74
+ if (!metas) { // set an empty object instead of an array
75
+ metas = {}
65
76
  }
66
77
  }
67
78
  return new TokenUnit(
68
- data[ 'id' ],
69
- data[ 'name' ],
79
+ data.id,
80
+ data.name,
70
81
  metas
71
- );
82
+ )
72
83
  }
73
84
 
74
85
  /**
@@ -76,24 +87,12 @@ export default class TokenUnit {
76
87
  * @param data
77
88
  * @returns {TokenUnit}
78
89
  */
79
- static createFromDB ( data ) {
90
+ static createFromDB (data) {
80
91
  return new TokenUnit(
81
- data[ 0 ],
82
- data[ 1 ],
83
- data.length > 2 ? data[ 2 ] : {}
84
- );
85
- }
86
-
87
- /**
88
- *
89
- * @param id
90
- * @param name
91
- * @param metas
92
- */
93
- constructor ( id, name, metas ) {
94
- this.id = id;
95
- this.name = name;
96
- this.metas = metas || {};
92
+ data[0],
93
+ data[1],
94
+ data.length > 2 ? data[2] : {}
95
+ )
97
96
  }
98
97
 
99
98
  /**
@@ -101,7 +100,7 @@ export default class TokenUnit {
101
100
  * @returns {*|null}
102
101
  */
103
102
  getFragmentZone () {
104
- return this.metas[ 'fragmentZone' ] || null;
103
+ return this.metas.fragmentZone || null
105
104
  }
106
105
 
107
106
  /**
@@ -109,14 +108,14 @@ export default class TokenUnit {
109
108
  * @returns {*|null}
110
109
  */
111
110
  getFusedTokenUnits () {
112
- return this.metas[ 'fusedTokenUnits' ] || null;
111
+ return this.metas.fusedTokenUnits || null
113
112
  }
114
113
 
115
114
  /**
116
115
  * @return array
117
116
  */
118
117
  toData () {
119
- return [ this.id, this.name, this.metas ];
118
+ return [this.id, this.name, this.metas]
120
119
  }
121
120
 
122
121
  /**
@@ -127,8 +126,7 @@ export default class TokenUnit {
127
126
  return {
128
127
  id: this.id,
129
128
  name: this.name,
130
- metas: JSON.stringify( this.metas )
131
- };
129
+ metas: JSON.stringify(this.metas)
130
+ }
132
131
  }
133
-
134
132
  }