alchemy 0.36.0 → 0.37.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.
@@ -32,6 +32,12 @@ export interface PriceRecurring {
32
32
  * `last_ever` for picking the last usage record ever (across period bounds) or `max` which picks the usage record with the maximum reported usage during a period.
33
33
  */
34
34
  aggregateUsage?: Stripe.PriceCreateParams.Recurring.AggregateUsage;
35
+
36
+ /**
37
+ * The ID of the billing meter this price is associated with.
38
+ * Only applicable when usageType = 'metered'.
39
+ */
40
+ meter?: string;
35
41
  }
36
42
 
37
43
  type TaxBehavior = Stripe.PriceCreateParams.TaxBehavior;
@@ -320,6 +326,25 @@ export interface Price extends Resource<"stripe::Price">, PriceProps {
320
326
  * }
321
327
  * ]
322
328
  * });
329
+ *
330
+ * @example
331
+ * // Create a metered price with billing meter for API usage tracking
332
+ * const meteredPrice = await Price("api-usage-price", {
333
+ * product: "prod_xyz",
334
+ * currency: "usd",
335
+ * billingScheme: "tiered",
336
+ * tiersMode: "graduated",
337
+ * recurring: {
338
+ * interval: "month",
339
+ * usageType: "metered",
340
+ * meter: "meter_123abc" // Associate with billing meter
341
+ * },
342
+ * tiers: [
343
+ * { upTo: 10000, unitAmountDecimal: "0" },
344
+ * { upTo: 25000, unitAmountDecimal: "0.002" },
345
+ * { upTo: "inf", flatAmountDecimal: "3000" }
346
+ * ]
347
+ * });
323
348
  */
324
349
  export const Price = Resource(
325
350
  "stripe::Price",
@@ -370,6 +395,9 @@ export const Price = Resource(
370
395
  expand: ["tiers"],
371
396
  };
372
397
 
398
+ // Note: Stripe doesn't allow updating recurring fields (including meter) after price creation
399
+ // If meter needs to be changed, a new price must be created
400
+
373
401
  price = await stripe.prices.update(this.output.id, updateParams);
374
402
  } else {
375
403
  // Create new price
@@ -401,6 +429,21 @@ export const Price = Resource(
401
429
  usage_type: props.recurring.usageType,
402
430
  aggregate_usage: props.recurring.aggregateUsage,
403
431
  };
432
+
433
+ // Add meter to recurring if present (only for metered usage type)
434
+ if (props.recurring.meter) {
435
+ if (props.recurring.usageType !== "metered") {
436
+ throw new Error(
437
+ "Meter can only be set for prices with recurring.usageType = 'metered'",
438
+ );
439
+ }
440
+ // Extend the recurring params with meter
441
+ (
442
+ createParams.recurring as Stripe.PriceCreateParams.Recurring & {
443
+ meter: string;
444
+ }
445
+ ).meter = props.recurring.meter;
446
+ }
404
447
  }
405
448
 
406
449
  // Add tier configuration if present
@@ -452,7 +495,7 @@ export const Price = Resource(
452
495
  // Need to retrieve with expanded tiers
453
496
  price = await stripe.prices.retrieve(existingPrices.data[0].id, {
454
497
  expand: ["tiers"],
455
- } as any);
498
+ });
456
499
  }
457
500
  } else {
458
501
  price = await stripe.prices.create(createParams);
@@ -472,6 +515,9 @@ export const Price = Resource(
472
515
  .usage_type as Stripe.PriceCreateParams.Recurring.UsageType,
473
516
  aggregateUsage: price.recurring
474
517
  .aggregate_usage as Stripe.PriceCreateParams.Recurring.AggregateUsage,
518
+ meter: (
519
+ price.recurring as Stripe.Price.Recurring & { meter?: string }
520
+ ).meter,
475
521
  }
476
522
  : undefined;
477
523