paj_ramp 1.2.2 → 1.2.4

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.
@@ -1,9 +1,28 @@
1
1
  import { get } from "../../utils/api.js";
2
2
 
3
- type RateType = {
4
- baseCurrency: string;
5
- targetCurrency: string;
6
- rate: number;
3
+ type AllRateResponseType = {
4
+ onRampRate: {
5
+ baseCurrency: "USD";
6
+ targetCurrency: "NGN";
7
+ isActive: true;
8
+ rate: 1510;
9
+ type: "onRamp";
10
+ };
11
+ offRampRate: {
12
+ baseCurrency: "USD";
13
+ targetCurrency: "NGN";
14
+ isActive: true;
15
+ rate: 1525;
16
+ type: "offRamp";
17
+ };
18
+ };
19
+
20
+ type RateByAmountType = {
21
+ rate: {
22
+ baseCurrency: string;
23
+ targetCurrency: string;
24
+ rate: number;
25
+ };
7
26
  amounts: {
8
27
  userTax: number;
9
28
  merchantTax: number;
@@ -12,24 +31,113 @@ type RateType = {
12
31
  };
13
32
  };
14
33
 
34
+ type RateByRateTypeType = {
35
+ baseCurrency: "USD";
36
+ targetCurrency: "NGN";
37
+ isActive: true;
38
+ rate: 1525;
39
+ type: "offRamp";
40
+ };
41
+
42
+ export enum RateType {
43
+ onRamp = "onRamp",
44
+ offRamp = "offRamp",
45
+ }
46
+
47
+ /**
48
+ * Fetches rate information based on the provided parameter, which can be a number or a rate type.
49
+ * This function returns all rates, rates by amount, or rates by type depending on the input.
50
+ *
51
+ * Args:
52
+ * param: A number representing the amount or a RateType enum value.
53
+ *
54
+ * Returns:
55
+ * A promise resolving to the rate information relevant to the input parameter.
56
+ *
57
+ * Raises:
58
+ * Throws an error if the rate information cannot be fetched.
59
+ */
60
+ export const getRate = async (param: number | RateType) => {
61
+ try {
62
+ const url = "/pub/rate";
63
+
64
+ if (!param) {
65
+ return getAllRate(url);
66
+ } else if (typeof param === "number") {
67
+ return getRateByAmount(url, param);
68
+ } else {
69
+ return getRateByRateType(url, param);
70
+ }
71
+ } catch (err) {
72
+ console.error("Error fetching Rate:", err);
73
+ throw err;
74
+ }
75
+ };
76
+
15
77
  /**
16
- * Fetches the exchange rate and related amounts for a given amount from the public API.
17
- * Returns an object containing currency information, rate, and detailed amounts, or throws an error if the request fails.
78
+ * Retrieves all available rate information for on-ramp and off-ramp transactions.
79
+ * This function returns a promise that resolves to the complete set of rate data.
18
80
  *
19
81
  * Args:
20
- * amount: The amount for which to fetch the rate. If not provided or falsy, fetches the default rate.
82
+ * url: The endpoint URL to fetch rate information from.
21
83
  *
22
84
  * Returns:
23
- * An object with baseCurrency, targetCurrency, rate, and amounts (userTax, merchantTax, amountUSD, userAmountFiat).
85
+ * A promise resolving to the full rate response data.
24
86
  *
25
87
  * Raises:
26
- * Throws an error if the request fails.
88
+ * Throws an error if the rate information cannot be fetched.
27
89
  */
28
- export const getRate = async (amount: number) => {
90
+ const getAllRate = async (url: string) => {
29
91
  try {
30
- return await get<RateType>(amount ? `/pub/rate/${amount}` : "/pub/rate");
92
+ return await get<AllRateResponseType>(url);
31
93
  } catch (err) {
32
94
  console.error("Error fetching Rate:", err);
33
95
  throw err;
34
96
  }
35
97
  };
98
+
99
+ /**
100
+ * Retrieves rate information based on a specific amount for on-ramp or off-ramp transactions.
101
+ * This function returns a promise that resolves to the rate and associated amounts for the given value.
102
+ *
103
+ * Args:
104
+ * url: The endpoint URL to fetch rate information from.
105
+ * amount: The amount for which the rate information is requested.
106
+ *
107
+ * Returns:
108
+ * A promise resolving to the rate and amount details for the specified value.
109
+ *
110
+ * Raises:
111
+ * Throws an error if the rate information cannot be fetched.
112
+ */
113
+ export const getRateByAmount = async (url: string, amount: number) => {
114
+ try {
115
+ return await get<RateByAmountType>(`/pub/rate/${amount}`);
116
+ } catch (err) {
117
+ console.error("Error fetching Rate by Amount:", err);
118
+ throw err;
119
+ }
120
+ };
121
+
122
+ /**
123
+ * Retrieves rate information based on a specific rate type for on-ramp or off-ramp transactions.
124
+ * This function returns a promise that resolves to the rate details for the given rate type.
125
+ *
126
+ * Args:
127
+ * url: The endpoint URL to fetch rate information from.
128
+ * rateType: The type of rate to retrieve, specified as a RateType enum value.
129
+ *
130
+ * Returns:
131
+ * A promise resolving to the rate details for the specified rate type.
132
+ *
133
+ * Raises:
134
+ * Throws an error if the rate information cannot be fetched.
135
+ */
136
+ export const getRateByRateType = async (url: string, rateType: RateType) => {
137
+ try {
138
+ return await get<RateByRateTypeType>(`/pub/rate/${rateType}`);
139
+ } catch (err) {
140
+ console.error("Error fetching Rate by Rate Type:", err);
141
+ throw err;
142
+ }
143
+ };
@@ -17,12 +17,12 @@ type InitiateResponse = {
17
17
  * Raises:
18
18
  * Throws an error if the request fails.
19
19
  */
20
- export const initiate = async (email: string) => {
20
+ export const initiate = async (email: string, apiKey: string) => {
21
21
  try {
22
22
  return await post<InitiateResponse>(
23
23
  "/pub/initiate",
24
24
  { email },
25
- { "x-api-key": "3ada687e-78d1-45f3-933d-c992adcc2bbb" }
25
+ { "x-api-key": apiKey, "Content-Type": "application/json" }
26
26
  );
27
27
  } catch (err) {
28
28
  console.error("Error initiating:", err);
@@ -1,4 +1,4 @@
1
- import { get } from "../../utils/api.js";
1
+ import { get } from '../../utils/api.js';
2
2
 
3
3
  type ResolveBankAccountType = {
4
4
  accountName: string;
@@ -26,15 +26,20 @@ type ResolveBankAccountType = {
26
26
  * Throws an error if the request fails.
27
27
  */
28
28
  export const resolveBankAccount = async (
29
+ token: string,
29
30
  bankId: string,
30
31
  accountNumber: string
31
32
  ) => {
32
33
  try {
33
34
  return await get<ResolveBankAccountType>(
34
- `/pub/bankaccount/resolve/?bankId=${bankId}&accountNumber=${accountNumber}`
35
+ `/pub/bank-account/confirm/?bankId=${bankId}&accountNumber=${accountNumber}`,
36
+ {},
37
+ {
38
+ Authorization: `Bearer ${token}`,
39
+ }
35
40
  );
36
41
  } catch (err) {
37
- console.error("Error resolving bank account:", err);
42
+ console.error('Error resolving bank account:', err);
38
43
  throw err;
39
44
  }
40
45
  };
@@ -1,5 +1,20 @@
1
1
  import { post } from "../../utils/api.js";
2
2
 
3
+ type VerifyType = {
4
+ email: string;
5
+ isActive: string;
6
+ expiresAt: string;
7
+ token: string;
8
+ };
9
+
10
+ type deviceSignatureType = {
11
+ uuid: string;
12
+ device: string;
13
+ os?: string;
14
+ browser?: string;
15
+ ip?: string;
16
+ };
17
+
3
18
  /**
4
19
  * Verifies a user's identity using email, OTP, and device signature via the public API.
5
20
  * Returns verification details including email, activation status, expiration, and token, or throws an error if the request fails.
@@ -15,21 +30,22 @@ import { post } from "../../utils/api.js";
15
30
  * Raises:
16
31
  * Throws an error if the request fails.
17
32
  */
33
+
18
34
  export const verify = async (
19
35
  email: string,
20
36
  otp: string,
21
- deviceSignature: string
37
+ deviceSignature: deviceSignatureType,
38
+ apiKey: string
22
39
  ) => {
23
40
  try {
24
- return await post<{
25
- email: string;
26
- isActive: string;
27
- expiresAt: string;
28
- token: string;
29
- }>(
41
+ return await post<VerifyType>(
30
42
  "/pub/verify",
31
- { email, otp, deviceSignature },
32
- { "x-api-key": "3ada687e-78d1-45f3-933d-c992adcc2bbb" }
43
+ {
44
+ email,
45
+ otp,
46
+ device: deviceSignature,
47
+ },
48
+ { "x-api-key": apiKey }
33
49
  );
34
50
  } catch (err) {
35
51
  console.error("Error verifying:", err);
@@ -6,11 +6,12 @@ type CreateOrderType = {
6
6
  recipient: string;
7
7
  mint: string;
8
8
  chain: string;
9
+ webhookURL: string;
9
10
  token?: string;
10
11
  };
11
12
 
12
13
  export const createOrder = async (options: CreateOrderType) => {
13
- const { fiatAmount, currency, recipient, mint, chain, token } = options;
14
+ const { fiatAmount, currency, recipient, mint, chain, webhookURL, token } = options;
14
15
  try {
15
16
  return await post<CreateOrderType>(
16
17
  "/pub/onramp",
@@ -20,6 +21,7 @@ export const createOrder = async (options: CreateOrderType) => {
20
21
  recipient,
21
22
  mint,
22
23
  chain,
24
+ webhookURL
23
25
  },
24
26
  {
25
27
  Authorization: `Bearer ${token}`,
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "paj_ramp",
3
- "version": "1.2.2",
4
- "description": "paj offramp service",
5
- "main": "dist/sdk.js",
6
- "types": "dist/sdk.d.ts",
7
- "type": "module",
8
- "scripts": {
9
- "prelink": "npm run build",
10
- "build": "tsc",
11
- "test": "jest"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/paj-cash/paj_ramp.git"
16
- },
17
- "keywords": [
18
- "PAJ"
19
- ],
20
- "author": "Ebube",
21
- "license": "ISC",
22
- "bugs": {
23
- "url": "https://github.com/paj-cash/paj_ramp/issues"
24
- },
25
- "homepage": "https://github.com/paj-cash/paj_ramp#readme",
26
- "devDependencies": {
27
- "@types/node": "^22.15.24",
28
- "typescript": "^5.8.3"
29
- },
30
- "dependencies": {
31
- "@solana/web3.js": "^1.98.2",
32
- "@types/jest": "^29.5.14",
33
- "axios": "^1.9.0",
34
- "bs58": "^6.0.0",
35
- "dotenv": "^16.5.0",
36
- "jest": "^30.0.0",
37
- "socket.io-client": "^4.8.1",
38
- "ts-jest": "^29.3.4",
39
- "tsx": "4.20.3",
40
- "tweetnacl": "^1.0.3"
41
- }
42
- }
1
+ {
2
+ "name": "paj_ramp",
3
+ "version": "1.2.4",
4
+ "description": "paj offramp/onramp service",
5
+ "main": "dist/sdk.js",
6
+ "types": "dist/sdk.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "prelink": "npm run build",
10
+ "build": "tsc",
11
+ "test": "jest"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/paj-cash/paj_ramp.git"
16
+ },
17
+ "keywords": [
18
+ "PAJ"
19
+ ],
20
+ "author": "Ebube",
21
+ "license": "ISC",
22
+ "bugs": {
23
+ "url": "https://github.com/paj-cash/paj_ramp/issues"
24
+ },
25
+ "homepage": "https://github.com/paj-cash/paj_ramp#readme",
26
+ "devDependencies": {
27
+ "@types/node": "^22.15.24",
28
+ "typescript": "^5.8.3"
29
+ },
30
+ "dependencies": {
31
+ "@solana/web3.js": "^1.98.2",
32
+ "@types/jest": "^29.5.14",
33
+ "axios": "^1.9.0",
34
+ "bs58": "^6.0.0",
35
+ "dotenv": "^16.5.0",
36
+ "jest": "^30.0.0",
37
+ "socket.io-client": "^4.8.1",
38
+ "ts-jest": "^29.3.4",
39
+ "tsx": "4.20.3",
40
+ "tweetnacl": "^1.0.3"
41
+ }
42
+ }
package/sdk.ts CHANGED
@@ -1,41 +1,44 @@
1
1
  // A JavaScript SDK for interacting with our offramp and onramp service.
2
2
 
3
3
  // Switch Environment: "staging" | "production"
4
- import { setBaseUrl } from "./utils/axios.js";
4
+ import { setBaseUrl } from './utils/axios.js';
5
5
 
6
- export const initializeSDK = (env: "staging" | "production") => {
7
- if (env === "staging") {
8
- setBaseUrl("https://api-staging.paj.cash");
6
+ export const initializeSDK = (env: 'staging' | 'production') => {
7
+ if (env === 'staging') {
8
+ setBaseUrl('https://api-staging.paj.cash');
9
9
  } else {
10
- setBaseUrl("https://api.paj.cash");
10
+ setBaseUrl('https://api.paj.cash');
11
11
  }
12
12
  };
13
13
 
14
14
  // OFF RAMP
15
15
 
16
16
  // Wallet Info
17
- export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
18
- export { getRate } from "./lib/off_ramp/getRate.js";
17
+ // export { getTXPoolAddress } from "./lib/off_ramp/getTXPoolAddress.js";
18
+ export { getRate, RateType } from './lib/off_ramp/getRate.js';
19
19
 
20
20
  // Session Management
21
- export { initiate } from "./lib/off_ramp/initiate.js";
22
- export { verify } from "./lib/off_ramp/verify.js";
21
+ export { initiate } from './lib/off_ramp/initiate.js';
22
+ export { verify } from './lib/off_ramp/verify.js';
23
23
 
24
- // Banking Operations
24
+ // // Banking Operations
25
25
  export { getBanks } from "./lib/off_ramp/getBanks.js";
26
26
  export { resolveBankAccount } from "./lib/off_ramp/resolveBankAccount.js";
27
27
  export { addBankAccount } from "./lib/off_ramp/addBankAccount.js";
28
28
  export { getBankAccounts } from "./lib/off_ramp/getBankAccounts.js";
29
29
 
30
30
  // Wallet Operations
31
- export { getWallet } from "./lib/off_ramp/getWallet.js";
32
- export { addWallet } from "./lib/off_ramp/addWallet.js";
33
- export { switchWalletBankAccount } from "./lib/off_ramp/switchWalletBankAccount.js";
31
+ // export { getWallet } from './lib/off_ramp/getWallet.js';
32
+ // export { addWallet } from './lib/off_ramp/addWallet.js';
33
+ // export { switchWalletBankAccount } from './lib/off_ramp/switchWalletBankAccount.js';
34
+
35
+ // DIRECT OFF RAMP
36
+ export { offRampCreateOrder } from './lib/direct_off_ramp/directCreateOrder.js';
34
37
 
35
38
  // ON RAMP
36
39
 
37
40
  // Create Order
38
- export { createOrder } from "./lib/on_ramp/createOrder.js";
41
+ export { createOrder } from './lib/on_ramp/createOrder.js';
39
42
 
40
43
  // Observe Order Socket.IO
41
- export { observeOrder } from "./lib/on_ramp/observeOrder.js";
44
+ export { observeOrder } from './lib/on_ramp/observeOrder.js';
@@ -0,0 +1,41 @@
1
+ import axios from "axios";
2
+
3
+ // Test both HTTP and HTTPS to see which one works
4
+ async function testProtocols() {
5
+ const urls = [
6
+ "https://api-staging.paj.cash",
7
+ "http://api-staging.paj.cash",
8
+ "https://api.paj.cash",
9
+ "http://api.paj.cash"
10
+ ];
11
+
12
+ for (const url of urls) {
13
+ try {
14
+ console.log(`\nšŸ” Testing: ${url}`);
15
+
16
+ const response = await axios.get(`${url}/pub/rate`, {
17
+ timeout: 5000,
18
+ validateStatus: () => true // Don't throw on any status code
19
+ });
20
+
21
+ console.log(`āœ… SUCCESS: ${url}`);
22
+ console.log(` Status: ${response.status}`);
23
+ console.log(` Protocol: ${url.startsWith('https') ? 'HTTPS' : 'HTTP'}`);
24
+
25
+ } catch (error) {
26
+ console.log(`āŒ FAILED: ${url}`);
27
+ console.log(` Error: ${error.message}`);
28
+
29
+ if (error.code === 'ECONNREFUSED') {
30
+ console.log(` Reason: Connection refused (server not running or wrong port)`);
31
+ } else if (error.message.includes('wrong version number')) {
32
+ console.log(` Reason: Protocol mismatch (HTTPS client to HTTP server)`);
33
+ } else if (error.message.includes('ENOTFOUND')) {
34
+ console.log(` Reason: Domain not found`);
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ console.log("šŸš€ Testing PAJ API protocols...");
41
+ testProtocols().catch(console.error);