@reevit/core 0.5.1 → 0.6.0
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 +19 -0
- package/dist/index.d.mts +48 -3
- package/dist/index.d.ts +48 -3
- package/dist/index.js +130 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ const { data, error } = await client.createPaymentIntent({
|
|
|
34
34
|
amount: 5000,
|
|
35
35
|
currency: 'GHS',
|
|
36
36
|
email: 'customer@example.com',
|
|
37
|
+
idempotencyKey: 'order_12345',
|
|
37
38
|
}, 'card');
|
|
38
39
|
|
|
39
40
|
if (data) {
|
|
@@ -51,6 +52,24 @@ console.log(validatePhone('0241234567')); // true
|
|
|
51
52
|
console.log(detectNetwork('0241234567')); // "mtn"
|
|
52
53
|
```
|
|
53
54
|
|
|
55
|
+
### Intent Identity & Idempotency
|
|
56
|
+
|
|
57
|
+
Core exports helpers to stabilize intent creation and dedupe in-flight requests.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { resolveIntentIdentity } from '@reevit/core';
|
|
61
|
+
|
|
62
|
+
const { idempotencyKey, reference } = resolveIntentIdentity({
|
|
63
|
+
config: {
|
|
64
|
+
amount: 5000,
|
|
65
|
+
currency: 'GHS',
|
|
66
|
+
email: 'customer@example.com',
|
|
67
|
+
idempotencyKey: 'order_12345',
|
|
68
|
+
},
|
|
69
|
+
method: 'card',
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
54
73
|
## License
|
|
55
74
|
|
|
56
75
|
MIT © Reevit
|
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,8 @@ interface ReevitCheckoutConfig {
|
|
|
22
22
|
customerName?: string;
|
|
23
23
|
/** Unique reference for this transaction */
|
|
24
24
|
reference?: string;
|
|
25
|
+
/** Optional idempotency key to safely retry or dedupe intent creation */
|
|
26
|
+
idempotencyKey?: string;
|
|
25
27
|
/** Additional metadata to attach to the payment */
|
|
26
28
|
metadata?: Record<string, unknown>;
|
|
27
29
|
/** Custom fields for payment links (if applicable) */
|
|
@@ -83,12 +85,18 @@ interface PaymentError {
|
|
|
83
85
|
details?: Record<string, unknown>;
|
|
84
86
|
}
|
|
85
87
|
interface ReevitTheme {
|
|
86
|
-
/** Primary brand color */
|
|
88
|
+
/** Primary brand color (main text color) */
|
|
87
89
|
primaryColor?: string;
|
|
88
|
-
/** Primary text color on brand surfaces */
|
|
90
|
+
/** Primary text color on brand surfaces (description/secondary text) */
|
|
89
91
|
primaryForegroundColor?: string;
|
|
92
|
+
/** Button background color */
|
|
93
|
+
buttonBackgroundColor?: string;
|
|
94
|
+
/** Button text color */
|
|
95
|
+
buttonTextColor?: string;
|
|
90
96
|
/** Background color */
|
|
91
97
|
backgroundColor?: string;
|
|
98
|
+
/** Border color for borders and dividers */
|
|
99
|
+
borderColor?: string;
|
|
92
100
|
/** Surface color for cards/panels */
|
|
93
101
|
surfaceColor?: string;
|
|
94
102
|
/** Text color */
|
|
@@ -174,6 +182,8 @@ interface PaymentIntent {
|
|
|
174
182
|
availableMethods: PaymentMethod[];
|
|
175
183
|
/** Reference provided or generated */
|
|
176
184
|
reference?: string;
|
|
185
|
+
/** Organization ID (from Reevit backend, required for webhook routing) */
|
|
186
|
+
orgId?: string;
|
|
177
187
|
/** Connection ID (from Reevit backend) */
|
|
178
188
|
connectionId?: string;
|
|
179
189
|
/** Provider name (from backend) */
|
|
@@ -229,6 +239,7 @@ interface CreatePaymentIntentRequest {
|
|
|
229
239
|
}
|
|
230
240
|
interface PaymentIntentResponse {
|
|
231
241
|
id: string;
|
|
242
|
+
org_id?: string;
|
|
232
243
|
connection_id: string;
|
|
233
244
|
provider: string;
|
|
234
245
|
status: string;
|
|
@@ -294,6 +305,12 @@ interface ReevitAPIClientConfig {
|
|
|
294
305
|
/** Request timeout in milliseconds */
|
|
295
306
|
timeout?: number;
|
|
296
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Generates a deterministic idempotency key based on input parameters
|
|
310
|
+
* Uses a simple hash function suitable for browser environments
|
|
311
|
+
* Exported for use by SDK hooks (e.g., payment link flows)
|
|
312
|
+
*/
|
|
313
|
+
declare function generateIdempotencyKey(params: Record<string, unknown>): string;
|
|
297
314
|
/**
|
|
298
315
|
* Reevit API Client
|
|
299
316
|
*/
|
|
@@ -304,6 +321,7 @@ declare class ReevitAPIClient {
|
|
|
304
321
|
constructor(config: ReevitAPIClientConfig);
|
|
305
322
|
/**
|
|
306
323
|
* Makes an authenticated API request
|
|
324
|
+
* @param idempotencyKey Optional deterministic idempotency key for the request
|
|
307
325
|
*/
|
|
308
326
|
private request;
|
|
309
327
|
/**
|
|
@@ -401,6 +419,33 @@ declare function cn(...classes: (string | boolean | undefined | null)[]): string
|
|
|
401
419
|
*/
|
|
402
420
|
declare function detectCountryFromCurrency(currency: string): string;
|
|
403
421
|
|
|
422
|
+
/**
|
|
423
|
+
* Intent identity + cache helpers
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
interface IntentIdentityOptions {
|
|
427
|
+
config: ReevitCheckoutConfig;
|
|
428
|
+
method?: PaymentMethod;
|
|
429
|
+
preferredProvider?: string;
|
|
430
|
+
allowedProviders?: string[];
|
|
431
|
+
publicKey?: string;
|
|
432
|
+
}
|
|
433
|
+
interface IntentCacheEntry {
|
|
434
|
+
promise?: Promise<PaymentIntentResponse>;
|
|
435
|
+
response?: PaymentIntentResponse;
|
|
436
|
+
expiresAt: number;
|
|
437
|
+
reference?: string;
|
|
438
|
+
}
|
|
439
|
+
declare function resolveIntentIdentity(options: IntentIdentityOptions): {
|
|
440
|
+
idempotencyKey: string;
|
|
441
|
+
reference: string;
|
|
442
|
+
cacheEntry?: IntentCacheEntry;
|
|
443
|
+
};
|
|
444
|
+
declare function getIntentCacheEntry(idempotencyKey: string): IntentCacheEntry | undefined;
|
|
445
|
+
declare function cacheIntentPromise(idempotencyKey: string, promise: Promise<PaymentIntentResponse>): IntentCacheEntry;
|
|
446
|
+
declare function cacheIntentResponse(idempotencyKey: string, response: PaymentIntentResponse): IntentCacheEntry;
|
|
447
|
+
declare function clearIntentCacheEntry(idempotencyKey: string): void;
|
|
448
|
+
|
|
404
449
|
/**
|
|
405
450
|
* Reevit State Machine
|
|
406
451
|
* Shared state management logic for all SDKs
|
|
@@ -446,4 +491,4 @@ declare function createInitialState(): ReevitState;
|
|
|
446
491
|
*/
|
|
447
492
|
declare function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState;
|
|
448
493
|
|
|
449
|
-
export { type APIErrorResponse, type CardFormData, type CheckoutProviderOption, type CheckoutState, type ConfirmPaymentRequest, type CreatePaymentIntentRequest, type HubtelSessionResponse, type MobileMoneyFormData, type MobileMoneyNetwork, type PSPConfig, type PSPType, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, type PaymentResult, type PaymentSource, ReevitAPIClient, type ReevitAPIClientConfig, type ReevitAction, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitState, type ReevitTheme, cn, createInitialState, createReevitClient, createThemeVariables, detectCountryFromCurrency, detectNetwork, formatAmount, formatPhone, generateReference, reevitReducer, validatePhone };
|
|
494
|
+
export { type APIErrorResponse, type CardFormData, type CheckoutProviderOption, type CheckoutState, type ConfirmPaymentRequest, type CreatePaymentIntentRequest, type HubtelSessionResponse, type IntentCacheEntry, type MobileMoneyFormData, type MobileMoneyNetwork, type PSPConfig, type PSPType, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, type PaymentResult, type PaymentSource, ReevitAPIClient, type ReevitAPIClientConfig, type ReevitAction, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitState, type ReevitTheme, cacheIntentPromise, cacheIntentResponse, clearIntentCacheEntry, cn, createInitialState, createReevitClient, createThemeVariables, detectCountryFromCurrency, detectNetwork, formatAmount, formatPhone, generateIdempotencyKey, generateReference, getIntentCacheEntry, reevitReducer, resolveIntentIdentity, validatePhone };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ interface ReevitCheckoutConfig {
|
|
|
22
22
|
customerName?: string;
|
|
23
23
|
/** Unique reference for this transaction */
|
|
24
24
|
reference?: string;
|
|
25
|
+
/** Optional idempotency key to safely retry or dedupe intent creation */
|
|
26
|
+
idempotencyKey?: string;
|
|
25
27
|
/** Additional metadata to attach to the payment */
|
|
26
28
|
metadata?: Record<string, unknown>;
|
|
27
29
|
/** Custom fields for payment links (if applicable) */
|
|
@@ -83,12 +85,18 @@ interface PaymentError {
|
|
|
83
85
|
details?: Record<string, unknown>;
|
|
84
86
|
}
|
|
85
87
|
interface ReevitTheme {
|
|
86
|
-
/** Primary brand color */
|
|
88
|
+
/** Primary brand color (main text color) */
|
|
87
89
|
primaryColor?: string;
|
|
88
|
-
/** Primary text color on brand surfaces */
|
|
90
|
+
/** Primary text color on brand surfaces (description/secondary text) */
|
|
89
91
|
primaryForegroundColor?: string;
|
|
92
|
+
/** Button background color */
|
|
93
|
+
buttonBackgroundColor?: string;
|
|
94
|
+
/** Button text color */
|
|
95
|
+
buttonTextColor?: string;
|
|
90
96
|
/** Background color */
|
|
91
97
|
backgroundColor?: string;
|
|
98
|
+
/** Border color for borders and dividers */
|
|
99
|
+
borderColor?: string;
|
|
92
100
|
/** Surface color for cards/panels */
|
|
93
101
|
surfaceColor?: string;
|
|
94
102
|
/** Text color */
|
|
@@ -174,6 +182,8 @@ interface PaymentIntent {
|
|
|
174
182
|
availableMethods: PaymentMethod[];
|
|
175
183
|
/** Reference provided or generated */
|
|
176
184
|
reference?: string;
|
|
185
|
+
/** Organization ID (from Reevit backend, required for webhook routing) */
|
|
186
|
+
orgId?: string;
|
|
177
187
|
/** Connection ID (from Reevit backend) */
|
|
178
188
|
connectionId?: string;
|
|
179
189
|
/** Provider name (from backend) */
|
|
@@ -229,6 +239,7 @@ interface CreatePaymentIntentRequest {
|
|
|
229
239
|
}
|
|
230
240
|
interface PaymentIntentResponse {
|
|
231
241
|
id: string;
|
|
242
|
+
org_id?: string;
|
|
232
243
|
connection_id: string;
|
|
233
244
|
provider: string;
|
|
234
245
|
status: string;
|
|
@@ -294,6 +305,12 @@ interface ReevitAPIClientConfig {
|
|
|
294
305
|
/** Request timeout in milliseconds */
|
|
295
306
|
timeout?: number;
|
|
296
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Generates a deterministic idempotency key based on input parameters
|
|
310
|
+
* Uses a simple hash function suitable for browser environments
|
|
311
|
+
* Exported for use by SDK hooks (e.g., payment link flows)
|
|
312
|
+
*/
|
|
313
|
+
declare function generateIdempotencyKey(params: Record<string, unknown>): string;
|
|
297
314
|
/**
|
|
298
315
|
* Reevit API Client
|
|
299
316
|
*/
|
|
@@ -304,6 +321,7 @@ declare class ReevitAPIClient {
|
|
|
304
321
|
constructor(config: ReevitAPIClientConfig);
|
|
305
322
|
/**
|
|
306
323
|
* Makes an authenticated API request
|
|
324
|
+
* @param idempotencyKey Optional deterministic idempotency key for the request
|
|
307
325
|
*/
|
|
308
326
|
private request;
|
|
309
327
|
/**
|
|
@@ -401,6 +419,33 @@ declare function cn(...classes: (string | boolean | undefined | null)[]): string
|
|
|
401
419
|
*/
|
|
402
420
|
declare function detectCountryFromCurrency(currency: string): string;
|
|
403
421
|
|
|
422
|
+
/**
|
|
423
|
+
* Intent identity + cache helpers
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
interface IntentIdentityOptions {
|
|
427
|
+
config: ReevitCheckoutConfig;
|
|
428
|
+
method?: PaymentMethod;
|
|
429
|
+
preferredProvider?: string;
|
|
430
|
+
allowedProviders?: string[];
|
|
431
|
+
publicKey?: string;
|
|
432
|
+
}
|
|
433
|
+
interface IntentCacheEntry {
|
|
434
|
+
promise?: Promise<PaymentIntentResponse>;
|
|
435
|
+
response?: PaymentIntentResponse;
|
|
436
|
+
expiresAt: number;
|
|
437
|
+
reference?: string;
|
|
438
|
+
}
|
|
439
|
+
declare function resolveIntentIdentity(options: IntentIdentityOptions): {
|
|
440
|
+
idempotencyKey: string;
|
|
441
|
+
reference: string;
|
|
442
|
+
cacheEntry?: IntentCacheEntry;
|
|
443
|
+
};
|
|
444
|
+
declare function getIntentCacheEntry(idempotencyKey: string): IntentCacheEntry | undefined;
|
|
445
|
+
declare function cacheIntentPromise(idempotencyKey: string, promise: Promise<PaymentIntentResponse>): IntentCacheEntry;
|
|
446
|
+
declare function cacheIntentResponse(idempotencyKey: string, response: PaymentIntentResponse): IntentCacheEntry;
|
|
447
|
+
declare function clearIntentCacheEntry(idempotencyKey: string): void;
|
|
448
|
+
|
|
404
449
|
/**
|
|
405
450
|
* Reevit State Machine
|
|
406
451
|
* Shared state management logic for all SDKs
|
|
@@ -446,4 +491,4 @@ declare function createInitialState(): ReevitState;
|
|
|
446
491
|
*/
|
|
447
492
|
declare function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState;
|
|
448
493
|
|
|
449
|
-
export { type APIErrorResponse, type CardFormData, type CheckoutProviderOption, type CheckoutState, type ConfirmPaymentRequest, type CreatePaymentIntentRequest, type HubtelSessionResponse, type MobileMoneyFormData, type MobileMoneyNetwork, type PSPConfig, type PSPType, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, type PaymentResult, type PaymentSource, ReevitAPIClient, type ReevitAPIClientConfig, type ReevitAction, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitState, type ReevitTheme, cn, createInitialState, createReevitClient, createThemeVariables, detectCountryFromCurrency, detectNetwork, formatAmount, formatPhone, generateReference, reevitReducer, validatePhone };
|
|
494
|
+
export { type APIErrorResponse, type CardFormData, type CheckoutProviderOption, type CheckoutState, type ConfirmPaymentRequest, type CreatePaymentIntentRequest, type HubtelSessionResponse, type IntentCacheEntry, type MobileMoneyFormData, type MobileMoneyNetwork, type PSPConfig, type PSPType, type PaymentDetailResponse, type PaymentError, type PaymentIntent, type PaymentIntentResponse, type PaymentMethod, type PaymentResult, type PaymentSource, ReevitAPIClient, type ReevitAPIClientConfig, type ReevitAction, type ReevitCheckoutCallbacks, type ReevitCheckoutConfig, type ReevitState, type ReevitTheme, cacheIntentPromise, cacheIntentResponse, clearIntentCacheEntry, cn, createInitialState, createReevitClient, createThemeVariables, detectCountryFromCurrency, detectNetwork, formatAmount, formatPhone, generateIdempotencyKey, generateReference, getIntentCacheEntry, reevitReducer, resolveIntentIdentity, validatePhone };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ReevitAPIClient: () => ReevitAPIClient,
|
|
24
|
+
cacheIntentPromise: () => cacheIntentPromise,
|
|
25
|
+
cacheIntentResponse: () => cacheIntentResponse,
|
|
26
|
+
clearIntentCacheEntry: () => clearIntentCacheEntry,
|
|
24
27
|
cn: () => cn,
|
|
25
28
|
createInitialState: () => createInitialState,
|
|
26
29
|
createReevitClient: () => createReevitClient,
|
|
@@ -29,8 +32,11 @@ __export(index_exports, {
|
|
|
29
32
|
detectNetwork: () => detectNetwork,
|
|
30
33
|
formatAmount: () => formatAmount,
|
|
31
34
|
formatPhone: () => formatPhone,
|
|
35
|
+
generateIdempotencyKey: () => generateIdempotencyKey,
|
|
32
36
|
generateReference: () => generateReference,
|
|
37
|
+
getIntentCacheEntry: () => getIntentCacheEntry,
|
|
33
38
|
reevitReducer: () => reevitReducer,
|
|
39
|
+
resolveIntentIdentity: () => resolveIntentIdentity,
|
|
34
40
|
validatePhone: () => validatePhone
|
|
35
41
|
});
|
|
36
42
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -52,6 +58,18 @@ function createPaymentError(response, errorData) {
|
|
|
52
58
|
}
|
|
53
59
|
};
|
|
54
60
|
}
|
|
61
|
+
function generateIdempotencyKey(params) {
|
|
62
|
+
const sortedKeys = Object.keys(params).sort();
|
|
63
|
+
const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(params[key])}`).join("|");
|
|
64
|
+
let hash = 5381;
|
|
65
|
+
for (let i = 0; i < stableString.length; i++) {
|
|
66
|
+
hash = (hash << 5) + hash + stableString.charCodeAt(i);
|
|
67
|
+
hash = hash & hash;
|
|
68
|
+
}
|
|
69
|
+
const hashHex = (hash >>> 0).toString(16);
|
|
70
|
+
const timeBucket = Math.floor(Date.now() / (5 * 60 * 1e3));
|
|
71
|
+
return `reevit_${timeBucket}_${hashHex}`;
|
|
72
|
+
}
|
|
55
73
|
var ReevitAPIClient = class {
|
|
56
74
|
constructor(config) {
|
|
57
75
|
this.publicKey = config.publicKey || "";
|
|
@@ -60,20 +78,21 @@ var ReevitAPIClient = class {
|
|
|
60
78
|
}
|
|
61
79
|
/**
|
|
62
80
|
* Makes an authenticated API request
|
|
81
|
+
* @param idempotencyKey Optional deterministic idempotency key for the request
|
|
63
82
|
*/
|
|
64
|
-
async request(method, path, body) {
|
|
83
|
+
async request(method, path, body, idempotencyKey) {
|
|
65
84
|
const controller = new AbortController();
|
|
66
85
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
67
86
|
const headers = {
|
|
68
87
|
"Content-Type": "application/json",
|
|
69
88
|
"X-Reevit-Client": "@reevit/core",
|
|
70
|
-
"X-Reevit-Client-Version": "0.
|
|
89
|
+
"X-Reevit-Client-Version": "0.5.9"
|
|
71
90
|
};
|
|
72
91
|
if (this.publicKey) {
|
|
73
92
|
headers["X-Reevit-Key"] = this.publicKey;
|
|
74
93
|
}
|
|
75
94
|
if (method === "POST" || method === "PATCH" || method === "PUT") {
|
|
76
|
-
headers["Idempotency-Key"] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}
|
|
95
|
+
headers["Idempotency-Key"] = idempotencyKey || (body ? generateIdempotencyKey(body) : `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`);
|
|
77
96
|
}
|
|
78
97
|
try {
|
|
79
98
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
@@ -145,7 +164,16 @@ var ReevitAPIClient = class {
|
|
|
145
164
|
allowed_providers: options?.allowedProviders
|
|
146
165
|
};
|
|
147
166
|
}
|
|
148
|
-
|
|
167
|
+
const idempotencyKey = config.idempotencyKey || generateIdempotencyKey({
|
|
168
|
+
amount: config.amount,
|
|
169
|
+
currency: config.currency,
|
|
170
|
+
customer: config.email || config.metadata?.customerId || "",
|
|
171
|
+
reference: config.reference || "",
|
|
172
|
+
method: method || "",
|
|
173
|
+
provider: options?.preferredProviders?.[0] || options?.allowedProviders?.[0] || "",
|
|
174
|
+
publicKey: this.publicKey
|
|
175
|
+
});
|
|
176
|
+
return this.request("POST", "/v1/payments/intents", request, idempotencyKey);
|
|
149
177
|
}
|
|
150
178
|
/**
|
|
151
179
|
* Retrieves a payment intent by ID
|
|
@@ -275,22 +303,29 @@ function detectNetwork(phone) {
|
|
|
275
303
|
function createThemeVariables(theme) {
|
|
276
304
|
const variables = {};
|
|
277
305
|
if (theme.primaryColor) {
|
|
278
|
-
variables["--reevit-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
306
|
+
variables["--reevit-text"] = theme.primaryColor;
|
|
307
|
+
}
|
|
308
|
+
if (theme.primaryForegroundColor) {
|
|
309
|
+
variables["--reevit-text-secondary"] = theme.primaryForegroundColor;
|
|
310
|
+
variables["--reevit-muted"] = theme.primaryForegroundColor;
|
|
311
|
+
}
|
|
312
|
+
if (theme.buttonBackgroundColor) {
|
|
313
|
+
variables["--reevit-primary"] = theme.buttonBackgroundColor;
|
|
314
|
+
variables["--reevit-primary-hover"] = theme.buttonBackgroundColor;
|
|
315
|
+
}
|
|
316
|
+
if (theme.buttonTextColor) {
|
|
317
|
+
variables["--reevit-primary-foreground"] = theme.buttonTextColor;
|
|
287
318
|
}
|
|
288
319
|
if (theme.backgroundColor) {
|
|
289
320
|
variables["--reevit-background"] = theme.backgroundColor;
|
|
321
|
+
variables["--reevit-surface"] = theme.backgroundColor;
|
|
290
322
|
}
|
|
291
323
|
if (theme.surfaceColor) {
|
|
292
324
|
variables["--reevit-surface"] = theme.surfaceColor;
|
|
293
325
|
}
|
|
326
|
+
if (theme.borderColor) {
|
|
327
|
+
variables["--reevit-border"] = theme.borderColor;
|
|
328
|
+
}
|
|
294
329
|
if (theme.textColor) {
|
|
295
330
|
variables["--reevit-text"] = theme.textColor;
|
|
296
331
|
}
|
|
@@ -307,24 +342,6 @@ function createThemeVariables(theme) {
|
|
|
307
342
|
}
|
|
308
343
|
return variables;
|
|
309
344
|
}
|
|
310
|
-
function getContrastingColor(color) {
|
|
311
|
-
const hex = color.trim();
|
|
312
|
-
if (!hex.startsWith("#")) {
|
|
313
|
-
return null;
|
|
314
|
-
}
|
|
315
|
-
const normalized = hex.length === 4 ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}` : hex;
|
|
316
|
-
if (normalized.length !== 7) {
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
const r = parseInt(normalized.slice(1, 3), 16);
|
|
320
|
-
const g = parseInt(normalized.slice(3, 5), 16);
|
|
321
|
-
const b = parseInt(normalized.slice(5, 7), 16);
|
|
322
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
const brightness = (r * 299 + g * 587 + b * 114) / 1e3;
|
|
326
|
-
return brightness >= 140 ? "#0b1120" : "#ffffff";
|
|
327
|
-
}
|
|
328
345
|
function cn(...classes) {
|
|
329
346
|
return classes.filter(Boolean).join(" ");
|
|
330
347
|
}
|
|
@@ -345,6 +362,82 @@ function detectCountryFromCurrency(currency) {
|
|
|
345
362
|
return currencyToCountry[currency.toUpperCase()] || "GH";
|
|
346
363
|
}
|
|
347
364
|
|
|
365
|
+
// src/intent.ts
|
|
366
|
+
var INTENT_CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
367
|
+
var intentCache = /* @__PURE__ */ new Map();
|
|
368
|
+
function pruneIntentCache(now = Date.now()) {
|
|
369
|
+
for (const [key, entry] of intentCache) {
|
|
370
|
+
if (entry.expiresAt <= now) {
|
|
371
|
+
intentCache.delete(key);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function getIntentCacheEntryInternal(key) {
|
|
376
|
+
const entry = intentCache.get(key);
|
|
377
|
+
if (!entry) {
|
|
378
|
+
return void 0;
|
|
379
|
+
}
|
|
380
|
+
if (entry.expiresAt <= Date.now()) {
|
|
381
|
+
intentCache.delete(key);
|
|
382
|
+
return void 0;
|
|
383
|
+
}
|
|
384
|
+
return entry;
|
|
385
|
+
}
|
|
386
|
+
function setIntentCacheEntryInternal(key, update) {
|
|
387
|
+
const now = Date.now();
|
|
388
|
+
const existing = getIntentCacheEntryInternal(key);
|
|
389
|
+
const next = {
|
|
390
|
+
...existing,
|
|
391
|
+
...update,
|
|
392
|
+
expiresAt: now + INTENT_CACHE_TTL_MS
|
|
393
|
+
};
|
|
394
|
+
intentCache.set(key, next);
|
|
395
|
+
return next;
|
|
396
|
+
}
|
|
397
|
+
function buildIdempotencyPayload(options) {
|
|
398
|
+
const { config, method, preferredProvider, allowedProviders, publicKey } = options;
|
|
399
|
+
const payload = {
|
|
400
|
+
amount: config.amount,
|
|
401
|
+
currency: config.currency,
|
|
402
|
+
email: config.email || "",
|
|
403
|
+
phone: config.phone || "",
|
|
404
|
+
customerName: config.customerName || "",
|
|
405
|
+
paymentLinkCode: config.paymentLinkCode || "",
|
|
406
|
+
paymentMethods: config.paymentMethods || [],
|
|
407
|
+
metadata: config.metadata || {},
|
|
408
|
+
customFields: config.customFields || {},
|
|
409
|
+
method: method || "",
|
|
410
|
+
preferredProvider: preferredProvider || "",
|
|
411
|
+
allowedProviders: allowedProviders || [],
|
|
412
|
+
publicKey: publicKey || config.publicKey || ""
|
|
413
|
+
};
|
|
414
|
+
if (config.reference) {
|
|
415
|
+
payload.reference = config.reference;
|
|
416
|
+
}
|
|
417
|
+
return payload;
|
|
418
|
+
}
|
|
419
|
+
function resolveIntentIdentity(options) {
|
|
420
|
+
pruneIntentCache();
|
|
421
|
+
const idempotencyKey = options.config.idempotencyKey || generateIdempotencyKey(buildIdempotencyPayload(options));
|
|
422
|
+
const existing = getIntentCacheEntryInternal(idempotencyKey);
|
|
423
|
+
const reference = options.config.reference || existing?.reference || generateReference();
|
|
424
|
+
const cacheEntry = setIntentCacheEntryInternal(idempotencyKey, { reference });
|
|
425
|
+
return { idempotencyKey, reference, cacheEntry };
|
|
426
|
+
}
|
|
427
|
+
function getIntentCacheEntry(idempotencyKey) {
|
|
428
|
+
pruneIntentCache();
|
|
429
|
+
return getIntentCacheEntryInternal(idempotencyKey);
|
|
430
|
+
}
|
|
431
|
+
function cacheIntentPromise(idempotencyKey, promise) {
|
|
432
|
+
return setIntentCacheEntryInternal(idempotencyKey, { promise });
|
|
433
|
+
}
|
|
434
|
+
function cacheIntentResponse(idempotencyKey, response) {
|
|
435
|
+
return setIntentCacheEntryInternal(idempotencyKey, { response, promise: void 0 });
|
|
436
|
+
}
|
|
437
|
+
function clearIntentCacheEntry(idempotencyKey) {
|
|
438
|
+
intentCache.delete(idempotencyKey);
|
|
439
|
+
}
|
|
440
|
+
|
|
348
441
|
// src/state.ts
|
|
349
442
|
function createInitialState() {
|
|
350
443
|
return {
|
|
@@ -387,6 +480,9 @@ function reevitReducer(state, action) {
|
|
|
387
480
|
// Annotate the CommonJS export names for ESM import in node:
|
|
388
481
|
0 && (module.exports = {
|
|
389
482
|
ReevitAPIClient,
|
|
483
|
+
cacheIntentPromise,
|
|
484
|
+
cacheIntentResponse,
|
|
485
|
+
clearIntentCacheEntry,
|
|
390
486
|
cn,
|
|
391
487
|
createInitialState,
|
|
392
488
|
createReevitClient,
|
|
@@ -395,8 +491,11 @@ function reevitReducer(state, action) {
|
|
|
395
491
|
detectNetwork,
|
|
396
492
|
formatAmount,
|
|
397
493
|
formatPhone,
|
|
494
|
+
generateIdempotencyKey,
|
|
398
495
|
generateReference,
|
|
496
|
+
getIntentCacheEntry,
|
|
399
497
|
reevitReducer,
|
|
498
|
+
resolveIntentIdentity,
|
|
400
499
|
validatePhone
|
|
401
500
|
});
|
|
402
501
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/api/client.ts","../src/utils.ts","../src/state.ts"],"sourcesContent":["/**\n * @reevit/core\n * Shared utilities and API client for Reevit payment SDKs\n */\n\n// API Client\nexport {\n ReevitAPIClient,\n createReevitClient,\n type ReevitAPIClientConfig,\n type CreatePaymentIntentRequest,\n type PaymentIntentResponse,\n type PaymentDetailResponse,\n type ConfirmPaymentRequest,\n type APIErrorResponse,\n} from './api/client';\n\n// Types\nexport type {\n PaymentMethod,\n MobileMoneyNetwork,\n ReevitCheckoutConfig,\n ReevitCheckoutCallbacks,\n CheckoutState,\n PaymentResult,\n PaymentError,\n ReevitTheme,\n CheckoutProviderOption,\n MobileMoneyFormData,\n CardFormData,\n PaymentIntent,\n PSPConfig,\n PSPType,\n PaymentSource,\n HubtelSessionResponse,\n} from './types';\n\n// Utilities\nexport {\n formatAmount,\n generateReference,\n validatePhone,\n formatPhone,\n detectNetwork,\n detectCountryFromCurrency,\n createThemeVariables,\n cn,\n} from './utils';\n\n// State machine helpers\nexport {\n createInitialState,\n reevitReducer,\n type ReevitState,\n type ReevitAction,\n} from './state';\n","/**\n * Reevit API Client\n * \n * Handles communication with the Reevit backend for payment operations.\n */\n\nimport type { PaymentMethod, ReevitCheckoutConfig, PaymentError, HubtelSessionResponse } from '../types';\n\n// API Response Types (matching backend handlers_payments.go)\nexport interface CreatePaymentIntentRequest {\n amount: number;\n currency: string;\n method?: string;\n country: string;\n customer_id?: string;\n metadata?: Record<string, unknown>;\n description?: string;\n policy?: {\n prefer?: string[];\n allowed_providers?: string[];\n max_amount?: number;\n blocked_bins?: string[];\n allowed_bins?: string[];\n velocity_max_per_minute?: number;\n };\n}\n\nexport interface PaymentIntentResponse {\n id: string;\n connection_id: string;\n provider: string;\n status: string;\n client_secret: string;\n psp_public_key: string;\n psp_credentials?: {\n merchantAccount?: string | number;\n basicAuth?: string;\n [key: string]: unknown;\n };\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n reference?: string;\n available_psps?: Array<{\n provider: string;\n name: string;\n methods: string[];\n countries?: string[];\n }>;\n branding?: Record<string, unknown>;\n}\n\nexport interface ConfirmPaymentRequest {\n provider_ref_id: string;\n provider_data?: Record<string, unknown>;\n}\n\nexport interface PaymentDetailResponse {\n id: string;\n connection_id: string;\n provider: string;\n method: string;\n status: string;\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n customer_id?: string;\n client_secret: string;\n provider_ref_id?: string;\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n /** Payment source type (payment_link, api, subscription) */\n source?: 'payment_link' | 'api' | 'subscription';\n /** ID of the source (payment link ID, subscription ID, etc.) */\n source_id?: string;\n /** Human-readable description of the source (e.g., payment link name) */\n source_description?: string;\n}\n\nexport interface APIErrorResponse {\n code: string;\n message: string;\n details?: Record<string, string>;\n}\n\n// API Client configuration\nexport interface ReevitAPIClientConfig {\n /** Your Reevit public key */\n publicKey?: string;\n /** Base URL for the Reevit API (defaults to production) */\n baseUrl?: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n}\n\n// Default API base URLs\nconst API_BASE_URL_PRODUCTION = 'https://api.reevit.io';\nconst API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Determines if a public key is for sandbox mode\n */\nexport function isSandboxKey(publicKey: string): boolean {\n return publicKey.startsWith('pk_test_') ||\n publicKey.startsWith('pk_sandbox_') ||\n publicKey.startsWith('pfk_test_') ||\n publicKey.startsWith('pfk_sandbox_');\n}\n\n/**\n * Creates a PaymentError from an API error response\n */\nfunction createPaymentError(response: Response, errorData: APIErrorResponse): PaymentError {\n return {\n code: errorData.code || 'api_error',\n message: errorData.message || 'An unexpected error occurred',\n details: {\n httpStatus: response.status,\n ...errorData.details,\n },\n };\n}\n\n/**\n * Reevit API Client\n */\nexport class ReevitAPIClient {\n private readonly publicKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(config: ReevitAPIClientConfig) {\n this.publicKey = config.publicKey || '';\n this.baseUrl = config.baseUrl || (config.publicKey && isSandboxKey(config.publicKey)\n ? API_BASE_URL_SANDBOX\n : API_BASE_URL_PRODUCTION);\n this.timeout = config.timeout || DEFAULT_TIMEOUT;\n }\n\n /**\n * Makes an authenticated API request\n */\n private async request<T>(\n method: string,\n path: string,\n body?: unknown\n ): Promise<{ data?: T; error?: PaymentError }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n // Generate headers with idempotency key for mutating requests\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Reevit-Client': '@reevit/core',\n 'X-Reevit-Client-Version': '0.3.2',\n };\n if (this.publicKey) {\n headers['X-Reevit-Key'] = this.publicKey;\n }\n\n if (method === 'POST' || method === 'PATCH' || method === 'PUT') {\n headers['Idempotency-Key'] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;\n }\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n const responseData = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n return {\n error: createPaymentError(response, responseData as APIErrorResponse),\n };\n }\n\n return { data: responseData as T };\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof Error) {\n if (err.name === 'AbortError') {\n return {\n error: {\n code: 'request_timeout',\n message: 'The request timed out. Please try again.',\n },\n };\n }\n\n if (err.message.includes('Failed to fetch') || err.message.includes('NetworkError')) {\n return {\n error: {\n code: 'network_error',\n message: 'Unable to connect to Reevit. Please check your internet connection.',\n },\n };\n }\n }\n\n return {\n error: {\n code: 'unknown_error',\n message: 'An unexpected error occurred. Please try again.',\n },\n };\n }\n }\n\n /**\n * Creates a payment intent\n */\n async createPaymentIntent(\n config: ReevitCheckoutConfig,\n method?: PaymentMethod,\n country: string = 'GH',\n options?: { preferredProviders?: string[]; allowedProviders?: string[] }\n ): Promise<{ data?: PaymentIntentResponse; error?: PaymentError }> {\n // Build metadata with customer_email for PSP providers that require it\n const metadata: Record<string, unknown> = { ...config.metadata };\n if (config.email) {\n metadata.customer_email = config.email;\n }\n if (config.phone) {\n metadata.customer_phone = config.phone;\n }\n\n const request: CreatePaymentIntentRequest = {\n amount: config.amount,\n currency: config.currency,\n country,\n customer_id: config.email || (config.metadata?.customerId as string | undefined),\n metadata,\n };\n\n if (method) {\n request.method = this.mapPaymentMethod(method);\n }\n\n if (options?.preferredProviders?.length || options?.allowedProviders?.length) {\n request.policy = {\n prefer: options?.preferredProviders,\n allowed_providers: options?.allowedProviders,\n };\n }\n\n return this.request<PaymentIntentResponse>('POST', '/v1/payments/intents', request);\n }\n\n /**\n * Retrieves a payment intent by ID\n */\n async getPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('GET', `/v1/payments/${paymentId}`);\n }\n\n /**\n * Confirms a payment after PSP callback\n */\n async confirmPayment(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm`);\n }\n\n /**\n * Confirms a payment intent using client secret (public endpoint)\n */\n async confirmPaymentIntent(paymentId: string, clientSecret: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm-intent?client_secret=${clientSecret}`);\n }\n\n /**\n * Cancels a payment intent\n */\n async cancelPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/cancel`);\n }\n\n /**\n * Creates a Hubtel session token for secure checkout\n * Returns a short-lived token that contains Hubtel credentials\n * Credentials are never exposed to the client directly\n */\n async createHubtelSession(\n paymentId: string,\n clientSecret?: string\n ): Promise<{ data?: HubtelSessionResponse; error?: PaymentError }> {\n const query = clientSecret ? `?client_secret=${encodeURIComponent(clientSecret)}` : '';\n return this.request<HubtelSessionResponse>('POST', `/v1/payments/hubtel/sessions/${paymentId}${query}`);\n }\n\n /**\n * Maps SDK payment method to backend format\n */\n private mapPaymentMethod(method: PaymentMethod): string {\n switch (method) {\n case 'card':\n return 'card';\n case 'mobile_money':\n return 'mobile_money';\n case 'bank_transfer':\n return 'bank_transfer';\n default:\n return method;\n }\n }\n}\n\n/**\n * Creates a new Reevit API client instance\n */\nexport function createReevitClient(config: ReevitAPIClientConfig): ReevitAPIClient {\n return new ReevitAPIClient(config);\n}\n","/**\n * Utility Functions\n * Shared utilities for Reevit SDKs\n */\n\nimport type { MobileMoneyNetwork, ReevitTheme } from './types';\n\n/**\n * Formats an amount from smallest currency unit to display format\n */\nexport function formatAmount(amount: number, currency: string): string {\n const majorUnit = amount / 100;\n\n const currencyFormats: Record<string, { locale: string; minimumFractionDigits: number }> = {\n GHS: { locale: 'en-GH', minimumFractionDigits: 2 },\n NGN: { locale: 'en-NG', minimumFractionDigits: 2 },\n KES: { locale: 'en-KE', minimumFractionDigits: 2 },\n USD: { locale: 'en-US', minimumFractionDigits: 2 },\n EUR: { locale: 'de-DE', minimumFractionDigits: 2 },\n GBP: { locale: 'en-GB', minimumFractionDigits: 2 },\n };\n\n const format = currencyFormats[currency.toUpperCase()] || { locale: 'en-US', minimumFractionDigits: 2 };\n\n try {\n return new Intl.NumberFormat(format.locale, {\n style: 'currency',\n currency: currency.toUpperCase(),\n minimumFractionDigits: format.minimumFractionDigits,\n }).format(majorUnit);\n } catch {\n // Fallback for unsupported currencies\n return `${currency} ${majorUnit.toFixed(2)}`;\n }\n}\n\n/**\n * Generates a unique payment reference\n */\nexport function generateReference(prefix: string = 'reevit'): string {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 8);\n return `${prefix}_${timestamp}_${random}`;\n}\n\n/**\n * Validates a phone number for mobile money\n */\nexport function validatePhone(phone: string, country: string = 'GH'): boolean {\n // Remove non-digit characters\n const digits = phone.replace(/\\D/g, '');\n\n const patterns: Record<string, RegExp> = {\n GH: /^(?:233|0)?[235][0-9]{8}$/, // Ghana\n NG: /^(?:234|0)?[789][01][0-9]{8}$/, // Nigeria\n KE: /^(?:254|0)?[17][0-9]{8}$/, // Kenya\n };\n\n const pattern = patterns[country.toUpperCase()];\n if (!pattern) return digits.length >= 10;\n\n return pattern.test(digits);\n}\n\n/**\n * Formats a phone number for display\n */\nexport function formatPhone(phone: string, country: string = 'GH'): string {\n const digits = phone.replace(/\\D/g, '');\n\n if (country === 'GH') {\n // Format as 0XX XXX XXXX\n if (digits.startsWith('233') && digits.length === 12) {\n const local = '0' + digits.slice(3);\n return `${local.slice(0, 3)} ${local.slice(3, 6)} ${local.slice(6)}`;\n }\n if (digits.length === 10 && digits.startsWith('0')) {\n return `${digits.slice(0, 3)} ${digits.slice(3, 6)} ${digits.slice(6)}`;\n }\n }\n\n return phone;\n}\n\n/**\n * Detects mobile money network from phone number (Ghana)\n */\nexport function detectNetwork(phone: string): MobileMoneyNetwork | null {\n const digits = phone.replace(/\\D/g, '');\n\n // Get the network prefix (first 3 digits after country code or 0)\n let prefix: string;\n if (digits.startsWith('233')) {\n prefix = digits.slice(3, 5);\n } else if (digits.startsWith('0')) {\n prefix = digits.slice(1, 3);\n } else {\n prefix = digits.slice(0, 2);\n }\n\n // Ghana network prefixes\n const mtnPrefixes = ['24', '25', '53', '54', '55', '59'];\n const telecelPrefixes = ['20', '50'];\n const airteltigoPrefixes = ['26', '27', '56', '57'];\n\n if (mtnPrefixes.includes(prefix)) return 'mtn';\n if (telecelPrefixes.includes(prefix)) return 'telecel';\n if (airteltigoPrefixes.includes(prefix)) return 'airteltigo';\n\n return null;\n}\n\n/**\n * Creates CSS custom property variables from theme\n */\nexport function createThemeVariables(theme: ReevitTheme): Record<string, string> {\n const variables: Record<string, string> = {};\n\n if (theme.primaryColor) {\n variables['--reevit-primary'] = theme.primaryColor;\n if (theme.primaryForegroundColor) {\n variables['--reevit-primary-foreground'] = theme.primaryForegroundColor;\n } else {\n const contrast = getContrastingColor(theme.primaryColor);\n if (contrast) {\n variables['--reevit-primary-foreground'] = contrast;\n }\n }\n }\n if (theme.backgroundColor) {\n variables['--reevit-background'] = theme.backgroundColor;\n }\n if (theme.surfaceColor) {\n variables['--reevit-surface'] = theme.surfaceColor;\n }\n if (theme.textColor) {\n variables['--reevit-text'] = theme.textColor;\n }\n if (theme.mutedTextColor) {\n variables['--reevit-text-secondary'] = theme.mutedTextColor;\n }\n if (theme.borderRadius) {\n variables['--reevit-radius'] = theme.borderRadius;\n variables['--reevit-radius-sm'] = theme.borderRadius;\n variables['--reevit-radius-lg'] = theme.borderRadius;\n }\n if (theme.fontFamily) {\n variables['--reevit-font'] = theme.fontFamily;\n }\n\n return variables;\n}\n\nfunction getContrastingColor(color: string): string | null {\n const hex = color.trim();\n if (!hex.startsWith('#')) {\n return null;\n }\n\n const normalized = hex.length === 4\n ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`\n : hex;\n\n if (normalized.length !== 7) {\n return null;\n }\n\n const r = parseInt(normalized.slice(1, 3), 16);\n const g = parseInt(normalized.slice(3, 5), 16);\n const b = parseInt(normalized.slice(5, 7), 16);\n\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\n return null;\n }\n\n const brightness = (r * 299 + g * 587 + b * 114) / 1000;\n return brightness >= 140 ? '#0b1120' : '#ffffff';\n}\n\n/**\n * Simple class name concatenation utility\n */\nexport function cn(...classes: (string | boolean | undefined | null)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n\n/**\n * Detects country code from currency\n */\nexport function detectCountryFromCurrency(currency: string): string {\n const currencyToCountry: Record<string, string> = {\n GHS: 'GH',\n NGN: 'NG',\n KES: 'KE',\n UGX: 'UG',\n TZS: 'TZ',\n ZAR: 'ZA',\n XOF: 'CI',\n XAF: 'CM',\n USD: 'US',\n EUR: 'DE',\n GBP: 'GB',\n };\n\n return currencyToCountry[currency.toUpperCase()] || 'GH';\n}\n","/**\n * Reevit State Machine\n * Shared state management logic for all SDKs\n */\n\nimport type { CheckoutState, PaymentIntent, PaymentMethod, PaymentResult, PaymentError } from './types';\n\n// State shape\nexport interface ReevitState {\n status: CheckoutState;\n paymentIntent: PaymentIntent | null;\n selectedMethod: PaymentMethod | null;\n error: PaymentError | null;\n result: PaymentResult | null;\n}\n\n// Actions\nexport type ReevitAction =\n | { type: 'INIT_START' }\n | { type: 'INIT_SUCCESS'; payload: PaymentIntent }\n | { type: 'INIT_ERROR'; payload: PaymentError }\n | { type: 'SELECT_METHOD'; payload: PaymentMethod }\n | { type: 'PROCESS_START' }\n | { type: 'PROCESS_SUCCESS'; payload: PaymentResult }\n | { type: 'PROCESS_ERROR'; payload: PaymentError }\n | { type: 'RESET' }\n | { type: 'CLOSE' };\n\n/**\n * Creates the initial state for the checkout\n */\nexport function createInitialState(): ReevitState {\n return {\n status: 'idle',\n paymentIntent: null,\n selectedMethod: null,\n error: null,\n result: null,\n };\n}\n\n/**\n * State reducer for checkout flow\n */\nexport function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState {\n switch (action.type) {\n case 'INIT_START':\n return { ...state, status: 'loading', error: null };\n case 'INIT_SUCCESS':\n return {\n ...state,\n status: 'ready',\n paymentIntent: action.payload,\n selectedMethod:\n action.payload.availableMethods?.length === 1 ? action.payload.availableMethods[0] : null,\n };\n case 'INIT_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'SELECT_METHOD':\n return { ...state, status: 'method_selected', selectedMethod: action.payload };\n case 'PROCESS_START':\n return { ...state, status: 'processing', error: null };\n case 'PROCESS_SUCCESS':\n return { ...state, status: 'success', result: action.payload };\n case 'PROCESS_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'RESET':\n return { ...createInitialState(), status: 'ready', paymentIntent: state.paymentIntent };\n case 'CLOSE':\n return { ...state, status: 'closed' };\n default:\n return state;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqGA,IAAM,0BAA0B;AAChC,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AAKjB,SAAS,aAAa,WAA4B;AACvD,SAAO,UAAU,WAAW,UAAU,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,WAAW,KAChC,UAAU,WAAW,cAAc;AACvC;AAKA,SAAS,mBAAmB,UAAoB,WAA2C;AACzF,SAAO;AAAA,IACL,MAAM,UAAU,QAAQ;AAAA,IACxB,SAAS,UAAU,WAAW;AAAA,IAC9B,SAAS;AAAA,MACP,YAAY,SAAS;AAAA,MACrB,GAAG,UAAU;AAAA,IACf;AAAA,EACF;AACF;AAKO,IAAM,kBAAN,MAAsB;AAAA,EAK3B,YAAY,QAA+B;AACzC,SAAK,YAAY,OAAO,aAAa;AACrC,SAAK,UAAU,OAAO,YAAY,OAAO,aAAa,aAAa,OAAO,SAAS,IAC/E,uBACA;AACJ,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,QACZ,QACA,MACA,MAC6C;AAC7C,UAAM,aAAa,IAAI,gBAAgB;AACvC,UAAM,YAAY,WAAW,MAAM,WAAW,MAAM,GAAG,KAAK,OAAO;AAGnE,UAAM,UAAkC;AAAA,MACtC,gBAAgB;AAAA,MAChB,mBA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WAAW,OAAO,KAAK;AAAA,IACpD,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,QAAQ;AAAA,QACR,eAAe,OAAO;AAAA,QACtB,gBACE,OAAO,QAAQ,kBAAkB,WAAW,IAAI,OAAO,QAAQ,iBAAiB,CAAC,IAAI;AAAA,MACzF;AAAA,IACF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,mBAAmB,gBAAgB,OAAO,QAAQ;AAAA,IAC/E,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,cAAc,OAAO,KAAK;AAAA,IACvD,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,QAAQ,OAAO,QAAQ;AAAA,IAC/D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,mBAAmB,GAAG,QAAQ,SAAS,eAAe,MAAM,cAAc;AAAA,IACxF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,SAAS;AAAA,IACtC;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/client.ts","../src/utils.ts","../src/intent.ts","../src/state.ts"],"sourcesContent":["/**\n * @reevit/core\n * Shared utilities and API client for Reevit payment SDKs\n */\n\n// API Client\nexport {\n ReevitAPIClient,\n createReevitClient,\n generateIdempotencyKey,\n type ReevitAPIClientConfig,\n type CreatePaymentIntentRequest,\n type PaymentIntentResponse,\n type PaymentDetailResponse,\n type ConfirmPaymentRequest,\n type APIErrorResponse,\n} from './api/client';\n\n// Types\nexport type {\n PaymentMethod,\n MobileMoneyNetwork,\n ReevitCheckoutConfig,\n ReevitCheckoutCallbacks,\n CheckoutState,\n PaymentResult,\n PaymentError,\n ReevitTheme,\n CheckoutProviderOption,\n MobileMoneyFormData,\n CardFormData,\n PaymentIntent,\n PSPConfig,\n PSPType,\n PaymentSource,\n HubtelSessionResponse,\n} from './types';\n\n// Utilities\nexport {\n formatAmount,\n generateReference,\n validatePhone,\n formatPhone,\n detectNetwork,\n detectCountryFromCurrency,\n createThemeVariables,\n cn,\n} from './utils';\n\n// Intent identity + cache helpers\nexport {\n resolveIntentIdentity,\n getIntentCacheEntry,\n cacheIntentPromise,\n cacheIntentResponse,\n clearIntentCacheEntry,\n type IntentCacheEntry,\n} from './intent';\n\n// State machine helpers\nexport {\n createInitialState,\n reevitReducer,\n type ReevitState,\n type ReevitAction,\n} from './state';\n","/**\n * Reevit API Client\n * \n * Handles communication with the Reevit backend for payment operations.\n */\n\nimport type { PaymentMethod, ReevitCheckoutConfig, PaymentError, HubtelSessionResponse } from '../types';\n\n// API Response Types (matching backend handlers_payments.go)\nexport interface CreatePaymentIntentRequest {\n amount: number;\n currency: string;\n method?: string;\n country: string;\n customer_id?: string;\n metadata?: Record<string, unknown>;\n description?: string;\n policy?: {\n prefer?: string[];\n allowed_providers?: string[];\n max_amount?: number;\n blocked_bins?: string[];\n allowed_bins?: string[];\n velocity_max_per_minute?: number;\n };\n}\n\nexport interface PaymentIntentResponse {\n id: string;\n org_id?: string;\n connection_id: string;\n provider: string;\n status: string;\n client_secret: string;\n psp_public_key: string;\n psp_credentials?: {\n merchantAccount?: string | number;\n basicAuth?: string;\n [key: string]: unknown;\n };\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n reference?: string;\n available_psps?: Array<{\n provider: string;\n name: string;\n methods: string[];\n countries?: string[];\n }>;\n branding?: Record<string, unknown>;\n}\n\nexport interface ConfirmPaymentRequest {\n provider_ref_id: string;\n provider_data?: Record<string, unknown>;\n}\n\nexport interface PaymentDetailResponse {\n id: string;\n connection_id: string;\n provider: string;\n method: string;\n status: string;\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n customer_id?: string;\n client_secret: string;\n provider_ref_id?: string;\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n /** Payment source type (payment_link, api, subscription) */\n source?: 'payment_link' | 'api' | 'subscription';\n /** ID of the source (payment link ID, subscription ID, etc.) */\n source_id?: string;\n /** Human-readable description of the source (e.g., payment link name) */\n source_description?: string;\n}\n\nexport interface APIErrorResponse {\n code: string;\n message: string;\n details?: Record<string, string>;\n}\n\n// API Client configuration\nexport interface ReevitAPIClientConfig {\n /** Your Reevit public key */\n publicKey?: string;\n /** Base URL for the Reevit API (defaults to production) */\n baseUrl?: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n}\n\n// Default API base URLs\nconst API_BASE_URL_PRODUCTION = 'https://api.reevit.io';\nconst API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Determines if a public key is for sandbox mode\n */\nexport function isSandboxKey(publicKey: string): boolean {\n return publicKey.startsWith('pk_test_') ||\n publicKey.startsWith('pk_sandbox_') ||\n publicKey.startsWith('pfk_test_') ||\n publicKey.startsWith('pfk_sandbox_');\n}\n\n/**\n * Creates a PaymentError from an API error response\n */\nfunction createPaymentError(response: Response, errorData: APIErrorResponse): PaymentError {\n return {\n code: errorData.code || 'api_error',\n message: errorData.message || 'An unexpected error occurred',\n details: {\n httpStatus: response.status,\n ...errorData.details,\n },\n };\n}\n\n/**\n * Generates a deterministic idempotency key based on input parameters\n * Uses a simple hash function suitable for browser environments\n * Exported for use by SDK hooks (e.g., payment link flows)\n */\nexport function generateIdempotencyKey(params: Record<string, unknown>): string {\n // Create a stable string representation of the parameters\n const sortedKeys = Object.keys(params).sort();\n const stableString = sortedKeys\n .map(key => `${key}:${JSON.stringify(params[key])}`)\n .join('|');\n\n // Simple hash function (djb2 algorithm)\n let hash = 5381;\n for (let i = 0; i < stableString.length; i++) {\n hash = ((hash << 5) + hash) + stableString.charCodeAt(i);\n hash = hash & hash; // Convert to 32-bit integer\n }\n\n // Convert to positive hex string\n const hashHex = (hash >>> 0).toString(16);\n\n // Add a time bucket (5-minute windows) to allow retries within a reasonable window\n // but prevent keys from being reused across completely different sessions\n const timeBucket = Math.floor(Date.now() / (5 * 60 * 1000));\n\n return `reevit_${timeBucket}_${hashHex}`;\n}\n\n/**\n * Reevit API Client\n */\nexport class ReevitAPIClient {\n private readonly publicKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(config: ReevitAPIClientConfig) {\n this.publicKey = config.publicKey || '';\n this.baseUrl = config.baseUrl || (config.publicKey && isSandboxKey(config.publicKey)\n ? API_BASE_URL_SANDBOX\n : API_BASE_URL_PRODUCTION);\n this.timeout = config.timeout || DEFAULT_TIMEOUT;\n }\n\n /**\n * Makes an authenticated API request\n * @param idempotencyKey Optional deterministic idempotency key for the request\n */\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n idempotencyKey?: string\n ): Promise<{ data?: T; error?: PaymentError }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n // Generate headers with idempotency key for mutating requests\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Reevit-Client': '@reevit/core',\n 'X-Reevit-Client-Version': '0.5.9',\n };\n if (this.publicKey) {\n headers['X-Reevit-Key'] = this.publicKey;\n }\n\n if (method === 'POST' || method === 'PATCH' || method === 'PUT') {\n // Use provided deterministic key, or generate one based on request body\n headers['Idempotency-Key'] = idempotencyKey ||\n (body ? generateIdempotencyKey(body as Record<string, unknown>) : `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`);\n }\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n const responseData = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n return {\n error: createPaymentError(response, responseData as APIErrorResponse),\n };\n }\n\n return { data: responseData as T };\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof Error) {\n if (err.name === 'AbortError') {\n return {\n error: {\n code: 'request_timeout',\n message: 'The request timed out. Please try again.',\n },\n };\n }\n\n if (err.message.includes('Failed to fetch') || err.message.includes('NetworkError')) {\n return {\n error: {\n code: 'network_error',\n message: 'Unable to connect to Reevit. Please check your internet connection.',\n },\n };\n }\n }\n\n return {\n error: {\n code: 'unknown_error',\n message: 'An unexpected error occurred. Please try again.',\n },\n };\n }\n }\n\n /**\n * Creates a payment intent\n */\n async createPaymentIntent(\n config: ReevitCheckoutConfig,\n method?: PaymentMethod,\n country: string = 'GH',\n options?: { preferredProviders?: string[]; allowedProviders?: string[] }\n ): Promise<{ data?: PaymentIntentResponse; error?: PaymentError }> {\n // Build metadata with customer_email for PSP providers that require it\n const metadata: Record<string, unknown> = { ...config.metadata };\n if (config.email) {\n metadata.customer_email = config.email;\n }\n if (config.phone) {\n metadata.customer_phone = config.phone;\n }\n\n const request: CreatePaymentIntentRequest = {\n amount: config.amount,\n currency: config.currency,\n country,\n customer_id: config.email || (config.metadata?.customerId as string | undefined),\n metadata,\n };\n\n if (method) {\n request.method = this.mapPaymentMethod(method);\n }\n\n if (options?.preferredProviders?.length || options?.allowedProviders?.length) {\n request.policy = {\n prefer: options?.preferredProviders,\n allowed_providers: options?.allowedProviders,\n };\n }\n\n // Generate a deterministic idempotency key based on payment parameters\n // This ensures that duplicate requests for the same payment return the same intent\n const idempotencyKey = config.idempotencyKey || generateIdempotencyKey({\n amount: config.amount,\n currency: config.currency,\n customer: config.email || config.metadata?.customerId || '',\n reference: config.reference || '',\n method: method || '',\n provider: options?.preferredProviders?.[0] || options?.allowedProviders?.[0] || '',\n publicKey: this.publicKey,\n });\n\n return this.request<PaymentIntentResponse>('POST', '/v1/payments/intents', request, idempotencyKey);\n }\n\n /**\n * Retrieves a payment intent by ID\n */\n async getPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('GET', `/v1/payments/${paymentId}`);\n }\n\n /**\n * Confirms a payment after PSP callback\n */\n async confirmPayment(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm`);\n }\n\n /**\n * Confirms a payment intent using client secret (public endpoint)\n */\n async confirmPaymentIntent(paymentId: string, clientSecret: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm-intent?client_secret=${clientSecret}`);\n }\n\n /**\n * Cancels a payment intent\n */\n async cancelPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/cancel`);\n }\n\n /**\n * Creates a Hubtel session token for secure checkout\n * Returns a short-lived token that contains Hubtel credentials\n * Credentials are never exposed to the client directly\n */\n async createHubtelSession(\n paymentId: string,\n clientSecret?: string\n ): Promise<{ data?: HubtelSessionResponse; error?: PaymentError }> {\n const query = clientSecret ? `?client_secret=${encodeURIComponent(clientSecret)}` : '';\n return this.request<HubtelSessionResponse>('POST', `/v1/payments/hubtel/sessions/${paymentId}${query}`);\n }\n\n /**\n * Maps SDK payment method to backend format\n */\n private mapPaymentMethod(method: PaymentMethod): string {\n switch (method) {\n case 'card':\n return 'card';\n case 'mobile_money':\n return 'mobile_money';\n case 'bank_transfer':\n return 'bank_transfer';\n default:\n return method;\n }\n }\n}\n\n/**\n * Creates a new Reevit API client instance\n */\nexport function createReevitClient(config: ReevitAPIClientConfig): ReevitAPIClient {\n return new ReevitAPIClient(config);\n}\n","/**\n * Utility Functions\n * Shared utilities for Reevit SDKs\n */\n\nimport type { MobileMoneyNetwork, ReevitTheme } from './types';\n\n/**\n * Formats an amount from smallest currency unit to display format\n */\nexport function formatAmount(amount: number, currency: string): string {\n const majorUnit = amount / 100;\n\n const currencyFormats: Record<string, { locale: string; minimumFractionDigits: number }> = {\n GHS: { locale: 'en-GH', minimumFractionDigits: 2 },\n NGN: { locale: 'en-NG', minimumFractionDigits: 2 },\n KES: { locale: 'en-KE', minimumFractionDigits: 2 },\n USD: { locale: 'en-US', minimumFractionDigits: 2 },\n EUR: { locale: 'de-DE', minimumFractionDigits: 2 },\n GBP: { locale: 'en-GB', minimumFractionDigits: 2 },\n };\n\n const format = currencyFormats[currency.toUpperCase()] || { locale: 'en-US', minimumFractionDigits: 2 };\n\n try {\n return new Intl.NumberFormat(format.locale, {\n style: 'currency',\n currency: currency.toUpperCase(),\n minimumFractionDigits: format.minimumFractionDigits,\n }).format(majorUnit);\n } catch {\n // Fallback for unsupported currencies\n return `${currency} ${majorUnit.toFixed(2)}`;\n }\n}\n\n/**\n * Generates a unique payment reference\n */\nexport function generateReference(prefix: string = 'reevit'): string {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 8);\n return `${prefix}_${timestamp}_${random}`;\n}\n\n/**\n * Validates a phone number for mobile money\n */\nexport function validatePhone(phone: string, country: string = 'GH'): boolean {\n // Remove non-digit characters\n const digits = phone.replace(/\\D/g, '');\n\n const patterns: Record<string, RegExp> = {\n GH: /^(?:233|0)?[235][0-9]{8}$/, // Ghana\n NG: /^(?:234|0)?[789][01][0-9]{8}$/, // Nigeria\n KE: /^(?:254|0)?[17][0-9]{8}$/, // Kenya\n };\n\n const pattern = patterns[country.toUpperCase()];\n if (!pattern) return digits.length >= 10;\n\n return pattern.test(digits);\n}\n\n/**\n * Formats a phone number for display\n */\nexport function formatPhone(phone: string, country: string = 'GH'): string {\n const digits = phone.replace(/\\D/g, '');\n\n if (country === 'GH') {\n // Format as 0XX XXX XXXX\n if (digits.startsWith('233') && digits.length === 12) {\n const local = '0' + digits.slice(3);\n return `${local.slice(0, 3)} ${local.slice(3, 6)} ${local.slice(6)}`;\n }\n if (digits.length === 10 && digits.startsWith('0')) {\n return `${digits.slice(0, 3)} ${digits.slice(3, 6)} ${digits.slice(6)}`;\n }\n }\n\n return phone;\n}\n\n/**\n * Detects mobile money network from phone number (Ghana)\n */\nexport function detectNetwork(phone: string): MobileMoneyNetwork | null {\n const digits = phone.replace(/\\D/g, '');\n\n // Get the network prefix (first 3 digits after country code or 0)\n let prefix: string;\n if (digits.startsWith('233')) {\n prefix = digits.slice(3, 5);\n } else if (digits.startsWith('0')) {\n prefix = digits.slice(1, 3);\n } else {\n prefix = digits.slice(0, 2);\n }\n\n // Ghana network prefixes\n const mtnPrefixes = ['24', '25', '53', '54', '55', '59'];\n const telecelPrefixes = ['20', '50'];\n const airteltigoPrefixes = ['26', '27', '56', '57'];\n\n if (mtnPrefixes.includes(prefix)) return 'mtn';\n if (telecelPrefixes.includes(prefix)) return 'telecel';\n if (airteltigoPrefixes.includes(prefix)) return 'airteltigo';\n\n return null;\n}\n\n/**\n * Creates CSS custom property variables from theme\n */\nexport function createThemeVariables(theme: ReevitTheme): Record<string, string> {\n const variables: Record<string, string> = {};\n\n // Primary color = main text color\n if (theme.primaryColor) {\n variables['--reevit-text'] = theme.primaryColor;\n }\n\n // Primary foreground = description/secondary text color\n if (theme.primaryForegroundColor) {\n variables['--reevit-text-secondary'] = theme.primaryForegroundColor;\n variables['--reevit-muted'] = theme.primaryForegroundColor;\n }\n\n // Button colors\n if (theme.buttonBackgroundColor) {\n variables['--reevit-primary'] = theme.buttonBackgroundColor;\n variables['--reevit-primary-hover'] = theme.buttonBackgroundColor;\n }\n if (theme.buttonTextColor) {\n variables['--reevit-primary-foreground'] = theme.buttonTextColor;\n }\n\n // Background and surface colors\n if (theme.backgroundColor) {\n variables['--reevit-background'] = theme.backgroundColor;\n variables['--reevit-surface'] = theme.backgroundColor;\n }\n if (theme.surfaceColor) {\n variables['--reevit-surface'] = theme.surfaceColor;\n }\n\n // Border color\n if (theme.borderColor) {\n variables['--reevit-border'] = theme.borderColor;\n }\n\n // Legacy text color support\n if (theme.textColor) {\n variables['--reevit-text'] = theme.textColor;\n }\n if (theme.mutedTextColor) {\n variables['--reevit-text-secondary'] = theme.mutedTextColor;\n }\n\n // Border radius\n if (theme.borderRadius) {\n variables['--reevit-radius'] = theme.borderRadius;\n variables['--reevit-radius-sm'] = theme.borderRadius;\n variables['--reevit-radius-lg'] = theme.borderRadius;\n }\n\n // Font family\n if (theme.fontFamily) {\n variables['--reevit-font'] = theme.fontFamily;\n }\n\n return variables;\n}\n\nfunction getContrastingColor(color: string): string | null {\n const hex = color.trim();\n if (!hex.startsWith('#')) {\n return null;\n }\n\n const normalized = hex.length === 4\n ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`\n : hex;\n\n if (normalized.length !== 7) {\n return null;\n }\n\n const r = parseInt(normalized.slice(1, 3), 16);\n const g = parseInt(normalized.slice(3, 5), 16);\n const b = parseInt(normalized.slice(5, 7), 16);\n\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\n return null;\n }\n\n const brightness = (r * 299 + g * 587 + b * 114) / 1000;\n return brightness >= 140 ? '#0b1120' : '#ffffff';\n}\n\n/**\n * Simple class name concatenation utility\n */\nexport function cn(...classes: (string | boolean | undefined | null)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n\n/**\n * Detects country code from currency\n */\nexport function detectCountryFromCurrency(currency: string): string {\n const currencyToCountry: Record<string, string> = {\n GHS: 'GH',\n NGN: 'NG',\n KES: 'KE',\n UGX: 'UG',\n TZS: 'TZ',\n ZAR: 'ZA',\n XOF: 'CI',\n XAF: 'CM',\n USD: 'US',\n EUR: 'DE',\n GBP: 'GB',\n };\n\n return currencyToCountry[currency.toUpperCase()] || 'GH';\n}\n","/**\n * Intent identity + cache helpers\n */\n\nimport type { PaymentIntentResponse } from './api/client';\nimport { generateIdempotencyKey } from './api/client';\nimport type { PaymentMethod, ReevitCheckoutConfig } from './types';\nimport { generateReference } from './utils';\n\nconst INTENT_CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes\n\nexport interface IntentIdentityOptions {\n config: ReevitCheckoutConfig;\n method?: PaymentMethod;\n preferredProvider?: string;\n allowedProviders?: string[];\n publicKey?: string;\n}\n\nexport interface IntentCacheEntry {\n promise?: Promise<PaymentIntentResponse>;\n response?: PaymentIntentResponse;\n expiresAt: number;\n reference?: string;\n}\n\nconst intentCache = new Map<string, IntentCacheEntry>();\n\nfunction pruneIntentCache(now: number = Date.now()): void {\n for (const [key, entry] of intentCache) {\n if (entry.expiresAt <= now) {\n intentCache.delete(key);\n }\n }\n}\n\nfunction getIntentCacheEntryInternal(key: string): IntentCacheEntry | undefined {\n const entry = intentCache.get(key);\n if (!entry) {\n return undefined;\n }\n if (entry.expiresAt <= Date.now()) {\n intentCache.delete(key);\n return undefined;\n }\n return entry;\n}\n\nfunction setIntentCacheEntryInternal(key: string, update: Partial<IntentCacheEntry>): IntentCacheEntry {\n const now = Date.now();\n const existing = getIntentCacheEntryInternal(key);\n const next: IntentCacheEntry = {\n ...existing,\n ...update,\n expiresAt: now + INTENT_CACHE_TTL_MS,\n };\n intentCache.set(key, next);\n return next;\n}\n\nfunction buildIdempotencyPayload(options: IntentIdentityOptions): Record<string, unknown> {\n const { config, method, preferredProvider, allowedProviders, publicKey } = options;\n const payload: Record<string, unknown> = {\n amount: config.amount,\n currency: config.currency,\n email: config.email || '',\n phone: config.phone || '',\n customerName: config.customerName || '',\n paymentLinkCode: config.paymentLinkCode || '',\n paymentMethods: config.paymentMethods || [],\n metadata: config.metadata || {},\n customFields: config.customFields || {},\n method: method || '',\n preferredProvider: preferredProvider || '',\n allowedProviders: allowedProviders || [],\n publicKey: publicKey || config.publicKey || '',\n };\n\n if (config.reference) {\n payload.reference = config.reference;\n }\n\n return payload;\n}\n\nexport function resolveIntentIdentity(options: IntentIdentityOptions): {\n idempotencyKey: string;\n reference: string;\n cacheEntry?: IntentCacheEntry;\n} {\n pruneIntentCache();\n\n const idempotencyKey =\n options.config.idempotencyKey || generateIdempotencyKey(buildIdempotencyPayload(options));\n const existing = getIntentCacheEntryInternal(idempotencyKey);\n const reference = options.config.reference || existing?.reference || generateReference();\n\n const cacheEntry = setIntentCacheEntryInternal(idempotencyKey, { reference });\n\n return { idempotencyKey, reference, cacheEntry };\n}\n\nexport function getIntentCacheEntry(idempotencyKey: string): IntentCacheEntry | undefined {\n pruneIntentCache();\n return getIntentCacheEntryInternal(idempotencyKey);\n}\n\nexport function cacheIntentPromise(\n idempotencyKey: string,\n promise: Promise<PaymentIntentResponse>\n): IntentCacheEntry {\n return setIntentCacheEntryInternal(idempotencyKey, { promise });\n}\n\nexport function cacheIntentResponse(\n idempotencyKey: string,\n response: PaymentIntentResponse\n): IntentCacheEntry {\n return setIntentCacheEntryInternal(idempotencyKey, { response, promise: undefined });\n}\n\nexport function clearIntentCacheEntry(idempotencyKey: string): void {\n intentCache.delete(idempotencyKey);\n}\n","/**\n * Reevit State Machine\n * Shared state management logic for all SDKs\n */\n\nimport type { CheckoutState, PaymentIntent, PaymentMethod, PaymentResult, PaymentError } from './types';\n\n// State shape\nexport interface ReevitState {\n status: CheckoutState;\n paymentIntent: PaymentIntent | null;\n selectedMethod: PaymentMethod | null;\n error: PaymentError | null;\n result: PaymentResult | null;\n}\n\n// Actions\nexport type ReevitAction =\n | { type: 'INIT_START' }\n | { type: 'INIT_SUCCESS'; payload: PaymentIntent }\n | { type: 'INIT_ERROR'; payload: PaymentError }\n | { type: 'SELECT_METHOD'; payload: PaymentMethod }\n | { type: 'PROCESS_START' }\n | { type: 'PROCESS_SUCCESS'; payload: PaymentResult }\n | { type: 'PROCESS_ERROR'; payload: PaymentError }\n | { type: 'RESET' }\n | { type: 'CLOSE' };\n\n/**\n * Creates the initial state for the checkout\n */\nexport function createInitialState(): ReevitState {\n return {\n status: 'idle',\n paymentIntent: null,\n selectedMethod: null,\n error: null,\n result: null,\n };\n}\n\n/**\n * State reducer for checkout flow\n */\nexport function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState {\n switch (action.type) {\n case 'INIT_START':\n return { ...state, status: 'loading', error: null };\n case 'INIT_SUCCESS':\n return {\n ...state,\n status: 'ready',\n paymentIntent: action.payload,\n selectedMethod:\n action.payload.availableMethods?.length === 1 ? action.payload.availableMethods[0] : null,\n };\n case 'INIT_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'SELECT_METHOD':\n return { ...state, status: 'method_selected', selectedMethod: action.payload };\n case 'PROCESS_START':\n return { ...state, status: 'processing', error: null };\n case 'PROCESS_SUCCESS':\n return { ...state, status: 'success', result: action.payload };\n case 'PROCESS_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'RESET':\n return { ...createInitialState(), status: 'ready', paymentIntent: state.paymentIntent };\n case 'CLOSE':\n return { ...state, status: 'closed' };\n default:\n return state;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsGA,IAAM,0BAA0B;AAChC,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AAKjB,SAAS,aAAa,WAA4B;AACvD,SAAO,UAAU,WAAW,UAAU,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,WAAW,KAChC,UAAU,WAAW,cAAc;AACvC;AAKA,SAAS,mBAAmB,UAAoB,WAA2C;AACzF,SAAO;AAAA,IACL,MAAM,UAAU,QAAQ;AAAA,IACxB,SAAS,UAAU,WAAW;AAAA,IAC9B,SAAS;AAAA,MACP,YAAY,SAAS;AAAA,MACrB,GAAG,UAAU;AAAA,IACf;AAAA,EACF;AACF;AAOO,SAAS,uBAAuB,QAAyC;AAE9E,QAAM,aAAa,OAAO,KAAK,MAAM,EAAE,KAAK;AAC5C,QAAM,eAAe,WAClB,IAAI,SAAO,GAAG,GAAG,IAAI,KAAK,UAAU,OAAO,GAAG,CAAC,CAAC,EAAE,EAClD,KAAK,GAAG;AAGX,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IA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QACL,GAAG;AAAA,QACH,QAAQ;AAAA,QACR,eAAe,OAAO;AAAA,QACtB,gBACE,OAAO,QAAQ,kBAAkB,WAAW,IAAI,OAAO,QAAQ,iBAAiB,CAAC,IAAI;AAAA,MACzF;AAAA,IACF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,mBAAmB,gBAAgB,OAAO,QAAQ;AAAA,IAC/E,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,cAAc,OAAO,KAAK;AAAA,IACvD,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,QAAQ,OAAO,QAAQ;AAAA,IAC/D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,mBAAmB,GAAG,QAAQ,SAAS,eAAe,MAAM,cAAc;AAAA,IACxF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,SAAS;AAAA,IACtC;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,18 @@ function createPaymentError(response, errorData) {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
function generateIdempotencyKey(params) {
|
|
19
|
+
const sortedKeys = Object.keys(params).sort();
|
|
20
|
+
const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(params[key])}`).join("|");
|
|
21
|
+
let hash = 5381;
|
|
22
|
+
for (let i = 0; i < stableString.length; i++) {
|
|
23
|
+
hash = (hash << 5) + hash + stableString.charCodeAt(i);
|
|
24
|
+
hash = hash & hash;
|
|
25
|
+
}
|
|
26
|
+
const hashHex = (hash >>> 0).toString(16);
|
|
27
|
+
const timeBucket = Math.floor(Date.now() / (5 * 60 * 1e3));
|
|
28
|
+
return `reevit_${timeBucket}_${hashHex}`;
|
|
29
|
+
}
|
|
18
30
|
var ReevitAPIClient = class {
|
|
19
31
|
constructor(config) {
|
|
20
32
|
this.publicKey = config.publicKey || "";
|
|
@@ -23,20 +35,21 @@ var ReevitAPIClient = class {
|
|
|
23
35
|
}
|
|
24
36
|
/**
|
|
25
37
|
* Makes an authenticated API request
|
|
38
|
+
* @param idempotencyKey Optional deterministic idempotency key for the request
|
|
26
39
|
*/
|
|
27
|
-
async request(method, path, body) {
|
|
40
|
+
async request(method, path, body, idempotencyKey) {
|
|
28
41
|
const controller = new AbortController();
|
|
29
42
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
30
43
|
const headers = {
|
|
31
44
|
"Content-Type": "application/json",
|
|
32
45
|
"X-Reevit-Client": "@reevit/core",
|
|
33
|
-
"X-Reevit-Client-Version": "0.
|
|
46
|
+
"X-Reevit-Client-Version": "0.5.9"
|
|
34
47
|
};
|
|
35
48
|
if (this.publicKey) {
|
|
36
49
|
headers["X-Reevit-Key"] = this.publicKey;
|
|
37
50
|
}
|
|
38
51
|
if (method === "POST" || method === "PATCH" || method === "PUT") {
|
|
39
|
-
headers["Idempotency-Key"] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}
|
|
52
|
+
headers["Idempotency-Key"] = idempotencyKey || (body ? generateIdempotencyKey(body) : `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`);
|
|
40
53
|
}
|
|
41
54
|
try {
|
|
42
55
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
@@ -108,7 +121,16 @@ var ReevitAPIClient = class {
|
|
|
108
121
|
allowed_providers: options?.allowedProviders
|
|
109
122
|
};
|
|
110
123
|
}
|
|
111
|
-
|
|
124
|
+
const idempotencyKey = config.idempotencyKey || generateIdempotencyKey({
|
|
125
|
+
amount: config.amount,
|
|
126
|
+
currency: config.currency,
|
|
127
|
+
customer: config.email || config.metadata?.customerId || "",
|
|
128
|
+
reference: config.reference || "",
|
|
129
|
+
method: method || "",
|
|
130
|
+
provider: options?.preferredProviders?.[0] || options?.allowedProviders?.[0] || "",
|
|
131
|
+
publicKey: this.publicKey
|
|
132
|
+
});
|
|
133
|
+
return this.request("POST", "/v1/payments/intents", request, idempotencyKey);
|
|
112
134
|
}
|
|
113
135
|
/**
|
|
114
136
|
* Retrieves a payment intent by ID
|
|
@@ -238,22 +260,29 @@ function detectNetwork(phone) {
|
|
|
238
260
|
function createThemeVariables(theme) {
|
|
239
261
|
const variables = {};
|
|
240
262
|
if (theme.primaryColor) {
|
|
241
|
-
variables["--reevit-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
263
|
+
variables["--reevit-text"] = theme.primaryColor;
|
|
264
|
+
}
|
|
265
|
+
if (theme.primaryForegroundColor) {
|
|
266
|
+
variables["--reevit-text-secondary"] = theme.primaryForegroundColor;
|
|
267
|
+
variables["--reevit-muted"] = theme.primaryForegroundColor;
|
|
268
|
+
}
|
|
269
|
+
if (theme.buttonBackgroundColor) {
|
|
270
|
+
variables["--reevit-primary"] = theme.buttonBackgroundColor;
|
|
271
|
+
variables["--reevit-primary-hover"] = theme.buttonBackgroundColor;
|
|
272
|
+
}
|
|
273
|
+
if (theme.buttonTextColor) {
|
|
274
|
+
variables["--reevit-primary-foreground"] = theme.buttonTextColor;
|
|
250
275
|
}
|
|
251
276
|
if (theme.backgroundColor) {
|
|
252
277
|
variables["--reevit-background"] = theme.backgroundColor;
|
|
278
|
+
variables["--reevit-surface"] = theme.backgroundColor;
|
|
253
279
|
}
|
|
254
280
|
if (theme.surfaceColor) {
|
|
255
281
|
variables["--reevit-surface"] = theme.surfaceColor;
|
|
256
282
|
}
|
|
283
|
+
if (theme.borderColor) {
|
|
284
|
+
variables["--reevit-border"] = theme.borderColor;
|
|
285
|
+
}
|
|
257
286
|
if (theme.textColor) {
|
|
258
287
|
variables["--reevit-text"] = theme.textColor;
|
|
259
288
|
}
|
|
@@ -270,24 +299,6 @@ function createThemeVariables(theme) {
|
|
|
270
299
|
}
|
|
271
300
|
return variables;
|
|
272
301
|
}
|
|
273
|
-
function getContrastingColor(color) {
|
|
274
|
-
const hex = color.trim();
|
|
275
|
-
if (!hex.startsWith("#")) {
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
const normalized = hex.length === 4 ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}` : hex;
|
|
279
|
-
if (normalized.length !== 7) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
const r = parseInt(normalized.slice(1, 3), 16);
|
|
283
|
-
const g = parseInt(normalized.slice(3, 5), 16);
|
|
284
|
-
const b = parseInt(normalized.slice(5, 7), 16);
|
|
285
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
const brightness = (r * 299 + g * 587 + b * 114) / 1e3;
|
|
289
|
-
return brightness >= 140 ? "#0b1120" : "#ffffff";
|
|
290
|
-
}
|
|
291
302
|
function cn(...classes) {
|
|
292
303
|
return classes.filter(Boolean).join(" ");
|
|
293
304
|
}
|
|
@@ -308,6 +319,82 @@ function detectCountryFromCurrency(currency) {
|
|
|
308
319
|
return currencyToCountry[currency.toUpperCase()] || "GH";
|
|
309
320
|
}
|
|
310
321
|
|
|
322
|
+
// src/intent.ts
|
|
323
|
+
var INTENT_CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
324
|
+
var intentCache = /* @__PURE__ */ new Map();
|
|
325
|
+
function pruneIntentCache(now = Date.now()) {
|
|
326
|
+
for (const [key, entry] of intentCache) {
|
|
327
|
+
if (entry.expiresAt <= now) {
|
|
328
|
+
intentCache.delete(key);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function getIntentCacheEntryInternal(key) {
|
|
333
|
+
const entry = intentCache.get(key);
|
|
334
|
+
if (!entry) {
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
if (entry.expiresAt <= Date.now()) {
|
|
338
|
+
intentCache.delete(key);
|
|
339
|
+
return void 0;
|
|
340
|
+
}
|
|
341
|
+
return entry;
|
|
342
|
+
}
|
|
343
|
+
function setIntentCacheEntryInternal(key, update) {
|
|
344
|
+
const now = Date.now();
|
|
345
|
+
const existing = getIntentCacheEntryInternal(key);
|
|
346
|
+
const next = {
|
|
347
|
+
...existing,
|
|
348
|
+
...update,
|
|
349
|
+
expiresAt: now + INTENT_CACHE_TTL_MS
|
|
350
|
+
};
|
|
351
|
+
intentCache.set(key, next);
|
|
352
|
+
return next;
|
|
353
|
+
}
|
|
354
|
+
function buildIdempotencyPayload(options) {
|
|
355
|
+
const { config, method, preferredProvider, allowedProviders, publicKey } = options;
|
|
356
|
+
const payload = {
|
|
357
|
+
amount: config.amount,
|
|
358
|
+
currency: config.currency,
|
|
359
|
+
email: config.email || "",
|
|
360
|
+
phone: config.phone || "",
|
|
361
|
+
customerName: config.customerName || "",
|
|
362
|
+
paymentLinkCode: config.paymentLinkCode || "",
|
|
363
|
+
paymentMethods: config.paymentMethods || [],
|
|
364
|
+
metadata: config.metadata || {},
|
|
365
|
+
customFields: config.customFields || {},
|
|
366
|
+
method: method || "",
|
|
367
|
+
preferredProvider: preferredProvider || "",
|
|
368
|
+
allowedProviders: allowedProviders || [],
|
|
369
|
+
publicKey: publicKey || config.publicKey || ""
|
|
370
|
+
};
|
|
371
|
+
if (config.reference) {
|
|
372
|
+
payload.reference = config.reference;
|
|
373
|
+
}
|
|
374
|
+
return payload;
|
|
375
|
+
}
|
|
376
|
+
function resolveIntentIdentity(options) {
|
|
377
|
+
pruneIntentCache();
|
|
378
|
+
const idempotencyKey = options.config.idempotencyKey || generateIdempotencyKey(buildIdempotencyPayload(options));
|
|
379
|
+
const existing = getIntentCacheEntryInternal(idempotencyKey);
|
|
380
|
+
const reference = options.config.reference || existing?.reference || generateReference();
|
|
381
|
+
const cacheEntry = setIntentCacheEntryInternal(idempotencyKey, { reference });
|
|
382
|
+
return { idempotencyKey, reference, cacheEntry };
|
|
383
|
+
}
|
|
384
|
+
function getIntentCacheEntry(idempotencyKey) {
|
|
385
|
+
pruneIntentCache();
|
|
386
|
+
return getIntentCacheEntryInternal(idempotencyKey);
|
|
387
|
+
}
|
|
388
|
+
function cacheIntentPromise(idempotencyKey, promise) {
|
|
389
|
+
return setIntentCacheEntryInternal(idempotencyKey, { promise });
|
|
390
|
+
}
|
|
391
|
+
function cacheIntentResponse(idempotencyKey, response) {
|
|
392
|
+
return setIntentCacheEntryInternal(idempotencyKey, { response, promise: void 0 });
|
|
393
|
+
}
|
|
394
|
+
function clearIntentCacheEntry(idempotencyKey) {
|
|
395
|
+
intentCache.delete(idempotencyKey);
|
|
396
|
+
}
|
|
397
|
+
|
|
311
398
|
// src/state.ts
|
|
312
399
|
function createInitialState() {
|
|
313
400
|
return {
|
|
@@ -349,6 +436,9 @@ function reevitReducer(state, action) {
|
|
|
349
436
|
}
|
|
350
437
|
export {
|
|
351
438
|
ReevitAPIClient,
|
|
439
|
+
cacheIntentPromise,
|
|
440
|
+
cacheIntentResponse,
|
|
441
|
+
clearIntentCacheEntry,
|
|
352
442
|
cn,
|
|
353
443
|
createInitialState,
|
|
354
444
|
createReevitClient,
|
|
@@ -357,8 +447,11 @@ export {
|
|
|
357
447
|
detectNetwork,
|
|
358
448
|
formatAmount,
|
|
359
449
|
formatPhone,
|
|
450
|
+
generateIdempotencyKey,
|
|
360
451
|
generateReference,
|
|
452
|
+
getIntentCacheEntry,
|
|
361
453
|
reevitReducer,
|
|
454
|
+
resolveIntentIdentity,
|
|
362
455
|
validatePhone
|
|
363
456
|
};
|
|
364
457
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/client.ts","../src/utils.ts","../src/state.ts"],"sourcesContent":["/**\n * Reevit API Client\n * \n * Handles communication with the Reevit backend for payment operations.\n */\n\nimport type { PaymentMethod, ReevitCheckoutConfig, PaymentError, HubtelSessionResponse } from '../types';\n\n// API Response Types (matching backend handlers_payments.go)\nexport interface CreatePaymentIntentRequest {\n amount: number;\n currency: string;\n method?: string;\n country: string;\n customer_id?: string;\n metadata?: Record<string, unknown>;\n description?: string;\n policy?: {\n prefer?: string[];\n allowed_providers?: string[];\n max_amount?: number;\n blocked_bins?: string[];\n allowed_bins?: string[];\n velocity_max_per_minute?: number;\n };\n}\n\nexport interface PaymentIntentResponse {\n id: string;\n connection_id: string;\n provider: string;\n status: string;\n client_secret: string;\n psp_public_key: string;\n psp_credentials?: {\n merchantAccount?: string | number;\n basicAuth?: string;\n [key: string]: unknown;\n };\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n reference?: string;\n available_psps?: Array<{\n provider: string;\n name: string;\n methods: string[];\n countries?: string[];\n }>;\n branding?: Record<string, unknown>;\n}\n\nexport interface ConfirmPaymentRequest {\n provider_ref_id: string;\n provider_data?: Record<string, unknown>;\n}\n\nexport interface PaymentDetailResponse {\n id: string;\n connection_id: string;\n provider: string;\n method: string;\n status: string;\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n customer_id?: string;\n client_secret: string;\n provider_ref_id?: string;\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n /** Payment source type (payment_link, api, subscription) */\n source?: 'payment_link' | 'api' | 'subscription';\n /** ID of the source (payment link ID, subscription ID, etc.) */\n source_id?: string;\n /** Human-readable description of the source (e.g., payment link name) */\n source_description?: string;\n}\n\nexport interface APIErrorResponse {\n code: string;\n message: string;\n details?: Record<string, string>;\n}\n\n// API Client configuration\nexport interface ReevitAPIClientConfig {\n /** Your Reevit public key */\n publicKey?: string;\n /** Base URL for the Reevit API (defaults to production) */\n baseUrl?: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n}\n\n// Default API base URLs\nconst API_BASE_URL_PRODUCTION = 'https://api.reevit.io';\nconst API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Determines if a public key is for sandbox mode\n */\nexport function isSandboxKey(publicKey: string): boolean {\n return publicKey.startsWith('pk_test_') ||\n publicKey.startsWith('pk_sandbox_') ||\n publicKey.startsWith('pfk_test_') ||\n publicKey.startsWith('pfk_sandbox_');\n}\n\n/**\n * Creates a PaymentError from an API error response\n */\nfunction createPaymentError(response: Response, errorData: APIErrorResponse): PaymentError {\n return {\n code: errorData.code || 'api_error',\n message: errorData.message || 'An unexpected error occurred',\n details: {\n httpStatus: response.status,\n ...errorData.details,\n },\n };\n}\n\n/**\n * Reevit API Client\n */\nexport class ReevitAPIClient {\n private readonly publicKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(config: ReevitAPIClientConfig) {\n this.publicKey = config.publicKey || '';\n this.baseUrl = config.baseUrl || (config.publicKey && isSandboxKey(config.publicKey)\n ? API_BASE_URL_SANDBOX\n : API_BASE_URL_PRODUCTION);\n this.timeout = config.timeout || DEFAULT_TIMEOUT;\n }\n\n /**\n * Makes an authenticated API request\n */\n private async request<T>(\n method: string,\n path: string,\n body?: unknown\n ): Promise<{ data?: T; error?: PaymentError }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n // Generate headers with idempotency key for mutating requests\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Reevit-Client': '@reevit/core',\n 'X-Reevit-Client-Version': '0.3.2',\n };\n if (this.publicKey) {\n headers['X-Reevit-Key'] = this.publicKey;\n }\n\n if (method === 'POST' || method === 'PATCH' || method === 'PUT') {\n headers['Idempotency-Key'] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;\n }\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n const responseData = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n return {\n error: createPaymentError(response, responseData as APIErrorResponse),\n };\n }\n\n return { data: responseData as T };\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof Error) {\n if (err.name === 'AbortError') {\n return {\n error: {\n code: 'request_timeout',\n message: 'The request timed out. Please try again.',\n },\n };\n }\n\n if (err.message.includes('Failed to fetch') || err.message.includes('NetworkError')) {\n return {\n error: {\n code: 'network_error',\n message: 'Unable to connect to Reevit. Please check your internet connection.',\n },\n };\n }\n }\n\n return {\n error: {\n code: 'unknown_error',\n message: 'An unexpected error occurred. Please try again.',\n },\n };\n }\n }\n\n /**\n * Creates a payment intent\n */\n async createPaymentIntent(\n config: ReevitCheckoutConfig,\n method?: PaymentMethod,\n country: string = 'GH',\n options?: { preferredProviders?: string[]; allowedProviders?: string[] }\n ): Promise<{ data?: PaymentIntentResponse; error?: PaymentError }> {\n // Build metadata with customer_email for PSP providers that require it\n const metadata: Record<string, unknown> = { ...config.metadata };\n if (config.email) {\n metadata.customer_email = config.email;\n }\n if (config.phone) {\n metadata.customer_phone = config.phone;\n }\n\n const request: CreatePaymentIntentRequest = {\n amount: config.amount,\n currency: config.currency,\n country,\n customer_id: config.email || (config.metadata?.customerId as string | undefined),\n metadata,\n };\n\n if (method) {\n request.method = this.mapPaymentMethod(method);\n }\n\n if (options?.preferredProviders?.length || options?.allowedProviders?.length) {\n request.policy = {\n prefer: options?.preferredProviders,\n allowed_providers: options?.allowedProviders,\n };\n }\n\n return this.request<PaymentIntentResponse>('POST', '/v1/payments/intents', request);\n }\n\n /**\n * Retrieves a payment intent by ID\n */\n async getPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('GET', `/v1/payments/${paymentId}`);\n }\n\n /**\n * Confirms a payment after PSP callback\n */\n async confirmPayment(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm`);\n }\n\n /**\n * Confirms a payment intent using client secret (public endpoint)\n */\n async confirmPaymentIntent(paymentId: string, clientSecret: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm-intent?client_secret=${clientSecret}`);\n }\n\n /**\n * Cancels a payment intent\n */\n async cancelPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/cancel`);\n }\n\n /**\n * Creates a Hubtel session token for secure checkout\n * Returns a short-lived token that contains Hubtel credentials\n * Credentials are never exposed to the client directly\n */\n async createHubtelSession(\n paymentId: string,\n clientSecret?: string\n ): Promise<{ data?: HubtelSessionResponse; error?: PaymentError }> {\n const query = clientSecret ? `?client_secret=${encodeURIComponent(clientSecret)}` : '';\n return this.request<HubtelSessionResponse>('POST', `/v1/payments/hubtel/sessions/${paymentId}${query}`);\n }\n\n /**\n * Maps SDK payment method to backend format\n */\n private mapPaymentMethod(method: PaymentMethod): string {\n switch (method) {\n case 'card':\n return 'card';\n case 'mobile_money':\n return 'mobile_money';\n case 'bank_transfer':\n return 'bank_transfer';\n default:\n return method;\n }\n }\n}\n\n/**\n * Creates a new Reevit API client instance\n */\nexport function createReevitClient(config: ReevitAPIClientConfig): ReevitAPIClient {\n return new ReevitAPIClient(config);\n}\n","/**\n * Utility Functions\n * Shared utilities for Reevit SDKs\n */\n\nimport type { MobileMoneyNetwork, ReevitTheme } from './types';\n\n/**\n * Formats an amount from smallest currency unit to display format\n */\nexport function formatAmount(amount: number, currency: string): string {\n const majorUnit = amount / 100;\n\n const currencyFormats: Record<string, { locale: string; minimumFractionDigits: number }> = {\n GHS: { locale: 'en-GH', minimumFractionDigits: 2 },\n NGN: { locale: 'en-NG', minimumFractionDigits: 2 },\n KES: { locale: 'en-KE', minimumFractionDigits: 2 },\n USD: { locale: 'en-US', minimumFractionDigits: 2 },\n EUR: { locale: 'de-DE', minimumFractionDigits: 2 },\n GBP: { locale: 'en-GB', minimumFractionDigits: 2 },\n };\n\n const format = currencyFormats[currency.toUpperCase()] || { locale: 'en-US', minimumFractionDigits: 2 };\n\n try {\n return new Intl.NumberFormat(format.locale, {\n style: 'currency',\n currency: currency.toUpperCase(),\n minimumFractionDigits: format.minimumFractionDigits,\n }).format(majorUnit);\n } catch {\n // Fallback for unsupported currencies\n return `${currency} ${majorUnit.toFixed(2)}`;\n }\n}\n\n/**\n * Generates a unique payment reference\n */\nexport function generateReference(prefix: string = 'reevit'): string {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 8);\n return `${prefix}_${timestamp}_${random}`;\n}\n\n/**\n * Validates a phone number for mobile money\n */\nexport function validatePhone(phone: string, country: string = 'GH'): boolean {\n // Remove non-digit characters\n const digits = phone.replace(/\\D/g, '');\n\n const patterns: Record<string, RegExp> = {\n GH: /^(?:233|0)?[235][0-9]{8}$/, // Ghana\n NG: /^(?:234|0)?[789][01][0-9]{8}$/, // Nigeria\n KE: /^(?:254|0)?[17][0-9]{8}$/, // Kenya\n };\n\n const pattern = patterns[country.toUpperCase()];\n if (!pattern) return digits.length >= 10;\n\n return pattern.test(digits);\n}\n\n/**\n * Formats a phone number for display\n */\nexport function formatPhone(phone: string, country: string = 'GH'): string {\n const digits = phone.replace(/\\D/g, '');\n\n if (country === 'GH') {\n // Format as 0XX XXX XXXX\n if (digits.startsWith('233') && digits.length === 12) {\n const local = '0' + digits.slice(3);\n return `${local.slice(0, 3)} ${local.slice(3, 6)} ${local.slice(6)}`;\n }\n if (digits.length === 10 && digits.startsWith('0')) {\n return `${digits.slice(0, 3)} ${digits.slice(3, 6)} ${digits.slice(6)}`;\n }\n }\n\n return phone;\n}\n\n/**\n * Detects mobile money network from phone number (Ghana)\n */\nexport function detectNetwork(phone: string): MobileMoneyNetwork | null {\n const digits = phone.replace(/\\D/g, '');\n\n // Get the network prefix (first 3 digits after country code or 0)\n let prefix: string;\n if (digits.startsWith('233')) {\n prefix = digits.slice(3, 5);\n } else if (digits.startsWith('0')) {\n prefix = digits.slice(1, 3);\n } else {\n prefix = digits.slice(0, 2);\n }\n\n // Ghana network prefixes\n const mtnPrefixes = ['24', '25', '53', '54', '55', '59'];\n const telecelPrefixes = ['20', '50'];\n const airteltigoPrefixes = ['26', '27', '56', '57'];\n\n if (mtnPrefixes.includes(prefix)) return 'mtn';\n if (telecelPrefixes.includes(prefix)) return 'telecel';\n if (airteltigoPrefixes.includes(prefix)) return 'airteltigo';\n\n return null;\n}\n\n/**\n * Creates CSS custom property variables from theme\n */\nexport function createThemeVariables(theme: ReevitTheme): Record<string, string> {\n const variables: Record<string, string> = {};\n\n if (theme.primaryColor) {\n variables['--reevit-primary'] = theme.primaryColor;\n if (theme.primaryForegroundColor) {\n variables['--reevit-primary-foreground'] = theme.primaryForegroundColor;\n } else {\n const contrast = getContrastingColor(theme.primaryColor);\n if (contrast) {\n variables['--reevit-primary-foreground'] = contrast;\n }\n }\n }\n if (theme.backgroundColor) {\n variables['--reevit-background'] = theme.backgroundColor;\n }\n if (theme.surfaceColor) {\n variables['--reevit-surface'] = theme.surfaceColor;\n }\n if (theme.textColor) {\n variables['--reevit-text'] = theme.textColor;\n }\n if (theme.mutedTextColor) {\n variables['--reevit-text-secondary'] = theme.mutedTextColor;\n }\n if (theme.borderRadius) {\n variables['--reevit-radius'] = theme.borderRadius;\n variables['--reevit-radius-sm'] = theme.borderRadius;\n variables['--reevit-radius-lg'] = theme.borderRadius;\n }\n if (theme.fontFamily) {\n variables['--reevit-font'] = theme.fontFamily;\n }\n\n return variables;\n}\n\nfunction getContrastingColor(color: string): string | null {\n const hex = color.trim();\n if (!hex.startsWith('#')) {\n return null;\n }\n\n const normalized = hex.length === 4\n ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`\n : hex;\n\n if (normalized.length !== 7) {\n return null;\n }\n\n const r = parseInt(normalized.slice(1, 3), 16);\n const g = parseInt(normalized.slice(3, 5), 16);\n const b = parseInt(normalized.slice(5, 7), 16);\n\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\n return null;\n }\n\n const brightness = (r * 299 + g * 587 + b * 114) / 1000;\n return brightness >= 140 ? '#0b1120' : '#ffffff';\n}\n\n/**\n * Simple class name concatenation utility\n */\nexport function cn(...classes: (string | boolean | undefined | null)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n\n/**\n * Detects country code from currency\n */\nexport function detectCountryFromCurrency(currency: string): string {\n const currencyToCountry: Record<string, string> = {\n GHS: 'GH',\n NGN: 'NG',\n KES: 'KE',\n UGX: 'UG',\n TZS: 'TZ',\n ZAR: 'ZA',\n XOF: 'CI',\n XAF: 'CM',\n USD: 'US',\n EUR: 'DE',\n GBP: 'GB',\n };\n\n return currencyToCountry[currency.toUpperCase()] || 'GH';\n}\n","/**\n * Reevit State Machine\n * Shared state management logic for all SDKs\n */\n\nimport type { CheckoutState, PaymentIntent, PaymentMethod, PaymentResult, PaymentError } from './types';\n\n// State shape\nexport interface ReevitState {\n status: CheckoutState;\n paymentIntent: PaymentIntent | null;\n selectedMethod: PaymentMethod | null;\n error: PaymentError | null;\n result: PaymentResult | null;\n}\n\n// Actions\nexport type ReevitAction =\n | { type: 'INIT_START' }\n | { type: 'INIT_SUCCESS'; payload: PaymentIntent }\n | { type: 'INIT_ERROR'; payload: PaymentError }\n | { type: 'SELECT_METHOD'; payload: PaymentMethod }\n | { type: 'PROCESS_START' }\n | { type: 'PROCESS_SUCCESS'; payload: PaymentResult }\n | { type: 'PROCESS_ERROR'; payload: PaymentError }\n | { type: 'RESET' }\n | { type: 'CLOSE' };\n\n/**\n * Creates the initial state for the checkout\n */\nexport function createInitialState(): ReevitState {\n return {\n status: 'idle',\n paymentIntent: null,\n selectedMethod: null,\n error: null,\n result: null,\n };\n}\n\n/**\n * State reducer for checkout flow\n */\nexport function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState {\n switch (action.type) {\n case 'INIT_START':\n return { ...state, status: 'loading', error: null };\n case 'INIT_SUCCESS':\n return {\n ...state,\n status: 'ready',\n paymentIntent: action.payload,\n selectedMethod:\n action.payload.availableMethods?.length === 1 ? action.payload.availableMethods[0] : null,\n };\n case 'INIT_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'SELECT_METHOD':\n return { ...state, status: 'method_selected', selectedMethod: action.payload };\n case 'PROCESS_START':\n return { ...state, status: 'processing', error: null };\n case 'PROCESS_SUCCESS':\n return { ...state, status: 'success', result: action.payload };\n case 'PROCESS_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'RESET':\n return { ...createInitialState(), status: 'ready', paymentIntent: state.paymentIntent };\n case 'CLOSE':\n return { ...state, status: 'closed' };\n default:\n return state;\n }\n}\n"],"mappings":";AAqGA,IAAM,0BAA0B;AAChC,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AAKjB,SAAS,aAAa,WAA4B;AACvD,SAAO,UAAU,WAAW,UAAU,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,WAAW,KAChC,UAAU,WAAW,cAAc;AACvC;AAKA,SAAS,mBAAmB,UAAoB,WAA2C;AACzF,SAAO;AAAA,IACL,MAAM,UAAU,QAAQ;AAAA,IACxB,SAAS,UAAU,WAAW;AAAA,IAC9B,SAAS;AAAA,MACP,YAAY,SAAS;AAAA,MACrB,GAAG,UAAU;AAAA,IACf;AAAA,EACF;AACF;AAKO,IAAM,kBAAN,MAAsB;AAAA,EAK3B,YAAY,QAA+B;AACzC,SAAK,YAAY,OAAO,aAAa;AACrC,SAAK,UAAU,OAAO,YAAY,OAAO,aAAa,aAAa,OAAO,SAAS,IAC/E,uBACA;AACJ,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,QACZ,QACA,MACA,MAC6C;AAC7C,UAAM,aAAa,IAAI,gBAAgB;AACvC,UAAM,YA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S,cAAc,OAAoB,QAAmC;AACnF,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,OAAO,KAAK;AAAA,IACpD,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,QAAQ;AAAA,QACR,eAAe,OAAO;AAAA,QACtB,gBACE,OAAO,QAAQ,kBAAkB,WAAW,IAAI,OAAO,QAAQ,iBAAiB,CAAC,IAAI;AAAA,MACzF;AAAA,IACF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,mBAAmB,gBAAgB,OAAO,QAAQ;AAAA,IAC/E,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,cAAc,OAAO,KAAK;AAAA,IACvD,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,QAAQ,OAAO,QAAQ;AAAA,IAC/D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,UAAU,OAAO,OAAO,QAAQ;AAAA,IAC7D,KAAK;AACH,aAAO,EAAE,GAAG,mBAAmB,GAAG,QAAQ,SAAS,eAAe,MAAM,cAAc;AAAA,IACxF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,SAAS;AAAA,IACtC;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/api/client.ts","../src/utils.ts","../src/intent.ts","../src/state.ts"],"sourcesContent":["/**\n * Reevit API Client\n * \n * Handles communication with the Reevit backend for payment operations.\n */\n\nimport type { PaymentMethod, ReevitCheckoutConfig, PaymentError, HubtelSessionResponse } from '../types';\n\n// API Response Types (matching backend handlers_payments.go)\nexport interface CreatePaymentIntentRequest {\n amount: number;\n currency: string;\n method?: string;\n country: string;\n customer_id?: string;\n metadata?: Record<string, unknown>;\n description?: string;\n policy?: {\n prefer?: string[];\n allowed_providers?: string[];\n max_amount?: number;\n blocked_bins?: string[];\n allowed_bins?: string[];\n velocity_max_per_minute?: number;\n };\n}\n\nexport interface PaymentIntentResponse {\n id: string;\n org_id?: string;\n connection_id: string;\n provider: string;\n status: string;\n client_secret: string;\n psp_public_key: string;\n psp_credentials?: {\n merchantAccount?: string | number;\n basicAuth?: string;\n [key: string]: unknown;\n };\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n reference?: string;\n available_psps?: Array<{\n provider: string;\n name: string;\n methods: string[];\n countries?: string[];\n }>;\n branding?: Record<string, unknown>;\n}\n\nexport interface ConfirmPaymentRequest {\n provider_ref_id: string;\n provider_data?: Record<string, unknown>;\n}\n\nexport interface PaymentDetailResponse {\n id: string;\n connection_id: string;\n provider: string;\n method: string;\n status: string;\n amount: number;\n currency: string;\n fee_amount: number;\n fee_currency: string;\n net_amount: number;\n customer_id?: string;\n client_secret: string;\n provider_ref_id?: string;\n metadata?: Record<string, unknown>;\n created_at: string;\n updated_at: string;\n /** Payment source type (payment_link, api, subscription) */\n source?: 'payment_link' | 'api' | 'subscription';\n /** ID of the source (payment link ID, subscription ID, etc.) */\n source_id?: string;\n /** Human-readable description of the source (e.g., payment link name) */\n source_description?: string;\n}\n\nexport interface APIErrorResponse {\n code: string;\n message: string;\n details?: Record<string, string>;\n}\n\n// API Client configuration\nexport interface ReevitAPIClientConfig {\n /** Your Reevit public key */\n publicKey?: string;\n /** Base URL for the Reevit API (defaults to production) */\n baseUrl?: string;\n /** Request timeout in milliseconds */\n timeout?: number;\n}\n\n// Default API base URLs\nconst API_BASE_URL_PRODUCTION = 'https://api.reevit.io';\nconst API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Determines if a public key is for sandbox mode\n */\nexport function isSandboxKey(publicKey: string): boolean {\n return publicKey.startsWith('pk_test_') ||\n publicKey.startsWith('pk_sandbox_') ||\n publicKey.startsWith('pfk_test_') ||\n publicKey.startsWith('pfk_sandbox_');\n}\n\n/**\n * Creates a PaymentError from an API error response\n */\nfunction createPaymentError(response: Response, errorData: APIErrorResponse): PaymentError {\n return {\n code: errorData.code || 'api_error',\n message: errorData.message || 'An unexpected error occurred',\n details: {\n httpStatus: response.status,\n ...errorData.details,\n },\n };\n}\n\n/**\n * Generates a deterministic idempotency key based on input parameters\n * Uses a simple hash function suitable for browser environments\n * Exported for use by SDK hooks (e.g., payment link flows)\n */\nexport function generateIdempotencyKey(params: Record<string, unknown>): string {\n // Create a stable string representation of the parameters\n const sortedKeys = Object.keys(params).sort();\n const stableString = sortedKeys\n .map(key => `${key}:${JSON.stringify(params[key])}`)\n .join('|');\n\n // Simple hash function (djb2 algorithm)\n let hash = 5381;\n for (let i = 0; i < stableString.length; i++) {\n hash = ((hash << 5) + hash) + stableString.charCodeAt(i);\n hash = hash & hash; // Convert to 32-bit integer\n }\n\n // Convert to positive hex string\n const hashHex = (hash >>> 0).toString(16);\n\n // Add a time bucket (5-minute windows) to allow retries within a reasonable window\n // but prevent keys from being reused across completely different sessions\n const timeBucket = Math.floor(Date.now() / (5 * 60 * 1000));\n\n return `reevit_${timeBucket}_${hashHex}`;\n}\n\n/**\n * Reevit API Client\n */\nexport class ReevitAPIClient {\n private readonly publicKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(config: ReevitAPIClientConfig) {\n this.publicKey = config.publicKey || '';\n this.baseUrl = config.baseUrl || (config.publicKey && isSandboxKey(config.publicKey)\n ? API_BASE_URL_SANDBOX\n : API_BASE_URL_PRODUCTION);\n this.timeout = config.timeout || DEFAULT_TIMEOUT;\n }\n\n /**\n * Makes an authenticated API request\n * @param idempotencyKey Optional deterministic idempotency key for the request\n */\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n idempotencyKey?: string\n ): Promise<{ data?: T; error?: PaymentError }> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n // Generate headers with idempotency key for mutating requests\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Reevit-Client': '@reevit/core',\n 'X-Reevit-Client-Version': '0.5.9',\n };\n if (this.publicKey) {\n headers['X-Reevit-Key'] = this.publicKey;\n }\n\n if (method === 'POST' || method === 'PATCH' || method === 'PUT') {\n // Use provided deterministic key, or generate one based on request body\n headers['Idempotency-Key'] = idempotencyKey ||\n (body ? generateIdempotencyKey(body as Record<string, unknown>) : `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`);\n }\n\n try {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n const responseData = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n return {\n error: createPaymentError(response, responseData as APIErrorResponse),\n };\n }\n\n return { data: responseData as T };\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof Error) {\n if (err.name === 'AbortError') {\n return {\n error: {\n code: 'request_timeout',\n message: 'The request timed out. Please try again.',\n },\n };\n }\n\n if (err.message.includes('Failed to fetch') || err.message.includes('NetworkError')) {\n return {\n error: {\n code: 'network_error',\n message: 'Unable to connect to Reevit. Please check your internet connection.',\n },\n };\n }\n }\n\n return {\n error: {\n code: 'unknown_error',\n message: 'An unexpected error occurred. Please try again.',\n },\n };\n }\n }\n\n /**\n * Creates a payment intent\n */\n async createPaymentIntent(\n config: ReevitCheckoutConfig,\n method?: PaymentMethod,\n country: string = 'GH',\n options?: { preferredProviders?: string[]; allowedProviders?: string[] }\n ): Promise<{ data?: PaymentIntentResponse; error?: PaymentError }> {\n // Build metadata with customer_email for PSP providers that require it\n const metadata: Record<string, unknown> = { ...config.metadata };\n if (config.email) {\n metadata.customer_email = config.email;\n }\n if (config.phone) {\n metadata.customer_phone = config.phone;\n }\n\n const request: CreatePaymentIntentRequest = {\n amount: config.amount,\n currency: config.currency,\n country,\n customer_id: config.email || (config.metadata?.customerId as string | undefined),\n metadata,\n };\n\n if (method) {\n request.method = this.mapPaymentMethod(method);\n }\n\n if (options?.preferredProviders?.length || options?.allowedProviders?.length) {\n request.policy = {\n prefer: options?.preferredProviders,\n allowed_providers: options?.allowedProviders,\n };\n }\n\n // Generate a deterministic idempotency key based on payment parameters\n // This ensures that duplicate requests for the same payment return the same intent\n const idempotencyKey = config.idempotencyKey || generateIdempotencyKey({\n amount: config.amount,\n currency: config.currency,\n customer: config.email || config.metadata?.customerId || '',\n reference: config.reference || '',\n method: method || '',\n provider: options?.preferredProviders?.[0] || options?.allowedProviders?.[0] || '',\n publicKey: this.publicKey,\n });\n\n return this.request<PaymentIntentResponse>('POST', '/v1/payments/intents', request, idempotencyKey);\n }\n\n /**\n * Retrieves a payment intent by ID\n */\n async getPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('GET', `/v1/payments/${paymentId}`);\n }\n\n /**\n * Confirms a payment after PSP callback\n */\n async confirmPayment(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm`);\n }\n\n /**\n * Confirms a payment intent using client secret (public endpoint)\n */\n async confirmPaymentIntent(paymentId: string, clientSecret: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/confirm-intent?client_secret=${clientSecret}`);\n }\n\n /**\n * Cancels a payment intent\n */\n async cancelPaymentIntent(paymentId: string): Promise<{ data?: PaymentDetailResponse; error?: PaymentError }> {\n return this.request<PaymentDetailResponse>('POST', `/v1/payments/${paymentId}/cancel`);\n }\n\n /**\n * Creates a Hubtel session token for secure checkout\n * Returns a short-lived token that contains Hubtel credentials\n * Credentials are never exposed to the client directly\n */\n async createHubtelSession(\n paymentId: string,\n clientSecret?: string\n ): Promise<{ data?: HubtelSessionResponse; error?: PaymentError }> {\n const query = clientSecret ? `?client_secret=${encodeURIComponent(clientSecret)}` : '';\n return this.request<HubtelSessionResponse>('POST', `/v1/payments/hubtel/sessions/${paymentId}${query}`);\n }\n\n /**\n * Maps SDK payment method to backend format\n */\n private mapPaymentMethod(method: PaymentMethod): string {\n switch (method) {\n case 'card':\n return 'card';\n case 'mobile_money':\n return 'mobile_money';\n case 'bank_transfer':\n return 'bank_transfer';\n default:\n return method;\n }\n }\n}\n\n/**\n * Creates a new Reevit API client instance\n */\nexport function createReevitClient(config: ReevitAPIClientConfig): ReevitAPIClient {\n return new ReevitAPIClient(config);\n}\n","/**\n * Utility Functions\n * Shared utilities for Reevit SDKs\n */\n\nimport type { MobileMoneyNetwork, ReevitTheme } from './types';\n\n/**\n * Formats an amount from smallest currency unit to display format\n */\nexport function formatAmount(amount: number, currency: string): string {\n const majorUnit = amount / 100;\n\n const currencyFormats: Record<string, { locale: string; minimumFractionDigits: number }> = {\n GHS: { locale: 'en-GH', minimumFractionDigits: 2 },\n NGN: { locale: 'en-NG', minimumFractionDigits: 2 },\n KES: { locale: 'en-KE', minimumFractionDigits: 2 },\n USD: { locale: 'en-US', minimumFractionDigits: 2 },\n EUR: { locale: 'de-DE', minimumFractionDigits: 2 },\n GBP: { locale: 'en-GB', minimumFractionDigits: 2 },\n };\n\n const format = currencyFormats[currency.toUpperCase()] || { locale: 'en-US', minimumFractionDigits: 2 };\n\n try {\n return new Intl.NumberFormat(format.locale, {\n style: 'currency',\n currency: currency.toUpperCase(),\n minimumFractionDigits: format.minimumFractionDigits,\n }).format(majorUnit);\n } catch {\n // Fallback for unsupported currencies\n return `${currency} ${majorUnit.toFixed(2)}`;\n }\n}\n\n/**\n * Generates a unique payment reference\n */\nexport function generateReference(prefix: string = 'reevit'): string {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 8);\n return `${prefix}_${timestamp}_${random}`;\n}\n\n/**\n * Validates a phone number for mobile money\n */\nexport function validatePhone(phone: string, country: string = 'GH'): boolean {\n // Remove non-digit characters\n const digits = phone.replace(/\\D/g, '');\n\n const patterns: Record<string, RegExp> = {\n GH: /^(?:233|0)?[235][0-9]{8}$/, // Ghana\n NG: /^(?:234|0)?[789][01][0-9]{8}$/, // Nigeria\n KE: /^(?:254|0)?[17][0-9]{8}$/, // Kenya\n };\n\n const pattern = patterns[country.toUpperCase()];\n if (!pattern) return digits.length >= 10;\n\n return pattern.test(digits);\n}\n\n/**\n * Formats a phone number for display\n */\nexport function formatPhone(phone: string, country: string = 'GH'): string {\n const digits = phone.replace(/\\D/g, '');\n\n if (country === 'GH') {\n // Format as 0XX XXX XXXX\n if (digits.startsWith('233') && digits.length === 12) {\n const local = '0' + digits.slice(3);\n return `${local.slice(0, 3)} ${local.slice(3, 6)} ${local.slice(6)}`;\n }\n if (digits.length === 10 && digits.startsWith('0')) {\n return `${digits.slice(0, 3)} ${digits.slice(3, 6)} ${digits.slice(6)}`;\n }\n }\n\n return phone;\n}\n\n/**\n * Detects mobile money network from phone number (Ghana)\n */\nexport function detectNetwork(phone: string): MobileMoneyNetwork | null {\n const digits = phone.replace(/\\D/g, '');\n\n // Get the network prefix (first 3 digits after country code or 0)\n let prefix: string;\n if (digits.startsWith('233')) {\n prefix = digits.slice(3, 5);\n } else if (digits.startsWith('0')) {\n prefix = digits.slice(1, 3);\n } else {\n prefix = digits.slice(0, 2);\n }\n\n // Ghana network prefixes\n const mtnPrefixes = ['24', '25', '53', '54', '55', '59'];\n const telecelPrefixes = ['20', '50'];\n const airteltigoPrefixes = ['26', '27', '56', '57'];\n\n if (mtnPrefixes.includes(prefix)) return 'mtn';\n if (telecelPrefixes.includes(prefix)) return 'telecel';\n if (airteltigoPrefixes.includes(prefix)) return 'airteltigo';\n\n return null;\n}\n\n/**\n * Creates CSS custom property variables from theme\n */\nexport function createThemeVariables(theme: ReevitTheme): Record<string, string> {\n const variables: Record<string, string> = {};\n\n // Primary color = main text color\n if (theme.primaryColor) {\n variables['--reevit-text'] = theme.primaryColor;\n }\n\n // Primary foreground = description/secondary text color\n if (theme.primaryForegroundColor) {\n variables['--reevit-text-secondary'] = theme.primaryForegroundColor;\n variables['--reevit-muted'] = theme.primaryForegroundColor;\n }\n\n // Button colors\n if (theme.buttonBackgroundColor) {\n variables['--reevit-primary'] = theme.buttonBackgroundColor;\n variables['--reevit-primary-hover'] = theme.buttonBackgroundColor;\n }\n if (theme.buttonTextColor) {\n variables['--reevit-primary-foreground'] = theme.buttonTextColor;\n }\n\n // Background and surface colors\n if (theme.backgroundColor) {\n variables['--reevit-background'] = theme.backgroundColor;\n variables['--reevit-surface'] = theme.backgroundColor;\n }\n if (theme.surfaceColor) {\n variables['--reevit-surface'] = theme.surfaceColor;\n }\n\n // Border color\n if (theme.borderColor) {\n variables['--reevit-border'] = theme.borderColor;\n }\n\n // Legacy text color support\n if (theme.textColor) {\n variables['--reevit-text'] = theme.textColor;\n }\n if (theme.mutedTextColor) {\n variables['--reevit-text-secondary'] = theme.mutedTextColor;\n }\n\n // Border radius\n if (theme.borderRadius) {\n variables['--reevit-radius'] = theme.borderRadius;\n variables['--reevit-radius-sm'] = theme.borderRadius;\n variables['--reevit-radius-lg'] = theme.borderRadius;\n }\n\n // Font family\n if (theme.fontFamily) {\n variables['--reevit-font'] = theme.fontFamily;\n }\n\n return variables;\n}\n\nfunction getContrastingColor(color: string): string | null {\n const hex = color.trim();\n if (!hex.startsWith('#')) {\n return null;\n }\n\n const normalized = hex.length === 4\n ? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`\n : hex;\n\n if (normalized.length !== 7) {\n return null;\n }\n\n const r = parseInt(normalized.slice(1, 3), 16);\n const g = parseInt(normalized.slice(3, 5), 16);\n const b = parseInt(normalized.slice(5, 7), 16);\n\n if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\n return null;\n }\n\n const brightness = (r * 299 + g * 587 + b * 114) / 1000;\n return brightness >= 140 ? '#0b1120' : '#ffffff';\n}\n\n/**\n * Simple class name concatenation utility\n */\nexport function cn(...classes: (string | boolean | undefined | null)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n\n/**\n * Detects country code from currency\n */\nexport function detectCountryFromCurrency(currency: string): string {\n const currencyToCountry: Record<string, string> = {\n GHS: 'GH',\n NGN: 'NG',\n KES: 'KE',\n UGX: 'UG',\n TZS: 'TZ',\n ZAR: 'ZA',\n XOF: 'CI',\n XAF: 'CM',\n USD: 'US',\n EUR: 'DE',\n GBP: 'GB',\n };\n\n return currencyToCountry[currency.toUpperCase()] || 'GH';\n}\n","/**\n * Intent identity + cache helpers\n */\n\nimport type { PaymentIntentResponse } from './api/client';\nimport { generateIdempotencyKey } from './api/client';\nimport type { PaymentMethod, ReevitCheckoutConfig } from './types';\nimport { generateReference } from './utils';\n\nconst INTENT_CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes\n\nexport interface IntentIdentityOptions {\n config: ReevitCheckoutConfig;\n method?: PaymentMethod;\n preferredProvider?: string;\n allowedProviders?: string[];\n publicKey?: string;\n}\n\nexport interface IntentCacheEntry {\n promise?: Promise<PaymentIntentResponse>;\n response?: PaymentIntentResponse;\n expiresAt: number;\n reference?: string;\n}\n\nconst intentCache = new Map<string, IntentCacheEntry>();\n\nfunction pruneIntentCache(now: number = Date.now()): void {\n for (const [key, entry] of intentCache) {\n if (entry.expiresAt <= now) {\n intentCache.delete(key);\n }\n }\n}\n\nfunction getIntentCacheEntryInternal(key: string): IntentCacheEntry | undefined {\n const entry = intentCache.get(key);\n if (!entry) {\n return undefined;\n }\n if (entry.expiresAt <= Date.now()) {\n intentCache.delete(key);\n return undefined;\n }\n return entry;\n}\n\nfunction setIntentCacheEntryInternal(key: string, update: Partial<IntentCacheEntry>): IntentCacheEntry {\n const now = Date.now();\n const existing = getIntentCacheEntryInternal(key);\n const next: IntentCacheEntry = {\n ...existing,\n ...update,\n expiresAt: now + INTENT_CACHE_TTL_MS,\n };\n intentCache.set(key, next);\n return next;\n}\n\nfunction buildIdempotencyPayload(options: IntentIdentityOptions): Record<string, unknown> {\n const { config, method, preferredProvider, allowedProviders, publicKey } = options;\n const payload: Record<string, unknown> = {\n amount: config.amount,\n currency: config.currency,\n email: config.email || '',\n phone: config.phone || '',\n customerName: config.customerName || '',\n paymentLinkCode: config.paymentLinkCode || '',\n paymentMethods: config.paymentMethods || [],\n metadata: config.metadata || {},\n customFields: config.customFields || {},\n method: method || '',\n preferredProvider: preferredProvider || '',\n allowedProviders: allowedProviders || [],\n publicKey: publicKey || config.publicKey || '',\n };\n\n if (config.reference) {\n payload.reference = config.reference;\n }\n\n return payload;\n}\n\nexport function resolveIntentIdentity(options: IntentIdentityOptions): {\n idempotencyKey: string;\n reference: string;\n cacheEntry?: IntentCacheEntry;\n} {\n pruneIntentCache();\n\n const idempotencyKey =\n options.config.idempotencyKey || generateIdempotencyKey(buildIdempotencyPayload(options));\n const existing = getIntentCacheEntryInternal(idempotencyKey);\n const reference = options.config.reference || existing?.reference || generateReference();\n\n const cacheEntry = setIntentCacheEntryInternal(idempotencyKey, { reference });\n\n return { idempotencyKey, reference, cacheEntry };\n}\n\nexport function getIntentCacheEntry(idempotencyKey: string): IntentCacheEntry | undefined {\n pruneIntentCache();\n return getIntentCacheEntryInternal(idempotencyKey);\n}\n\nexport function cacheIntentPromise(\n idempotencyKey: string,\n promise: Promise<PaymentIntentResponse>\n): IntentCacheEntry {\n return setIntentCacheEntryInternal(idempotencyKey, { promise });\n}\n\nexport function cacheIntentResponse(\n idempotencyKey: string,\n response: PaymentIntentResponse\n): IntentCacheEntry {\n return setIntentCacheEntryInternal(idempotencyKey, { response, promise: undefined });\n}\n\nexport function clearIntentCacheEntry(idempotencyKey: string): void {\n intentCache.delete(idempotencyKey);\n}\n","/**\n * Reevit State Machine\n * Shared state management logic for all SDKs\n */\n\nimport type { CheckoutState, PaymentIntent, PaymentMethod, PaymentResult, PaymentError } from './types';\n\n// State shape\nexport interface ReevitState {\n status: CheckoutState;\n paymentIntent: PaymentIntent | null;\n selectedMethod: PaymentMethod | null;\n error: PaymentError | null;\n result: PaymentResult | null;\n}\n\n// Actions\nexport type ReevitAction =\n | { type: 'INIT_START' }\n | { type: 'INIT_SUCCESS'; payload: PaymentIntent }\n | { type: 'INIT_ERROR'; payload: PaymentError }\n | { type: 'SELECT_METHOD'; payload: PaymentMethod }\n | { type: 'PROCESS_START' }\n | { type: 'PROCESS_SUCCESS'; payload: PaymentResult }\n | { type: 'PROCESS_ERROR'; payload: PaymentError }\n | { type: 'RESET' }\n | { type: 'CLOSE' };\n\n/**\n * Creates the initial state for the checkout\n */\nexport function createInitialState(): ReevitState {\n return {\n status: 'idle',\n paymentIntent: null,\n selectedMethod: null,\n error: null,\n result: null,\n };\n}\n\n/**\n * State reducer for checkout flow\n */\nexport function reevitReducer(state: ReevitState, action: ReevitAction): ReevitState {\n switch (action.type) {\n case 'INIT_START':\n return { ...state, status: 'loading', error: null };\n case 'INIT_SUCCESS':\n return {\n ...state,\n status: 'ready',\n paymentIntent: action.payload,\n selectedMethod:\n action.payload.availableMethods?.length === 1 ? action.payload.availableMethods[0] : null,\n };\n case 'INIT_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'SELECT_METHOD':\n return { ...state, status: 'method_selected', selectedMethod: action.payload };\n case 'PROCESS_START':\n return { ...state, status: 'processing', error: null };\n case 'PROCESS_SUCCESS':\n return { ...state, status: 'success', result: action.payload };\n case 'PROCESS_ERROR':\n return { ...state, status: 'failed', error: action.payload };\n case 'RESET':\n return { ...createInitialState(), status: 'ready', paymentIntent: state.paymentIntent };\n case 'CLOSE':\n return { ...state, status: 'closed' };\n default:\n return state;\n }\n}\n"],"mappings":";AAsGA,IAAM,0BAA0B;AAChC,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AAKjB,SAAS,aAAa,WAA4B;AACvD,SAAO,UAAU,WAAW,UAAU,KACpC,UAAU,WAAW,aAAa,KAClC,UAAU,WAAW,WAAW,KAChC,UAAU,WAAW,cAAc;AACvC;AAKA,SAAS,mBAAmB,UAAoB,WAA2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