@wishknish/knishio-client-ts 0.7.2 → 0.7.6
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/index.cjs +2819 -1186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +378 -142
- package/dist/index.d.ts +378 -142
- package/dist/index.iife.js +22799 -20747
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +2817 -1185
- package/dist/index.js.map +1 -1
- package/package.json +12 -6
- package/src/AuthToken.ts +8 -2
- package/src/KnishIOClient.ts +367 -118
- package/src/constants.ts +5 -3
- package/src/core/Atom.ts +167 -100
- package/src/core/AtomMeta.ts +11 -28
- package/src/core/Meta.ts +18 -15
- package/src/core/Molecule.ts +582 -140
- package/src/core/Wallet.ts +19 -24
- package/src/index.ts +9 -10
- package/src/instance/rules/Rule.ts +128 -19
- package/src/libraries/CheckMolecule.ts +88 -1
- package/src/libraries/GraphQLClient.ts +17 -22
- package/src/libraries/crypto.ts +14 -30
- package/src/libraries/strings.ts +26 -25
- package/src/mutation/MutationAppendRequest.ts +52 -0
- package/src/mutation/MutationCreateRule.ts +2 -2
- package/src/mutation/MutationPeering.ts +37 -0
- package/src/mutation/MutationRequestAuthorization.ts +3 -3
- package/src/query/Query.ts +6 -6
- package/src/query/QueryActiveSession.ts +0 -1
- package/src/query/QueryAtom.ts +27 -27
- package/src/query/QueryContinuId.ts +8 -0
- package/src/query/QueryMetaType.ts +1 -1
- package/src/query/QueryMetaTypeViaMolecule.ts +221 -0
- package/src/query/QueryWalletList.ts +2 -2
- package/src/response/Response.ts +17 -1
- package/src/response/ResponseAppendRequest.ts +17 -0
- package/src/response/ResponseBalance.ts +8 -3
- package/src/response/ResponseContinuId.ts +1 -1
- package/src/response/ResponseMetaType.ts +32 -19
- package/src/response/ResponseMetaTypeViaMolecule.ts +224 -0
- package/src/response/ResponsePeering.ts +17 -0
- package/src/response/ResponsePolicy.ts +2 -3
- package/src/response/ResponseProposeMolecule.ts +0 -1
- package/src/response/ResponseRequestAuthorization.ts +32 -2
- package/src/response/ResponseRequestAuthorizationGuest.ts +25 -1
- package/src/response/ResponseWalletList.ts +1 -1
- package/src/schemas/index.ts +12 -1
- package/src/types/client.ts +3 -2
- package/src/types/graphql.ts +3 -2
- package/src/types/guards.ts +18 -5
- package/src/types/index.ts +19 -4
|
@@ -65,8 +65,8 @@ export default class MutationCreateRule extends MutationProposeMolecule {
|
|
|
65
65
|
}: {
|
|
66
66
|
metaType: MetaType
|
|
67
67
|
metaId: MetaId
|
|
68
|
-
rule:
|
|
69
|
-
policy
|
|
68
|
+
rule: any[] | any // Accept single object or array
|
|
69
|
+
policy?: Record<string, any> | null
|
|
70
70
|
}): void {
|
|
71
71
|
(this.$__molecule as any).createRule({
|
|
72
72
|
metaType,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
3
|
+
|
|
4
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
5
|
+
|
|
6
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import MutationProposeMolecule from './MutationProposeMolecule'
|
|
10
|
+
import ResponsePeering from '../response/ResponsePeering'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Mutation for registering a peer node via the P-isotope
|
|
14
|
+
* Matches JavaScript SDK MutationPeering implementation exactly
|
|
15
|
+
*/
|
|
16
|
+
export default class MutationPeering extends MutationProposeMolecule {
|
|
17
|
+
/**
|
|
18
|
+
* Fills a molecule with a P-isotope peering atom
|
|
19
|
+
* Matches JavaScript SDK fillMolecule method exactly
|
|
20
|
+
*/
|
|
21
|
+
override fillMolecule({ host }: { host: string }): void {
|
|
22
|
+
(this.$__molecule as any).initPeering({ host });
|
|
23
|
+
(this.$__molecule as any).sign({});
|
|
24
|
+
(this.$__molecule as any).check()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Builds a Response object out of a JSON object
|
|
29
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
30
|
+
*/
|
|
31
|
+
override createResponse(json: any): ResponsePeering {
|
|
32
|
+
return new ResponsePeering({
|
|
33
|
+
query: this,
|
|
34
|
+
json
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -59,9 +59,9 @@ export default class MutationRequestAuthorization extends MutationProposeMolecul
|
|
|
59
59
|
* Matches JavaScript SDK fillMolecule method exactly
|
|
60
60
|
*/
|
|
61
61
|
override fillMolecule({ meta }: { meta: any }): void {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
this.$__molecule.initAuthorization({ meta })
|
|
63
|
+
this.$__molecule.sign({})
|
|
64
|
+
this.$__molecule.check()
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
package/src/query/Query.ts
CHANGED
|
@@ -151,12 +151,12 @@ export default class Query {
|
|
|
151
151
|
/**
|
|
152
152
|
* Executes the Query and returns a Response
|
|
153
153
|
*/
|
|
154
|
-
async execute({
|
|
155
|
-
variables =
|
|
156
|
-
context = {}
|
|
157
|
-
}: {
|
|
158
|
-
variables?: Record<string, any>
|
|
159
|
-
context?: Record<string, any>
|
|
154
|
+
async execute({
|
|
155
|
+
variables = null,
|
|
156
|
+
context = {}
|
|
157
|
+
}: {
|
|
158
|
+
variables?: Record<string, any> | null
|
|
159
|
+
context?: Record<string, any>
|
|
160
160
|
} = {}): Promise<Response | null> {
|
|
161
161
|
this.$__request = this.createQuery({ variables })
|
|
162
162
|
|
package/src/query/QueryAtom.ts
CHANGED
|
@@ -156,33 +156,33 @@ export default class QueryAtom extends Query {
|
|
|
156
156
|
latest,
|
|
157
157
|
queryArgs
|
|
158
158
|
}: {
|
|
159
|
-
molecularHashes?: string[]
|
|
160
|
-
molecularHash?: string
|
|
161
|
-
bundleHashes?: string[]
|
|
162
|
-
bundleHash?: string
|
|
163
|
-
positions?: string[]
|
|
164
|
-
position?: string
|
|
165
|
-
walletAddresses?: string[]
|
|
166
|
-
walletAddress?: string
|
|
167
|
-
isotopes?: string[]
|
|
168
|
-
isotope?: string
|
|
169
|
-
tokenSlugs?: string[]
|
|
170
|
-
tokenSlug?: string
|
|
171
|
-
cellSlugs?: string[]
|
|
172
|
-
cellSlug?: string
|
|
173
|
-
batchIds?: string[]
|
|
174
|
-
batchId?: string
|
|
175
|
-
values?: string[]
|
|
176
|
-
value?: string | number
|
|
177
|
-
metaTypes?: string[]
|
|
178
|
-
metaType?: string
|
|
179
|
-
metaIds?: string[]
|
|
180
|
-
metaId?: string
|
|
181
|
-
indexes?: number[]
|
|
182
|
-
index?: number
|
|
183
|
-
filter?: object[]
|
|
184
|
-
latest?: boolean
|
|
185
|
-
queryArgs?: object
|
|
159
|
+
molecularHashes?: string[] | null
|
|
160
|
+
molecularHash?: string | null
|
|
161
|
+
bundleHashes?: string[] | null
|
|
162
|
+
bundleHash?: string | null
|
|
163
|
+
positions?: string[] | null
|
|
164
|
+
position?: string | null
|
|
165
|
+
walletAddresses?: string[] | null
|
|
166
|
+
walletAddress?: string | null
|
|
167
|
+
isotopes?: string[] | null
|
|
168
|
+
isotope?: string | null
|
|
169
|
+
tokenSlugs?: string[] | null
|
|
170
|
+
tokenSlug?: string | null
|
|
171
|
+
cellSlugs?: string[] | null
|
|
172
|
+
cellSlug?: string | null
|
|
173
|
+
batchIds?: string[] | null
|
|
174
|
+
batchId?: string | null
|
|
175
|
+
values?: string[] | null
|
|
176
|
+
value?: string | number | null
|
|
177
|
+
metaTypes?: string[] | null
|
|
178
|
+
metaType?: string | null
|
|
179
|
+
metaIds?: string[] | null
|
|
180
|
+
metaId?: string | null
|
|
181
|
+
indexes?: number[] | null
|
|
182
|
+
index?: number | null
|
|
183
|
+
filter?: object[] | null
|
|
184
|
+
latest?: boolean | null
|
|
185
|
+
queryArgs?: object | null
|
|
186
186
|
}): Record<string, any> {
|
|
187
187
|
if (molecularHash) {
|
|
188
188
|
molecularHashes = molecularHashes || []
|
|
@@ -79,6 +79,14 @@ export default class QueryContinuId extends Query {
|
|
|
79
79
|
}`
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Force network-only for ContinuID queries to prevent URQL cache from
|
|
84
|
+
* returning stale wallet positions after mutations advance the ContinuID chain
|
|
85
|
+
*/
|
|
86
|
+
override createQueryContext(): Record<string, any> {
|
|
87
|
+
return { requestPolicy: 'network-only' }
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
/**
|
|
83
91
|
* Returns a Response object
|
|
84
92
|
* Matches JavaScript SDK createResponse method exactly
|
|
@@ -114,7 +114,7 @@ export default class QueryMetaType extends Query {
|
|
|
114
114
|
latest?: boolean | null
|
|
115
115
|
filter?: any | null
|
|
116
116
|
queryArgs?: any | null
|
|
117
|
-
count?: string | null
|
|
117
|
+
count?: string | number | null
|
|
118
118
|
countBy?: string | null
|
|
119
119
|
cellSlug?: string | null
|
|
120
120
|
} = {}): Record<string, any> {
|
|
@@ -0,0 +1,221 @@
|
|
|
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-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Query from './Query'
|
|
50
|
+
import ResponseMetaTypeViaMolecule from '../response/ResponseMetaTypeViaMolecule'
|
|
51
|
+
import { gql } from '@urql/core'
|
|
52
|
+
import type { GraphQLClient } from '../types/graphql'
|
|
53
|
+
import type KnishIOClient from '../KnishIOClient'
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Query for retrieving Meta Asset information via Molecule data.
|
|
57
|
+
*
|
|
58
|
+
* Unlike QueryMetaTypeViaAtom, this query includes molecule data with atoms
|
|
59
|
+
* (including otsFragment and metasJson) for integrity verification and
|
|
60
|
+
* client-side metadata extraction.
|
|
61
|
+
*/
|
|
62
|
+
export default class QueryMetaTypeViaMolecule extends Query {
|
|
63
|
+
/**
|
|
64
|
+
* Create new QueryMetaTypeViaMolecule instance
|
|
65
|
+
*/
|
|
66
|
+
constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
|
|
67
|
+
super(graphQLClient, knishIOClient)
|
|
68
|
+
|
|
69
|
+
this.$__query = gql`query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $keys: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String, $atomValues: [String!], $cellSlugs: [String!] ) {
|
|
70
|
+
MetaTypeViaAtom(
|
|
71
|
+
metaTypes: $metaTypes
|
|
72
|
+
metaIds: $metaIds
|
|
73
|
+
atomValues: $atomValues
|
|
74
|
+
cellSlugs: $cellSlugs
|
|
75
|
+
filter: $filter,
|
|
76
|
+
latest: $latest,
|
|
77
|
+
queryArgs: $queryArgs
|
|
78
|
+
countBy: $countBy
|
|
79
|
+
) {
|
|
80
|
+
metaType,
|
|
81
|
+
instanceCount {
|
|
82
|
+
key,
|
|
83
|
+
value
|
|
84
|
+
},
|
|
85
|
+
instances {
|
|
86
|
+
metaType,
|
|
87
|
+
metaId,
|
|
88
|
+
createdAt,
|
|
89
|
+
metas( values: $values, keys: $keys ) {
|
|
90
|
+
molecularHash,
|
|
91
|
+
position,
|
|
92
|
+
key,
|
|
93
|
+
value,
|
|
94
|
+
createdAt
|
|
95
|
+
},
|
|
96
|
+
molecule {
|
|
97
|
+
molecularHash,
|
|
98
|
+
bundleHash,
|
|
99
|
+
cellSlug,
|
|
100
|
+
status,
|
|
101
|
+
createdAt,
|
|
102
|
+
atoms {
|
|
103
|
+
position,
|
|
104
|
+
walletAddress,
|
|
105
|
+
isotope,
|
|
106
|
+
tokenSlug,
|
|
107
|
+
value,
|
|
108
|
+
batchId,
|
|
109
|
+
metaType,
|
|
110
|
+
metaId,
|
|
111
|
+
index,
|
|
112
|
+
createdAt,
|
|
113
|
+
otsFragment,
|
|
114
|
+
metasJson
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
paginatorInfo {
|
|
119
|
+
currentPage,
|
|
120
|
+
total
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Builds a GraphQL-friendly variables object based on input fields
|
|
128
|
+
*/
|
|
129
|
+
static createVariables({
|
|
130
|
+
metaType = null,
|
|
131
|
+
metaId = null,
|
|
132
|
+
key = null,
|
|
133
|
+
value = null,
|
|
134
|
+
keys = null,
|
|
135
|
+
values = null,
|
|
136
|
+
atomValues = null,
|
|
137
|
+
latest = null,
|
|
138
|
+
filter = null,
|
|
139
|
+
queryArgs = null,
|
|
140
|
+
countBy = null,
|
|
141
|
+
cellSlug = null
|
|
142
|
+
}: {
|
|
143
|
+
metaType?: string | string[] | null
|
|
144
|
+
metaId?: string | string[] | null
|
|
145
|
+
key?: string | null
|
|
146
|
+
value?: string | null
|
|
147
|
+
keys?: string[] | null
|
|
148
|
+
values?: string[] | null
|
|
149
|
+
atomValues?: string[] | null
|
|
150
|
+
latest?: boolean | null
|
|
151
|
+
filter?: any[] | null
|
|
152
|
+
queryArgs?: any | null
|
|
153
|
+
countBy?: string | null
|
|
154
|
+
cellSlug?: string | string[] | null
|
|
155
|
+
} = {}): Record<string, any> {
|
|
156
|
+
const variables: Record<string, any> = {}
|
|
157
|
+
|
|
158
|
+
if (atomValues) {
|
|
159
|
+
variables.atomValues = atomValues
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (keys) {
|
|
163
|
+
variables.keys = keys
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (values) {
|
|
167
|
+
variables.values = values
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (metaType) {
|
|
171
|
+
variables.metaTypes = typeof metaType === 'string' ? [metaType] : metaType
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (metaId) {
|
|
175
|
+
variables.metaIds = typeof metaId === 'string' ? [metaId] : metaId
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (cellSlug) {
|
|
179
|
+
variables.cellSlugs = typeof cellSlug === 'string' ? [cellSlug] : cellSlug
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (countBy) {
|
|
183
|
+
variables.countBy = countBy
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (filter) {
|
|
187
|
+
variables.filter = filter
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (key && value) {
|
|
191
|
+
variables.filter = variables.filter || []
|
|
192
|
+
variables.filter.push({
|
|
193
|
+
key,
|
|
194
|
+
value,
|
|
195
|
+
comparison: '='
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
variables.latest = latest === true
|
|
200
|
+
|
|
201
|
+
if (queryArgs) {
|
|
202
|
+
if (typeof queryArgs.limit === 'undefined' || queryArgs.limit === 0) {
|
|
203
|
+
queryArgs.limit = '*'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
variables.queryArgs = queryArgs
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return variables
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Returns a Response object
|
|
214
|
+
*/
|
|
215
|
+
override createResponse(json: any): ResponseMetaTypeViaMolecule {
|
|
216
|
+
return new ResponseMetaTypeViaMolecule({
|
|
217
|
+
query: this,
|
|
218
|
+
json
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -64,8 +64,8 @@ export default class QueryWalletList extends Query {
|
|
|
64
64
|
constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
|
|
65
65
|
super(graphQLClient, knishIOClient)
|
|
66
66
|
|
|
67
|
-
this.$__query = gql`query( $bundleHash: String, $
|
|
68
|
-
Wallet( bundleHash: $bundleHash,
|
|
67
|
+
this.$__query = gql`query( $bundleHash: String, $token: String ) {
|
|
68
|
+
Wallet( bundleHash: $bundleHash, token: $token ) {
|
|
69
69
|
address,
|
|
70
70
|
bundleHash,
|
|
71
71
|
token {
|
package/src/response/Response.ts
CHANGED
|
@@ -95,6 +95,17 @@ export default class Response implements UniversalResponse<any> {
|
|
|
95
95
|
throw new InvalidResponseException()
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// Check for GraphQL errors array
|
|
99
|
+
if (this.$__response.errors && Array.isArray(this.$__response.errors) && this.$__response.errors.length > 0) {
|
|
100
|
+
const errorMessage = this.$__response.errors[0].message || 'Unknown GraphQL error'
|
|
101
|
+
|
|
102
|
+
if (errorMessage.includes('Unauthenticated')) {
|
|
103
|
+
throw new UnauthenticatedException('Unauthenticated request')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
throw new InvalidResponseException(`GraphQL Error: ${errorMessage}`)
|
|
107
|
+
}
|
|
108
|
+
|
|
98
109
|
this.init()
|
|
99
110
|
}
|
|
100
111
|
|
|
@@ -113,9 +124,14 @@ export default class Response implements UniversalResponse<any> {
|
|
|
113
124
|
return this.response()
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
// Check if response has data field
|
|
128
|
+
if (!this.response().data) {
|
|
129
|
+
throw new InvalidResponseException('Response has no data field')
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
// Check key & return custom data from the response
|
|
117
133
|
if (!Dot.has(this.response(), this.dataKey)) {
|
|
118
|
-
throw new InvalidResponseException()
|
|
134
|
+
throw new InvalidResponseException(`Missing expected field: ${this.dataKey}`)
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
return Dot.get(this.response(), this.dataKey)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
3
|
+
|
|
4
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
5
|
+
|
|
6
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import ResponseProposeMolecule from './ResponseProposeMolecule'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Response for append requests via A-isotope
|
|
13
|
+
* Matches JavaScript SDK ResponseAppendRequest implementation exactly
|
|
14
|
+
*/
|
|
15
|
+
export default class ResponseAppendRequest extends ResponseProposeMolecule {
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -77,7 +77,10 @@ export default class ResponseBalance extends Response {
|
|
|
77
77
|
* Matches JavaScript SDK payload() method exactly
|
|
78
78
|
*/
|
|
79
79
|
override payload(): Wallet | null {
|
|
80
|
-
const
|
|
80
|
+
const balanceData = this.data() as any
|
|
81
|
+
|
|
82
|
+
// Balance query returns an array, get the first result
|
|
83
|
+
const walletData = Array.isArray(balanceData) ? balanceData[0] : balanceData
|
|
81
84
|
|
|
82
85
|
if (!walletData || !walletData.bundleHash || !walletData.tokenSlug) {
|
|
83
86
|
return null
|
|
@@ -102,7 +105,9 @@ export default class ResponseBalance extends Response {
|
|
|
102
105
|
}): Wallet {
|
|
103
106
|
let wallet: Wallet
|
|
104
107
|
|
|
105
|
-
|
|
108
|
+
// Handle null, undefined, or empty string positions
|
|
109
|
+
// Empty positions occur for shadow wallets created before this fix
|
|
110
|
+
if (!data.position) {
|
|
106
111
|
wallet = Wallet.create({
|
|
107
112
|
bundle: data.bundleHash,
|
|
108
113
|
token: data.tokenSlug,
|
|
@@ -144,7 +149,7 @@ export default class ResponseBalance extends Response {
|
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
// Set balance and other properties
|
|
147
|
-
wallet.balance =
|
|
152
|
+
wallet.balance = String(data.amount != null ? data.amount : 0)
|
|
148
153
|
wallet.pubkey = data.pubkey
|
|
149
154
|
wallet.createdAt = data.createdAt
|
|
150
155
|
|
|
@@ -93,7 +93,7 @@ export default class ResponseContinuId extends Response {
|
|
|
93
93
|
wallet.batchId = continuId.batchId
|
|
94
94
|
wallet.characters = continuId.characters
|
|
95
95
|
wallet.pubkey = continuId.pubkey
|
|
96
|
-
wallet.balance = continuId.amount
|
|
96
|
+
wallet.balance = String(continuId.amount != null ? continuId.amount : 0)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
return wallet
|
|
@@ -72,37 +72,50 @@ export default class ResponseMetaType extends Response {
|
|
|
72
72
|
})
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Extracts payload from metaData object
|
|
77
|
+
*/
|
|
78
|
+
private extractPayload(metaData: any): any {
|
|
79
|
+
return {
|
|
80
|
+
instances: metaData?.instances || [],
|
|
81
|
+
instanceCount: metaData?.instanceCount || [],
|
|
82
|
+
paginatorInfo: metaData?.paginatorInfo || {}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
75
86
|
/**
|
|
76
87
|
* Returns meta type instance results
|
|
77
|
-
*
|
|
88
|
+
* Handles various response formats from server:
|
|
89
|
+
* - Array of results (normal case)
|
|
90
|
+
* - Single object (filtered queries)
|
|
91
|
+
* - null/undefined (no results)
|
|
92
|
+
* - Empty array (no matching data)
|
|
78
93
|
*/
|
|
79
94
|
override payload(): any | null {
|
|
80
95
|
const metaTypeData = this.data()
|
|
81
96
|
|
|
82
|
-
|
|
97
|
+
// Handle null/undefined responses
|
|
98
|
+
if (metaTypeData === null || metaTypeData === undefined) {
|
|
83
99
|
return null
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
response.instances = metaData.instances
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (metaData.instanceCount) {
|
|
99
|
-
response.instanceCount = metaData.instanceCount
|
|
102
|
+
// Handle array response (expected format)
|
|
103
|
+
if (Array.isArray(metaTypeData)) {
|
|
104
|
+
if (metaTypeData.length === 0) {
|
|
105
|
+
// Return empty structure instead of null for empty results
|
|
106
|
+
return this.extractPayload(null)
|
|
107
|
+
}
|
|
108
|
+
// Get last element without mutating the array
|
|
109
|
+
const metaData = metaTypeData[metaTypeData.length - 1]
|
|
110
|
+
return this.extractPayload(metaData)
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
113
|
+
// Handle single object response (some filtered queries)
|
|
114
|
+
if (typeof metaTypeData === 'object') {
|
|
115
|
+
return this.extractPayload(metaTypeData)
|
|
104
116
|
}
|
|
105
117
|
|
|
106
|
-
return
|
|
118
|
+
// Unknown format, return null
|
|
119
|
+
return null
|
|
107
120
|
}
|
|
108
121
|
}
|