@lunora/payment 1.0.0-alpha.26 → 1.0.0-alpha.28

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
@@ -1,35 +1,35 @@
1
- import { a as ProviderId, C as Customer, b as PaymentSession, S as Subscription, U as UsageEvent, W as WebhookActionType, A as ApplyResult, P as PaymentAdapter, c as AttachInput, d as CheckoutResult, e as CancelSubscriptionOptions, f as CheckInput, g as CheckResult, h as CheckoutInput, F as FeatureBalance, T as TrackInput, i as TrackResult, j as CurrencyCode, M as Money, k as PaymentState, l as SubscriptionState, m as WebhookAction } from "./packem_shared/adapter.d-BOheUepr.mjs";
2
- export { type n as AdapterRegistry, type o as CaptureInput, type p as CustomerRef, type q as PortalInput, type r as ProviderCapabilities, type R as RefundAmountKind, type s as RefundInput, type t as ReportUsageInput, type u as SubscriptionPatch, type v as WebhookHeaders, type w as WebhookInput, x as createAdapterRegistry } from "./packem_shared/adapter.d-BOheUepr.mjs";
1
+ import { a as ProviderId, C as Customer, b as PaymentSession, S as Subscription, U as UsageEvent, W as WebhookActionType, A as ApplyResult, P as PaymentAdapter, c as AttachInput, d as CheckoutResult, e as CancelSubscriptionOptions, f as CheckInput, g as CheckResult, h as CheckoutInput, F as FeatureBalance, T as TrackInput, i as TrackResult, j as CurrencyCode, M as Money, k as PaymentState, l as SubscriptionState, m as WebhookAction } from "./packem_shared/adapter.d-CMjjkTGB.mjs";
2
+ export { type n as AdapterRegistry, type o as CaptureInput, type p as CustomerRef, type q as PortalInput, type r as ProviderCapabilities, type R as RefundAmountKind, type s as RefundInput, type t as ReportUsageInput, type u as SubscriptionPatch, type v as WebhookHeaders, type w as WebhookInput, x as createAdapterRegistry } from "./packem_shared/adapter.d-CMjjkTGB.mjs";
3
3
  import { LunoraError } from '@lunora/errors';
4
4
  import { TableDefinition } from '@lunora/server';
5
5
  /**
6
- * `PaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
7
- * @experimental
8
- */
6
+ * `PaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
7
+ * @experimental
8
+ */
9
9
  interface PaymentStore {
10
10
  getCustomerByReference: (provider: ProviderId, referenceId: string) => Promise<Customer | undefined>;
11
11
  getPaymentSession: (provider: ProviderId, id: string) => Promise<PaymentSession | undefined>;
12
12
  getSubscription: (provider: ProviderId, id: string) => Promise<Subscription | undefined>;
13
13
  listSubscriptionsByReference: (referenceId: string) => Promise<Subscription[]>;
14
14
  /**
15
- * Claims a provider event id for processing. Resolves `true` the first time an event is seen
16
- * and `false` for a duplicate — the inbound-idempotency primitive.
17
- */
15
+ * Claims a provider event id for processing. Resolves `true` the first time an event is seen
16
+ * and `false` for a duplicate — the inbound-idempotency primitive.
17
+ */
18
18
  markEventProcessed: (provider: ProviderId, eventId: string) => Promise<boolean>;
19
19
  /** Flag a recorded usage event as forwarded to the provider's metering API. */
20
20
  markUsageReported: (provider: ProviderId, idempotencyKey: string) => Promise<void>;
21
21
  /**
22
- * Append a usage event. Resolves `true` when newly recorded and `false` when its
23
- * `idempotencyKey` was already seen — the exactly-once primitive behind `track`.
24
- */
22
+ * Append a usage event. Resolves `true` when newly recorded and `false` when its
23
+ * `idempotencyKey` was already seen — the exactly-once primitive behind `track`.
24
+ */
25
25
  recordUsage: (event: UsageEvent) => Promise<boolean>;
26
26
  /**
27
- * Release a previously-claimed event id (see {@link PaymentStore.markEventProcessed}) so a
28
- * provider retry can re-process it. Called only when applying the claimed event *throws* (a
29
- * genuine store-write failure): the atomic insert-claim guards concurrent duplicates, but a
30
- * claim that outlives a failed apply would dedupe the retry and lose the effect — so the claim
31
- * is rolled back on failure. A no-op if the id was never claimed.
32
- */
27
+ * Release a previously-claimed event id (see {@link PaymentStore.markEventProcessed}) so a
28
+ * provider retry can re-process it. Called only when applying the claimed event *throws* (a
29
+ * genuine store-write failure): the atomic insert-claim guards concurrent duplicates, but a
30
+ * claim that outlives a failed apply would dedupe the retry and lose the effect — so the claim
31
+ * is rolled back on failure. A no-op if the id was never claimed.
32
+ */
33
33
  releaseEvent: (provider: ProviderId, eventId: string) => Promise<void>;
34
34
  /** Sum recorded usage `quantity` for a `(referenceId, featureId)` pair since `since` (epoch ms). */
35
35
  sumUsage: (referenceId: string, featureId: string, since: number) => Promise<number>;
@@ -38,9 +38,9 @@ interface PaymentStore {
38
38
  upsertSubscription: (subscription: Subscription) => Promise<void>;
39
39
  }
40
40
  /**
41
- * In-memory {@link PaymentStore} for tests and local development. Not durable.
42
- * @experimental
43
- */
41
+ * In-memory {@link PaymentStore} for tests and local development. Not durable.
42
+ * @experimental
43
+ */
44
44
  declare class MemoryPaymentStore implements PaymentStore {
45
45
  private readonly customers;
46
46
  private readonly processedEvents;
@@ -61,9 +61,9 @@ declare class MemoryPaymentStore implements PaymentStore {
61
61
  upsertSubscription(subscription: Subscription): Promise<void>;
62
62
  }
63
63
  /**
64
- * `PlanDefinition` is part of the experimental `@lunora/payment` API and may change without a major version bump.
65
- * @experimental
66
- */
64
+ * `PlanDefinition` is part of the experimental `@lunora/payment` API and may change without a major version bump.
65
+ * @experimental
66
+ */
67
67
  interface PlanDefinition {
68
68
  /** Feature flags this plan grants. */
69
69
  readonly features?: ReadonlyArray<string>;
@@ -73,17 +73,17 @@ interface PlanDefinition {
73
73
  readonly priceIds: ReadonlyArray<string>;
74
74
  }
75
75
  /**
76
- * `EntitlementsConfig` is part of the experimental `@lunora/payment` API and may change without a major version bump.
77
- * @experimental
78
- */
76
+ * `EntitlementsConfig` is part of the experimental `@lunora/payment` API and may change without a major version bump.
77
+ * @experimental
78
+ */
79
79
  interface EntitlementsConfig {
80
80
  /** Plan name → definition. */
81
81
  readonly plans: Record<string, PlanDefinition>;
82
82
  }
83
83
  /**
84
- * `Entitlements` is part of the experimental `@lunora/payment` API and may change without a major version bump.
85
- * @experimental
86
- */
84
+ * `Entitlements` is part of the experimental `@lunora/payment` API and may change without a major version bump.
85
+ * @experimental
86
+ */
87
87
  interface Entitlements {
88
88
  readonly features: ReadonlySet<string>;
89
89
  /** True when an active subscription grants `feature`. */
@@ -94,36 +94,36 @@ interface Entitlements {
94
94
  readonly plans: ReadonlyArray<string>;
95
95
  }
96
96
  /**
97
- * Start of the window `check` sums metered usage over: the most recent billing-period start among
98
- * a reference's active subscriptions. `0` (count all-time) when no active subscription reports one
99
- * — limits still bind, they just never reset until the provider sends a period.
100
- * @experimental
101
- */
97
+ * Start of the window `check` sums metered usage over: the most recent billing-period start among
98
+ * a reference's active subscriptions. `0` (count all-time) when no active subscription reports one
99
+ * — limits still bind, they just never reset until the provider sends a period.
100
+ * @experimental
101
+ */
102
102
  declare const usagePeriodStart: (subscriptions: ReadonlyArray<Subscription>) => number;
103
103
  /**
104
- * Every feature name a config can grant — the union of `features` flags and `limits` keys across all plans, sorted.
105
- * @experimental
106
- */
104
+ * Every feature name a config can grant — the union of `features` flags and `limits` keys across all plans, sorted.
105
+ * @experimental
106
+ */
107
107
  declare const featureNames: (config: EntitlementsConfig) => string[];
108
108
  /**
109
- * Whether the reference holds an entitling (active/trialing) subscription on `priceId` — the basis of a product `check`.
110
- * @experimental
111
- */
109
+ * Whether the reference holds an entitling (active/trialing) subscription on `priceId` — the basis of a product `check`.
110
+ * @experimental
111
+ */
112
112
  declare const hasActivePrice: (subscriptions: ReadonlyArray<Subscription>, priceId: string) => boolean;
113
113
  /**
114
- * Derive {@link Entitlements} from a reference's subscriptions. Pure — the basis of `check`.
115
- * @experimental
116
- */
114
+ * Derive {@link Entitlements} from a reference's subscriptions. Pure — the basis of `check`.
115
+ * @experimental
116
+ */
117
117
  declare const resolveEntitlements: (config: EntitlementsConfig, subscriptions: ReadonlyArray<Subscription>) => Entitlements;
118
118
  /**
119
- * Convenience: resolve entitlements straight from the store for a reference.
120
- * @experimental
121
- */
119
+ * Convenience: resolve entitlements straight from the store for a reference.
120
+ * @experimental
121
+ */
122
122
  declare const entitlementsForReference: (store: PaymentStore, config: EntitlementsConfig, referenceId: string) => Promise<Entitlements>;
123
123
  /**
124
- * `PaymentEvent` is part of the experimental `@lunora/payment` API and may change without a major version bump.
125
- * @experimental
126
- */
124
+ * `PaymentEvent` is part of the experimental `@lunora/payment` API and may change without a major version bump.
125
+ * @experimental
126
+ */
127
127
  type PaymentEvent = {
128
128
  action: WebhookActionType;
129
129
  eventId: string;
@@ -169,25 +169,25 @@ type PaymentEvent = {
169
169
  type: "usage.report_failed";
170
170
  };
171
171
  /**
172
- * `PaymentObserver` is part of the experimental `@lunora/payment` API and may change without a major version bump.
173
- * @experimental
174
- */
172
+ * `PaymentObserver` is part of the experimental `@lunora/payment` API and may change without a major version bump.
173
+ * @experimental
174
+ */
175
175
  type PaymentObserver = (event: PaymentEvent) => void;
176
176
  /**
177
- * Returns whether the current caller may act on `referenceId`. Throwing is also treated as denial.
178
- * @experimental
179
- */
177
+ * Returns whether the current caller may act on `referenceId`. Throwing is also treated as denial.
178
+ * @experimental
179
+ */
180
180
  type AuthorizeReference = (referenceId: string) => boolean | Promise<boolean>;
181
181
  /**
182
- * `CreatePaymentOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
183
- * @experimental
184
- */
182
+ * `CreatePaymentOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
183
+ * @experimental
184
+ */
185
185
  interface CreatePaymentOptions {
186
186
  readonly adapter: PaymentAdapter;
187
187
  /**
188
- * Per-caller authorization for every mutation. Return `false` to reject with 403. Omit only
189
- * for trusted server-internal callers (e.g. the reconciliation sweep).
190
- */
188
+ * Per-caller authorization for every mutation. Return `false` to reject with 403. Omit only
189
+ * for trusted server-internal callers (e.g. the reconciliation sweep).
190
+ */
191
191
  readonly authorize?: AuthorizeReference;
192
192
  /** Plan → features/limits map. Required for `check`; omit if you don't gate features. */
193
193
  readonly entitlements?: EntitlementsConfig;
@@ -196,22 +196,22 @@ interface CreatePaymentOptions {
196
196
  readonly store: PaymentStore;
197
197
  }
198
198
  /**
199
- * `LunoraPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
200
- * @experimental
201
- */
199
+ * `LunoraPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
200
+ * @experimental
201
+ */
202
202
  interface LunoraPayment {
203
203
  readonly adapter: PaymentAdapter;
204
204
  /**
205
- * Subscribe a reference to a plan — a plan-oriented alias of {@link LunoraPayment.createCheckout}
206
- * with `mode` defaulting to `"subscription"`. Returns a hosted-checkout URL to redirect to.
207
- */
205
+ * Subscribe a reference to a plan — a plan-oriented alias of {@link LunoraPayment.createCheckout}
206
+ * with `mode` defaulting to `"subscription"`. Returns a hosted-checkout URL to redirect to.
207
+ */
208
208
  attach: (input: AttachInput) => Promise<CheckoutResult>;
209
209
  cancelSubscription: (subscriptionId: string, options?: CancelSubscriptionOptions) => Promise<Subscription>;
210
210
  /**
211
- * Is a reference allowed something right now? Pass `featureId` to check a grant/allowance (boolean
212
- * features check plan grants; metered features subtract usage tracked this period) or `priceId` to
213
- * check active access to a product. The feature path requires `entitlements` to be configured.
214
- */
211
+ * Is a reference allowed something right now? Pass `featureId` to check a grant/allowance (boolean
212
+ * features check plan grants; metered features subtract usage tracked this period) or `priceId` to
213
+ * check active access to a product. The feature path requires `entitlements` to be configured.
214
+ */
215
215
  check: (input: CheckInput) => Promise<CheckResult>;
216
216
  createCheckout: (input: CheckoutInput) => Promise<CheckoutResult>;
217
217
  /** Open the provider billing portal for the caller's own customer (derived from the store). */
@@ -225,28 +225,28 @@ interface LunoraPayment {
225
225
  listSubscriptions: (referenceId: string) => Promise<Subscription[]>;
226
226
  readonly store: PaymentStore;
227
227
  /**
228
- * Record metered usage for a reference's feature — durably (exactly-once by idempotency key) and,
229
- * when the provider supports it, forwarded to its metering API. Best-effort upstream: a reporting
230
- * failure is observed, never thrown, and the local ledger that `check` reads is always updated.
231
- */
228
+ * Record metered usage for a reference's feature — durably (exactly-once by idempotency key) and,
229
+ * when the provider supports it, forwarded to its metering API. Best-effort upstream: a reporting
230
+ * failure is observed, never thrown, and the local ledger that `check` reads is always updated.
231
+ */
232
232
  track: (input: TrackInput) => Promise<TrackResult>;
233
233
  }
234
234
  /**
235
- * `createPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
236
- * @experimental
237
- */
235
+ * `createPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
236
+ * @experimental
237
+ */
238
238
  declare const createPayment: (options: CreatePaymentOptions) => LunoraPayment;
239
239
  /**
240
- * A stored row, carrying Lunora's document id.
241
- * @experimental
242
- */
240
+ * A stored row, carrying Lunora's document id.
241
+ * @experimental
242
+ */
243
243
  interface PaymentRow extends Record<string, unknown> {
244
244
  readonly _id: string;
245
245
  }
246
246
  /**
247
- * Minimal write/read surface this store needs; `ctx.db` satisfies it structurally.
248
- * @experimental
249
- */
247
+ * Minimal write/read surface this store needs; `ctx.db` satisfies it structurally.
248
+ * @experimental
249
+ */
250
250
  interface PaymentDatabase {
251
251
  delete: (id: string) => Promise<void>;
252
252
  findFirst: (table: string, where: Record<string, unknown>) => Promise<PaymentRow | null>;
@@ -255,14 +255,14 @@ interface PaymentDatabase {
255
255
  patch: (id: string, patch: Record<string, unknown>) => Promise<void>;
256
256
  }
257
257
  /**
258
- * `createDatabasePaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
259
- * @experimental
260
- */
258
+ * `createDatabasePaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
259
+ * @experimental
260
+ */
261
261
  declare const createDatabasePaymentStore: (database: PaymentDatabase) => PaymentStore;
262
262
  /**
263
- * Structural subset of Lunora's `ctx.db` (the `findFirst`/`findMany(tableName, { where })` form).
264
- * @experimental
265
- */
263
+ * Structural subset of Lunora's `ctx.db` (the `findFirst`/`findMany(tableName, { where })` form).
264
+ * @experimental
265
+ */
266
266
  interface LunoraDatabaseLike {
267
267
  delete: (id: string) => Promise<void>;
268
268
  findFirst: (table: string, args?: {
@@ -277,9 +277,9 @@ interface LunoraDatabaseLike {
277
277
  patch: (id: string, patch: Record<string, unknown>) => Promise<void>;
278
278
  }
279
279
  /**
280
- * Structural subset of a Lunora function context used to build payments.
281
- * @experimental
282
- */
280
+ * Structural subset of a Lunora function context used to build payments.
281
+ * @experimental
282
+ */
283
283
  interface PaymentContextLike {
284
284
  auth?: {
285
285
  userId?: null | string;
@@ -287,9 +287,9 @@ interface PaymentContextLike {
287
287
  db: LunoraDatabaseLike;
288
288
  }
289
289
  /**
290
- * `PaymentsFromContextOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
291
- * @experimental
292
- */
290
+ * `PaymentsFromContextOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
291
+ * @experimental
292
+ */
293
293
  interface PaymentsFromContextOptions {
294
294
  readonly adapter: PaymentAdapter;
295
295
  /** Override the default "caller owns the referenceId" authorization. */
@@ -300,101 +300,101 @@ interface PaymentsFromContextOptions {
300
300
  readonly observability?: PaymentObserver;
301
301
  }
302
302
  /**
303
- * Adapt a Lunora `ctx.db` to the {@link PaymentDatabase} port the store writes through.
304
- * @experimental
305
- */
303
+ * Adapt a Lunora `ctx.db` to the {@link PaymentDatabase} port the store writes through.
304
+ * @experimental
305
+ */
306
306
  declare const lunoraDatabaseToPaymentDatabase: (database: LunoraDatabaseLike) => PaymentDatabase;
307
307
  /**
308
- * `paymentsFromContext` is part of the experimental `@lunora/payment` API and may change without a major version bump.
309
- * @experimental
310
- */
308
+ * `paymentsFromContext` is part of the experimental `@lunora/payment` API and may change without a major version bump.
309
+ * @experimental
310
+ */
311
311
  declare const paymentsFromContext: (context: PaymentContextLike, options: PaymentsFromContextOptions) => LunoraPayment;
312
312
  /**
313
- * `PaymentErrorCode` is part of the experimental `@lunora/payment` API and may change without a major version bump.
314
- * @experimental
315
- */
313
+ * `PaymentErrorCode` is part of the experimental `@lunora/payment` API and may change without a major version bump.
314
+ * @experimental
315
+ */
316
316
  type PaymentErrorCode = "CONFIG_INVALID" | "CURRENCY_MISMATCH" | "FORBIDDEN" | "INVALID_TRANSITION" | "NOT_FOUND" | "PROVIDER_ERROR" | "WEBHOOK_SIGNATURE_INVALID" | "WEBHOOK_TIMESTAMP_INVALID";
317
317
  /**
318
- * Typed error for all `@lunora/payment` failures. A `LunoraError` subclass; `status` maps onto an HTTP response.
319
- * @experimental
320
- */
318
+ * Typed error for all `@lunora/payment` failures. A `LunoraError` subclass; `status` maps onto an HTTP response.
319
+ * @experimental
320
+ */
321
321
  declare class LunoraPaymentError extends LunoraError {
322
322
  readonly code: PaymentErrorCode;
323
323
  constructor(code: PaymentErrorCode, message: string);
324
324
  }
325
325
  /**
326
- * Build a deterministic idempotency key from an operation name and stable parts.
327
- * @experimental
328
- */
326
+ * Build a deterministic idempotency key from an operation name and stable parts.
327
+ * @experimental
328
+ */
329
329
  declare const idempotencyKey: (operation: string, ...parts: ReadonlyArray<number | string>) => string;
330
330
  /**
331
- * True when the currency has no minor unit (e.g. JPY).
332
- * @experimental
333
- */
331
+ * True when the currency has no minor unit (e.g. JPY).
332
+ * @experimental
333
+ */
334
334
  declare const isZeroDecimalCurrency: (currency: CurrencyCode) => boolean;
335
335
  /**
336
- * Construct money. Currency is normalized to uppercase; never use floats for amounts.
337
- * @experimental
338
- */
336
+ * Construct money. Currency is normalized to uppercase; never use floats for amounts.
337
+ * @experimental
338
+ */
339
339
  declare const money: (minorUnits: bigint | number, currency: CurrencyCode) => Money;
340
340
  /**
341
- * `zeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
342
- * @experimental
343
- */
341
+ * `zeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
342
+ * @experimental
343
+ */
344
344
  declare const zeroMoney: (currency: CurrencyCode) => Money;
345
345
  /**
346
- * Localized currency string for display (e.g. `$19.99`). For UI only — never for arithmetic.
347
- * @experimental
348
- */
346
+ * Localized currency string for display (e.g. `$19.99`). For UI only — never for arithmetic.
347
+ * @experimental
348
+ */
349
349
  declare const formatMoney: (value: Money, locale?: string) => string;
350
350
  /**
351
- * `addMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
352
- * @experimental
353
- */
351
+ * `addMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
352
+ * @experimental
353
+ */
354
354
  declare const addMoney: (a: Money, b: Money) => Money;
355
355
  /**
356
- * `subtractMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
357
- * @experimental
358
- */
356
+ * `subtractMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
357
+ * @experimental
358
+ */
359
359
  declare const subtractMoney: (a: Money, b: Money) => Money;
360
360
  /**
361
- * Compares two same-currency amounts, returning -1, 0, or 1.
362
- * @experimental
363
- */
361
+ * Compares two same-currency amounts, returning -1, 0, or 1.
362
+ * @experimental
363
+ */
364
364
  declare const compareMoney: (a: Money, b: Money) => -1 | 0 | 1;
365
365
  /**
366
- * Split an amount across integer ratios, distributing the remainder to the smallest unit so the
367
- * parts always sum back to the original. The basis for seat/proration math.
368
- * @experimental
369
- */
366
+ * Split an amount across integer ratios, distributing the remainder to the smallest unit so the
367
+ * parts always sum back to the original. The basis for seat/proration math.
368
+ * @experimental
369
+ */
370
370
  declare const allocateMoney: (amount: Money, ratios: ReadonlyArray<bigint>) => Money[];
371
371
  /**
372
- * `isZeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
373
- * @experimental
374
- */
372
+ * `isZeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
373
+ * @experimental
374
+ */
375
375
  declare const isZeroMoney: (a: Money) => boolean;
376
376
  /**
377
- * JSON-safe wire form of money (bigint encoded as a decimal string).
378
- * @experimental
379
- */
377
+ * JSON-safe wire form of money (bigint encoded as a decimal string).
378
+ * @experimental
379
+ */
380
380
  interface MoneyJSON {
381
381
  readonly currency: CurrencyCode;
382
382
  readonly minorUnits: string;
383
383
  }
384
384
  /**
385
- * `toMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
386
- * @experimental
387
- */
385
+ * `toMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
386
+ * @experimental
387
+ */
388
388
  declare const toMoneyJSON: (m: Money) => MoneyJSON;
389
389
  /**
390
- * `fromMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
391
- * @experimental
392
- */
390
+ * `fromMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
391
+ * @experimental
392
+ */
393
393
  declare const fromMoneyJSON: (json: MoneyJSON) => Money;
394
394
  /**
395
- * `ReconcileInput` is part of the experimental `@lunora/payment` API and may change without a major version bump.
396
- * @experimental
397
- */
395
+ * `ReconcileInput` is part of the experimental `@lunora/payment` API and may change without a major version bump.
396
+ * @experimental
397
+ */
398
398
  interface ReconcileInput {
399
399
  readonly adapter: PaymentAdapter;
400
400
  /** Optional telemetry sink — fired per drifted row and once on completion. */
@@ -404,9 +404,9 @@ interface ReconcileInput {
404
404
  readonly subscriptionIds?: ReadonlyArray<string>;
405
405
  }
406
406
  /**
407
- * `ReconcileResult` is part of the experimental `@lunora/payment` API and may change without a major version bump.
408
- * @experimental
409
- */
407
+ * `ReconcileResult` is part of the experimental `@lunora/payment` API and may change without a major version bump.
408
+ * @experimental
409
+ */
410
410
  interface ReconcileResult {
411
411
  readonly checkedPayments: number;
412
412
  readonly checkedSubscriptions: number;
@@ -416,69 +416,69 @@ interface ReconcileResult {
416
416
  readonly updatedSubscriptions: number;
417
417
  }
418
418
  /**
419
- * `reconcile` is part of the experimental `@lunora/payment` API and may change without a major version bump.
420
- * @experimental
421
- */
419
+ * `reconcile` is part of the experimental `@lunora/payment` API and may change without a major version bump.
420
+ * @experimental
421
+ */
422
422
  declare const reconcile: (input: ReconcileInput) => Promise<ReconcileResult>;
423
423
  /**
424
- * `paymentTables` is part of the experimental `@lunora/payment` API and may change without a major version bump.
425
- * @experimental
426
- */
424
+ * `paymentTables` is part of the experimental `@lunora/payment` API and may change without a major version bump.
425
+ * @experimental
426
+ */
427
427
  declare const paymentTables: Record<string, TableDefinition>;
428
428
  /**
429
- * Action that may advance a payment session.
430
- * @experimental
431
- */
429
+ * Action that may advance a payment session.
430
+ * @experimental
431
+ */
432
432
  type PaymentAction = "authorize" | "cancel" | "capture" | "fail" | "partial_refund" | "refund";
433
433
  /**
434
- * Action that may advance a subscription.
435
- * @experimental
436
- */
434
+ * Action that may advance a subscription.
435
+ * @experimental
436
+ */
437
437
  type SubscriptionAction = "activate" | "cancel" | "mark_past_due" | "pause" | "renew" | "resume";
438
438
  /**
439
- * `PAYMENT_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
440
- * @experimental
441
- */
439
+ * `PAYMENT_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
440
+ * @experimental
441
+ */
442
442
  declare const PAYMENT_TERMINAL_STATES: ReadonlySet<PaymentState>;
443
443
  /**
444
- * `SUBSCRIPTION_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
445
- * @experimental
446
- */
444
+ * `SUBSCRIPTION_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
445
+ * @experimental
446
+ */
447
447
  declare const SUBSCRIPTION_TERMINAL_STATES: ReadonlySet<SubscriptionState>;
448
448
  /**
449
- * Next payment state for an action, or `undefined` if the transition is illegal from `from`.
450
- * @experimental
451
- */
449
+ * Next payment state for an action, or `undefined` if the transition is illegal from `from`.
450
+ * @experimental
451
+ */
452
452
  declare const nextPaymentState: (from: PaymentState, action: PaymentAction) => PaymentState | undefined;
453
453
  /**
454
- * `canTransitionPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
455
- * @experimental
456
- */
454
+ * `canTransitionPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
455
+ * @experimental
456
+ */
457
457
  declare const canTransitionPayment: (from: PaymentState, action: PaymentAction) => boolean;
458
458
  /**
459
- * Next subscription state for an action, or `undefined` if the transition is illegal from `from`.
460
- * @experimental
461
- */
459
+ * Next subscription state for an action, or `undefined` if the transition is illegal from `from`.
460
+ * @experimental
461
+ */
462
462
  declare const nextSubscriptionState: (from: SubscriptionState, action: SubscriptionAction) => SubscriptionState | undefined;
463
463
  /**
464
- * `canTransitionSubscription` is part of the experimental `@lunora/payment` API and may change without a major version bump.
465
- * @experimental
466
- */
464
+ * `canTransitionSubscription` is part of the experimental `@lunora/payment` API and may change without a major version bump.
465
+ * @experimental
466
+ */
467
467
  declare const canTransitionSubscription: (from: SubscriptionState, action: SubscriptionAction) => boolean;
468
468
  /**
469
- * `applyWebhookAction` is part of the experimental `@lunora/payment` API and may change without a major version bump.
470
- * @experimental
471
- */
469
+ * `applyWebhookAction` is part of the experimental `@lunora/payment` API and may change without a major version bump.
470
+ * @experimental
471
+ */
472
472
  declare const applyWebhookAction: (store: PaymentStore, action: WebhookAction, observer?: PaymentObserver) => Promise<ApplyResult>;
473
473
  /**
474
- * Constant-time string comparison to avoid leaking byte positions via timing.
475
- * @experimental
476
- */
474
+ * Constant-time string comparison to avoid leaking byte positions via timing.
475
+ * @experimental
476
+ */
477
477
  declare const constantTimeEqual: (a: string, b: string) => boolean;
478
478
  /**
479
- * `hmacSha256Hex` is part of the experimental `@lunora/payment` API and may change without a major version bump.
480
- * @experimental
481
- */
479
+ * `hmacSha256Hex` is part of the experimental `@lunora/payment` API and may change without a major version bump.
480
+ * @experimental
481
+ */
482
482
  declare const hmacSha256Hex: (secret: string, payload: string) => Promise<string>;
483
483
  interface VerifyStandardWebhookInput {
484
484
  /** Injectable clock (ms since epoch) for tests. */
@@ -497,11 +497,11 @@ interface VerifyStandardWebhookInput {
497
497
  readonly webhookTimestamp: string;
498
498
  }
499
499
  /**
500
- * Verify a Standard Webhooks signature (the scheme Polar and svix use):
501
- * `base64(HMAC_SHA256(key, "{id}.{timestamp}.{payload}"))` compared against the header's `v1`
502
- * entries, with a replay-window check. Throws a {@link LunoraPaymentError} on any failure.
503
- * @experimental
504
- */
500
+ * Verify a Standard Webhooks signature (the scheme Polar and svix use):
501
+ * `base64(HMAC_SHA256(key, "{id}.{timestamp}.{payload}"))` compared against the header's `v1`
502
+ * entries, with a replay-window check. Throws a {@link LunoraPaymentError} on any failure.
503
+ * @experimental
504
+ */
505
505
  declare const verifyStandardWebhook: (input: VerifyStandardWebhookInput) => Promise<void>;
506
506
  interface VerifyCreemSignatureInput {
507
507
  /** Raw request body, exactly as received. */
@@ -512,10 +512,10 @@ interface VerifyCreemSignatureInput {
512
512
  readonly signature: string;
513
513
  }
514
514
  /**
515
- * Verify a Creem webhook signature: `hex(HMAC_SHA256(secret, rawBody))` compared against the
516
- * `creem-signature` header. Creem's scheme signs the raw body with no timestamp, so there is no
517
- * replay-window check. Throws a {@link LunoraPaymentError} on any failure.
518
- * @experimental
519
- */
515
+ * Verify a Creem webhook signature: `hex(HMAC_SHA256(secret, rawBody))` compared against the
516
+ * `creem-signature` header. Creem's scheme signs the raw body with no timestamp, so there is no
517
+ * replay-window check. Throws a {@link LunoraPaymentError} on any failure.
518
+ * @experimental
519
+ */
520
520
  declare const verifyCreemSignature: (input: VerifyCreemSignatureInput) => Promise<void>;
521
521
  export { type ApplyResult, type AttachInput, type AuthorizeReference, type CancelSubscriptionOptions, type CheckInput, type CheckResult, type CheckoutInput, type CheckoutResult, type CreatePaymentOptions, type CurrencyCode, type Customer, type Entitlements, type EntitlementsConfig, type FeatureBalance, type LunoraDatabaseLike, type LunoraPayment, LunoraPaymentError, MemoryPaymentStore, type Money, type MoneyJSON, PAYMENT_TERMINAL_STATES, type PaymentAction, type PaymentAdapter, type PaymentContextLike, type PaymentDatabase, type PaymentErrorCode, type PaymentEvent, type PaymentObserver, type PaymentRow, type PaymentSession, type PaymentState, type PaymentStore, type PaymentsFromContextOptions, type PlanDefinition, type ProviderId, type ReconcileInput, type ReconcileResult, SUBSCRIPTION_TERMINAL_STATES, type Subscription, type SubscriptionAction, type SubscriptionState, type TrackInput, type TrackResult, type UsageEvent, type WebhookAction, type WebhookActionType, addMoney, allocateMoney, applyWebhookAction, canTransitionPayment, canTransitionSubscription, compareMoney, constantTimeEqual, createDatabasePaymentStore, createPayment, entitlementsForReference, featureNames, formatMoney, fromMoneyJSON, hasActivePrice, hmacSha256Hex, idempotencyKey, isZeroDecimalCurrency, isZeroMoney, lunoraDatabaseToPaymentDatabase, money, nextPaymentState, nextSubscriptionState, paymentTables, paymentsFromContext, reconcile, resolveEntitlements, subtractMoney, toMoneyJSON, usagePeriodStart, verifyCreemSignature, verifyStandardWebhook, zeroMoney };