@lavapayments/nodejs 6.1.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/README.md CHANGED
@@ -39,7 +39,7 @@ console.log(checkoutSession.checkout_session_token);
39
39
  // Generate a forward token
40
40
  const forwardToken = lava.generateForwardToken({
41
41
  connection_secret: 'connection_secret',
42
- product_secret: 'product_secret',
42
+ meter_secret: 'meter_secret',
43
43
  });
44
44
 
45
45
  // Use the token to make an API request through Lava
@@ -65,11 +65,11 @@ const data = await response.json();
65
65
  console.log(data);
66
66
  ```
67
67
 
68
- ### Check a connection's balance
68
+ ### Check a connection's credit status
69
69
 
70
70
  ```typescript
71
71
  const connection = await lava.connections.retrieve('connection_id');
72
- console.log('Current balance:', connection.wallet.balance);
72
+ console.log('Has credit balance:', connection.has_lava_credit_balance);
73
73
  ```
74
74
 
75
75
  ### Get connection requests
package/dist/index.d.mts CHANGED
@@ -1,32 +1,25 @@
1
1
  interface CreateCheckoutSessionParams {
2
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
6
  credit_bundle_id?: string;
8
7
  }
9
- interface CheckoutSessionsListParams {
10
- cursor?: string;
11
- limit?: number;
12
- reference_id?: string;
13
- }
14
8
  interface ConnectionsListParams {
15
9
  cursor?: string;
16
10
  limit?: number;
17
- reference_id?: string;
18
11
  }
19
12
  interface RequestsListParams {
20
13
  cursor?: string;
21
14
  limit?: number;
22
15
  connection_id?: string;
23
- product_id?: string;
16
+ meter_id?: string;
24
17
  metadata_filters?: Record<string, string>;
25
18
  }
26
19
  interface CreateRequestParams {
27
20
  request_id: string;
28
21
  connection_secret: string;
29
- product_secret: string;
22
+ meter_secret: string;
30
23
  metadata?: Record<string, string>;
31
24
  input_tokens?: number;
32
25
  output_tokens?: number;
@@ -44,7 +37,7 @@ interface UsageParams {
44
37
  start: string;
45
38
  end?: string;
46
39
  connection_id?: string;
47
- product_id?: string;
40
+ meter_id?: string;
48
41
  metadata_filters?: Record<string, string>;
49
42
  }
50
43
  interface ListResponse<T> {
@@ -52,79 +45,67 @@ interface ListResponse<T> {
52
45
  has_more: boolean;
53
46
  next_cursor?: string;
54
47
  }
55
- interface CreateSubscriptionConfigParams {
56
- name: string;
57
- period_amount: string;
58
- rollover_type: 'full' | 'none';
59
- }
60
- interface UpdateSubscriptionConfigParams {
61
- name?: string;
62
- period_amount?: string;
63
- rollover_type?: 'full' | 'none';
64
- }
65
48
  type RestCheckoutSession = {
66
49
  checkout_session_id: string;
67
50
  checkout_session_token: string;
68
51
  checkout_mode: 'onboarding' | 'topup' | 'subscription' | 'credit_bundle';
69
52
  origin_url: string;
70
53
  connection_id?: string;
71
- reference_id?: string;
72
54
  subscription_config_id?: string;
73
55
  created_at: string;
74
56
  completed_at?: string;
75
57
  };
76
- type RestConnection = {
77
- connection_id: string;
78
- connection_secret: string;
79
- reference_id?: string;
80
- wallet: {
81
- balance: string;
82
- phone: string;
83
- email: string;
84
- first_name: string;
85
- last_name: string;
86
- autopay_enabled: boolean;
87
- };
88
- next_usage_reset: string;
89
- previous_usage_reset: string;
90
- created_at: string;
91
- };
92
- type RestConnectionSubscriptionCredits = {
93
- total_remaining: string;
94
- cycle_remaining: string;
95
- bundle_remaining: string;
96
- cycle_rollover: 'full' | 'none';
97
- bundle_rollover: 'full' | 'none';
98
- };
99
- type RestConnectionSubscriptionPendingChange = {
100
- type: 'cancellation' | 'downgrade';
101
- effective_at: string | null;
102
- subscription_config_id?: string;
103
- name?: string;
104
- period_amount?: string;
105
- included_credit?: string;
58
+ type RestConnectionCustomer = {
59
+ phone: string;
60
+ email: string;
61
+ first_name: string;
62
+ last_name: string;
106
63
  };
107
- type RestConnectionSubscriptionDetails = {
108
- active_subscription_id: string;
64
+ /**
65
+ * Simple subscription summary included in connection responses.
66
+ * For full subscription details, use getSubscription().
67
+ */
68
+ type RestConnectionSubscription = {
69
+ subscription_id: string;
109
70
  subscription_config_id: string;
110
71
  name: string;
111
72
  status: 'active' | 'cancelled';
112
- billing_interval: 'month' | 'year';
113
- period_amount: string;
114
- included_credit: string;
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;
115
84
  cycle_start_at: string | null;
116
85
  cycle_end_at: string | null;
117
- credits: RestConnectionSubscriptionCredits;
118
- pending_change: RestConnectionSubscriptionPendingChange | null;
86
+ plan: RestSubscriptionPlan;
87
+ credits: RestSubscriptionCredits;
88
+ pending_change: RestPendingChange | null;
119
89
  };
120
- type RestConnectionSubscription = {
121
- subscription: RestConnectionSubscriptionDetails | null;
90
+ /**
91
+ * Response shape for getSubscription() method.
92
+ */
93
+ type RestConnectionSubscriptionResponse = {
94
+ subscription: RestSubscriptionBase | null;
95
+ };
96
+ type RestConnection = {
97
+ connection_id: string;
98
+ connection_secret: string;
99
+ has_lava_credit_balance: boolean;
100
+ customer: RestConnectionCustomer;
101
+ subscription: RestConnectionSubscription | null;
102
+ created_at: string;
122
103
  };
123
104
  type RestRequest = {
124
105
  request_id: string;
125
106
  status: 'pending' | 'completed' | 'error';
126
107
  connection_id?: string;
127
- product_id?: string;
108
+ meter_id?: string;
128
109
  provider: string;
129
110
  provider_key_type: 'managed' | 'unmanaged';
130
111
  model?: string;
@@ -201,35 +182,91 @@ type RestUsage = {
201
182
  total_net_volume: string;
202
183
  };
203
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
+ };
204
195
  type RestSubscriptionConfig = {
205
196
  subscription_config_id: string;
206
197
  merchant_id: string;
207
198
  name: string;
208
199
  period_amount: string;
200
+ included_credit: string;
201
+ billing_interval: 'day' | 'week' | 'month' | 'year';
209
202
  rollover_type: 'full' | 'none';
210
203
  bundle_rollover_type: 'full' | 'none';
204
+ linked_meters: RestSubscriptionConfigLinkedMeter[];
205
+ credit_bundles: RestSubscriptionConfigCreditBundle[];
211
206
  created_at: string;
212
207
  };
213
- type RestActiveSubscription = {
214
- active_subscription_id: string;
215
- 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;
216
265
  subscription_config_id: string;
217
- started_at: string;
218
- billing_anchor: number;
219
- cancelled_at?: string;
220
- scheduled_cancellation_at: string | null;
221
- status: 'active' | 'cancelled';
266
+ name: string;
267
+ cost: string;
268
+ credit_amount: string;
222
269
  created_at: string;
223
- subscription_config: RestSubscriptionConfig;
224
- wallet: {
225
- wallet_id: string;
226
- phone: string;
227
- email?: string;
228
- first_name?: string;
229
- last_name?: string;
230
- active_balance: string;
231
- created_at: string;
232
- };
233
270
  };
234
271
 
235
272
  /** biome-ignore-all lint/style/noNamespace: package uses namespace */
@@ -249,18 +286,6 @@ declare namespace Resources {
249
286
  * @returns Created checkout session
250
287
  */
251
288
  create(params: CreateCheckoutSessionParams): Promise<RestCheckoutSession>;
252
- /**
253
- * List checkout sessions
254
- * @param params List parameters
255
- * @returns Paginated list of checkout sessions
256
- */
257
- list(params?: CheckoutSessionsListParams): Promise<ListResponse<RestCheckoutSession>>;
258
- /**
259
- * Retrieve a checkout session
260
- * @param checkoutSessionId Checkout session ID
261
- * @returns Checkout session details
262
- */
263
- retrieve(checkoutSessionId: string): Promise<RestCheckoutSession>;
264
289
  }
265
290
  /**
266
291
  * Connection related endpoints
@@ -284,7 +309,7 @@ declare namespace Resources {
284
309
  * @param connectionId Connection ID
285
310
  * @returns Subscription details or null if no active subscription
286
311
  */
287
- getSubscription(connectionId: string): Promise<RestConnectionSubscription>;
312
+ getSubscription(connectionId: string): Promise<RestConnectionSubscriptionResponse>;
288
313
  /**
289
314
  * Delete a connection
290
315
  * @param connectionId Connection ID
@@ -328,44 +353,80 @@ declare namespace Resources {
328
353
  */
329
354
  retrieve(params: UsageParams): Promise<RestUsage>;
330
355
  }
331
- export class SubscriptionsResource extends BaseResource {
356
+ /**
357
+ * Meter related endpoints
358
+ */
359
+ export class MetersResource extends BaseResource {
332
360
  /**
333
- * List subscription configurations
334
- * @returns List of subscription configurations
361
+ * List meters
362
+ * @param params Optional pagination parameters
363
+ * @returns Paginated list of meters
335
364
  */
336
- listConfigs(): Promise<RestSubscriptionConfig[]>;
365
+ list(params?: {
366
+ cursor?: string;
367
+ limit?: number;
368
+ }): Promise<ListResponse<RestMeter>>;
337
369
  /**
338
- * Create a subscription configuration
339
- * @param params Subscription configuration parameters
340
- * @returns Created subscription configuration
370
+ * Retrieve a meter
371
+ * @param id Meter ID
372
+ * @returns Meter details
341
373
  */
342
- 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 {
343
380
  /**
344
- * Update a subscription configuration
345
- * @param id Subscription configuration ID
346
- * @param params Update parameters
347
- * @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
348
394
  */
349
- updateConfig(id: string, params: UpdateSubscriptionConfigParams): Promise<RestSubscriptionConfig>;
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
402
+ */
403
+ listConfigs(params?: {
404
+ cursor?: string;
405
+ limit?: number;
406
+ }): Promise<ListResponse<RestSubscriptionConfig>>;
350
407
  /**
351
- * Delete a subscription configuration
408
+ * Retrieve a subscription configuration
352
409
  * @param id Subscription configuration ID
353
- * @returns Success response
410
+ * @returns Subscription configuration details
354
411
  */
355
- deleteConfig(id: string): Promise<{
356
- success: boolean;
357
- }>;
412
+ retrieveConfig(id: string): Promise<RestSubscriptionConfig>;
358
413
  /**
359
- * List active subscriptions for a merchant
360
- * @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
361
417
  */
362
- 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>>;
363
424
  /**
364
- * Cancel an active subscription
365
- * @param id Active subscription ID
425
+ * Cancel a subscription
426
+ * @param id Subscription ID
366
427
  * @returns Success response
367
428
  */
368
- cancelActiveSubscription(id: string): Promise<{
429
+ cancel(id: string): Promise<{
369
430
  success: boolean;
370
431
  }>;
371
432
  }
@@ -383,11 +444,11 @@ interface Config {
383
444
  }
384
445
  type ForwardTokenOptions = {
385
446
  connection_secret: string;
386
- product_secret: string;
447
+ meter_secret: string;
387
448
  provider_key?: string;
388
449
  } | {
389
450
  connection_secret: null;
390
- product_secret: null;
451
+ meter_secret: null;
391
452
  provider_key: string;
392
453
  };
393
454
  declare class Lava {
@@ -414,6 +475,14 @@ declare class Lava {
414
475
  * The subscriptions resource
415
476
  */
416
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;
417
486
  /**
418
487
  * Provider URLs for convenience
419
488
  */
@@ -471,4 +540,4 @@ declare class Lava {
471
540
  generateForwardToken(options: ForwardTokenOptions): string;
472
541
  }
473
542
 
474
- 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 RestConnectionSubscription, type RestConnectionSubscriptionCredits, type RestConnectionSubscriptionDetails, type RestConnectionSubscriptionPendingChange, 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 };