@rozoai/intent-common 0.0.28-beta.2 → 0.0.28-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/base.d.ts +90 -0
- package/dist/api/base.js +142 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +29 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/payment.d.ts +93 -0
- package/dist/api/payment.js +27 -0
- package/dist/api/payment.js.map +1 -0
- package/dist/bridge.d.ts +164 -0
- package/dist/bridge.js +316 -0
- package/dist/bridge.js.map +1 -0
- package/dist/daimoPay.d.ts +8 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/README.md +275 -0
- package/src/api/base.ts +215 -0
- package/src/api/payment.ts +112 -0
- package/src/bridge.ts +382 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RozoAI API Configuration Constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const ROZO_API_URL = "https://intentapiv2.rozo.ai/functions/v1";
|
|
5
|
+
export declare const ROZO_API_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ4Y3Zmb2xobmNtdXZmYXp1cXViIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTI4Mzg2NjYsImV4cCI6MjA2ODQxNDY2Nn0.B4dV5y_-zCMKSNm3_qyCbAvCPJmoOGv_xB783LfAVUA";
|
|
6
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
7
|
+
export interface RequestOptions {
|
|
8
|
+
method?: HttpMethod;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
body?: any;
|
|
11
|
+
params?: Record<string, string>;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface ApiResponse<T = any> {
|
|
15
|
+
data: T | null;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
status: number | null;
|
|
18
|
+
}
|
|
19
|
+
export interface RequestState<T = any> extends ApiResponse<T> {
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
isError: boolean;
|
|
22
|
+
isSuccess: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* API Configuration
|
|
26
|
+
*/
|
|
27
|
+
export interface ApiConfig {
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
apiToken: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set API configuration
|
|
33
|
+
* @param config - API configuration
|
|
34
|
+
*/
|
|
35
|
+
export declare const setApiConfig: (config: Partial<ApiConfig>) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Get current API configuration
|
|
38
|
+
* @returns Current API configuration
|
|
39
|
+
*/
|
|
40
|
+
export declare const getApiConfig: () => ApiConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Core fetch function for making API requests
|
|
43
|
+
* @param url - API endpoint path
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @returns Promise with response data
|
|
46
|
+
*/
|
|
47
|
+
export declare const fetchApi: <T = any>(url: string, options?: RequestOptions) => Promise<ApiResponse<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* API client with methods for different HTTP verbs
|
|
50
|
+
*/
|
|
51
|
+
export declare const apiClient: {
|
|
52
|
+
/**
|
|
53
|
+
* GET request
|
|
54
|
+
* @param url - API endpoint path
|
|
55
|
+
* @param options - Request options
|
|
56
|
+
* @returns Promise with response data
|
|
57
|
+
*/
|
|
58
|
+
get: <T = any>(url: string, options?: Omit<RequestOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
59
|
+
/**
|
|
60
|
+
* POST request
|
|
61
|
+
* @param url - API endpoint path
|
|
62
|
+
* @param body - Request body
|
|
63
|
+
* @param options - Additional request options
|
|
64
|
+
* @returns Promise with response data
|
|
65
|
+
*/
|
|
66
|
+
post: <T = any>(url: string, body: any, options?: Omit<RequestOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
67
|
+
/**
|
|
68
|
+
* PUT request
|
|
69
|
+
* @param url - API endpoint path
|
|
70
|
+
* @param body - Request body
|
|
71
|
+
* @param options - Additional request options
|
|
72
|
+
* @returns Promise with response data
|
|
73
|
+
*/
|
|
74
|
+
put: <T = any>(url: string, body: any, options?: Omit<RequestOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
75
|
+
/**
|
|
76
|
+
* PATCH request
|
|
77
|
+
* @param url - API endpoint path
|
|
78
|
+
* @param body - Request body
|
|
79
|
+
* @param options - Additional request options
|
|
80
|
+
* @returns Promise with response data
|
|
81
|
+
*/
|
|
82
|
+
patch: <T = any>(url: string, body: any, options?: Omit<RequestOptions, "method" | "body">) => Promise<ApiResponse<T>>;
|
|
83
|
+
/**
|
|
84
|
+
* DELETE request
|
|
85
|
+
* @param url - API endpoint path
|
|
86
|
+
* @param options - Request options
|
|
87
|
+
* @returns Promise with response data
|
|
88
|
+
*/
|
|
89
|
+
delete: <T = any>(url: string, options?: Omit<RequestOptions, "method">) => Promise<ApiResponse<T>>;
|
|
90
|
+
};
|
package/dist/api/base.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiClient = exports.fetchApi = exports.getApiConfig = exports.setApiConfig = exports.ROZO_API_TOKEN = exports.ROZO_API_URL = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* RozoAI API Configuration Constants
|
|
6
|
+
*/
|
|
7
|
+
exports.ROZO_API_URL = "https://intentapiv2.rozo.ai/functions/v1";
|
|
8
|
+
exports.ROZO_API_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ4Y3Zmb2xobmNtdXZmYXp1cXViIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTI4Mzg2NjYsImV4cCI6MjA2ODQxNDY2Nn0.B4dV5y_-zCMKSNm3_qyCbAvCPJmoOGv_xB783LfAVUA";
|
|
9
|
+
// Default configuration (can be overridden via setApiConfig)
|
|
10
|
+
let apiConfig = {
|
|
11
|
+
baseUrl: exports.ROZO_API_URL,
|
|
12
|
+
apiToken: exports.ROZO_API_TOKEN,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Set API configuration
|
|
16
|
+
* @param config - API configuration
|
|
17
|
+
*/
|
|
18
|
+
const setApiConfig = (config) => {
|
|
19
|
+
apiConfig = { ...apiConfig, ...config };
|
|
20
|
+
};
|
|
21
|
+
exports.setApiConfig = setApiConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Get current API configuration
|
|
24
|
+
* @returns Current API configuration
|
|
25
|
+
*/
|
|
26
|
+
const getApiConfig = () => {
|
|
27
|
+
return apiConfig;
|
|
28
|
+
};
|
|
29
|
+
exports.getApiConfig = getApiConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a URL with query parameters
|
|
32
|
+
* @param url - Base URL
|
|
33
|
+
* @param params - Query parameters
|
|
34
|
+
* @returns Full URL with query parameters
|
|
35
|
+
*/
|
|
36
|
+
const createUrl = (url, params) => {
|
|
37
|
+
const fullUrl = url.startsWith("/")
|
|
38
|
+
? `${apiConfig.baseUrl}${url}`
|
|
39
|
+
: `${apiConfig.baseUrl}/${url}`;
|
|
40
|
+
if (!params)
|
|
41
|
+
return fullUrl;
|
|
42
|
+
const queryParams = new URLSearchParams();
|
|
43
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
44
|
+
if (value !== undefined && value !== null) {
|
|
45
|
+
queryParams.append(key, value);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const queryString = queryParams.toString();
|
|
49
|
+
return queryString ? `${fullUrl}?${queryString}` : fullUrl;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Core fetch function for making API requests
|
|
53
|
+
* @param url - API endpoint path
|
|
54
|
+
* @param options - Request options
|
|
55
|
+
* @returns Promise with response data
|
|
56
|
+
*/
|
|
57
|
+
const fetchApi = async (url, options = {}) => {
|
|
58
|
+
const { method = "GET", headers = {}, body, params, signal } = options;
|
|
59
|
+
try {
|
|
60
|
+
const fullUrl = createUrl(url, params);
|
|
61
|
+
const requestHeaders = {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
...headers,
|
|
64
|
+
Authorization: `Bearer ${apiConfig.apiToken}`,
|
|
65
|
+
};
|
|
66
|
+
const requestOptions = {
|
|
67
|
+
method,
|
|
68
|
+
headers: requestHeaders,
|
|
69
|
+
signal,
|
|
70
|
+
};
|
|
71
|
+
if (body && method !== "GET") {
|
|
72
|
+
requestOptions.body = JSON.stringify(body);
|
|
73
|
+
}
|
|
74
|
+
const response = await fetch(fullUrl, requestOptions);
|
|
75
|
+
const status = response.status;
|
|
76
|
+
// Handle non-JSON responses
|
|
77
|
+
const contentType = response.headers.get("content-type");
|
|
78
|
+
let data = null;
|
|
79
|
+
if (contentType && contentType.includes("application/json")) {
|
|
80
|
+
data = (await response.json());
|
|
81
|
+
}
|
|
82
|
+
else if (contentType && contentType.includes("text/")) {
|
|
83
|
+
data = (await response.text());
|
|
84
|
+
}
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new Error(data ? JSON.stringify(data) : response.statusText);
|
|
87
|
+
}
|
|
88
|
+
return { data, error: null, status };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
data: null,
|
|
93
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
94
|
+
status: null,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.fetchApi = fetchApi;
|
|
99
|
+
/**
|
|
100
|
+
* API client with methods for different HTTP verbs
|
|
101
|
+
*/
|
|
102
|
+
exports.apiClient = {
|
|
103
|
+
/**
|
|
104
|
+
* GET request
|
|
105
|
+
* @param url - API endpoint path
|
|
106
|
+
* @param options - Request options
|
|
107
|
+
* @returns Promise with response data
|
|
108
|
+
*/
|
|
109
|
+
get: (url, options = {}) => (0, exports.fetchApi)(url, { ...options, method: "GET" }),
|
|
110
|
+
/**
|
|
111
|
+
* POST request
|
|
112
|
+
* @param url - API endpoint path
|
|
113
|
+
* @param body - Request body
|
|
114
|
+
* @param options - Additional request options
|
|
115
|
+
* @returns Promise with response data
|
|
116
|
+
*/
|
|
117
|
+
post: (url, body, options = {}) => (0, exports.fetchApi)(url, { ...options, method: "POST", body }),
|
|
118
|
+
/**
|
|
119
|
+
* PUT request
|
|
120
|
+
* @param url - API endpoint path
|
|
121
|
+
* @param body - Request body
|
|
122
|
+
* @param options - Additional request options
|
|
123
|
+
* @returns Promise with response data
|
|
124
|
+
*/
|
|
125
|
+
put: (url, body, options = {}) => (0, exports.fetchApi)(url, { ...options, method: "PUT", body }),
|
|
126
|
+
/**
|
|
127
|
+
* PATCH request
|
|
128
|
+
* @param url - API endpoint path
|
|
129
|
+
* @param body - Request body
|
|
130
|
+
* @param options - Additional request options
|
|
131
|
+
* @returns Promise with response data
|
|
132
|
+
*/
|
|
133
|
+
patch: (url, body, options = {}) => (0, exports.fetchApi)(url, { ...options, method: "PATCH", body }),
|
|
134
|
+
/**
|
|
135
|
+
* DELETE request
|
|
136
|
+
* @param url - API endpoint path
|
|
137
|
+
* @param options - Request options
|
|
138
|
+
* @returns Promise with response data
|
|
139
|
+
*/
|
|
140
|
+
delete: (url, options = {}) => (0, exports.fetchApi)(url, { ...options, method: "DELETE" }),
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,YAAY,GAAG,0CAA0C,CAAC;AAC1D,QAAA,cAA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AA,gBAAQ,EAAI,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAE5D;;;;;OAKG;IACH,MAAM,EAAE,CACN,GAAW,EACX,UAA0C,EAAE,EAC5C,EAAE,CAAC,IAAA,gBAAQ,EAAI,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;CACxD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client utilities for RozoAI Intent Pay
|
|
3
|
+
*
|
|
4
|
+
* This module provides core API client functionality for making HTTP requests
|
|
5
|
+
* to the RozoAI payment API. It includes:
|
|
6
|
+
* - Base API client with support for GET, POST, PUT, PATCH, DELETE
|
|
7
|
+
* - Payment API functions and types
|
|
8
|
+
* - Type-safe interfaces for requests and responses
|
|
9
|
+
*
|
|
10
|
+
* Note: React hooks for these APIs are available in the @rozoai/intent-pay package.
|
|
11
|
+
*/
|
|
12
|
+
export * from "./payment";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API client utilities for RozoAI Intent Pay
|
|
4
|
+
*
|
|
5
|
+
* This module provides core API client functionality for making HTTP requests
|
|
6
|
+
* to the RozoAI payment API. It includes:
|
|
7
|
+
* - Base API client with support for GET, POST, PUT, PATCH, DELETE
|
|
8
|
+
* - Payment API functions and types
|
|
9
|
+
* - Type-safe interfaces for requests and responses
|
|
10
|
+
*
|
|
11
|
+
* Note: React hooks for these APIs are available in the @rozoai/intent-pay package.
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
__exportStar(require("./payment"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;AAEH,4CAA0B"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ApiResponse } from "./base";
|
|
2
|
+
/**
|
|
3
|
+
* Payment display information
|
|
4
|
+
*/
|
|
5
|
+
export interface PaymentDisplay {
|
|
6
|
+
intent: string;
|
|
7
|
+
paymentValue: string;
|
|
8
|
+
currency: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Payment destination information
|
|
12
|
+
*/
|
|
13
|
+
export interface PaymentDestination {
|
|
14
|
+
destinationAddress?: string;
|
|
15
|
+
chainId: string;
|
|
16
|
+
amountUnits: string;
|
|
17
|
+
tokenSymbol: string;
|
|
18
|
+
tokenAddress?: string;
|
|
19
|
+
txHash?: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Payment source information
|
|
23
|
+
*/
|
|
24
|
+
export interface PaymentSource {
|
|
25
|
+
sourceAddress?: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Payment request data type
|
|
30
|
+
*/
|
|
31
|
+
export interface PaymentRequestData {
|
|
32
|
+
appId: string;
|
|
33
|
+
display: PaymentDisplay;
|
|
34
|
+
destination: PaymentDestination;
|
|
35
|
+
externalId?: string;
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Payment response data type
|
|
41
|
+
*/
|
|
42
|
+
export interface PaymentResponseData {
|
|
43
|
+
id: string;
|
|
44
|
+
status: "payment_unpaid" | string;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
display: {
|
|
47
|
+
intent: string;
|
|
48
|
+
currency: string;
|
|
49
|
+
paymentValue?: string;
|
|
50
|
+
};
|
|
51
|
+
source: PaymentSource | null;
|
|
52
|
+
destination: {
|
|
53
|
+
destinationAddress: string;
|
|
54
|
+
txHash: string | null;
|
|
55
|
+
chainId: string;
|
|
56
|
+
amountUnits: string;
|
|
57
|
+
tokenSymbol: string;
|
|
58
|
+
tokenAddress: string;
|
|
59
|
+
};
|
|
60
|
+
metadata: {
|
|
61
|
+
daimoOrderId?: string;
|
|
62
|
+
intent: string;
|
|
63
|
+
items: unknown[];
|
|
64
|
+
payer: Record<string, unknown>;
|
|
65
|
+
appId: string;
|
|
66
|
+
orderDate: string;
|
|
67
|
+
webhookUrl: string;
|
|
68
|
+
provider: string;
|
|
69
|
+
receivingAddress: string;
|
|
70
|
+
memo: string | null;
|
|
71
|
+
payinchainid: string;
|
|
72
|
+
payintokenaddress: string;
|
|
73
|
+
preferredChain: string;
|
|
74
|
+
preferredToken: string;
|
|
75
|
+
preferredTokenAddress: string;
|
|
76
|
+
source_tx_hash?: string;
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
url: string;
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new payment
|
|
84
|
+
* @param paymentData - Payment data to send
|
|
85
|
+
* @returns Promise with payment response
|
|
86
|
+
*/
|
|
87
|
+
export declare const createRozoPayment: (paymentData: PaymentRequestData) => Promise<ApiResponse<PaymentResponseData>>;
|
|
88
|
+
/**
|
|
89
|
+
* Gets payment details by ID
|
|
90
|
+
* @param paymentId - Payment ID
|
|
91
|
+
* @returns Promise with payment response
|
|
92
|
+
*/
|
|
93
|
+
export declare const getRozoPayment: (paymentId: string) => Promise<ApiResponse<PaymentResponseData>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRozoPayment = exports.createRozoPayment = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new payment
|
|
7
|
+
* @param paymentData - Payment data to send
|
|
8
|
+
* @returns Promise with payment response
|
|
9
|
+
*/
|
|
10
|
+
const createRozoPayment = (paymentData) => {
|
|
11
|
+
return base_1.apiClient.post("/payment-api", paymentData);
|
|
12
|
+
};
|
|
13
|
+
exports.createRozoPayment = createRozoPayment;
|
|
14
|
+
/**
|
|
15
|
+
* Gets payment details by ID
|
|
16
|
+
* @param paymentId - Payment ID
|
|
17
|
+
* @returns Promise with payment response
|
|
18
|
+
*/
|
|
19
|
+
const getRozoPayment = (paymentId) => {
|
|
20
|
+
const isMugglePay = paymentId.includes("mugglepay_order");
|
|
21
|
+
const endpoint = isMugglePay
|
|
22
|
+
? `payment-api/${paymentId}`
|
|
23
|
+
: `payment/id/${paymentId}`;
|
|
24
|
+
return base_1.apiClient.get(endpoint);
|
|
25
|
+
};
|
|
26
|
+
exports.getRozoPayment = getRozoPayment;
|
|
27
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../src/api/payment.ts"],"names":[],"mappings":";;;AAAA,iCAAgD;AAuFhD;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,CAC/B,WAA+B,EACY,EAAE;IAC7C,OAAO,gBAAS,CAAC,IAAI,CAAsB,cAAc,EAAE,WAAW,CAAC,CAAC;AAC1E,CAAC,CAAC;AAJW,QAAA,iBAAiB,qBAI5B;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAC5B,SAAiB,EAC0B,EAAE;IAC7C,MAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,WAAW;QAC1B,CAAC,CAAC,eAAe,SAAS,EAAE;QAC5B,CAAC,CAAC,cAAc,SAAS,EAAE,CAAC;IAC9B,OAAO,gBAAS,CAAC,GAAG,CAAsB,QAAQ,CAAC,CAAC;AACtD,CAAC,CAAC;AARW,QAAA,cAAc,kBAQzB"}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { RozoPayHydratedOrderWithOrg } from ".";
|
|
2
|
+
import type { PaymentResponseData } from "./api/payment";
|
|
3
|
+
export interface PaymentBridgeConfig {
|
|
4
|
+
toChain?: number;
|
|
5
|
+
toToken?: string;
|
|
6
|
+
toAddress: string;
|
|
7
|
+
toStellarAddress?: string;
|
|
8
|
+
toSolanaAddress?: string;
|
|
9
|
+
toUnits: string;
|
|
10
|
+
payInTokenAddress: string;
|
|
11
|
+
log?: (msg: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface PreferredPaymentConfig {
|
|
14
|
+
preferredChain: string;
|
|
15
|
+
preferredToken: "USDC" | "USDT" | "XLM";
|
|
16
|
+
preferredTokenAddress?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DestinationConfig {
|
|
19
|
+
destinationAddress?: string;
|
|
20
|
+
chainId: string;
|
|
21
|
+
amountUnits: string;
|
|
22
|
+
tokenSymbol: string;
|
|
23
|
+
tokenAddress: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates payment bridge configuration for cross-chain payment routing
|
|
27
|
+
*
|
|
28
|
+
* Determines the optimal payment routing based on the destination chain/token
|
|
29
|
+
* and the wallet payment option selected by the user. This function handles
|
|
30
|
+
* the complexity of multi-chain payments by:
|
|
31
|
+
*
|
|
32
|
+
* 1. **Preferred Payment Method**: Identifies which chain/token the user will pay from
|
|
33
|
+
* - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, and BSC USDT
|
|
34
|
+
* - Sets appropriate chain ID and token address for the source transaction
|
|
35
|
+
*
|
|
36
|
+
* 2. **Destination Configuration**: Determines where funds will be received
|
|
37
|
+
* - Supports Base, Solana, and Stellar as destination chains
|
|
38
|
+
* - Handles special address formats for Solana and Stellar addresses
|
|
39
|
+
* - Defaults to Base USDC when no special destination is specified
|
|
40
|
+
*
|
|
41
|
+
* 3. **Cross-Chain Bridging**: Configures the payment bridge parameters
|
|
42
|
+
* - Maps user's selected wallet/token to the appropriate payment method
|
|
43
|
+
* - Sets up destination chain and token configuration
|
|
44
|
+
* - Handles token address formatting (e.g., Stellar's `USDC:issuerPK` format)
|
|
45
|
+
*
|
|
46
|
+
* @param config - Payment bridge configuration parameters
|
|
47
|
+
* @param config.toChain - Destination chain ID (defaults to Base: 8453)
|
|
48
|
+
* @param config.toToken - Destination token address (defaults to Base USDC)
|
|
49
|
+
* @param config.toAddress - Standard EVM destination address
|
|
50
|
+
* @param config.toStellarAddress - Stellar-specific destination address (if paying to Stellar)
|
|
51
|
+
* @param config.toSolanaAddress - Solana-specific destination address (if paying to Solana)
|
|
52
|
+
* @param config.toUnits - Amount in token units (smallest denomination)
|
|
53
|
+
* @param config.payInTokenAddress - Token address user selected to pay with
|
|
54
|
+
* @param config.log - Optional logging function for debugging
|
|
55
|
+
*
|
|
56
|
+
* @returns Payment routing configuration
|
|
57
|
+
* @returns preferred - Source payment configuration (chain, token user will pay from)
|
|
58
|
+
* @returns destination - Destination payment configuration (chain, token user will receive)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // User wants to pay with Polygon USDC to receive on Base
|
|
63
|
+
* const { preferred, destination } = createPaymentBridgeConfig({
|
|
64
|
+
* toChain: 8453, // Base
|
|
65
|
+
* toToken: baseUSDC.token,
|
|
66
|
+
* toAddress: '0x123...',
|
|
67
|
+
* toUnits: '1000000', // 1 USDC
|
|
68
|
+
* payInTokenAddress: polygonUSDC.token,
|
|
69
|
+
* log: console.log
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // preferred = { preferredChain: '137', preferredToken: 'USDC', preferredTokenAddress: '0x2791...' }
|
|
73
|
+
* // destination = { destinationAddress: '0x123...', chainId: '8453', amountUnits: '1000000', ... }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // User wants to pay to a Stellar address
|
|
79
|
+
* const { preferred, destination } = createPaymentBridgeConfig({
|
|
80
|
+
* toStellarAddress: 'GDZS...',
|
|
81
|
+
* toUnits: '1000000',
|
|
82
|
+
* payInTokenAddress: baseUSDC.token,
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // destination will be configured for Stellar chain with USDC:issuerPK format
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @note Currently only supports Base USDC and Stellar USDC as destination chains.
|
|
89
|
+
* Support for additional destination chains is planned.
|
|
90
|
+
*
|
|
91
|
+
* @see PreferredPaymentConfig
|
|
92
|
+
* @see DestinationConfig
|
|
93
|
+
*/
|
|
94
|
+
export declare function createPaymentBridgeConfig({ toChain, toToken, toAddress, toStellarAddress, toSolanaAddress, toUnits, payInTokenAddress, log, }: PaymentBridgeConfig): {
|
|
95
|
+
preferred: PreferredPaymentConfig;
|
|
96
|
+
destination: DestinationConfig;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Transforms a payment API response into a fully hydrated order object
|
|
100
|
+
*
|
|
101
|
+
* Converts the payment response data from the RozoAI payment API into a complete
|
|
102
|
+
* `RozoPayHydratedOrderWithOrg` object that contains all the information needed
|
|
103
|
+
* to display order status, track payments, and handle cross-chain transactions.
|
|
104
|
+
*
|
|
105
|
+
* This function performs several key transformations:
|
|
106
|
+
*
|
|
107
|
+
* 1. **Token Resolution**: Identifies the correct token based on chain and address
|
|
108
|
+
* - Uses `getKnownToken()` to resolve token metadata (decimals, symbol, logo, etc.)
|
|
109
|
+
* - Handles special cases for Stellar tokens using issuer public key
|
|
110
|
+
*
|
|
111
|
+
* 2. **Order Structure**: Creates a complete order with all required fields
|
|
112
|
+
* - Generates random order ID for internal tracking
|
|
113
|
+
* - Sets up intent, handoff, and contract addresses
|
|
114
|
+
* - Configures bridge token options and destination amounts
|
|
115
|
+
*
|
|
116
|
+
* 3. **Status Initialization**: Sets initial payment statuses
|
|
117
|
+
* - Source status: WAITING_PAYMENT (awaiting user transaction)
|
|
118
|
+
* - Destination status: PENDING (not yet received)
|
|
119
|
+
* - Intent status: UNPAID (payment not initiated)
|
|
120
|
+
*
|
|
121
|
+
* 4. **Metadata Merge**: Combines various metadata sources
|
|
122
|
+
* - Merges order metadata, user metadata, and custom metadata
|
|
123
|
+
* - Preserves external ID and organization information
|
|
124
|
+
*
|
|
125
|
+
* @param order - Payment response data from the RozoAI payment API
|
|
126
|
+
* @param order.metadata - Payment metadata including chain, token, and routing info
|
|
127
|
+
* @param order.destination - Destination configuration (chain, token, amount, address)
|
|
128
|
+
* @param order.source - Source transaction info (if payment has been initiated)
|
|
129
|
+
* @param order.orgId - Organization ID for the payment
|
|
130
|
+
* @param order.externalId - External reference ID (if provided by merchant)
|
|
131
|
+
*
|
|
132
|
+
* @returns Complete hydrated order object with all payment tracking information
|
|
133
|
+
* @returns id - Unique order identifier (random BigInt)
|
|
134
|
+
* @returns mode - Order mode (HYDRATED)
|
|
135
|
+
* @returns sourceStatus - Source transaction status
|
|
136
|
+
* @returns destStatus - Destination transaction status
|
|
137
|
+
* @returns intentStatus - Overall payment intent status
|
|
138
|
+
* @returns metadata - Merged metadata from all sources
|
|
139
|
+
* @returns org - Organization information
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const paymentResponse = await getRozoPayment(paymentId);
|
|
144
|
+
*
|
|
145
|
+
* const hydratedOrder = formatPaymentResponseDataToHydratedOrder(
|
|
146
|
+
* paymentResponse.data,
|
|
147
|
+
* 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'
|
|
148
|
+
* );
|
|
149
|
+
*
|
|
150
|
+
* console.log(hydratedOrder.sourceStatus); // 'WAITING_PAYMENT'
|
|
151
|
+
* console.log(hydratedOrder.destFinalCallTokenAmount.token.symbol); // 'USDC'
|
|
152
|
+
* console.log(hydratedOrder.usdValue); // 10.00
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @note The generated order ID is random and intended for client-side tracking only.
|
|
156
|
+
* Use `externalId` or the API payment ID for server-side reference.
|
|
157
|
+
*
|
|
158
|
+
* @note The function sets a 5-minute expiration timestamp from the current time.
|
|
159
|
+
*
|
|
160
|
+
* @see PaymentResponseData
|
|
161
|
+
* @see RozoPayHydratedOrderWithOrg
|
|
162
|
+
* @see getKnownToken
|
|
163
|
+
*/
|
|
164
|
+
export declare function formatResponseToHydratedOrder(order: PaymentResponseData): RozoPayHydratedOrderWithOrg;
|