@stripe/extensibility-sdk 1.0.1 → 1.3.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.
- package/README.md +17 -15
- package/dist/config-values/generate.cjs +1 -1
- package/dist/config-values/generate.d.ts +1 -1
- package/dist/config-values/generate.d.ts.map +1 -1
- package/dist/config-values/generate.js +1 -1
- package/dist/extensibility-sdk-alpha.d.ts +29 -157
- package/dist/extensibility-sdk-beta.d.ts +29 -157
- package/dist/extensibility-sdk-config-values-internal.d.ts +1 -1
- package/dist/extensibility-sdk-extensions-alpha.d.ts +7 -157
- package/dist/extensibility-sdk-extensions-beta.d.ts +7 -157
- package/dist/extensibility-sdk-extensions-billing-bill-discount_calculation-alpha.d.ts +631 -0
- package/dist/extensibility-sdk-extensions-billing-bill-discount_calculation-beta.d.ts +631 -0
- package/dist/extensibility-sdk-extensions-billing-bill-discount_calculation-internal.d.ts +666 -0
- package/dist/extensibility-sdk-extensions-billing-bill-discount_calculation-public.d.ts +631 -0
- package/dist/extensibility-sdk-extensions-billing-customer_balance_application-alpha.d.ts +475 -0
- package/dist/extensibility-sdk-extensions-billing-customer_balance_application-beta.d.ts +475 -0
- package/dist/extensibility-sdk-extensions-billing-customer_balance_application-internal.d.ts +510 -0
- package/dist/extensibility-sdk-extensions-billing-customer_balance_application-public.d.ts +475 -0
- package/dist/extensibility-sdk-extensions-billing-invoice_collection_options-alpha.d.ts +110 -0
- package/dist/extensibility-sdk-extensions-billing-invoice_collection_options-beta.d.ts +110 -0
- package/dist/extensibility-sdk-extensions-billing-invoice_collection_options-internal.d.ts +123 -0
- package/dist/extensibility-sdk-extensions-billing-invoice_collection_options-public.d.ts +110 -0
- package/dist/extensibility-sdk-extensions-billing-prorations-alpha.d.ts +607 -0
- package/dist/extensibility-sdk-extensions-billing-prorations-beta.d.ts +607 -0
- package/dist/extensibility-sdk-extensions-billing-prorations-internal.d.ts +642 -0
- package/dist/extensibility-sdk-extensions-billing-prorations-public.d.ts +607 -0
- package/dist/extensibility-sdk-extensions-billing-recurring_billing_item_handling-alpha.d.ts +735 -0
- package/dist/extensibility-sdk-extensions-billing-recurring_billing_item_handling-beta.d.ts +735 -0
- package/dist/extensibility-sdk-extensions-billing-recurring_billing_item_handling-internal.d.ts +772 -0
- package/dist/extensibility-sdk-extensions-billing-recurring_billing_item_handling-public.d.ts +735 -0
- package/dist/extensibility-sdk-extensions-core-workflows-custom_action-alpha.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-core-workflows-custom_action-beta.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-core-workflows-custom_action-internal.d.ts +140 -0
- package/dist/extensibility-sdk-extensions-core-workflows-custom_action-public.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-extend-workflows-custom_action-alpha.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-extend-workflows-custom_action-beta.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-extend-workflows-custom_action-internal.d.ts +140 -0
- package/dist/extensibility-sdk-extensions-extend-workflows-custom_action-public.d.ts +126 -0
- package/dist/extensibility-sdk-extensions-internal.d.ts +7 -157
- package/dist/extensibility-sdk-extensions-public.d.ts +7 -157
- package/dist/extensibility-sdk-internal-internal.d.ts +2 -2
- package/dist/extensibility-sdk-internal.d.ts +145 -162
- package/dist/extensibility-sdk-public.d.ts +29 -157
- package/dist/extensibility-sdk-stdlib-alpha.d.ts +593 -0
- package/dist/extensibility-sdk-stdlib-beta.d.ts +593 -0
- package/dist/extensibility-sdk-stdlib-internal.d.ts +1096 -0
- package/dist/extensibility-sdk-stdlib-public.d.ts +593 -0
- package/dist/extensions/billing/bill/discount_calculation.cjs +437 -0
- package/dist/extensions/billing/bill/discount_calculation.d.ts +0 -20
- package/dist/extensions/billing/bill/discount_calculation.d.ts.map +1 -1
- package/dist/extensions/billing/bill/discount_calculation.js +430 -0
- package/dist/extensions/billing/customer_balance_application.cjs +297 -0
- package/dist/extensions/billing/customer_balance_application.d.ts +0 -20
- package/dist/extensions/billing/customer_balance_application.d.ts.map +1 -1
- package/dist/extensions/billing/customer_balance_application.js +284 -0
- package/dist/extensions/billing/invoice_collection_options.cjs +166 -0
- package/dist/extensions/billing/invoice_collection_options.d.ts +4 -24
- package/dist/extensions/billing/invoice_collection_options.d.ts.map +1 -1
- package/dist/extensions/billing/invoice_collection_options.js +155 -0
- package/dist/extensions/billing/prorations.cjs +501 -0
- package/dist/extensions/billing/prorations.d.ts +0 -20
- package/dist/extensions/billing/prorations.d.ts.map +1 -1
- package/dist/extensions/billing/prorations.js +492 -0
- package/dist/extensions/billing/recurring_billing_item_handling.cjs +639 -0
- package/dist/extensions/billing/recurring_billing_item_handling.d.ts +0 -30
- package/dist/extensions/billing/recurring_billing_item_handling.d.ts.map +1 -1
- package/dist/extensions/billing/recurring_billing_item_handling.js +632 -0
- package/dist/extensions/core/workflows/custom_action.cjs +124 -0
- package/dist/extensions/core/workflows/custom_action.d.ts +1 -21
- package/dist/extensions/core/workflows/custom_action.d.ts.map +1 -1
- package/dist/extensions/core/workflows/custom_action.js +111 -0
- package/dist/extensions/extend/workflows/custom_action.cjs +124 -0
- package/dist/extensions/extend/workflows/custom_action.d.ts +1 -21
- package/dist/extensions/extend/workflows/custom_action.d.ts.map +1 -1
- package/dist/extensions/extend/workflows/custom_action.js +111 -0
- package/dist/extensions/index.cjs +27 -265
- package/dist/extensions/index.js +27 -265
- package/dist/extensions/registry.d.ts +2 -2
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/index.cjs +452 -2390
- package/dist/index.js +479 -2286
- package/dist/internal.cjs +22 -54
- package/dist/internal.js +22 -54
- package/dist/stdlib/generated.d.ts +1 -1
- package/dist/stdlib/generated.d.ts.map +1 -1
- package/dist/stdlib/index.cjs +2003 -0
- package/dist/stdlib/index.d.ts +2 -2
- package/dist/stdlib/index.d.ts.map +1 -1
- package/dist/stdlib/index.js +1943 -0
- package/dist/stdlib/transform-strategies.d.ts +46 -6
- package/dist/stdlib/transform-strategies.d.ts.map +1 -1
- package/dist/stdlib/types.d.ts +82 -0
- package/dist/stdlib/types.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +65 -1
- package/dist/stdlib/extension-method.d.ts +0 -27
- package/dist/stdlib/extension-method.d.ts.map +0 -1
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { __integerBrand } from '@formspec/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Opaque brand key used as a property key in SDK branded types.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* You do not need to use this directly — it is already embedded in
|
|
8
|
+
* branded values returned by factory functions like {@link (Integer:type)}.from().
|
|
9
|
+
*
|
|
10
|
+
* String-literal const (not `unique symbol`) so that independent
|
|
11
|
+
* declaration rollups (root vs subpath) produce structurally compatible
|
|
12
|
+
* branded types.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
declare const __brand: '__brand';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Unique brand key for the `Decimal` type.
|
|
20
|
+
*
|
|
21
|
+
* Using a dedicated key (rather than the shared `__brand`) lets formspec's
|
|
22
|
+
* structural brand-detection distinguish `Decimal` from other SDK branded
|
|
23
|
+
* types (e.g., `Ref`) that also carry `[__brand]`.
|
|
24
|
+
*
|
|
25
|
+
* String-literal const (not `unique symbol`) so that independent
|
|
26
|
+
* declaration rollups (root vs subpath) produce structurally compatible
|
|
27
|
+
* branded types.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
declare const __decimalBrand: '__decimalBrand';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Distinct brand key for PositiveInteger so an Integer is not assignable to
|
|
35
|
+
* PositiveInteger without going through the guard. PositiveInteger is a
|
|
36
|
+
* subtype of Integer (it carries both brands), so it can be used wherever
|
|
37
|
+
* Integer is expected.
|
|
38
|
+
*
|
|
39
|
+
* String-literal const (not `unique symbol`) so that independent
|
|
40
|
+
* declaration rollups (root vs subpath) produce structurally compatible
|
|
41
|
+
* branded types.
|
|
42
|
+
*
|
|
43
|
+
* For internal use only — may be removed in a future release.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
declare const __positiveIntegerBrand: '__positiveIntegerBrand';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Opaque type-tag key used by SDK scalar types to carry Stripe type metadata.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* You do not need to use this directly — it is already embedded in
|
|
54
|
+
* branded values returned by factory functions like {@link (Integer:type)}.from().
|
|
55
|
+
*
|
|
56
|
+
* String-literal const (not `unique symbol`) so that independent
|
|
57
|
+
* declaration rollups (root vs subpath) produce structurally compatible
|
|
58
|
+
* branded types.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
declare const __stripeType: '__stripeType';
|
|
63
|
+
|
|
64
|
+
/** @public */
|
|
65
|
+
declare type AnyTimeRange = {
|
|
66
|
+
at: Date;
|
|
67
|
+
value: 'oneTime';
|
|
68
|
+
} | {
|
|
69
|
+
endDate: Date;
|
|
70
|
+
startDate: Date;
|
|
71
|
+
value: 'timeRange';
|
|
72
|
+
} | {
|
|
73
|
+
otherValue: string;
|
|
74
|
+
value: 'other';
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Context values threaded into config application at runtime.
|
|
79
|
+
*
|
|
80
|
+
* The platform dispatch layer builds this from the extension context
|
|
81
|
+
* (`_configAppContextFromContext`) and passes it through the config
|
|
82
|
+
* transformer into `_applyConfig`.
|
|
83
|
+
*
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
declare interface _ConfigApplicationContext {
|
|
87
|
+
/** ISO 8601 clock time for Billing test clocks. */
|
|
88
|
+
clockTime?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @public */
|
|
92
|
+
declare interface Context {
|
|
93
|
+
type: string;
|
|
94
|
+
id: string;
|
|
95
|
+
livemode: boolean;
|
|
96
|
+
stripeContext?: string;
|
|
97
|
+
clockTime?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @public */
|
|
101
|
+
declare type Currency = 'aed' | 'afn' | 'all' | 'amd' | 'ang' | 'aoa' | 'apt' | 'arb' | 'ars' | 'aud' | 'avax' | 'awg' | 'azn' | 'bam' | 'bbd' | 'bdt' | 'bgn' | 'bhd' | 'bif' | 'bmd' | 'bnb' | 'bnd' | 'bob' | 'bov' | 'brl' | 'bsd' | 'btc' | 'btn' | 'buidl' | 'bwp' | 'byn' | 'byr' | 'bzd' | 'cad' | 'cdf' | 'celo' | 'che' | 'chf' | 'chw' | 'clf' | 'clp' | 'cny' | 'cop' | 'cou' | 'crc' | 'cuc' | 'cup' | 'cve' | 'czk' | 'dai' | 'djf' | 'dkk' | 'dop' | 'dzd' | 'eek' | 'egp' | 'ern' | 'etb' | 'eth' | 'eur' | 'eurc' | 'fjd' | 'fkp' | 'frxusd' | 'gbp' | 'gel' | 'ghc' | 'ghs' | 'gip' | 'gmd' | 'gnf' | 'gtq' | 'gyd' | 'hkd' | 'hnl' | 'hrk' | 'htg' | 'huf' | 'hype' | 'idr' | 'ils' | 'inr' | 'iqd' | 'irr' | 'isk' | 'jmd' | 'jod' | 'jpy' | 'kes' | 'kgs' | 'khr' | 'kmf' | 'kpw' | 'krw' | 'kwd' | 'kyd' | 'kzt' | 'lak' | 'lbp' | 'lkr' | 'lrd' | 'lsl' | 'ltl' | 'lvl' | 'lyd' | 'lzd' | 'm' | 'mad' | 'mdl' | 'mga' | 'mkd' | 'mmk' | 'mnt' | 'mon' | 'mop' | 'mro' | 'mru' | 'mur' | 'mvr' | 'mwk' | 'mxn' | 'mxv' | 'myr' | 'mzn' | 'nad' | 'ngn' | 'nio' | 'nok' | 'npr' | 'nzd' | 'omr' | 'open_usd' | 'ord' | 'pab' | 'pen' | 'pgk' | 'php' | 'pkr' | 'pln' | 'pol' | 'pyg' | 'pyusd' | 'qar' | 'rd' | 're' | 'ron' | 'rsd' | 'rub' | 'rwf' | 'sar' | 'sbd' | 'scr' | 'sdg' | 'sek' | 'sgd' | 'shp' | 'sle' | 'sll' | 'sol' | 'sos' | 'srd' | 'ssp' | 'std' | 'stn' | 'sui' | 'svc' | 'syp' | 'szl' | 'thb' | 'tjs' | 'tmt' | 'tnd' | 'top' | 'trx' | 'try' | 'ttd' | 'twd' | 'tzs' | 'uah' | 'ugx' | 'usd' | 'usdb' | 'usdc' | 'usdg' | 'usdp' | 'usdsui' | 'usdt' | 'usn' | 'ustb' | 'uyi' | 'uyu' | 'uzs' | 'vef' | 'ves' | 'vnd' | 'vuv' | 'wst' | 'xaf' | 'xcd' | 'xcg' | 'xeur' | 'xlm' | 'xof' | 'xpf' | 'xpl' | 'xusd' | 'yer' | 'zar' | 'zmk' | 'zmw' | 'zwd' | 'zwg' | 'zwl';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Arbitrary-precision decimal type for billing calculations.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* `Decimal` values are created by the {@link (Decimal:variable) | Decimal companion object}
|
|
108
|
+
* and store values as `coefficient × 10^exponent` using `BigInt`. They avoid
|
|
109
|
+
* every common binary floating-point pitfall — `Decimal.from('0.1').add(Decimal.from('0.2'))`
|
|
110
|
+
* is exactly `0.3`.
|
|
111
|
+
*
|
|
112
|
+
* Instances are immutable (frozen) and all arithmetic returns a new
|
|
113
|
+
* `Decimal`. The public type carries two brand symbols so the type system
|
|
114
|
+
* prevents accidental assignment from plain `number`, `string`, or
|
|
115
|
+
* `bigint`.
|
|
116
|
+
*
|
|
117
|
+
* Create values via the companion object:
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { Decimal, RoundDirection } from '@stripe/extensibility-sdk';
|
|
122
|
+
*
|
|
123
|
+
* const price = Decimal.from('19.99');
|
|
124
|
+
* const tax = price.mul(Decimal.from('0.0825'));
|
|
125
|
+
* const total = price.add(tax);
|
|
126
|
+
*
|
|
127
|
+
* console.log(total.toFixed(2, 'half-up')); // "21.64"
|
|
128
|
+
* console.log(JSON.stringify({ total })); // '{"total":"21.639175"}'
|
|
129
|
+
* console.log(total.toFixed(2, 'half-even')); // "21.64"
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
declare interface Decimal {
|
|
135
|
+
/**
|
|
136
|
+
* Nominal brand tag.
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
readonly [__brand]: 'Decimal';
|
|
140
|
+
/** @internal */
|
|
141
|
+
readonly [__decimalBrand]: true;
|
|
142
|
+
/**
|
|
143
|
+
* Stripe type discriminator.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
readonly [__stripeType]: 'decimal';
|
|
147
|
+
/**
|
|
148
|
+
* Return the sum of this value and `other`.
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
add(other: DecimalLike): Decimal;
|
|
152
|
+
/**
|
|
153
|
+
* Return the difference of this value and `other`.
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
sub(other: DecimalLike): Decimal;
|
|
157
|
+
/**
|
|
158
|
+
* Return the product of this value and `other`.
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
mul(other: DecimalLike): Decimal;
|
|
162
|
+
/**
|
|
163
|
+
* Return the quotient of this value divided by `other`.
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
div(other: DecimalLike, precision: number, direction: RoundDirection): Decimal;
|
|
167
|
+
/**
|
|
168
|
+
* Three-way comparison: returns `-1`, `0`, or `1`.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
cmp(other: DecimalLike): -1 | 0 | 1;
|
|
172
|
+
/**
|
|
173
|
+
* Return `true` if this value is numerically equal to `other`.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
eq(other: DecimalLike): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Return `true` if this value is strictly less than `other`.
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
lt(other: DecimalLike): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Return `true` if this value is less than or equal to `other`.
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
lte(other: DecimalLike): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Return `true` if this value is strictly greater than `other`.
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
gt(other: DecimalLike): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Return `true` if this value is greater than or equal to `other`.
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
gte(other: DecimalLike): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Return `true` if this value is exactly zero.
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
201
|
+
isZero(): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Return `true` if this value is strictly less than zero.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
isNegative(): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Return `true` if this value is strictly greater than zero.
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
isPositive(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Return the additive inverse of this value.
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
neg(): Decimal;
|
|
217
|
+
/**
|
|
218
|
+
* Return the absolute value.
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
abs(): Decimal;
|
|
222
|
+
/**
|
|
223
|
+
* Round this value to the specified precision.
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
round(direction: RoundDirection, options: DecimalRoundingOptions | keyof typeof DecimalRoundingPresets): Decimal;
|
|
227
|
+
/**
|
|
228
|
+
* Return the canonical string representation.
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
toString(): string;
|
|
232
|
+
/**
|
|
233
|
+
* Return the JSON-serializable string representation.
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
toJSON(): string;
|
|
237
|
+
/**
|
|
238
|
+
* Convert to a JavaScript `number` (lossy).
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
toNumber(): number;
|
|
242
|
+
/**
|
|
243
|
+
* Format as a fixed-point string with exactly `decimalPlaces` digits.
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
toFixed(decimalPlaces: number, direction: RoundDirection): string;
|
|
247
|
+
/**
|
|
248
|
+
* Convert to an {@link (Integer:type)} by rounding.
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
toInteger(direction: RoundDirection): Integer;
|
|
252
|
+
/**
|
|
253
|
+
* Rejects implicit coercion; explicit `String(d)` and template literals still work.
|
|
254
|
+
* @public
|
|
255
|
+
*/
|
|
256
|
+
[Symbol.toPrimitive](hint: 'default' | 'number' | 'string'): string;
|
|
257
|
+
/**
|
|
258
|
+
* Returns the string representation; invoked by the JavaScript engine as a fallback coercion path.
|
|
259
|
+
* @public
|
|
260
|
+
*/
|
|
261
|
+
valueOf(): string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Companion object for creating `Decimal` instances.
|
|
266
|
+
*
|
|
267
|
+
* @public
|
|
268
|
+
*/
|
|
269
|
+
declare const Decimal: DecimalCompanion;
|
|
270
|
+
|
|
271
|
+
/** @public */
|
|
272
|
+
declare interface DecimalCompanion {
|
|
273
|
+
/** Type guard: narrows `unknown` to `Decimal`. @public */
|
|
274
|
+
is(value: unknown): value is Decimal;
|
|
275
|
+
/** Assertion guard: throws if not a `Decimal`. @public */
|
|
276
|
+
assert(value: unknown): asserts value is Decimal;
|
|
277
|
+
/** Create a Decimal from a {@link DecimalLike} value. @public */
|
|
278
|
+
from(value: DecimalLike): Decimal;
|
|
279
|
+
/** The Decimal value `0`. @public */
|
|
280
|
+
readonly zero: Decimal;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Values that can be coerced to a `Decimal` via `Decimal.from()`.
|
|
285
|
+
*
|
|
286
|
+
* @remarks
|
|
287
|
+
* This union is accepted by `Decimal.from()` and by all arithmetic and
|
|
288
|
+
* comparison methods on `Decimal` instances. Non-Decimal values are
|
|
289
|
+
* coerced via `Decimal.from()` before the operation.
|
|
290
|
+
*
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
declare type DecimalLike = bigint | Decimal | Integer | number | string;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Precision specification for `Decimal.round()`.
|
|
297
|
+
*
|
|
298
|
+
* @remarks
|
|
299
|
+
* Two modes are supported:
|
|
300
|
+
* - `"decimal-places"` — round to a fixed number of digits after the decimal point.
|
|
301
|
+
* - `"significant-figures"` — round to a fixed number of significant digits.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* // Round to 2 decimal places
|
|
306
|
+
* amount.round('half-even', { mode: 'decimal-places', value: 2 });
|
|
307
|
+
*
|
|
308
|
+
* // Round to 4 significant figures
|
|
309
|
+
* amount.round('half-up', { mode: 'significant-figures', value: 4 });
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
declare interface DecimalRoundingOptions {
|
|
315
|
+
/** Whether to count digits from the decimal point (`"decimal-places"`) or from the most significant digit (`"significant-figures"`). */
|
|
316
|
+
mode: 'decimal-places' | 'significant-figures';
|
|
317
|
+
/**
|
|
318
|
+
* The number of digits to retain. Interpreted as decimal places when
|
|
319
|
+
* `mode` is `"decimal-places"`, or as significant figures when `mode`
|
|
320
|
+
* is `"significant-figures"`.
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
value: number;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Built-in rounding presets keyed by semantic name.
|
|
328
|
+
*
|
|
329
|
+
* @remarks
|
|
330
|
+
* Stripe defines the full set of supported preset names accepted by
|
|
331
|
+
* `Decimal.round()`.
|
|
332
|
+
*
|
|
333
|
+
* | Preset | Equivalent DecimalRoundingOptions |
|
|
334
|
+
* | ------------------- | ----------------------------------------------------- |
|
|
335
|
+
* | `"ubb-usage-count"` | `{ mode: "significant-figures", value: 15 }` |
|
|
336
|
+
* | `"v1-api"` | `{ mode: "decimal-places", value: 12 }` |
|
|
337
|
+
*
|
|
338
|
+
* @public
|
|
339
|
+
*/
|
|
340
|
+
declare const DecimalRoundingPresets: Readonly<{
|
|
341
|
+
'ubb-usage-count': Readonly<{
|
|
342
|
+
mode: "significant-figures";
|
|
343
|
+
value: number;
|
|
344
|
+
}>;
|
|
345
|
+
'v1-api': Readonly<{
|
|
346
|
+
mode: "decimal-places";
|
|
347
|
+
value: number;
|
|
348
|
+
}>;
|
|
349
|
+
}>;
|
|
350
|
+
|
|
351
|
+
/** @public */
|
|
352
|
+
export declare namespace DiscountCalculation {
|
|
353
|
+
/** @public */
|
|
354
|
+
export type BillingReason = 'automatic_pending_invoice_item_invoice' | 'manual' | 'quote_accept' | 'subscription_cancel' | 'subscription_create' | 'subscription_cycle' | 'subscription_threshold' | 'subscription_trial_ended' | 'subscription_update' | 'subscription' | 'upcoming';
|
|
355
|
+
/** @public */
|
|
356
|
+
export type PricingTierMode = 'graduated' | 'volume';
|
|
357
|
+
/** @public */
|
|
358
|
+
export type PriceType = 'one_time' | 'recurring';
|
|
359
|
+
/** @public */
|
|
360
|
+
export type PricingScheme = 'per_unit' | 'tiered';
|
|
361
|
+
/** @public */
|
|
362
|
+
export type UsageType = 'licensed' | 'metered';
|
|
363
|
+
/** @public */
|
|
364
|
+
export type RecurringPriceInterval = 'day' | 'month' | 'week' | 'year';
|
|
365
|
+
/**
|
|
366
|
+
* The result of a discount calculation.
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
export interface DiscountResult {
|
|
370
|
+
/** The computed discount to apply. */
|
|
371
|
+
discount: Discount;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* A discount to apply to a discountable item.
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
export interface Discount {
|
|
378
|
+
/** The discount amount to subtract from the discountable item. */
|
|
379
|
+
amount: MonetaryAmount;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* An item eligible for discount calculation, containing its line items and billing context.
|
|
383
|
+
* @public
|
|
384
|
+
*/
|
|
385
|
+
export interface DiscountableItem {
|
|
386
|
+
/** The individual line items that make up the discountable item. */
|
|
387
|
+
lineItems: DiscountableLineItem[];
|
|
388
|
+
/** The total gross amount of the discountable item before any discounts. */
|
|
389
|
+
grossAmount: MonetaryAmount;
|
|
390
|
+
/** The customer associated with the discountable item. */
|
|
391
|
+
customer?: Customer;
|
|
392
|
+
/** The reason this item is being billed. */
|
|
393
|
+
billingReason?: BillingReason;
|
|
394
|
+
/** The subscription associated with the discountable item. */
|
|
395
|
+
subscription?: Subscription;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* The subscription associated with the discountable item.
|
|
399
|
+
* @public
|
|
400
|
+
*/
|
|
401
|
+
export interface Subscription {
|
|
402
|
+
/** The unique identifier of the subscription. */
|
|
403
|
+
id: string;
|
|
404
|
+
/** The Unix timestamp of the billing cycle anchor. */
|
|
405
|
+
billingCycleAnchor?: number;
|
|
406
|
+
/** The structured billing cycle anchor configuration. */
|
|
407
|
+
billingCycleAnchorConfig?: BillingCycleAnchorConfig;
|
|
408
|
+
/** Custom key-value pairs attached to the subscription. */
|
|
409
|
+
metadata: Record<string, string>;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Configuration for the billing cycle anchor, specifying when recurring billing periods start.
|
|
413
|
+
* @public
|
|
414
|
+
*/
|
|
415
|
+
export interface BillingCycleAnchorConfig {
|
|
416
|
+
/** The month component of the billing cycle anchor. */
|
|
417
|
+
month: number;
|
|
418
|
+
/** The day of the month for the billing cycle anchor. */
|
|
419
|
+
dayOfMonth: number;
|
|
420
|
+
/** The hour component of the billing cycle anchor. */
|
|
421
|
+
hour: number;
|
|
422
|
+
/** The minute component of the billing cycle anchor. */
|
|
423
|
+
minute: number;
|
|
424
|
+
/** The second component of the billing cycle anchor. */
|
|
425
|
+
second: number;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* The customer associated with the discountable item.
|
|
429
|
+
* @public
|
|
430
|
+
*/
|
|
431
|
+
export interface Customer {
|
|
432
|
+
/** The unique identifier of the customer. */
|
|
433
|
+
id: string;
|
|
434
|
+
/** Custom key-value pairs attached to the customer. */
|
|
435
|
+
metadata: Record<string, string>;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* A single line item within a discountable item.
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
export interface DiscountableLineItem {
|
|
442
|
+
/** The subtotal amount of this line item. */
|
|
443
|
+
subtotal: MonetaryAmount;
|
|
444
|
+
/** The quantity of this line item. */
|
|
445
|
+
quantity?: Decimal;
|
|
446
|
+
/** The billing period this line item covers. */
|
|
447
|
+
period: AnyTimeRange;
|
|
448
|
+
/** The price information for this line item. */
|
|
449
|
+
price?: Price;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The price associated with a line item.
|
|
453
|
+
* @public
|
|
454
|
+
*/
|
|
455
|
+
export interface Price {
|
|
456
|
+
/** The unique identifier for the price. */
|
|
457
|
+
id: string;
|
|
458
|
+
/** The product this price belongs to. */
|
|
459
|
+
product?: Product;
|
|
460
|
+
/** The recurring pricing configuration, if applicable. */
|
|
461
|
+
recurring?: RecurringPrice;
|
|
462
|
+
/** The billing scheme, either per-unit or tiered. */
|
|
463
|
+
billingScheme?: PricingScheme;
|
|
464
|
+
/** The pricing tiers, applicable for tiered billing schemes. */
|
|
465
|
+
tiers: PriceTier[];
|
|
466
|
+
/** The price type, either one-time or recurring. */
|
|
467
|
+
type?: PriceType;
|
|
468
|
+
/** The tiering mode, either graduated or volume. */
|
|
469
|
+
tiersMode?: PricingTierMode;
|
|
470
|
+
/** Key-value metadata attached to the price. */
|
|
471
|
+
metadata: Record<string, string>;
|
|
472
|
+
/** The unit amount of the price. */
|
|
473
|
+
unitAmount?: Decimal;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* A tier within a tiered pricing structure.
|
|
477
|
+
* @public
|
|
478
|
+
*/
|
|
479
|
+
export interface PriceTier {
|
|
480
|
+
/** The flat fee charged for this tier. */
|
|
481
|
+
flatAmount?: Decimal;
|
|
482
|
+
/** The per-unit price for this tier. */
|
|
483
|
+
unitAmount?: Decimal;
|
|
484
|
+
/** The upper bound of the tier range. */
|
|
485
|
+
upTo?: Decimal;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* The recurring pricing configuration for a price.
|
|
489
|
+
* @public
|
|
490
|
+
*/
|
|
491
|
+
export interface RecurringPrice {
|
|
492
|
+
/** The billing interval for the recurring price. */
|
|
493
|
+
interval: RecurringPriceInterval;
|
|
494
|
+
/** The number of intervals between each billing cycle. */
|
|
495
|
+
intervalCount: number;
|
|
496
|
+
/** The usage type, either licensed or metered. */
|
|
497
|
+
usageType?: UsageType;
|
|
498
|
+
/** The identifier of the meter tracking usage for this price. */
|
|
499
|
+
meter?: string;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The product associated with a price.
|
|
503
|
+
* @public
|
|
504
|
+
*/
|
|
505
|
+
export interface Product {
|
|
506
|
+
/** The unique identifier of the product. */
|
|
507
|
+
id: string;
|
|
508
|
+
/** The name of the product. */
|
|
509
|
+
name: string;
|
|
510
|
+
/** Custom key-value pairs attached to the product. */
|
|
511
|
+
metadata: Record<string, string>;
|
|
512
|
+
}
|
|
513
|
+
/** @internal */
|
|
514
|
+
export function $platformWrapComputeDiscounts(configTransformer?: (wireConfig: unknown, appCtx: _ConfigApplicationContext) => unknown): (cls: new () => { computeDiscounts(...a: unknown[]): unknown }, wireArgs: unknown, wireConfig: unknown, ctx: unknown) => unknown;
|
|
515
|
+
/**
|
|
516
|
+
* Computes discount amounts for a discountable item and returns a discount result.
|
|
517
|
+
* @public
|
|
518
|
+
*/
|
|
519
|
+
export type ComputeDiscountsFunction<Config> = (request: DiscountableItem, config: Config, context: Context) => DiscountResult;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* @example
|
|
524
|
+
* ```ts
|
|
525
|
+
* import type { Billing, Context } from '@stripe/extensibility-sdk';
|
|
526
|
+
*
|
|
527
|
+
* // eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
528
|
+
* interface MyDiscountCalculationConfig {}
|
|
529
|
+
*
|
|
530
|
+
* export default class MyDiscountCalculation implements Billing.Bill
|
|
531
|
+
* .DiscountCalculation<MyDiscountCalculationConfig> {
|
|
532
|
+
* computeDiscounts(
|
|
533
|
+
* request: Billing.Bill.DiscountCalculation.DiscountableItem,
|
|
534
|
+
* _config: MyDiscountCalculationConfig,
|
|
535
|
+
* _context: Context
|
|
536
|
+
* ) {
|
|
537
|
+
* // TODO: implement your discount logic here
|
|
538
|
+
*
|
|
539
|
+
* return {
|
|
540
|
+
* discount: { amount: request.grossAmount },
|
|
541
|
+
* };
|
|
542
|
+
* }
|
|
543
|
+
* }
|
|
544
|
+
*
|
|
545
|
+
* ```
|
|
546
|
+
* @public
|
|
547
|
+
*/
|
|
548
|
+
export declare interface DiscountCalculation<Config> {
|
|
549
|
+
computeDiscounts: DiscountCalculation.ComputeDiscountsFunction<Config>;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** A branded integer — a `number` guaranteed to satisfy `Number.isInteger`. @public */
|
|
553
|
+
declare type Integer = {
|
|
554
|
+
readonly [__integerBrand]: true;
|
|
555
|
+
readonly [__stripeType]: 'int';
|
|
556
|
+
} & number;
|
|
557
|
+
|
|
558
|
+
/** Factory, type guard, and utilities for {@link (Integer:type)} branded values. @public */
|
|
559
|
+
declare const Integer: IntegerCompanion;
|
|
560
|
+
|
|
561
|
+
/** @public */
|
|
562
|
+
declare interface IntegerCompanion {
|
|
563
|
+
/** The Integer value `0`. @public */
|
|
564
|
+
readonly zero: Integer;
|
|
565
|
+
/** Type guard: narrows `unknown` to {@link (Integer:type)}. @public */
|
|
566
|
+
is(value: unknown): value is Integer;
|
|
567
|
+
/** Assertion guard: throws if not an {@link (Integer:type)}. @public */
|
|
568
|
+
assert(value: unknown): asserts value is Integer;
|
|
569
|
+
/** Coerce a value to {@link (Integer:type)} by rounding. @public */
|
|
570
|
+
from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): Integer;
|
|
571
|
+
/** Lossless conversion to `Decimal`. @public */
|
|
572
|
+
toDecimal(value: Integer): Decimal;
|
|
573
|
+
/** Type guard: narrows {@link (Integer:type)} to {@link (PositiveInteger:type)}. @public */
|
|
574
|
+
isPositive(value: Integer): value is PositiveInteger;
|
|
575
|
+
/** Assertion guard: throws if the Integer is negative. @public */
|
|
576
|
+
assertIsPositive(value: Integer): asserts value is PositiveInteger;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Rounding directions for coercing a number to an integer.
|
|
581
|
+
*
|
|
582
|
+
* A focused subset of {@link https://standards.ieee.org/ieee/754/6210/ | IEEE 754-2019} §4.3:
|
|
583
|
+
*
|
|
584
|
+
* | Direction | Behavior | Examples (→ integer) |
|
|
585
|
+
* | -------------- | ---------------------------- | ------------------------------ |
|
|
586
|
+
* | `'ceil'` | Toward +∞ | 1.1→2, -1.1→-1 |
|
|
587
|
+
* | `'floor'` | Toward -∞ | 1.9→1, -1.1→-2 |
|
|
588
|
+
* | `'round-down'` | Toward zero (truncate) | 1.9→1, -1.9→-1 |
|
|
589
|
+
* | `'round-up'` | Away from zero | 1.1→2, -1.1→-2 |
|
|
590
|
+
* | `'half-up'` | Nearest; ties away from zero | 0.5→1, -0.5→-1, 1.4→1 |
|
|
591
|
+
*
|
|
592
|
+
* @public
|
|
593
|
+
*/
|
|
594
|
+
declare type IntegerRoundDirection = 'ceil' | 'floor' | 'half-up' | 'round-down' | 'round-up';
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Represents a monetary value with amount and currency.
|
|
598
|
+
* @format monetary-amount
|
|
599
|
+
* @public
|
|
600
|
+
*/
|
|
601
|
+
declare interface MonetaryAmount {
|
|
602
|
+
/** The numerical value. */
|
|
603
|
+
amount: Decimal;
|
|
604
|
+
/** The currency code. */
|
|
605
|
+
currency: Currency;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* A branded non-negative integer — a `number` guaranteed to be an integer ≥ 0.
|
|
610
|
+
*
|
|
611
|
+
* This is a subtype of {@link (Integer:type)}: every non-negative integer is an
|
|
612
|
+
* integer, so `PositiveInteger` values are assignable to `Integer` contexts.
|
|
613
|
+
* The reverse is not true — an `Integer` cannot be assigned where a
|
|
614
|
+
* `PositiveInteger` is expected without going through the `PositiveInteger.is()`
|
|
615
|
+
* type guard or `PositiveInteger.from()` factory.
|
|
616
|
+
*
|
|
617
|
+
* @remarks
|
|
618
|
+
* Despite the name, this type includes zero (`>= 0`, not `> 0`).
|
|
619
|
+
* The schema-level constraint `@minimum 0` should be added to fields
|
|
620
|
+
* typed as `PositiveInteger` to ensure the non-negativity invariant
|
|
621
|
+
* is enforced at validation time.
|
|
622
|
+
*
|
|
623
|
+
* @public
|
|
624
|
+
*/
|
|
625
|
+
declare type PositiveInteger = {
|
|
626
|
+
readonly [__integerBrand]: true;
|
|
627
|
+
readonly [__positiveIntegerBrand]: true;
|
|
628
|
+
readonly [__stripeType]: 'int';
|
|
629
|
+
} & number;
|
|
630
|
+
|
|
631
|
+
/** Factory, type guard, and utilities for {@link (PositiveInteger:type)} branded values. @public */
|
|
632
|
+
declare const PositiveInteger: PositiveIntegerCompanion;
|
|
633
|
+
|
|
634
|
+
/** @public */
|
|
635
|
+
declare interface PositiveIntegerCompanion {
|
|
636
|
+
/** Type guard: narrows `unknown` to {@link (PositiveInteger:type)}. @public */
|
|
637
|
+
is(value: unknown): value is PositiveInteger;
|
|
638
|
+
/** Assertion guard: throws if not a {@link (PositiveInteger:type)}. @public */
|
|
639
|
+
assert(value: unknown): asserts value is PositiveInteger;
|
|
640
|
+
/** Coerce a value to {@link (PositiveInteger:type)} by rounding. Throws if negative. @public */
|
|
641
|
+
from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): PositiveInteger;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Rounding direction for Decimal operations.
|
|
646
|
+
*
|
|
647
|
+
* @remarks
|
|
648
|
+
* Seven modes corresponding to
|
|
649
|
+
* {@link https://standards.ieee.org/ieee/754/6210/ | IEEE 754-2019} §4.3
|
|
650
|
+
* rounding-direction attributes:
|
|
651
|
+
*
|
|
652
|
+
* | Direction | IEEE 754 name | Behavior | Examples (→ integer) |
|
|
653
|
+
* | -------------- | ----------------------- | --------------------------------- | ------------------------------------- |
|
|
654
|
+
* | `'ceil'` | `roundTowardPositive` | Toward +∞ | 1.1→2, -1.1→-1 |
|
|
655
|
+
* | `'floor'` | `roundTowardNegative` | Toward -∞ | 1.9→1, -1.1→-2 |
|
|
656
|
+
* | `'round-down'` | `roundTowardZero` | Toward zero (truncate) | 1.9→1, -1.9→-1 |
|
|
657
|
+
* | `'round-up'` | — | Away from zero | 1.1→2, -1.1→-2 |
|
|
658
|
+
* | `'half-up'` | `roundTiesToAway` | Nearest; ties away from zero | 0.5→1, -0.5→-1, 1.4→1 |
|
|
659
|
+
* | `'half-down'` | — | Nearest; ties toward zero | 0.5→0, -0.5→0, 1.6→2 |
|
|
660
|
+
* | `'half-even'` | `roundTiesToEven` | Nearest; ties to even (banker's) | 0.5→0, 1.5→2, 2.5→2, 3.5→4 |
|
|
661
|
+
*
|
|
662
|
+
* @public
|
|
663
|
+
*/
|
|
664
|
+
declare type RoundDirection = 'ceil' | 'floor' | 'half-down' | 'half-even' | 'half-up' | 'round-down' | 'round-up';
|
|
665
|
+
|
|
666
|
+
export { }
|