@wishknish/knishio-client-js 0.8.1 → 0.8.2
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.cjs.js +4 -4
- package/dist/client.cjs.js.map +1 -1
- package/dist/client.es.mjs +37 -8
- package/dist/client.es.mjs.map +1 -1
- package/dist/client.iife.js +22 -22
- package/dist/client.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/Atom.js +18 -20
- package/src/KnishIOClient.js +3 -3
- package/src/Molecule.js +42 -38
- package/src/Wallet.js +3 -3
- package/src/instance/Rules/Callback.js +1 -0
- package/src/instance/Rules/Meta.js +1 -3
- package/src/instance/Rules/Rule.js +1 -0
- package/src/libraries/strings.js +1 -0
- package/src/libraries/urql/UrqlClientWrapper.js +41 -10
- package/src/query/QueryPolicy.js +1 -1
- package/src/response/Response.js +3 -3
- package/src/response/ResponseActiveSession.js +0 -1
- package/src/response/ResponseAtom.js +0 -1
- package/src/response/ResponseAuthorizationGuest.js +0 -1
- package/src/response/ResponseBalance.js +0 -1
- package/src/response/ResponseContinuId.js +0 -1
- package/src/response/ResponseLinkIdentifier.js +0 -1
- package/src/response/ResponseMetaType.js +0 -1
- package/src/response/ResponseMetaTypeViaAtom.js +0 -1
- package/src/response/ResponseMetaTypeViaMolecule.js +0 -1
- package/src/response/ResponsePolicy.js +0 -1
- package/src/response/ResponseQueryActiveSession.js +0 -1
- package/src/response/ResponseQueryUserActivity.js +0 -1
- package/src/response/ResponseWalletBundle.js +0 -1
- package/src/response/ResponseWalletList.js +0 -1
package/package.json
CHANGED
package/src/Atom.js
CHANGED
|
@@ -212,7 +212,7 @@ export default class Atom {
|
|
|
212
212
|
|
|
213
213
|
/**
|
|
214
214
|
* Returns JSON-ready object for cross-SDK compatibility (2025 JS best practices)
|
|
215
|
-
*
|
|
215
|
+
*
|
|
216
216
|
* Provides clean serialization of atomic operations with optional OTS fragments.
|
|
217
217
|
* Follows 2025 JavaScript best practices with proper type safety and validation.
|
|
218
218
|
*
|
|
@@ -226,15 +226,15 @@ export default class Atom {
|
|
|
226
226
|
const {
|
|
227
227
|
includeOtsFragments = true,
|
|
228
228
|
validateFields = false
|
|
229
|
-
} = options
|
|
229
|
+
} = options
|
|
230
230
|
|
|
231
231
|
try {
|
|
232
232
|
// Validate required fields if requested
|
|
233
233
|
if (validateFields) {
|
|
234
|
-
const requiredFields = ['position', 'walletAddress', 'isotope', 'token']
|
|
234
|
+
const requiredFields = ['position', 'walletAddress', 'isotope', 'token']
|
|
235
235
|
for (const field of requiredFields) {
|
|
236
236
|
if (!this[field]) {
|
|
237
|
-
throw new Error(`Required field '${field}' is missing or empty`)
|
|
237
|
+
throw new Error(`Required field '${field}' is missing or empty`)
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
}
|
|
@@ -258,23 +258,22 @@ export default class Atom {
|
|
|
258
258
|
index: this.index,
|
|
259
259
|
createdAt: this.createdAt,
|
|
260
260
|
version: this.version
|
|
261
|
-
}
|
|
261
|
+
}
|
|
262
262
|
|
|
263
263
|
// Optional OTS fragments (can be large, so optional)
|
|
264
264
|
if (includeOtsFragments && this.otsFragment) {
|
|
265
|
-
serialized.otsFragment = this.otsFragment
|
|
265
|
+
serialized.otsFragment = this.otsFragment
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
return serialized
|
|
269
|
-
|
|
268
|
+
return serialized
|
|
270
269
|
} catch (error) {
|
|
271
|
-
throw new Error(`Atom serialization failed: ${error.message}`)
|
|
270
|
+
throw new Error(`Atom serialization failed: ${error.message}`)
|
|
272
271
|
}
|
|
273
272
|
}
|
|
274
273
|
|
|
275
274
|
/**
|
|
276
275
|
* Creates an Atom instance from JSON data (2025 JS best practices)
|
|
277
|
-
*
|
|
276
|
+
*
|
|
278
277
|
* Handles cross-SDK atom deserialization with robust error handling.
|
|
279
278
|
* Essential for reconstructing atoms from other SDK implementations.
|
|
280
279
|
*
|
|
@@ -289,18 +288,18 @@ export default class Atom {
|
|
|
289
288
|
const {
|
|
290
289
|
validateStructure = true,
|
|
291
290
|
strictMode = false
|
|
292
|
-
} = options
|
|
291
|
+
} = options
|
|
293
292
|
|
|
294
293
|
try {
|
|
295
294
|
// Parse JSON safely
|
|
296
|
-
const data = typeof json === 'string' ? JSON.parse(json) : json
|
|
295
|
+
const data = typeof json === 'string' ? JSON.parse(json) : json
|
|
297
296
|
|
|
298
297
|
// Validate required fields in strict mode
|
|
299
298
|
if (strictMode || validateStructure) {
|
|
300
|
-
const requiredFields = ['position', 'walletAddress', 'isotope', 'token']
|
|
299
|
+
const requiredFields = ['position', 'walletAddress', 'isotope', 'token']
|
|
301
300
|
for (const field of requiredFields) {
|
|
302
301
|
if (!data[field]) {
|
|
303
|
-
throw new Error(`Required field '${field}' is missing or empty`)
|
|
302
|
+
throw new Error(`Required field '${field}' is missing or empty`)
|
|
304
303
|
}
|
|
305
304
|
}
|
|
306
305
|
}
|
|
@@ -318,20 +317,19 @@ export default class Atom {
|
|
|
318
317
|
meta: data.meta,
|
|
319
318
|
index: data.index,
|
|
320
319
|
version: data.version
|
|
321
|
-
})
|
|
320
|
+
})
|
|
322
321
|
|
|
323
322
|
// Set additional properties that may not be in constructor
|
|
324
323
|
if (data.otsFragment) {
|
|
325
|
-
atom.otsFragment = data.otsFragment
|
|
324
|
+
atom.otsFragment = data.otsFragment
|
|
326
325
|
}
|
|
327
326
|
if (data.createdAt) {
|
|
328
|
-
atom.createdAt = data.createdAt
|
|
327
|
+
atom.createdAt = data.createdAt
|
|
329
328
|
}
|
|
330
329
|
|
|
331
|
-
return atom
|
|
332
|
-
|
|
330
|
+
return atom
|
|
333
331
|
} catch (error) {
|
|
334
|
-
throw new Error(`Atom deserialization failed: ${error.message}`)
|
|
332
|
+
throw new Error(`Atom deserialization failed: ${error.message}`)
|
|
335
333
|
}
|
|
336
334
|
}
|
|
337
335
|
|
package/src/KnishIOClient.js
CHANGED
|
@@ -582,15 +582,15 @@ export default class KnishIOClient {
|
|
|
582
582
|
* @param molecule
|
|
583
583
|
*/
|
|
584
584
|
async createMoleculeMutation ({
|
|
585
|
-
mutationClass,
|
|
585
|
+
mutationClass: MutationClass,
|
|
586
586
|
molecule = null
|
|
587
587
|
}) {
|
|
588
|
-
this.log('info', `KnishIOClient::createMoleculeQuery() - Creating a new ${
|
|
588
|
+
this.log('info', `KnishIOClient::createMoleculeQuery() - Creating a new ${ MutationClass.name } query...`)
|
|
589
589
|
|
|
590
590
|
// If you don't supply the molecule, we'll generate one for you
|
|
591
591
|
const _molecule = molecule || await this.createMolecule({})
|
|
592
592
|
|
|
593
|
-
const mutation = new
|
|
593
|
+
const mutation = new MutationClass(this.client(), this, _molecule)
|
|
594
594
|
|
|
595
595
|
if (!(mutation instanceof MutationProposeMolecule)) {
|
|
596
596
|
throw new CodeException(`${ this.constructor.name }::createMoleculeMutation() - This method only accepts MutationProposeMolecule!`)
|
package/src/Molecule.js
CHANGED
|
@@ -264,7 +264,13 @@ export default class Molecule {
|
|
|
264
264
|
const condition = totalCondition ? mappedHashArray[index] < 8 : mappedHashArray[index] > -8
|
|
265
265
|
|
|
266
266
|
if (condition) {
|
|
267
|
-
|
|
267
|
+
if (totalCondition) {
|
|
268
|
+
++mappedHashArray[index]
|
|
269
|
+
++total
|
|
270
|
+
} else {
|
|
271
|
+
--mappedHashArray[index]
|
|
272
|
+
--total
|
|
273
|
+
}
|
|
268
274
|
|
|
269
275
|
if (total === 0) {
|
|
270
276
|
break
|
|
@@ -716,7 +722,7 @@ export default class Molecule {
|
|
|
716
722
|
}) {
|
|
717
723
|
// Calculate final amount from all recipients
|
|
718
724
|
let amount = 0
|
|
719
|
-
for (const
|
|
725
|
+
for (const recipientAmount of Object.values(recipients || {})) {
|
|
720
726
|
amount += recipientAmount
|
|
721
727
|
}
|
|
722
728
|
if (this.sourceWallet.balance - amount < 0) {
|
|
@@ -1184,7 +1190,7 @@ export default class Molecule {
|
|
|
1184
1190
|
const {
|
|
1185
1191
|
includeValidationContext = false,
|
|
1186
1192
|
includeOtsFragments = true
|
|
1187
|
-
} = options
|
|
1193
|
+
} = options
|
|
1188
1194
|
|
|
1189
1195
|
try {
|
|
1190
1196
|
// Core molecule properties (server-compatible fields only)
|
|
@@ -1199,7 +1205,7 @@ export default class Molecule {
|
|
|
1199
1205
|
atoms: this.atoms.map(atom => atom.toJSON({
|
|
1200
1206
|
includeOtsFragments
|
|
1201
1207
|
}))
|
|
1202
|
-
}
|
|
1208
|
+
}
|
|
1203
1209
|
|
|
1204
1210
|
// Parent molecular hashes for DAG linkage (only include when non-empty
|
|
1205
1211
|
// to maintain backward compatibility with servers that don't support it)
|
|
@@ -1225,7 +1231,7 @@ export default class Molecule {
|
|
|
1225
1231
|
tokenUnits: this.sourceWallet.tokenUnits || [],
|
|
1226
1232
|
tradeRates: this.sourceWallet.tradeRates || {},
|
|
1227
1233
|
molecules: this.sourceWallet.molecules || {}
|
|
1228
|
-
}
|
|
1234
|
+
}
|
|
1229
1235
|
}
|
|
1230
1236
|
|
|
1231
1237
|
if (this.remainderWallet) {
|
|
@@ -1241,14 +1247,13 @@ export default class Molecule {
|
|
|
1241
1247
|
tokenUnits: this.remainderWallet.tokenUnits || [],
|
|
1242
1248
|
tradeRates: this.remainderWallet.tradeRates || {},
|
|
1243
1249
|
molecules: this.remainderWallet.molecules || {}
|
|
1244
|
-
}
|
|
1250
|
+
}
|
|
1245
1251
|
}
|
|
1246
1252
|
}
|
|
1247
1253
|
|
|
1248
|
-
return serialized
|
|
1249
|
-
|
|
1254
|
+
return serialized
|
|
1250
1255
|
} catch (error) {
|
|
1251
|
-
throw new Error(`Molecule serialization failed: ${error.message}`)
|
|
1256
|
+
throw new Error(`Molecule serialization failed: ${error.message}`)
|
|
1252
1257
|
}
|
|
1253
1258
|
}
|
|
1254
1259
|
|
|
@@ -1269,16 +1274,16 @@ export default class Molecule {
|
|
|
1269
1274
|
const {
|
|
1270
1275
|
includeValidationContext = false,
|
|
1271
1276
|
validateStructure = true
|
|
1272
|
-
} = options
|
|
1277
|
+
} = options
|
|
1273
1278
|
|
|
1274
1279
|
try {
|
|
1275
1280
|
// Parse JSON safely
|
|
1276
|
-
const data = typeof json === 'string' ? JSON.parse(json) : json
|
|
1281
|
+
const data = typeof json === 'string' ? JSON.parse(json) : json
|
|
1277
1282
|
|
|
1278
1283
|
// Validate required fields in strict mode
|
|
1279
1284
|
if (validateStructure) {
|
|
1280
1285
|
if (!data.molecularHash || !Array.isArray(data.atoms)) {
|
|
1281
|
-
throw new Error('Invalid molecule data: missing molecularHash or atoms array')
|
|
1286
|
+
throw new Error('Invalid molecule data: missing molecularHash or atoms array')
|
|
1282
1287
|
}
|
|
1283
1288
|
}
|
|
1284
1289
|
|
|
@@ -1288,24 +1293,24 @@ export default class Molecule {
|
|
|
1288
1293
|
bundle: data.bundle || null,
|
|
1289
1294
|
cellSlug: data.cellSlug || null,
|
|
1290
1295
|
version: data.version || null
|
|
1291
|
-
})
|
|
1296
|
+
})
|
|
1292
1297
|
|
|
1293
1298
|
// Populate core properties
|
|
1294
|
-
molecule.status = data.status
|
|
1295
|
-
molecule.molecularHash = data.molecularHash
|
|
1296
|
-
molecule.createdAt = data.createdAt || String(+new Date())
|
|
1297
|
-
molecule.cellSlugOrigin = data.cellSlugOrigin
|
|
1298
|
-
molecule.parentHashes = Array.isArray(data.parentHashes) ? [...data.parentHashes] : []
|
|
1299
|
+
molecule.status = data.status
|
|
1300
|
+
molecule.molecularHash = data.molecularHash
|
|
1301
|
+
molecule.createdAt = data.createdAt || String(+new Date())
|
|
1302
|
+
molecule.cellSlugOrigin = data.cellSlugOrigin
|
|
1303
|
+
molecule.parentHashes = Array.isArray(data.parentHashes) ? [...data.parentHashes] : []
|
|
1299
1304
|
|
|
1300
1305
|
// Reconstruct atoms array with proper Atom instances
|
|
1301
1306
|
if (Array.isArray(data.atoms)) {
|
|
1302
1307
|
molecule.atoms = data.atoms.map((atomData, index) => {
|
|
1303
1308
|
try {
|
|
1304
|
-
return Atom.fromJSON(atomData)
|
|
1309
|
+
return Atom.fromJSON(atomData)
|
|
1305
1310
|
} catch (error) {
|
|
1306
|
-
throw new Error(`Failed to reconstruct atom ${index}: ${error.message}`)
|
|
1311
|
+
throw new Error(`Failed to reconstruct atom ${index}: ${error.message}`)
|
|
1307
1312
|
}
|
|
1308
|
-
})
|
|
1313
|
+
})
|
|
1309
1314
|
}
|
|
1310
1315
|
|
|
1311
1316
|
// Reconstruct validation context if available and requested
|
|
@@ -1319,17 +1324,17 @@ export default class Molecule {
|
|
|
1319
1324
|
bundle: data.sourceWallet.bundle,
|
|
1320
1325
|
batchId: data.sourceWallet.batchId,
|
|
1321
1326
|
characters: data.sourceWallet.characters
|
|
1322
|
-
})
|
|
1327
|
+
})
|
|
1323
1328
|
|
|
1324
1329
|
// Set additional properties for validation context
|
|
1325
|
-
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0)
|
|
1326
|
-
molecule.sourceWallet.address = data.sourceWallet.address
|
|
1330
|
+
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0)
|
|
1331
|
+
molecule.sourceWallet.address = data.sourceWallet.address
|
|
1327
1332
|
if (data.sourceWallet.pubkey) {
|
|
1328
|
-
molecule.sourceWallet.pubkey = data.sourceWallet.pubkey
|
|
1333
|
+
molecule.sourceWallet.pubkey = data.sourceWallet.pubkey
|
|
1329
1334
|
}
|
|
1330
|
-
molecule.sourceWallet.tokenUnits = data.sourceWallet.tokenUnits || []
|
|
1331
|
-
molecule.sourceWallet.tradeRates = data.sourceWallet.tradeRates || {}
|
|
1332
|
-
molecule.sourceWallet.molecules = data.sourceWallet.molecules || {}
|
|
1335
|
+
molecule.sourceWallet.tokenUnits = data.sourceWallet.tokenUnits || []
|
|
1336
|
+
molecule.sourceWallet.tradeRates = data.sourceWallet.tradeRates || {}
|
|
1337
|
+
molecule.sourceWallet.molecules = data.sourceWallet.molecules || {}
|
|
1333
1338
|
}
|
|
1334
1339
|
|
|
1335
1340
|
if (data.remainderWallet) {
|
|
@@ -1341,24 +1346,23 @@ export default class Molecule {
|
|
|
1341
1346
|
bundle: data.remainderWallet.bundle,
|
|
1342
1347
|
batchId: data.remainderWallet.batchId,
|
|
1343
1348
|
characters: data.remainderWallet.characters
|
|
1344
|
-
})
|
|
1349
|
+
})
|
|
1345
1350
|
|
|
1346
1351
|
// Set additional properties for validation context
|
|
1347
|
-
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0)
|
|
1348
|
-
molecule.remainderWallet.address = data.remainderWallet.address
|
|
1352
|
+
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0)
|
|
1353
|
+
molecule.remainderWallet.address = data.remainderWallet.address
|
|
1349
1354
|
if (data.remainderWallet.pubkey) {
|
|
1350
|
-
molecule.remainderWallet.pubkey = data.remainderWallet.pubkey
|
|
1355
|
+
molecule.remainderWallet.pubkey = data.remainderWallet.pubkey
|
|
1351
1356
|
}
|
|
1352
|
-
molecule.remainderWallet.tokenUnits = data.remainderWallet.tokenUnits || []
|
|
1353
|
-
molecule.remainderWallet.tradeRates = data.remainderWallet.tradeRates || {}
|
|
1354
|
-
molecule.remainderWallet.molecules = data.remainderWallet.molecules || {}
|
|
1357
|
+
molecule.remainderWallet.tokenUnits = data.remainderWallet.tokenUnits || []
|
|
1358
|
+
molecule.remainderWallet.tradeRates = data.remainderWallet.tradeRates || {}
|
|
1359
|
+
molecule.remainderWallet.molecules = data.remainderWallet.molecules || {}
|
|
1355
1360
|
}
|
|
1356
1361
|
}
|
|
1357
1362
|
|
|
1358
|
-
return molecule
|
|
1359
|
-
|
|
1363
|
+
return molecule
|
|
1360
1364
|
} catch (error) {
|
|
1361
|
-
throw new Error(`Molecule deserialization failed: ${error.message}`)
|
|
1365
|
+
throw new Error(`Molecule deserialization failed: ${error.message}`)
|
|
1362
1366
|
}
|
|
1363
1367
|
}
|
|
1364
1368
|
|
package/src/Wallet.js
CHANGED
|
@@ -283,11 +283,11 @@ export default class Wallet {
|
|
|
283
283
|
* Initializes the ML-KEM key pair
|
|
284
284
|
*/
|
|
285
285
|
initializeMLKEM () {
|
|
286
|
-
// Generate a 64-byte (512-bit) seed from the Knish.IO private key
|
|
286
|
+
// Generate a 64-byte (512-bit) seed from the Knish.IO private key
|
|
287
287
|
// Use deterministic approach: generateSecret(key, 128) → 128 hex chars = 64 bytes
|
|
288
|
-
const seedHex = generateSecret(this.key, 128)
|
|
288
|
+
const seedHex = generateSecret(this.key, 128) // 128 hex chars = 64 bytes
|
|
289
289
|
|
|
290
|
-
// Convert the hex string to a Uint8Array
|
|
290
|
+
// Convert the hex string to a Uint8Array
|
|
291
291
|
const seed = new Uint8Array(64)
|
|
292
292
|
for (let i = 0; i < 64; i++) {
|
|
293
293
|
seed[i] = parseInt(seedHex.substr(i * 2, 2), 16)
|
|
@@ -52,6 +52,7 @@ import { isNumeric } from '../../libraries/strings.js'
|
|
|
52
52
|
import { intersect } from '../../libraries/array.js'
|
|
53
53
|
import CodeException from '../../exception/CodeException.js'
|
|
54
54
|
|
|
55
|
+
/* eslint-disable accessor-pairs -- intentional setter-only fluent rule builder; values are read directly via __field, no getter needed */
|
|
55
56
|
export default class Callback {
|
|
56
57
|
/**
|
|
57
58
|
*
|
|
@@ -47,9 +47,7 @@ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
49
|
export default class Meta {
|
|
50
|
-
constructor ({}) {
|
|
51
|
-
const args = arguments[0]
|
|
52
|
-
|
|
50
|
+
constructor (args = {}) {
|
|
53
51
|
for (const key in args) {
|
|
54
52
|
this[`__${ key }`] = args[key]
|
|
55
53
|
}
|
|
@@ -51,6 +51,7 @@ import Condition from './Condition.js'
|
|
|
51
51
|
import RuleArgumentException from './exception/RuleArgumentException.js'
|
|
52
52
|
import MetaMissingException from '../../exception/MetaMissingException.js'
|
|
53
53
|
|
|
54
|
+
/* eslint-disable accessor-pairs -- intentional setter-only fluent rule builder; values are read directly via __field, no getter needed */
|
|
54
55
|
export default class Rule {
|
|
55
56
|
/**
|
|
56
57
|
*
|
package/src/libraries/strings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Hex from './Hex.js'
|
|
2
2
|
|
|
3
|
+
/* eslint-disable no-extend-native -- intentional guarded String.prototype polyfill (trim) + SDK camel/snake-case helpers relied on across the codebase */
|
|
3
4
|
if (!String.prototype.trim) {
|
|
4
5
|
String.prototype.trim = function () {
|
|
5
6
|
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')
|
|
@@ -67,24 +67,55 @@ class UrqlClientWrapper {
|
|
|
67
67
|
})
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Builds the urql operation options forwarded with a query/mutation.
|
|
72
|
+
*
|
|
73
|
+
* Forwards the requestPolicy (so a long-lived client does not serve stale
|
|
74
|
+
* cache-first reads) and, when the caller supplied a per-query abort signal,
|
|
75
|
+
* the signal too — while re-supplying the X-Auth-Token header. urql REPLACES
|
|
76
|
+
* (not merges) the client-level fetchOptions with any operation-context
|
|
77
|
+
* fetchOptions (createRequestOperation builds the op context as
|
|
78
|
+
* {...baseOpts, ...opts}), so forwarding fetchOptions WITHOUT the header would
|
|
79
|
+
* drop X-Auth-Token and break auth. The header here is byte-identical to the
|
|
80
|
+
* client-level one set in createUrqlClient.
|
|
81
|
+
*
|
|
82
|
+
* @param {object} context
|
|
83
|
+
* @returns {object|undefined}
|
|
84
|
+
*/
|
|
85
|
+
buildRequestOptions (context) {
|
|
86
|
+
if (!context) {
|
|
87
|
+
return undefined
|
|
88
|
+
}
|
|
89
|
+
const opts = {}
|
|
90
|
+
if (context.requestPolicy) {
|
|
91
|
+
opts.requestPolicy = context.requestPolicy
|
|
92
|
+
}
|
|
93
|
+
const callerSignal = context.fetchOptions && context.fetchOptions.signal
|
|
94
|
+
if (callerSignal) {
|
|
95
|
+
// Combine the per-query abort signal with the 60s timeout so either can
|
|
96
|
+
// cancel the request; fall back to the caller signal where AbortSignal.any
|
|
97
|
+
// is unavailable.
|
|
98
|
+
const signal = (typeof AbortSignal !== 'undefined' && typeof AbortSignal.any === 'function')
|
|
99
|
+
? AbortSignal.any([callerSignal, AbortSignal.timeout(60000)])
|
|
100
|
+
: callerSignal
|
|
101
|
+
opts.fetchOptions = {
|
|
102
|
+
headers: { 'X-Auth-Token': this.$__authToken },
|
|
103
|
+
signal
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return Object.keys(opts).length ? opts : undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
70
109
|
async query (request) {
|
|
71
110
|
const { query, variables, context } = request
|
|
72
|
-
|
|
73
|
-
// client does not serve stale cache-first reads. We deliberately do NOT
|
|
74
|
-
// forward the whole context: urql REPLACES (not merges) the client-level
|
|
75
|
-
// fetchOptions with any context.fetchOptions (createRequestOperation builds
|
|
76
|
-
// the op context as {...baseOpts, ...opts}), which would drop the
|
|
77
|
-
// X-Auth-Token header set in createUrqlClient and break authentication.
|
|
78
|
-
const opts = (context && context.requestPolicy) ? { requestPolicy: context.requestPolicy } : undefined
|
|
111
|
+
const opts = this.buildRequestOptions(context)
|
|
79
112
|
const result = await this.$__client.query(query, variables || {}, opts).toPromise()
|
|
80
113
|
return this.formatResponse(result)
|
|
81
114
|
}
|
|
82
115
|
|
|
83
116
|
async mutate (request) {
|
|
84
117
|
const { mutation, variables, context } = request
|
|
85
|
-
|
|
86
|
-
// would clobber the auth-bearing client-level fetchOptions).
|
|
87
|
-
const opts = (context && context.requestPolicy) ? { requestPolicy: context.requestPolicy } : undefined
|
|
118
|
+
const opts = this.buildRequestOptions(context)
|
|
88
119
|
const result = await this.$__client.mutation(mutation, variables || {}, opts).toPromise()
|
|
89
120
|
return this.formatResponse(result)
|
|
90
121
|
}
|
package/src/query/QueryPolicy.js
CHANGED
|
@@ -48,7 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
|
48
48
|
|
|
49
49
|
import Query from './Query.js'
|
|
50
50
|
import ResponsePolicy from '../response/ResponsePolicy.js'
|
|
51
|
-
import { gql } from
|
|
51
|
+
import { gql } from '@urql/core'
|
|
52
52
|
|
|
53
53
|
export default class QueryPolicy extends Query {
|
|
54
54
|
/**
|
package/src/response/Response.js
CHANGED
|
@@ -176,7 +176,7 @@ export default class Response {
|
|
|
176
176
|
/**
|
|
177
177
|
* Enhanced interface methods for standardized response handling
|
|
178
178
|
*/
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
/**
|
|
181
181
|
* Get error reason (alias for error() to match standardized interface)
|
|
182
182
|
* @return {string|null}
|
|
@@ -247,7 +247,7 @@ export default class Response {
|
|
|
247
247
|
*/
|
|
248
248
|
debug (label = null) {
|
|
249
249
|
const debugPrefix = label ? `[${label}]` : `[${this.constructor.name}]`
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
if (this.success()) {
|
|
252
252
|
console.debug(`${debugPrefix} Success:`, {
|
|
253
253
|
payload: this.payload(),
|
|
@@ -261,7 +261,7 @@ export default class Response {
|
|
|
261
261
|
rawData: this.$__response
|
|
262
262
|
})
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
return this
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -46,7 +46,6 @@ 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 Query from '../query/Query.js'
|
|
50
49
|
import Response from './Response.js'
|
|
51
50
|
|
|
52
51
|
export default class ResponseActiveSession extends Response {
|
|
@@ -46,7 +46,6 @@ 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 Query from '../query/Query.js'
|
|
50
49
|
import Response from './Response.js'
|
|
51
50
|
import Dot from '../libraries/Dot.js'
|
|
52
51
|
import InvalidResponseException from '../exception/InvalidResponseException.js'
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
import ResponseWalletList from './ResponseWalletList.js'
|
|
51
50
|
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
import Wallet from '../Wallet.js'
|
|
51
50
|
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
import Dot from '../libraries/Dot.js'
|
|
51
50
|
|
|
@@ -46,7 +46,6 @@ 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 Query from '../query/Query.js'
|
|
50
49
|
import Response from './Response.js'
|
|
51
50
|
|
|
52
51
|
export default class ResponseMetaTypeViaAtom extends Response {
|
|
@@ -46,7 +46,6 @@ 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 Query from '../query/Query.js'
|
|
50
49
|
import Response from './Response.js'
|
|
51
50
|
import CheckMolecule from '../libraries/CheckMolecule.js'
|
|
52
51
|
|
|
@@ -46,7 +46,6 @@ 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 Query from '../query/Query.js'
|
|
50
49
|
import Response from './Response.js'
|
|
51
50
|
|
|
52
51
|
export default class ResponsePolicy extends Response {
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
|
|
51
50
|
export default class ResponseQueryUserActivity extends Response {
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
import Meta from '../Meta.js'
|
|
51
50
|
|
|
@@ -45,7 +45,6 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import Query from '../query/Query.js'
|
|
49
48
|
import Response from './Response.js'
|
|
50
49
|
import Wallet from '../Wallet.js'
|
|
51
50
|
import TokenUnit from '../TokenUnit.js'
|