@rozoai/intent-common 0.0.28-beta.2 → 0.0.28-beta.3

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/bridge.js ADDED
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPaymentBridgeConfig = createPaymentBridgeConfig;
4
+ exports.formatResponseToHydratedOrder = formatResponseToHydratedOrder;
5
+ const viem_1 = require("viem");
6
+ const _1 = require(".");
7
+ /**
8
+ * Creates payment bridge configuration for cross-chain payment routing
9
+ *
10
+ * Determines the optimal payment routing based on the destination chain/token
11
+ * and the wallet payment option selected by the user. This function handles
12
+ * the complexity of multi-chain payments by:
13
+ *
14
+ * 1. **Preferred Payment Method**: Identifies which chain/token the user will pay from
15
+ * - Supports Base USDC, Polygon USDC, Solana USDC, Stellar USDC, and BSC USDT
16
+ * - Sets appropriate chain ID and token address for the source transaction
17
+ *
18
+ * 2. **Destination Configuration**: Determines where funds will be received
19
+ * - Supports Base, Solana, and Stellar as destination chains
20
+ * - Handles special address formats for Solana and Stellar addresses
21
+ * - Defaults to Base USDC when no special destination is specified
22
+ *
23
+ * 3. **Cross-Chain Bridging**: Configures the payment bridge parameters
24
+ * - Maps user's selected wallet/token to the appropriate payment method
25
+ * - Sets up destination chain and token configuration
26
+ * - Handles token address formatting (e.g., Stellar's `USDC:issuerPK` format)
27
+ *
28
+ * @param config - Payment bridge configuration parameters
29
+ * @param config.toChain - Destination chain ID (defaults to Base: 8453)
30
+ * @param config.toToken - Destination token address (defaults to Base USDC)
31
+ * @param config.toAddress - Standard EVM destination address
32
+ * @param config.toStellarAddress - Stellar-specific destination address (if paying to Stellar)
33
+ * @param config.toSolanaAddress - Solana-specific destination address (if paying to Solana)
34
+ * @param config.toUnits - Amount in token units (smallest denomination)
35
+ * @param config.payInTokenAddress - Token address user selected to pay with
36
+ * @param config.log - Optional logging function for debugging
37
+ *
38
+ * @returns Payment routing configuration
39
+ * @returns preferred - Source payment configuration (chain, token user will pay from)
40
+ * @returns destination - Destination payment configuration (chain, token user will receive)
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // User wants to pay with Polygon USDC to receive on Base
45
+ * const { preferred, destination } = createPaymentBridgeConfig({
46
+ * toChain: 8453, // Base
47
+ * toToken: baseUSDC.token,
48
+ * toAddress: '0x123...',
49
+ * toUnits: '1000000', // 1 USDC
50
+ * payInTokenAddress: polygonUSDC.token,
51
+ * log: console.log
52
+ * });
53
+ *
54
+ * // preferred = { preferredChain: '137', preferredToken: 'USDC', preferredTokenAddress: '0x2791...' }
55
+ * // destination = { destinationAddress: '0x123...', chainId: '8453', amountUnits: '1000000', ... }
56
+ * ```
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // User wants to pay to a Stellar address
61
+ * const { preferred, destination } = createPaymentBridgeConfig({
62
+ * toStellarAddress: 'GDZS...',
63
+ * toUnits: '1000000',
64
+ * payInTokenAddress: baseUSDC.token,
65
+ * });
66
+ *
67
+ * // destination will be configured for Stellar chain with USDC:issuerPK format
68
+ * ```
69
+ *
70
+ * @note Currently only supports Base USDC and Stellar USDC as destination chains.
71
+ * Support for additional destination chains is planned.
72
+ *
73
+ * @see PreferredPaymentConfig
74
+ * @see DestinationConfig
75
+ */
76
+ function createPaymentBridgeConfig({ toChain = _1.baseUSDC.chainId, toToken = _1.baseUSDC.token, toAddress, toStellarAddress, toSolanaAddress, toUnits, payInTokenAddress, log, }) {
77
+ // Default configuration for Base USDC payments
78
+ let preferred = {
79
+ preferredChain: String(toChain),
80
+ preferredToken: "USDC",
81
+ };
82
+ let destination = {
83
+ destinationAddress: toAddress,
84
+ chainId: String(toChain),
85
+ amountUnits: toUnits,
86
+ tokenSymbol: "USDC",
87
+ tokenAddress: toToken,
88
+ };
89
+ /**
90
+ * IMPORTANT: Because we only support PAY OUT USDC BASE & STELLAR
91
+ * So, We force toChain and toToken to Base USDC as default PayParams
92
+ *
93
+ * @TODO: Adjust this when we support another PAY OUT chain
94
+ */
95
+ if (toChain === _1.base.chainId && toToken === _1.baseUSDC.token) {
96
+ // Determine preferred payment method based on wallet selection
97
+ if (payInTokenAddress) {
98
+ // Pay In USDC Polygon
99
+ if (payInTokenAddress === _1.polygonUSDC.token) {
100
+ log?.(`[Payment Bridge] Pay In USDC Polygon`);
101
+ preferred = {
102
+ preferredChain: String(_1.polygonUSDC.chainId),
103
+ preferredToken: "USDC",
104
+ preferredTokenAddress: _1.polygonUSDC.token,
105
+ };
106
+ }
107
+ // Pay In USDC Solana
108
+ else if (payInTokenAddress === _1.rozoSolanaUSDC.token) {
109
+ log?.(`[Payment Bridge] Pay In USDC Solana`);
110
+ preferred = {
111
+ preferredChain: String(_1.rozoSolanaUSDC.chainId),
112
+ preferredToken: "USDC",
113
+ preferredTokenAddress: _1.rozoSolanaUSDC.token,
114
+ };
115
+ }
116
+ // Pay In USDC Stellar
117
+ else if (payInTokenAddress === _1.rozoStellarUSDC.token) {
118
+ log?.(`[Payment Bridge] Pay In USDC Stellar`);
119
+ preferred = {
120
+ preferredChain: String(_1.rozoStellarUSDC.chainId),
121
+ preferredToken: "USDC",
122
+ preferredTokenAddress: `USDC:${_1.rozoStellarUSDC.token}`,
123
+ };
124
+ }
125
+ // Pay In USDT BSC
126
+ else if (payInTokenAddress === _1.bscUSDT.token) {
127
+ log?.(`[Payment Bridge] Pay In USDT BSC`);
128
+ preferred = {
129
+ preferredChain: String(_1.bscUSDT.chainId),
130
+ preferredToken: "USDT",
131
+ preferredTokenAddress: _1.bscUSDT.token,
132
+ };
133
+ }
134
+ }
135
+ // Determine destination based on special address types
136
+ if (toStellarAddress) {
137
+ log?.(`[Payment Bridge] Pay Out USDC Stellar`);
138
+ destination = {
139
+ destinationAddress: toStellarAddress,
140
+ chainId: String(_1.rozoStellar.chainId),
141
+ amountUnits: toUnits,
142
+ tokenSymbol: "USDC",
143
+ tokenAddress: `USDC:${_1.rozoStellarUSDC.token}`,
144
+ };
145
+ }
146
+ else if (toSolanaAddress) {
147
+ log?.(`[Payment Bridge] Pay Out USDC Solana`);
148
+ destination = {
149
+ destinationAddress: toSolanaAddress,
150
+ chainId: String(_1.rozoSolanaUSDC.chainId),
151
+ amountUnits: toUnits,
152
+ tokenSymbol: "USDC",
153
+ tokenAddress: _1.rozoSolanaUSDC.token,
154
+ };
155
+ }
156
+ else {
157
+ log?.(`[Payment Bridge] Pay Out USDC Base`);
158
+ // Keep default Base configuration
159
+ }
160
+ }
161
+ return { preferred, destination };
162
+ }
163
+ /**
164
+ * Transforms a payment API response into a fully hydrated order object
165
+ *
166
+ * Converts the payment response data from the RozoAI payment API into a complete
167
+ * `RozoPayHydratedOrderWithOrg` object that contains all the information needed
168
+ * to display order status, track payments, and handle cross-chain transactions.
169
+ *
170
+ * This function performs several key transformations:
171
+ *
172
+ * 1. **Token Resolution**: Identifies the correct token based on chain and address
173
+ * - Uses `getKnownToken()` to resolve token metadata (decimals, symbol, logo, etc.)
174
+ * - Handles special cases for Stellar tokens using issuer public key
175
+ *
176
+ * 2. **Order Structure**: Creates a complete order with all required fields
177
+ * - Generates random order ID for internal tracking
178
+ * - Sets up intent, handoff, and contract addresses
179
+ * - Configures bridge token options and destination amounts
180
+ *
181
+ * 3. **Status Initialization**: Sets initial payment statuses
182
+ * - Source status: WAITING_PAYMENT (awaiting user transaction)
183
+ * - Destination status: PENDING (not yet received)
184
+ * - Intent status: UNPAID (payment not initiated)
185
+ *
186
+ * 4. **Metadata Merge**: Combines various metadata sources
187
+ * - Merges order metadata, user metadata, and custom metadata
188
+ * - Preserves external ID and organization information
189
+ *
190
+ * @param order - Payment response data from the RozoAI payment API
191
+ * @param order.metadata - Payment metadata including chain, token, and routing info
192
+ * @param order.destination - Destination configuration (chain, token, amount, address)
193
+ * @param order.source - Source transaction info (if payment has been initiated)
194
+ * @param order.orgId - Organization ID for the payment
195
+ * @param order.externalId - External reference ID (if provided by merchant)
196
+ *
197
+ * @returns Complete hydrated order object with all payment tracking information
198
+ * @returns id - Unique order identifier (random BigInt)
199
+ * @returns mode - Order mode (HYDRATED)
200
+ * @returns sourceStatus - Source transaction status
201
+ * @returns destStatus - Destination transaction status
202
+ * @returns intentStatus - Overall payment intent status
203
+ * @returns metadata - Merged metadata from all sources
204
+ * @returns org - Organization information
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const paymentResponse = await getRozoPayment(paymentId);
209
+ *
210
+ * const hydratedOrder = formatPaymentResponseDataToHydratedOrder(
211
+ * paymentResponse.data,
212
+ * 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'
213
+ * );
214
+ *
215
+ * console.log(hydratedOrder.sourceStatus); // 'WAITING_PAYMENT'
216
+ * console.log(hydratedOrder.destFinalCallTokenAmount.token.symbol); // 'USDC'
217
+ * console.log(hydratedOrder.usdValue); // 10.00
218
+ * ```
219
+ *
220
+ * @note The generated order ID is random and intended for client-side tracking only.
221
+ * Use `externalId` or the API payment ID for server-side reference.
222
+ *
223
+ * @note The function sets a 5-minute expiration timestamp from the current time.
224
+ *
225
+ * @see PaymentResponseData
226
+ * @see RozoPayHydratedOrderWithOrg
227
+ * @see getKnownToken
228
+ */
229
+ function formatResponseToHydratedOrder(order) {
230
+ const destAddress = order.metadata.receivingAddress;
231
+ const requiredChain = order.metadata.preferredChain || _1.baseUSDC.chainId;
232
+ const chain = (0, _1.getKnownToken)(Number(requiredChain), Number(requiredChain) === _1.rozoStellar.chainId
233
+ ? _1.rozoStellarUSDC.token
234
+ : order.metadata.preferredTokenAddress);
235
+ return {
236
+ id: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
237
+ mode: _1.RozoPayOrderMode.HYDRATED,
238
+ intentAddr: destAddress,
239
+ handoffAddr: destAddress,
240
+ escrowContractAddress: destAddress,
241
+ bridgerContractAddress: destAddress,
242
+ // @TODO: use correct destination token
243
+ bridgeTokenOutOptions: [
244
+ {
245
+ token: {
246
+ chainId: _1.baseUSDC.chainId,
247
+ token: _1.baseUSDC.token,
248
+ symbol: _1.baseUSDC.symbol,
249
+ usd: 1,
250
+ priceFromUsd: 1,
251
+ decimals: _1.baseUSDC.decimals,
252
+ displayDecimals: 2,
253
+ logoSourceURI: _1.baseUSDC.logoSourceURI,
254
+ logoURI: _1.baseUSDC.logoURI,
255
+ maxAcceptUsd: 100000,
256
+ maxSendUsd: 0,
257
+ },
258
+ amount: (0, viem_1.parseUnits)(order.destination.amountUnits, _1.baseUSDC.decimals).toString(),
259
+ usd: Number(order.destination.amountUnits),
260
+ },
261
+ ],
262
+ selectedBridgeTokenOutAddr: null,
263
+ selectedBridgeTokenOutAmount: null,
264
+ destFinalCallTokenAmount: {
265
+ token: {
266
+ chainId: chain ? chain.chainId : _1.baseUSDC.chainId,
267
+ token: chain ? chain.token : _1.baseUSDC.token,
268
+ symbol: chain ? chain.symbol : _1.baseUSDC.symbol,
269
+ usd: 1,
270
+ priceFromUsd: 1,
271
+ decimals: chain ? chain.decimals : _1.baseUSDC.decimals,
272
+ displayDecimals: 2,
273
+ logoSourceURI: chain ? chain.logoSourceURI : _1.baseUSDC.logoSourceURI,
274
+ logoURI: chain ? chain.logoURI : _1.baseUSDC.logoURI,
275
+ maxAcceptUsd: 100000,
276
+ maxSendUsd: 0,
277
+ },
278
+ amount: (0, viem_1.parseUnits)(order.destination.amountUnits, chain ? chain.decimals : _1.baseUSDC.decimals).toString(),
279
+ usd: Number(order.destination.amountUnits),
280
+ },
281
+ usdValue: Number(order.destination.amountUnits),
282
+ destFinalCall: {
283
+ to: destAddress,
284
+ value: BigInt("0"),
285
+ data: "0x",
286
+ },
287
+ refundAddr: order.source?.sourceAddress || null,
288
+ nonce: order.nonce,
289
+ sourceTokenAmount: null,
290
+ sourceFulfillerAddr: null,
291
+ sourceInitiateTxHash: null,
292
+ sourceStartTxHash: null,
293
+ sourceStatus: _1.RozoPayOrderStatusSource.WAITING_PAYMENT,
294
+ destStatus: _1.RozoPayOrderStatusDest.PENDING,
295
+ intentStatus: _1.RozoPayIntentStatus.UNPAID,
296
+ destFastFinishTxHash: null,
297
+ destClaimTxHash: null,
298
+ redirectUri: null,
299
+ createdAt: Math.floor(Date.now() / 1000),
300
+ lastUpdatedAt: Math.floor(Date.now() / 1000),
301
+ orgId: order.orgId,
302
+ metadata: {
303
+ ...(order?.metadata ?? {}),
304
+ ...(order.userMetadata ?? {}),
305
+ ...(order.metadata ?? {}),
306
+ },
307
+ externalId: order.externalId,
308
+ userMetadata: order.userMetadata,
309
+ expirationTs: BigInt(Math.floor(Date.now() / 1000 + 5 * 60).toString()),
310
+ org: {
311
+ orgId: order.orgId,
312
+ name: "Pay Rozo",
313
+ },
314
+ };
315
+ }
316
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":";;AAiHA,8DAoGC;AAoED,sEAoGC;AA7XD,+BAAkC;AAClC,wBAeW;AA4BX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,SAAgB,yBAAyB,CAAC,EACxC,OAAO,GAAG,WAAQ,CAAC,OAAO,EAC1B,OAAO,GAAG,WAAQ,CAAC,KAAK,EACxB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,iBAAiB,EACjB,GAAG,GACiB;IAIpB,+CAA+C;IAC/C,IAAI,SAAS,GAA2B;QACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC;QAC/B,cAAc,EAAE,MAAM;KACvB,CAAC;IAEF,IAAI,WAAW,GAAsB;QACnC,kBAAkB,EAAE,SAAS;QAC7B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACxB,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,MAAM;QACnB,YAAY,EAAE,OAAO;KACtB,CAAC;IAEF;;;;;OAKG;IACH,IAAI,OAAO,KAAK,OAAI,CAAC,OAAO,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U,EAAE,yBAAsB,CAAC,OAAO;QAC1C,YAAY,EAAE,sBAAmB,CAAC,MAAM;QACxC,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;QACrB,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QACxC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5C,KAAK,EAAE,KAAK,CAAC,KAAe;QAC5B,QAAQ,EAAE;YACR,GAAG,CAAC,KAAK,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC1B,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;YAC7B,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;SACnB;QACR,UAAU,EAAE,KAAK,CAAC,UAA2B;QAC7C,YAAY,EAAE,KAAK,CAAC,YAA0C;QAC9D,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACvE,GAAG,EAAE;YACH,KAAK,EAAE,KAAK,CAAC,KAAe;YAC5B,IAAI,EAAE,UAAU;SACjB;KACF,CAAC;AACJ,CAAC"}
@@ -122,10 +122,6 @@ export declare const zRozoPayOrderMetadata: z.ZodObject<{
122
122
  price?: string | undefined;
123
123
  priceDetails?: string | undefined;
124
124
  }[];
125
- style?: {
126
- background?: string | undefined;
127
- } | undefined;
128
- orgLogo?: string | undefined;
129
125
  payer?: {
130
126
  preferredChains?: number[] | undefined;
131
127
  preferredTokens?: {
@@ -136,6 +132,10 @@ export declare const zRozoPayOrderMetadata: z.ZodObject<{
136
132
  paymentOptions?: string[] | undefined;
137
133
  } | undefined;
138
134
  memo?: string | undefined;
135
+ style?: {
136
+ background?: string | undefined;
137
+ } | undefined;
138
+ orgLogo?: string | undefined;
139
139
  customDeeplinkUrl?: string | undefined;
140
140
  }, {
141
141
  intent: string;
@@ -146,10 +146,6 @@ export declare const zRozoPayOrderMetadata: z.ZodObject<{
146
146
  price?: string | undefined;
147
147
  priceDetails?: string | undefined;
148
148
  }[];
149
- style?: {
150
- background?: string | undefined;
151
- } | undefined;
152
- orgLogo?: string | undefined;
153
149
  payer?: {
154
150
  preferredChains?: number[] | undefined;
155
151
  preferredTokens?: {
@@ -160,6 +156,10 @@ export declare const zRozoPayOrderMetadata: z.ZodObject<{
160
156
  paymentOptions?: string[] | undefined;
161
157
  } | undefined;
162
158
  memo?: string | undefined;
159
+ style?: {
160
+ background?: string | undefined;
161
+ } | undefined;
162
+ orgLogo?: string | undefined;
163
163
  customDeeplinkUrl?: string | undefined;
164
164
  }>;
165
165
  export type RozoPayOrderMetadata = z.infer<typeof zRozoPayOrderMetadata>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ export * from "./api";
1
2
  export * from "./assert";
3
+ export * from "./bridge";
2
4
  export * from "./chain";
3
5
  export * from "./daimoPay";
4
6
  export * from "./debug";
package/dist/index.js CHANGED
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
17
18
  __exportStar(require("./assert"), exports);
19
+ __exportStar(require("./bridge"), exports);
18
20
  __exportStar(require("./chain"), exports);
19
21
  __exportStar(require("./daimoPay"), exports);
20
22
  __exportStar(require("./debug"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rozoai/intent-common",
3
- "version": "0.0.28-beta.2",
3
+ "version": "0.0.28-beta.3",
4
4
  "description": "Intent Pay shared types and utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,275 @@
1
+ # API Client Utility
2
+
3
+ A clean, flexible TypeScript utility for handling API requests to the RozoAI API service.
4
+
5
+ ## Overview
6
+
7
+ This utility provides a modular approach to API requests with:
8
+
9
+ - A base client for core HTTP operations
10
+ - Endpoint-specific modules for domain operations
11
+ - TypeScript interfaces for type safety
12
+ - Configuration management for API URLs and tokens
13
+ - Pre-configured defaults for RozoAI API
14
+
15
+ ## Default Configuration
16
+
17
+ The API client comes pre-configured with RozoAI production settings:
18
+
19
+ ```typescript
20
+ import { ROZO_API_URL, ROZO_API_TOKEN } from "@rozoai/intent-common";
21
+
22
+ console.log(ROZO_API_URL); // "https://intentapiv2.rozo.ai/functions/v1"
23
+ console.log(ROZO_API_TOKEN); // Pre-configured production token
24
+ ```
25
+
26
+ These defaults are automatically used by the API client, so you can start making requests immediately without any configuration.
27
+
28
+ ## Structure
29
+
30
+ ```bash
31
+ api/
32
+ ├── base.ts # Core API client functionality
33
+ ├── index.ts # Re-exports all API modules
34
+ ├── payment.ts # Payment-specific endpoints
35
+ └── README.md # Documentation
36
+ ```
37
+
38
+ ## Base API Client
39
+
40
+ The base client (`base.ts`) provides the foundation for all API requests:
41
+
42
+ ```typescript
43
+ import { apiClient, setApiConfig } from "@rozoai/intent-common";
44
+
45
+ // Configure the API client (optional, uses defaults if not set)
46
+ setApiConfig({
47
+ baseUrl: "https://intentapiv2.rozo.ai/functions/v1",
48
+ apiToken: "your-api-token",
49
+ });
50
+
51
+ // Make a GET request
52
+ const response = await apiClient.get("/some-endpoint");
53
+
54
+ // Make a POST request with data
55
+ const response = await apiClient.post("/some-endpoint", { data: "value" });
56
+
57
+ // Make a request with custom headers
58
+ const response = await apiClient.get("/some-endpoint", {
59
+ headers: { "Custom-Header": "value" },
60
+ });
61
+
62
+ // Make a request with query parameters
63
+ const response = await apiClient.get("/some-endpoint", {
64
+ params: { filter: "active", sort: "desc" },
65
+ });
66
+ ```
67
+
68
+ ## Using Payment API
69
+
70
+ The payment module provides typed functions for payment operations:
71
+
72
+ ```typescript
73
+ import {
74
+ createRozoPayment,
75
+ getRozoPayment,
76
+ createRozoPaymentRequest,
77
+ } from "@rozoai/intent-common";
78
+
79
+ // Create a payment
80
+ const handleSubmitPayment = async () => {
81
+ const paymentData = createRozoPaymentRequest({
82
+ appId: "your-app-id",
83
+ display: {
84
+ intent: "Pay for product",
85
+ paymentValue: "100.00",
86
+ currency: "USD",
87
+ },
88
+ destination: {
89
+ chainId: "8453",
90
+ amountUnits: "100000000",
91
+ tokenSymbol: "USDC",
92
+ tokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
93
+ },
94
+ });
95
+
96
+ const response = await createRozoPayment(paymentData);
97
+
98
+ if (response.data) {
99
+ console.log("Payment created:", response.data.id);
100
+ } else if (response.error) {
101
+ console.error("Error creating payment:", response.error.message);
102
+ }
103
+ };
104
+
105
+ // Get payment details
106
+ const fetchPaymentDetails = async (paymentId: string) => {
107
+ const response = await getRozoPayment(paymentId);
108
+
109
+ if (response.data) {
110
+ console.log("Payment status:", response.data.status);
111
+ }
112
+ };
113
+ ```
114
+
115
+ ## React Hooks
116
+
117
+ React hooks for these APIs are available in the `@rozoai/intent-pay` package:
118
+
119
+ ```typescript
120
+ // In @rozoai/intent-pay
121
+ import {
122
+ useCreateRozoPayment,
123
+ useRozoPayment,
124
+ useRozoPayments
125
+ } from '@rozoai/intent-pay';
126
+
127
+ // Use in React components
128
+ const PaymentForm = () => {
129
+ const [paymentState, submitPayment] = useCreateRozoPayment();
130
+
131
+ const handleSubmit = (formData) => {
132
+ submitPayment({
133
+ appId: 'your-app-id',
134
+ display: { ... },
135
+ destination: { ... }
136
+ });
137
+ };
138
+
139
+ if (paymentState.isLoading) return <div>Processing...</div>;
140
+ if (paymentState.isError) return <div>Error: {paymentState.error?.message}</div>;
141
+ if (paymentState.isSuccess) return <div>Success! ID: {paymentState.data?.id}</div>;
142
+
143
+ return <FormComponent onSubmit={handleSubmit} />;
144
+ };
145
+ ```
146
+
147
+ ## Error Handling
148
+
149
+ All API responses include standardized error handling:
150
+
151
+ ```typescript
152
+ const response = await createRozoPayment(data);
153
+
154
+ if (response.error) {
155
+ // Handle error
156
+ console.error("API Error:", response.error.message);
157
+ return;
158
+ }
159
+
160
+ // Process successful response
161
+ const paymentData = response.data;
162
+ ```
163
+
164
+ ## TypeScript Integration
165
+
166
+ All functions are fully typed:
167
+
168
+ ```typescript
169
+ import { PaymentResponseData, ApiResponse } from "@rozoai/intent-common";
170
+
171
+ const response: ApiResponse<PaymentResponseData> = await getRozoPayment(
172
+ paymentId
173
+ );
174
+ // response.data will be typed as PaymentResponseData | null
175
+ ```
176
+
177
+ ## Configuration
178
+
179
+ ### Using Default Configuration
180
+
181
+ The API client is pre-configured with production RozoAI settings, so you can use it immediately:
182
+
183
+ ```typescript
184
+ import { createRozoPayment } from "@rozoai/intent-common";
185
+
186
+ // Works out of the box with default configuration
187
+ const response = await createRozoPayment({
188
+ appId: "your-app-id",
189
+ display: { intent: "Payment", paymentValue: "10.00", currency: "USD" },
190
+ destination: {
191
+ chainId: "8453",
192
+ amountUnits: "10000000",
193
+ tokenSymbol: "USDC",
194
+ },
195
+ });
196
+ ```
197
+
198
+ ### Customizing Configuration
199
+
200
+ For testing, staging, or custom environments, you can override the defaults:
201
+
202
+ ```typescript
203
+ import {
204
+ setApiConfig,
205
+ getApiConfig,
206
+ ROZO_API_URL,
207
+ ROZO_API_TOKEN,
208
+ } from "@rozoai/intent-common";
209
+
210
+ // Override for staging environment
211
+ setApiConfig({
212
+ baseUrl: "https://staging-api.rozo.ai/v1",
213
+ apiToken: "your-staging-token",
214
+ });
215
+
216
+ // Or reset to production defaults
217
+ setApiConfig({
218
+ baseUrl: ROZO_API_URL,
219
+ apiToken: ROZO_API_TOKEN,
220
+ });
221
+
222
+ // Get current configuration
223
+ const config = getApiConfig();
224
+ console.log(config.baseUrl, config.apiToken);
225
+ ```
226
+
227
+ ### Configuration in Different Environments
228
+
229
+ **Production (Default):**
230
+
231
+ ```typescript
232
+ // No configuration needed - uses ROZO_API_URL and ROZO_API_TOKEN automatically
233
+ import { createRozoPayment } from "@rozoai/intent-common";
234
+ const response = await createRozoPayment(data);
235
+ ```
236
+
237
+ **Staging:**
238
+
239
+ ```typescript
240
+ import { setApiConfig } from "@rozoai/intent-common";
241
+
242
+ setApiConfig({
243
+ baseUrl: "https://staging.intentapi.rozo.ai/v1",
244
+ apiToken: process.env.STAGING_API_TOKEN,
245
+ });
246
+ ```
247
+
248
+ **Development/Testing:**
249
+
250
+ ```typescript
251
+ import { setApiConfig } from "@rozoai/intent-common";
252
+
253
+ setApiConfig({
254
+ baseUrl: "http://localhost:3000/api",
255
+ apiToken: "dev_token",
256
+ });
257
+ ```
258
+
259
+ ## Available Payment Functions
260
+
261
+ - `createRozoPayment(paymentData)` - Create a new payment
262
+ - `getRozoPayment(paymentId)` - Get payment by ID
263
+ - `getRozoPaymentByExternalId(externalId)` - Get payment by external ID
264
+ - `updateRozoPayment(paymentId, paymentData)` - Update a payment
265
+ - `cancelRozoPayment(paymentId)` - Cancel a payment
266
+ - `listRozoPayments(params?)` - List all payments with optional filters
267
+ - `createRozoPaymentRequest(options)` - Create a payment request payload
268
+
269
+ ## Best Practices
270
+
271
+ - Configure the API client once at app initialization
272
+ - Leverage TypeScript interfaces for type safety
273
+ - Handle loading, error, and success states properly
274
+ - Use the React hooks (from @rozoai/intent-pay) when working in React components
275
+ - Implement proper error handling for all API calls