@wishknish/knishio-client-ts 0.7.0 → 0.7.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/index.cjs +235 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1833 -0
- package/dist/index.d.ts +1833 -0
- package/dist/index.iife.js +238 -181
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +235 -194
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
- package/src/KnishIOClient.ts +183 -231
- package/src/core/Atom.ts +1 -1
- package/src/core/Molecule.ts +0 -1
- package/src/core/Wallet.ts +71 -8
- package/src/libraries/CheckMolecule.ts +3 -3
- package/src/libraries/GraphQLClient.ts +61 -23
- package/src/libraries/array.ts +2 -2
- package/src/libraries/crypto.ts +28 -25
- package/src/libraries/strings.ts +3 -3
- package/src/mutation/MutationProposeMolecule.ts +2 -1
- package/src/query/Query.ts +2 -1
- package/src/query/QueryAtom.ts +4 -3
- package/src/query/QueryBalance.ts +2 -1
- package/src/query/QueryBatch.ts +4 -3
- package/src/query/QueryContinuId.ts +4 -3
- package/src/query/QueryMetaType.ts +4 -3
- package/src/query/QueryMetaTypeViaAtom.ts +4 -3
- package/src/query/QueryWalletBundle.ts +2 -1
- package/src/query/QueryWalletList.ts +4 -3
- package/src/response/EnhancedResponse.ts +19 -24
- package/src/response/Response.ts +3 -3
- package/src/response/ResponseAtom.ts +1 -1
- package/src/response/ResponseAuthorizationGuest.ts +1 -1
- package/src/response/ResponseBalance.ts +1 -1
- package/src/response/ResponseContinuId.ts +1 -1
- package/src/response/ResponseMetaType.ts +1 -1
- package/src/response/ResponseMetaTypeViaAtom.ts +1 -1
- package/src/response/ResponsePolicy.ts +1 -1
- package/src/response/ResponseProposeMolecule.ts +4 -5
- package/src/response/ResponseQueryActiveSession.ts +1 -1
- package/src/response/ResponseQueryUserActivity.ts +1 -1
- package/src/response/ResponseRequestAuthorizationGuest.ts +1 -1
- package/src/response/ResponseTransferTokens.ts +1 -1
- package/src/response/ResponseWalletBundle.ts +1 -1
- package/src/response/ResponseWalletList.ts +1 -1
- package/src/types/graphql.ts +8 -0
- package/src/types/index.ts +2 -7
- package/src/types/response.ts +12 -7
|
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
|
48
48
|
|
|
49
49
|
import Query from './Query'
|
|
50
50
|
import ResponseWalletList from '../response/ResponseWalletList'
|
|
51
|
-
import
|
|
51
|
+
import { gql } from '@urql/core'
|
|
52
|
+
import type { GraphQLClient } from '../types/graphql'
|
|
52
53
|
import type KnishIOClient from '../KnishIOClient'
|
|
53
54
|
|
|
54
55
|
/**
|
|
@@ -60,10 +61,10 @@ export default class QueryWalletList extends Query {
|
|
|
60
61
|
* Create new QueryWalletList instance
|
|
61
62
|
* Matches JavaScript SDK constructor signature exactly
|
|
62
63
|
*/
|
|
63
|
-
constructor(graphQLClient:
|
|
64
|
+
constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
|
|
64
65
|
super(graphQLClient, knishIOClient)
|
|
65
66
|
|
|
66
|
-
this.$__query = `query( $bundleHash: String, $tokenSlug: String ) {
|
|
67
|
+
this.$__query = gql`query( $bundleHash: String, $tokenSlug: String ) {
|
|
67
68
|
Wallet( bundleHash: $bundleHash, tokenSlug: $tokenSlug ) {
|
|
68
69
|
address,
|
|
69
70
|
bundleHash,
|
|
@@ -5,17 +5,12 @@
|
|
|
5
5
|
functional programming support, and enhanced error handling.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ValidationResult,
|
|
13
|
-
ResponseError,
|
|
8
|
+
import {
|
|
9
|
+
EnhancedResponse,
|
|
10
|
+
ValidationResult,
|
|
11
|
+
ResponseError,
|
|
14
12
|
ResponseMetadata,
|
|
15
|
-
|
|
16
|
-
ValidationResultSchema,
|
|
17
|
-
isSuccessResponse,
|
|
18
|
-
isErrorResponse
|
|
13
|
+
ValidationResultSchema
|
|
19
14
|
} from '@/types/response'
|
|
20
15
|
|
|
21
16
|
/**
|
|
@@ -93,10 +88,10 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
93
88
|
const mappedValue = mapper(this._payload)
|
|
94
89
|
return new StandardResponse(true, mappedValue, null, this._rawData, this._metadata)
|
|
95
90
|
} catch (error) {
|
|
96
|
-
return new StandardResponse(false, null, `Mapping failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
91
|
+
return new StandardResponse<U>(false, null as any, `Mapping failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
97
92
|
}
|
|
98
93
|
} else {
|
|
99
|
-
return new StandardResponse(false, null, this._errorMessage, this._rawData, this._metadata)
|
|
94
|
+
return new StandardResponse<U>(false, null as any, this._errorMessage, this._rawData, this._metadata)
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
@@ -105,10 +100,10 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
105
100
|
try {
|
|
106
101
|
return mapper(this._payload)
|
|
107
102
|
} catch (error) {
|
|
108
|
-
return new StandardResponse(false, null, `FlatMap failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
103
|
+
return new StandardResponse<U>(false, null as any, `FlatMap failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
109
104
|
}
|
|
110
105
|
} else {
|
|
111
|
-
return new StandardResponse(false, null, this._errorMessage, this._rawData, this._metadata)
|
|
106
|
+
return new StandardResponse<U>(false, null as any, this._errorMessage, this._rawData, this._metadata)
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
109
|
|
|
@@ -118,10 +113,10 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
118
113
|
if (predicate(this._payload)) {
|
|
119
114
|
return this
|
|
120
115
|
} else {
|
|
121
|
-
return new StandardResponse(false, null, 'Filter predicate failed', this._rawData, this._metadata)
|
|
116
|
+
return new StandardResponse<T>(false, null as any, 'Filter predicate failed', this._rawData, this._metadata)
|
|
122
117
|
}
|
|
123
118
|
} catch (error) {
|
|
124
|
-
return new StandardResponse(false, null, `Filter failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
119
|
+
return new StandardResponse<T>(false, null as any, `Filter failed: ${error instanceof Error ? error.message : String(error)}`, this._rawData, this._metadata)
|
|
125
120
|
}
|
|
126
121
|
} else {
|
|
127
122
|
return this
|
|
@@ -187,17 +182,17 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
187
182
|
|
|
188
183
|
static failure<T>(errorMessage: string | ResponseError, rawData?: any, metadata?: Partial<ResponseMetadata>): StandardResponse<T> {
|
|
189
184
|
const message = typeof errorMessage === 'string' ? errorMessage : errorMessage.message
|
|
190
|
-
return new StandardResponse(false, null, message, rawData, metadata)
|
|
185
|
+
return new StandardResponse<T>(false, null as any, message, rawData, metadata)
|
|
191
186
|
}
|
|
192
187
|
|
|
193
188
|
static fromValidationResult<T>(result: ValidationResult<T>, rawData?: any, metadata?: Partial<ResponseMetadata>): StandardResponse<T> {
|
|
194
189
|
if (result.success && result.data !== undefined) {
|
|
195
|
-
return new StandardResponse(true, result.data, null, rawData, {
|
|
190
|
+
return new StandardResponse<T>(true, result.data, null, rawData, {
|
|
196
191
|
...metadata,
|
|
197
192
|
warnings: result.warnings
|
|
198
193
|
})
|
|
199
194
|
} else {
|
|
200
|
-
return new StandardResponse(false, null, result.error?.message || 'Validation failed', rawData, {
|
|
195
|
+
return new StandardResponse<T>(false, null as any, result.error?.message || 'Validation failed', rawData, {
|
|
201
196
|
...metadata,
|
|
202
197
|
error: result.error
|
|
203
198
|
})
|
|
@@ -225,7 +220,7 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
225
220
|
// Enhanced response validation
|
|
226
221
|
validate(): ValidationResult<T> {
|
|
227
222
|
try {
|
|
228
|
-
|
|
223
|
+
ValidationResultSchema.parse(this.toValidationResult())
|
|
229
224
|
return {
|
|
230
225
|
success: true,
|
|
231
226
|
data: this._payload as T,
|
|
@@ -247,27 +242,27 @@ export class StandardResponse<T> implements EnhancedResponse<T> {
|
|
|
247
242
|
export class ResponseFactory {
|
|
248
243
|
|
|
249
244
|
static createSuccessResponse<T>(
|
|
250
|
-
payload: T,
|
|
245
|
+
payload: T,
|
|
251
246
|
operation: string,
|
|
252
247
|
rawData?: any,
|
|
253
248
|
duration?: number
|
|
254
249
|
): StandardResponse<T> {
|
|
255
250
|
return StandardResponse.success(payload, rawData, {
|
|
256
251
|
operation,
|
|
257
|
-
duration,
|
|
252
|
+
...(duration !== undefined ? { duration } : {}),
|
|
258
253
|
timestamp: new Date().toISOString()
|
|
259
254
|
})
|
|
260
255
|
}
|
|
261
256
|
|
|
262
257
|
static createErrorResponse<T>(
|
|
263
258
|
errorMessage: string,
|
|
264
|
-
operation: string,
|
|
259
|
+
operation: string,
|
|
265
260
|
rawData?: any,
|
|
266
261
|
duration?: number
|
|
267
262
|
): StandardResponse<T> {
|
|
268
263
|
return StandardResponse.failure(errorMessage, rawData, {
|
|
269
264
|
operation,
|
|
270
|
-
duration,
|
|
265
|
+
...(duration !== undefined ? { duration } : {}),
|
|
271
266
|
timestamp: new Date().toISOString()
|
|
272
267
|
})
|
|
273
268
|
}
|
package/src/response/Response.ts
CHANGED
|
@@ -57,7 +57,7 @@ import { UniversalResponse, ValidationResult } from '@/types/response'
|
|
|
57
57
|
* Enhanced with standardized interface and ValidationResult support
|
|
58
58
|
*/
|
|
59
59
|
export default class Response implements UniversalResponse<any> {
|
|
60
|
-
|
|
60
|
+
public dataKey: string | null
|
|
61
61
|
protected errorKey: string = 'exception'
|
|
62
62
|
protected $__payload: any = null
|
|
63
63
|
protected $__query: Query
|
|
@@ -89,7 +89,7 @@ export default class Response implements UniversalResponse<any> {
|
|
|
89
89
|
const error = Dot.get(this.$__response, this.errorKey)
|
|
90
90
|
|
|
91
91
|
if (String(error).includes('Unauthenticated')) {
|
|
92
|
-
throw new UnauthenticatedException()
|
|
92
|
+
throw new UnauthenticatedException('Unauthenticated request')
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
throw new InvalidResponseException()
|
|
@@ -186,7 +186,7 @@ export default class Response implements UniversalResponse<any> {
|
|
|
186
186
|
success: false,
|
|
187
187
|
error: {
|
|
188
188
|
message: this.reason() || 'Unknown error',
|
|
189
|
-
context: this.constructor.name,
|
|
189
|
+
context: this.constructor.name as any,
|
|
190
190
|
details: this.$__response?.errors || []
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -76,7 +76,7 @@ export default class ResponseAtom extends Response {
|
|
|
76
76
|
* Returns atom instance results
|
|
77
77
|
* Matches JavaScript SDK payload method exactly
|
|
78
78
|
*/
|
|
79
|
-
payload(): any | null {
|
|
79
|
+
override payload(): any | null {
|
|
80
80
|
const metaTypeData = this.data()
|
|
81
81
|
|
|
82
82
|
if (!metaTypeData) {
|
|
@@ -76,7 +76,7 @@ export default class ResponseBalance extends Response {
|
|
|
76
76
|
* Returns a wallet with balance
|
|
77
77
|
* Matches JavaScript SDK payload() method exactly
|
|
78
78
|
*/
|
|
79
|
-
payload(): Wallet | null {
|
|
79
|
+
override payload(): Wallet | null {
|
|
80
80
|
const walletData = this.data() as any
|
|
81
81
|
|
|
82
82
|
if (!walletData || !walletData.bundleHash || !walletData.tokenSlug) {
|
|
@@ -77,7 +77,7 @@ export default class ResponseContinuId extends Response {
|
|
|
77
77
|
* Returns the ContinuID wallet
|
|
78
78
|
* Matches JavaScript SDK payload method exactly
|
|
79
79
|
*/
|
|
80
|
-
payload(): Wallet | null {
|
|
80
|
+
override payload(): Wallet | null {
|
|
81
81
|
let wallet: Wallet | null = null
|
|
82
82
|
|
|
83
83
|
const continuId = this.data()
|
|
@@ -76,7 +76,7 @@ export default class ResponseMetaType extends Response {
|
|
|
76
76
|
* Returns meta type instance results
|
|
77
77
|
* Matches JavaScript SDK payload method exactly
|
|
78
78
|
*/
|
|
79
|
-
payload(): any | null {
|
|
79
|
+
override payload(): any | null {
|
|
80
80
|
const metaTypeData = this.data()
|
|
81
81
|
|
|
82
82
|
if (!metaTypeData || metaTypeData.length === 0) {
|
|
@@ -76,7 +76,7 @@ export default class ResponseMetaTypeViaAtom extends Response {
|
|
|
76
76
|
* Returns meta type instance results via atom
|
|
77
77
|
* Matches JavaScript SDK payload method exactly
|
|
78
78
|
*/
|
|
79
|
-
payload(): any | null {
|
|
79
|
+
override payload(): any | null {
|
|
80
80
|
const metaTypeData = this.data()
|
|
81
81
|
|
|
82
82
|
if (!metaTypeData || metaTypeData.length === 0) {
|
|
@@ -57,7 +57,6 @@ import type Query from '../query/Query'
|
|
|
57
57
|
*/
|
|
58
58
|
export default class ResponseProposeMolecule extends Response {
|
|
59
59
|
private $__clientMolecule: any
|
|
60
|
-
private $__payload: any = null
|
|
61
60
|
|
|
62
61
|
/**
|
|
63
62
|
* Class constructor
|
|
@@ -82,7 +81,7 @@ export default class ResponseProposeMolecule extends Response {
|
|
|
82
81
|
* Initialize response object with payload data
|
|
83
82
|
* Matches JavaScript SDK init method exactly
|
|
84
83
|
*/
|
|
85
|
-
init(): void {
|
|
84
|
+
override init(): void {
|
|
86
85
|
const payloadJson = Dot.get(this.data(), 'payload')
|
|
87
86
|
try {
|
|
88
87
|
this.$__payload = Object.prototype.toString.call(payloadJson) === '[object String]'
|
|
@@ -125,7 +124,7 @@ export default class ResponseProposeMolecule extends Response {
|
|
|
125
124
|
* Returns whether molecule was accepted or not
|
|
126
125
|
* Matches JavaScript SDK success method exactly
|
|
127
126
|
*/
|
|
128
|
-
success(): boolean {
|
|
127
|
+
override success(): boolean {
|
|
129
128
|
return this.status() === 'accepted'
|
|
130
129
|
}
|
|
131
130
|
|
|
@@ -141,7 +140,7 @@ export default class ResponseProposeMolecule extends Response {
|
|
|
141
140
|
* Returns the reason for rejection
|
|
142
141
|
* Matches JavaScript SDK reason method exactly
|
|
143
142
|
*/
|
|
144
|
-
reason(): string {
|
|
143
|
+
override reason(): string {
|
|
145
144
|
return Dot.get(this.data(), 'reason', 'Invalid response from server') as string
|
|
146
145
|
}
|
|
147
146
|
|
|
@@ -149,7 +148,7 @@ export default class ResponseProposeMolecule extends Response {
|
|
|
149
148
|
* Returns payload object
|
|
150
149
|
* Matches JavaScript SDK payload method exactly
|
|
151
150
|
*/
|
|
152
|
-
payload(): any {
|
|
151
|
+
override payload(): any {
|
|
153
152
|
return this.$__payload
|
|
154
153
|
}
|
|
155
154
|
}
|
|
@@ -57,7 +57,7 @@ export default class ResponseTransferTokens extends ResponseProposeMolecule {
|
|
|
57
57
|
* Returns result of the transfer
|
|
58
58
|
* Matches JavaScript SDK payload method exactly
|
|
59
59
|
*/
|
|
60
|
-
payload(): { reason: string | null; status: string | null } {
|
|
60
|
+
override payload(): { reason: string | null; status: string | null } {
|
|
61
61
|
const result = {
|
|
62
62
|
reason: null as string | null,
|
|
63
63
|
status: null as string | null
|
|
@@ -76,7 +76,7 @@ export default class ResponseWalletBundle extends Response {
|
|
|
76
76
|
* Returns a wallet bundle with normalized metadata
|
|
77
77
|
* Matches JavaScript SDK payload() method exactly
|
|
78
78
|
*/
|
|
79
|
-
payload(): Record<string, any> | null {
|
|
79
|
+
override payload(): Record<string, any> | null {
|
|
80
80
|
const bundleData = this.data() as any[]
|
|
81
81
|
|
|
82
82
|
if (!bundleData || bundleData.length === 0) {
|
|
@@ -159,7 +159,7 @@ export default class ResponseWalletList extends Response {
|
|
|
159
159
|
* Returns response payload
|
|
160
160
|
* Matches JavaScript SDK payload method exactly
|
|
161
161
|
*/
|
|
162
|
-
payload(): Wallet[] | null {
|
|
162
|
+
override payload(): Wallet[] | null {
|
|
163
163
|
return this.getWallets()
|
|
164
164
|
}
|
|
165
165
|
}
|
package/src/types/graphql.ts
CHANGED
|
@@ -490,10 +490,18 @@ export interface GraphQLClient {
|
|
|
490
490
|
variables?: TVariables
|
|
491
491
|
): Promise<GraphQLResponse<TResult>>
|
|
492
492
|
|
|
493
|
+
// Alias for mutation() to match JS SDK interface
|
|
494
|
+
mutate<TResult = unknown, TVariables = GraphQLVariables>(
|
|
495
|
+
request: GraphQLRequest,
|
|
496
|
+
variables?: TVariables
|
|
497
|
+
): Promise<GraphQLResponse<TResult>>
|
|
498
|
+
|
|
493
499
|
subscription<TResult = unknown, TVariables = GraphQLVariables>(
|
|
494
500
|
request: GraphQLRequest,
|
|
495
501
|
variables?: TVariables
|
|
496
502
|
): AsyncIterableIterator<GraphQLResponse<TResult>>
|
|
503
|
+
|
|
504
|
+
getUri(): string
|
|
497
505
|
}
|
|
498
506
|
|
|
499
507
|
export interface UrqlClientWrapper extends GraphQLClient {
|
package/src/types/index.ts
CHANGED
|
@@ -57,9 +57,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
|
57
57
|
|
|
58
58
|
import type {
|
|
59
59
|
AtomIsotope,
|
|
60
|
-
KnishIOErrorType,
|
|
61
|
-
HexChar,
|
|
62
|
-
Base17Char,
|
|
60
|
+
KnishIOErrorType,
|
|
61
|
+
HexChar,
|
|
63
62
|
HexPattern,
|
|
64
63
|
Base17Pattern,
|
|
65
64
|
WalletAddressPattern,
|
|
@@ -69,10 +68,6 @@ import type {
|
|
|
69
68
|
ErrorMessageTemplate,
|
|
70
69
|
ValidationErrorTemplate,
|
|
71
70
|
OperationErrorTemplate,
|
|
72
|
-
QueryType,
|
|
73
|
-
MutationType,
|
|
74
|
-
SubscriptionType,
|
|
75
|
-
BalanceQueryType,
|
|
76
71
|
NodeEnvironment
|
|
77
72
|
} from '../constants'
|
|
78
73
|
|
package/src/types/response.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface ValidationResult<T> {
|
|
|
24
24
|
details?: string[]
|
|
25
25
|
code?: string
|
|
26
26
|
context?: Record<string, any>
|
|
27
|
+
timestamp?: string
|
|
28
|
+
operation?: string
|
|
27
29
|
}
|
|
28
30
|
warnings?: string[]
|
|
29
31
|
}
|
|
@@ -31,11 +33,11 @@ export interface ValidationResult<T> {
|
|
|
31
33
|
// Enhanced error information with detailed context
|
|
32
34
|
export interface ResponseError {
|
|
33
35
|
message: string
|
|
34
|
-
code?: string
|
|
36
|
+
code?: string | undefined
|
|
35
37
|
details?: any
|
|
36
|
-
context?: string
|
|
37
|
-
timestamp?: string
|
|
38
|
-
operation?: string
|
|
38
|
+
context?: string | Record<string, any> | undefined
|
|
39
|
+
timestamp?: string | undefined
|
|
40
|
+
operation?: string | undefined
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
// Response validation schemas for runtime type checking
|
|
@@ -92,10 +94,13 @@ export interface ConfigValidationResult<T> extends ValidationResult<T> {
|
|
|
92
94
|
export interface ResponseMetadata {
|
|
93
95
|
timestamp: string
|
|
94
96
|
operation: string
|
|
95
|
-
duration?: number
|
|
96
|
-
requestId?: string
|
|
97
|
-
serverVersion?: string
|
|
97
|
+
duration?: number | undefined
|
|
98
|
+
requestId?: string | undefined
|
|
99
|
+
serverVersion?: string | undefined
|
|
98
100
|
clientVersion: string
|
|
101
|
+
// Additional properties used in enhanced error handling
|
|
102
|
+
warnings?: string[] | undefined
|
|
103
|
+
error?: ResponseError | undefined
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
// Enhanced response type with comprehensive metadata
|