@wishknish/knishio-client-js 0.4.39 → 0.4.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishknish/knishio-client-js",
3
- "version": "0.4.39",
3
+ "version": "0.4.42",
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",
@@ -45,6 +45,7 @@
45
45
  "base-x": "^3.0.8",
46
46
  "big-integer": "^1.6.48",
47
47
  "buffer": "^6.0.3",
48
+ "core-js": "3.21.1",
48
49
  "get-random-values": "^1.2.2",
49
50
  "graphql": "^15.5.0",
50
51
  "isomorphic-fetch": "^3.0.0",
@@ -58,50 +59,48 @@
58
59
  "/src"
59
60
  ],
60
61
  "devDependencies": {
61
- "@babel/core": "^7.12.13",
62
- "@babel/plugin-external-helpers": "^7.12.13",
63
- "@babel/plugin-proposal-class-properties": "^7.12.13",
64
- "@babel/plugin-proposal-decorators": "^7.12.13",
65
- "@babel/plugin-proposal-do-expressions": "^7.12.13",
66
- "@babel/plugin-proposal-export-default-from": "^7.12.13",
67
- "@babel/plugin-proposal-export-namespace-from": "^7.12.13",
68
- "@babel/plugin-proposal-function-bind": "^7.12.13",
69
- "@babel/plugin-proposal-function-sent": "^7.12.13",
70
- "@babel/plugin-proposal-json-strings": "^7.12.13",
71
- "@babel/plugin-proposal-logical-assignment-operators": "^7.12.13",
72
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
73
- "@babel/plugin-proposal-numeric-separator": "^7.12.13",
74
- "@babel/plugin-proposal-optional-chaining": "^7.12.13",
75
- "@babel/plugin-proposal-pipeline-operator": "^7.12.13",
76
- "@babel/plugin-proposal-throw-expressions": "^7.12.13",
62
+ "@babel/core": "^7.17.8",
63
+ "@babel/eslint-parser": "^7.17.0",
64
+ "@babel/eslint-plugin": "^7.17.7",
65
+ "@babel/plugin-external-helpers": "^7.16.7",
66
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
67
+ "@babel/plugin-proposal-decorators": "^7.17.8",
68
+ "@babel/plugin-proposal-do-expressions": "^7.16.7",
69
+ "@babel/plugin-proposal-export-default-from": "^7.16.7",
70
+ "@babel/plugin-proposal-export-namespace-from": "^7.16.7",
71
+ "@babel/plugin-proposal-function-bind": "^7.16.7",
72
+ "@babel/plugin-proposal-function-sent": "^7.16.7",
73
+ "@babel/plugin-proposal-json-strings": "^7.16.7",
74
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.16.7",
75
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
76
+ "@babel/plugin-proposal-numeric-separator": "^7.16.7",
77
+ "@babel/plugin-proposal-optional-chaining": "^7.16.7",
78
+ "@babel/plugin-proposal-pipeline-operator": "^7.17.6",
79
+ "@babel/plugin-proposal-throw-expressions": "^7.16.7",
77
80
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
78
- "@babel/plugin-syntax-import-meta": "^7.0.0",
79
- "@babel/plugin-transform-arrow-functions": "^7.12.13",
80
- "@babel/plugin-transform-async-to-generator": "^7.12.13",
81
- "@babel/plugin-transform-classes": "^7.12.13",
82
- "@babel/plugin-transform-for-of": "^7.12.13",
83
- "@babel/plugin-transform-property-mutators": "^7.12.13",
81
+ "@babel/plugin-syntax-import-meta": "^7.10.4",
82
+ "@babel/plugin-transform-arrow-functions": "^7.16.7",
83
+ "@babel/plugin-transform-async-to-generator": "^7.16.8",
84
+ "@babel/plugin-transform-classes": "^7.16.7",
85
+ "@babel/plugin-transform-for-of": "^7.16.7",
86
+ "@babel/plugin-transform-property-mutators": "^7.16.7",
84
87
  "@babel/plugin-transform-runtime": "^7.12.15",
85
88
  "@babel/plugin-transform-shorthand-properties": "^7.12.13",
86
- "@babel/polyfill": "^7.12.1",
87
89
  "@babel/preset-env": "^7.12.13",
88
90
  "@babel/runtime": "^7.12.13",
89
91
  "@rollup/plugin-babel": "^5.2.3",
90
92
  "@rollup/plugin-commonjs": "^19.0.0",
93
+ "@rollup/plugin-inject": "^4.0.4",
91
94
  "@rollup/plugin-node-resolve": "^13.0.0",
92
- "babel-eslint": "^10.1.0",
95
+ "@rollup/plugin-replace": "^4.0.0",
93
96
  "babel-loader": "^8.2.2",
94
- "babel-preset-es2015-rollup": "^3.0.0",
95
97
  "eslint": "^7.23.0",
96
98
  "eslint-plugin-vue": "^7.8.0",
97
- "nodemon": "^2.0.7",
98
- "rollup": "^2.38.5",
99
- "rollup-plugin-node-polyfills": "^0.2.1",
99
+ "nodemon": "^2.0.15",
100
+ "rollup": "^2.70.1",
100
101
  "rollup-plugin-peer-deps-external": "^2.2.4",
101
- "rollup-plugin-replace": "^2.2.0",
102
102
  "rollup-plugin-terser": "^7.0.2",
103
- "rollup-plugin-uglify": "^6.0.4",
104
- "uglify-es": "^3.3.9",
103
+ "uglify-js": "^3.15.3",
105
104
  "webpack": "^5.21.1",
106
105
  "webpack-cli": "^4.5.0",
107
106
  "webpack-merge": "^5.7.3"
package/src/Atom.js CHANGED
@@ -319,6 +319,11 @@ export default class Atom {
319
319
  continue;
320
320
  }
321
321
 
322
+ // Excluded keys
323
+ if ( [ 'otsFragment', 'index' ].includes( property ) ) {
324
+ continue;
325
+ }
326
+
322
327
  // Hashing individual meta keys and values
323
328
  if ( property === 'meta' ) {
324
329
  for ( const meta of value ) {
@@ -93,6 +93,7 @@ import QueryAtom from './query/QueryAtom';
93
93
  import QueryPolicy from './query/QueryPolicy';
94
94
  import MutationCreatePolicy from './mutation/MutationCreatePolicy';
95
95
  import QueryMetaTypeViaAtom from './query/QueryMetaTypeViaAtom';
96
+ import MutationCreateRule from './mutation/MutationCreateRule';
96
97
 
97
98
 
98
99
  /**
@@ -153,7 +154,7 @@ export default class KnishIOClient {
153
154
  this.$__authTokenObjects = {};
154
155
  this.$__authInProcess = false;
155
156
 
156
- if( cellSlug ) {
157
+ if ( cellSlug ) {
157
158
  this.setCellSlug( cellSlug );
158
159
  }
159
160
 
@@ -460,30 +461,29 @@ export default class KnishIOClient {
460
461
  console.info( 'KnishIOClient::createMolecule() - Creating a new molecule...' );
461
462
  }
462
463
 
463
- const _secret = secret || this.getSecret();
464
- let _sourceWallet = sourceWallet;
464
+ secret = secret || this.getSecret();
465
465
 
466
466
  // Sets the source wallet as the last remainder wallet (to maintain ContinuID)
467
- if ( !sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet().token !== 'AUTH' && this.lastMoleculeQuery && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response().success() ) {
468
- _sourceWallet = this.getRemainderWallet();
467
+ if ( !sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet().token !== 'AUTH' && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response().success() ) {
468
+ sourceWallet = this.getRemainderWallet();
469
469
  }
470
470
 
471
471
  // Unable to use last remainder wallet; Figure out what wallet to use:
472
- if ( _sourceWallet === null ) {
473
- _sourceWallet = await this.getSourceWallet();
472
+ if ( sourceWallet === null ) {
473
+ sourceWallet = await this.getSourceWallet();
474
474
  }
475
475
 
476
476
  // Set the remainder wallet for the next transaction
477
477
  this.remainderWallet = remainderWallet || Wallet.create( {
478
- secretOrBundle: _secret,
478
+ secretOrBundle: secret,
479
479
  token: 'USER',
480
- batchId: _sourceWallet.batchId,
481
- characters: _sourceWallet.characters
480
+ batchId: sourceWallet.batchId,
481
+ characters: sourceWallet.characters
482
482
  } );
483
483
 
484
484
  return new Molecule( {
485
- secret: _secret,
486
- sourceWallet: _sourceWallet,
485
+ secret,
486
+ sourceWallet,
487
487
  remainderWallet: this.getRemainderWallet(),
488
488
  cellSlug: this.cellSlug()
489
489
  } );
@@ -546,15 +546,17 @@ export default class KnishIOClient {
546
546
  * @returns {Promise<*>}
547
547
  */
548
548
  async executeQuery ( query, variables = null ) {
549
- /*
550
- if ( true || this.$__authToken && this.$__authToken.isExpired() ) {
549
+ // console.info( `KnishIOClient::executeQuery() - Check token expiration... ${ this.$__authToken.$__expiresAt * 1000 } == ${ Date.now() } ` );
550
+ if ( this.$__authToken && this.$__authToken.isExpired() ) {
551
+ console.info( 'KnishIOClient::executeQuery() - Access token is expired. Getting new one...' );
552
+
551
553
  await this.requestAuthToken( {
552
554
  secret: this.$__secret,
553
555
  cellSlug: this.$__cellSlug,
554
556
  encrypt: this.$__encrypt
555
557
  } );
556
558
  }
557
- */
559
+
558
560
  return query.execute( {
559
561
  variables
560
562
  } );
@@ -691,34 +693,6 @@ export default class KnishIOClient {
691
693
  this.subscribe().unsubscribeAll();
692
694
  }
693
695
 
694
-
695
- /**
696
- * @param {string} metaType
697
- * @param {string} metaId
698
- * @param {object[]|null} filter
699
- * @param {object[]|null} queryArgs
700
- * @returns {Promise<ResponseAtom>}
701
- */
702
- async queryMetaViaAtom ( {
703
- metaType,
704
- metaId,
705
- filter = null,
706
- queryArgs = {
707
- limit: 15,
708
- offset: 1
709
- }
710
- } ) {
711
-
712
- return await this.queryAtom( {
713
- metaType,
714
- metaId,
715
- filter,
716
- isotopes: [ 'C', 'M' ],
717
- latest: true,
718
- queryArgs
719
- } );
720
- }
721
-
722
696
  /**
723
697
  * Retrieves metadata for the given metaType and provided parameters
724
698
  *
@@ -734,6 +708,9 @@ export default class KnishIOClient {
734
708
  * @param {string|null} count
735
709
  * @param {string|null} countBy
736
710
  * @param {boolean} throughAtom
711
+ * @param {array|null} values
712
+ * @param {array|null} keys
713
+ * @param {array|null} atomValues
737
714
  * @return {Promise<ResponseMetaType>}
738
715
  */
739
716
  queryMeta ( {
@@ -748,7 +725,10 @@ export default class KnishIOClient {
748
725
  queryArgs = null,
749
726
  count = null,
750
727
  countBy = null,
751
- throughAtom = false
728
+ throughAtom = false,
729
+ values = null,
730
+ keys = null,
731
+ atomValues = null
752
732
  } ) {
753
733
 
754
734
  if ( this.$__logging ) {
@@ -772,7 +752,10 @@ export default class KnishIOClient {
772
752
  latestMetas,
773
753
  filter,
774
754
  queryArgs,
775
- countBy
755
+ countBy,
756
+ values,
757
+ keys,
758
+ atomValues
776
759
  } );
777
760
  } else {
778
761
  /**
@@ -1195,6 +1178,42 @@ export default class KnishIOClient {
1195
1178
  return await this.executeQuery( query );
1196
1179
  }
1197
1180
 
1181
+ /**
1182
+ *
1183
+ * @param {string} metaType
1184
+ * @param {string} metaId
1185
+ * @param {object[]} rule
1186
+ * @param {object} policy
1187
+ * @returns {Promise<ResponseCreateRule>}
1188
+ */
1189
+ async createRule ( {
1190
+ metaType,
1191
+ metaId,
1192
+ rule,
1193
+ policy = {}
1194
+ } ) {
1195
+ /**
1196
+ * @type {MutationCreateRule}
1197
+ */
1198
+ const query = await this.createMoleculeMutation( {
1199
+ mutationClass: MutationCreateRule,
1200
+ molecule: await this.createMolecule( {
1201
+ secret: this.getSecret(),
1202
+ sourceWallet: await this.getSourceWallet()
1203
+ } )
1204
+ }
1205
+ );
1206
+
1207
+ query.fillMolecule( {
1208
+ metaType,
1209
+ metaId,
1210
+ rule,
1211
+ policy
1212
+ } );
1213
+
1214
+ return await this.executeQuery( query );
1215
+ }
1216
+
1198
1217
  /**
1199
1218
  * Builds and executes a molecule to convey new metadata to the ledger
1200
1219
  *
@@ -1776,6 +1795,66 @@ export default class KnishIOClient {
1776
1795
  }
1777
1796
 
1778
1797
 
1798
+
1799
+ /**
1800
+ * Builds and executes a molecule to destroy the specified Token units
1801
+ *
1802
+ * @param {string} token
1803
+ * @param {number|null} amount
1804
+ * @param {array|null} units
1805
+ * @param {Wallet|null} sourceWallet
1806
+ * @return {Promise<unknown>}
1807
+ */
1808
+ async replenishToken ( {
1809
+ token,
1810
+ amount = null,
1811
+ units = [],
1812
+ sourceWallet = null
1813
+ } ) {
1814
+
1815
+
1816
+ if ( sourceWallet === null ) {
1817
+ sourceWallet = ( await this.queryBalance( { token } ) ).payload();
1818
+ }
1819
+ /*
1820
+ if ( !sourceWallet ) {
1821
+ throw new TransferWalletException( 'Source wallet is missing or invalid.' );
1822
+ }
1823
+ */
1824
+
1825
+ // Remainder wallet
1826
+ let remainderWallet = Wallet.create( {
1827
+ secretOrBundle: this.getSecret(),
1828
+ token,
1829
+ characters: sourceWallet.characters
1830
+ } );
1831
+
1832
+ // Batch ID default initialization
1833
+ remainderWallet.initBatchId( {
1834
+ sourceWallet,
1835
+ isRemainder: true
1836
+ } );
1837
+
1838
+
1839
+ // Burn tokens
1840
+ let molecule = await this.createMolecule( {
1841
+ secret: null,
1842
+ sourceWallet,
1843
+ remainderWallet
1844
+ } );
1845
+ molecule.replenishToken( {
1846
+ amount,
1847
+ units
1848
+ } );
1849
+ molecule.sign( {} );
1850
+ molecule.check();
1851
+
1852
+
1853
+ const query = ( new MutationProposeMolecule( this.client(), molecule ) );
1854
+ return this.executeQuery( query );
1855
+ }
1856
+
1857
+
1779
1858
  /**
1780
1859
  * Request a guest auth token
1781
1860
  *
@@ -1803,7 +1882,7 @@ export default class KnishIOClient {
1803
1882
  /**
1804
1883
  * @type {ResponseRequestAuthorizationGuest}
1805
1884
  */
1806
- const response = await this.executeQuery( query, {
1885
+ const response = await query.execute( {
1807
1886
  cellSlug,
1808
1887
  pubkey: wallet.pubkey,
1809
1888
  encrypt
@@ -1864,7 +1943,8 @@ export default class KnishIOClient {
1864
1943
  /**
1865
1944
  * @type {ResponseRequestAuthorization}
1866
1945
  */
1867
- const response = await this.executeQuery( query );
1946
+ const response = await query.execute( {} );
1947
+
1868
1948
 
1869
1949
  // Did the authorization molecule get accepted?
1870
1950
  if ( response.success() ) {
@@ -1936,7 +2016,7 @@ export default class KnishIOClient {
1936
2016
 
1937
2017
  // Set auth token
1938
2018
  if ( this.$__logging ) {
1939
- console.info( `KnishIOClient::authorize() - Successfully retrieved auth token ${ this.$__authToken.token }...` );
2019
+ console.info( `KnishIOClient::authorize() - Successfully retrieved auth token ${ this.$__authToken.getToken() }...` );
1940
2020
  }
1941
2021
 
1942
2022
  // Switch encryption mode if it has been changed
package/src/Meta.js CHANGED
@@ -119,35 +119,23 @@ export default class Meta {
119
119
  */
120
120
  static policy ( meta, policy ) {
121
121
  const metas = {
122
- conditions: 'policy',
123
- rule: meta[ 'rule' ] || [],
124
- callback: meta[ 'callback' ] || {}
122
+ policy: {}
125
123
  };
126
124
 
127
125
  if ( policy ) {
128
126
  for ( const [ policyKey, value ] of Object.entries( policy || {} ) ) {
129
127
 
130
128
  if ( value !== null && [ 'read', 'write' ].includes( policyKey ) ) {
131
- metas[ 'callback' ][ policyKey ] = {};
129
+ metas.policy[ policyKey ] = {};
132
130
 
133
131
  for ( const [ key, content ] of Object.entries( value ) ) {
134
- metas[ 'callback' ][ policyKey ][ key ] = content;
132
+ metas.policy[ policyKey ][ key ] = content;
135
133
  }
136
134
  }
137
135
  }
138
136
  }
139
137
 
140
- metas[ 'callback' ] = Meta.__defaultPolicy( metas[ 'callback' ], meta );
141
-
142
- for ( const policyKey of [ 'conditions', 'rule', 'callback' ] ) {
143
- metas[ policyKey ] = Array.isArray( metas[ policyKey ] ) ||
144
- Object.prototype.toString.call( metas[ policyKey ] ) === '[object Object]' ?
145
- JSON.stringify( metas[ policyKey ] ) : metas[ policyKey ];
146
-
147
- if ( policyKey === 'conditions' && Object.prototype.toString.call( metas[ policyKey ] ) === '[object String]' ) {
148
- metas[ policyKey ] = JSON.stringify( metas[ policyKey ] );
149
- }
150
- }
138
+ metas.policy = JSON.stringify( Meta.__defaultPolicy( metas.policy, meta ) );
151
139
 
152
140
  return metas;
153
141
  }