@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.
Files changed (141) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +425 -0
  3. package/dist/index.cjs +9961 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.iife.js +32241 -0
  6. package/dist/index.iife.js.map +1 -0
  7. package/dist/index.js +9853 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +113 -0
  10. package/src/AuthToken.ts +214 -0
  11. package/src/KnishIOClient.ts +2020 -0
  12. package/src/constants.ts +398 -0
  13. package/src/core/Atom.ts +646 -0
  14. package/src/core/AtomMeta.ts +278 -0
  15. package/src/core/Meta.ts +428 -0
  16. package/src/core/Molecule.ts +825 -0
  17. package/src/core/PolicyMeta.ts +130 -0
  18. package/src/core/TokenUnit.ts +148 -0
  19. package/src/core/Wallet.ts +467 -0
  20. package/src/exception/AtomIndexException.ts +97 -0
  21. package/src/exception/AtomsMissingException.ts +109 -0
  22. package/src/exception/AuthorizationRejectedException.ts +63 -0
  23. package/src/exception/BalanceInsufficientException.ts +58 -0
  24. package/src/exception/BaseException.ts +275 -0
  25. package/src/exception/BatchIdException.ts +58 -0
  26. package/src/exception/CodeException.ts +119 -0
  27. package/src/exception/DecryptionKeyException.ts +65 -0
  28. package/src/exception/InvalidResponseException.ts +112 -0
  29. package/src/exception/MetaMissingException.ts +58 -0
  30. package/src/exception/MolecularHashMismatchException.ts +115 -0
  31. package/src/exception/MolecularHashMissingException.ts +58 -0
  32. package/src/exception/NegativeAmountException.ts +58 -0
  33. package/src/exception/PolicyInvalidException.ts +58 -0
  34. package/src/exception/SignatureMalformedException.ts +58 -0
  35. package/src/exception/SignatureMismatchException.ts +98 -0
  36. package/src/exception/StackableUnitAmountException.ts +65 -0
  37. package/src/exception/StackableUnitDecimalsException.ts +65 -0
  38. package/src/exception/TransferBalanceException.ts +98 -0
  39. package/src/exception/TransferMalformedException.ts +58 -0
  40. package/src/exception/TransferMismatchedException.ts +58 -0
  41. package/src/exception/TransferRemainderException.ts +58 -0
  42. package/src/exception/TransferToSelfException.ts +58 -0
  43. package/src/exception/TransferUnbalancedException.ts +58 -0
  44. package/src/exception/UnauthenticatedException.ts +147 -0
  45. package/src/exception/WalletCredentialException.ts +108 -0
  46. package/src/exception/WalletShadowException.ts +65 -0
  47. package/src/exception/WrongTokenTypeException.ts +58 -0
  48. package/src/exception/index.ts +272 -0
  49. package/src/index.ts +512 -0
  50. package/src/instance/rules/Callback.ts +257 -0
  51. package/src/instance/rules/Condition.ts +96 -0
  52. package/src/instance/rules/Meta.ts +163 -0
  53. package/src/instance/rules/Rule.ts +29 -0
  54. package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
  55. package/src/libraries/CheckMolecule.ts +581 -0
  56. package/src/libraries/Decimal.ts +94 -0
  57. package/src/libraries/Dot.ts +202 -0
  58. package/src/libraries/GraphQLClient.ts +276 -0
  59. package/src/libraries/Hex.ts +155 -0
  60. package/src/libraries/UrqlClientWrapper.ts +336 -0
  61. package/src/libraries/array.ts +91 -0
  62. package/src/libraries/crypto.ts +816 -0
  63. package/src/libraries/strings.ts +458 -0
  64. package/src/mutation/Mutation.ts +103 -0
  65. package/src/mutation/MutationActiveSession.ts +108 -0
  66. package/src/mutation/MutationClaimShadowWallet.ts +91 -0
  67. package/src/mutation/MutationCreateIdentifier.ts +86 -0
  68. package/src/mutation/MutationCreateMeta.ts +92 -0
  69. package/src/mutation/MutationCreateRule.ts +90 -0
  70. package/src/mutation/MutationCreateToken.ts +92 -0
  71. package/src/mutation/MutationCreateWallet.ts +78 -0
  72. package/src/mutation/MutationDepositBufferToken.ts +72 -0
  73. package/src/mutation/MutationLinkIdentifier.ts +87 -0
  74. package/src/mutation/MutationProposeMolecule.ts +147 -0
  75. package/src/mutation/MutationRequestAuthorization.ts +77 -0
  76. package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
  77. package/src/mutation/MutationRequestTokens.ts +98 -0
  78. package/src/mutation/MutationTransferTokens.ts +87 -0
  79. package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
  80. package/src/query/Query.ts +187 -0
  81. package/src/query/QueryActiveSession.ts +89 -0
  82. package/src/query/QueryAtom.ts +275 -0
  83. package/src/query/QueryBalance.ts +102 -0
  84. package/src/query/QueryBatch.ts +145 -0
  85. package/src/query/QueryBatchHistory.ts +86 -0
  86. package/src/query/QueryContinuId.ts +91 -0
  87. package/src/query/QueryMetaType.ts +177 -0
  88. package/src/query/QueryMetaTypeViaAtom.ts +199 -0
  89. package/src/query/QueryPolicy.ts +91 -0
  90. package/src/query/QueryToken.ts +90 -0
  91. package/src/query/QueryUserActivity.ts +153 -0
  92. package/src/query/QueryWalletBundle.ts +92 -0
  93. package/src/query/QueryWalletList.ts +106 -0
  94. package/src/response/EnhancedResponse.ts +345 -0
  95. package/src/response/Response.ts +254 -0
  96. package/src/response/ResponseActiveSession.ts +72 -0
  97. package/src/response/ResponseAtom.ts +132 -0
  98. package/src/response/ResponseAuthorizationGuest.ts +119 -0
  99. package/src/response/ResponseBalance.ts +153 -0
  100. package/src/response/ResponseClaimShadowWallet.ts +56 -0
  101. package/src/response/ResponseContinuId.ts +101 -0
  102. package/src/response/ResponseCreateIdentifier.ts +56 -0
  103. package/src/response/ResponseCreateMeta.ts +58 -0
  104. package/src/response/ResponseCreateRule.ts +56 -0
  105. package/src/response/ResponseCreateToken.ts +58 -0
  106. package/src/response/ResponseCreateWallet.ts +58 -0
  107. package/src/response/ResponseLinkIdentifier.ts +87 -0
  108. package/src/response/ResponseMetaBatch.ts +72 -0
  109. package/src/response/ResponseMetaType.ts +108 -0
  110. package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
  111. package/src/response/ResponsePolicy.ts +90 -0
  112. package/src/response/ResponseProposeMolecule.ts +155 -0
  113. package/src/response/ResponseQueryActiveSession.ts +105 -0
  114. package/src/response/ResponseQueryUserActivity.ts +89 -0
  115. package/src/response/ResponseRequestAuthorization.ts +100 -0
  116. package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
  117. package/src/response/ResponseRequestTokens.ts +58 -0
  118. package/src/response/ResponseTransferTokens.ts +72 -0
  119. package/src/response/ResponseWalletBundle.ts +95 -0
  120. package/src/response/ResponseWalletList.ts +165 -0
  121. package/src/schemas/index.ts +457 -0
  122. package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
  123. package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
  124. package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
  125. package/src/subscribe/Subscribe.ts +182 -0
  126. package/src/subscribe/WalletStatusSubscribe.ts +70 -0
  127. package/src/subscribe/index.ts +59 -0
  128. package/src/types/assertions.ts +722 -0
  129. package/src/types/client.ts +567 -0
  130. package/src/types/crypto.ts +541 -0
  131. package/src/types/graphql.ts +630 -0
  132. package/src/types/guards.ts +659 -0
  133. package/src/types/index.ts +614 -0
  134. package/src/types/response.ts +133 -0
  135. package/src/types/template-literals.ts +382 -0
  136. package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
  137. package/src/validation/ValidationService.ts +607 -0
  138. package/src/validation/schemas.ts +447 -0
  139. package/src/versions/HashAtom.ts +170 -0
  140. package/src/versions/Version4.ts +120 -0
  141. package/src/versions/index.ts +80 -0
@@ -0,0 +1,90 @@
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 Response from './Response'
50
+ import type Query from '@/query/Query'
51
+
52
+ /**
53
+ * Response for Policy queries
54
+ */
55
+ export default class ResponsePolicy extends Response {
56
+ /**
57
+ * Constructor
58
+ */
59
+ constructor({
60
+ query,
61
+ json
62
+ }: {
63
+ query: Query
64
+ json: Record<string, any>
65
+ }) {
66
+ super({
67
+ query,
68
+ json
69
+ })
70
+ this.dataKey = 'data.Policy'
71
+ this.init()
72
+ }
73
+
74
+ /**
75
+ * Returns the policy payload
76
+ */
77
+ payload(): any {
78
+ const policy = this.data()
79
+
80
+ if (!policy) {
81
+ return null
82
+ }
83
+
84
+ if (policy.callback) {
85
+ return JSON.parse(policy.callback)
86
+ }
87
+
88
+ return null
89
+ }
90
+ }
@@ -0,0 +1,155 @@
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 Response from './Response'
50
+ import Dot from '../libraries/Dot'
51
+ import Molecule from '../core/Molecule'
52
+ import type Query from '../query/Query'
53
+
54
+ /**
55
+ * Response for proposing new Molecules
56
+ * Matches JavaScript SDK ResponseProposeMolecule implementation exactly
57
+ */
58
+ export default class ResponseProposeMolecule extends Response {
59
+ private $__clientMolecule: any
60
+ private $__payload: any = null
61
+
62
+ /**
63
+ * Class constructor
64
+ */
65
+ constructor({
66
+ query,
67
+ json
68
+ }: {
69
+ query: Query
70
+ json: Record<string, unknown>
71
+ }) {
72
+ super({
73
+ query,
74
+ json,
75
+ dataKey: 'data.ProposeMolecule'
76
+ })
77
+ this.$__clientMolecule = (query as any).molecule()
78
+ this.init()
79
+ }
80
+
81
+ /**
82
+ * Initialize response object with payload data
83
+ * Matches JavaScript SDK init method exactly
84
+ */
85
+ init(): void {
86
+ const payloadJson = Dot.get(this.data(), 'payload')
87
+ try {
88
+ this.$__payload = Object.prototype.toString.call(payloadJson) === '[object String]'
89
+ ? JSON.parse(payloadJson as string)
90
+ : payloadJson
91
+ } catch (err) {
92
+ this.$__payload = null
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Returns the client molecule
98
+ * Matches JavaScript SDK clientMolecule method exactly
99
+ */
100
+ clientMolecule(): any {
101
+ return this.$__clientMolecule
102
+ }
103
+
104
+ /**
105
+ * Returns the resulting molecule
106
+ * Matches JavaScript SDK molecule method exactly
107
+ */
108
+ molecule(): Molecule | null {
109
+ const data = this.data()
110
+
111
+ if (!data) {
112
+ return null
113
+ }
114
+
115
+ const molecule = new Molecule({})
116
+
117
+ molecule.molecularHash = Dot.get(data, 'molecularHash')
118
+ molecule.status = Dot.get(data, 'status')
119
+ molecule.createdAt = Dot.get(data, 'createdAt')
120
+
121
+ return molecule
122
+ }
123
+
124
+ /**
125
+ * Returns whether molecule was accepted or not
126
+ * Matches JavaScript SDK success method exactly
127
+ */
128
+ success(): boolean {
129
+ return this.status() === 'accepted'
130
+ }
131
+
132
+ /**
133
+ * Returns the status of the proposal
134
+ * Matches JavaScript SDK status method exactly
135
+ */
136
+ status(): string {
137
+ return Dot.get(this.data(), 'status', 'rejected') as string
138
+ }
139
+
140
+ /**
141
+ * Returns the reason for rejection
142
+ * Matches JavaScript SDK reason method exactly
143
+ */
144
+ reason(): string {
145
+ return Dot.get(this.data(), 'reason', 'Invalid response from server') as string
146
+ }
147
+
148
+ /**
149
+ * Returns payload object
150
+ * Matches JavaScript SDK payload method exactly
151
+ */
152
+ payload(): any {
153
+ return this.$__payload
154
+ }
155
+ }
@@ -0,0 +1,105 @@
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 Response from './Response'
50
+ import type Query from '@/query/Query'
51
+
52
+ /**
53
+ * Response for QueryActiveSession
54
+ */
55
+ export default class ResponseQueryActiveSession extends Response {
56
+ /**
57
+ * Constructor
58
+ */
59
+ constructor({
60
+ query,
61
+ json
62
+ }: {
63
+ query: Query
64
+ json: Record<string, any>
65
+ }) {
66
+ super({
67
+ query,
68
+ json,
69
+ dataKey: 'data.ActiveUser'
70
+ })
71
+ }
72
+
73
+ /**
74
+ * Returns processed active session data
75
+ */
76
+ payload(): any {
77
+ const list = this.data()
78
+
79
+ if (!list) {
80
+ return null
81
+ }
82
+
83
+ const activeUsers: any[] = []
84
+
85
+ for (const item of list) {
86
+ const activeSession = { ...item }
87
+
88
+ if (activeSession.jsonData) {
89
+ activeSession.jsonData = JSON.parse(activeSession.jsonData)
90
+ }
91
+
92
+ if (activeSession.createdAt) {
93
+ activeSession.createdAt = new Date(activeSession.createdAt)
94
+ }
95
+
96
+ if (activeSession.updatedAt) {
97
+ activeSession.updatedAt = new Date(activeSession.updatedAt)
98
+ }
99
+
100
+ activeUsers.push(activeSession)
101
+ }
102
+
103
+ return activeUsers
104
+ }
105
+ }
@@ -0,0 +1,89 @@
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 Response from './Response'
50
+ import type Query from '@/query/Query'
51
+
52
+ /**
53
+ * Response for QueryUserActivity
54
+ */
55
+ export default class ResponseQueryUserActivity extends Response {
56
+ /**
57
+ * Constructor
58
+ */
59
+ constructor({
60
+ query,
61
+ json
62
+ }: {
63
+ query: Query
64
+ json: Record<string, any>
65
+ }) {
66
+ super({
67
+ query,
68
+ json,
69
+ dataKey: 'data.UserActivity'
70
+ })
71
+ }
72
+
73
+ /**
74
+ * Returns processed user activity data
75
+ */
76
+ payload(): any {
77
+ const data = JSON.parse(JSON.stringify(this.data()))
78
+
79
+ if (data.instances) {
80
+ for (const datum of data.instances) {
81
+ if (datum.jsonData) {
82
+ datum.jsonData = JSON.parse(datum.jsonData)
83
+ }
84
+ }
85
+ }
86
+
87
+ return data
88
+ }
89
+ }
@@ -0,0 +1,100 @@
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 Dot from '../libraries/Dot'
50
+ import { InvalidResponseException } from '../exception'
51
+ import ResponseProposeMolecule from './ResponseProposeMolecule'
52
+
53
+ /**
54
+ * ResponseRequestAuthorization class - Response for auth token mutation
55
+ * Matches JavaScript SDK ResponseRequestAuthorization implementation exactly
56
+ */
57
+ export default class ResponseRequestAuthorization extends ResponseProposeMolecule {
58
+ /**
59
+ * Return the authorization key
60
+ * Matches JavaScript SDK payloadKey method exactly
61
+ */
62
+ payloadKey(key: string): any {
63
+ if (!Dot.has(this.payload(), key)) {
64
+ throw new InvalidResponseException(`ResponseRequestAuthorization::payloadKey() - '${key}' key was not found in the payload!`)
65
+ }
66
+ return Dot.get(this.payload(), key)
67
+ }
68
+
69
+ /**
70
+ * Returns the auth token
71
+ * Matches JavaScript SDK token method exactly
72
+ */
73
+ token(): string {
74
+ return this.payloadKey('token')
75
+ }
76
+
77
+ /**
78
+ * Returns timestamp
79
+ * Matches JavaScript SDK time method exactly
80
+ */
81
+ time(): string {
82
+ return this.payloadKey('time')
83
+ }
84
+
85
+ /**
86
+ * Returns encryption info
87
+ * Matches JavaScript SDK encrypt method exactly
88
+ */
89
+ encrypt(): string {
90
+ return this.payloadKey('encrypt')
91
+ }
92
+
93
+ /**
94
+ * Returns public key
95
+ * Matches JavaScript SDK pubKey method exactly
96
+ */
97
+ pubKey(): string {
98
+ return this.payloadKey('key')
99
+ }
100
+ }
@@ -0,0 +1,133 @@
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 Response from './Response'
50
+ import Dot from '@/libraries/Dot'
51
+ import { InvalidResponseException } from '@/exception'
52
+ import type MutationRequestAuthorizationGuest from '@/mutation/MutationRequestAuthorizationGuest'
53
+
54
+ /**
55
+ * Response for guest auth mutation
56
+ */
57
+ export default class ResponseRequestAuthorizationGuest extends Response {
58
+ /**
59
+ * Constructor
60
+ */
61
+ constructor({
62
+ query,
63
+ json
64
+ }: {
65
+ query: MutationRequestAuthorizationGuest
66
+ json: Record<string, any>
67
+ }) {
68
+ super({
69
+ query,
70
+ json,
71
+ dataKey: 'data.AccessToken'
72
+ })
73
+ }
74
+
75
+ /**
76
+ * Returns the reason for rejection
77
+ */
78
+ reason(): string {
79
+ return 'Invalid response from server'
80
+ }
81
+
82
+ /**
83
+ * Returns whether authorization was successful
84
+ */
85
+ success(): boolean {
86
+ return this.payload() !== null
87
+ }
88
+
89
+ /**
90
+ * Returns authorization data
91
+ */
92
+ payload(): any {
93
+ return this.data()
94
+ }
95
+
96
+ /**
97
+ * Returns the authorization key
98
+ */
99
+ payloadKey(key: string): any {
100
+ if (!Dot.has(this.payload(), key)) {
101
+ throw new InvalidResponseException(`ResponseRequestAuthorizationGuest::payloadKey() - '${key}' key is not found in the payload!`)
102
+ }
103
+ return Dot.get(this.payload(), key)
104
+ }
105
+
106
+ /**
107
+ * Returns the auth token
108
+ */
109
+ token(): any {
110
+ return this.payloadKey('token')
111
+ }
112
+
113
+ /**
114
+ * Returns timestamp
115
+ */
116
+ time(): any {
117
+ return this.payloadKey('time')
118
+ }
119
+
120
+ /**
121
+ * Returns public key
122
+ */
123
+ pubKey(): string {
124
+ return this.payloadKey('key')
125
+ }
126
+
127
+ /**
128
+ * Returns encrypt flag
129
+ */
130
+ encrypt(): any {
131
+ return this.payloadKey('encrypt')
132
+ }
133
+ }