@usebillow/sdk 0.5.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 (56) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +274 -0
  4. package/dist/billing-C4RIMgH_.d.ts +1053 -0
  5. package/dist/billing-DZ4rIyg7.d.cts +1053 -0
  6. package/dist/billing-status-BZQN_gm7.d.cts +29 -0
  7. package/dist/billing-status-BZQN_gm7.d.ts +29 -0
  8. package/dist/chunk-CCG4F5FK.js +48 -0
  9. package/dist/chunk-CCG4F5FK.js.map +1 -0
  10. package/dist/chunk-Z6VXPONT.js +1493 -0
  11. package/dist/chunk-Z6VXPONT.js.map +1 -0
  12. package/dist/config.cjs +233 -0
  13. package/dist/config.cjs.map +1 -0
  14. package/dist/config.d.cts +104 -0
  15. package/dist/config.d.ts +104 -0
  16. package/dist/config.js +228 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/credits-C3Fe3TO0.d.cts +315 -0
  19. package/dist/credits-C3Fe3TO0.d.ts +315 -0
  20. package/dist/index.cjs +1560 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +2379 -0
  23. package/dist/index.d.ts +2379 -0
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/ingestion.cjs +259 -0
  27. package/dist/ingestion.cjs.map +1 -0
  28. package/dist/ingestion.d.cts +182 -0
  29. package/dist/ingestion.d.ts +182 -0
  30. package/dist/ingestion.js +252 -0
  31. package/dist/ingestion.js.map +1 -0
  32. package/dist/react.cjs +360 -0
  33. package/dist/react.cjs.map +1 -0
  34. package/dist/react.d.cts +71 -0
  35. package/dist/react.d.ts +71 -0
  36. package/dist/react.js +153 -0
  37. package/dist/react.js.map +1 -0
  38. package/dist/server.cjs +98 -0
  39. package/dist/server.cjs.map +1 -0
  40. package/dist/server.d.cts +54 -0
  41. package/dist/server.d.ts +54 -0
  42. package/dist/server.js +96 -0
  43. package/dist/server.js.map +1 -0
  44. package/dist/status.cjs +60 -0
  45. package/dist/status.cjs.map +1 -0
  46. package/dist/status.d.cts +31 -0
  47. package/dist/status.d.ts +31 -0
  48. package/dist/status.js +3 -0
  49. package/dist/status.js.map +1 -0
  50. package/dist/webhooks.cjs +157 -0
  51. package/dist/webhooks.cjs.map +1 -0
  52. package/dist/webhooks.d.cts +391 -0
  53. package/dist/webhooks.d.ts +391 -0
  54. package/dist/webhooks.js +143 -0
  55. package/dist/webhooks.js.map +1 -0
  56. package/package.json +169 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Public SDK types for prepaid credits. Re-exported by ../types.ts.
3
+ *
4
+ * Every credit quantity is a `string` of whole microcredits (1 credit = 1,000,000), e.g.
5
+ * `"5000000"` for 5 credits - never a `number`, which would silently round past 2^53. Parse one
6
+ * with `BigInt(value)` to do arithmetic. Money (prices, charges) stays a number of minor units.
7
+ */
8
+ /** A Credit Grant's kind. Spending draws `included` first and `purchased` last, among equals. */
9
+ type CreditGrantKind = "included" | "promotional" | "adjustment" | "purchased";
10
+ /**
11
+ * Where a credit balance stands: `exhausted` when nothing is spendable, else `critical` or `low`
12
+ * at or below the project's percentages of its reference, else `normal`.
13
+ */
14
+ type CreditThresholdLevel = "normal" | "low" | "critical" | "exhausted";
15
+ /** A lot of credits on a Customer's Credit Account. */
16
+ interface CreditGrant {
17
+ id: string;
18
+ /** The Customer's external id. */
19
+ customerId: string;
20
+ kind: CreditGrantKind;
21
+ /** Microcredits issued. */
22
+ amount: string;
23
+ /** Microcredits still spendable (not held by a reservation, not expired), as issued. */
24
+ available: string;
25
+ /** Microcredits held by open reservations, as issued. */
26
+ held: string;
27
+ /** When its unheld credits expire (ISO 8601); null = never. */
28
+ expiresAt: string | null;
29
+ /** Credit Action categories it may pay for; null = every category. */
30
+ eligibility: string[] | null;
31
+ /** Your reason for issuing it, as given; cleared when the customer is erased. */
32
+ reason: string | null;
33
+ metadata: Record<string, string> | null;
34
+ createdAt: string;
35
+ }
36
+ /** What `credits.grants.create` answers: the grant its idempotency key stands for. */
37
+ interface CreditGrantRequestResult extends CreditGrant {
38
+ /**
39
+ * `true` when the idempotency key was already used: this is the grant that earlier request
40
+ * made, as it was issued, and nothing new was granted. `false` when this call made it.
41
+ */
42
+ replayed: boolean;
43
+ }
44
+ /**
45
+ * Grant credits to a Customer. Only `promotional` and `adjustment` grants are issued here:
46
+ * purchased credits come from top-ups, included ones from subscriptions.
47
+ */
48
+ interface CreateCreditGrantInput {
49
+ /** The Customer's external id. */
50
+ customerId: string;
51
+ kind: "promotional" | "adjustment";
52
+ /** Positive whole microcredits as a decimal string, at most 19 digits. */
53
+ amount: string;
54
+ /** When its unheld credits expire (ISO 8601 with a timezone, in the future); omit = never. */
55
+ expiresAt?: string;
56
+ /**
57
+ * Credit Action categories it may pay for (lowercase, e.g. `"messaging"`). Omit for the
58
+ * Project's default for the kind; `null` for every category.
59
+ */
60
+ eligibility?: string[] | null;
61
+ /** Why it was issued, kept on the grant and cleared on erasure. Required for an `adjustment`. */
62
+ reason?: string;
63
+ /** At most 20 keys (40 characters) and values (500 characters). Never personal data. */
64
+ metadata?: Record<string, string>;
65
+ }
66
+ /** A Credit Account's status: `frozen` takes no new reservations; `closed` (erased) takes nothing. */
67
+ type CreditAccountStatus = "active" | "frozen" | "closed";
68
+ /**
69
+ * A customer's credit balance, true at `asOf`. A balance never grants spending authority - only a
70
+ * reservation does. A customer with no credit account yet reads as zeros, `active`, `exhausted`.
71
+ */
72
+ interface CreditBalance {
73
+ /** The customer's external id. */
74
+ customerId: string;
75
+ status: CreditAccountStatus;
76
+ /** Unheld credits of grants that have not expired: what reservations could hold now. */
77
+ spendable: string;
78
+ /** Credits held by open reservations. */
79
+ held: string;
80
+ /** Credits consumed since `periodStart`, net of reversals. */
81
+ consumedThisPeriod: string;
82
+ /** The current included period's start, else the first instant of the current UTC month. */
83
+ periodStart: string;
84
+ /** Unheld credits expiring within the next 7 days, and the earliest of those expiries. */
85
+ expiringSoon: {
86
+ amount: string;
87
+ earliestAt: string | null;
88
+ };
89
+ byBucket: {
90
+ /** Spendable credits per grant kind; they sum to `spendable`. */
91
+ kinds: Record<CreditGrantKind, string>;
92
+ /**
93
+ * Spendable credits per category some grant is limited to, counting the grants that pay for
94
+ * every category too: the figures overlap and need not sum to `spendable`.
95
+ */
96
+ categories: Record<string, string>;
97
+ /** Spendable on a category not listed: the grants that pay for every category. */
98
+ otherCategories: string;
99
+ };
100
+ /** The active included grants (a subscription's period allowance); null when there are none. */
101
+ currentPeriod: {
102
+ granted: string;
103
+ /** Consumed from them, net of reversals. */
104
+ used: string;
105
+ held: string;
106
+ /** Unheld and spendable. */
107
+ remaining: string;
108
+ start: string;
109
+ /** When they expire (the period end); null if one never does. */
110
+ end: string | null;
111
+ } | null;
112
+ thresholds: {
113
+ lowPercent: number;
114
+ criticalPercent: number;
115
+ /** What the percentages apply to: the current period's credits, else the last top-up's. */
116
+ reference: string | null;
117
+ level: CreditThresholdLevel;
118
+ };
119
+ /** The server time the whole read was true at (ISO 8601). */
120
+ asOf: string;
121
+ }
122
+ /** A ledger transaction's type: one per balance change. */
123
+ type CreditTransactionType = "grant" | "hold" | "release" | "consume" | "expire" | "reverse" | "revoke" | "adjust";
124
+ /** One balance change on a customer's credit ledger, with its effect on the account's totals. */
125
+ interface CreditLedgerEntry {
126
+ id: string;
127
+ type: CreditTransactionType;
128
+ /** Why Billow posted it, as a system code (`api_grant`, `grant_expired`, ...); never free text. */
129
+ reason: string | null;
130
+ /** How it moved the account's unheld credits (signed). */
131
+ availableDelta: string;
132
+ /** How it moved the account's held credits (signed). */
133
+ heldDelta: string;
134
+ availableAfter: string;
135
+ heldAfter: string;
136
+ grantId: string | null;
137
+ reservationId: string | null;
138
+ topUpId: string | null;
139
+ /** On a reversal: the consumption (its `consume` transaction) it gives back. */
140
+ consumptionId: string | null;
141
+ /** Your own reason on the resource it belongs to (a grant's or reversal's); cleared on erasure. */
142
+ callerReason: string | null;
143
+ /** The metadata of the resource it belongs to: its reservation, reversal or top-up, else its grant. */
144
+ metadata: Record<string, string> | null;
145
+ createdAt: string;
146
+ }
147
+ /** What `credits.usage.get` totals each row by. */
148
+ type CreditUsageGroupBy = "action" | "category";
149
+ interface CreditUsageParams {
150
+ /** The first UTC day (`YYYY-MM-DD`); defaults to 29 days before `to`. */
151
+ from?: string;
152
+ /** The last UTC day (`YYYY-MM-DD`), included; defaults to today (UTC). At most 92 days in all. */
153
+ to?: string;
154
+ /** A Credit Action (default) or a category. */
155
+ groupBy?: CreditUsageGroupBy;
156
+ }
157
+ /** A customer's credit consumption per UTC day; days with none have no row. */
158
+ interface CreditUsage {
159
+ /** The customer's external id. */
160
+ customerId: string;
161
+ from: string;
162
+ to: string;
163
+ groupBy: CreditUsageGroupBy;
164
+ data: Array<{
165
+ /** The UTC day, `YYYY-MM-DD`. */
166
+ date: string;
167
+ /** The Credit Action, or the category. */
168
+ key: string;
169
+ units: string;
170
+ amount: string;
171
+ }>;
172
+ }
173
+ /** Money: whole minor units of a currency (e.g. piasters), with its ISO-4217 code. */
174
+ interface CreditMoney {
175
+ amount: number;
176
+ currency: string;
177
+ }
178
+ /** A Credit Pack's configuration: a one-time catalog Price sold as credits, plus a bonus. */
179
+ interface CreditPack {
180
+ id: string;
181
+ name: string;
182
+ priceId: string;
183
+ /** The Price's amount and currency as they are now (a top-up keeps what it was bought at). */
184
+ price: CreditMoney;
185
+ /** Microcredits the purchased grant issues. */
186
+ credits: string;
187
+ /** Microcredits the bonus grant issues (a separate `promotional` grant); "0" for no bonus. */
188
+ bonusCredits: string;
189
+ /** How long after a top-up succeeds its bonus expires, in seconds; null = never. */
190
+ bonusExpiresInSeconds: number | null;
191
+ /** Categories the bonus may pay for; null = every category. */
192
+ bonusEligibility: string[] | null;
193
+ /** An archived pack is never sold again. */
194
+ archived: boolean;
195
+ createdAt: string;
196
+ updatedAt: string;
197
+ }
198
+ /**
199
+ * Configure a Credit Pack on a one-time catalog Price that costs something (free credits are
200
+ * promotional grants, never a pack). A pack must issue something.
201
+ */
202
+ interface CreateCreditPackInput {
203
+ /** A `one_time` catalog Price: what the pack costs, and in which currency. */
204
+ priceId: string;
205
+ name: string;
206
+ /** Whole microcredits as a decimal string; may be "0" when the pack is all bonus. */
207
+ credits: string;
208
+ /** Whole microcredits as a decimal string; omit for no bonus. */
209
+ bonusCredits?: string;
210
+ /** Seconds after the top-up succeeds that the bonus expires; omit or null = never. */
211
+ bonusExpiresInSeconds?: number | null;
212
+ /** Categories the bonus may pay for; omit or null = every category. */
213
+ bonusEligibility?: string[] | null;
214
+ }
215
+ /** Edit a Credit Pack: any of its terms, its Price, or `archived`. Top-ups keep their terms. */
216
+ type UpdateCreditPackInput = Partial<CreateCreditPackInput> & {
217
+ archived?: boolean;
218
+ };
219
+ /** A pack a customer can buy, with its derived price per credit and savings. */
220
+ interface CreditPackListItem {
221
+ id: string;
222
+ name: string;
223
+ credits: string;
224
+ bonusCredits: string;
225
+ /** The catalog Price: what `pricePerCredit` and `savingsBps` are measured on. */
226
+ price: CreditMoney;
227
+ /**
228
+ * The tax a top-up of the pack charges (the Price's treatment, else your project's default):
229
+ * added on top when exclusive, already inside `price` when inclusive; 0 when none applies.
230
+ */
231
+ tax: CreditMoney;
232
+ /** What a top-up of the pack charges: `price` plus any exclusive `tax`. For display only. */
233
+ total: CreditMoney;
234
+ /** When the bonus expires after purchase, in seconds; null without a bonus or when it never does. */
235
+ bonusExpiresInSeconds: number | null;
236
+ /** The categories the bonus may pay for; null without a bonus or when it pays for every one. */
237
+ bonusEligibility: string[] | null;
238
+ /**
239
+ * Minor units of `price` per credit (credits plus bonus), rounded half-up to 6 decimal places,
240
+ * as a decimal string - for display only, never used to charge.
241
+ */
242
+ pricePerCredit: string;
243
+ /**
244
+ * Basis points cheaper per credit than the currency's base pack (its highest per-credit price),
245
+ * rounded down; 0 for the base pack itself.
246
+ */
247
+ savingsBps: number;
248
+ }
249
+ /** The packs a customer can buy in one currency, cheapest first. */
250
+ interface CreditPacks {
251
+ currency: string;
252
+ data: CreditPackListItem[];
253
+ }
254
+ /**
255
+ * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
256
+ * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
257
+ * the customer was erased, nothing granted; `binding_mismatch` - the payment did not match the
258
+ * top-up, nothing granted. The last two wait for a refund.
259
+ */
260
+ type CreditTopUpStatus = "pending" | "succeeded" | "failed" | "unfulfilled" | "binding_mismatch";
261
+ /** One purchase of a Credit Pack, as it now stands. */
262
+ interface CreditTopUp {
263
+ id: string;
264
+ /** The customer's external id. */
265
+ customerId: string;
266
+ packId: string;
267
+ status: CreditTopUpStatus;
268
+ /** The terms bought: what success grants. */
269
+ credits: string;
270
+ bonusCredits: string;
271
+ bonusExpiresInSeconds: number | null;
272
+ bonusEligibility: string[] | null;
273
+ /** What the payment collects (the Price plus any exclusive tax), in minor units. */
274
+ amount: number;
275
+ currency: string;
276
+ /** The charge collecting it; null until it exists. */
277
+ chargeId: string | null;
278
+ /** The hosted checkout to send the buyer to, while it can still take the payment. */
279
+ checkoutUrl: string | null;
280
+ purchasedGrantId: string | null;
281
+ bonusGrantId: string | null;
282
+ /** Microcredits refunds and lost chargebacks of the payment have revoked so far. */
283
+ revoked: string;
284
+ /** Of the revoked credits, those already spent and not paid back since. */
285
+ shortfall: string;
286
+ metadata: Record<string, string> | null;
287
+ settledAt: string | null;
288
+ createdAt: string;
289
+ }
290
+ /** Buy a Credit Pack for a customer. */
291
+ interface CreateCreditTopUpInput {
292
+ /** The customer's external id. */
293
+ customerId: string;
294
+ packId: string;
295
+ /** Where the hosted checkout sends the buyer when they are done. */
296
+ redirectionUrl?: string;
297
+ /** At most 20 keys (40 characters) and values (500 characters). Never personal data. */
298
+ metadata?: Record<string, string>;
299
+ }
300
+ /** What `credits.topUps.create` answers: the top-up its idempotency key stands for. */
301
+ interface CreditTopUpRequestResult extends CreditTopUp {
302
+ /**
303
+ * `true` when the idempotency key was already used: this is that request's top-up as it now
304
+ * stands, and nothing new was bought. `false` when this call made it.
305
+ */
306
+ replayed: boolean;
307
+ }
308
+ /** Narrow a customer's top-ups list. */
309
+ interface CreditTopUpListParams {
310
+ limit?: number;
311
+ cursor?: string;
312
+ status?: CreditTopUpStatus;
313
+ }
314
+
315
+ export type { CreditGrantKind as C, UpdateCreditPackInput as U, CreditThresholdLevel as a, CreditGrant as b, CreditTopUp as c, CreateCreditGrantInput as d, CreditGrantRequestResult as e, CreditPacks as f, CreateCreditPackInput as g, CreditPack as h, CreateCreditTopUpInput as i, CreditTopUpRequestResult as j, CreditTopUpListParams as k, CreditBalance as l, CreditLedgerEntry as m, CreditUsageParams as n, CreditUsage as o, CreditAccountStatus as p, CreditMoney as q, CreditPackListItem as r, CreditTopUpStatus as s, CreditTransactionType as t, CreditUsageGroupBy as u };
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Public SDK types for prepaid credits. Re-exported by ../types.ts.
3
+ *
4
+ * Every credit quantity is a `string` of whole microcredits (1 credit = 1,000,000), e.g.
5
+ * `"5000000"` for 5 credits - never a `number`, which would silently round past 2^53. Parse one
6
+ * with `BigInt(value)` to do arithmetic. Money (prices, charges) stays a number of minor units.
7
+ */
8
+ /** A Credit Grant's kind. Spending draws `included` first and `purchased` last, among equals. */
9
+ type CreditGrantKind = "included" | "promotional" | "adjustment" | "purchased";
10
+ /**
11
+ * Where a credit balance stands: `exhausted` when nothing is spendable, else `critical` or `low`
12
+ * at or below the project's percentages of its reference, else `normal`.
13
+ */
14
+ type CreditThresholdLevel = "normal" | "low" | "critical" | "exhausted";
15
+ /** A lot of credits on a Customer's Credit Account. */
16
+ interface CreditGrant {
17
+ id: string;
18
+ /** The Customer's external id. */
19
+ customerId: string;
20
+ kind: CreditGrantKind;
21
+ /** Microcredits issued. */
22
+ amount: string;
23
+ /** Microcredits still spendable (not held by a reservation, not expired), as issued. */
24
+ available: string;
25
+ /** Microcredits held by open reservations, as issued. */
26
+ held: string;
27
+ /** When its unheld credits expire (ISO 8601); null = never. */
28
+ expiresAt: string | null;
29
+ /** Credit Action categories it may pay for; null = every category. */
30
+ eligibility: string[] | null;
31
+ /** Your reason for issuing it, as given; cleared when the customer is erased. */
32
+ reason: string | null;
33
+ metadata: Record<string, string> | null;
34
+ createdAt: string;
35
+ }
36
+ /** What `credits.grants.create` answers: the grant its idempotency key stands for. */
37
+ interface CreditGrantRequestResult extends CreditGrant {
38
+ /**
39
+ * `true` when the idempotency key was already used: this is the grant that earlier request
40
+ * made, as it was issued, and nothing new was granted. `false` when this call made it.
41
+ */
42
+ replayed: boolean;
43
+ }
44
+ /**
45
+ * Grant credits to a Customer. Only `promotional` and `adjustment` grants are issued here:
46
+ * purchased credits come from top-ups, included ones from subscriptions.
47
+ */
48
+ interface CreateCreditGrantInput {
49
+ /** The Customer's external id. */
50
+ customerId: string;
51
+ kind: "promotional" | "adjustment";
52
+ /** Positive whole microcredits as a decimal string, at most 19 digits. */
53
+ amount: string;
54
+ /** When its unheld credits expire (ISO 8601 with a timezone, in the future); omit = never. */
55
+ expiresAt?: string;
56
+ /**
57
+ * Credit Action categories it may pay for (lowercase, e.g. `"messaging"`). Omit for the
58
+ * Project's default for the kind; `null` for every category.
59
+ */
60
+ eligibility?: string[] | null;
61
+ /** Why it was issued, kept on the grant and cleared on erasure. Required for an `adjustment`. */
62
+ reason?: string;
63
+ /** At most 20 keys (40 characters) and values (500 characters). Never personal data. */
64
+ metadata?: Record<string, string>;
65
+ }
66
+ /** A Credit Account's status: `frozen` takes no new reservations; `closed` (erased) takes nothing. */
67
+ type CreditAccountStatus = "active" | "frozen" | "closed";
68
+ /**
69
+ * A customer's credit balance, true at `asOf`. A balance never grants spending authority - only a
70
+ * reservation does. A customer with no credit account yet reads as zeros, `active`, `exhausted`.
71
+ */
72
+ interface CreditBalance {
73
+ /** The customer's external id. */
74
+ customerId: string;
75
+ status: CreditAccountStatus;
76
+ /** Unheld credits of grants that have not expired: what reservations could hold now. */
77
+ spendable: string;
78
+ /** Credits held by open reservations. */
79
+ held: string;
80
+ /** Credits consumed since `periodStart`, net of reversals. */
81
+ consumedThisPeriod: string;
82
+ /** The current included period's start, else the first instant of the current UTC month. */
83
+ periodStart: string;
84
+ /** Unheld credits expiring within the next 7 days, and the earliest of those expiries. */
85
+ expiringSoon: {
86
+ amount: string;
87
+ earliestAt: string | null;
88
+ };
89
+ byBucket: {
90
+ /** Spendable credits per grant kind; they sum to `spendable`. */
91
+ kinds: Record<CreditGrantKind, string>;
92
+ /**
93
+ * Spendable credits per category some grant is limited to, counting the grants that pay for
94
+ * every category too: the figures overlap and need not sum to `spendable`.
95
+ */
96
+ categories: Record<string, string>;
97
+ /** Spendable on a category not listed: the grants that pay for every category. */
98
+ otherCategories: string;
99
+ };
100
+ /** The active included grants (a subscription's period allowance); null when there are none. */
101
+ currentPeriod: {
102
+ granted: string;
103
+ /** Consumed from them, net of reversals. */
104
+ used: string;
105
+ held: string;
106
+ /** Unheld and spendable. */
107
+ remaining: string;
108
+ start: string;
109
+ /** When they expire (the period end); null if one never does. */
110
+ end: string | null;
111
+ } | null;
112
+ thresholds: {
113
+ lowPercent: number;
114
+ criticalPercent: number;
115
+ /** What the percentages apply to: the current period's credits, else the last top-up's. */
116
+ reference: string | null;
117
+ level: CreditThresholdLevel;
118
+ };
119
+ /** The server time the whole read was true at (ISO 8601). */
120
+ asOf: string;
121
+ }
122
+ /** A ledger transaction's type: one per balance change. */
123
+ type CreditTransactionType = "grant" | "hold" | "release" | "consume" | "expire" | "reverse" | "revoke" | "adjust";
124
+ /** One balance change on a customer's credit ledger, with its effect on the account's totals. */
125
+ interface CreditLedgerEntry {
126
+ id: string;
127
+ type: CreditTransactionType;
128
+ /** Why Billow posted it, as a system code (`api_grant`, `grant_expired`, ...); never free text. */
129
+ reason: string | null;
130
+ /** How it moved the account's unheld credits (signed). */
131
+ availableDelta: string;
132
+ /** How it moved the account's held credits (signed). */
133
+ heldDelta: string;
134
+ availableAfter: string;
135
+ heldAfter: string;
136
+ grantId: string | null;
137
+ reservationId: string | null;
138
+ topUpId: string | null;
139
+ /** On a reversal: the consumption (its `consume` transaction) it gives back. */
140
+ consumptionId: string | null;
141
+ /** Your own reason on the resource it belongs to (a grant's or reversal's); cleared on erasure. */
142
+ callerReason: string | null;
143
+ /** The metadata of the resource it belongs to: its reservation, reversal or top-up, else its grant. */
144
+ metadata: Record<string, string> | null;
145
+ createdAt: string;
146
+ }
147
+ /** What `credits.usage.get` totals each row by. */
148
+ type CreditUsageGroupBy = "action" | "category";
149
+ interface CreditUsageParams {
150
+ /** The first UTC day (`YYYY-MM-DD`); defaults to 29 days before `to`. */
151
+ from?: string;
152
+ /** The last UTC day (`YYYY-MM-DD`), included; defaults to today (UTC). At most 92 days in all. */
153
+ to?: string;
154
+ /** A Credit Action (default) or a category. */
155
+ groupBy?: CreditUsageGroupBy;
156
+ }
157
+ /** A customer's credit consumption per UTC day; days with none have no row. */
158
+ interface CreditUsage {
159
+ /** The customer's external id. */
160
+ customerId: string;
161
+ from: string;
162
+ to: string;
163
+ groupBy: CreditUsageGroupBy;
164
+ data: Array<{
165
+ /** The UTC day, `YYYY-MM-DD`. */
166
+ date: string;
167
+ /** The Credit Action, or the category. */
168
+ key: string;
169
+ units: string;
170
+ amount: string;
171
+ }>;
172
+ }
173
+ /** Money: whole minor units of a currency (e.g. piasters), with its ISO-4217 code. */
174
+ interface CreditMoney {
175
+ amount: number;
176
+ currency: string;
177
+ }
178
+ /** A Credit Pack's configuration: a one-time catalog Price sold as credits, plus a bonus. */
179
+ interface CreditPack {
180
+ id: string;
181
+ name: string;
182
+ priceId: string;
183
+ /** The Price's amount and currency as they are now (a top-up keeps what it was bought at). */
184
+ price: CreditMoney;
185
+ /** Microcredits the purchased grant issues. */
186
+ credits: string;
187
+ /** Microcredits the bonus grant issues (a separate `promotional` grant); "0" for no bonus. */
188
+ bonusCredits: string;
189
+ /** How long after a top-up succeeds its bonus expires, in seconds; null = never. */
190
+ bonusExpiresInSeconds: number | null;
191
+ /** Categories the bonus may pay for; null = every category. */
192
+ bonusEligibility: string[] | null;
193
+ /** An archived pack is never sold again. */
194
+ archived: boolean;
195
+ createdAt: string;
196
+ updatedAt: string;
197
+ }
198
+ /**
199
+ * Configure a Credit Pack on a one-time catalog Price that costs something (free credits are
200
+ * promotional grants, never a pack). A pack must issue something.
201
+ */
202
+ interface CreateCreditPackInput {
203
+ /** A `one_time` catalog Price: what the pack costs, and in which currency. */
204
+ priceId: string;
205
+ name: string;
206
+ /** Whole microcredits as a decimal string; may be "0" when the pack is all bonus. */
207
+ credits: string;
208
+ /** Whole microcredits as a decimal string; omit for no bonus. */
209
+ bonusCredits?: string;
210
+ /** Seconds after the top-up succeeds that the bonus expires; omit or null = never. */
211
+ bonusExpiresInSeconds?: number | null;
212
+ /** Categories the bonus may pay for; omit or null = every category. */
213
+ bonusEligibility?: string[] | null;
214
+ }
215
+ /** Edit a Credit Pack: any of its terms, its Price, or `archived`. Top-ups keep their terms. */
216
+ type UpdateCreditPackInput = Partial<CreateCreditPackInput> & {
217
+ archived?: boolean;
218
+ };
219
+ /** A pack a customer can buy, with its derived price per credit and savings. */
220
+ interface CreditPackListItem {
221
+ id: string;
222
+ name: string;
223
+ credits: string;
224
+ bonusCredits: string;
225
+ /** The catalog Price: what `pricePerCredit` and `savingsBps` are measured on. */
226
+ price: CreditMoney;
227
+ /**
228
+ * The tax a top-up of the pack charges (the Price's treatment, else your project's default):
229
+ * added on top when exclusive, already inside `price` when inclusive; 0 when none applies.
230
+ */
231
+ tax: CreditMoney;
232
+ /** What a top-up of the pack charges: `price` plus any exclusive `tax`. For display only. */
233
+ total: CreditMoney;
234
+ /** When the bonus expires after purchase, in seconds; null without a bonus or when it never does. */
235
+ bonusExpiresInSeconds: number | null;
236
+ /** The categories the bonus may pay for; null without a bonus or when it pays for every one. */
237
+ bonusEligibility: string[] | null;
238
+ /**
239
+ * Minor units of `price` per credit (credits plus bonus), rounded half-up to 6 decimal places,
240
+ * as a decimal string - for display only, never used to charge.
241
+ */
242
+ pricePerCredit: string;
243
+ /**
244
+ * Basis points cheaper per credit than the currency's base pack (its highest per-credit price),
245
+ * rounded down; 0 for the base pack itself.
246
+ */
247
+ savingsBps: number;
248
+ }
249
+ /** The packs a customer can buy in one currency, cheapest first. */
250
+ interface CreditPacks {
251
+ currency: string;
252
+ data: CreditPackListItem[];
253
+ }
254
+ /**
255
+ * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
256
+ * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
257
+ * the customer was erased, nothing granted; `binding_mismatch` - the payment did not match the
258
+ * top-up, nothing granted. The last two wait for a refund.
259
+ */
260
+ type CreditTopUpStatus = "pending" | "succeeded" | "failed" | "unfulfilled" | "binding_mismatch";
261
+ /** One purchase of a Credit Pack, as it now stands. */
262
+ interface CreditTopUp {
263
+ id: string;
264
+ /** The customer's external id. */
265
+ customerId: string;
266
+ packId: string;
267
+ status: CreditTopUpStatus;
268
+ /** The terms bought: what success grants. */
269
+ credits: string;
270
+ bonusCredits: string;
271
+ bonusExpiresInSeconds: number | null;
272
+ bonusEligibility: string[] | null;
273
+ /** What the payment collects (the Price plus any exclusive tax), in minor units. */
274
+ amount: number;
275
+ currency: string;
276
+ /** The charge collecting it; null until it exists. */
277
+ chargeId: string | null;
278
+ /** The hosted checkout to send the buyer to, while it can still take the payment. */
279
+ checkoutUrl: string | null;
280
+ purchasedGrantId: string | null;
281
+ bonusGrantId: string | null;
282
+ /** Microcredits refunds and lost chargebacks of the payment have revoked so far. */
283
+ revoked: string;
284
+ /** Of the revoked credits, those already spent and not paid back since. */
285
+ shortfall: string;
286
+ metadata: Record<string, string> | null;
287
+ settledAt: string | null;
288
+ createdAt: string;
289
+ }
290
+ /** Buy a Credit Pack for a customer. */
291
+ interface CreateCreditTopUpInput {
292
+ /** The customer's external id. */
293
+ customerId: string;
294
+ packId: string;
295
+ /** Where the hosted checkout sends the buyer when they are done. */
296
+ redirectionUrl?: string;
297
+ /** At most 20 keys (40 characters) and values (500 characters). Never personal data. */
298
+ metadata?: Record<string, string>;
299
+ }
300
+ /** What `credits.topUps.create` answers: the top-up its idempotency key stands for. */
301
+ interface CreditTopUpRequestResult extends CreditTopUp {
302
+ /**
303
+ * `true` when the idempotency key was already used: this is that request's top-up as it now
304
+ * stands, and nothing new was bought. `false` when this call made it.
305
+ */
306
+ replayed: boolean;
307
+ }
308
+ /** Narrow a customer's top-ups list. */
309
+ interface CreditTopUpListParams {
310
+ limit?: number;
311
+ cursor?: string;
312
+ status?: CreditTopUpStatus;
313
+ }
314
+
315
+ export type { CreditGrantKind as C, UpdateCreditPackInput as U, CreditThresholdLevel as a, CreditGrant as b, CreditTopUp as c, CreateCreditGrantInput as d, CreditGrantRequestResult as e, CreditPacks as f, CreateCreditPackInput as g, CreditPack as h, CreateCreditTopUpInput as i, CreditTopUpRequestResult as j, CreditTopUpListParams as k, CreditBalance as l, CreditLedgerEntry as m, CreditUsageParams as n, CreditUsage as o, CreditAccountStatus as p, CreditMoney as q, CreditPackListItem as r, CreditTopUpStatus as s, CreditTransactionType as t, CreditUsageGroupBy as u };