@mesub/node 0.0.0-stage → 0.1.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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +835 -2
  3. package/dist/chunk-43Q4PNF7.cjs +480 -0
  4. package/dist/chunk-43Q4PNF7.cjs.map +1 -0
  5. package/dist/chunk-ELK7IBLO.js +340 -0
  6. package/dist/chunk-ELK7IBLO.js.map +1 -0
  7. package/dist/chunk-JJWHMB2X.js +480 -0
  8. package/dist/chunk-JJWHMB2X.js.map +1 -0
  9. package/dist/chunk-KMPBFNJE.js +2038 -0
  10. package/dist/chunk-KMPBFNJE.js.map +1 -0
  11. package/dist/chunk-PCDZI7B4.cjs +340 -0
  12. package/dist/chunk-PCDZI7B4.cjs.map +1 -0
  13. package/dist/chunk-SGSYQJYT.cjs +2038 -0
  14. package/dist/chunk-SGSYQJYT.cjs.map +1 -0
  15. package/dist/chunk-VMKI4VVA.cjs +120 -0
  16. package/dist/chunk-VMKI4VVA.cjs.map +1 -0
  17. package/dist/chunk-XDLLXY7Y.js +120 -0
  18. package/dist/chunk-XDLLXY7Y.js.map +1 -0
  19. package/dist/client-BQuRYSdB.d.ts +759 -0
  20. package/dist/client-Dm1jamju.d.cts +759 -0
  21. package/dist/errors-CtPucyOh.d.cts +112 -0
  22. package/dist/errors-DqW3DMBS.d.ts +112 -0
  23. package/dist/express.cjs +129 -0
  24. package/dist/express.cjs.map +1 -0
  25. package/dist/express.d.cts +57 -0
  26. package/dist/express.d.ts +57 -0
  27. package/dist/express.js +129 -0
  28. package/dist/express.js.map +1 -0
  29. package/dist/guard-DKb6iU1z.d.ts +51 -0
  30. package/dist/guard-Dhy4fI6n.d.cts +51 -0
  31. package/dist/index.cjs +39 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +44 -0
  34. package/dist/index.d.ts +44 -0
  35. package/dist/index.js +39 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/nest.cjs +62 -0
  38. package/dist/nest.cjs.map +1 -0
  39. package/dist/nest.d.cts +57 -0
  40. package/dist/nest.d.ts +57 -0
  41. package/dist/nest.js +62 -0
  42. package/dist/nest.js.map +1 -0
  43. package/dist/next.cjs +113 -0
  44. package/dist/next.cjs.map +1 -0
  45. package/dist/next.d.cts +63 -0
  46. package/dist/next.d.ts +63 -0
  47. package/dist/next.js +113 -0
  48. package/dist/next.js.map +1 -0
  49. package/dist/routes-CLtZnUzl.d.ts +130 -0
  50. package/dist/routes-DWkRFOP0.d.cts +130 -0
  51. package/dist/situations.cjs +15 -0
  52. package/dist/situations.cjs.map +1 -0
  53. package/dist/situations.d.cts +607 -0
  54. package/dist/situations.d.ts +607 -0
  55. package/dist/situations.js +15 -0
  56. package/dist/situations.js.map +1 -0
  57. package/dist/subscriptions-D1hE7MUc.d.cts +768 -0
  58. package/dist/subscriptions-D1hE7MUc.d.ts +768 -0
  59. package/dist/testing.cjs +1486 -0
  60. package/dist/testing.cjs.map +1 -0
  61. package/dist/testing.d.cts +331 -0
  62. package/dist/testing.d.ts +331 -0
  63. package/dist/testing.js +1486 -0
  64. package/dist/testing.js.map +1 -0
  65. package/package.json +158 -4
@@ -0,0 +1,768 @@
1
+ /**
2
+ * What `GET /v1/access` answers, copied from the back's `AccessAnswer`, which
3
+ * stays the source of truth. The contract test of #8 checks the two agree.
4
+ * Snake case, as the API serves it.
5
+ */
6
+ /**
7
+ * `superseded` is a stopped subscription the wallet came back over
8
+ * (Mesub-io/backend#213): the row that replaced it is the one in force, so
9
+ * `/v1/access` answers that one, but the back's type allows it.
10
+ *
11
+ * `cancelled` only while the cancellation runs: once its end date passed it
12
+ * reads `ended`, with `end_reason` `cancelled` (Mesub-io/backend#236).
13
+ *
14
+ * For a few minutes past a plan's end, `active` or `unpaid` is still read
15
+ * with `access` false, until Mesub ends the row: a guard reads `access`.
16
+ */
17
+ type SubscriptionStatus = 'pending' | 'active' | 'cancelled' | 'unpaid' | 'stopped' | 'ended' | 'failed' | 'superseded' | 'none';
18
+ /** `late` only while a pull failed and a retry is pending. */
19
+ type PaymentStatus = 'paid' | 'late' | 'none';
20
+ /**
21
+ * Why a subscription ended (Mesub-io/backend#236): cancelled and past its end
22
+ * date, the plan deleted, replaced by another at its address or past its own
23
+ * end, its subscription account closed outside Mesub (`closed_elsewhere`) or
24
+ * through it (`closed`). `authority_closed` is what Mesub served for
25
+ * `closed_elsewhere` before Mesub-io/backend#476: read the same way, it goes
26
+ * once no Mesub serves it.
27
+ */
28
+ type EndReason = 'cancelled' | 'plan_removed' | 'plan_replaced' | 'plan_ended' | 'closed_elsewhere' | 'authority_closed' | 'closed';
29
+ /**
30
+ * Why a payment is late (Mesub-io/backend#264), as the last failed pull found
31
+ * it: the wallet holds too little (adding funds fixes it), Mesub's approval on
32
+ * the token account was revoked or replaced by another app's (adding funds
33
+ * does not fix it), or the wallet's authorisation was closed, which is final.
34
+ */
35
+ type LateReason = 'insufficient_balance' | 'approval_revoked' | 'authority_closed';
36
+ /**
37
+ * Why a subscription stopped (Mesub-io/backend#402): every retry of the
38
+ * missed payment failed (`out_of_retries`), on Free the last day to pay it
39
+ * passed (`retry_deadline_passed`), or the wallet closed its subscription
40
+ * authority for good (`authority_closed`). After the first two the
41
+ * subscription stays open on chain and the subscriber can come back over it;
42
+ * after the third nobody can charge it again, the subscriber cannot come
43
+ * back over it, and can close it at once (`closable`).
44
+ */
45
+ type StopReason = 'out_of_retries' | 'retry_deadline_passed' | 'authority_closed';
46
+ /**
47
+ * Why every charge of a subscription is blocked, none of it the subscriber's
48
+ * doing (Mesub-io/backend#398). The merchant's own setup, theirs to fix, by
49
+ * name: Mesub's puller taken off the plan on chain, a receiving wallet that
50
+ * is not in the plan's destinations, has no token account for the plan's
51
+ * token or whose token account is frozen (Mesub-io/backend#395), a token
52
+ * that no longer exists. `mesub` for every cause of Mesub's.
53
+ */
54
+ type BlockedReason = 'puller_not_allowed' | 'receiver_not_allowed' | 'receiver_account_missing' | 'receiver_account_frozen' | 'mint_gone' | 'mesub';
55
+ /**
56
+ * `blocked` is a pull nothing was tried for, none of it the subscriber's
57
+ * doing (Mesub's fee payer, the network): it never counts against them.
58
+ */
59
+ type PullOutcome = 'paid' | 'skipped' | 'rejected' | 'blocked';
60
+ /** One pull attempt, newest first, as the subscriber it concerns may see it. */
61
+ interface ServedAttempt {
62
+ outcome: PullOutcome;
63
+ /**
64
+ * Mesub's short reason, null on a paid one: snake case
65
+ * (`insufficient_balance`) since Mesub-io/backend#475. An open string:
66
+ * besides the named ones, two families carry a code, `program_${number}`
67
+ * (a program refused the transfer, `program_4`) and `solana_${number}`
68
+ * (any other failure, `solana_7050005`), and new names get added.
69
+ */
70
+ reason: string | null;
71
+ /** In the mint's smallest unit, as a string: a u64 does not survive JSON. */
72
+ amount: string;
73
+ attempted_at: string;
74
+ signature: string | null;
75
+ }
76
+ interface AccessAnswer {
77
+ /**
78
+ * The wallet the answer is about. Asked by external id or email, the one
79
+ * that pays, and null when the customer has nothing on this plan.
80
+ */
81
+ wallet: string | null;
82
+ plan: string;
83
+ /**
84
+ * The subscription this answer is about (Mesub-io/backend#469), the one
85
+ * to `cancel`, `resume`, `close` or `retry` without listing the
86
+ * customer's subscriptions first. Null with `status` `none`. Read as null
87
+ * from a back that predates it.
88
+ */
89
+ subscription_id: string | null;
90
+ /**
91
+ * The only field a guard needs. False from the plan's end on, for a plan
92
+ * that has one, whatever `status` still reads.
93
+ */
94
+ access: boolean;
95
+ status: SubscriptionStatus;
96
+ /**
97
+ * A seat parked over the project's cap (Mesub-io/backend#236): `status`
98
+ * stays as it was, nothing is charged, and access runs to the end of the
99
+ * paid period. Read as false from a back that predates it.
100
+ */
101
+ paused: boolean;
102
+ /**
103
+ * Why it ended, only when `status` is `ended`; null on one that ended
104
+ * before the back recorded reasons. Read as null from a back that
105
+ * predates it.
106
+ */
107
+ end_reason: EndReason | null;
108
+ /**
109
+ * Why it is late, when `status` is `unpaid`, or `stopped` for the payment
110
+ * it stopped on; null on a refusal Mesub cannot place.
111
+ */
112
+ late_reason: LateReason | null;
113
+ /**
114
+ * Why it stopped, only when `status` is `stopped`; null on one that
115
+ * stopped before Mesub recorded why. Read as null from a back that
116
+ * predates it (Mesub-io/backend#402).
117
+ */
118
+ stop_reason: StopReason | null;
119
+ /** `none` on a paused seat: nothing is billed, so nothing is late. */
120
+ payment_status: PaymentStatus;
121
+ /**
122
+ * Since when every charge is blocked for a reason that is not the
123
+ * subscriber's (Mesub-io/backend#398), and whose cause it is; both null
124
+ * unless blocked. `status` and `payment_status` do not move for it, and
125
+ * Mesub keeps trying. `access` does: it ends at `access_until`, the end
126
+ * of the period after the one paid for, or sooner under a cause of the
127
+ * merchant's setup, and comes back with the first charge that goes
128
+ * through, nothing to sign. Read as null from a back that predates them.
129
+ */
130
+ blocked_since: string | null;
131
+ blocked_reason: BlockedReason | null;
132
+ subscribed_since: string | null;
133
+ first_subscribed_at: string | null;
134
+ current_period_end: string | null;
135
+ cancelled_at: string | null;
136
+ /**
137
+ * When access ends unless a pull renews it; null while `access` is false.
138
+ * Never later than the plan's end, where access stops for everyone, the
139
+ * last period being charged in full all the same. On a blocked one
140
+ * (`blocked_since`), when access ends if nothing is collected by then.
141
+ */
142
+ access_until: string | null;
143
+ /**
144
+ * A pull Mesub will run: the next charge, or the next retry on a late
145
+ * one, never both. Neither once the plan's end leaves no pull to run
146
+ * (Mesub-io/backend#362): the last period has no `next_charge_at`.
147
+ */
148
+ next_charge_at: string | null;
149
+ next_retry_at: string | null;
150
+ /**
151
+ * Free only (Mesub-io/backend#191): when hand retries of a missed pull
152
+ * close, two minutes before the end of its period, or the plan's end
153
+ * when that comes first; past it the subscription stops. Null on every
154
+ * other tier, whose retries are in `next_retry_at`. Read as null from a
155
+ * back that predates it. Like
156
+ * `paused` and `end_reason`, undefined only on an answer cached by an
157
+ * older SDK.
158
+ */
159
+ retry_deadline: string | null;
160
+ /**
161
+ * Whether the subscriber can close the subscription on chain now, which
162
+ * returns its deposit to their wallet (Mesub-io/backend#402): a
163
+ * cancellation past its end, one ended with its plan, or one stopped
164
+ * with `stop_reason` `authority_closed`. As Mesub last read the chain:
165
+ * `close` reads it again, and may still refuse. Read as false from a back
166
+ * that predates it.
167
+ */
168
+ closable: boolean;
169
+ /**
170
+ * When it can be closed, if not now: the end of the period a
171
+ * cancellation set. Null when `closable` is true, and when no date is
172
+ * known yet (a running one, or one stopped with `out_of_retries`, is
173
+ * cancelled first). Read as null from a back that predates it.
174
+ */
175
+ closable_from: string | null;
176
+ /** Only when asked for with `{ attempts: true }`. */
177
+ attempts?: ServedAttempt[];
178
+ /** Seconds this answer stays true: how long it is cached. */
179
+ revalidate_after: number;
180
+ }
181
+ /**
182
+ * Every plan of the project a customer has, when no plan is named: what
183
+ * `accessList` answers. Plans they never subscribed to are left out.
184
+ */
185
+ interface AccessList {
186
+ plans: AccessAnswer[];
187
+ /** The soonest of the plans', so one cached list goes stale with its first. */
188
+ revalidate_after: number;
189
+ }
190
+ /**
191
+ * Who an access question is about: exactly one of the wallet that pays, your
192
+ * own id for the customer (the `external_id` given at checkout), or the email
193
+ * given at checkout. A string alone is a wallet, as before.
194
+ */
195
+ type Customer = {
196
+ wallet: string;
197
+ } | {
198
+ external_id: string;
199
+ } | {
200
+ email: string;
201
+ };
202
+ interface AccessOptions {
203
+ /** Also answer the last pull attempts. Skips the cache both ways. */
204
+ attempts?: boolean;
205
+ }
206
+
207
+ type QueryValue = string | number | boolean | undefined;
208
+ interface TransportConfig {
209
+ apiKey: string;
210
+ baseUrl: string;
211
+ /** Sent with every call, before the SDK's own, which they never replace. */
212
+ headers: Record<string, string>;
213
+ fetch: typeof fetch;
214
+ timeout: number;
215
+ maxRetries: number;
216
+ }
217
+ /** What any one call may set for itself. */
218
+ interface RequestOptions {
219
+ /** Per attempt, in milliseconds. Defaults to the client's `timeout`. */
220
+ timeout?: number;
221
+ /**
222
+ * Stops the call, and any wait for a retry: it then rejects with the
223
+ * signal's reason, and is never sent again.
224
+ */
225
+ signal?: AbortSignal;
226
+ }
227
+ /** What one GET may change from the client's configuration. */
228
+ interface CallOptions extends RequestOptions {
229
+ maxRetries?: number;
230
+ /**
231
+ * Epoch ms by which the call settles, retries and waits included: each
232
+ * attempt is cut at it, and a wait that would outlast it is not waited.
233
+ */
234
+ deadline?: number;
235
+ /**
236
+ * False to throw a 429 at once, whatever it asks: a guard falls back
237
+ * rather than wait for the rate limit, and send more on top of it.
238
+ */
239
+ retryRateLimited?: boolean;
240
+ }
241
+ /** @internal Authenticated JSON calls to the Mesub API, with timeouts and retries. */
242
+ declare class Transport {
243
+ #private;
244
+ constructor(config: TransportConfig);
245
+ get(path: string, query?: Record<string, QueryValue>, options?: CallOptions): Promise<unknown>;
246
+ /**
247
+ * A POST with a JSON body, sent once: never retried here, whatever the
248
+ * status, a timeout or a network error. A write that got no answer may
249
+ * still have been done: its caller decides, knowing the route, whether
250
+ * the same body may be sent again (`submit` does, Mesub-io/backend#190)
251
+ * or the state read back.
252
+ */
253
+ post(path: string, body: unknown, options?: Omit<CallOptions, 'maxRetries'>): Promise<unknown>;
254
+ }
255
+
256
+ /**
257
+ * Subscribing from your own server, with the API key (Mesub-io/backend#143):
258
+ * `POST /v1/subscriptions`, a fresh transaction, its submit, the reads, and what stops one
259
+ * (Mesub-io/backend#276): cancel, resume and close. The types copy the
260
+ * back's `server-subscriptions.service.ts`, which stays the source of truth.
261
+ * Snake case, as the API serves it.
262
+ */
263
+ /**
264
+ * A subscription's status. Unlike `/v1/access`, may be `expired`: a checkout
265
+ * nobody signed (Mesub-io/backend#139). `superseded` is a stopped one the
266
+ * wallet came back over (Mesub-io/backend#213): a newer row holds the
267
+ * subscription. Never `none`: a row exists. `cancelled` reads `ended` once
268
+ * its end date passed, as on `/v1/access` (Mesub-io/backend#236).
269
+ */
270
+ type ServerSubscriptionStatus = 'pending' | 'active' | 'cancelled' | 'unpaid' | 'stopped' | 'ended' | 'failed' | 'expired' | 'superseded';
271
+ /** One subscription to your project's plans, as `GET /v1/subscriptions/:id` answers it. */
272
+ interface ServerSubscription {
273
+ id: string;
274
+ status: ServerSubscriptionStatus;
275
+ /** A seat parked over the project's cap, status unchanged, as `/v1/access` answers it. */
276
+ paused: boolean;
277
+ /** Why it ended, only on `ended`, as `/v1/access` answers it. */
278
+ end_reason: EndReason | null;
279
+ /** Why it is late, on `unpaid` or `stopped`, as `/v1/access` answers it. */
280
+ late_reason: LateReason | null;
281
+ /** Why it stopped, only on `stopped`, as `/v1/access` answers it. */
282
+ stop_reason: StopReason | null;
283
+ /** Whether it grants access now, as `/v1/access` answers it. */
284
+ access: boolean;
285
+ /** `paid`, `late` or `none`, as `/v1/access` answers it. */
286
+ payment_status: PaymentStatus;
287
+ /**
288
+ * Since when its charges are blocked for a reason that is not the
289
+ * subscriber's, and whose cause it is, as `/v1/access` answers them
290
+ * (Mesub-io/backend#398): both null unless blocked. Read as null from a
291
+ * back that predates them.
292
+ */
293
+ blocked_since: string | null;
294
+ blocked_reason: BlockedReason | null;
295
+ /** The plan's slug. */
296
+ plan: string | null;
297
+ wallet: string;
298
+ email: string | null;
299
+ external_id: string | null;
300
+ /** The period paid for last; null before the first. */
301
+ current_period_start: string | null;
302
+ current_period_end: string | null;
303
+ /**
304
+ * The next charge on a running one, the next retry on a late one: never
305
+ * both, and neither once the plan's end leaves no pull to run.
306
+ */
307
+ next_charge_at: string | null;
308
+ next_retry_at: string | null;
309
+ /**
310
+ * Free only, as `/v1/access` answers it (Mesub-io/backend#191): when hand
311
+ * retries close, the plan's end when that comes first; past it the
312
+ * subscription stops. Read as null from a back that predates it.
313
+ */
314
+ retry_deadline: string | null;
315
+ /**
316
+ * The retry due at `next_retry_at` and how many the missed period gets
317
+ * (Mesub-io/backend#289): 2 and 3 before the second retry of three. Both
318
+ * null unless Mesub retries on its own: not late, paused, stopped, on
319
+ * Free, or on a plan that ends before the retry. Read as null from a
320
+ * back that predates them.
321
+ */
322
+ next_retry_number: number | null;
323
+ retries_allowed: number | null;
324
+ /**
325
+ * When access ends unless a pull renews it; null while `access` is false.
326
+ * Never later than the plan's end.
327
+ */
328
+ access_until: string | null;
329
+ /** Whether the subscriber can close it now, as `/v1/access` answers it. */
330
+ closable: boolean;
331
+ /** When it can be closed, if not now and a date is known, as `/v1/access` answers it. */
332
+ closable_from: string | null;
333
+ created_at: string;
334
+ confirmed_at: string | null;
335
+ }
336
+ /** What subscribing costs in SOL, in lamports, as strings: a u64 does not survive JSON. */
337
+ interface SubscribeCosts {
338
+ /** Given back to the subscriber when the accounts are closed. `authority` is null if it exists. */
339
+ rent: {
340
+ subscription: string;
341
+ authority: string | null;
342
+ total: string;
343
+ };
344
+ /** Spent: the network's fee per signature, the wallet's and Mesub's. */
345
+ fee: {
346
+ signatures: number;
347
+ per_signature: string;
348
+ priority: string;
349
+ total: string;
350
+ };
351
+ total: string;
352
+ }
353
+ /** What `create` and `transaction` answer: what the wallet signs, terms first, then the transaction. */
354
+ interface SubscribeTransaction {
355
+ subscription: {
356
+ id: string;
357
+ status: ServerSubscriptionStatus;
358
+ };
359
+ /** Base64, signed by nobody: the wallet signs it with signTransaction, without sending it. */
360
+ transaction: string;
361
+ last_valid_block_height: string;
362
+ /**
363
+ * When `last_valid_block_height` is expected to pass, about half a minute
364
+ * after the answer (Mesub-io/backend#471): an estimate that errs early,
365
+ * for a countdown or to ask `transaction` for a fresh one in time. The
366
+ * height is the truth: rebuild after `transaction_expired`, before this
367
+ * time as after it. Null from a back that predates it.
368
+ */
369
+ transaction_expires_at: string | null;
370
+ costs: SubscribeCosts;
371
+ /** Signed as is with the wallet's signMessage, over its UTF-8 bytes, before `expires_at`. */
372
+ terms: {
373
+ message: string;
374
+ expires_at: string;
375
+ };
376
+ }
377
+ /**
378
+ * What `submit` settled on: what Mesub answered, or, when its answer was lost
379
+ * and the subscription read back is `active` or `cancelled`, that one.
380
+ */
381
+ interface SubmitResult {
382
+ /**
383
+ * `active`, or `cancelled` if the wallet set an end (`ended` once that
384
+ * end passed); `pending` or `failed` with a `reason`.
385
+ */
386
+ subscription: ServerSubscription;
387
+ /**
388
+ * Mesub's own, set when nothing landed (`pending`) or what landed is not
389
+ * Mesub's (`failed`). Never made up by the SDK. A sentence for a person,
390
+ * which Mesub may reword: branch on `reason_code`.
391
+ */
392
+ reason?: string;
393
+ /** Why, for a program: set exactly when `reason` is, from a back that serves it. */
394
+ reason_code?: ConfirmReasonCode;
395
+ }
396
+ /**
397
+ * What `cancel`, `resume` and `close` answer: a transaction only the wallet
398
+ * signs, and sends itself. Mesub signs nothing of it.
399
+ */
400
+ interface WalletTransaction {
401
+ /** Base64, signed by nobody: the wallet signs and sends it, then names its signature. */
402
+ transaction: string;
403
+ /** The block height past which it can no longer land. */
404
+ last_valid_block_height: string;
405
+ /** When that height is expected to pass, as `SubscribeTransaction` says it. */
406
+ transaction_expires_at: string | null;
407
+ }
408
+ /** What the wallet answered when it sent the transaction of `cancel`, `resume` or `close`. */
409
+ interface ConfirmParams {
410
+ /** The transaction's signature, base58. */
411
+ signature: string;
412
+ }
413
+ /** What `confirmCancel`, `confirmResume` and `confirmClose` settled on. */
414
+ interface ConfirmResult {
415
+ /** The subscription as it is now: moved, or as it was with a `reason`. */
416
+ subscription: ServerSubscription;
417
+ /**
418
+ * Mesub's own, set when nothing changed: the transaction failed, expired
419
+ * before it landed, or the subscription moved on meanwhile. A sentence
420
+ * for a person, which Mesub may reword: branch on `reason_code`.
421
+ */
422
+ reason?: string;
423
+ /** Why, for a program: set exactly when `reason` is, from a back that serves it. */
424
+ reason_code?: ConfirmReasonCode;
425
+ }
426
+ /**
427
+ * Why a submit or a confirm settled nothing, or not what was built
428
+ * (Mesub-io/backend#470): stable, snake case, never reworded. An open family:
429
+ * Mesub adds codes, so keep a default branch; one newer than this release is
430
+ * handed on as it is.
431
+ *
432
+ * - `not_our_transaction`: not a transaction Mesub co-signed over terms the
433
+ * wallet signed for this subscription.
434
+ * - `transaction_failed`: it landed and the chain refused it.
435
+ * - `transaction_expired`: its blockhash ran out before it landed.
436
+ * - `nothing_landed`: on a submit, nothing stands at its address yet.
437
+ * - `subscription_not_on_chain`: on a cancel or a resume, it is gone on chain.
438
+ * - `subscription_mismatch`: what landed names another wallet, plan, amount
439
+ * or period: now `failed`.
440
+ * - `dev_not_running`: Mesub's own Dev plan landed cancelled or part paid.
441
+ * - `earlier_subscription_running`: a comeback paid while the one it came
442
+ * back over ran again.
443
+ * - `subscription_remade`: on a submit, closed and made again without Mesub.
444
+ * - `cancellation_not_landed`, `resume_not_landed`, `close_not_landed`: the
445
+ * chain does not show the action.
446
+ * - `subscription_changed`: it moved on while the cancellation was read.
447
+ * - `subscription_not_cancelled`: on a resume, nothing to resume.
448
+ * - `cancelled_subscription_remade`: on a resume, closed and made again
449
+ * without Mesub: it stays `cancelled`.
450
+ * - `resume_unverified`: on a resume, the one on chain cannot be told to be
451
+ * the one cancelled: it stays `cancelled`.
452
+ */
453
+ type ConfirmReasonCode = 'not_our_transaction' | 'transaction_failed' | 'transaction_expired' | 'nothing_landed' | 'subscription_not_on_chain' | 'subscription_mismatch' | 'dev_not_running' | 'earlier_subscription_running' | 'subscription_remade' | 'cancellation_not_landed' | 'resume_not_landed' | 'close_not_landed' | 'subscription_changed' | 'subscription_not_cancelled' | 'cancelled_subscription_remade' | 'resume_unverified' | (string & {});
454
+ /** One page of a customer's subscriptions, newest first. */
455
+ interface ServerSubscriptionList {
456
+ data: ServerSubscription[];
457
+ /** Ask for the next page with `starting_after` set to the last id of this one. */
458
+ has_more: boolean;
459
+ }
460
+ /**
461
+ * One pull attempt of a subscription, as `GET /v1/subscriptions/:id/attempts`
462
+ * answers it (Mesub-io/backend#289): an attempt of `/v1/access`, with its id,
463
+ * whether it was a retry and the period it was for.
464
+ */
465
+ interface SubscriptionAttempt {
466
+ id: string;
467
+ attempted_at: string;
468
+ /** One of `PullOutcome` today; a newer one is handed on as is. */
469
+ outcome: PullOutcome;
470
+ /**
471
+ * Mesub's short reason, null on a paid one, as on `ServedAttempt`: snake
472
+ * case, an open string with the `program_${number}` and
473
+ * `solana_${number}` families.
474
+ */
475
+ reason: string | null;
476
+ /**
477
+ * In the mint's smallest unit, as a string. What was asked for; on a
478
+ * `paid` one that is what the transfer moved.
479
+ */
480
+ amount: string;
481
+ /**
482
+ * That amount in dollars at the price of the instant it was attempted, a
483
+ * decimal string such as `"9.99"`. Null until Mesub priced it, when it
484
+ * knows no price, and from a Mesub that predates it.
485
+ */
486
+ amount_usd: string | null;
487
+ /** The transaction that paid. Null on every outcome but `paid`, a refused one included. */
488
+ signature: string | null;
489
+ /** The subscription had already failed on this period. */
490
+ retry: boolean;
491
+ /**
492
+ * On a retry of the plan's, which one and out of how many, as recorded
493
+ * when it ran: 1 is the first after the missed charge. Both null on a
494
+ * first try, on a hand retry on Dev or Business, on an attempt that kept
495
+ * none, and from a back that does not serve them.
496
+ */
497
+ retry_number: number | null;
498
+ retries_allowed: number | null;
499
+ /** The start of the period it was for; null when Mesub recorded none. */
500
+ period_start: string | null;
501
+ }
502
+ /** One page of a subscription's attempts, newest first, and what it paid in all. */
503
+ interface SubscriptionAttemptList {
504
+ data: SubscriptionAttempt[];
505
+ /** Ask for the next page with `starting_after` set to the last id of this one. */
506
+ has_more: boolean;
507
+ /**
508
+ * Its `paid` attempts since it began and the sum of what they moved, in
509
+ * the mint's smallest unit: counted by Mesub over all of them, not this page.
510
+ */
511
+ paid: {
512
+ count: number;
513
+ amount: string;
514
+ };
515
+ }
516
+ /** Which page of a subscription's attempts. */
517
+ interface AttemptsParams {
518
+ /** 1 to 100, 20 by default. */
519
+ limit?: number;
520
+ /** The id of the last attempt of the previous page. */
521
+ starting_after?: string;
522
+ }
523
+ interface SubscribeParams {
524
+ /** The plan's slug. */
525
+ plan: string;
526
+ /** The wallet that signs and pays. */
527
+ wallet: string;
528
+ /** Where the subscriber's notices go. Not verified by Mesub. */
529
+ email?: string;
530
+ /** Your own id for this customer, handed back as given. */
531
+ external_id?: string;
532
+ }
533
+ interface SubmitParams {
534
+ /** The transaction of `create`, signed by the wallet, base64. */
535
+ transaction: string;
536
+ /** The wallet's signMessage over `terms.message`, base58. */
537
+ terms_signature: string;
538
+ }
539
+ interface SubmitOptions extends RequestOptions {
540
+ /**
541
+ * Per send, in milliseconds: 90 s by default. Lower it behind a proxy
542
+ * or a function with a shorter limit (Cloudflare cuts at 100 s); a send
543
+ * cut short may still be co-signed and land, so read the subscription
544
+ * back afterwards.
545
+ */
546
+ timeout?: number;
547
+ /**
548
+ * The whole submit in milliseconds, its sends and the waits between
549
+ * them: `timeout` plus 30 s by default, so 120 s. A send is cut at it,
550
+ * and a wait that would outlast it is not waited. Reading the
551
+ * subscription back once it is spent takes 10 s more at most, retries
552
+ * included: 130 s in all by default.
553
+ */
554
+ budget?: number;
555
+ }
556
+ interface ConfirmOptions extends RequestOptions {
557
+ /**
558
+ * In milliseconds: 90 s by default. Mesub waits for the transaction to
559
+ * land or its blockhash to expire, about a minute. A confirm cut short
560
+ * changed nothing: send it again with the same signature.
561
+ */
562
+ timeout?: number;
563
+ }
564
+ /**
565
+ * Whose subscriptions to list: a `Customer`, named exactly one way and
566
+ * normalised as `access` names them, and what narrows the page.
567
+ */
568
+ type ListParams = Customer & {
569
+ /** Only this plan's, by slug. */
570
+ plan?: string;
571
+ /** 1 to 100, 20 by default. */
572
+ limit?: number;
573
+ /** The id of the last subscription of the previous page. */
574
+ starting_after?: string;
575
+ };
576
+ declare class Subscriptions {
577
+ #private;
578
+ /** @internal */
579
+ constructor(transport: Transport, seen?: (subscription: ServerSubscription) => Promise<void>, changed?: (subscription: ServerSubscription) => Promise<void>);
580
+ /**
581
+ * Reserves a subscription to that plan for that wallet, and builds what
582
+ * it signs: `terms.message`, then `transaction`. Hand both to your front,
583
+ * then their signatures to `submit`. Called again for the same plan,
584
+ * wallet and customer (`external_id`, else `email`) while nothing landed,
585
+ * it answers the same subscription with a fresh transaction; by its id,
586
+ * `transaction` does. Another
587
+ * customer naming that wallet gets a subscription of its own
588
+ * (Mesub-io/backend#311): only the one the wallet signs for lands, and
589
+ * the others then expire. Sent once, never retried.
590
+ */
591
+ create(params: SubscribeParams, options?: RequestOptions): Promise<SubscribeTransaction>;
592
+ /**
593
+ * Relays what the wallet signed. Mesub checks it, co-signs, sends it and
594
+ * waits for the chain, so one send takes up to a minute or so: 90 s
595
+ * unless `options.timeout` says otherwise.
596
+ *
597
+ * When the send gets no answer that says what became of it (a timeout,
598
+ * a network error, a 5xx), or an error Mesub marks `retryable`, the same
599
+ * request, the same body, is sent again, up to twice, after the
600
+ * `Retry-After` Mesub asked for or 10 s, within `options.budget` (120 s
601
+ * by default). That is safe since Mesub-io/backend#190 and #202: Mesub
602
+ * recognises the transaction and the terms signature it already
603
+ * co-signed, signs nothing again, and answers from the chain or from the
604
+ * subscription it settled. Its answer is then returned as if the first
605
+ * send had got it, a `pending` with Mesub's own `reason` included.
606
+ *
607
+ * When no send got an answer, the subscription is read back once, within
608
+ * 10 s: it is returned if `active` or `cancelled` (it landed), and
609
+ * otherwise a `MesubSubmitError` `unavailable` is thrown with it attached
610
+ * as `subscription` (null if that read failed too): the wallet may have
611
+ * paid and the transaction may still land, so read it again with
612
+ * `retrieve` rather than create anew. A 2xx this SDK cannot read is read
613
+ * back the same way, and thrown as `unexpected`; so is a replay refused
614
+ * with `not_awaiting_signature` after a send that got no answer, thrown
615
+ * as that `conflict`.
616
+ *
617
+ * A 503 `unavailable` (too many submits waiting on the project,
618
+ * Mesub-io/backend#505) says nothing was signed or sent: it is replayed
619
+ * after its `Retry-After` (2 s) like any retryable refusal, and when the
620
+ * replays run out it is thrown as is, `retryable`, with no read back,
621
+ * unless an earlier send got no answer.
622
+ *
623
+ * Any other refusal (`terms_expired`, `transaction_expired`, ...) is
624
+ * thrown as is. After `transaction_expired` nothing was sent and the same
625
+ * submit cannot land: call `transaction(id)` for a new one, never
626
+ * `create` again.
627
+ * An abort through `options.signal` stops everything, sends, waits and
628
+ * the read back, and rejects with the signal's reason; a send already out
629
+ * may have been co-signed, so read the subscription back.
630
+ *
631
+ * A subscription returned with `access` (`active`, or `cancelled` before
632
+ * its end) drops the `/v1/access` answers cached for that customer (its
633
+ * wallet, external id and email) that still say no: `hasAccess` right
634
+ * after asks Mesub again.
635
+ */
636
+ submit(id: string, params: SubmitParams, options?: SubmitOptions): Promise<SubmitResult>;
637
+ /**
638
+ * A fresh transaction for a subscription still `pending`, with the terms
639
+ * it names (Mesub-io/backend#427). A transaction lives about half a
640
+ * minute, the terms five: have the terms signed first, call this when the
641
+ * wallet is ready, have it sign the transaction at once, then `submit`.
642
+ * Always sign the transaction of the last call. It is also what follows
643
+ * a submit refused with `transaction_expired`.
644
+ *
645
+ * A terms signature you hold is still good when `terms.message` is, to
646
+ * the letter, the message the wallet signed. Another text is new terms:
647
+ * have the wallet sign it, the old signature is refused
648
+ * (`invalid_terms_signature`).
649
+ *
650
+ * Reserves nothing and sends no body: the wallet, the plan and the
651
+ * customer are the subscription's own. Refused with `apiCode`
652
+ * `not_awaiting_signature` once it is signed, expired or ended (call
653
+ * `create` again for an expired one), and with what `create` refuses of
654
+ * a plan or a wallet (`plan_ended`, `insufficient_balance`,
655
+ * `already_subscribed`, ...). Sent once, never retried: asking twice is
656
+ * safe, only the last transaction is to be signed.
657
+ */
658
+ transaction(id: string, options?: RequestOptions): Promise<SubscribeTransaction>;
659
+ /**
660
+ * Builds the transaction that cancels an `active`, `unpaid` or `stopped`
661
+ * subscription. Hand it to your front: the subscription's wallet signs
662
+ * and sends it, then `confirmCancel` takes the signature. Nothing is
663
+ * cancelled until then. Sent once, never retried.
664
+ *
665
+ * One paid up keeps its access to the end of its period; a late or
666
+ * stopped one has none, and its missed period is never collected.
667
+ */
668
+ cancel(id: string, options?: RequestOptions): Promise<WalletTransaction>;
669
+ /**
670
+ * Settles a cancellation the wallet sent, by the signature it answered:
671
+ * `cancelled`, or the subscription as it was with a `reason` when nothing
672
+ * landed. Mesub waits for the chain, so up to a minute or so: 90 s unless
673
+ * `options.timeout` says otherwise. Sent once, never retried; the same
674
+ * confirm sent again is answered the same.
675
+ *
676
+ * Settled without a `reason`, it drops every `/v1/access` answer cached
677
+ * for that customer on that plan: `access` right after asks Mesub again.
678
+ */
679
+ confirmCancel(id: string, params: ConfirmParams, options?: ConfirmOptions): Promise<ConfirmResult>;
680
+ /**
681
+ * Builds the transaction that takes a `cancelled` subscription back,
682
+ * before the period it paid for is over. Hand it to your front: the
683
+ * wallet signs and sends it, then `confirmResume` takes the signature.
684
+ * Sent once, never retried.
685
+ */
686
+ resume(id: string, options?: RequestOptions): Promise<WalletTransaction>;
687
+ /** As `confirmCancel`, for a resume: `active` again, or a `reason`. */
688
+ confirmResume(id: string, params: ConfirmParams, options?: ConfirmOptions): Promise<ConfirmResult>;
689
+ /**
690
+ * Builds the transaction that closes the wallet's authorisation on a
691
+ * subscription that is over: its rent goes back to the wallet. Mesub
692
+ * builds it for a cancelled one past its end; for a stopped one
693
+ * cancelled on chain and past its end, or whose authority is closed for
694
+ * good; and for one `ended` with its plan (`end_reason` `plan_removed`,
695
+ * `plan_replaced` or `plan_ended`). A stopped one that nothing cancelled
696
+ * is refused with `subscription_not_cancelled`: cancel it first.
697
+ * Hand the transaction to your front: the wallet signs and sends it,
698
+ * then `confirmClose` takes the signature. Sent once, never retried.
699
+ */
700
+ close(id: string, options?: RequestOptions): Promise<WalletTransaction>;
701
+ /** As `confirmCancel`, for a close: `ended` with `end_reason` `closed`, or a `reason`. */
702
+ confirmClose(id: string, params: ConfirmParams, options?: ConfirmOptions): Promise<ConfirmResult>;
703
+ /**
704
+ * Pays a late payment now (Mesub-io/backend#354): the pull of the missed
705
+ * period runs at once rather than at its next retry, with nothing for the
706
+ * wallet to sign, since it approved the plan when it subscribed. Answers
707
+ * the subscription, still `unpaid`: the outcome comes with the pull, as
708
+ * the `subscription.renewed` or `subscription.payment_failed` webhook.
709
+ *
710
+ * The merchant's hand retry from the dashboard follows the same rules: on
711
+ * Free it is one of the missed period's three, whoever fires it; on Dev
712
+ * and Business it runs beside the schedule, the wait between two doubling.
713
+ * Mesub refuses it first when it cannot succeed, so it never spends a
714
+ * retry for nothing: `apiCode` `insufficient_balance` (top up, then pay
715
+ * again), `retry_cannot_succeed` (the wallet no longer approves it, its
716
+ * token account is frozen, or its authority is closed), `retry_too_soon`
717
+ * (`retryAfter` says when), `retries_spent`, `retry_deadline_passed`,
718
+ * `subscription_not_late`, `subscription_paused`, `plan_ended`. Two more
719
+ * are `retryable`: `subscription_changed` (two retries met, or a pull
720
+ * moved the subscription on) and, on Free, `pull_running` (a pull runs
721
+ * now). Read the subscription back before you ask again. A 503 is
722
+ * `retryable` too, and nothing changed: `unavailable` (the charge could
723
+ * not be queued) or `network_unavailable`, with `retryAfter` saying when
724
+ * to ask again (20 s and 10 s). Sent once, never retried: a second one is
725
+ * a second retry.
726
+ */
727
+ retry(id: string, options?: RequestOptions): Promise<ServerSubscription>;
728
+ /**
729
+ * One subscription of your project, by id. Found with `access`, it drops
730
+ * the access answers cached that still say no, as `submit` does.
731
+ */
732
+ retrieve(id: string, options?: RequestOptions): Promise<ServerSubscription>;
733
+ /**
734
+ * A customer's subscriptions, newest first, one page at a time; expired
735
+ * checkouts included. `listAll` walks every page.
736
+ *
737
+ * The customer is named as for `access`, and normalised the same way;
738
+ * none or two of `wallet`, `external_id` and `email` throws a TypeError.
739
+ * Each one with `access` drops the access answers cached that still say
740
+ * no, as `submit` does.
741
+ */
742
+ list(params: ListParams, options?: RequestOptions): Promise<ServerSubscriptionList>;
743
+ /**
744
+ * Every subscription `list` would answer, page after page, for `for await`.
745
+ * Each page is one call, made when the previous one is used up.
746
+ */
747
+ listAll(params: ListParams, options?: RequestOptions): AsyncGenerator<ServerSubscription, void, undefined>;
748
+ /**
749
+ * That subscription's own pull attempts, newest first, one page at a
750
+ * time, and `paid`: what it paid since it began, whatever the page.
751
+ * `allAttempts` walks every page.
752
+ *
753
+ * The id asked and no other: a subscription the wallet came back over
754
+ * (`superseded`) keeps its own payments, and the one that replaced it
755
+ * starts from its first pull. Needs a Mesub that serves the route
756
+ * (Mesub-io/backend#289): from an older one it throws a `not_found`
757
+ * whose `apiCode` is null, where an id it does not hold is a `not_found`
758
+ * whose `apiCode` is `subscription_not_found`.
759
+ */
760
+ attempts(id: string, params?: AttemptsParams, options?: RequestOptions): Promise<SubscriptionAttemptList>;
761
+ /**
762
+ * Every attempt `attempts` would answer, page after page, for `for await`.
763
+ * Each page is one call, made when the previous one is used up.
764
+ */
765
+ allAttempts(id: string, params?: AttemptsParams, options?: RequestOptions): AsyncGenerator<SubscriptionAttempt, void, undefined>;
766
+ }
767
+
768
+ export { type AccessAnswer as A, type BlockedReason as B, type Customer as C, type EndReason as E, type LateReason as L, type PaymentStatus as P, type RequestOptions as R, type ServedAttempt as S, Transport as T, type WalletTransaction as W, type AccessList as a, type AccessOptions as b, type AttemptsParams as c, type ConfirmOptions as d, type ConfirmParams as e, type ConfirmReasonCode as f, type ConfirmResult as g, type ListParams as h, type PullOutcome as i, type ServerSubscription as j, type ServerSubscriptionList as k, type ServerSubscriptionStatus as l, type StopReason as m, type SubmitOptions as n, type SubmitParams as o, type SubmitResult as p, type SubscribeCosts as q, type SubscribeParams as r, type SubscribeTransaction as s, type SubscriptionAttempt as t, type SubscriptionAttemptList as u, type SubscriptionStatus as v, Subscriptions as w };