Skip to content

Commit

Permalink
Fix: token added for addressbook functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkmonarch committed Oct 30, 2023
1 parent eaca345 commit f1d25f9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/address-book/generate-message.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import axios from "axios";
import Apis from "../utils/api-config";
import {AddressbookMessage} from "../types/address-book/index";
import { AddressbookMessage } from "../types/address-book/index";
import { Headers } from "../types";

export const _generateMessage = async (data: AddressbookMessage, headers: Headers): Promise<any> => {
export const _generateMessage = async (data: AddressbookMessage, token: string): Promise<any> => {
const req = await axios({
url: `${Apis.wAddressBookGenerateMessageEndpoint}`,
method: "POST",
headers: headers,
headers: {
"Authorization": "Bearer " + token,
},
data
})

Expand Down
7 changes: 5 additions & 2 deletions src/address-book/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import axios from "axios";
import Apis from "../utils/api-config";
import { Headers } from "../types";

export const _get = async (owner: string, headers:Headers): Promise<any[]> => {
export const _get = async (owner: string, token: String): Promise<any[]> => {
const req = await axios({
url: `${Apis.wAddressBookEndpoint}?owner=${owner}`,
method: "GET",
headers: headers,

headers: {
"Authorization": "Bearer " + token,
},
})

const res = await req.data
Expand Down
24 changes: 12 additions & 12 deletions src/address-book/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {_get} from './get';
import {_generateMessage} from './generate-message';
import {_create} from './create';
import {_update} from './update';
import {UpdateAddressbook, AddressBook, AddressbookMessage, } from "../types/address-book/index";
import { _get } from './get';
import { _generateMessage } from './generate-message';
import { _create } from './create';
import { _update } from './update';
import { UpdateAddressbook, AddressBook, AddressbookMessage, } from "../types/address-book/index";
import { Headers } from '../types';
export default class Addressbook{
export default class Addressbook {
private headers: Headers

constructor(headers: Headers) {
this.headers = headers
}

get(owner: string) {
return _get(owner, this.headers)
get(owner: string, token: String) {
return _get(owner, token)
}

generateMessage(data: AddressbookMessage) {
return _generateMessage(data, this.headers)
generateMessage(data: AddressbookMessage, token: string) {
return _generateMessage(data, token)
}

create(data: AddressBook) {
return _create(data,this.headers)
return _create(data, this.headers)
}

update(data: UpdateAddressbook) {
Expand Down
4 changes: 2 additions & 2 deletions src/types/address-book/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const addresses = z.object({
});

export const addressBookIdentity = z.object({
addressBookIdentity: z.string(),
identity: z.string(),
name: z.string(),
});

export const addressbookGenerateMessage = z.object({
id: z.string(),
id: z.number(),
name: z.string(),
addresses: z.array(addresses).optional(),
identities: z.array(addressBookIdentity).optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/types/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "zod";
export const headersSchema = z.object({
"secret-key": z.string(),
"content-type": z.string().default("application/json"),
"Accept": z.string().default("application/json")
"Accept": z.string().default("application/json"),
})

export type Headers = z.infer<typeof headersSchema>
28 changes: 28 additions & 0 deletions tests/addressbook/generate-message.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Fetcch from "../../src";

describe("module: generate-message", () => {
const fetcch = new Fetcch("4ff9ecc8-4537-4e2e-950d-0cefbd16f2a5");
test("generate message for creating a addressbook", async () => {
const message = await fetcch.addressBook.generateMessage(
{
"id": 1,
"name": "Book 1",
"addresses": [
{
"address": "0x123",
"name": "Satyam",
"chainType": "EVM"
}
],
"identities": [
{
"identity": "satyam@fetcch",
"name": "Sataa"
}
],
"owner": "satyam@fetcch"
}
);
expect(message).toBeDefined();
});
});
9 changes: 9 additions & 0 deletions tests/addressbook/get.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Fetcch from "../../src";

describe("module: get-addressbook", () => {
const fetcch = new Fetcch("4ff9ecc8-4537-4e2e-950d-0cefbd16f2a5");
test("get addressbook of the user", async () => {
const addressbook = await fetcch.addressBook.get("v@pay", "token");
expect(addressbook).toBeDefined();
});
});
2 changes: 1 addition & 1 deletion tests/identity/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("module: get-identity", () => {

test("get identity by a handle", async () => {
try {
const ID = await fetcch.identity.get("vpay");
const ID = await fetcch.identity.get("v@pay");
console.log(ID);
expect(ID).toBeDefined();

Expand Down

0 comments on commit f1d25f9

Please sign in to comment.