From 8c3cffbde1e683acd26678908d56a26b2a562404 Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Thu, 26 Oct 2023 17:50:10 +0530 Subject: [PATCH 1/6] Fix: structure in identity module --- src/auth/index.ts | 22 ++++++++++---- .../{login_message.ts => login-message.ts} | 8 ++--- src/auth/login.ts | 8 +++-- ...{create_identity.ts => create-identity.ts} | 8 ++--- ...essage.ts => generate-identity-message.ts} | 8 ++--- src/identity/generateIdentityMessage.test.ts | 27 ----------------- src/identity/get.ts | 8 ++--- src/identity/getIdentity.test.ts | 7 ----- src/identity/index.ts | 30 ++++++++++++++----- 9 files changed, 57 insertions(+), 69 deletions(-) rename src/auth/{login_message.ts => login-message.ts} (63%) rename src/identity/{create_identity.ts => create-identity.ts} (61%) rename src/identity/{generate_identity_message.ts => generate-identity-message.ts} (61%) delete mode 100644 src/identity/generateIdentityMessage.test.ts delete mode 100644 src/identity/getIdentity.test.ts diff --git a/src/auth/index.ts b/src/auth/index.ts index 6c99ca4..3a3263d 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -1,7 +1,19 @@ -import { login } from "./login"; -import { generateMessage } from "./login_message"; +import { _login } from "./login"; +import { _generateMessage } from "./login-message"; +import { AuthSchema, Headers } from "../types"; -export default{ - login, - generateMessage +export default class Auth { + private headers: Headers + + constructor(headers: Headers) { + this.headers = headers + } + + login(actions: AuthSchema) { + return _login(actions,this.headers) + } + + generateMessage(owner: string) { + return _generateMessage(owner, this.headers) + } } \ No newline at end of file diff --git a/src/auth/login_message.ts b/src/auth/login-message.ts similarity index 63% rename from src/auth/login_message.ts rename to src/auth/login-message.ts index cf2966d..465dcbb 100644 --- a/src/auth/login_message.ts +++ b/src/auth/login-message.ts @@ -1,8 +1,8 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import { getSecretKey } from ".."; +import { Headers } from '../types'; -export const generateMessage = async (owner:string): Promise => { +export const _generateMessage = async (owner:string,headers: Headers): Promise => { const data = { "owner": owner }; @@ -10,9 +10,7 @@ export const generateMessage = async (owner:string): Promise => { const req = await axios({ url: Apis.wGenerateAuthenticationMessageEndpoint, method: 'POST', - headers: { - 'secret-key': getSecretKey() - }, + headers: headers, data }) diff --git a/src/auth/login.ts b/src/auth/login.ts index 2e5cef8..6d38a5b 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -1,12 +1,14 @@ import Apis from "../utils/api-config"; import axios from "axios"; -import { AuthSchema } from "../types/auth"; +import { AuthSchema, } from "../types/auth"; +import { Headers } from "../types"; -export const login = async (auth: AuthSchema): Promise => { +export const _login = async (auth: AuthSchema,headers:Headers): Promise => { const req = await axios({ url: Apis.wAuthenticationEndpoint, method: 'POST', - data: auth + data: auth, + headers: headers }) const res = await req.data diff --git a/src/identity/create_identity.ts b/src/identity/create-identity.ts similarity index 61% rename from src/identity/create_identity.ts rename to src/identity/create-identity.ts index f15127b..648e77d 100644 --- a/src/identity/create_identity.ts +++ b/src/identity/create-identity.ts @@ -1,15 +1,13 @@ import axios from "axios"; import Apis from "../utils/api-config"; import {identitySchema} from "../types/identity"; -import { getSecretKey } from ".."; +import { Headers } from "../types"; -export const create = async (data: identitySchema): Promise => { +export const _create = async (data: identitySchema, headers:Headers): Promise => { const req = await axios({ url: Apis.wGetIdentityEndpoint, method: "POST", - headers: { - "secret-key": getSecretKey() - }, + headers: headers, data }) diff --git a/src/identity/generate_identity_message.ts b/src/identity/generate-identity-message.ts similarity index 61% rename from src/identity/generate_identity_message.ts rename to src/identity/generate-identity-message.ts index dc2ae13..4fc9a22 100644 --- a/src/identity/generate_identity_message.ts +++ b/src/identity/generate-identity-message.ts @@ -1,16 +1,14 @@ import axios from "axios"; import Apis from "../utils/api-config"; import { generateIdentityMessageSchema } from "../types/identity"; -import { getSecretKey } from ".."; +import { Headers } from "../types"; -export const generateMessage = async (data: generateIdentityMessageSchema): Promise => { +export const _generateMessage = async (data: generateIdentityMessageSchema, headers: Headers): Promise => { const req = await axios({ url: Apis.wIdentityGenerateMessageEndpoint, method: "POST", - headers: { - "secret-key": getSecretKey() - }, + headers: headers, data }) diff --git a/src/identity/generateIdentityMessage.test.ts b/src/identity/generateIdentityMessage.test.ts deleted file mode 100644 index 877b25e..0000000 --- a/src/identity/generateIdentityMessage.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { generateIdentityMessage } from "./generate_identity_message"; -import { expect, test } from "vitest" - -test("generateIdentityMessage", async () => { - const message = await generateIdentityMessage( - { - "id": "satyamx@pay", - "identifier": "satyamx", - "provider": "pay", - "default": { - "address": "0xeD8A3D22b07C69f3c7D8458B94Ee4F0CE3A790D1", - "chain": 2, - "isMultisig": false, - "isSmartContractWallet": true - }, - "secondary": [ - { - "address": "0x1DCcc9BaF7E8d7A18f948acD467CE016044fC546", - "chain": 6, - "isMultisig": false, - "isSmartContractWallet": false - } - ] - }, - ) - expect(message).toBeDefined() -}); \ No newline at end of file diff --git a/src/identity/get.ts b/src/identity/get.ts index ca25bff..2a2b4a2 100644 --- a/src/identity/get.ts +++ b/src/identity/get.ts @@ -1,14 +1,12 @@ -import { getSecretKey } from ".."; import Apis from "../utils/api-config"; import axios from "axios"; +import { Headers } from '../types'; -export const get = async (id: string): Promise => { +export const _get = async (id: string, headers: Headers): Promise => { const req = await axios({ url: `${Apis.wGetIdentityEndpoint}?id=${id}`, method: "GET", - headers: { - "secret-key":getSecretKey() - } + headers: headers }) const res = await req.data diff --git a/src/identity/getIdentity.test.ts b/src/identity/getIdentity.test.ts deleted file mode 100644 index 2767d50..0000000 --- a/src/identity/getIdentity.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expect, test } from "vitest" -import {getIdentity} from "./get"; - -test("getIdentity", async () => { - const identity = await getIdentity("v@pay"); - expect(identity).toBeDefined(); -}); \ No newline at end of file diff --git a/src/identity/index.ts b/src/identity/index.ts index b655b8c..357734e 100644 --- a/src/identity/index.ts +++ b/src/identity/index.ts @@ -1,9 +1,25 @@ -import {get} from "./get"; -import {create} from "./create_identity"; -import {generateMessage} from "./generate_identity_message"; +import {_get} from "./get"; +import {_generateMessage} from "./generate-identity-message"; +import {_create} from "./create-identity"; +import { Headers } from '../types'; +import {generateIdentityMessageSchema, identitySchema} from "../types/identity"; +export default class identity { + + private headers: Headers + + constructor(headers: Headers) { + this.headers = headers + } -export default { - get, - create, - generateMessage + get(id: string) { + return _get(id, this.headers) + } + + generateMessage(data: generateIdentityMessageSchema) { + return _generateMessage(data, this.headers) + } + + create(data: identitySchema) { + return _create(data,this.headers) + } } From a74669449380960861a16c4838c282b1ffd38d5b Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Thu, 26 Oct 2023 17:58:49 +0530 Subject: [PATCH 2/6] Fix: structure fixed address-book --- ...age.ts => addressbook-generate-message.ts} | 8 +++--- src/address-book/create-addressbook.ts | 17 ++++++++++++ src/address-book/create_addressbook.ts | 19 -------------- src/address-book/{get_circle.ts => get.ts} | 8 +++--- src/address-book/index.ts | 26 ++++++++++++------- ...e_addressbook.ts => update-addressbook.ts} | 8 +++--- 6 files changed, 43 insertions(+), 43 deletions(-) rename src/address-book/{addressbook_generate_message.ts => addressbook-generate-message.ts} (62%) create mode 100644 src/address-book/create-addressbook.ts delete mode 100644 src/address-book/create_addressbook.ts rename src/address-book/{get_circle.ts => get.ts} (59%) rename src/address-book/{update_addressbook.ts => update-addressbook.ts} (62%) diff --git a/src/address-book/addressbook_generate_message.ts b/src/address-book/addressbook-generate-message.ts similarity index 62% rename from src/address-book/addressbook_generate_message.ts rename to src/address-book/addressbook-generate-message.ts index 823857b..e21ac27 100644 --- a/src/address-book/addressbook_generate_message.ts +++ b/src/address-book/addressbook-generate-message.ts @@ -1,15 +1,13 @@ import axios from "axios"; import Apis from "../utils/api-config"; import {addressbookMessageSchema} from "../types/address-book/index"; -import { getSecretKey } from ".."; +import { Headers } from "../types"; -export const generateMessage = async (data: addressbookMessageSchema): Promise => { +export const _generateMessage = async (data: addressbookMessageSchema, headers: Headers): Promise => { const req = await axios({ url: `${Apis.wAddressBookGenerateMessageEndpoint}`, method: "POST", - headers: { - "secret-key": getSecretKey() - }, + headers: headers, data }) diff --git a/src/address-book/create-addressbook.ts b/src/address-book/create-addressbook.ts new file mode 100644 index 0000000..493541f --- /dev/null +++ b/src/address-book/create-addressbook.ts @@ -0,0 +1,17 @@ +import axios from "axios"; +import Apis from "../utils/api-config"; +import {addressbookSchemaType} from "../types/address-book/index"; +import { Headers } from "../types"; + +export const _create = async (data: addressbookSchemaType, headers:Headers): Promise => { + const req = await axios({ + url: `${Apis.wAddressBookEndpoint}`, + method: "POST", + headers: headers, + data + }) + + const res = await req.data + + return res.data +} \ No newline at end of file diff --git a/src/address-book/create_addressbook.ts b/src/address-book/create_addressbook.ts deleted file mode 100644 index 7ab40a9..0000000 --- a/src/address-book/create_addressbook.ts +++ /dev/null @@ -1,19 +0,0 @@ -import axios from "axios"; -import Apis from "../utils/api-config"; -import {addressbookMessageSchema} from "../types/address-book/index"; -import { getSecretKey } from ".."; - -export const create = async (data: addressbookMessageSchema): Promise => { - const req = await axios({ - url: `${Apis.wAddressBookEndpoint}`, - method: "POST", - headers: { - "secret-key": getSecretKey() - }, - data - }) - - const res = await req.data - - return res.data -} \ No newline at end of file diff --git a/src/address-book/get_circle.ts b/src/address-book/get.ts similarity index 59% rename from src/address-book/get_circle.ts rename to src/address-book/get.ts index b1fd850..3b4bce6 100644 --- a/src/address-book/get_circle.ts +++ b/src/address-book/get.ts @@ -1,14 +1,12 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import { getSecretKey } from ".."; +import { Headers } from "../types"; -export const get = async (owner: string): Promise => { +export const _get = async (owner: string, headers:Headers): Promise => { const req = await axios({ url: `${Apis.wAddressBookEndpoint}?owner=${owner}`, method: "GET", - headers: { - "secret-key": getSecretKey() - } + headers: headers, }) const res = await req.data diff --git a/src/address-book/index.ts b/src/address-book/index.ts index 2f6f0da..c8eda65 100644 --- a/src/address-book/index.ts +++ b/src/address-book/index.ts @@ -1,11 +1,19 @@ -import {get} from './get_circle'; -import {generateMessage} from './addressbook_generate_message'; -import {create} from './create_addressbook'; -import {update} from './update_addressbook'; +import {_get} from './get'; +import {_generateMessage} from './addressbook-generate-message'; +import {_create} from './create-addressbook'; +import {_update} from './update-addressbook'; +import {addressbookMessageSchema, updateAddressbookSchemaType,addressbookSchemaType} from "../types/address-book/index"; +import { Headers } from '../types'; +export default class Addressbook{ + private headers: Headers + + constructor(headers: Headers) { + this.headers = headers + } + + get(owner: string) { + return _get(owner, this.headers) + } + -export default { - get, - generateMessage, - create, - update } diff --git a/src/address-book/update_addressbook.ts b/src/address-book/update-addressbook.ts similarity index 62% rename from src/address-book/update_addressbook.ts rename to src/address-book/update-addressbook.ts index 6174ec6..0b930c8 100644 --- a/src/address-book/update_addressbook.ts +++ b/src/address-book/update-addressbook.ts @@ -1,15 +1,13 @@ import Apis from "../utils/api-config"; import axios from "axios"; import {updateAddressbookSchemaType} from "../types/address-book/index"; -import { getSecretKey } from ".."; +import { Headers } from "../types"; -export const update = async (data: updateAddressbookSchemaType): Promise => { +export const _update = async (data: updateAddressbookSchemaType, headers:Headers): Promise => { const req = await axios({ url: Apis.wAddressBookEndpoint, method: "PATCH", - headers: { - "secret-key": getSecretKey() - }, + headers: headers, data }) From b0abc5118c93a092ec53142abd370344534e9cc1 Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Thu, 26 Oct 2023 18:03:37 +0530 Subject: [PATCH 3/6] Fix: structure changed for request module --- src/address-book/index.ts | 6 +++ .../{create_request.ts => create-request.ts} | 10 ++--- ...enerate_message.ts => generate-message.ts} | 8 ++-- src/request/get.ts | 8 ++-- src/request/index.ts | 38 ++++++++++++++----- .../{update_request.ts => update-request.ts} | 8 ++-- src/types/request/index.ts | 1 - 7 files changed, 47 insertions(+), 32 deletions(-) rename src/request/{create_request.ts => create-request.ts} (52%) rename src/request/{generate_message.ts => generate-message.ts} (62%) rename src/request/{update_request.ts => update-request.ts} (64%) diff --git a/src/address-book/index.ts b/src/address-book/index.ts index c8eda65..8139aad 100644 --- a/src/address-book/index.ts +++ b/src/address-book/index.ts @@ -15,5 +15,11 @@ export default class Addressbook{ return _get(owner, this.headers) } + generateMessage(data: addressbookMessageSchema) { + return _generateMessage(data, this.headers) + } + create(data: addressbookSchemaType) { + return _create(data,this.headers) + } } diff --git a/src/request/create_request.ts b/src/request/create-request.ts similarity index 52% rename from src/request/create_request.ts rename to src/request/create-request.ts index bba9b73..4e63dd0 100644 --- a/src/request/create_request.ts +++ b/src/request/create-request.ts @@ -1,15 +1,13 @@ -import { getSecretKey } from ".." -import { Request } from "../types/request" +import { RequestSchema } from "../types/request" import Apis from "../utils/api-config" import axios from "axios" +import { Headers } from "../types" -export const create = async (data: Request): Promise => { +export const _create = async (data: RequestSchema, headers: Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestEndpoint, method: "POST", - headers: { - "secret-key":getSecretKey() - }, + headers: headers, data }) diff --git a/src/request/generate_message.ts b/src/request/generate-message.ts similarity index 62% rename from src/request/generate_message.ts rename to src/request/generate-message.ts index 9243cc5..dd2e1bc 100644 --- a/src/request/generate_message.ts +++ b/src/request/generate-message.ts @@ -1,15 +1,13 @@ import { MessageSchema } from '../types/request/index'; import axios from "axios"; import Apis from "../utils/api-config"; -import { getSecretKey } from ".."; +import { Headers } from '../types'; -export const generateMessage = async (data: MessageSchema): Promise => { +export const _generateMessage = async (data: MessageSchema, headers:Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestGenerateMessageEndpoint, method: "POST", - headers: { - "secret-key": getSecretKey() - }, + headers: headers, data }) diff --git a/src/request/get.ts b/src/request/get.ts index eaffec5..f555753 100644 --- a/src/request/get.ts +++ b/src/request/get.ts @@ -1,14 +1,12 @@ import axios from "axios" import Apis from "../utils/api-config" -import { getSecretKey } from ".." +import { Headers } from "../types" -export const get = async (id: string): Promise => { +export const _get = async (id: string, headers:Headers): Promise => { const req = await axios({ url: `${Apis.wPaymentRequestEndpoint}?id=${id}`, method: "GET", - headers: { - "secret-key": getSecretKey() - } + headers: headers, }) const res = await req.data diff --git a/src/request/index.ts b/src/request/index.ts index a444704..e273358 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -1,11 +1,29 @@ -import { get } from './get' -import { create } from './create_request' -import { generateMessage } from './generate_message' -import { update } from './update_request' - -export default { - get, - create, - generateMessage, - update +import { _get } from './get' +import { _create } from './create-request' +import { _generateMessage } from './generate-message' +import { _update } from './update-request' +import {Headers} from '../types' +import {RequestSchema, MessageSchema, UpdateRequestSchema} from '../types/request/index' +export default class Request { + private headers: Headers + + constructor(headers: Headers) { + this.headers = headers + } + + get(requestId: string) { + return _get(requestId, this.headers) + } + + create(data: RequestSchema) { + return _create(data, this.headers) + } + + generateMessage(data: MessageSchema) { + return _generateMessage(data, this.headers) + } + + update(data: UpdateRequestSchema) { + return _update(data, this.headers) + } } diff --git a/src/request/update_request.ts b/src/request/update-request.ts similarity index 64% rename from src/request/update_request.ts rename to src/request/update-request.ts index c25aa86..11aab3c 100644 --- a/src/request/update_request.ts +++ b/src/request/update-request.ts @@ -1,18 +1,16 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import { getSecretKey } from ".."; import { UpdateRequestSchema } from "../types/request"; +import { Headers } from "../types"; -export const update = async (body: UpdateRequestSchema): Promise => { +export const _update = async (body: UpdateRequestSchema, headers: Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestEndpoint, method: "PATCH", params: { body }, - headers: { - "secret-key": getSecretKey() - } + headers:headers }) const res = await req.data diff --git a/src/types/request/index.ts b/src/types/request/index.ts index 2ab64ef..92499d1 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -56,7 +56,6 @@ export const MessageSchema = z.object({ label: z.string(), }) -export type Request = z.infer export type RequestSchema = z.input export type Actions = z.input export type UpdateRequestSchema = z.input From bf82590875076cc036f477a617956ae3242ba855 Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Thu, 26 Oct 2023 18:08:00 +0530 Subject: [PATCH 4/6] Fix: renaming files --- src/address-book/{create-addressbook.ts => create.ts} | 0 .../{addressbook-generate-message.ts => generate-message.ts} | 0 src/address-book/{update-addressbook.ts => update.ts} | 0 src/identity/{create-identity.ts => create.ts} | 0 .../{generate-identity-message.ts => generate-message.ts} | 0 src/request/{create-request.ts => create.ts} | 0 src/request/{update-request.ts => update.ts} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename src/address-book/{create-addressbook.ts => create.ts} (100%) rename src/address-book/{addressbook-generate-message.ts => generate-message.ts} (100%) rename src/address-book/{update-addressbook.ts => update.ts} (100%) rename src/identity/{create-identity.ts => create.ts} (100%) rename src/identity/{generate-identity-message.ts => generate-message.ts} (100%) rename src/request/{create-request.ts => create.ts} (100%) rename src/request/{update-request.ts => update.ts} (100%) diff --git a/src/address-book/create-addressbook.ts b/src/address-book/create.ts similarity index 100% rename from src/address-book/create-addressbook.ts rename to src/address-book/create.ts diff --git a/src/address-book/addressbook-generate-message.ts b/src/address-book/generate-message.ts similarity index 100% rename from src/address-book/addressbook-generate-message.ts rename to src/address-book/generate-message.ts diff --git a/src/address-book/update-addressbook.ts b/src/address-book/update.ts similarity index 100% rename from src/address-book/update-addressbook.ts rename to src/address-book/update.ts diff --git a/src/identity/create-identity.ts b/src/identity/create.ts similarity index 100% rename from src/identity/create-identity.ts rename to src/identity/create.ts diff --git a/src/identity/generate-identity-message.ts b/src/identity/generate-message.ts similarity index 100% rename from src/identity/generate-identity-message.ts rename to src/identity/generate-message.ts diff --git a/src/request/create-request.ts b/src/request/create.ts similarity index 100% rename from src/request/create-request.ts rename to src/request/create.ts diff --git a/src/request/update-request.ts b/src/request/update.ts similarity index 100% rename from src/request/update-request.ts rename to src/request/update.ts From 38b2f633169701ad6aa1dd0e9e26be4c51e5ccf5 Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Thu, 26 Oct 2023 18:17:43 +0530 Subject: [PATCH 5/6] Fix: types schema naming convention --- src/address-book/create.ts | 4 ++-- src/address-book/generate-message.ts | 4 ++-- src/address-book/index.ts | 16 ++++++++++------ src/address-book/update.ts | 4 ++-- src/auth/index.ts | 4 ++-- src/auth/login.ts | 4 ++-- src/identity/generate-message.ts | 4 ++-- src/identity/index.ts | 10 +++++----- src/request/create.ts | 4 ++-- src/request/generate-message.ts | 4 ++-- src/request/index.ts | 12 ++++++------ src/request/update.ts | 4 ++-- src/types/address-book/index.ts | 6 +++--- src/types/auth/index.ts | 2 +- src/types/identity/index.ts | 4 ++-- src/types/request/index.ts | 6 +++--- 16 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/address-book/create.ts b/src/address-book/create.ts index 493541f..c496ad5 100644 --- a/src/address-book/create.ts +++ b/src/address-book/create.ts @@ -1,9 +1,9 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import {addressbookSchemaType} from "../types/address-book/index"; +import {AddressBook} from "../types/address-book/index"; import { Headers } from "../types"; -export const _create = async (data: addressbookSchemaType, headers:Headers): Promise => { +export const _create = async (data: AddressBook, headers:Headers): Promise => { const req = await axios({ url: `${Apis.wAddressBookEndpoint}`, method: "POST", diff --git a/src/address-book/generate-message.ts b/src/address-book/generate-message.ts index e21ac27..537a950 100644 --- a/src/address-book/generate-message.ts +++ b/src/address-book/generate-message.ts @@ -1,9 +1,9 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import {addressbookMessageSchema} from "../types/address-book/index"; +import {AddressbookMessage} from "../types/address-book/index"; import { Headers } from "../types"; -export const _generateMessage = async (data: addressbookMessageSchema, headers: Headers): Promise => { +export const _generateMessage = async (data: AddressbookMessage, headers: Headers): Promise => { const req = await axios({ url: `${Apis.wAddressBookGenerateMessageEndpoint}`, method: "POST", diff --git a/src/address-book/index.ts b/src/address-book/index.ts index 8139aad..d8c5acd 100644 --- a/src/address-book/index.ts +++ b/src/address-book/index.ts @@ -1,8 +1,8 @@ import {_get} from './get'; -import {_generateMessage} from './addressbook-generate-message'; -import {_create} from './create-addressbook'; -import {_update} from './update-addressbook'; -import {addressbookMessageSchema, updateAddressbookSchemaType,addressbookSchemaType} from "../types/address-book/index"; +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{ private headers: Headers @@ -15,11 +15,15 @@ export default class Addressbook{ return _get(owner, this.headers) } - generateMessage(data: addressbookMessageSchema) { + generateMessage(data: AddressbookMessage) { return _generateMessage(data, this.headers) } - create(data: addressbookSchemaType) { + create(data: AddressBook) { return _create(data,this.headers) } + + update(data: UpdateAddressbook) { + return _update(data, this.headers) + } } diff --git a/src/address-book/update.ts b/src/address-book/update.ts index 0b930c8..211446d 100644 --- a/src/address-book/update.ts +++ b/src/address-book/update.ts @@ -1,9 +1,9 @@ import Apis from "../utils/api-config"; import axios from "axios"; -import {updateAddressbookSchemaType} from "../types/address-book/index"; +import {UpdateAddressbook} from "../types/address-book/index"; import { Headers } from "../types"; -export const _update = async (data: updateAddressbookSchemaType, headers:Headers): Promise => { +export const _update = async (data: UpdateAddressbook, headers:Headers): Promise => { const req = await axios({ url: Apis.wAddressBookEndpoint, method: "PATCH", diff --git a/src/auth/index.ts b/src/auth/index.ts index 3a3263d..c4a3695 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -1,6 +1,6 @@ import { _login } from "./login"; import { _generateMessage } from "./login-message"; -import { AuthSchema, Headers } from "../types"; +import { Authentication, Headers } from "../types"; export default class Auth { private headers: Headers @@ -9,7 +9,7 @@ export default class Auth { this.headers = headers } - login(actions: AuthSchema) { + login(actions: Authentication) { return _login(actions,this.headers) } diff --git a/src/auth/login.ts b/src/auth/login.ts index 6d38a5b..6415b00 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -1,9 +1,9 @@ import Apis from "../utils/api-config"; import axios from "axios"; -import { AuthSchema, } from "../types/auth"; +import { Authentication } from "../types/auth"; import { Headers } from "../types"; -export const _login = async (auth: AuthSchema,headers:Headers): Promise => { +export const _login = async (auth: Authentication,headers:Headers): Promise => { const req = await axios({ url: Apis.wAuthenticationEndpoint, method: 'POST', diff --git a/src/identity/generate-message.ts b/src/identity/generate-message.ts index 4fc9a22..b742451 100644 --- a/src/identity/generate-message.ts +++ b/src/identity/generate-message.ts @@ -1,9 +1,9 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import { generateIdentityMessageSchema } from "../types/identity"; +import { GenerateIdentityMessage } from "../types/identity"; import { Headers } from "../types"; -export const _generateMessage = async (data: generateIdentityMessageSchema, headers: Headers): Promise => { +export const _generateMessage = async (data: GenerateIdentityMessage, headers: Headers): Promise => { const req = await axios({ url: Apis.wIdentityGenerateMessageEndpoint, diff --git a/src/identity/index.ts b/src/identity/index.ts index 357734e..6065124 100644 --- a/src/identity/index.ts +++ b/src/identity/index.ts @@ -1,8 +1,8 @@ import {_get} from "./get"; -import {_generateMessage} from "./generate-identity-message"; -import {_create} from "./create-identity"; +import {_generateMessage} from "./generate-message"; +import {_create} from "./create"; import { Headers } from '../types'; -import {generateIdentityMessageSchema, identitySchema} from "../types/identity"; +import {GenerateIdentityMessage, Identity} from "../types/identity"; export default class identity { private headers: Headers @@ -15,11 +15,11 @@ export default class identity { return _get(id, this.headers) } - generateMessage(data: generateIdentityMessageSchema) { + generateMessage(data: GenerateIdentityMessage) { return _generateMessage(data, this.headers) } - create(data: identitySchema) { + create(data: Identity) { return _create(data,this.headers) } } diff --git a/src/request/create.ts b/src/request/create.ts index 4e63dd0..faf279a 100644 --- a/src/request/create.ts +++ b/src/request/create.ts @@ -1,9 +1,9 @@ -import { RequestSchema } from "../types/request" +import { PaymentRequest } from "../types/request" import Apis from "../utils/api-config" import axios from "axios" import { Headers } from "../types" -export const _create = async (data: RequestSchema, headers: Headers): Promise => { +export const _create = async (data: PaymentRequest, headers: Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestEndpoint, method: "POST", diff --git a/src/request/generate-message.ts b/src/request/generate-message.ts index dd2e1bc..2a6b169 100644 --- a/src/request/generate-message.ts +++ b/src/request/generate-message.ts @@ -1,9 +1,9 @@ -import { MessageSchema } from '../types/request/index'; +import { GenerateMessage } from '../types/request/index'; import axios from "axios"; import Apis from "../utils/api-config"; import { Headers } from '../types'; -export const _generateMessage = async (data: MessageSchema, headers:Headers): Promise => { +export const _generateMessage = async (data: GenerateMessage, headers:Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestGenerateMessageEndpoint, method: "POST", diff --git a/src/request/index.ts b/src/request/index.ts index e273358..40f5cf7 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -1,9 +1,9 @@ import { _get } from './get' -import { _create } from './create-request' +import { _create } from './create' import { _generateMessage } from './generate-message' -import { _update } from './update-request' +import { _update } from './update' import {Headers} from '../types' -import {RequestSchema, MessageSchema, UpdateRequestSchema} from '../types/request/index' +import {PaymentRequest, UpdateRequest, GenerateMessage} from '../types/request/index' export default class Request { private headers: Headers @@ -15,15 +15,15 @@ export default class Request { return _get(requestId, this.headers) } - create(data: RequestSchema) { + create(data: PaymentRequest) { return _create(data, this.headers) } - generateMessage(data: MessageSchema) { + generateMessage(data: GenerateMessage) { return _generateMessage(data, this.headers) } - update(data: UpdateRequestSchema) { + update(data: UpdateRequest) { return _update(data, this.headers) } } diff --git a/src/request/update.ts b/src/request/update.ts index 11aab3c..d00c77d 100644 --- a/src/request/update.ts +++ b/src/request/update.ts @@ -1,9 +1,9 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import { UpdateRequestSchema } from "../types/request"; +import { UpdateRequest } from "../types/request"; import { Headers } from "../types"; -export const _update = async (body: UpdateRequestSchema, headers: Headers): Promise => { +export const _update = async (body: UpdateRequest, headers: Headers): Promise => { const req = await axios({ url: Apis.wPaymentRequestEndpoint, method: "PATCH", diff --git a/src/types/address-book/index.ts b/src/types/address-book/index.ts index dae9604..fcdd753 100644 --- a/src/types/address-book/index.ts +++ b/src/types/address-book/index.ts @@ -37,6 +37,6 @@ export const updateAddressbookSchema = z.object({ signature: z.string(), }); -export type addressbookMessageSchema = z.infer; -export type addressbookSchemaType = z.infer; -export type updateAddressbookSchemaType = z.infer; \ No newline at end of file +export type AddressbookMessage = z.infer; +export type AddressBook = z.infer; +export type UpdateAddressbook = z.infer; \ No newline at end of file diff --git a/src/types/auth/index.ts b/src/types/auth/index.ts index 628ddc8..b68c479 100644 --- a/src/types/auth/index.ts +++ b/src/types/auth/index.ts @@ -10,4 +10,4 @@ export const authSchema = z.object({ timestamp: z.number(), }); -export type AuthSchema = z.infer \ No newline at end of file +export type Authentication = z.infer \ No newline at end of file diff --git a/src/types/identity/index.ts b/src/types/identity/index.ts index fc2ac8d..0c16e87 100644 --- a/src/types/identity/index.ts +++ b/src/types/identity/index.ts @@ -27,5 +27,5 @@ export const generateMessage = z.object({ secondary: z.array(addressConfig).optional(), }); -export type generateIdentityMessageSchema = z.infer; -export type identitySchema = z.infer; \ No newline at end of file +export type GenerateIdentityMessage = z.infer; +export type Identity = z.infer; \ No newline at end of file diff --git a/src/types/request/index.ts b/src/types/request/index.ts index 92499d1..3cda330 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -56,9 +56,9 @@ export const MessageSchema = z.object({ label: z.string(), }) -export type RequestSchema = z.input +export type PaymentRequest = z.input export type Actions = z.input -export type UpdateRequestSchema = z.input -export type MessageSchema = z.input +export type UpdateRequest = z.input +export type GenerateMessage = z.input export * from "./request-intent-types" \ No newline at end of file From 961b16c402c838ebd60ce95b43c91880a4eddfd6 Mon Sep 17 00:00:00 2001 From: Rahul Kulkarni Date: Sat, 28 Oct 2023 13:54:47 +0530 Subject: [PATCH 6/6] Feat: initializer added for modules --- src/identity/create.ts | 4 ++-- src/identity/index.ts | 6 +++--- src/index.ts | 15 +++++++++------ src/types/identity/index.ts | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/identity/create.ts b/src/identity/create.ts index 648e77d..bc440ad 100644 --- a/src/identity/create.ts +++ b/src/identity/create.ts @@ -1,9 +1,9 @@ import axios from "axios"; import Apis from "../utils/api-config"; -import {identitySchema} from "../types/identity"; +import {IdentityIntent} from "../types/identity"; import { Headers } from "../types"; -export const _create = async (data: identitySchema, headers:Headers): Promise => { +export const _create = async (data: IdentityIntent, headers:Headers): Promise => { const req = await axios({ url: Apis.wGetIdentityEndpoint, method: "POST", diff --git a/src/identity/index.ts b/src/identity/index.ts index 6065124..58bd6cc 100644 --- a/src/identity/index.ts +++ b/src/identity/index.ts @@ -2,8 +2,8 @@ import {_get} from "./get"; import {_generateMessage} from "./generate-message"; import {_create} from "./create"; import { Headers } from '../types'; -import {GenerateIdentityMessage, Identity} from "../types/identity"; -export default class identity { +import {GenerateIdentityMessage, IdentityIntent} from "../types/identity"; +export default class Identity { private headers: Headers @@ -19,7 +19,7 @@ export default class identity { return _generateMessage(data, this.headers) } - create(data: Identity) { + create(data: IdentityIntent) { return _create(data,this.headers) } } diff --git a/src/index.ts b/src/index.ts index 9353469..046173c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ -import request from "./request"; -import identity from "./identity"; +import Request from "./request"; import Payments from "./payments"; -import addressBook from "./address-book"; +import Addressbook from "./address-book"; import { Headers, headersSchema } from "./types"; +import Identity from "./identity"; export default class Fetcch { secretKey: string; - request = request; - identity = identity; + request: Request; + identity: Identity; payments: Payments; - addressBook = addressBook; + addressBook: Addressbook; private headers: Headers @@ -23,5 +23,8 @@ export default class Fetcch { }) this.payments = new Payments(this.headers) + this.addressBook = new Addressbook(this.headers) + this.request = new Request(this.headers) + this.identity = new Identity(this.headers) } } \ No newline at end of file diff --git a/src/types/identity/index.ts b/src/types/identity/index.ts index 0c16e87..1fc624f 100644 --- a/src/types/identity/index.ts +++ b/src/types/identity/index.ts @@ -28,4 +28,4 @@ export const generateMessage = z.object({ }); export type GenerateIdentityMessage = z.infer; -export type Identity = z.infer; \ No newline at end of file +export type IdentityIntent = z.infer; \ No newline at end of file