@lunora/payment 1.0.0-alpha.24 → 1.0.0-alpha.26
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 +2 -0
- package/dist/index.d.mts +214 -25
- package/dist/index.d.ts +214 -25
- package/dist/packem_shared/{adapter.d-SULGy2QF.d.mts → adapter.d-BOheUepr.d.mts} +121 -15
- package/dist/packem_shared/{adapter.d-SULGy2QF.d.ts → adapter.d-BOheUepr.d.ts} +121 -15
- package/dist/providers/autumn-features.d.mts +41 -6
- package/dist/providers/autumn-features.d.ts +41 -6
- package/dist/providers/autumn.d.mts +10 -1
- package/dist/providers/autumn.d.ts +10 -1
- package/dist/providers/creem.d.mts +10 -1
- package/dist/providers/creem.d.ts +10 -1
- package/dist/providers/dodopayments.d.mts +10 -1
- package/dist/providers/dodopayments.d.ts +10 -1
- package/dist/providers/polar.d.mts +10 -1
- package/dist/providers/polar.d.ts +10 -1
- package/dist/providers/stripe.d.mts +10 -1
- package/dist/providers/stripe.d.ts +10 -1
- package/package.json +4 -4
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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-
|
|
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-
|
|
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";
|
|
3
3
|
import { LunoraError } from '@lunora/errors';
|
|
4
4
|
import { TableDefinition } from '@lunora/server';
|
|
5
|
+
/**
|
|
6
|
+
* `PaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
5
9
|
interface PaymentStore {
|
|
6
10
|
getCustomerByReference: (provider: ProviderId, referenceId: string) => Promise<Customer | undefined>;
|
|
7
11
|
getPaymentSession: (provider: ProviderId, id: string) => Promise<PaymentSession | undefined>;
|
|
@@ -33,7 +37,10 @@ interface PaymentStore {
|
|
|
33
37
|
upsertPaymentSession: (session: PaymentSession) => Promise<void>;
|
|
34
38
|
upsertSubscription: (subscription: Subscription) => Promise<void>;
|
|
35
39
|
}
|
|
36
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* In-memory {@link PaymentStore} for tests and local development. Not durable.
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
37
44
|
declare class MemoryPaymentStore implements PaymentStore {
|
|
38
45
|
private readonly customers;
|
|
39
46
|
private readonly processedEvents;
|
|
@@ -53,6 +60,10 @@ declare class MemoryPaymentStore implements PaymentStore {
|
|
|
53
60
|
upsertPaymentSession(session: PaymentSession): Promise<void>;
|
|
54
61
|
upsertSubscription(subscription: Subscription): Promise<void>;
|
|
55
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* `PlanDefinition` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
65
|
+
* @experimental
|
|
66
|
+
*/
|
|
56
67
|
interface PlanDefinition {
|
|
57
68
|
/** Feature flags this plan grants. */
|
|
58
69
|
readonly features?: ReadonlyArray<string>;
|
|
@@ -61,10 +72,18 @@ interface PlanDefinition {
|
|
|
61
72
|
/** Provider price/product ids that grant this plan. */
|
|
62
73
|
readonly priceIds: ReadonlyArray<string>;
|
|
63
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* `EntitlementsConfig` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
77
|
+
* @experimental
|
|
78
|
+
*/
|
|
64
79
|
interface EntitlementsConfig {
|
|
65
80
|
/** Plan name → definition. */
|
|
66
81
|
readonly plans: Record<string, PlanDefinition>;
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* `Entitlements` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
85
|
+
* @experimental
|
|
86
|
+
*/
|
|
68
87
|
interface Entitlements {
|
|
69
88
|
readonly features: ReadonlySet<string>;
|
|
70
89
|
/** True when an active subscription grants `feature`. */
|
|
@@ -78,16 +97,33 @@ interface Entitlements {
|
|
|
78
97
|
* Start of the window `check` sums metered usage over: the most recent billing-period start among
|
|
79
98
|
* a reference's active subscriptions. `0` (count all-time) when no active subscription reports one
|
|
80
99
|
* — limits still bind, they just never reset until the provider sends a period.
|
|
100
|
+
* @experimental
|
|
81
101
|
*/
|
|
82
102
|
declare const usagePeriodStart: (subscriptions: ReadonlyArray<Subscription>) => number;
|
|
83
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Every feature name a config can grant — the union of `features` flags and `limits` keys across all plans, sorted.
|
|
105
|
+
* @experimental
|
|
106
|
+
*/
|
|
84
107
|
declare const featureNames: (config: EntitlementsConfig) => string[];
|
|
85
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Whether the reference holds an entitling (active/trialing) subscription on `priceId` — the basis of a product `check`.
|
|
110
|
+
* @experimental
|
|
111
|
+
*/
|
|
86
112
|
declare const hasActivePrice: (subscriptions: ReadonlyArray<Subscription>, priceId: string) => boolean;
|
|
87
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Derive {@link Entitlements} from a reference's subscriptions. Pure — the basis of `check`.
|
|
115
|
+
* @experimental
|
|
116
|
+
*/
|
|
88
117
|
declare const resolveEntitlements: (config: EntitlementsConfig, subscriptions: ReadonlyArray<Subscription>) => Entitlements;
|
|
89
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Convenience: resolve entitlements straight from the store for a reference.
|
|
120
|
+
* @experimental
|
|
121
|
+
*/
|
|
90
122
|
declare const entitlementsForReference: (store: PaymentStore, config: EntitlementsConfig, referenceId: string) => Promise<Entitlements>;
|
|
123
|
+
/**
|
|
124
|
+
* `PaymentEvent` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
125
|
+
* @experimental
|
|
126
|
+
*/
|
|
91
127
|
type PaymentEvent = {
|
|
92
128
|
action: WebhookActionType;
|
|
93
129
|
eventId: string;
|
|
@@ -132,9 +168,20 @@ type PaymentEvent = {
|
|
|
132
168
|
referenceId: string;
|
|
133
169
|
type: "usage.report_failed";
|
|
134
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* `PaymentObserver` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
173
|
+
* @experimental
|
|
174
|
+
*/
|
|
135
175
|
type PaymentObserver = (event: PaymentEvent) => void;
|
|
136
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* Returns whether the current caller may act on `referenceId`. Throwing is also treated as denial.
|
|
178
|
+
* @experimental
|
|
179
|
+
*/
|
|
137
180
|
type AuthorizeReference = (referenceId: string) => boolean | Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* `CreatePaymentOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
183
|
+
* @experimental
|
|
184
|
+
*/
|
|
138
185
|
interface CreatePaymentOptions {
|
|
139
186
|
readonly adapter: PaymentAdapter;
|
|
140
187
|
/**
|
|
@@ -148,6 +195,10 @@ interface CreatePaymentOptions {
|
|
|
148
195
|
readonly observability?: PaymentObserver;
|
|
149
196
|
readonly store: PaymentStore;
|
|
150
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* `LunoraPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
200
|
+
* @experimental
|
|
201
|
+
*/
|
|
151
202
|
interface LunoraPayment {
|
|
152
203
|
readonly adapter: PaymentAdapter;
|
|
153
204
|
/**
|
|
@@ -180,12 +231,22 @@ interface LunoraPayment {
|
|
|
180
231
|
*/
|
|
181
232
|
track: (input: TrackInput) => Promise<TrackResult>;
|
|
182
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* `createPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
236
|
+
* @experimental
|
|
237
|
+
*/
|
|
183
238
|
declare const createPayment: (options: CreatePaymentOptions) => LunoraPayment;
|
|
184
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* A stored row, carrying Lunora's document id.
|
|
241
|
+
* @experimental
|
|
242
|
+
*/
|
|
185
243
|
interface PaymentRow extends Record<string, unknown> {
|
|
186
244
|
readonly _id: string;
|
|
187
245
|
}
|
|
188
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* Minimal write/read surface this store needs; `ctx.db` satisfies it structurally.
|
|
248
|
+
* @experimental
|
|
249
|
+
*/
|
|
189
250
|
interface PaymentDatabase {
|
|
190
251
|
delete: (id: string) => Promise<void>;
|
|
191
252
|
findFirst: (table: string, where: Record<string, unknown>) => Promise<PaymentRow | null>;
|
|
@@ -193,8 +254,15 @@ interface PaymentDatabase {
|
|
|
193
254
|
insert: (table: string, document: Record<string, unknown>) => Promise<string>;
|
|
194
255
|
patch: (id: string, patch: Record<string, unknown>) => Promise<void>;
|
|
195
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* `createDatabasePaymentStore` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
259
|
+
* @experimental
|
|
260
|
+
*/
|
|
196
261
|
declare const createDatabasePaymentStore: (database: PaymentDatabase) => PaymentStore;
|
|
197
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* Structural subset of Lunora's `ctx.db` (the `findFirst`/`findMany(tableName, { where })` form).
|
|
264
|
+
* @experimental
|
|
265
|
+
*/
|
|
198
266
|
interface LunoraDatabaseLike {
|
|
199
267
|
delete: (id: string) => Promise<void>;
|
|
200
268
|
findFirst: (table: string, args?: {
|
|
@@ -208,13 +276,20 @@ interface LunoraDatabaseLike {
|
|
|
208
276
|
insert: (table: string, document: Record<string, unknown>) => Promise<string>;
|
|
209
277
|
patch: (id: string, patch: Record<string, unknown>) => Promise<void>;
|
|
210
278
|
}
|
|
211
|
-
/**
|
|
279
|
+
/**
|
|
280
|
+
* Structural subset of a Lunora function context used to build payments.
|
|
281
|
+
* @experimental
|
|
282
|
+
*/
|
|
212
283
|
interface PaymentContextLike {
|
|
213
284
|
auth?: {
|
|
214
285
|
userId?: null | string;
|
|
215
286
|
};
|
|
216
287
|
db: LunoraDatabaseLike;
|
|
217
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* `PaymentsFromContextOptions` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
291
|
+
* @experimental
|
|
292
|
+
*/
|
|
218
293
|
interface PaymentsFromContextOptions {
|
|
219
294
|
readonly adapter: PaymentAdapter;
|
|
220
295
|
/** Override the default "caller owns the referenceId" authorization. */
|
|
@@ -224,41 +299,102 @@ interface PaymentsFromContextOptions {
|
|
|
224
299
|
/** Optional telemetry sink, forwarded to the facade. */
|
|
225
300
|
readonly observability?: PaymentObserver;
|
|
226
301
|
}
|
|
227
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Adapt a Lunora `ctx.db` to the {@link PaymentDatabase} port the store writes through.
|
|
304
|
+
* @experimental
|
|
305
|
+
*/
|
|
228
306
|
declare const lunoraDatabaseToPaymentDatabase: (database: LunoraDatabaseLike) => PaymentDatabase;
|
|
307
|
+
/**
|
|
308
|
+
* `paymentsFromContext` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
309
|
+
* @experimental
|
|
310
|
+
*/
|
|
229
311
|
declare const paymentsFromContext: (context: PaymentContextLike, options: PaymentsFromContextOptions) => LunoraPayment;
|
|
312
|
+
/**
|
|
313
|
+
* `PaymentErrorCode` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
314
|
+
* @experimental
|
|
315
|
+
*/
|
|
230
316
|
type PaymentErrorCode = "CONFIG_INVALID" | "CURRENCY_MISMATCH" | "FORBIDDEN" | "INVALID_TRANSITION" | "NOT_FOUND" | "PROVIDER_ERROR" | "WEBHOOK_SIGNATURE_INVALID" | "WEBHOOK_TIMESTAMP_INVALID";
|
|
231
|
-
/**
|
|
317
|
+
/**
|
|
318
|
+
* Typed error for all `@lunora/payment` failures. A `LunoraError` subclass; `status` maps onto an HTTP response.
|
|
319
|
+
* @experimental
|
|
320
|
+
*/
|
|
232
321
|
declare class LunoraPaymentError extends LunoraError {
|
|
233
322
|
readonly code: PaymentErrorCode;
|
|
234
323
|
constructor(code: PaymentErrorCode, message: string);
|
|
235
324
|
}
|
|
236
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* Build a deterministic idempotency key from an operation name and stable parts.
|
|
327
|
+
* @experimental
|
|
328
|
+
*/
|
|
237
329
|
declare const idempotencyKey: (operation: string, ...parts: ReadonlyArray<number | string>) => string;
|
|
238
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* True when the currency has no minor unit (e.g. JPY).
|
|
332
|
+
* @experimental
|
|
333
|
+
*/
|
|
239
334
|
declare const isZeroDecimalCurrency: (currency: CurrencyCode) => boolean;
|
|
240
|
-
/**
|
|
335
|
+
/**
|
|
336
|
+
* Construct money. Currency is normalized to uppercase; never use floats for amounts.
|
|
337
|
+
* @experimental
|
|
338
|
+
*/
|
|
241
339
|
declare const money: (minorUnits: bigint | number, currency: CurrencyCode) => Money;
|
|
340
|
+
/**
|
|
341
|
+
* `zeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
342
|
+
* @experimental
|
|
343
|
+
*/
|
|
242
344
|
declare const zeroMoney: (currency: CurrencyCode) => Money;
|
|
243
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Localized currency string for display (e.g. `$19.99`). For UI only — never for arithmetic.
|
|
347
|
+
* @experimental
|
|
348
|
+
*/
|
|
244
349
|
declare const formatMoney: (value: Money, locale?: string) => string;
|
|
350
|
+
/**
|
|
351
|
+
* `addMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
352
|
+
* @experimental
|
|
353
|
+
*/
|
|
245
354
|
declare const addMoney: (a: Money, b: Money) => Money;
|
|
355
|
+
/**
|
|
356
|
+
* `subtractMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
357
|
+
* @experimental
|
|
358
|
+
*/
|
|
246
359
|
declare const subtractMoney: (a: Money, b: Money) => Money;
|
|
247
|
-
/**
|
|
360
|
+
/**
|
|
361
|
+
* Compares two same-currency amounts, returning -1, 0, or 1.
|
|
362
|
+
* @experimental
|
|
363
|
+
*/
|
|
248
364
|
declare const compareMoney: (a: Money, b: Money) => -1 | 0 | 1;
|
|
249
365
|
/**
|
|
250
366
|
* Split an amount across integer ratios, distributing the remainder to the smallest unit so the
|
|
251
367
|
* parts always sum back to the original. The basis for seat/proration math.
|
|
368
|
+
* @experimental
|
|
252
369
|
*/
|
|
253
370
|
declare const allocateMoney: (amount: Money, ratios: ReadonlyArray<bigint>) => Money[];
|
|
371
|
+
/**
|
|
372
|
+
* `isZeroMoney` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
373
|
+
* @experimental
|
|
374
|
+
*/
|
|
254
375
|
declare const isZeroMoney: (a: Money) => boolean;
|
|
255
|
-
/**
|
|
376
|
+
/**
|
|
377
|
+
* JSON-safe wire form of money (bigint encoded as a decimal string).
|
|
378
|
+
* @experimental
|
|
379
|
+
*/
|
|
256
380
|
interface MoneyJSON {
|
|
257
381
|
readonly currency: CurrencyCode;
|
|
258
382
|
readonly minorUnits: string;
|
|
259
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* `toMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
386
|
+
* @experimental
|
|
387
|
+
*/
|
|
260
388
|
declare const toMoneyJSON: (m: Money) => MoneyJSON;
|
|
389
|
+
/**
|
|
390
|
+
* `fromMoneyJSON` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
391
|
+
* @experimental
|
|
392
|
+
*/
|
|
261
393
|
declare const fromMoneyJSON: (json: MoneyJSON) => Money;
|
|
394
|
+
/**
|
|
395
|
+
* `ReconcileInput` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
396
|
+
* @experimental
|
|
397
|
+
*/
|
|
262
398
|
interface ReconcileInput {
|
|
263
399
|
readonly adapter: PaymentAdapter;
|
|
264
400
|
/** Optional telemetry sink — fired per drifted row and once on completion. */
|
|
@@ -267,6 +403,10 @@ interface ReconcileInput {
|
|
|
267
403
|
readonly store: PaymentStore;
|
|
268
404
|
readonly subscriptionIds?: ReadonlyArray<string>;
|
|
269
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* `ReconcileResult` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
408
|
+
* @experimental
|
|
409
|
+
*/
|
|
270
410
|
interface ReconcileResult {
|
|
271
411
|
readonly checkedPayments: number;
|
|
272
412
|
readonly checkedSubscriptions: number;
|
|
@@ -275,23 +415,70 @@ interface ReconcileResult {
|
|
|
275
415
|
readonly updatedPayments: number;
|
|
276
416
|
readonly updatedSubscriptions: number;
|
|
277
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* `reconcile` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
420
|
+
* @experimental
|
|
421
|
+
*/
|
|
278
422
|
declare const reconcile: (input: ReconcileInput) => Promise<ReconcileResult>;
|
|
423
|
+
/**
|
|
424
|
+
* `paymentTables` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
425
|
+
* @experimental
|
|
426
|
+
*/
|
|
279
427
|
declare const paymentTables: Record<string, TableDefinition>;
|
|
280
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* Action that may advance a payment session.
|
|
430
|
+
* @experimental
|
|
431
|
+
*/
|
|
281
432
|
type PaymentAction = "authorize" | "cancel" | "capture" | "fail" | "partial_refund" | "refund";
|
|
282
|
-
/**
|
|
433
|
+
/**
|
|
434
|
+
* Action that may advance a subscription.
|
|
435
|
+
* @experimental
|
|
436
|
+
*/
|
|
283
437
|
type SubscriptionAction = "activate" | "cancel" | "mark_past_due" | "pause" | "renew" | "resume";
|
|
438
|
+
/**
|
|
439
|
+
* `PAYMENT_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
440
|
+
* @experimental
|
|
441
|
+
*/
|
|
284
442
|
declare const PAYMENT_TERMINAL_STATES: ReadonlySet<PaymentState>;
|
|
443
|
+
/**
|
|
444
|
+
* `SUBSCRIPTION_TERMINAL_STATES` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
445
|
+
* @experimental
|
|
446
|
+
*/
|
|
285
447
|
declare const SUBSCRIPTION_TERMINAL_STATES: ReadonlySet<SubscriptionState>;
|
|
286
|
-
/**
|
|
448
|
+
/**
|
|
449
|
+
* Next payment state for an action, or `undefined` if the transition is illegal from `from`.
|
|
450
|
+
* @experimental
|
|
451
|
+
*/
|
|
287
452
|
declare const nextPaymentState: (from: PaymentState, action: PaymentAction) => PaymentState | undefined;
|
|
453
|
+
/**
|
|
454
|
+
* `canTransitionPayment` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
455
|
+
* @experimental
|
|
456
|
+
*/
|
|
288
457
|
declare const canTransitionPayment: (from: PaymentState, action: PaymentAction) => boolean;
|
|
289
|
-
/**
|
|
458
|
+
/**
|
|
459
|
+
* Next subscription state for an action, or `undefined` if the transition is illegal from `from`.
|
|
460
|
+
* @experimental
|
|
461
|
+
*/
|
|
290
462
|
declare const nextSubscriptionState: (from: SubscriptionState, action: SubscriptionAction) => SubscriptionState | undefined;
|
|
463
|
+
/**
|
|
464
|
+
* `canTransitionSubscription` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
465
|
+
* @experimental
|
|
466
|
+
*/
|
|
291
467
|
declare const canTransitionSubscription: (from: SubscriptionState, action: SubscriptionAction) => boolean;
|
|
468
|
+
/**
|
|
469
|
+
* `applyWebhookAction` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
470
|
+
* @experimental
|
|
471
|
+
*/
|
|
292
472
|
declare const applyWebhookAction: (store: PaymentStore, action: WebhookAction, observer?: PaymentObserver) => Promise<ApplyResult>;
|
|
293
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* Constant-time string comparison to avoid leaking byte positions via timing.
|
|
475
|
+
* @experimental
|
|
476
|
+
*/
|
|
294
477
|
declare const constantTimeEqual: (a: string, b: string) => boolean;
|
|
478
|
+
/**
|
|
479
|
+
* `hmacSha256Hex` is part of the experimental `@lunora/payment` API and may change without a major version bump.
|
|
480
|
+
* @experimental
|
|
481
|
+
*/
|
|
295
482
|
declare const hmacSha256Hex: (secret: string, payload: string) => Promise<string>;
|
|
296
483
|
interface VerifyStandardWebhookInput {
|
|
297
484
|
/** Injectable clock (ms since epoch) for tests. */
|
|
@@ -313,6 +500,7 @@ interface VerifyStandardWebhookInput {
|
|
|
313
500
|
* Verify a Standard Webhooks signature (the scheme Polar and svix use):
|
|
314
501
|
* `base64(HMAC_SHA256(key, "{id}.{timestamp}.{payload}"))` compared against the header's `v1`
|
|
315
502
|
* entries, with a replay-window check. Throws a {@link LunoraPaymentError} on any failure.
|
|
503
|
+
* @experimental
|
|
316
504
|
*/
|
|
317
505
|
declare const verifyStandardWebhook: (input: VerifyStandardWebhookInput) => Promise<void>;
|
|
318
506
|
interface VerifyCreemSignatureInput {
|
|
@@ -327,6 +515,7 @@ interface VerifyCreemSignatureInput {
|
|
|
327
515
|
* Verify a Creem webhook signature: `hex(HMAC_SHA256(secret, rawBody))` compared against the
|
|
328
516
|
* `creem-signature` header. Creem's scheme signs the raw body with no timestamp, so there is no
|
|
329
517
|
* replay-window check. Throws a {@link LunoraPaymentError} on any failure.
|
|
518
|
+
* @experimental
|
|
330
519
|
*/
|
|
331
520
|
declare const verifyCreemSignature: (input: VerifyCreemSignatureInput) => Promise<void>;
|
|
332
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 };
|