@vaultsfyi/sdk 1.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.
@@ -0,0 +1,20 @@
1
+ export function generateQueryParams(
2
+ queryParams: Record<string, string | number | boolean | null | undefined | bigint | string[]> | undefined
3
+ ): string {
4
+ if (!queryParams || Object.keys(queryParams).length === 0) return ''
5
+
6
+ const params = new URLSearchParams()
7
+ for (const [key, value] of Object.entries(queryParams)) {
8
+ if (value == null) continue
9
+
10
+ if (Array.isArray(value)) {
11
+ for (const item of value) {
12
+ params.append(key, item)
13
+ }
14
+ } else {
15
+ params.set(key, value.toString())
16
+ }
17
+ }
18
+
19
+ return `?${params}`
20
+ }
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { VaultsSdk } from '../src/client'
3
+
4
+ describe('sdk:constructor', () => {
5
+ it('simple constructor', () => {
6
+ const sdk = new VaultsSdk({ apiKey: 'test' })
7
+
8
+ expect(sdk['apiKey']).toBe('test')
9
+ expect(sdk['apiBaseUrl']).toBe('https://api.vaults.fyi')
10
+ })
11
+
12
+ it('custom api base url', () => {
13
+ const sdk = new VaultsSdk({ apiKey: 'test' }, { apiBaseUrl: 'https://test.api.vaults.fyi' })
14
+
15
+ expect(sdk['apiKey']).toBe('test')
16
+ expect(sdk['apiBaseUrl']).toBe('https://test.api.vaults.fyi')
17
+ })
18
+ })
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { generateQueryParams } from '../../src/utils/generateQueryParams'
3
+
4
+ describe('utils:generateQueryParams', () => {
5
+ it('empty string for undefined', () => {
6
+ expect(generateQueryParams(undefined)).toBe('')
7
+ })
8
+
9
+ it('returns empty string for empty object', () => {
10
+ expect(generateQueryParams({})).toBe('')
11
+ })
12
+
13
+ it('returns query params', () => {
14
+ expect(generateQueryParams({ a: '1', b: '2' })).toBe('?a=1&b=2')
15
+ })
16
+
17
+ it('returns query params with different types', () => {
18
+ expect(generateQueryParams({ a: 1, b: 2n, c: true, d: false, e: null, f: undefined })).toBe(
19
+ '?a=1&b=2&c=true&d=false'
20
+ )
21
+ })
22
+
23
+ it('returns query params with array', () => {
24
+ expect(generateQueryParams({ a: ['1', '2'] })).toBe('?a=1&a=2')
25
+ })
26
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "preserve",
4
+ "resolveJsonModule": true,
5
+ "esModuleInterop": true,
6
+ "target": "esnext",
7
+ "sourceMap": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true,
10
+ "strict": true
11
+ },
12
+ "include": ["src"]
13
+ }