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