hivesigner 3.3.5 → 4.0.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/README.md +13 -0
- package/lib/client.d.ts +1 -2
- package/lib/hivesigner.min.js +1 -10
- package/lib/index.js +135 -224
- package/lib/methods/send-operation.method.d.ts +1 -2
- package/lib/methods/send-operations.method.d.ts +1 -2
- package/lib/methods/send-transaction.method.d.ts +1 -2
- package/lib/types/callback-function.type.d.ts +1 -1
- package/lib/types/hive.types.d.ts +13 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/send-response.type.d.ts +1 -1
- package/package.json +8 -18
- package/rollup.config.js +4 -3
- package/src/client.spec.ts +28 -30
- package/src/client.ts +8 -7
- package/src/methods/send-operation.method.spec.ts +1 -1
- package/src/methods/send-operation.method.ts +1 -2
- package/src/methods/send-operations.method.spec.ts +1 -1
- package/src/methods/send-operations.method.ts +1 -2
- package/src/methods/send-transaction.method.spec.ts +1 -1
- package/src/methods/send-transaction.method.ts +1 -2
- package/src/require-import.spec.js +6 -1
- package/src/types/hive.types.ts +12 -0
- package/src/types/index.ts +1 -0
- package/tsconfig.json +3 -1
- package/webpack.config.js +8 -1
- package/.babelrc +0 -8
package/src/client.spec.ts
CHANGED
|
@@ -2,16 +2,14 @@ import { Client } from './client'
|
|
|
2
2
|
import { ClientConfig } from './types'
|
|
3
3
|
import { API_URL, BASE_URL } from './consts'
|
|
4
4
|
import * as utilities from './utilities'
|
|
5
|
-
import * as crossFetch from 'cross-fetch'
|
|
6
5
|
|
|
7
6
|
jest.mock('./utilities')
|
|
8
|
-
jest.mock('cross-fetch')
|
|
9
7
|
|
|
10
8
|
describe('Client', function () {
|
|
11
9
|
let instance: Client
|
|
12
10
|
let isBrowserMock: jest.Mock
|
|
13
|
-
let
|
|
14
|
-
let
|
|
11
|
+
let fetchMock: jest.Mock
|
|
12
|
+
let fetchResponseMock: { status: string | number, json: () => {} }
|
|
15
13
|
|
|
16
14
|
beforeEach(() => {
|
|
17
15
|
instance = new Client({
|
|
@@ -26,12 +24,12 @@ describe('Client', function () {
|
|
|
26
24
|
isBrowserMock = utilities.isBrowser as jest.Mock
|
|
27
25
|
isBrowserMock.mockReturnValue(false)
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
fetchResponseMock = {
|
|
30
28
|
status: 200,
|
|
31
29
|
json: async () => ({ error: '' })
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
fetchMock = jest.fn().mockImplementation(async (...args: any[]) => fetchResponseMock)
|
|
32
|
+
global.fetch = fetchMock
|
|
35
33
|
})
|
|
36
34
|
|
|
37
35
|
it('should create instance', function () {
|
|
@@ -101,7 +99,7 @@ describe('Client', function () {
|
|
|
101
99
|
|
|
102
100
|
it('should return promise resolve on send call', async function () {
|
|
103
101
|
const response = await instance.send('me', 'POST', {})
|
|
104
|
-
expect(
|
|
102
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/me`,{
|
|
105
103
|
method: 'POST',
|
|
106
104
|
headers: {
|
|
107
105
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -110,11 +108,11 @@ describe('Client', function () {
|
|
|
110
108
|
},
|
|
111
109
|
body: JSON.stringify({})
|
|
112
110
|
})
|
|
113
|
-
expect(response).toStrictEqual(await
|
|
111
|
+
expect(response).toStrictEqual(await fetchResponseMock.json())
|
|
114
112
|
})
|
|
115
113
|
|
|
116
114
|
it('should return promise error on send call with if 200 status', async function () {
|
|
117
|
-
|
|
115
|
+
fetchResponseMock = {
|
|
118
116
|
status: 'not_200_OK',
|
|
119
117
|
json: async () => ({ error: '' })
|
|
120
118
|
}
|
|
@@ -124,12 +122,12 @@ describe('Client', function () {
|
|
|
124
122
|
console.error('Client.send not threw error')
|
|
125
123
|
expect(true).toBe(false)
|
|
126
124
|
} catch (failureResponse) {
|
|
127
|
-
expect(failureResponse).toStrictEqual(await
|
|
125
|
+
expect(failureResponse).toStrictEqual(await fetchResponseMock.json())
|
|
128
126
|
}
|
|
129
127
|
})
|
|
130
128
|
|
|
131
129
|
it('should return promise error on send call if has json error', async function () {
|
|
132
|
-
|
|
130
|
+
fetchResponseMock = {
|
|
133
131
|
status: 200,
|
|
134
132
|
json: async () => ({ error: 'I have an error' })
|
|
135
133
|
}
|
|
@@ -140,7 +138,7 @@ describe('Client', function () {
|
|
|
140
138
|
expect(true).toBe(false)
|
|
141
139
|
} catch (failureResponse) {
|
|
142
140
|
expect(failureResponse).toBeTruthy()
|
|
143
|
-
expect(failureResponse).toStrictEqual(await
|
|
141
|
+
expect(failureResponse).toStrictEqual(await fetchResponseMock.json())
|
|
144
142
|
}
|
|
145
143
|
})
|
|
146
144
|
|
|
@@ -149,14 +147,14 @@ describe('Client', function () {
|
|
|
149
147
|
const response = await instance.send('me', 'POST', {}, callback)
|
|
150
148
|
|
|
151
149
|
expect(callback).toHaveBeenCalled()
|
|
152
|
-
expect(callback).toHaveBeenCalledWith(null, await
|
|
150
|
+
expect(callback).toHaveBeenCalledWith(null, await fetchResponseMock.json())
|
|
153
151
|
expect(callback).lastReturnedWith('results')
|
|
154
152
|
expect(response).toBe('results')
|
|
155
153
|
})
|
|
156
154
|
|
|
157
155
|
it('should return promise with failure results on send call with callback', async function () {
|
|
158
156
|
const callback = jest.fn().mockReturnValue('results')
|
|
159
|
-
|
|
157
|
+
fetchResponseMock = {
|
|
160
158
|
status: 'not_200_OK',
|
|
161
159
|
json: async () => ({ error: '' })
|
|
162
160
|
}
|
|
@@ -164,14 +162,14 @@ describe('Client', function () {
|
|
|
164
162
|
|
|
165
163
|
|
|
166
164
|
expect(callback).toHaveBeenCalled()
|
|
167
|
-
expect(callback).toHaveBeenCalledWith(await
|
|
165
|
+
expect(callback).toHaveBeenCalledWith(await fetchResponseMock.json(), null)
|
|
168
166
|
expect(callback).lastReturnedWith('results')
|
|
169
167
|
expect(response).toBe('results')
|
|
170
168
|
})
|
|
171
169
|
|
|
172
170
|
it('should return promise on broadcast call', async function () {
|
|
173
171
|
const response = await instance.broadcast([])
|
|
174
|
-
expect(
|
|
172
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
175
173
|
method: 'POST',
|
|
176
174
|
headers: {
|
|
177
175
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -185,7 +183,7 @@ describe('Client', function () {
|
|
|
185
183
|
|
|
186
184
|
it('should return promise on updateUserMetadata call', async function () {
|
|
187
185
|
const response = await instance.updateUserMetadata({ username: '' })
|
|
188
|
-
expect(
|
|
186
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/me`,{
|
|
189
187
|
method: 'PUT',
|
|
190
188
|
headers: {
|
|
191
189
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -199,7 +197,7 @@ describe('Client', function () {
|
|
|
199
197
|
|
|
200
198
|
it('should send request and return client instance on revokeToken call', async function () {
|
|
201
199
|
const response = await instance.revokeToken()
|
|
202
|
-
expect(
|
|
200
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/oauth2/token/revoke`,{
|
|
203
201
|
method: 'POST',
|
|
204
202
|
headers: {
|
|
205
203
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -213,7 +211,7 @@ describe('Client', function () {
|
|
|
213
211
|
|
|
214
212
|
it('should send request and return promise on claimRewardBalance call', async function () {
|
|
215
213
|
const response = await instance.claimRewardBalance('', '', '', '')
|
|
216
|
-
expect(
|
|
214
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
217
215
|
method: 'POST',
|
|
218
216
|
headers: {
|
|
219
217
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -234,7 +232,7 @@ describe('Client', function () {
|
|
|
234
232
|
|
|
235
233
|
it('should send request and return promise on custom json call', async function () {
|
|
236
234
|
const response = await instance.customJson('', '', '', {})
|
|
237
|
-
expect(
|
|
235
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
238
236
|
method: 'POST',
|
|
239
237
|
headers: {
|
|
240
238
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -255,7 +253,7 @@ describe('Client', function () {
|
|
|
255
253
|
|
|
256
254
|
it('should send request and return promise on ignore call', async function () {
|
|
257
255
|
const response = await instance.ignore('', '')
|
|
258
|
-
expect(
|
|
256
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
259
257
|
method: 'POST',
|
|
260
258
|
headers: {
|
|
261
259
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -280,7 +278,7 @@ describe('Client', function () {
|
|
|
280
278
|
|
|
281
279
|
it('should send request and return promise on unfollow call', async function () {
|
|
282
280
|
const response = await instance.unfollow('', '')
|
|
283
|
-
expect(
|
|
281
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
284
282
|
method: 'POST',
|
|
285
283
|
headers: {
|
|
286
284
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -305,7 +303,7 @@ describe('Client', function () {
|
|
|
305
303
|
|
|
306
304
|
it('should send request and return promise on follow call', async function () {
|
|
307
305
|
const response = await instance.follow('', '')
|
|
308
|
-
expect(
|
|
306
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
309
307
|
method: 'POST',
|
|
310
308
|
headers: {
|
|
311
309
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -330,7 +328,7 @@ describe('Client', function () {
|
|
|
330
328
|
|
|
331
329
|
it('should send request and return promise on reblog call', async function () {
|
|
332
330
|
const response = await instance.reblog('', '', '')
|
|
333
|
-
expect(
|
|
331
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
334
332
|
method: 'POST',
|
|
335
333
|
headers: {
|
|
336
334
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -355,7 +353,7 @@ describe('Client', function () {
|
|
|
355
353
|
|
|
356
354
|
it('should send request and return promise on deleteComment call', async function () {
|
|
357
355
|
const response = await instance.deleteComment('', '')
|
|
358
|
-
expect(
|
|
356
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
359
357
|
method: 'POST',
|
|
360
358
|
headers: {
|
|
361
359
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -374,7 +372,7 @@ describe('Client', function () {
|
|
|
374
372
|
|
|
375
373
|
it('should send request and return promise on comment call', async function () {
|
|
376
374
|
let response = await instance.comment('', '', '', '', '', {}, {})
|
|
377
|
-
expect(
|
|
375
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
378
376
|
method: 'POST',
|
|
379
377
|
headers: {
|
|
380
378
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -396,7 +394,7 @@ describe('Client', function () {
|
|
|
396
394
|
expect(response).toBeTruthy()
|
|
397
395
|
|
|
398
396
|
response = await instance.comment('', '', '', '', '', {}, 'meta')
|
|
399
|
-
expect(
|
|
397
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
400
398
|
method: 'POST',
|
|
401
399
|
headers: {
|
|
402
400
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -420,7 +418,7 @@ describe('Client', function () {
|
|
|
420
418
|
|
|
421
419
|
it('should send request and return promise on vote call', async function () {
|
|
422
420
|
const response = await instance.vote('', '', '', 0)
|
|
423
|
-
expect(
|
|
421
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/broadcast`,{
|
|
424
422
|
method: 'POST',
|
|
425
423
|
headers: {
|
|
426
424
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -441,7 +439,7 @@ describe('Client', function () {
|
|
|
441
439
|
|
|
442
440
|
it('should send request and return promise on me call', async function () {
|
|
443
441
|
const response = await instance.me()
|
|
444
|
-
expect(
|
|
442
|
+
expect(global.fetch).toHaveBeenCalledWith(`${instance.apiURL}/api/me`,{
|
|
445
443
|
method: 'POST',
|
|
446
444
|
headers: {
|
|
447
445
|
Accept: 'application/json, text/plain, */*',
|
package/src/client.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CallbackFunction, ClientConfig, LoginOptions, SendResponse } from './types'
|
|
1
|
+
import { CallbackFunction, ClientConfig, LoginOptions, Operation, SendResponse } from './types'
|
|
3
2
|
import { API_URL, BASE_URL } from './consts'
|
|
4
3
|
import { isBrowser } from './utilities'
|
|
5
|
-
import { Operation } from '@hiveio/dhive'
|
|
6
|
-
|
|
7
|
-
// Bind fetch to avoid "Illegal invocation" errors in browsers
|
|
8
|
-
const fetch = crossFetch.bind(typeof globalThis !== 'undefined' ? globalThis : undefined)
|
|
9
4
|
|
|
10
5
|
export class Client {
|
|
11
6
|
public apiURL: string
|
|
@@ -296,7 +291,13 @@ export class Client {
|
|
|
296
291
|
}
|
|
297
292
|
|
|
298
293
|
private async makeRequest(url: string, method: string, body: any): Promise<SendResponse> {
|
|
299
|
-
|
|
294
|
+
if (typeof globalThis.fetch !== 'function') {
|
|
295
|
+
throw new Error(
|
|
296
|
+
'hivesigner: fetch is not available. Node.js 18+ or a modern browser is required. ' +
|
|
297
|
+
'If you are in an older environment, provide a global fetch polyfill.'
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
const response = await globalThis.fetch(url, {
|
|
300
301
|
method,
|
|
301
302
|
headers: {
|
|
302
303
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BETA_URL } from '../consts'
|
|
2
2
|
import { encodeOp, Parameters } from 'hive-uri'
|
|
3
3
|
import { isBrowser } from '../utilities'
|
|
4
|
-
import { CallbackFunction } from '../types'
|
|
5
|
-
import { Operation } from '@hiveio/dhive'
|
|
4
|
+
import { CallbackFunction, Operation } from '../types'
|
|
6
5
|
|
|
7
6
|
export function sendOperation(op: Operation, params: Parameters, cb: CallbackFunction): string | void {
|
|
8
7
|
const uri = encodeOp(op, params)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { encodeOps, Parameters } from 'hive-uri'
|
|
2
2
|
import { isBrowser } from '../utilities'
|
|
3
3
|
import { BETA_URL } from '../consts'
|
|
4
|
-
import { CallbackFunction } from '../types'
|
|
5
|
-
import { Operation } from '@hiveio/dhive'
|
|
4
|
+
import { CallbackFunction, Operation } from '../types'
|
|
6
5
|
|
|
7
6
|
export function sendOperations(ops: Operation[], params: Parameters, cb: CallbackFunction): string | void {
|
|
8
7
|
const uri = encodeOps(ops, params)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sendTransaction } from './send-transaction.method'
|
|
2
|
-
import { Transaction } from '
|
|
2
|
+
import { Transaction } from '../types'
|
|
3
3
|
import * as hive from 'hive-uri'
|
|
4
4
|
import * as utilities from '../utilities'
|
|
5
5
|
import { CallbackFunction } from '../types'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { encodeTx, Parameters } from 'hive-uri'
|
|
2
2
|
import { BETA_URL } from '../consts'
|
|
3
3
|
import { isBrowser } from '../utilities'
|
|
4
|
-
import { CallbackFunction } from '../types'
|
|
5
|
-
import { Transaction } from '@hiveio/dhive'
|
|
4
|
+
import { CallbackFunction, Transaction } from '../types'
|
|
6
5
|
|
|
7
6
|
export function sendTransaction(tx: Transaction, params: Parameters, cb: CallbackFunction): string | void {
|
|
8
7
|
const uri = encodeTx(tx, params)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
const hs = require('../lib/index');
|
|
2
2
|
|
|
3
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
4
|
+
status: 200,
|
|
5
|
+
json: async () => ({ error: '' })
|
|
6
|
+
});
|
|
7
|
+
|
|
3
8
|
describe('Require import testing', function () {
|
|
4
9
|
it('should be instance of Client and call me', function () {
|
|
5
10
|
const client = new hs.Client({ accessToken: 'some_wrong_access_token' });
|
|
@@ -8,4 +13,4 @@ describe('Require import testing', function () {
|
|
|
8
13
|
const me = client.me();
|
|
9
14
|
expect(me).toBeInstanceOf(Promise);
|
|
10
15
|
});
|
|
11
|
-
});
|
|
16
|
+
});
|
package/src/types/index.ts
CHANGED
package/tsconfig.json
CHANGED
package/webpack.config.js
CHANGED