@lavapayments/nodejs 2.5.1 → 2.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/dist/index.d.mts CHANGED
@@ -89,76 +89,72 @@ declare class Lava {
89
89
  generateForwardToken(options: ForwardTokenOptions): string;
90
90
  }
91
91
 
92
- type CheckoutMode = "onboarding" | "topup";
93
92
  interface CreateCheckoutSessionParams {
94
- checkout_mode: CheckoutMode;
93
+ checkout_mode: "onboarding" | "topup";
95
94
  origin_url: string;
96
95
  reference_id?: string;
97
96
  connection_id?: string;
98
97
  }
99
- interface CheckoutSession {
98
+ interface CheckoutSessionsListParams {
99
+ cursor?: string;
100
+ limit?: number;
101
+ reference_id?: string;
102
+ }
103
+ interface ConnectionsListParams {
104
+ cursor?: string;
105
+ limit?: number;
106
+ reference_id?: string;
107
+ }
108
+ interface RequestsListParams {
109
+ cursor?: string;
110
+ limit?: number;
111
+ connection_id?: string;
112
+ product_id?: string;
113
+ metadata_filters?: Record<string, string>;
114
+ }
115
+ interface RequestsListResponse {
116
+ data: Request[];
117
+ has_more: boolean;
118
+ next_cursor?: string;
119
+ }
120
+ interface UsageParams {
121
+ start: string;
122
+ end?: string;
123
+ connection_id?: string;
124
+ product_id?: string;
125
+ metadata_filters?: Record<string, string>;
126
+ }
127
+ interface ListResponse<T> {
128
+ data: T[];
129
+ has_more: boolean;
130
+ next_cursor?: string;
131
+ }
132
+ type RestCheckoutSession = {
100
133
  checkout_session_id: string;
101
134
  checkout_session_token: string;
102
- checkout_mode: CheckoutMode;
135
+ checkout_mode: "onboarding" | "topup";
103
136
  origin_url: string;
104
137
  connection_id?: string;
105
138
  reference_id?: string;
106
139
  created_at: string;
107
140
  completed_at?: string;
108
- }
109
- interface Wallet {
110
- balance: string;
111
- phone: string;
112
- email: string;
113
- first_name: string;
114
- last_name: string;
115
- }
116
- interface Connection {
141
+ };
142
+ type RestConnection = {
117
143
  connection_id: string;
118
144
  connection_secret: string;
119
145
  reference_id?: string;
120
- wallet: Wallet;
146
+ wallet: {
147
+ balance: string;
148
+ phone: string;
149
+ email: string;
150
+ first_name: string;
151
+ last_name: string;
152
+ };
121
153
  next_usage_reset: string;
122
154
  previous_usage_reset: string;
123
155
  created_at: string;
124
- }
125
- interface ConnectionsListParams {
126
- cursor?: string;
127
- limit?: number;
128
- reference_id?: string;
129
- }
130
- interface ConnectionsListResponse {
131
- data: Connection[];
132
- has_more: boolean;
133
- next_cursor?: string;
134
- }
135
- interface ModelUsage {
136
- input_tokens: number;
137
- output_tokens: number;
138
- total_tokens: number;
139
- input_cost: string;
140
- output_cost: string;
141
- total_cost: string;
142
- }
143
- interface FeeTierBreakdown {
144
- tier: {
145
- start: number;
146
- rate: string;
147
- };
148
- tokens: number;
149
- cost: string;
150
- }
151
- interface Fee {
152
- amount: string;
153
- rate_type: "fixed" | "percentage";
154
- token_basis: "input+output" | "output";
155
- breakdown: FeeTierBreakdown[];
156
- }
157
- interface ServiceCharge {
158
- amount: string;
159
- payer: "wallet" | "merchant";
160
- }
161
- interface Request {
156
+ };
157
+ type RestRequest = {
162
158
  request_id: string;
163
159
  connection_id?: string;
164
160
  product_id?: string;
@@ -167,27 +163,40 @@ interface Request {
167
163
  model: string;
168
164
  endpoint: string;
169
165
  response_id?: string;
170
- model_usage: ModelUsage;
171
- fee: Fee;
172
- service_charge: ServiceCharge;
166
+ model_usage: {
167
+ input_tokens: number;
168
+ output_tokens: number;
169
+ total_tokens: number;
170
+ input_cost: string;
171
+ output_cost: string;
172
+ total_cost: string;
173
+ payer: "wallet" | "merchant";
174
+ };
175
+ fee: {
176
+ amount: string;
177
+ rate_type: "fixed" | "percentage";
178
+ token_basis: "input+output" | "output";
179
+ breakdown: {
180
+ tier: {
181
+ start: number;
182
+ rate: string;
183
+ };
184
+ tokens: number;
185
+ cost: string;
186
+ }[];
187
+ };
188
+ service_charge: {
189
+ amount: string;
190
+ payer: "wallet" | "merchant";
191
+ };
173
192
  total_request_cost: string;
193
+ total_wallet_cost: string;
194
+ total_merchant_cost: string;
174
195
  metadata: Record<string, string>;
175
196
  timestamp: string;
176
197
  created_at: string;
177
- }
178
- interface RequestsListParams {
179
- cursor?: string;
180
- limit?: number;
181
- connection_id?: string;
182
- product_id?: string;
183
- metadata_filters?: Record<string, string>;
184
- }
185
- interface RequestsListResponse {
186
- data: Request[];
187
- has_more: boolean;
188
- next_cursor?: string;
189
- }
190
- interface UsageData {
198
+ };
199
+ type RestUsage = {
191
200
  items: {
192
201
  date: string;
193
202
  total_requests: number;
@@ -196,6 +205,8 @@ interface UsageData {
196
205
  total_fee_amount: string;
197
206
  total_service_charge_amount: string;
198
207
  total_request_cost: string;
208
+ total_wallet_cost: string;
209
+ total_merchant_cost: string;
199
210
  }[];
200
211
  totals: {
201
212
  total_requests: number;
@@ -204,16 +215,10 @@ interface UsageData {
204
215
  total_fee_amount: string;
205
216
  total_service_charge_amount: string;
206
217
  total_request_cost: string;
218
+ total_wallet_cost: string;
219
+ total_merchant_cost: string;
207
220
  };
208
- }
209
- interface UsageParams {
210
- start: string;
211
- end?: string;
212
- connection_id?: string;
213
- product_id?: string;
214
- metadata_filters?: Record<string, string>;
215
- }
216
- type Usage = UsageData[];
221
+ };
217
222
 
218
223
  declare namespace Resources {
219
224
  abstract class BaseResource {
@@ -229,13 +234,19 @@ declare namespace Resources {
229
234
  * @param params Checkout session parameters
230
235
  * @returns Created checkout session
231
236
  */
232
- create(params: CreateCheckoutSessionParams): Promise<CheckoutSession>;
237
+ create(params: CreateCheckoutSessionParams): Promise<RestCheckoutSession>;
238
+ /**
239
+ * List checkout sessions
240
+ * @param params List parameters
241
+ * @returns Paginated list of checkout sessions
242
+ */
243
+ list(params?: CheckoutSessionsListParams): Promise<ListResponse<RestCheckoutSession>>;
233
244
  /**
234
245
  * Retrieve a checkout session
235
246
  * @param checkoutSessionId Checkout session ID
236
247
  * @returns Checkout session details
237
248
  */
238
- retrieve(checkoutSessionId: string): Promise<CheckoutSession>;
249
+ retrieve(checkoutSessionId: string): Promise<RestCheckoutSession>;
239
250
  }
240
251
  /**
241
252
  * Connection related endpoints
@@ -246,13 +257,13 @@ declare namespace Resources {
246
257
  * @param params List parameters
247
258
  * @returns Paginated list of connections
248
259
  */
249
- list(params?: ConnectionsListParams): Promise<ConnectionsListResponse>;
260
+ list(params?: ConnectionsListParams): Promise<ListResponse<RestConnection>>;
250
261
  /**
251
262
  * Retrieve a connection
252
263
  * @param connectionId Connection ID
253
264
  * @returns Connection details
254
265
  */
255
- retrieve(connectionId: string): Promise<Connection>;
266
+ retrieve(connectionId: string): Promise<RestConnection>;
256
267
  /**
257
268
  * Delete a connection
258
269
  * @param connectionId Connection ID
@@ -271,13 +282,13 @@ declare namespace Resources {
271
282
  * @param params List parameters
272
283
  * @returns Paginated list of requests
273
284
  */
274
- list(params?: RequestsListParams): Promise<RequestsListResponse>;
285
+ list(params?: RequestsListParams): Promise<ListResponse<RestRequest>>;
275
286
  /**
276
287
  * Retrieve a request
277
288
  * @param requestId Request ID
278
289
  * @returns Request details
279
290
  */
280
- retrieve(requestId: string): Promise<Request>;
291
+ retrieve(requestId: string): Promise<RestRequest>;
281
292
  }
282
293
  /**
283
294
  * Usage related endpoints
@@ -288,9 +299,9 @@ declare namespace Resources {
288
299
  * @param params Usage parameters
289
300
  * @returns Usage data
290
301
  */
291
- retrieve(params: UsageParams): Promise<Usage>;
302
+ retrieve(params: UsageParams): Promise<RestUsage>;
292
303
  }
293
304
  export { };
294
305
  }
295
306
 
296
- export { type ApiVersion, type CheckoutMode, type CheckoutSession, type Config, type Connection, type ConnectionsListParams, type ConnectionsListResponse, type CreateCheckoutSessionParams, type Fee, type FeeTierBreakdown, type ForwardTokenOptions, Lava, type ModelUsage, type Request, type RequestsListParams, type RequestsListResponse, Resources, type ServiceCharge, type Usage, type UsageData, type UsageParams, type Wallet };
307
+ export { type ApiVersion, type CheckoutSessionsListParams, type Config, type ConnectionsListParams, type CreateCheckoutSessionParams, type ForwardTokenOptions, Lava, type ListResponse, type RequestsListParams, type RequestsListResponse, Resources, type RestCheckoutSession, type RestConnection, type RestRequest, type RestUsage, type UsageParams };
package/dist/index.d.ts CHANGED
@@ -89,76 +89,72 @@ declare class Lava {
89
89
  generateForwardToken(options: ForwardTokenOptions): string;
90
90
  }
91
91
 
92
- type CheckoutMode = "onboarding" | "topup";
93
92
  interface CreateCheckoutSessionParams {
94
- checkout_mode: CheckoutMode;
93
+ checkout_mode: "onboarding" | "topup";
95
94
  origin_url: string;
96
95
  reference_id?: string;
97
96
  connection_id?: string;
98
97
  }
99
- interface CheckoutSession {
98
+ interface CheckoutSessionsListParams {
99
+ cursor?: string;
100
+ limit?: number;
101
+ reference_id?: string;
102
+ }
103
+ interface ConnectionsListParams {
104
+ cursor?: string;
105
+ limit?: number;
106
+ reference_id?: string;
107
+ }
108
+ interface RequestsListParams {
109
+ cursor?: string;
110
+ limit?: number;
111
+ connection_id?: string;
112
+ product_id?: string;
113
+ metadata_filters?: Record<string, string>;
114
+ }
115
+ interface RequestsListResponse {
116
+ data: Request[];
117
+ has_more: boolean;
118
+ next_cursor?: string;
119
+ }
120
+ interface UsageParams {
121
+ start: string;
122
+ end?: string;
123
+ connection_id?: string;
124
+ product_id?: string;
125
+ metadata_filters?: Record<string, string>;
126
+ }
127
+ interface ListResponse<T> {
128
+ data: T[];
129
+ has_more: boolean;
130
+ next_cursor?: string;
131
+ }
132
+ type RestCheckoutSession = {
100
133
  checkout_session_id: string;
101
134
  checkout_session_token: string;
102
- checkout_mode: CheckoutMode;
135
+ checkout_mode: "onboarding" | "topup";
103
136
  origin_url: string;
104
137
  connection_id?: string;
105
138
  reference_id?: string;
106
139
  created_at: string;
107
140
  completed_at?: string;
108
- }
109
- interface Wallet {
110
- balance: string;
111
- phone: string;
112
- email: string;
113
- first_name: string;
114
- last_name: string;
115
- }
116
- interface Connection {
141
+ };
142
+ type RestConnection = {
117
143
  connection_id: string;
118
144
  connection_secret: string;
119
145
  reference_id?: string;
120
- wallet: Wallet;
146
+ wallet: {
147
+ balance: string;
148
+ phone: string;
149
+ email: string;
150
+ first_name: string;
151
+ last_name: string;
152
+ };
121
153
  next_usage_reset: string;
122
154
  previous_usage_reset: string;
123
155
  created_at: string;
124
- }
125
- interface ConnectionsListParams {
126
- cursor?: string;
127
- limit?: number;
128
- reference_id?: string;
129
- }
130
- interface ConnectionsListResponse {
131
- data: Connection[];
132
- has_more: boolean;
133
- next_cursor?: string;
134
- }
135
- interface ModelUsage {
136
- input_tokens: number;
137
- output_tokens: number;
138
- total_tokens: number;
139
- input_cost: string;
140
- output_cost: string;
141
- total_cost: string;
142
- }
143
- interface FeeTierBreakdown {
144
- tier: {
145
- start: number;
146
- rate: string;
147
- };
148
- tokens: number;
149
- cost: string;
150
- }
151
- interface Fee {
152
- amount: string;
153
- rate_type: "fixed" | "percentage";
154
- token_basis: "input+output" | "output";
155
- breakdown: FeeTierBreakdown[];
156
- }
157
- interface ServiceCharge {
158
- amount: string;
159
- payer: "wallet" | "merchant";
160
- }
161
- interface Request {
156
+ };
157
+ type RestRequest = {
162
158
  request_id: string;
163
159
  connection_id?: string;
164
160
  product_id?: string;
@@ -167,27 +163,40 @@ interface Request {
167
163
  model: string;
168
164
  endpoint: string;
169
165
  response_id?: string;
170
- model_usage: ModelUsage;
171
- fee: Fee;
172
- service_charge: ServiceCharge;
166
+ model_usage: {
167
+ input_tokens: number;
168
+ output_tokens: number;
169
+ total_tokens: number;
170
+ input_cost: string;
171
+ output_cost: string;
172
+ total_cost: string;
173
+ payer: "wallet" | "merchant";
174
+ };
175
+ fee: {
176
+ amount: string;
177
+ rate_type: "fixed" | "percentage";
178
+ token_basis: "input+output" | "output";
179
+ breakdown: {
180
+ tier: {
181
+ start: number;
182
+ rate: string;
183
+ };
184
+ tokens: number;
185
+ cost: string;
186
+ }[];
187
+ };
188
+ service_charge: {
189
+ amount: string;
190
+ payer: "wallet" | "merchant";
191
+ };
173
192
  total_request_cost: string;
193
+ total_wallet_cost: string;
194
+ total_merchant_cost: string;
174
195
  metadata: Record<string, string>;
175
196
  timestamp: string;
176
197
  created_at: string;
177
- }
178
- interface RequestsListParams {
179
- cursor?: string;
180
- limit?: number;
181
- connection_id?: string;
182
- product_id?: string;
183
- metadata_filters?: Record<string, string>;
184
- }
185
- interface RequestsListResponse {
186
- data: Request[];
187
- has_more: boolean;
188
- next_cursor?: string;
189
- }
190
- interface UsageData {
198
+ };
199
+ type RestUsage = {
191
200
  items: {
192
201
  date: string;
193
202
  total_requests: number;
@@ -196,6 +205,8 @@ interface UsageData {
196
205
  total_fee_amount: string;
197
206
  total_service_charge_amount: string;
198
207
  total_request_cost: string;
208
+ total_wallet_cost: string;
209
+ total_merchant_cost: string;
199
210
  }[];
200
211
  totals: {
201
212
  total_requests: number;
@@ -204,16 +215,10 @@ interface UsageData {
204
215
  total_fee_amount: string;
205
216
  total_service_charge_amount: string;
206
217
  total_request_cost: string;
218
+ total_wallet_cost: string;
219
+ total_merchant_cost: string;
207
220
  };
208
- }
209
- interface UsageParams {
210
- start: string;
211
- end?: string;
212
- connection_id?: string;
213
- product_id?: string;
214
- metadata_filters?: Record<string, string>;
215
- }
216
- type Usage = UsageData[];
221
+ };
217
222
 
218
223
  declare namespace Resources {
219
224
  abstract class BaseResource {
@@ -229,13 +234,19 @@ declare namespace Resources {
229
234
  * @param params Checkout session parameters
230
235
  * @returns Created checkout session
231
236
  */
232
- create(params: CreateCheckoutSessionParams): Promise<CheckoutSession>;
237
+ create(params: CreateCheckoutSessionParams): Promise<RestCheckoutSession>;
238
+ /**
239
+ * List checkout sessions
240
+ * @param params List parameters
241
+ * @returns Paginated list of checkout sessions
242
+ */
243
+ list(params?: CheckoutSessionsListParams): Promise<ListResponse<RestCheckoutSession>>;
233
244
  /**
234
245
  * Retrieve a checkout session
235
246
  * @param checkoutSessionId Checkout session ID
236
247
  * @returns Checkout session details
237
248
  */
238
- retrieve(checkoutSessionId: string): Promise<CheckoutSession>;
249
+ retrieve(checkoutSessionId: string): Promise<RestCheckoutSession>;
239
250
  }
240
251
  /**
241
252
  * Connection related endpoints
@@ -246,13 +257,13 @@ declare namespace Resources {
246
257
  * @param params List parameters
247
258
  * @returns Paginated list of connections
248
259
  */
249
- list(params?: ConnectionsListParams): Promise<ConnectionsListResponse>;
260
+ list(params?: ConnectionsListParams): Promise<ListResponse<RestConnection>>;
250
261
  /**
251
262
  * Retrieve a connection
252
263
  * @param connectionId Connection ID
253
264
  * @returns Connection details
254
265
  */
255
- retrieve(connectionId: string): Promise<Connection>;
266
+ retrieve(connectionId: string): Promise<RestConnection>;
256
267
  /**
257
268
  * Delete a connection
258
269
  * @param connectionId Connection ID
@@ -271,13 +282,13 @@ declare namespace Resources {
271
282
  * @param params List parameters
272
283
  * @returns Paginated list of requests
273
284
  */
274
- list(params?: RequestsListParams): Promise<RequestsListResponse>;
285
+ list(params?: RequestsListParams): Promise<ListResponse<RestRequest>>;
275
286
  /**
276
287
  * Retrieve a request
277
288
  * @param requestId Request ID
278
289
  * @returns Request details
279
290
  */
280
- retrieve(requestId: string): Promise<Request>;
291
+ retrieve(requestId: string): Promise<RestRequest>;
281
292
  }
282
293
  /**
283
294
  * Usage related endpoints
@@ -288,9 +299,9 @@ declare namespace Resources {
288
299
  * @param params Usage parameters
289
300
  * @returns Usage data
290
301
  */
291
- retrieve(params: UsageParams): Promise<Usage>;
302
+ retrieve(params: UsageParams): Promise<RestUsage>;
292
303
  }
293
304
  export { };
294
305
  }
295
306
 
296
- export { type ApiVersion, type CheckoutMode, type CheckoutSession, type Config, type Connection, type ConnectionsListParams, type ConnectionsListResponse, type CreateCheckoutSessionParams, type Fee, type FeeTierBreakdown, type ForwardTokenOptions, Lava, type ModelUsage, type Request, type RequestsListParams, type RequestsListResponse, Resources, type ServiceCharge, type Usage, type UsageData, type UsageParams, type Wallet };
307
+ export { type ApiVersion, type CheckoutSessionsListParams, type Config, type ConnectionsListParams, type CreateCheckoutSessionParams, type ForwardTokenOptions, Lava, type ListResponse, type RequestsListParams, type RequestsListResponse, Resources, type RestCheckoutSession, type RestConnection, type RestRequest, type RestUsage, type UsageParams };
package/dist/index.js CHANGED
@@ -40,9 +40,33 @@ var Resources;
40
40
  * @returns Created checkout session
41
41
  */
42
42
  async create(params) {
43
- return this.lava.request("POST", "checkout_sessions", {
44
- data: params
45
- });
43
+ return this.lava.request(
44
+ "POST",
45
+ "checkout_sessions",
46
+ {
47
+ data: params
48
+ }
49
+ );
50
+ }
51
+ /**
52
+ * List checkout sessions
53
+ * @param params List parameters
54
+ * @returns Paginated list of checkout sessions
55
+ */
56
+ async list(params) {
57
+ const queryParams = {};
58
+ if (params) {
59
+ if (params.cursor) queryParams.cursor = params.cursor;
60
+ if (params.limit) queryParams.limit = params.limit.toString();
61
+ if (params.reference_id) queryParams.reference_id = params.reference_id;
62
+ }
63
+ return this.lava.request(
64
+ "GET",
65
+ "checkout_sessions",
66
+ {
67
+ query: queryParams
68
+ }
69
+ );
46
70
  }
47
71
  /**
48
72
  * Retrieve a checkout session
@@ -70,9 +94,13 @@ var Resources;
70
94
  if (params.limit) queryParams.limit = params.limit.toString();
71
95
  if (params.reference_id) queryParams.reference_id = params.reference_id;
72
96
  }
73
- return this.lava.request("GET", "connections", {
74
- query: queryParams
75
- });
97
+ return this.lava.request(
98
+ "GET",
99
+ "connections",
100
+ {
101
+ query: queryParams
102
+ }
103
+ );
76
104
  }
77
105
  /**
78
106
  * Retrieve a connection
package/dist/index.mjs CHANGED
@@ -13,9 +13,33 @@ var Resources;
13
13
  * @returns Created checkout session
14
14
  */
15
15
  async create(params) {
16
- return this.lava.request("POST", "checkout_sessions", {
17
- data: params
18
- });
16
+ return this.lava.request(
17
+ "POST",
18
+ "checkout_sessions",
19
+ {
20
+ data: params
21
+ }
22
+ );
23
+ }
24
+ /**
25
+ * List checkout sessions
26
+ * @param params List parameters
27
+ * @returns Paginated list of checkout sessions
28
+ */
29
+ async list(params) {
30
+ const queryParams = {};
31
+ if (params) {
32
+ if (params.cursor) queryParams.cursor = params.cursor;
33
+ if (params.limit) queryParams.limit = params.limit.toString();
34
+ if (params.reference_id) queryParams.reference_id = params.reference_id;
35
+ }
36
+ return this.lava.request(
37
+ "GET",
38
+ "checkout_sessions",
39
+ {
40
+ query: queryParams
41
+ }
42
+ );
19
43
  }
20
44
  /**
21
45
  * Retrieve a checkout session
@@ -43,9 +67,13 @@ var Resources;
43
67
  if (params.limit) queryParams.limit = params.limit.toString();
44
68
  if (params.reference_id) queryParams.reference_id = params.reference_id;
45
69
  }
46
- return this.lava.request("GET", "connections", {
47
- query: queryParams
48
- });
70
+ return this.lava.request(
71
+ "GET",
72
+ "connections",
73
+ {
74
+ query: queryParams
75
+ }
76
+ );
49
77
  }
50
78
  /**
51
79
  * Retrieve a connection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavapayments/nodejs",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "description": "Backend SDK for Lava Payments API - enabling usage-based billing for AI services",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",