@lavapayments/nodejs 6.0.0 → 7.0.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.ts CHANGED
@@ -1,31 +1,25 @@
1
1
  interface CreateCheckoutSessionParams {
2
- checkout_mode: 'onboarding' | 'topup' | 'subscription';
2
+ checkout_mode: 'onboarding' | 'topup' | 'subscription' | 'credit_bundle';
3
3
  origin_url: string;
4
- reference_id?: string;
5
4
  connection_id?: string;
6
5
  subscription_config_id?: string;
7
- }
8
- interface CheckoutSessionsListParams {
9
- cursor?: string;
10
- limit?: number;
11
- reference_id?: string;
6
+ credit_bundle_id?: string;
12
7
  }
13
8
  interface ConnectionsListParams {
14
9
  cursor?: string;
15
10
  limit?: number;
16
- reference_id?: string;
17
11
  }
18
12
  interface RequestsListParams {
19
13
  cursor?: string;
20
14
  limit?: number;
21
15
  connection_id?: string;
22
- product_id?: string;
16
+ meter_id?: string;
23
17
  metadata_filters?: Record<string, string>;
24
18
  }
25
19
  interface CreateRequestParams {
26
20
  request_id: string;
27
21
  connection_secret: string;
28
- product_secret: string;
22
+ meter_secret: string;
29
23
  metadata?: Record<string, string>;
30
24
  input_tokens?: number;
31
25
  output_tokens?: number;
@@ -43,7 +37,7 @@ interface UsageParams {
43
37
  start: string;
44
38
  end?: string;
45
39
  connection_id?: string;
46
- product_id?: string;
40
+ meter_id?: string;
47
41
  metadata_filters?: Record<string, string>;
48
42
  }
49
43
  interface ListResponse<T> {
@@ -51,48 +45,67 @@ interface ListResponse<T> {
51
45
  has_more: boolean;
52
46
  next_cursor?: string;
53
47
  }
54
- interface CreateSubscriptionConfigParams {
55
- name: string;
56
- period_amount: string;
57
- rollover_type: 'full' | 'none';
58
- }
59
- interface UpdateSubscriptionConfigParams {
60
- name?: string;
61
- period_amount?: string;
62
- rollover_type?: 'full' | 'none';
63
- }
64
48
  type RestCheckoutSession = {
65
49
  checkout_session_id: string;
66
50
  checkout_session_token: string;
67
- checkout_mode: 'onboarding' | 'topup' | 'subscription';
51
+ checkout_mode: 'onboarding' | 'topup' | 'subscription' | 'credit_bundle';
68
52
  origin_url: string;
69
53
  connection_id?: string;
70
- reference_id?: string;
71
54
  subscription_config_id?: string;
72
55
  created_at: string;
73
56
  completed_at?: string;
74
57
  };
58
+ type RestConnectionCustomer = {
59
+ phone: string;
60
+ email: string;
61
+ first_name: string;
62
+ last_name: string;
63
+ };
64
+ /**
65
+ * Simple subscription summary included in connection responses.
66
+ * For full subscription details, use getSubscription().
67
+ */
68
+ type RestConnectionSubscription = {
69
+ subscription_id: string;
70
+ subscription_config_id: string;
71
+ name: string;
72
+ status: 'active' | 'cancelled';
73
+ };
74
+ /**
75
+ * Base subscription shape shared between endpoints.
76
+ * Used directly by GET /v1/connections/:id/subscription
77
+ */
78
+ type RestSubscriptionBase = {
79
+ subscription_id: string;
80
+ subscription_config_id: string;
81
+ status: 'active' | 'cancelled';
82
+ started_at: string;
83
+ cancelled_at: string | null;
84
+ cycle_start_at: string | null;
85
+ cycle_end_at: string | null;
86
+ plan: RestSubscriptionPlan;
87
+ credits: RestSubscriptionCredits;
88
+ pending_change: RestPendingChange | null;
89
+ };
90
+ /**
91
+ * Response shape for getSubscription() method.
92
+ */
93
+ type RestConnectionSubscriptionResponse = {
94
+ subscription: RestSubscriptionBase | null;
95
+ };
75
96
  type RestConnection = {
76
97
  connection_id: string;
77
98
  connection_secret: string;
78
- reference_id?: string;
79
- wallet: {
80
- balance: string;
81
- phone: string;
82
- email: string;
83
- first_name: string;
84
- last_name: string;
85
- autopay_enabled: boolean;
86
- };
87
- next_usage_reset: string;
88
- previous_usage_reset: string;
99
+ has_lava_credit_balance: boolean;
100
+ customer: RestConnectionCustomer;
101
+ subscription: RestConnectionSubscription | null;
89
102
  created_at: string;
90
103
  };
91
104
  type RestRequest = {
92
105
  request_id: string;
93
106
  status: 'pending' | 'completed' | 'error';
94
107
  connection_id?: string;
95
- product_id?: string;
108
+ meter_id?: string;
96
109
  provider: string;
97
110
  provider_key_type: 'managed' | 'unmanaged';
98
111
  model?: string;
@@ -153,6 +166,8 @@ type RestUsage = {
153
166
  total_request_cost: string;
154
167
  total_wallet_cost: string;
155
168
  total_merchant_cost: string;
169
+ total_gross_volume: string;
170
+ total_net_volume: string;
156
171
  }[];
157
172
  totals: {
158
173
  total_requests: number;
@@ -163,35 +178,95 @@ type RestUsage = {
163
178
  total_request_cost: string;
164
179
  total_wallet_cost: string;
165
180
  total_merchant_cost: string;
181
+ total_gross_volume: string;
182
+ total_net_volume: string;
166
183
  };
167
184
  };
185
+ type RestSubscriptionConfigLinkedMeter = {
186
+ meter_id: string;
187
+ name: string;
188
+ };
189
+ type RestSubscriptionConfigCreditBundle = {
190
+ credit_bundle_id: string;
191
+ name: string;
192
+ cost: string;
193
+ credit_amount: string;
194
+ };
168
195
  type RestSubscriptionConfig = {
169
196
  subscription_config_id: string;
170
197
  merchant_id: string;
171
198
  name: string;
172
199
  period_amount: string;
200
+ included_credit: string;
201
+ billing_interval: 'day' | 'week' | 'month' | 'year';
173
202
  rollover_type: 'full' | 'none';
203
+ bundle_rollover_type: 'full' | 'none';
204
+ linked_meters: RestSubscriptionConfigLinkedMeter[];
205
+ credit_bundles: RestSubscriptionConfigCreditBundle[];
174
206
  created_at: string;
175
207
  };
176
- type RestActiveSubscription = {
177
- active_subscription_id: string;
178
- wallet_id: string;
208
+ type RestPendingChange = {
209
+ type: 'cancellation' | 'downgrade';
210
+ effective_at: string | null;
211
+ subscription_config_id?: string;
212
+ name?: string;
213
+ period_amount?: string;
214
+ included_credit?: string;
215
+ };
216
+ type RestSubscriptionPlan = {
217
+ name: string;
218
+ period_amount: string;
219
+ included_credit: string;
220
+ billing_interval: 'day' | 'week' | 'month' | 'year';
221
+ rollover_type: 'full' | 'none';
222
+ bundle_rollover_type: 'full' | 'none';
223
+ };
224
+ type RestSubscriptionCredits = {
225
+ total_remaining: string;
226
+ cycle_remaining: string;
227
+ bundle_remaining: string;
228
+ };
229
+ type RestSubscriptionCustomer = {
230
+ phone: string;
231
+ email?: string;
232
+ first_name?: string;
233
+ last_name?: string;
234
+ };
235
+ /**
236
+ * Extended subscription shape for list endpoint.
237
+ * Adds connection_id and customer since endpoint spans connections.
238
+ */
239
+ type RestSubscription = RestSubscriptionBase & {
240
+ connection_id: string;
241
+ customer: RestSubscriptionCustomer;
242
+ };
243
+ /** @deprecated Use RestSubscription instead */
244
+ type RestActiveSubscription = RestSubscription;
245
+ /** @deprecated Use RestSubscriptionPlan instead */
246
+ type RestSubscriptionPlanDetails = RestSubscriptionPlan;
247
+ type RestMeterTier = {
248
+ start: number;
249
+ rate: string;
250
+ type: 'tokens_1m' | 'characters_1m' | 'minutes' | 'requests';
251
+ };
252
+ type RestMeter = {
253
+ meter_id: string;
254
+ meter_secret: string;
255
+ name: string;
256
+ rate_type: 'fixed' | 'percentage';
257
+ token_basis: 'input+output' | 'output';
258
+ base_cost_payer: 'merchant' | 'wallet';
259
+ service_charge_payer: 'merchant' | 'wallet';
260
+ tiers: RestMeterTier[];
261
+ created_at: string;
262
+ };
263
+ type RestCreditBundle = {
264
+ credit_bundle_id: string;
179
265
  subscription_config_id: string;
180
- started_at: string;
181
- billing_anchor: number;
182
- cancelled_at?: string;
183
- status: 'active' | 'cancelled';
266
+ name: string;
267
+ cost: string;
268
+ credit_amount: string;
184
269
  created_at: string;
185
- subscription_config: RestSubscriptionConfig;
186
- wallet: {
187
- wallet_id: string;
188
- phone: string;
189
- email?: string;
190
- first_name?: string;
191
- last_name?: string;
192
- active_balance: string;
193
- created_at: string;
194
- };
195
270
  };
196
271
 
197
272
  /** biome-ignore-all lint/style/noNamespace: package uses namespace */
@@ -211,18 +286,6 @@ declare namespace Resources {
211
286
  * @returns Created checkout session
212
287
  */
213
288
  create(params: CreateCheckoutSessionParams): Promise<RestCheckoutSession>;
214
- /**
215
- * List checkout sessions
216
- * @param params List parameters
217
- * @returns Paginated list of checkout sessions
218
- */
219
- list(params?: CheckoutSessionsListParams): Promise<ListResponse<RestCheckoutSession>>;
220
- /**
221
- * Retrieve a checkout session
222
- * @param checkoutSessionId Checkout session ID
223
- * @returns Checkout session details
224
- */
225
- retrieve(checkoutSessionId: string): Promise<RestCheckoutSession>;
226
289
  }
227
290
  /**
228
291
  * Connection related endpoints
@@ -240,6 +303,13 @@ declare namespace Resources {
240
303
  * @returns Connection details
241
304
  */
242
305
  retrieve(connectionId: string): Promise<RestConnection>;
306
+ /**
307
+ * Get subscription details for a connection.
308
+ * Returns plan info, current cycle credits, and any pending changes (cancellation or downgrade).
309
+ * @param connectionId Connection ID
310
+ * @returns Subscription details or null if no active subscription
311
+ */
312
+ getSubscription(connectionId: string): Promise<RestConnectionSubscriptionResponse>;
243
313
  /**
244
314
  * Delete a connection
245
315
  * @param connectionId Connection ID
@@ -283,44 +353,80 @@ declare namespace Resources {
283
353
  */
284
354
  retrieve(params: UsageParams): Promise<RestUsage>;
285
355
  }
286
- export class SubscriptionsResource extends BaseResource {
356
+ /**
357
+ * Meter related endpoints
358
+ */
359
+ export class MetersResource extends BaseResource {
287
360
  /**
288
- * List subscription configurations
289
- * @returns List of subscription configurations
361
+ * List meters
362
+ * @param params Optional pagination parameters
363
+ * @returns Paginated list of meters
290
364
  */
291
- listConfigs(): Promise<RestSubscriptionConfig[]>;
365
+ list(params?: {
366
+ cursor?: string;
367
+ limit?: number;
368
+ }): Promise<ListResponse<RestMeter>>;
292
369
  /**
293
- * Create a subscription configuration
294
- * @param params Subscription configuration parameters
295
- * @returns Created subscription configuration
370
+ * Retrieve a meter
371
+ * @param id Meter ID
372
+ * @returns Meter details
296
373
  */
297
- createConfig(params: CreateSubscriptionConfigParams): Promise<RestSubscriptionConfig>;
374
+ retrieve(id: string): Promise<RestMeter>;
375
+ }
376
+ /**
377
+ * Credit bundle related endpoints
378
+ */
379
+ export class CreditBundlesResource extends BaseResource {
298
380
  /**
299
- * Update a subscription configuration
300
- * @param id Subscription configuration ID
301
- * @param params Update parameters
302
- * @returns Updated subscription configuration
381
+ * List credit bundles
382
+ * @param params Optional filter and pagination parameters
383
+ * @returns Paginated list of credit bundles
384
+ */
385
+ list(params?: {
386
+ subscription_config_id?: string;
387
+ cursor?: string;
388
+ limit?: number;
389
+ }): Promise<ListResponse<RestCreditBundle>>;
390
+ /**
391
+ * Retrieve a credit bundle
392
+ * @param id Credit bundle ID
393
+ * @returns Credit bundle details
394
+ */
395
+ retrieve(id: string): Promise<RestCreditBundle>;
396
+ }
397
+ export class SubscriptionsResource extends BaseResource {
398
+ /**
399
+ * List subscription configurations
400
+ * @param params Optional pagination parameters
401
+ * @returns Paginated list of subscription configurations
303
402
  */
304
- updateConfig(id: string, params: UpdateSubscriptionConfigParams): Promise<RestSubscriptionConfig>;
403
+ listConfigs(params?: {
404
+ cursor?: string;
405
+ limit?: number;
406
+ }): Promise<ListResponse<RestSubscriptionConfig>>;
305
407
  /**
306
- * Delete a subscription configuration
408
+ * Retrieve a subscription configuration
307
409
  * @param id Subscription configuration ID
308
- * @returns Success response
410
+ * @returns Subscription configuration details
309
411
  */
310
- deleteConfig(id: string): Promise<{
311
- success: boolean;
312
- }>;
412
+ retrieveConfig(id: string): Promise<RestSubscriptionConfig>;
313
413
  /**
314
- * List active subscriptions for a merchant
315
- * @returns List of active subscriptions
414
+ * List subscriptions for a merchant
415
+ * @param params Optional filter and pagination parameters
416
+ * @returns Paginated list of subscriptions
316
417
  */
317
- listActiveSubscriptions(): Promise<RestActiveSubscription[]>;
418
+ list(params?: {
419
+ status?: 'active' | 'cancelled' | 'all';
420
+ connection_id?: string;
421
+ cursor?: string;
422
+ limit?: number;
423
+ }): Promise<ListResponse<RestSubscription>>;
318
424
  /**
319
- * Cancel an active subscription
320
- * @param id Active subscription ID
425
+ * Cancel a subscription
426
+ * @param id Subscription ID
321
427
  * @returns Success response
322
428
  */
323
- cancelActiveSubscription(id: string): Promise<{
429
+ cancel(id: string): Promise<{
324
430
  success: boolean;
325
431
  }>;
326
432
  }
@@ -338,11 +444,11 @@ interface Config {
338
444
  }
339
445
  type ForwardTokenOptions = {
340
446
  connection_secret: string;
341
- product_secret: string;
447
+ meter_secret: string;
342
448
  provider_key?: string;
343
449
  } | {
344
450
  connection_secret: null;
345
- product_secret: null;
451
+ meter_secret: null;
346
452
  provider_key: string;
347
453
  };
348
454
  declare class Lava {
@@ -369,6 +475,14 @@ declare class Lava {
369
475
  * The subscriptions resource
370
476
  */
371
477
  readonly subscriptions: Resources.SubscriptionsResource;
478
+ /**
479
+ * The meters resource
480
+ */
481
+ readonly meters: Resources.MetersResource;
482
+ /**
483
+ * The credit bundles resource
484
+ */
485
+ readonly creditBundles: Resources.CreditBundlesResource;
372
486
  /**
373
487
  * Provider URLs for convenience
374
488
  */
@@ -399,6 +513,7 @@ declare class Lava {
399
513
  gmicloud: string;
400
514
  chutes: string;
401
515
  baseten: string;
516
+ moonshot: string;
402
517
  };
403
518
  /**
404
519
  * Create a new Lava client
@@ -425,4 +540,4 @@ declare class Lava {
425
540
  generateForwardToken(options: ForwardTokenOptions): string;
426
541
  }
427
542
 
428
- export { type ApiVersion, type CheckoutSessionsListParams, type Config, type ConnectionsListParams, type CreateCheckoutSessionParams, type CreateRequestParams, type CreateSubscriptionConfigParams, type ForwardTokenOptions, Lava, type ListResponse, type RequestsListParams, type RequestsListResponse, Resources, type RestActiveSubscription, type RestCheckoutSession, type RestConnection, type RestRequest, type RestSubscriptionConfig, type RestUsage, type UpdateSubscriptionConfigParams, type UsageParams };
543
+ export { type ApiVersion, type Config, type ConnectionsListParams, type CreateCheckoutSessionParams, type CreateRequestParams, type ForwardTokenOptions, Lava, type ListResponse, type RequestsListParams, type RequestsListResponse, Resources, type RestActiveSubscription, type RestCheckoutSession, type RestConnection, type RestConnectionCustomer, type RestConnectionSubscription, type RestConnectionSubscriptionResponse, type RestCreditBundle, type RestMeter, type RestMeterTier, type RestPendingChange, type RestRequest, type RestSubscription, type RestSubscriptionBase, type RestSubscriptionConfig, type RestSubscriptionConfigCreditBundle, type RestSubscriptionConfigLinkedMeter, type RestSubscriptionCredits, type RestSubscriptionCustomer, type RestSubscriptionPlan, type RestSubscriptionPlanDetails, type RestUsage, type UsageParams };