Skip to content

Commit

Permalink
Feat(SPV-680 & SPV-887): correct api responses (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain authored Nov 18, 2024
1 parent 590f3af commit 76ebd06
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
12 changes: 5 additions & 7 deletions examples/access-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ const client = new SpvWalletClient(server, {
});

const createdAccessKey = await client.CreateAccessKey({ some_metadata: 'example' });
console.log('Created access key ID:', (createdAccessKey.id));
console.log('Metadata:', (createdAccessKey.metadata));
console.log('Created at:', (createdAccessKey.createdAt));
console.log('Created access key ID:', createdAccessKey.id);
console.log('Metadata:', createdAccessKey.metadata);
console.log('Created at:', createdAccessKey.createdAt);

const fetchedAccessKey = await client.GetAccessKeyByID(createdAccessKey.id);
console.log('Fetched access key ID:', (fetchedAccessKey.id));
console.log('Fetched access key ID:', fetchedAccessKey.id);

const revokedAccessKey = await client.RevokeAccessKey(createdAccessKey.id);
console.log('Revoked access key ID:', (revokedAccessKey.id));
console.log('Revoked at:', (revokedAccessKey.revokedAt));
await client.RevokeAccessKey(createdAccessKey.id);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsv/spv-wallet-js-client",
"version": "1.0.0-beta.24",
"version": "1.0.0-beta.25",
"description": "TypeScript library for connecting to a SPV Wallet server",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ export class SpvWalletClient {
* After this function is successfully called, the access key cannot be used anymore on an SPV Wallet server
*
* @param id string The database ID of the access key to revoke
* @return {AccessKey}
* @return void
*/
async RevokeAccessKey(id: string): Promise<AccessKey> {
async RevokeAccessKey(id: string): Promise<void> {
return await this.http.request(`users/current/keys/${id}`, 'DELETE');
}

Expand Down Expand Up @@ -617,9 +617,9 @@ export class SpvWalletClient {
* Remove a single contact by it's paymail address.
*
* @param {string} paymail Contact paymail to remove a specific contact
* @return {Contact}
* @return void
*/
async RemoveContact(paymail: string): Promise<Contact> {
async RemoveContact(paymail: string): Promise<void> {
return await this.http.request(`contacts/${paymail}`, 'DELETE');
}

Expand Down
42 changes: 21 additions & 21 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ describe('SPVWalletClient routing', () => {
const spvWalletClient = new SpvWalletClient(testClient.serverURL, options, { level: 'error' });

it.each`
spvWalletMethod | httpMethod | path | act
${'GetUserInfo'} | ${'get'} | ${'users/current'} | ${() => spvWalletClient.GetUserInfo()}
${'UpdateXPubMetadata'} | ${'patch'} | ${'users/current'} | ${() => spvWalletClient.UpdateUserMetadata({})}
${'GetAccessKeyByID'} | ${'get'} | ${'users/current/keys/' + accessKeyString} | ${() => spvWalletClient.GetAccessKeyByID(accessKeyString)}
${'GetAccessKeys'} | ${'get'} | ${'users/current/keys'} | ${() => spvWalletClient.GetAccessKeys({}, {}, {})}
${'CreateAccessKey'} | ${'post'} | ${'users/current/keys'} | ${() => spvWalletClient.CreateAccessKey({})}
${'RevokeAccessKey'} | ${'delete'} | ${'users/current/keys/' + accessKeyString} | ${() => spvWalletClient.RevokeAccessKey(accessKeyString)}
${'GetContactByPaymail'} | ${'get'} | ${'contacts/test'} | ${() => spvWalletClient.GetContactByPaymail('test')}
${'GetContacts'} | ${'get'} | ${'contacts'} | ${() => spvWalletClient.GetContacts({}, {}, {})}
${'UpsertContact'} | ${'put'} | ${'contacts/test'} | ${() => spvWalletClient.UpsertContact('test', '', '', {})}
${'RemoveContact'} | ${'delete'} | ${'contacts/test'} | ${() => spvWalletClient.RemoveContact('test')}
${'AcceptContactInvitation'} | ${'post'} | ${'invitations/test/contacts'} | ${() => spvWalletClient.AcceptContactInvitation('test')}
${'RejectContactInvitation'} | ${'delete'} | ${'invitations/test/contacts'} | ${() => spvWalletClient.RejectContactInvitation('test')}
${'UnconfirmContact'} | ${'delete'} | ${'contacts/test/confirmation'} | ${() => spvWalletClient.UnconfirmContact('test')}
${'GetTransactionById'} | ${'get'} | ${'transactions/id'} | ${() => spvWalletClient.GetTransactionById('id')}
${'GetTransactions'} | ${'get'} | ${'transactions'} | ${() => spvWalletClient.GetTransactions({}, {}, {})}
${'NewDraftTransaction'} | ${'post'} | ${'transactions/drafts'} | ${() => spvWalletClient.NewDraftTransaction({} as DraftTransactionConfig, {})}
${'RecordTransaction'} | ${'post'} | ${'transactions'} | ${() => spvWalletClient.RecordTransaction('', '', {})}
${'UpdateTransactionMetadata'} | ${'patch'} | ${'transactions/id'} | ${() => spvWalletClient.UpdateTransactionMetadata('id', {})}
${'GetUtxos'} | ${'get'} | ${'utxos'} | ${() => spvWalletClient.GetUtxos({}, {}, {})}
${'GetSharedConfig'} | ${'get'} | ${'configs/shared'} | ${() => spvWalletClient.GetSharedConfig()}
spvWalletMethod | httpMethod | path | act
${'GetUserInfo'} | ${'get'} | ${'users/current'} | ${() => spvWalletClient.GetUserInfo()}
${'UpdateXPubMetadata'} | ${'patch'} | ${'users/current'} | ${() => spvWalletClient.UpdateUserMetadata({})}
${'GetAccessKeyByID'} | ${'get'} | ${'users/current/keys/' + accessKeyString} | ${() => spvWalletClient.GetAccessKeyByID(accessKeyString)}
${'GetAccessKeys'} | ${'get'} | ${'users/current/keys'} | ${() => spvWalletClient.GetAccessKeys({}, {})}
${'CreateAccessKey'} | ${'post'} | ${'users/current/keys'} | ${() => spvWalletClient.CreateAccessKey({})}
${'RevokeAccessKey'} | ${'delete'} | ${'users/current/keys/' + accessKeyString} | ${() => spvWalletClient.RevokeAccessKey(accessKeyString)}
${'GetContactByPaymail'} | ${'get'} | ${'contacts/test'} | ${() => spvWalletClient.GetContactByPaymail('test')}
${'GetContacts'} | ${'get'} | ${'contacts'} | ${() => spvWalletClient.GetContacts({}, {}, {})}
${'UpsertContact'} | ${'put'} | ${'contacts/test'} | ${() => spvWalletClient.UpsertContact('test', '', '', {})}
${'RemoveContact'} | ${'delete'} | ${'contacts/test'} | ${() => spvWalletClient.RemoveContact('test')}
${'AcceptContactInvitation'} | ${'post'} | ${'invitations/test/contacts'} | ${() => spvWalletClient.AcceptContactInvitation('test')}
${'RejectContactInvitation'} | ${'delete'} | ${'invitations/test/contacts'} | ${() => spvWalletClient.RejectContactInvitation('test')}
${'UnconfirmContact'} | ${'delete'} | ${'contacts/test/confirmation'} | ${() => spvWalletClient.UnconfirmContact('test')}
${'GetTransactionById'} | ${'get'} | ${'transactions/id'} | ${() => spvWalletClient.GetTransactionById('id')}
${'GetTransactions'} | ${'get'} | ${'transactions'} | ${() => spvWalletClient.GetTransactions({}, {}, {})}
${'NewDraftTransaction'} | ${'post'} | ${'transactions/drafts'} | ${() => spvWalletClient.NewDraftTransaction({} as DraftTransactionConfig, {})}
${'RecordTransaction'} | ${'post'} | ${'transactions'} | ${() => spvWalletClient.RecordTransaction('', '', {})}
${'UpdateTransactionMetadata'} | ${'patch'} | ${'transactions/id'} | ${() => spvWalletClient.UpdateTransactionMetadata('id', {})}
${'GetUtxos'} | ${'get'} | ${'utxos'} | ${() => spvWalletClient.GetUtxos({}, {}, {})}
${'GetSharedConfig'} | ${'get'} | ${'configs/shared'} | ${() => spvWalletClient.GetSharedConfig()}
`('$spvWalletMethod', async ({ path, httpMethod, act }) => {
// given
setupHttpMock(httpMethod, path);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ export interface OldPaymailAddress {
xpub_id: string;
alias: string;
domain: string;
address: string;
public_name: string;
avatar: string;
created_at: Date;
Expand Down

0 comments on commit 76ebd06

Please sign in to comment.