diff --git a/src/address-book/generate-message.ts b/src/address-book/generate-message.ts index 537a950..2f2f8ee 100644 --- a/src/address-book/generate-message.ts +++ b/src/address-book/generate-message.ts @@ -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 => { +export const _generateMessage = async (data: AddressbookMessage, token: string): Promise => { const req = await axios({ url: `${Apis.wAddressBookGenerateMessageEndpoint}`, method: "POST", - headers: headers, + headers: { + "Authorization": "Bearer " + token, + }, data }) diff --git a/src/address-book/get.ts b/src/address-book/get.ts index 3b4bce6..f595f64 100644 --- a/src/address-book/get.ts +++ b/src/address-book/get.ts @@ -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 => { +export const _get = async (owner: string, token: String): Promise => { const req = await axios({ url: `${Apis.wAddressBookEndpoint}?owner=${owner}`, method: "GET", - headers: headers, + + headers: { + "Authorization": "Bearer " + token, + }, }) const res = await req.data diff --git a/src/address-book/index.ts b/src/address-book/index.ts index d8c5acd..1a8567b 100644 --- a/src/address-book/index.ts +++ b/src/address-book/index.ts @@ -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) { diff --git a/src/types/address-book/index.ts b/src/types/address-book/index.ts index fcdd753..b050ff5 100644 --- a/src/types/address-book/index.ts +++ b/src/types/address-book/index.ts @@ -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(), diff --git a/src/types/headers.ts b/src/types/headers.ts index 9452bcf..88bc45e 100644 --- a/src/types/headers.ts +++ b/src/types/headers.ts @@ -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 \ No newline at end of file diff --git a/tests/addressbook/generate-message.test.ts b/tests/addressbook/generate-message.test.ts new file mode 100644 index 0000000..17838b8 --- /dev/null +++ b/tests/addressbook/generate-message.test.ts @@ -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(); + }); +}); \ No newline at end of file diff --git a/tests/addressbook/get.test.ts b/tests/addressbook/get.test.ts new file mode 100644 index 0000000..afb8466 --- /dev/null +++ b/tests/addressbook/get.test.ts @@ -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(); + }); +}); \ No newline at end of file diff --git a/tests/identity/get.test.ts b/tests/identity/get.test.ts index 139b454..885cf31 100644 --- a/tests/identity/get.test.ts +++ b/tests/identity/get.test.ts @@ -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();