hivesigner 3.3.5 → 4.1.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 (58) hide show
  1. package/README.md +29 -2
  2. package/lib/client.d.ts +19 -3
  3. package/lib/hivesigner.min.js +1 -10
  4. package/lib/index.d.ts +4 -0
  5. package/lib/index.js +194 -225
  6. package/lib/methods/send-operation.method.d.ts +1 -2
  7. package/lib/methods/send-operations.method.d.ts +1 -2
  8. package/lib/methods/send-transaction.method.d.ts +1 -2
  9. package/lib/pkce.d.ts +16 -0
  10. package/lib/types/callback-function.type.d.ts +1 -1
  11. package/lib/types/hive.types.d.ts +13 -0
  12. package/lib/types/index.d.ts +2 -0
  13. package/lib/types/login-options.interface.d.ts +2 -0
  14. package/lib/types/send-response.type.d.ts +1 -1
  15. package/lib/types/token-response.interface.d.ts +8 -0
  16. package/package.json +11 -18
  17. package/.babelrc +0 -8
  18. package/.claude/settings.local.json +0 -12
  19. package/.eslintignore +0 -3
  20. package/.eslintrc.js +0 -16
  21. package/CLAUDE.md +0 -142
  22. package/docs/CNAME +0 -1
  23. package/docs/index.html +0 -221
  24. package/jest.config.js +0 -10
  25. package/rollup.config.js +0 -12
  26. package/src/client.spec.ts +0 -455
  27. package/src/client.ts +0 -317
  28. package/src/consts/api-url.const.ts +0 -1
  29. package/src/consts/base-url.const.ts +0 -1
  30. package/src/consts/beta-url.const.ts +0 -1
  31. package/src/consts/index.ts +0 -3
  32. package/src/default-import.spec.ts +0 -10
  33. package/src/factories/index.ts +0 -1
  34. package/src/factories/initialize.factory.spec.ts +0 -9
  35. package/src/factories/initialize.factory.ts +0 -7
  36. package/src/index.ts +0 -16
  37. package/src/methods/index.ts +0 -4
  38. package/src/methods/send-operation.method.spec.ts +0 -47
  39. package/src/methods/send-operation.method.ts +0 -15
  40. package/src/methods/send-operations.method.spec.ts +0 -47
  41. package/src/methods/send-operations.method.ts +0 -15
  42. package/src/methods/send-transaction.method.spec.ts +0 -47
  43. package/src/methods/send-transaction.method.ts +0 -15
  44. package/src/methods/sign.method.spec.ts +0 -60
  45. package/src/methods/sign.method.ts +0 -22
  46. package/src/modules-import.spec.ts +0 -11
  47. package/src/require-import.spec.js +0 -11
  48. package/src/require-import.spec.ts +0 -10
  49. package/src/types/callback-function.type.ts +0 -1
  50. package/src/types/client-config.interface.ts +0 -8
  51. package/src/types/index.ts +0 -5
  52. package/src/types/login-options.interface.ts +0 -3
  53. package/src/types/send-response.type.ts +0 -1
  54. package/src/types/sign-errors.interface.ts +0 -4
  55. package/src/utilities/index.ts +0 -1
  56. package/src/utilities/is-browser.util.ts +0 -3
  57. package/tsconfig.json +0 -15
  58. package/webpack.config.js +0 -26
package/src/client.ts DELETED
@@ -1,317 +0,0 @@
1
- import crossFetch from 'cross-fetch'
2
- import { CallbackFunction, ClientConfig, LoginOptions, SendResponse } from './types'
3
- import { API_URL, BASE_URL } from './consts'
4
- 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
-
10
- export class Client {
11
- public apiURL: string
12
- public app: string
13
- public callbackURL: string
14
- public scope: string[]
15
- public responseType: string
16
- public accessToken?: string
17
-
18
- constructor(config: ClientConfig) {
19
- this.apiURL = config.apiURL || API_URL
20
- this.app = config.app
21
- this.callbackURL = config.callbackURL
22
- this.accessToken = config.accessToken
23
- this.scope = config.scope
24
- this.responseType = config.responseType
25
- }
26
-
27
- public setBaseURL(): this {
28
- console.warn(
29
- 'The function "setBaseUrl" is deprecated, the base URL is always "https://hivesigner.com", you can only change the API URL with "setApiURL"'
30
- )
31
- return this
32
- }
33
-
34
- public setApiURL(url: string): this {
35
- this.apiURL = url
36
- return this
37
- }
38
-
39
- public setApp(app: string): this {
40
- this.app = app
41
- return this
42
- }
43
-
44
- public setCallbackURL(url: string): this {
45
- this.callbackURL = url
46
- return this
47
- }
48
-
49
- public setAccessToken(accessToken: string): this {
50
- this.accessToken = accessToken
51
- return this
52
- }
53
-
54
- public removeAccessToken(): this {
55
- delete this.accessToken
56
- return this
57
- }
58
-
59
- public setScope(scope: string[]): this {
60
- this.scope = scope
61
- return this
62
- }
63
-
64
- public getLoginURL(state: string, account?: string): string {
65
- const redirectUri = encodeURIComponent(this.callbackURL)
66
- let loginURL = `${BASE_URL}/oauth2/authorize?client_id=${this.app}&redirect_uri=${redirectUri}`
67
- if (this.responseType === 'code') {
68
- loginURL += `&response_type=${this.responseType}`
69
- }
70
- if (this.scope) {
71
- loginURL += `&scope=${this.scope.join(',')}`
72
- }
73
- if (state) {
74
- loginURL += `&state=${encodeURIComponent(state)}`
75
- }
76
- if (account) {
77
- loginURL += `&account=${encodeURIComponent(account)}`
78
- }
79
- return loginURL
80
- }
81
-
82
- public login(options: LoginOptions): void {
83
- if (isBrowser()) {
84
- // @ts-ignore
85
- window.location = this.getLoginURL(options.state)
86
- }
87
- }
88
-
89
- public me(): Promise<SendResponse>
90
- public me(cb: CallbackFunction): Promise<SendResponse>
91
- public me(cb?: CallbackFunction): Promise<SendResponse> {
92
- return this.send('me', 'POST', {}, cb)
93
- }
94
-
95
- public decode(memo: string): Promise<SendResponse>
96
- public decode(memo: string, cb: CallbackFunction): Promise<SendResponse>
97
- public decode(memo: string, cb?: CallbackFunction): Promise<SendResponse> {
98
- return this.send('decode', 'POST', {memo: memo}, cb)
99
- }
100
-
101
- public vote(voter: string, author: string, permlink: string, weight: string | number): Promise<SendResponse>
102
- public vote(
103
- voter: string,
104
- author: string,
105
- permlink: string,
106
- weight: string | number,
107
- cb: CallbackFunction
108
- ): Promise<SendResponse>
109
- public vote(
110
- voter: string,
111
- author: string,
112
- permlink: string,
113
- weight: string | number,
114
- cb?: CallbackFunction
115
- ): Promise<SendResponse> {
116
- const params = {
117
- voter,
118
- author,
119
- permlink,
120
- weight
121
- }
122
- return this.broadcast([['vote', params]], cb)
123
- }
124
-
125
- public comment(
126
- parentAuthor: string,
127
- parentPermlink: string,
128
- author: string,
129
- permlink: string,
130
- title: string,
131
- body: any,
132
- jsonMetadata: any
133
- ): Promise<SendResponse>
134
- public comment(
135
- parentAuthor: string,
136
- parentPermlink: string,
137
- author: string,
138
- permlink: string,
139
- title: string,
140
- body: any,
141
- jsonMetadata: any,
142
- cb: CallbackFunction
143
- ): Promise<SendResponse>
144
- public comment(
145
- parentAuthor: string,
146
- parentPermlink: string,
147
- author: string,
148
- permlink: string,
149
- title: string,
150
- body: any,
151
- jsonMetadata: any,
152
- cb?: CallbackFunction
153
- ): Promise<SendResponse> {
154
- let json = jsonMetadata
155
- if (typeof jsonMetadata !== 'string') {
156
- json = JSON.stringify(jsonMetadata)
157
- }
158
- const params = {
159
- parent_author: parentAuthor,
160
- parent_permlink: parentPermlink,
161
- author,
162
- permlink,
163
- title,
164
- body,
165
- json_metadata: json
166
- }
167
- return this.broadcast([['comment', params]], cb)
168
- }
169
-
170
- public deleteComment(author: string, permlink: string): Promise<SendResponse>
171
- public deleteComment(author: string, permlink: string, cb: CallbackFunction): Promise<SendResponse>
172
- public deleteComment(author: string, permlink: string, cb?: CallbackFunction): Promise<SendResponse> {
173
- const params = {
174
- author,
175
- permlink
176
- }
177
- return this.broadcast([['delete_comment', params]], cb)
178
- }
179
-
180
- public customJson(requiredAuths: any, requiredPostingAuths: any, id: string, json: any): Promise<SendResponse>
181
- public customJson(
182
- requiredAuths: any,
183
- requiredPostingAuths: any,
184
- id: string,
185
- json: any,
186
- cb: CallbackFunction
187
- ): Promise<SendResponse>
188
- public customJson(
189
- requiredAuths: any,
190
- requiredPostingAuths: any,
191
- id: string,
192
- json: any,
193
- cb?: CallbackFunction
194
- ): Promise<SendResponse> {
195
- const params = {
196
- required_auths: requiredAuths,
197
- required_posting_auths: requiredPostingAuths,
198
- id,
199
- json
200
- }
201
- return this.broadcast([['custom_json', params]], cb)
202
- }
203
-
204
- public reblog(account: string, author: string, permlink: string): Promise<SendResponse>
205
- public reblog(account: string, author: string, permlink: string, cb: CallbackFunction): Promise<SendResponse>
206
- public reblog(account: string, author: string, permlink: string, cb?: CallbackFunction): Promise<SendResponse> {
207
- const json = ['reblog', { account, author, permlink }]
208
- return this.customJson([], [account], 'follow', JSON.stringify(json), cb)
209
- }
210
-
211
- public follow(follower: string, following: string): Promise<SendResponse>
212
- public follow(follower: string, following: string, cb: CallbackFunction): Promise<SendResponse>
213
- public follow(follower: string, following: string, cb?: CallbackFunction): Promise<SendResponse> {
214
- const json = ['follow', { follower, following, what: ['blog'] }]
215
- return this.customJson([], [follower], 'follow', JSON.stringify(json), cb)
216
- }
217
-
218
- public unfollow(unfollower: string, unfollowing: string): Promise<SendResponse>
219
- public unfollow(unfollower: string, unfollowing: string, cb: CallbackFunction): Promise<SendResponse>
220
- public unfollow(unfollower: string, unfollowing: string, cb?: CallbackFunction): Promise<SendResponse> {
221
- const json = ['follow', { follower: unfollower, following: unfollowing, what: <string[]>[] }]
222
- return this.customJson([], [unfollower], 'follow', JSON.stringify(json), cb)
223
- }
224
-
225
- public ignore(follower: string, following: string): Promise<SendResponse>
226
- public ignore(follower: string, following: string, cb: CallbackFunction): Promise<SendResponse>
227
- public ignore(follower: string, following: string, cb?: CallbackFunction): Promise<SendResponse> {
228
- const json = ['follow', { follower, following, what: ['ignore'] }]
229
- return this.customJson([], [follower], 'follow', JSON.stringify(json), cb)
230
- }
231
-
232
- public claimRewardBalance(
233
- account: string,
234
- rewardHive: string,
235
- rewardHbd: string,
236
- rewardVests: string,
237
- ): Promise<SendResponse>
238
- public claimRewardBalance(
239
- account: string,
240
- rewardHive: string,
241
- rewardHbd: string,
242
- rewardVests: string,
243
- cb: CallbackFunction
244
- ): Promise<SendResponse>
245
- public claimRewardBalance(
246
- account: string,
247
- rewardHive: string,
248
- rewardHbd: string,
249
- rewardVests: string,
250
- cb?: CallbackFunction
251
- ): Promise<SendResponse> {
252
- const params = {
253
- account,
254
- reward_hive: rewardHive,
255
- reward_hbd: rewardHbd,
256
- reward_vests: rewardVests
257
- }
258
- return this.broadcast([['claim_reward_balance', params]], cb)
259
- }
260
-
261
- public async revokeToken(): Promise<Client>
262
- public async revokeToken(cb: CallbackFunction): Promise<Client>
263
- public async revokeToken(cb?: CallbackFunction): Promise<Client> {
264
- await this.send('oauth2/token/revoke', 'POST', { token: this.accessToken }, cb)
265
- return this.removeAccessToken()
266
- }
267
-
268
- public updateUserMetadata(metadata: any): Promise<SendResponse>
269
- public updateUserMetadata(metadata: any, cb: CallbackFunction): Promise<SendResponse>
270
- public updateUserMetadata(metadata: any = {}, cb?: CallbackFunction): Promise<SendResponse> {
271
- console.warn('The function "updateUserMetadata" is deprecated.')
272
- return this.send('me', 'PUT', { user_metadata: metadata }, cb)
273
- }
274
-
275
- public async send(route: string, method: string, body: any): Promise<SendResponse>
276
- public async send(route: string, method: string, body: any, cb: CallbackFunction): Promise<SendResponse>
277
- public async send(route: string, method: string, body: any, cb?: CallbackFunction): Promise<SendResponse> {
278
- const url = `${this.apiURL}/api/${route}`
279
-
280
- if (!cb) {
281
- return this.makeRequest(url, method, body)
282
- }
283
-
284
- try {
285
- const json = await this.makeRequest(url, method, body)
286
- return cb(null, json)
287
- } catch (failureResponse) {
288
- return cb(failureResponse, null)
289
- }
290
- }
291
-
292
- public broadcast(operations: Operation[]): Promise<SendResponse>
293
- public broadcast(operations: Operation[], cb: CallbackFunction): Promise<SendResponse>
294
- public broadcast(operations: Operation[], cb?: CallbackFunction): Promise<SendResponse> {
295
- return this.send('broadcast', 'POST', { operations }, cb)
296
- }
297
-
298
- private async makeRequest(url: string, method: string, body: any): Promise<SendResponse> {
299
- const response = await fetch(url, {
300
- method,
301
- headers: {
302
- Accept: 'application/json, text/plain, */*',
303
- 'Content-Type': 'application/json',
304
- Authorization: this.accessToken,
305
- },
306
- body: JSON.stringify(body),
307
- })
308
-
309
- const json = await response.json()
310
-
311
- if (response.status !== 200 || json.error) {
312
- throw json
313
- }
314
-
315
- return json
316
- }
317
- }
@@ -1 +0,0 @@
1
- export const API_URL = 'https://hivesigner.com'
@@ -1 +0,0 @@
1
- export const BASE_URL = 'https://hivesigner.com'
@@ -1 +0,0 @@
1
- export const BETA_URL = 'https://hivesigner.com'
@@ -1,3 +0,0 @@
1
- export * from './api-url.const'
2
- export * from './base-url.const'
3
- export * from './beta-url.const'
@@ -1,10 +0,0 @@
1
- import hivesigner from '../lib/index'
2
-
3
- describe('Testing default import', function () {
4
- it('should contain Client class', function () {
5
- expect(hivesigner.Client).toBeTruthy()
6
-
7
- const client = new hivesigner.Client({})
8
- expect(client).toBeInstanceOf(hivesigner.Client)
9
- })
10
- })
@@ -1 +0,0 @@
1
- export * from './initialize.factory'
@@ -1,9 +0,0 @@
1
- import { Initialize } from './initialize.factory'
2
- import { ClientConfig } from '../types'
3
- import { Client } from '../client'
4
-
5
- describe('Initialize Client factory', function () {
6
- it('should create client instance', function () {
7
- expect(Initialize({} as ClientConfig)).toBeInstanceOf(Client)
8
- })
9
- })
@@ -1,7 +0,0 @@
1
- import { ClientConfig } from '../types'
2
- import { Client } from '../client'
3
-
4
- export function Initialize(config: ClientConfig): Client {
5
- console.warn('The function "Initialize" is deprecated, please use the class "Client" instead.')
6
- return new Client(config)
7
- }
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- export * from './client'
2
- export * from './methods'
3
- export * from './factories'
4
-
5
- import { Client } from './client'
6
- import { Initialize } from './factories'
7
- import { sendTransaction, sendOperations, sendOperation, sign } from './methods'
8
-
9
- export default {
10
- Client,
11
- Initialize,
12
- sendTransaction,
13
- sendOperations,
14
- sendOperation,
15
- sign
16
- }
@@ -1,4 +0,0 @@
1
- export * from './sign.method'
2
- export * from './send-operation.method'
3
- export * from './send-operations.method'
4
- export * from './send-transaction.method'
@@ -1,47 +0,0 @@
1
- import { Operation } from '@hiveio/dhive'
2
- import * as hive from 'hive-uri'
3
- import * as utilities from '../utilities'
4
- import { CallbackFunction } from '../types'
5
- import { BETA_URL } from '../consts'
6
- import { sendOperation } from './send-operation.method'
7
-
8
- jest.mock('../utilities')
9
- jest.mock('hive-uri')
10
-
11
- describe('Send operation method', function () {
12
- let op: Operation
13
- let params: hive.Parameters
14
- let cb: CallbackFunction
15
- let encodeOpMock: jest.Mock
16
- let isBrowserMock: jest.Mock
17
-
18
- beforeEach(() => {
19
- op = {} as Operation
20
- params = {}
21
- cb = () => {}
22
-
23
- (window as { open: () => void }).open = jest.fn()
24
- encodeOpMock = hive.encodeOp as jest.Mock
25
- encodeOpMock.mockReturnValue('hive://')
26
-
27
- isBrowserMock = utilities.isBrowser as jest.Mock
28
- isBrowserMock.mockReturnValue(false)
29
- })
30
-
31
- it('should call call window open if its browser and has callback', function () {
32
- (window.open as jest.Mock).mockReturnValue({ focus: () => {} })
33
- isBrowserMock.mockReturnValue(true)
34
-
35
- sendOperation(op, params, cb)
36
- expect(window.open).toHaveBeenCalledWith(`${BETA_URL}/`, '_blank')
37
- })
38
-
39
- it('should return url if its not browser', function () {
40
- expect(sendOperation(op, params, cb)).toBe(`${BETA_URL}/`)
41
- })
42
-
43
- it('should return url if there is no callback', function () {
44
- cb = null
45
- expect(sendOperation(op, params, cb)).toBe(`${BETA_URL}/`)
46
- })
47
- })
@@ -1,15 +0,0 @@
1
- import { BETA_URL } from '../consts'
2
- import { encodeOp, Parameters } from 'hive-uri'
3
- import { isBrowser } from '../utilities'
4
- import { CallbackFunction } from '../types'
5
- import { Operation } from '@hiveio/dhive'
6
-
7
- export function sendOperation(op: Operation, params: Parameters, cb: CallbackFunction): string | void {
8
- const uri = encodeOp(op, params)
9
- const webUrl = uri.replace('hive://', `${BETA_URL}/`)
10
- if (cb && isBrowser()) {
11
- const win = window.open(webUrl, '_blank')
12
- return win.focus()
13
- }
14
- return webUrl
15
- }
@@ -1,47 +0,0 @@
1
- import { Operation } from '@hiveio/dhive'
2
- import * as hive from 'hive-uri'
3
- import * as utilities from '../utilities'
4
- import { CallbackFunction } from '../types'
5
- import { BETA_URL } from '../consts'
6
- import { sendOperations } from './send-operations.method'
7
-
8
- jest.mock('../utilities')
9
- jest.mock('hive-uri')
10
-
11
- describe('Send operations method', function () {
12
- let ops: Operation[]
13
- let params: hive.Parameters
14
- let cb: CallbackFunction
15
- let encodeOpsMock: jest.Mock
16
- let isBrowserMock: jest.Mock
17
-
18
- beforeEach(() => {
19
- ops = [] as Operation[]
20
- params = {}
21
- cb = () => {}
22
- (window as { open: () => void }).open = jest.fn()
23
-
24
- encodeOpsMock = hive.encodeOps as jest.Mock
25
- encodeOpsMock.mockReturnValue('hive://')
26
-
27
- isBrowserMock = utilities.isBrowser as jest.Mock
28
- isBrowserMock.mockReturnValue(false)
29
- })
30
-
31
- it('should call call window open if its browser and has callback', function () {
32
- (window.open as jest.Mock).mockReturnValue({ focus: () => {} })
33
- isBrowserMock.mockReturnValue(true)
34
-
35
- sendOperations(ops, params, cb)
36
- expect(window.open).toHaveBeenCalledWith(`${BETA_URL}/`, '_blank')
37
- })
38
-
39
- it('should return url if its not browser', function () {
40
- expect(sendOperations(ops, params, cb)).toBe(`${BETA_URL}/`)
41
- })
42
-
43
- it('should return url if there is no callback', function () {
44
- cb = null
45
- expect(sendOperations(ops, params, cb)).toBe(`${BETA_URL}/`)
46
- })
47
- })
@@ -1,15 +0,0 @@
1
- import { encodeOps, Parameters } from 'hive-uri'
2
- import { isBrowser } from '../utilities'
3
- import { BETA_URL } from '../consts'
4
- import { CallbackFunction } from '../types'
5
- import { Operation } from '@hiveio/dhive'
6
-
7
- export function sendOperations(ops: Operation[], params: Parameters, cb: CallbackFunction): string | void {
8
- const uri = encodeOps(ops, params)
9
- const webUrl = uri.replace('hive://', `${BETA_URL}/`)
10
- if (cb && isBrowser()) {
11
- const win = window.open(webUrl, '_blank')
12
- return win.focus()
13
- }
14
- return webUrl
15
- }
@@ -1,47 +0,0 @@
1
- import { sendTransaction } from './send-transaction.method'
2
- import { Transaction } from '@hiveio/dhive'
3
- import * as hive from 'hive-uri'
4
- import * as utilities from '../utilities'
5
- import { CallbackFunction } from '../types'
6
- import { BETA_URL } from '../consts'
7
-
8
- jest.mock('../utilities')
9
- jest.mock('hive-uri')
10
-
11
- describe('Send transaction method', function () {
12
- let tx: Transaction
13
- let params: hive.Parameters
14
- let cb: CallbackFunction
15
- let encodeTxMock: jest.Mock
16
- let isBrowserMock: jest.Mock
17
-
18
- beforeEach(() => {
19
- tx = {} as Transaction
20
- params = {}
21
- cb = () => {}
22
- (window as { open: () => void }).open = jest.fn()
23
-
24
- encodeTxMock = hive.encodeTx as jest.Mock
25
- encodeTxMock.mockReturnValue('hive://')
26
-
27
- isBrowserMock = utilities.isBrowser as jest.Mock
28
- isBrowserMock.mockReturnValue(false)
29
- })
30
-
31
- it('should call call window open if its browser and has callback', function () {
32
- (window.open as jest.Mock).mockReturnValue({ focus: () => {} })
33
- isBrowserMock.mockReturnValue(true)
34
-
35
- sendTransaction(tx, params, cb)
36
- expect(window.open).toHaveBeenCalledWith(`${BETA_URL}/`, '_blank')
37
- })
38
-
39
- it('should return url if its not browser', function () {
40
- expect(sendTransaction(tx, params, cb)).toBe(`${BETA_URL}/`)
41
- })
42
-
43
- it('should return url if there is no callback', function () {
44
- cb = null
45
- expect(sendTransaction(tx, params, cb)).toBe(`${BETA_URL}/`)
46
- })
47
- })
@@ -1,15 +0,0 @@
1
- import { encodeTx, Parameters } from 'hive-uri'
2
- import { BETA_URL } from '../consts'
3
- import { isBrowser } from '../utilities'
4
- import { CallbackFunction } from '../types'
5
- import { Transaction } from '@hiveio/dhive'
6
-
7
- export function sendTransaction(tx: Transaction, params: Parameters, cb: CallbackFunction): string | void {
8
- const uri = encodeTx(tx, params)
9
- const webUrl = uri.replace('hive://', `${BETA_URL}/`)
10
- if (cb && isBrowser()) {
11
- const win = window.open(webUrl, '_blank')
12
- return win.focus()
13
- }
14
- return webUrl
15
- }
@@ -1,60 +0,0 @@
1
- import { sign } from './sign.method'
2
- import { BASE_URL } from '../consts'
3
-
4
- describe('Sign method', function () {
5
- let name: string
6
- let params: Record<string, string | number | boolean>
7
- let redirectUri: string
8
-
9
- beforeEach(() => {
10
- name = ''
11
- params = {}
12
- redirectUri = ''
13
- })
14
-
15
- it('should return url if given correct parameters', function () {
16
- name = 'name'
17
- params = { one: 'one', two: 'two' }
18
- redirectUri = 'https://example.com'
19
-
20
- expect(sign(name, params, redirectUri))
21
- .toBe(`${BASE_URL}/sign/name?one=one&two=two&redirect_uri=https%3A%2F%2Fexample.com`)
22
- })
23
-
24
- it('should return url if given correct parameters without redirect uri', function () {
25
- name = 'name'
26
- params = { one: 'one', two: 'two' }
27
- redirectUri = null
28
-
29
- expect(sign(name, params, redirectUri)).toBe(`${BASE_URL}/sign/name?one=one&two=two`)
30
- })
31
-
32
- it('should return url if given correct name and empty parameters', function () {
33
- name = 'name'
34
-
35
- expect(sign(name, params, redirectUri)).toBe(`${BASE_URL}/sign/name?`)
36
- })
37
-
38
- it('should return error if given incorrect name', function () {
39
- name = null
40
-
41
- expect(sign(name, params, redirectUri)).toStrictEqual({
42
- error: 'invalid_request',
43
- error_description: 'Request has an invalid format'
44
- })
45
- })
46
-
47
- it('should return error if given incorrect params', function () {
48
- params = undefined
49
- expect(sign(name, params, redirectUri)).toStrictEqual({
50
- error: 'invalid_request',
51
- error_description: 'Request has an invalid format'
52
- })
53
-
54
- params = undefined
55
- expect(sign(name, params, redirectUri)).toStrictEqual({
56
- error: 'invalid_request',
57
- error_description: 'Request has an invalid format'
58
- })
59
- })
60
- })
@@ -1,22 +0,0 @@
1
- import { BASE_URL } from '../consts'
2
- import { SignErrors } from '../types'
3
-
4
- export function sign(
5
- name: string,
6
- params: Record<string, string | number | boolean>,
7
- redirectUri: string
8
- ): string | SignErrors {
9
- console.warn('The function "sign" is deprecated.')
10
- if (typeof name !== 'string' || typeof params !== 'object' || params === null) {
11
- return {
12
- error: 'invalid_request',
13
- error_description: 'Request has an invalid format'
14
- }
15
- }
16
- let url = `${BASE_URL}/sign/${name}?`
17
- url += Object.keys(params)
18
- .map(key => `${key}=${encodeURIComponent(params[key])}`)
19
- .join('&')
20
- url += redirectUri ? `&redirect_uri=${encodeURIComponent(redirectUri)}` : ''
21
- return url
22
- }
@@ -1,11 +0,0 @@
1
- // @ts-ignore
2
- import { Client } from '../lib/index'
3
-
4
- describe('Testing module imports', function () {
5
- it('should contain Client class', function () {
6
- expect(Client).toBeTruthy()
7
-
8
- const client = new Client({})
9
- expect(client).toBeInstanceOf(Client)
10
- })
11
- })