Skip to content

Commit

Permalink
feat(SPV-1366): correct return models from api
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain committed Jan 13, 2025
1 parent a056b91 commit 6ee2f04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 91 deletions.
6 changes: 0 additions & 6 deletions examples/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ try {
wh.handleIncomingEvents(fastifyHttpHandler);
});

const allWebhooks = await client.AdminGetWebhooks();
console.log('Subscribed webhooks list\n');
for (const w of allWebhooks) {
console.log(`URL: ${w.url}, banned: ${w.banned}\n`);
}

wh.registerHandler('StringEvent', async (event) => {
console.log(`\n\nProcessing event-string: ${event.value}\n\n`);
});
Expand Down
32 changes: 16 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ import {
User,
AdminStats,
PaymailAddress,
XPubs,
XPub,
PageModel,
Utxo,
MerkleRootsRepository,
QueryPageParams,
NewContact,
PaymailAddresses,
AdminTx,
AdminTxs,
Utxos,
} from './types';
import { defaultLogger, Logger, LoggerConfig, makeLogger } from './logger';
import { HttpClient } from './httpclient';
Expand Down Expand Up @@ -137,13 +133,13 @@ export class SpvWalletClient {
* @param {AdminAccessKeyFilter} 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 {QueryPageParams} params Database query parameters for page, page size and sorting
* @return {AccessKey}
* @return {PageModel<AccessKey>}
*/
async AdminGetAccessKeys(
conditions: AdminAccessKeyFilter,
metadata: Metadata,
params: QueryPageParams,
): Promise<AccessKey> {
): Promise<PageModel<AccessKey>> {
const basePath = 'admin/users/keys';
const queryString = buildQueryPath({
metadata,
Expand Down Expand Up @@ -235,13 +231,13 @@ export class SpvWalletClient {
* @param {TransactionFilter} 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 {QueryPageParams} params Database query parameters for page, page size and sorting
* @return {AdminTxs}
* @return {PageModel<AdminTx>}
*/
async AdminGetTransactions(
conditions: TransactionFilter,
metadata: Metadata,
params: QueryPageParams,
): Promise<AdminTxs> {
): Promise<PageModel<AdminTx>> {
const basePath = 'admin/transactions';
const queryString = buildQueryPath({
filter: conditions,
Expand All @@ -257,9 +253,13 @@ export class SpvWalletClient {
* @param {AdminUtxoFilter} 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 {QueryPageParams} params Database query parameters for page, page size and sorting
* @return {Utxos}
* @return {PageModel<Utxo>}
*/
async AdminGetUtxos(conditions: AdminUtxoFilter, metadata: Metadata, params: QueryPageParams): Promise<Utxos> {
async AdminGetUtxos(
conditions: AdminUtxoFilter,
metadata: Metadata,
params: QueryPageParams,
): Promise<PageModel<Utxo>> {
const basePath = 'admin/utxos';
const queryString = buildQueryPath({
filter: conditions,
Expand All @@ -276,9 +276,9 @@ export class SpvWalletClient {
* @param {XpubFilter} 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 {QueryPageParams} params Database query parameters for page, page size and sorting
* @return {XPubs}
* @return {PageModel<XPub>}
*/
async AdminGetXPubs(conditions: XpubFilter, metadata: Metadata, params: QueryPageParams): Promise<XPubs> {
async AdminGetXPubs(conditions: XpubFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<XPub>> {
const basePath = 'admin/users';
const queryString = buildQueryPath({
filter: conditions,
Expand Down Expand Up @@ -319,13 +319,13 @@ export class SpvWalletClient {
* @param {AdminPaymailFilter} 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 {QueryPageParams} params Database query parameters for page, page size and sorting
* @return {PaymailAddresses}
* @return {PageModel<PaymailAddress>}
*/
async AdminGetPaymails(
conditions: AdminPaymailFilter,
metadata: Metadata,
params: QueryPageParams,
): Promise<PaymailAddresses> {
): Promise<PageModel<PaymailAddress>> {
const basePath = 'admin/paymails';
const queryString = buildQueryPath({
metadata,
Expand Down Expand Up @@ -378,7 +378,7 @@ export class SpvWalletClient {
* @param url - The URL to subscribe the webhook to.
* @param tokenHeader - The header name for the authentication token.
* @param tokenValue - The value of the authentication token.
* @returns A Promise that resolves when the webhook subscription is complete.
* @returns void
*/
async AdminSubscribeWebhook(url: string, tokenHeader: string, tokenValue: string): Promise<void> {
return await this.http.adminRequest(`admin/webhooks/subscriptions`, 'POST', { url, tokenHeader, tokenValue });
Expand All @@ -388,7 +388,7 @@ export class SpvWalletClient {
* Admin only: Delete a webhook subscription by the given URL.
*
* @param url - The URL of the webhook subscription to delete.
* @returns A Promise that resolves when the webhook subscription is deleted.
* @returns void
*/
async AdminDeleteWebhook(url: string): Promise<void> {
return await this.http.adminRequest(`admin/webhooks/subscriptions`, 'DELETE', { url });
Expand Down
69 changes: 0 additions & 69 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ export interface XPub {
deletedAt?: Date;
}

/**
* Array of xpubs
* @see {@link XPub}
*/
export interface XPubs extends Array<XPub> {}

/**
* Page interface
*
Expand Down Expand Up @@ -216,12 +210,6 @@ export interface AdminStats {
utxosPerType: { [key: string]: any };
}

/**
* Array of xpubs
* @see {@link User}
*/
export interface Users extends Array<User> {}

/**
* Access key interface for non-admin (User) endpoints.
*/
Expand All @@ -236,11 +224,6 @@ export interface AccessKey {
revokedAt?: Date;
}

/**
* Array of AccessKeys for non-admin (User) endpoints.
*/
export interface AccessKeys extends Array<AccessKey> {}

/**
* NewContact interface for adding a new contact by admin.
* creatorPaymail is the paymail of the user who will be owner of the contact and it's required for admin createContact action.
Expand All @@ -266,11 +249,6 @@ export interface Contact {
metadata?: Metadata;
}

/**
* Array of Contacts for non-admin (User) endpoints.
*/
export interface Contacts extends PageModel<Contact> {}

/**
* Destination interface for non-admin (User) endpoints.
*/
Expand All @@ -290,11 +268,6 @@ export interface Destination {
deletedAt?: Date;
}

/**
* Array of Destinations for non-admin (User) endpoints.
*/
export interface Destinations extends Array<Destination> {}

/**
* Transaction interface for non-admin (User) endpoints.
*/
Expand All @@ -315,11 +288,6 @@ export interface Tx {
deletedAt?: Date;
}

/**
* Array of Txs for non-admin (User) endpoints.
*/
export interface Txs extends Array<Tx> {}

/**
* Transaction interface for Admin endpoints.
*/
Expand All @@ -332,11 +300,6 @@ export interface AdminTx extends Tx {
outputValue: number;
}

/**
* Array of Txs for Admin endpoints.
*/
export interface AdminTxs extends Array<AdminTx> {}

/**
* Utxo interface.
*/
Expand All @@ -356,11 +319,6 @@ export interface Utxo {
metadata?: Metadata;
}

/**
* Array of Utxos.
*/
export interface Utxos extends Array<Utxo> {}

/**
* Paymail address interface for Admin endpoints
*/
Expand All @@ -378,33 +336,6 @@ export interface PaymailAddress {
deletedAt?: Date;
}

/**
* Array of PaymailAddresses for Admin
*/
export interface PaymailAddresses extends Array<PaymailAddress> {}

/**
* Webhook interface for non-admin (User) endpoints.
*/
export interface Webhook {
url: string;
banned: boolean;
}

/**
* Output interface for non-admin (User) endpoints.
*/
export interface Output {
to: string;
satoshis: number;
opReturn?: OpReturn;
}

/**
* Array of Outputs for non-admin (User) endpoints.
*/
export interface Outputs extends Array<Output> {}

/**
* OP_RETURN data for transactions.
*/
Expand Down

0 comments on commit 6ee2f04

Please sign in to comment.