diff --git a/package.json b/package.json index 70132a1a..e6baa8b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bsv/spv-wallet-js-client", - "version": "1.0.0-beta.23", + "version": "1.0.0-beta.24", "description": "TypeScript library for connecting to a SPV Wallet server", "repository": { "type": "git", diff --git a/src/client.ts b/src/client.ts index 044011cb..f7b58ab9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -31,6 +31,7 @@ import { PageModel, Utxo, MerkleRootsRepository, + QueryPageParams, } from './types'; import { defaultLogger, Logger, LoggerConfig, makeLogger } from './logger'; import { HttpClient } from './httpclient'; @@ -537,19 +538,14 @@ export class SpvWalletClient { * Get a list of all access keys for the current user, filtered by conditions, metadata and queryParams * * @param {AccessKeyFilter} conditions Key value object to use to filter the documents - * @param {Metadata} metadata Key value object to use to filter the documents by the metadata * @param {QueryParams} queryParams Database query parameters for page, page size and sorting * @return {PageModel} */ - async GetAccessKeys( - conditions: AccessKeyFilter, - metadata: Metadata, - queryParams: QueryParams, - ): Promise> { + async GetAccessKeys(conditions: AccessKeyFilter, queryParams: QueryPageParams): Promise> { const basePath = `users/current/keys`; const queryString = buildQueryPath({ filter: conditions, - metadata: metadata, + metadata: {}, page: queryParams, }); diff --git a/src/query/query-builder.ts b/src/query/query-builder.ts index d777aee4..93f96190 100644 --- a/src/query/query-builder.ts +++ b/src/query/query-builder.ts @@ -1,5 +1,5 @@ -import { AccessKeyFilter, ContactFilter, ModelFilter, TransactionFilter, UtxoFilter, XpubFilter } from "../filters"; -import { Metadata, QueryParams as Page } from "../types"; +import { AccessKeyFilter, ContactFilter, ModelFilter, TransactionFilter, UtxoFilter, XpubFilter } from '../filters'; +import { Metadata, QueryParams as Page } from '../types'; export interface BuildPathOptions { filter: ModelFilter | TransactionFilter | UtxoFilter | XpubFilter | AccessKeyFilter | ContactFilter; @@ -11,6 +11,10 @@ function flattenParams(params: Record, parentKey?: string): Record< const flattened: Record = {}; Object.entries(params).forEach(([key, value]) => { + if (!value) { + return; + } + const newKey = parentKey ? `${parentKey}[${key}]` : key; if (typeof value === 'object' && value !== null && !Array.isArray(value)) { diff --git a/src/types.ts b/src/types.ts index 76492e20..fdcf02bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,50 +64,50 @@ export interface MerkleRootsRepository { "next_external_num": 229 } */ - export interface XPub { - /** - * metadata object - */ - metadata?: Metadata; - /** - * xpub id - */ - id: string; - /** - * Current balance in sats of the xpub - */ - current_balance: number; - /** - * Next internal (change address) number to use for a new destination - * - * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination - */ - next_internal_num: number; - /** - * Next external number to use for a new destination - * - * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination - */ - next_external_num: number; - /** - * Date when this object was created - */ - created_at?: Date; - /** - * Date when this object was last updated - */ - updated_at?: Date; - /** - * If this object has been deleted, this date will be set - */ - deleted_at?: Date; - } - +export interface XPub { + /** + * metadata object + */ + metadata?: Metadata; + /** + * xpub id + */ + id: string; + /** + * Current balance in sats of the xpub + */ + current_balance: number; + /** + * Next internal (change address) number to use for a new destination + * + * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination + */ + next_internal_num: number; + /** + * Next external number to use for a new destination + * + * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination + */ + next_external_num: number; + /** + * Date when this object was created + */ + created_at?: Date; /** - * Array of xpubs - * @see {@link XPub} + * Date when this object was last updated */ - export interface XPubs extends Array {} + updated_at?: Date; + /** + * If this object has been deleted, this date will be set + */ + deleted_at?: Date; +} + +/** + * Array of xpubs + * @see {@link XPub} + */ +export interface XPubs extends Array {} /** * Page interface @@ -444,7 +444,6 @@ export interface OldUtxo { */ export interface OldUtxos extends Array {} - /** * Old paymail address interface for Admin endpoints (Deprecated) */ @@ -719,6 +718,16 @@ export interface QueryParams { sortDirection?: string; } +/** + * Query page params to limit and order database list results. + */ +export interface QueryPageParams { + page?: number; + size?: number; + sort?: string; + sortBy?: string; +} + /** * SharedConfig defines the configuration shared by different parts of the application. */