@rift-finance/wallet 0.0.2
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 +1345 -0
- package/dist/base-service.d.ts +28 -0
- package/dist/base-service.d.ts.map +1 -0
- package/dist/base-service.js +49 -0
- package/dist/base-service.js.map +1 -0
- package/dist/http-client.d.ts +15 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +166 -0
- package/dist/http-client.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +130 -0
- package/dist/index.js.map +1 -0
- package/dist/mpesa-http-client.d.ts +14 -0
- package/dist/mpesa-http-client.d.ts.map +1 -0
- package/dist/mpesa-http-client.js +156 -0
- package/dist/mpesa-http-client.js.map +1 -0
- package/dist/services/assets.d.ts +31 -0
- package/dist/services/assets.d.ts.map +1 -0
- package/dist/services/assets.js +75 -0
- package/dist/services/assets.js.map +1 -0
- package/dist/services/auth.d.ts +23 -0
- package/dist/services/auth.d.ts.map +1 -0
- package/dist/services/auth.js +131 -0
- package/dist/services/auth.js.map +1 -0
- package/dist/services/defi.d.ts +6 -0
- package/dist/services/defi.d.ts.map +1 -0
- package/dist/services/defi.js +15 -0
- package/dist/services/defi.js.map +1 -0
- package/dist/services/notifications.d.ts +39 -0
- package/dist/services/notifications.d.ts.map +1 -0
- package/dist/services/notifications.js +79 -0
- package/dist/services/notifications.js.map +1 -0
- package/dist/services/onramp.d.ts +43 -0
- package/dist/services/onramp.d.ts.map +1 -0
- package/dist/services/onramp.js +109 -0
- package/dist/services/onramp.js.map +1 -0
- package/dist/services/payment-links.d.ts +24 -0
- package/dist/services/payment-links.d.ts.map +1 -0
- package/dist/services/payment-links.js +121 -0
- package/dist/services/payment-links.js.map +1 -0
- package/dist/services/signer.d.ts +25 -0
- package/dist/services/signer.d.ts.map +1 -0
- package/dist/services/signer.js +52 -0
- package/dist/services/signer.js.map +1 -0
- package/dist/services/transactions.d.ts +8 -0
- package/dist/services/transactions.d.ts.map +1 -0
- package/dist/services/transactions.js +29 -0
- package/dist/services/transactions.js.map +1 -0
- package/dist/services/wallet.d.ts +7 -0
- package/dist/services/wallet.d.ts.map +1 -0
- package/dist/services/wallet.js +28 -0
- package/dist/services/wallet.js.map +1 -0
- package/dist/types.d.ts +1069 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RiftHttpClient } from "./http-client";
|
|
2
|
+
import { RequestConfig } from "./types";
|
|
3
|
+
export declare abstract class BaseService {
|
|
4
|
+
protected httpClient: RiftHttpClient;
|
|
5
|
+
private bearerToken?;
|
|
6
|
+
constructor(httpClient: RiftHttpClient);
|
|
7
|
+
/**
|
|
8
|
+
* Set the bearer token for user authentication
|
|
9
|
+
*/
|
|
10
|
+
setBearerToken(token: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Clear the bearer token
|
|
13
|
+
*/
|
|
14
|
+
clearBearerToken(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Get the current bearer token
|
|
17
|
+
*/
|
|
18
|
+
getBearerToken(): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Make an authenticated request with bearer token
|
|
21
|
+
*/
|
|
22
|
+
protected authenticatedRequest<T>(config: RequestConfig): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Make a public request (no authentication required)
|
|
25
|
+
*/
|
|
26
|
+
protected publicRequest<T>(config: RequestConfig): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=base-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-service.d.ts","sourceRoot":"","sources":["../src/base-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,8BAAsB,WAAW;IAC7B,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC;IACvC,OAAO,CAAC,WAAW,CAAC,CAAS;gBAEjB,UAAU,EAAE,cAAc;IAItC;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAInC;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAIxB;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,SAAS;IAIpC;;OAEG;cACa,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAa1E;;OAEG;cACa,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;CAGpE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseService = void 0;
|
|
4
|
+
class BaseService {
|
|
5
|
+
httpClient;
|
|
6
|
+
bearerToken;
|
|
7
|
+
constructor(httpClient) {
|
|
8
|
+
this.httpClient = httpClient;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Set the bearer token for user authentication
|
|
12
|
+
*/
|
|
13
|
+
setBearerToken(token) {
|
|
14
|
+
this.bearerToken = token;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Clear the bearer token
|
|
18
|
+
*/
|
|
19
|
+
clearBearerToken() {
|
|
20
|
+
this.bearerToken = undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the current bearer token
|
|
24
|
+
*/
|
|
25
|
+
getBearerToken() {
|
|
26
|
+
return this.bearerToken;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Make an authenticated request with bearer token
|
|
30
|
+
*/
|
|
31
|
+
async authenticatedRequest(config) {
|
|
32
|
+
const headers = { ...config.headers };
|
|
33
|
+
if (this.bearerToken) {
|
|
34
|
+
headers.Authorization = `Bearer ${this.bearerToken}`;
|
|
35
|
+
}
|
|
36
|
+
return this.httpClient.request({
|
|
37
|
+
...config,
|
|
38
|
+
headers,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Make a public request (no authentication required)
|
|
43
|
+
*/
|
|
44
|
+
async publicRequest(config) {
|
|
45
|
+
return this.httpClient.request(config);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.BaseService = BaseService;
|
|
49
|
+
//# sourceMappingURL=base-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-service.js","sourceRoot":"","sources":["../src/base-service.ts"],"names":[],"mappings":";;;AAGA,MAAsB,WAAW;IACnB,UAAU,CAAiB;IAC/B,WAAW,CAAU;IAE7B,YAAY,UAA0B;QACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,KAAa;QAC1B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,oBAAoB,CAAI,MAAqB;QAC3D,MAAM,OAAO,GAAG,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,CAAC,aAAa,GAAG,UAAU,IAAI,CAAC,WAAW,EAAE,CAAC;QACvD,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAI;YAChC,GAAG,MAAM;YACT,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,aAAa,CAAI,MAAqB;QACpD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAI,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AAnDD,kCAmDC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpClient, RequestConfig, RiftConfig } from "./types";
|
|
2
|
+
export declare class RiftHttpClient implements HttpClient {
|
|
3
|
+
private config;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
constructor(config: RiftConfig);
|
|
6
|
+
private getDefaultBaseUrl;
|
|
7
|
+
request<T>(requestConfig: RequestConfig): Promise<T>;
|
|
8
|
+
private executeWithRetry;
|
|
9
|
+
private handleResponse;
|
|
10
|
+
private handleError;
|
|
11
|
+
private delay;
|
|
12
|
+
setApiKey(apiKey: string): void;
|
|
13
|
+
setBearerToken(token: string): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAY,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1E,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,UAAU;IAK9B,OAAO,CAAC,iBAAiB;IAWnB,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;YAyD5C,gBAAgB;YAqChB,cAAc;IAyC5B,OAAO,CAAC,WAAW;IA8BnB,OAAO,CAAC,KAAK;IAKb,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAGpC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RiftHttpClient = void 0;
|
|
4
|
+
class RiftHttpClient {
|
|
5
|
+
config;
|
|
6
|
+
baseUrl;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.baseUrl = config.baseUrl || this.getDefaultBaseUrl();
|
|
10
|
+
}
|
|
11
|
+
getDefaultBaseUrl() {
|
|
12
|
+
switch (this.config.environment) {
|
|
13
|
+
case "production":
|
|
14
|
+
return "https://api.rift.finance";
|
|
15
|
+
case "development":
|
|
16
|
+
return "https://dev.rift.finance";
|
|
17
|
+
default:
|
|
18
|
+
return "https://dev.rift.finance";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async request(requestConfig) {
|
|
22
|
+
const { method, url, data, params, headers = {} } = requestConfig;
|
|
23
|
+
// Build URL with query parameters
|
|
24
|
+
const fullUrl = new URL(url, this.baseUrl);
|
|
25
|
+
if (params) {
|
|
26
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
27
|
+
if (value !== undefined && value !== null) {
|
|
28
|
+
fullUrl.searchParams.append(key, String(value));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Build headers
|
|
33
|
+
const requestHeaders = {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
...headers,
|
|
36
|
+
};
|
|
37
|
+
// Add API key if available
|
|
38
|
+
if (this.config.apiKey) {
|
|
39
|
+
requestHeaders["X-API-Key"] = this.config.apiKey;
|
|
40
|
+
}
|
|
41
|
+
// Build fetch options
|
|
42
|
+
const fetchOptions = {
|
|
43
|
+
method,
|
|
44
|
+
headers: requestHeaders,
|
|
45
|
+
};
|
|
46
|
+
// Add body for POST/PUT requests
|
|
47
|
+
if (data && (method === "POST" || method === "PUT")) {
|
|
48
|
+
fetchOptions.body = JSON.stringify(data);
|
|
49
|
+
}
|
|
50
|
+
// Add timeout
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timeoutId = setTimeout(() => {
|
|
53
|
+
controller.abort();
|
|
54
|
+
}, this.config.timeout || 30000);
|
|
55
|
+
fetchOptions.signal = controller.signal;
|
|
56
|
+
try {
|
|
57
|
+
const response = await this.executeWithRetry(fullUrl.toString(), fetchOptions);
|
|
58
|
+
clearTimeout(timeoutId);
|
|
59
|
+
return await this.handleResponse(response);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
throw this.handleError(error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async executeWithRetry(url, options) {
|
|
67
|
+
const maxRetries = this.config.retries || 3;
|
|
68
|
+
let lastError;
|
|
69
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
70
|
+
try {
|
|
71
|
+
const response = await fetch(url, options);
|
|
72
|
+
// Don't retry on client errors (4xx), only on server errors (5xx) and network errors
|
|
73
|
+
if (response.ok || (response.status >= 400 && response.status < 500)) {
|
|
74
|
+
return response;
|
|
75
|
+
}
|
|
76
|
+
if (attempt === maxRetries) {
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
// Wait before retrying (exponential backoff)
|
|
80
|
+
await this.delay(Math.pow(2, attempt) * 1000);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
lastError = error;
|
|
84
|
+
if (attempt === maxRetries) {
|
|
85
|
+
throw lastError;
|
|
86
|
+
}
|
|
87
|
+
// Wait before retrying
|
|
88
|
+
await this.delay(Math.pow(2, attempt) * 1000);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
throw lastError;
|
|
92
|
+
}
|
|
93
|
+
async handleResponse(response) {
|
|
94
|
+
const contentType = response.headers.get("content-type");
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
97
|
+
let errorDetails = {};
|
|
98
|
+
try {
|
|
99
|
+
if (contentType?.includes("application/json")) {
|
|
100
|
+
errorDetails = await response.json();
|
|
101
|
+
errorMessage =
|
|
102
|
+
errorDetails.message || errorDetails.error || errorMessage;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
errorMessage = (await response.text()) || errorMessage;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// If we can't parse the error response, use the default message
|
|
110
|
+
}
|
|
111
|
+
const apiError = {
|
|
112
|
+
message: errorMessage,
|
|
113
|
+
error: errorDetails.error,
|
|
114
|
+
status: response.status,
|
|
115
|
+
};
|
|
116
|
+
throw apiError;
|
|
117
|
+
}
|
|
118
|
+
// Handle different response types
|
|
119
|
+
if (response.status === 204) {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
if (contentType?.includes("application/json")) {
|
|
123
|
+
return await response.json();
|
|
124
|
+
}
|
|
125
|
+
// For non-JSON responses, return as text
|
|
126
|
+
return (await response.text());
|
|
127
|
+
}
|
|
128
|
+
handleError(error) {
|
|
129
|
+
if (error.name === "AbortError") {
|
|
130
|
+
return {
|
|
131
|
+
message: "Request timeout",
|
|
132
|
+
error: "The request took too long to complete",
|
|
133
|
+
status: 408,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (error.message && error.status) {
|
|
137
|
+
// Already an ApiError
|
|
138
|
+
return error;
|
|
139
|
+
}
|
|
140
|
+
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
141
|
+
return {
|
|
142
|
+
message: "Network error",
|
|
143
|
+
error: "Unable to connect to the server. Please check your internet connection.",
|
|
144
|
+
status: 0,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
message: error.message || "An unexpected error occurred",
|
|
149
|
+
error: error.toString(),
|
|
150
|
+
status: 500,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
delay(ms) {
|
|
154
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
+
}
|
|
156
|
+
// Method to update API key
|
|
157
|
+
setApiKey(apiKey) {
|
|
158
|
+
this.config.apiKey = apiKey;
|
|
159
|
+
}
|
|
160
|
+
// Method to update bearer token for user authentication
|
|
161
|
+
setBearerToken(token) {
|
|
162
|
+
// This will be handled by individual service methods
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.RiftHttpClient = RiftHttpClient;
|
|
166
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IACjB,MAAM,CAAa;IACnB,OAAO,CAAS;IAExB,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC5D,CAAC;IAEO,iBAAiB;QACvB,QAAQ,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAChC,KAAK,YAAY;gBACf,OAAO,0BAA0B,CAAC;YACpC,KAAK,aAAa;gBAChB,OAAO,0BAA0B,CAAC;YACpC;gBACE,OAAO,0BAA0B,CAAC;QACtC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAI,aAA4B;QAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,aAAa,CAAC;QAElE,kCAAkC;QAClC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC9C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBAC1C,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAA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I,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAClC,sBAAsB;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAClE,OAAO;gBACL,OAAO,EAAE,eAAe;gBACxB,KAAK,EACH,yEAAyE;gBAC3E,MAAM,EAAE,CAAC;aACV,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,8BAA8B;YACxD,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;YACvB,MAAM,EAAE,GAAG;SACZ,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,2BAA2B;IAC3B,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IAC9B,CAAC;IAED,wDAAwD;IACxD,cAAc,CAAC,KAAa;QAC1B,qDAAqD;IACvD,CAAC;CACF;AAtMD,wCAsMC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Environment, RiftConfig } from "./types";
|
|
2
|
+
import { AuthService } from "./services/auth";
|
|
3
|
+
import { WalletService } from "./services/wallet";
|
|
4
|
+
import { TransactionService } from "./services/transactions";
|
|
5
|
+
import { PaymentLinksService } from "./services/payment-links";
|
|
6
|
+
import { SignerService } from "./services/signer";
|
|
7
|
+
import { DeFiService } from "./services/defi";
|
|
8
|
+
import { AssetsService } from "./services/assets";
|
|
9
|
+
import { OnrampService } from "./services/onramp";
|
|
10
|
+
import { NotificationService } from "./services/notifications";
|
|
11
|
+
export declare class Rift {
|
|
12
|
+
readonly config: RiftConfig;
|
|
13
|
+
private readonly httpClient;
|
|
14
|
+
readonly auth: AuthService;
|
|
15
|
+
readonly wallet: WalletService;
|
|
16
|
+
readonly transactions: TransactionService;
|
|
17
|
+
readonly paymentLinks: PaymentLinksService;
|
|
18
|
+
readonly signer: SignerService;
|
|
19
|
+
readonly defi: DeFiService;
|
|
20
|
+
readonly assets: AssetsService;
|
|
21
|
+
readonly onramp: OnrampService;
|
|
22
|
+
readonly notifications: NotificationService;
|
|
23
|
+
constructor(config: RiftConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Set the API key for project authentication
|
|
26
|
+
*/
|
|
27
|
+
setApiKey(apiKey: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Set the bearer token for user authentication across all services
|
|
30
|
+
*/
|
|
31
|
+
setBearerToken(token: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Clear the bearer token from all services
|
|
34
|
+
*/
|
|
35
|
+
clearBearerToken(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Set API key specifically for M-Pesa operations
|
|
38
|
+
*/
|
|
39
|
+
setMpesaApiKey(apiKey: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Check if the SDK is configured with an API key
|
|
42
|
+
*/
|
|
43
|
+
hasApiKey(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Check if the user is authenticated
|
|
46
|
+
*/
|
|
47
|
+
isAuthenticated(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get the current environment
|
|
50
|
+
*/
|
|
51
|
+
getEnvironment(): Environment;
|
|
52
|
+
/**
|
|
53
|
+
* Get the base URL being used
|
|
54
|
+
*/
|
|
55
|
+
getBaseUrl(): string;
|
|
56
|
+
}
|
|
57
|
+
export * from "./types";
|
|
58
|
+
export { Environment };
|
|
59
|
+
export { NotificationService } from "./services/notifications";
|
|
60
|
+
export default Rift;
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceR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M,EAAE,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,cAAc,IAAI,WAAW;IAI7B;;OAEG;IACH,UAAU,IAAI,MAAM;CAGrB;AAGD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,CAAC;AAGvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,eAAe,IAAI,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.NotificationService = exports.Environment = exports.Rift = void 0;
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return types_1.Environment; } });
|
|
20
|
+
const http_client_1 = require("./http-client");
|
|
21
|
+
const auth_1 = require("./services/auth");
|
|
22
|
+
const wallet_1 = require("./services/wallet");
|
|
23
|
+
const transactions_1 = require("./services/transactions");
|
|
24
|
+
const payment_links_1 = require("./services/payment-links");
|
|
25
|
+
const signer_1 = require("./services/signer");
|
|
26
|
+
const defi_1 = require("./services/defi");
|
|
27
|
+
const assets_1 = require("./services/assets");
|
|
28
|
+
const onramp_1 = require("./services/onramp");
|
|
29
|
+
const notifications_1 = require("./services/notifications");
|
|
30
|
+
class Rift {
|
|
31
|
+
config;
|
|
32
|
+
httpClient;
|
|
33
|
+
// Service instances
|
|
34
|
+
auth;
|
|
35
|
+
wallet;
|
|
36
|
+
transactions;
|
|
37
|
+
paymentLinks;
|
|
38
|
+
signer;
|
|
39
|
+
defi;
|
|
40
|
+
assets;
|
|
41
|
+
onramp;
|
|
42
|
+
notifications;
|
|
43
|
+
constructor(config) {
|
|
44
|
+
this.config = config;
|
|
45
|
+
this.httpClient = new http_client_1.RiftHttpClient(config);
|
|
46
|
+
// Initialize all services
|
|
47
|
+
this.auth = new auth_1.AuthService(this.httpClient);
|
|
48
|
+
this.wallet = new wallet_1.WalletService(this.httpClient);
|
|
49
|
+
this.transactions = new transactions_1.TransactionService(this.httpClient);
|
|
50
|
+
this.paymentLinks = new payment_links_1.PaymentLinksService(this.httpClient);
|
|
51
|
+
this.signer = new signer_1.SignerService(this.httpClient);
|
|
52
|
+
this.defi = new defi_1.DeFiService(this.httpClient);
|
|
53
|
+
this.assets = new assets_1.AssetsService(this.httpClient);
|
|
54
|
+
this.onramp = new onramp_1.OnrampService(this.httpClient, config);
|
|
55
|
+
this.notifications = new notifications_1.NotificationService(this.httpClient);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set the API key for project authentication
|
|
59
|
+
*/
|
|
60
|
+
setApiKey(apiKey) {
|
|
61
|
+
this.httpClient.setApiKey(apiKey);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set the bearer token for user authentication across all services
|
|
65
|
+
*/
|
|
66
|
+
setBearerToken(token) {
|
|
67
|
+
this.auth.setBearerToken(token);
|
|
68
|
+
this.wallet.setBearerToken(token);
|
|
69
|
+
this.transactions.setBearerToken(token);
|
|
70
|
+
this.paymentLinks.setBearerToken(token);
|
|
71
|
+
this.signer.setBearerToken(token);
|
|
72
|
+
this.defi.setBearerToken(token);
|
|
73
|
+
this.assets.setBearerToken(token);
|
|
74
|
+
this.notifications.setBearerToken(token);
|
|
75
|
+
// Note: onramp doesn't use bearer tokens
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Clear the bearer token from all services
|
|
79
|
+
*/
|
|
80
|
+
clearBearerToken() {
|
|
81
|
+
this.auth.clearBearerToken();
|
|
82
|
+
this.wallet.clearBearerToken();
|
|
83
|
+
this.transactions.clearBearerToken();
|
|
84
|
+
this.paymentLinks.clearBearerToken();
|
|
85
|
+
this.signer.clearBearerToken();
|
|
86
|
+
this.defi.clearBearerToken();
|
|
87
|
+
this.assets.clearBearerToken();
|
|
88
|
+
this.notifications.clearBearerToken();
|
|
89
|
+
// Note: onramp doesn't use bearer tokens
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Set API key specifically for M-Pesa operations
|
|
93
|
+
*/
|
|
94
|
+
setMpesaApiKey(apiKey) {
|
|
95
|
+
this.onramp.setMpesaApiKey(apiKey);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if the SDK is configured with an API key
|
|
99
|
+
*/
|
|
100
|
+
hasApiKey() {
|
|
101
|
+
return !!this.config.apiKey;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if the user is authenticated
|
|
105
|
+
*/
|
|
106
|
+
isAuthenticated() {
|
|
107
|
+
return this.auth.isAuthenticated();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the current environment
|
|
111
|
+
*/
|
|
112
|
+
getEnvironment() {
|
|
113
|
+
return this.config.environment;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the base URL being used
|
|
117
|
+
*/
|
|
118
|
+
getBaseUrl() {
|
|
119
|
+
return this.httpClient["baseUrl"];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.Rift = Rift;
|
|
123
|
+
// Export types and enums for consumers
|
|
124
|
+
__exportStar(require("./types"), exports);
|
|
125
|
+
// Export service classes
|
|
126
|
+
var notifications_2 = require("./services/notifications");
|
|
127
|
+
Object.defineProperty(exports, "NotificationService", { enumerable: true, get: function () { return notifications_2.NotificationService; } });
|
|
128
|
+
// Default export
|
|
129
|
+
exports.default = Rift;
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAkD;AAsHzC,4FAtHA,mBAAW,OAsHA;AArHpB,+CAA+C;AAC/C,0CAA8C;AAC9C,8CAAkD;AAClD,0DAA6D;AAC7D,4DAA+D;AAC/D,8CAAmD;AACnD,0CAA8C;AAC9C,8CAAkD;AAClD,8CAAkD;AAClD,4DAA+D;AAE/D,MAAa,IAAI;IACC,MAAM,CAAa;IAClB,UAAU,CAAiB;IAE5C,oBAAoB;IACJ,IAAI,CAAc;IAClB,MAAM,CAAgB;IACtB,YAAY,CAAqB;IACjC,YAAY,CAAsB;IAClC,MAAM,CAAgB;IACtB,IAAI,CAAc;IAClB,MAAM,CAAgB;IACtB,MAAM,CAAgB;IACtB,aAAa,CAAsB;IAEnD,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,4BAAc,CAAC,MAAM,CAAC,CAAC;QAE7C,0BAA0B;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,kBAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,GAAG,IAAI,iCAAkB,CAAC,IAAI,CAAC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,gBAAgB,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACtC,yCAAyC;IAC3C,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,MAAc;QAC3B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACF;AAtGD,oBAsGC;AAED,uCAAuC;AACvC,0CAAwB;AAGxB,yBAAyB;AACzB,0DAA+D;AAAtD,oHAAA,mBAAmB,OAAA;AAE5B,iBAAiB;AACjB,kBAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpClient, RequestConfig, RiftConfig } from "./types";
|
|
2
|
+
export declare class MpesaHttpClient implements HttpClient {
|
|
3
|
+
private config;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
constructor(config: RiftConfig);
|
|
6
|
+
private getMpesaBaseUrl;
|
|
7
|
+
request<T>(requestConfig: RequestConfig): Promise<T>;
|
|
8
|
+
private executeWithRetry;
|
|
9
|
+
private handleResponse;
|
|
10
|
+
private handleError;
|
|
11
|
+
private delay;
|
|
12
|
+
setApiKey(apiKey: string): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=mpesa-http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mpesa-http-client.d.ts","sourceRoot":"","sources":["../src/mpesa-http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAY,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1E,qBAAa,eAAgB,YAAW,UAAU;IAChD,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,UAAU;IAK9B,OAAO,CAAC,eAAe;IAKjB,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;YAyD5C,gBAAgB;YAqChB,cAAc;IAyC5B,OAAO,CAAC,WAAW;IA8BnB,OAAO,CAAC,KAAK;IAKb,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGhC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MpesaHttpClient = void 0;
|
|
4
|
+
class MpesaHttpClient {
|
|
5
|
+
config;
|
|
6
|
+
baseUrl;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.baseUrl = this.getMpesaBaseUrl();
|
|
10
|
+
}
|
|
11
|
+
getMpesaBaseUrl() {
|
|
12
|
+
// Always use the production Mpesa service URL as specified
|
|
13
|
+
return "https://mpesa-offramping-onramping-production.up.railway.app";
|
|
14
|
+
}
|
|
15
|
+
async request(requestConfig) {
|
|
16
|
+
const { method, url, data, params, headers = {} } = requestConfig;
|
|
17
|
+
// Build URL with query parameters
|
|
18
|
+
const fullUrl = new URL(url, this.baseUrl);
|
|
19
|
+
if (params) {
|
|
20
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
21
|
+
if (value !== undefined && value !== null) {
|
|
22
|
+
fullUrl.searchParams.append(key, String(value));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Build headers
|
|
27
|
+
const requestHeaders = {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
...headers,
|
|
30
|
+
};
|
|
31
|
+
// Add API key if available
|
|
32
|
+
if (this.config.apiKey) {
|
|
33
|
+
requestHeaders["X-API-Key"] = this.config.apiKey;
|
|
34
|
+
}
|
|
35
|
+
// Build fetch options
|
|
36
|
+
const fetchOptions = {
|
|
37
|
+
method,
|
|
38
|
+
headers: requestHeaders,
|
|
39
|
+
};
|
|
40
|
+
// Add body for POST/PUT requests
|
|
41
|
+
if (data && (method === "POST" || method === "PUT")) {
|
|
42
|
+
fetchOptions.body = JSON.stringify(data);
|
|
43
|
+
}
|
|
44
|
+
// Add timeout
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeoutId = setTimeout(() => {
|
|
47
|
+
controller.abort();
|
|
48
|
+
}, this.config.timeout || 30000);
|
|
49
|
+
fetchOptions.signal = controller.signal;
|
|
50
|
+
try {
|
|
51
|
+
const response = await this.executeWithRetry(fullUrl.toString(), fetchOptions);
|
|
52
|
+
clearTimeout(timeoutId);
|
|
53
|
+
return await this.handleResponse(response);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
clearTimeout(timeoutId);
|
|
57
|
+
throw this.handleError(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async executeWithRetry(url, options) {
|
|
61
|
+
const maxRetries = this.config.retries || 3;
|
|
62
|
+
let lastError;
|
|
63
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetch(url, options);
|
|
66
|
+
// Don't retry on client errors (4xx), only on server errors (5xx) and network errors
|
|
67
|
+
if (response.ok || (response.status >= 400 && response.status < 500)) {
|
|
68
|
+
return response;
|
|
69
|
+
}
|
|
70
|
+
if (attempt === maxRetries) {
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
// Wait before retrying (exponential backoff)
|
|
74
|
+
await this.delay(Math.pow(2, attempt) * 1000);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
lastError = error;
|
|
78
|
+
if (attempt === maxRetries) {
|
|
79
|
+
throw lastError;
|
|
80
|
+
}
|
|
81
|
+
// Wait before retrying
|
|
82
|
+
await this.delay(Math.pow(2, attempt) * 1000);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw lastError;
|
|
86
|
+
}
|
|
87
|
+
async handleResponse(response) {
|
|
88
|
+
const contentType = response.headers.get("content-type");
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
91
|
+
let errorDetails = {};
|
|
92
|
+
try {
|
|
93
|
+
if (contentType?.includes("application/json")) {
|
|
94
|
+
errorDetails = await response.json();
|
|
95
|
+
errorMessage =
|
|
96
|
+
errorDetails.message || errorDetails.error || errorMessage;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
errorMessage = (await response.text()) || errorMessage;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// If we can't parse the error response, use the default message
|
|
104
|
+
}
|
|
105
|
+
const apiError = {
|
|
106
|
+
message: errorMessage,
|
|
107
|
+
error: errorDetails.error,
|
|
108
|
+
status: response.status,
|
|
109
|
+
};
|
|
110
|
+
throw apiError;
|
|
111
|
+
}
|
|
112
|
+
// Handle different response types
|
|
113
|
+
if (response.status === 204) {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
if (contentType?.includes("application/json")) {
|
|
117
|
+
return await response.json();
|
|
118
|
+
}
|
|
119
|
+
// For non-JSON responses, return as text
|
|
120
|
+
return (await response.text());
|
|
121
|
+
}
|
|
122
|
+
handleError(error) {
|
|
123
|
+
if (error.name === "AbortError") {
|
|
124
|
+
return {
|
|
125
|
+
message: "Request timeout",
|
|
126
|
+
error: "The request took too long to complete",
|
|
127
|
+
status: 408,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (error.message && error.status) {
|
|
131
|
+
// Already an ApiError
|
|
132
|
+
return error;
|
|
133
|
+
}
|
|
134
|
+
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
135
|
+
return {
|
|
136
|
+
message: "Network error",
|
|
137
|
+
error: "Unable to connect to the server. Please check your internet connection.",
|
|
138
|
+
status: 0,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
message: error.message || "An unexpected error occurred",
|
|
143
|
+
error: error.toString(),
|
|
144
|
+
status: 500,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
delay(ms) {
|
|
148
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
149
|
+
}
|
|
150
|
+
// Method to update API key
|
|
151
|
+
setApiKey(apiKey) {
|
|
152
|
+
this.config.apiKey = apiKey;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.MpesaHttpClient = MpesaHttpClient;
|
|
156
|
+
//# sourceMappingURL=mpesa-http-client.js.map
|