@morambacrypto/connect 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,40 @@ const response = await client.auth.createJwtToken({ userid: "test@gmail.com" });
35
35
  console.log(response.data.token);
36
36
  ```
37
37
 
38
+ ### Creating a Company
39
+
40
+ ``` javascript
41
+ import { MorambaClient } from "@morambacrypto/connect";
42
+
43
+ const client = new MorambaClient({
44
+ baseURL: "https://crypto.moramba.io",
45
+ apiKey: process.env.API_KEY!,
46
+ partnerId: process.env.PARTNER_ID!,
47
+ });
48
+
49
+ // STEP 1 — Get JWT token
50
+ const jwt = await client.auth.createJwtToken({ userid: "admin@moramba.xyz" });
51
+ const token = jwt.data.token;
52
+
53
+ // STEP 2 — Create company
54
+ const company = await client.company.createCompany(
55
+ {
56
+ payment_method: {
57
+ network: "monad",
58
+ token: "moramba",
59
+ address: "0x62F6c82114809C00a1293be02A43C05a3F917202"
60
+ },
61
+ name: "Aeropres",
62
+ email: "admin@moramba.xyz",
63
+ },
64
+ token
65
+ );
66
+
67
+ console.log(company);
68
+
69
+
70
+ ```
71
+
38
72
  ## API Reference
39
73
 
40
74
  ### MorambaClient
@@ -1,4 +1,5 @@
1
1
  import { AuthAPI } from "./apis/auth.api";
2
+ import { CompanyAPI } from "./apis/company.api";
2
3
  export interface MorambaClientConfig {
3
4
  baseURL: string;
4
5
  apiKey: string;
@@ -7,5 +8,6 @@ export interface MorambaClientConfig {
7
8
  export declare class MorambaClient {
8
9
  auth: AuthAPI;
9
10
  private http;
11
+ company: CompanyAPI;
10
12
  constructor(config: MorambaClientConfig);
11
13
  }
@@ -1,10 +1,12 @@
1
1
  import { HttpClient } from "./client/HttpClient";
2
2
  import { AuthAPI } from "./apis/auth.api";
3
+ import { CompanyAPI } from "./apis/company.api";
3
4
  export class MorambaClient {
4
5
  constructor(config) {
5
6
  this.http = new HttpClient(config.baseURL, {
6
7
  "Content-Type": "application/json",
7
8
  });
8
9
  this.auth = new AuthAPI(this.http, config.partnerId, config.apiKey);
10
+ this.company = new CompanyAPI(this.http, config.partnerId, config.apiKey);
9
11
  }
10
12
  }
@@ -0,0 +1,9 @@
1
+ import { HttpClient } from "../client/HttpClient";
2
+ import { CreateCompanyPayload, CreateCompanyResponse } from "../types/company.types";
3
+ export declare class CompanyAPI {
4
+ private http;
5
+ private partnerId;
6
+ private apiKey;
7
+ constructor(http: HttpClient, partnerId: string, apiKey: string);
8
+ createCompany(payload: CreateCompanyPayload, jwtToken: string): Promise<CreateCompanyResponse>;
9
+ }
@@ -0,0 +1,17 @@
1
+ export class CompanyAPI {
2
+ constructor(http, partnerId, apiKey) {
3
+ this.http = http;
4
+ this.partnerId = partnerId;
5
+ this.apiKey = apiKey;
6
+ }
7
+ createCompany(payload, jwtToken) {
8
+ const fullBody = {
9
+ ...payload,
10
+ partner_id: this.partnerId,
11
+ api_key: this.apiKey,
12
+ };
13
+ return this.http.post("/api/v1/morambacypto/create/company", fullBody, {
14
+ Authorization: `Bearer ${jwtToken}`,
15
+ });
16
+ }
17
+ }
@@ -1,8 +1,12 @@
1
1
  import { AxiosInstance } from "axios";
2
2
  export declare class HttpClient {
3
3
  private client;
4
- constructor(baseURL: string, headers?: Record<string, string>);
4
+ private maxRetries;
5
+ private retryDelay;
6
+ constructor(baseURL: string, headers?: Record<string, string>, maxRetries?: number, // default: 4 retries
7
+ retryDelay?: number);
5
8
  get axiosInstance(): AxiosInstance;
6
- post<T = any>(url: string, data: any): Promise<T>;
9
+ private setupRetryInterceptor;
10
+ post<T = any>(url: string, data: any, extraHeaders?: Record<string, string>): Promise<T>;
7
11
  get<T = any>(url: string): Promise<T>;
8
12
  }
@@ -1,17 +1,43 @@
1
1
  import axios from "axios";
2
2
  export class HttpClient {
3
- constructor(baseURL, headers = {}) {
3
+ constructor(baseURL, headers = {}, maxRetries = 4, // default: 4 retries
4
+ retryDelay = 300 // base delay: 300ms
5
+ ) {
4
6
  this.client = axios.create({
5
7
  baseURL,
6
8
  headers,
7
9
  timeout: 10000,
8
10
  });
11
+ this.maxRetries = maxRetries;
12
+ this.retryDelay = retryDelay;
13
+ this.setupRetryInterceptor();
9
14
  }
10
15
  get axiosInstance() {
11
16
  return this.client;
12
17
  }
13
- post(url, data) {
14
- return this.client.post(url, data).then((res) => res.data);
18
+ setupRetryInterceptor() {
19
+ this.client.interceptors.response.use(response => response, async (error) => {
20
+ const config = error.config;
21
+ if (!config)
22
+ throw error;
23
+ // initialize retry counter
24
+ if (!config._retryCount)
25
+ config._retryCount = 0;
26
+ // stop retry if max reached
27
+ if (config._retryCount >= this.maxRetries) {
28
+ throw error;
29
+ }
30
+ config._retryCount++;
31
+ // exponential delay: delay * 2^(retryCount)
32
+ const delay = this.retryDelay * Math.pow(2, config._retryCount);
33
+ await new Promise(resolve => setTimeout(resolve, delay));
34
+ return this.client(config);
35
+ });
36
+ }
37
+ post(url, data, extraHeaders = {}) {
38
+ return this.client
39
+ .post(url, data, { headers: extraHeaders })
40
+ .then((res) => res.data);
15
41
  }
16
42
  get(url) {
17
43
  return this.client.get(url).then((res) => res.data);
@@ -0,0 +1,23 @@
1
+ export interface PaymentMethod {
2
+ network: string;
3
+ token: string;
4
+ address: string;
5
+ }
6
+ export interface CreateCompanyPayload {
7
+ payment_method: PaymentMethod;
8
+ name: string;
9
+ email: string;
10
+ }
11
+ export interface CompanyData {
12
+ id: string;
13
+ name: string;
14
+ email: string;
15
+ partner_id: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ }
19
+ export interface CreateCompanyResponse {
20
+ success: boolean;
21
+ message: string;
22
+ data: CompanyData | null;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morambacrypto/connect",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "This library use for interact with moramba-crypto project",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",