@wishknish/knishio-client-ts 0.7.0
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/LICENSE +674 -0
- package/README.md +425 -0
- package/dist/index.cjs +9961 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.iife.js +32241 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.js +9853 -0
- package/dist/index.js.map +1 -0
- package/package.json +113 -0
- package/src/AuthToken.ts +214 -0
- package/src/KnishIOClient.ts +2020 -0
- package/src/constants.ts +398 -0
- package/src/core/Atom.ts +646 -0
- package/src/core/AtomMeta.ts +278 -0
- package/src/core/Meta.ts +428 -0
- package/src/core/Molecule.ts +825 -0
- package/src/core/PolicyMeta.ts +130 -0
- package/src/core/TokenUnit.ts +148 -0
- package/src/core/Wallet.ts +467 -0
- package/src/exception/AtomIndexException.ts +97 -0
- package/src/exception/AtomsMissingException.ts +109 -0
- package/src/exception/AuthorizationRejectedException.ts +63 -0
- package/src/exception/BalanceInsufficientException.ts +58 -0
- package/src/exception/BaseException.ts +275 -0
- package/src/exception/BatchIdException.ts +58 -0
- package/src/exception/CodeException.ts +119 -0
- package/src/exception/DecryptionKeyException.ts +65 -0
- package/src/exception/InvalidResponseException.ts +112 -0
- package/src/exception/MetaMissingException.ts +58 -0
- package/src/exception/MolecularHashMismatchException.ts +115 -0
- package/src/exception/MolecularHashMissingException.ts +58 -0
- package/src/exception/NegativeAmountException.ts +58 -0
- package/src/exception/PolicyInvalidException.ts +58 -0
- package/src/exception/SignatureMalformedException.ts +58 -0
- package/src/exception/SignatureMismatchException.ts +98 -0
- package/src/exception/StackableUnitAmountException.ts +65 -0
- package/src/exception/StackableUnitDecimalsException.ts +65 -0
- package/src/exception/TransferBalanceException.ts +98 -0
- package/src/exception/TransferMalformedException.ts +58 -0
- package/src/exception/TransferMismatchedException.ts +58 -0
- package/src/exception/TransferRemainderException.ts +58 -0
- package/src/exception/TransferToSelfException.ts +58 -0
- package/src/exception/TransferUnbalancedException.ts +58 -0
- package/src/exception/UnauthenticatedException.ts +147 -0
- package/src/exception/WalletCredentialException.ts +108 -0
- package/src/exception/WalletShadowException.ts +65 -0
- package/src/exception/WrongTokenTypeException.ts +58 -0
- package/src/exception/index.ts +272 -0
- package/src/index.ts +512 -0
- package/src/instance/rules/Callback.ts +257 -0
- package/src/instance/rules/Condition.ts +96 -0
- package/src/instance/rules/Meta.ts +163 -0
- package/src/instance/rules/Rule.ts +29 -0
- package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
- package/src/libraries/CheckMolecule.ts +581 -0
- package/src/libraries/Decimal.ts +94 -0
- package/src/libraries/Dot.ts +202 -0
- package/src/libraries/GraphQLClient.ts +276 -0
- package/src/libraries/Hex.ts +155 -0
- package/src/libraries/UrqlClientWrapper.ts +336 -0
- package/src/libraries/array.ts +91 -0
- package/src/libraries/crypto.ts +816 -0
- package/src/libraries/strings.ts +458 -0
- package/src/mutation/Mutation.ts +103 -0
- package/src/mutation/MutationActiveSession.ts +108 -0
- package/src/mutation/MutationClaimShadowWallet.ts +91 -0
- package/src/mutation/MutationCreateIdentifier.ts +86 -0
- package/src/mutation/MutationCreateMeta.ts +92 -0
- package/src/mutation/MutationCreateRule.ts +90 -0
- package/src/mutation/MutationCreateToken.ts +92 -0
- package/src/mutation/MutationCreateWallet.ts +78 -0
- package/src/mutation/MutationDepositBufferToken.ts +72 -0
- package/src/mutation/MutationLinkIdentifier.ts +87 -0
- package/src/mutation/MutationProposeMolecule.ts +147 -0
- package/src/mutation/MutationRequestAuthorization.ts +77 -0
- package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
- package/src/mutation/MutationRequestTokens.ts +98 -0
- package/src/mutation/MutationTransferTokens.ts +87 -0
- package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
- package/src/query/Query.ts +187 -0
- package/src/query/QueryActiveSession.ts +89 -0
- package/src/query/QueryAtom.ts +275 -0
- package/src/query/QueryBalance.ts +102 -0
- package/src/query/QueryBatch.ts +145 -0
- package/src/query/QueryBatchHistory.ts +86 -0
- package/src/query/QueryContinuId.ts +91 -0
- package/src/query/QueryMetaType.ts +177 -0
- package/src/query/QueryMetaTypeViaAtom.ts +199 -0
- package/src/query/QueryPolicy.ts +91 -0
- package/src/query/QueryToken.ts +90 -0
- package/src/query/QueryUserActivity.ts +153 -0
- package/src/query/QueryWalletBundle.ts +92 -0
- package/src/query/QueryWalletList.ts +106 -0
- package/src/response/EnhancedResponse.ts +345 -0
- package/src/response/Response.ts +254 -0
- package/src/response/ResponseActiveSession.ts +72 -0
- package/src/response/ResponseAtom.ts +132 -0
- package/src/response/ResponseAuthorizationGuest.ts +119 -0
- package/src/response/ResponseBalance.ts +153 -0
- package/src/response/ResponseClaimShadowWallet.ts +56 -0
- package/src/response/ResponseContinuId.ts +101 -0
- package/src/response/ResponseCreateIdentifier.ts +56 -0
- package/src/response/ResponseCreateMeta.ts +58 -0
- package/src/response/ResponseCreateRule.ts +56 -0
- package/src/response/ResponseCreateToken.ts +58 -0
- package/src/response/ResponseCreateWallet.ts +58 -0
- package/src/response/ResponseLinkIdentifier.ts +87 -0
- package/src/response/ResponseMetaBatch.ts +72 -0
- package/src/response/ResponseMetaType.ts +108 -0
- package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
- package/src/response/ResponsePolicy.ts +90 -0
- package/src/response/ResponseProposeMolecule.ts +155 -0
- package/src/response/ResponseQueryActiveSession.ts +105 -0
- package/src/response/ResponseQueryUserActivity.ts +89 -0
- package/src/response/ResponseRequestAuthorization.ts +100 -0
- package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
- package/src/response/ResponseRequestTokens.ts +58 -0
- package/src/response/ResponseTransferTokens.ts +72 -0
- package/src/response/ResponseWalletBundle.ts +95 -0
- package/src/response/ResponseWalletList.ts +165 -0
- package/src/schemas/index.ts +457 -0
- package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
- package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
- package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
- package/src/subscribe/Subscribe.ts +182 -0
- package/src/subscribe/WalletStatusSubscribe.ts +70 -0
- package/src/subscribe/index.ts +59 -0
- package/src/types/assertions.ts +722 -0
- package/src/types/client.ts +567 -0
- package/src/types/crypto.ts +541 -0
- package/src/types/graphql.ts +630 -0
- package/src/types/guards.ts +659 -0
- package/src/types/index.ts +614 -0
- package/src/types/response.ts +133 -0
- package/src/types/template-literals.ts +382 -0
- package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
- package/src/validation/ValidationService.ts +607 -0
- package/src/validation/schemas.ts +447 -0
- package/src/versions/HashAtom.ts +170 -0
- package/src/versions/Version4.ts +120 -0
- package/src/versions/index.ts +80 -0
|
@@ -0,0 +1,63 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when attempt to authorize is rejected by the node
|
|
53
|
+
*/
|
|
54
|
+
export class AuthorizationRejectedException extends BaseException {
|
|
55
|
+
/**
|
|
56
|
+
* Constructor
|
|
57
|
+
*/
|
|
58
|
+
constructor(message: string = 'Authorization attempt rejected by ledger.') {
|
|
59
|
+
super('AUTHORIZATION_REJECTED_ERROR', message)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default AuthorizationRejectedException
|
|
@@ -0,0 +1,58 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Exception thrown when balance is insufficient for operation
|
|
53
|
+
*/
|
|
54
|
+
export default class BalanceInsufficientException extends BaseException {
|
|
55
|
+
constructor(message = 'Insufficient balance for this operation') {
|
|
56
|
+
super('BALANCE_INSUFFICIENT_ERROR', message)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
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
|
+
/**
|
|
50
|
+
* Base exception class for all KnishIO SDK errors
|
|
51
|
+
* Provides enhanced error handling with context and type safety
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import type { KnishIOErrorType, ErrorContext } from '@/types'
|
|
55
|
+
|
|
56
|
+
export interface BaseExceptionOptions {
|
|
57
|
+
message?: string
|
|
58
|
+
cause?: Error | unknown
|
|
59
|
+
context?: ErrorContext
|
|
60
|
+
code?: string
|
|
61
|
+
details?: Record<string, unknown>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Base exception class that all KnishIO SDK exceptions extend
|
|
66
|
+
* Maintains compatibility with JavaScript SDK while adding TypeScript enhancements
|
|
67
|
+
*/
|
|
68
|
+
export default class BaseException extends Error {
|
|
69
|
+
public readonly type: KnishIOErrorType
|
|
70
|
+
public readonly context: ErrorContext | null
|
|
71
|
+
public readonly code: string | null
|
|
72
|
+
public readonly details: Record<string, unknown> | null
|
|
73
|
+
public readonly timestamp: number
|
|
74
|
+
|
|
75
|
+
constructor(
|
|
76
|
+
type: KnishIOErrorType,
|
|
77
|
+
message: string,
|
|
78
|
+
options: BaseExceptionOptions = {}
|
|
79
|
+
) {
|
|
80
|
+
super(message)
|
|
81
|
+
|
|
82
|
+
// Maintain compatibility with Error interface
|
|
83
|
+
this.name = this.constructor.name
|
|
84
|
+
|
|
85
|
+
// KnishIO specific properties
|
|
86
|
+
this.type = type
|
|
87
|
+
this.context = options.context || null
|
|
88
|
+
this.code = options.code || null
|
|
89
|
+
this.details = options.details || null
|
|
90
|
+
this.timestamp = Date.now()
|
|
91
|
+
|
|
92
|
+
// Preserve stack trace
|
|
93
|
+
if (Error.captureStackTrace) {
|
|
94
|
+
Error.captureStackTrace(this, this.constructor)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Chain the cause if provided
|
|
98
|
+
if (options.cause) {
|
|
99
|
+
this.cause = options.cause
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get human-readable error message with context
|
|
105
|
+
*/
|
|
106
|
+
public getFullMessage(): string {
|
|
107
|
+
let fullMessage = this.message
|
|
108
|
+
|
|
109
|
+
if (this.context?.operation) {
|
|
110
|
+
fullMessage += ` (Operation: ${this.context.operation})`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (this.code) {
|
|
114
|
+
fullMessage += ` [Code: ${this.code}]`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return fullMessage
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get structured error data for logging/debugging
|
|
122
|
+
*/
|
|
123
|
+
public toJSON(): Record<string, unknown> {
|
|
124
|
+
return {
|
|
125
|
+
name: this.name,
|
|
126
|
+
type: this.type,
|
|
127
|
+
message: this.message,
|
|
128
|
+
code: this.code,
|
|
129
|
+
context: this.context,
|
|
130
|
+
details: this.details,
|
|
131
|
+
timestamp: this.timestamp,
|
|
132
|
+
stack: this.stack
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Check if this exception is of a specific type
|
|
138
|
+
*/
|
|
139
|
+
public isType(type: KnishIOErrorType): boolean {
|
|
140
|
+
return this.type === type
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get error context for the specific parameter
|
|
145
|
+
*/
|
|
146
|
+
public getContextValue(key: keyof ErrorContext): unknown {
|
|
147
|
+
return this.context?.[key] || null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Add additional context to the exception
|
|
152
|
+
*/
|
|
153
|
+
public withContext(additionalContext: Partial<ErrorContext>): this {
|
|
154
|
+
if (this.context) {
|
|
155
|
+
Object.assign(this.context, additionalContext)
|
|
156
|
+
}
|
|
157
|
+
return this
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Static factory method for creating exceptions with full context
|
|
162
|
+
*/
|
|
163
|
+
static create<T extends BaseException>(
|
|
164
|
+
this: new (type: KnishIOErrorType, message: string, options?: BaseExceptionOptions) => T,
|
|
165
|
+
type: KnishIOErrorType,
|
|
166
|
+
message: string,
|
|
167
|
+
options: BaseExceptionOptions = {}
|
|
168
|
+
): T {
|
|
169
|
+
return new this(type, message, {
|
|
170
|
+
...options,
|
|
171
|
+
context: {
|
|
172
|
+
timestamp: Date.now(),
|
|
173
|
+
...(new Error().stack ? { stack: new Error().stack } : {}),
|
|
174
|
+
...options.context
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Check if an error is a KnishIO SDK exception
|
|
181
|
+
*/
|
|
182
|
+
static isKnishIOException(error: unknown): error is BaseException {
|
|
183
|
+
return error instanceof BaseException
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Extract error type from any error
|
|
188
|
+
*/
|
|
189
|
+
static getErrorType(error: unknown): KnishIOErrorType | null {
|
|
190
|
+
if (BaseException.isKnishIOException(error)) {
|
|
191
|
+
return error.type
|
|
192
|
+
}
|
|
193
|
+
return null
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Convert any error to a KnishIO exception
|
|
198
|
+
*/
|
|
199
|
+
static fromError(
|
|
200
|
+
error: Error | unknown,
|
|
201
|
+
type: KnishIOErrorType = 'CODE_ERROR',
|
|
202
|
+
additionalContext?: Partial<ErrorContext>
|
|
203
|
+
): BaseException {
|
|
204
|
+
if (BaseException.isKnishIOException(error)) {
|
|
205
|
+
return error
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
209
|
+
const stack = error instanceof Error ? error.stack : undefined
|
|
210
|
+
|
|
211
|
+
return new BaseException(type, message, {
|
|
212
|
+
cause: error,
|
|
213
|
+
context: {
|
|
214
|
+
timestamp: Date.now(),
|
|
215
|
+
...(stack ? { stack } : {}),
|
|
216
|
+
...additionalContext
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// =============================================================================
|
|
223
|
+
// TYPE GUARDS AND UTILITY FUNCTIONS
|
|
224
|
+
// =============================================================================
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Type guard to check if an error is a specific KnishIO exception type
|
|
228
|
+
*/
|
|
229
|
+
export function isKnishIOError<T extends BaseException>(
|
|
230
|
+
error: unknown,
|
|
231
|
+
ExceptionClass: new (...args: any[]) => T
|
|
232
|
+
): error is T {
|
|
233
|
+
return error instanceof ExceptionClass
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Type guard to check if an error has a specific error type
|
|
238
|
+
*/
|
|
239
|
+
export function hasErrorType(error: unknown, type: KnishIOErrorType): error is BaseException {
|
|
240
|
+
return BaseException.isKnishIOException(error) && error.type === type
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Extract error message from any error-like object
|
|
245
|
+
*/
|
|
246
|
+
export function getErrorMessage(error: unknown): string {
|
|
247
|
+
if (error instanceof Error) {
|
|
248
|
+
return error.message
|
|
249
|
+
}
|
|
250
|
+
if (typeof error === 'string') {
|
|
251
|
+
return error
|
|
252
|
+
}
|
|
253
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
254
|
+
return String((error as { message: unknown }).message)
|
|
255
|
+
}
|
|
256
|
+
return 'Unknown error'
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Create error context for operations
|
|
261
|
+
*/
|
|
262
|
+
export function createErrorContext(
|
|
263
|
+
operation: string,
|
|
264
|
+
parameters: Record<string, unknown> = {},
|
|
265
|
+
additionalContext: Partial<ErrorContext> = {}
|
|
266
|
+
): ErrorContext {
|
|
267
|
+
const stack = new Error().stack
|
|
268
|
+
return {
|
|
269
|
+
operation,
|
|
270
|
+
parameters,
|
|
271
|
+
timestamp: Date.now(),
|
|
272
|
+
...(stack ? { stack } : {}),
|
|
273
|
+
...additionalContext
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Exception thrown when batch ID validation fails
|
|
53
|
+
*/
|
|
54
|
+
export default class BatchIdException extends BaseException {
|
|
55
|
+
constructor(message = 'Batch ID validation failed') {
|
|
56
|
+
super('BATCH_ID_ERROR', message)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 BaseException, { type BaseExceptionOptions } from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* CodeException - Thrown when there are code-related issues
|
|
53
|
+
* Used for general application logic errors
|
|
54
|
+
*/
|
|
55
|
+
export default class CodeException extends BaseException {
|
|
56
|
+
public readonly errorType: string = 'CODE_ERROR'
|
|
57
|
+
|
|
58
|
+
constructor(message: string, options: BaseExceptionOptions = {}) {
|
|
59
|
+
super('CODE_ERROR', message, {
|
|
60
|
+
code: 'CODE_ERROR',
|
|
61
|
+
...options
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create exception for general code errors
|
|
67
|
+
*/
|
|
68
|
+
static codeError(message: string, context?: Record<string, unknown>): CodeException {
|
|
69
|
+
return new CodeException(message, {
|
|
70
|
+
code: 'CODE_ERROR',
|
|
71
|
+
...(context ? { context } : {})
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create exception for validation errors
|
|
77
|
+
*/
|
|
78
|
+
static validationError(field: string, value: unknown, context?: Record<string, unknown>): CodeException {
|
|
79
|
+
return new CodeException(`Validation failed for field '${field}' with value: ${value}`, {
|
|
80
|
+
code: 'VALIDATION_ERROR',
|
|
81
|
+
context: {
|
|
82
|
+
operation: 'validation',
|
|
83
|
+
parameters: {
|
|
84
|
+
field,
|
|
85
|
+
value,
|
|
86
|
+
...context
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create exception for configuration errors
|
|
94
|
+
*/
|
|
95
|
+
static configurationError(message: string, context?: Record<string, unknown>): CodeException {
|
|
96
|
+
return new CodeException(`Configuration error: ${message}`, {
|
|
97
|
+
code: 'CONFIGURATION_ERROR',
|
|
98
|
+
...(context ? { context } : {})
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Create exception for operation failures
|
|
104
|
+
*/
|
|
105
|
+
static operationFailed(operation: string, reason?: string, context?: Record<string, unknown>): CodeException {
|
|
106
|
+
const message = reason
|
|
107
|
+
? `Operation '${operation}' failed: ${reason}`
|
|
108
|
+
: `Operation '${operation}' failed`
|
|
109
|
+
|
|
110
|
+
return new CodeException(message, {
|
|
111
|
+
code: 'OPERATION_FAILED',
|
|
112
|
+
context: {
|
|
113
|
+
operation,
|
|
114
|
+
...(reason ? { reason } : {}),
|
|
115
|
+
...context
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Decryption key exception - thrown when decryption fails
|
|
53
|
+
*/
|
|
54
|
+
export class DecryptionKeyException extends BaseException {
|
|
55
|
+
/**
|
|
56
|
+
* Constructor using proper error type
|
|
57
|
+
*/
|
|
58
|
+
constructor(
|
|
59
|
+
message: string = 'The decryption key was not valid for the given message.'
|
|
60
|
+
) {
|
|
61
|
+
super('DECRYPTION_KEY_ERROR', message)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default DecryptionKeyException
|