@stripe/extensibility-sdk 0.24.1 → 0.26.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 (54) hide show
  1. package/README.md +328 -0
  2. package/dist/config-values/generate.cjs +1 -1
  3. package/dist/config-values/generate.d.ts +2 -0
  4. package/dist/config-values/generate.d.ts.map +1 -1
  5. package/dist/config-values/generate.js +1 -1
  6. package/dist/extensibility-sdk-alpha.d.ts +141 -98
  7. package/dist/extensibility-sdk-beta.d.ts +141 -98
  8. package/dist/extensibility-sdk-extensions-alpha.d.ts +155 -25
  9. package/dist/extensibility-sdk-extensions-beta.d.ts +155 -25
  10. package/dist/extensibility-sdk-extensions-internal.d.ts +160 -26
  11. package/dist/extensibility-sdk-extensions-public.d.ts +155 -25
  12. package/dist/extensibility-sdk-internal-alpha.d.ts +5 -0
  13. package/dist/extensibility-sdk-internal-beta.d.ts +5 -0
  14. package/dist/extensibility-sdk-internal-internal.d.ts +5 -0
  15. package/dist/extensibility-sdk-internal-public.d.ts +5 -0
  16. package/dist/extensibility-sdk-internal.d.ts +144 -82
  17. package/dist/extensibility-sdk-public.d.ts +141 -98
  18. package/dist/extensibility-sdk-stdlib-alpha.d.ts +146 -98
  19. package/dist/extensibility-sdk-stdlib-beta.d.ts +146 -98
  20. package/dist/extensibility-sdk-stdlib-internal.d.ts +149 -82
  21. package/dist/extensibility-sdk-stdlib-public.d.ts +146 -98
  22. package/dist/extensions/billing/bill/discount_calculation.d.ts +5 -3
  23. package/dist/extensions/billing/customer_balance_application.d.ts +3 -1
  24. package/dist/extensions/billing/invoice_collection_setting.d.ts +15 -11
  25. package/dist/extensions/billing/prorations.d.ts +30 -21
  26. package/dist/extensions/billing/recurring_billing_item_handling.d.ts +41 -23
  27. package/dist/extensions/billing/types.d.ts +4 -4
  28. package/dist/extensions/core/workflows/custom_action.d.ts +6 -2
  29. package/dist/extensions/extend/workflows/custom_action.d.ts +6 -2
  30. package/dist/index.cjs +398 -163
  31. package/dist/index.js +395 -158
  32. package/dist/internal.d.ts +4 -0
  33. package/dist/internal.d.ts.map +1 -1
  34. package/dist/stdlib/brand.d.ts +16 -10
  35. package/dist/stdlib/brand.d.ts.map +1 -1
  36. package/dist/stdlib/decimal.d.ts +50 -22
  37. package/dist/stdlib/decimal.d.ts.map +1 -1
  38. package/dist/stdlib/index.cjs +398 -163
  39. package/dist/stdlib/index.d.ts +11 -5
  40. package/dist/stdlib/index.d.ts.map +1 -1
  41. package/dist/stdlib/index.js +395 -158
  42. package/dist/stdlib/refs.d.ts +12 -20
  43. package/dist/stdlib/refs.d.ts.map +1 -1
  44. package/dist/stdlib/scalars.d.ts +51 -36
  45. package/dist/stdlib/scalars.d.ts.map +1 -1
  46. package/dist/stdlib/to-const.d.ts +35 -0
  47. package/dist/stdlib/to-const.d.ts.map +1 -0
  48. package/dist/stdlib/transforms.d.ts +1 -1
  49. package/dist/stdlib/type-utils.d.ts +3 -1
  50. package/dist/stdlib/types.d.ts +11 -11
  51. package/dist/stdlib/types.d.ts.map +1 -1
  52. package/dist/tsconfig.build.tsbuildinfo +1 -1
  53. package/package.json +11 -11
  54. package/dist/api-surface.d.ts.map +0 -1
@@ -12,48 +12,65 @@
12
12
  import { __integerBrand } from '@formspec/core';
13
13
 
14
14
  /**
15
- * Opaque brand symbol used as a property key in SDK branded types.
15
+ * Opaque brand key used as a property key in SDK branded types.
16
16
  *
17
17
  * @remarks
18
18
  * You do not need to use this directly — it is already embedded in
19
- * branded values returned by factory functions like {@link (Integer:type)}.create().
20
- * The `unique symbol` key makes the brand non-enumerable and impossible
21
- * to forge without access to this symbol.
19
+ * branded values returned by factory functions like {@link (Integer:type)}.from().
20
+ *
21
+ * String-literal const (not `unique symbol`) so that independent
22
+ * declaration rollups (root vs subpath) produce structurally compatible
23
+ * branded types.
22
24
  *
23
25
  * @public
24
26
  */
25
- export declare const __brand: unique symbol;
27
+ export declare const __brand: '__brand';
26
28
 
27
29
  /**
28
- * Unique brand symbol for the {@link Decimal} type.
30
+ * Unique brand key for the `Decimal` type.
29
31
  *
30
- * Using a dedicated symbol (rather than the shared `__brand`) lets formspec's
32
+ * Using a dedicated key (rather than the shared `__brand`) lets formspec's
31
33
  * structural brand-detection distinguish `Decimal` from other SDK branded
32
- * types (e.g., `Ref`, `StreetAddress`) that also carry `[__brand]`.
34
+ * types (e.g., `Ref`) that also carry `[__brand]`.
35
+ *
36
+ * String-literal const (not `unique symbol`) so that independent
37
+ * declaration rollups (root vs subpath) produce structurally compatible
38
+ * branded types.
33
39
  *
34
40
  * @internal
35
41
  */
36
- declare const __decimalBrand: unique symbol;
42
+ export declare const __decimalBrand: '__decimalBrand';
37
43
 
38
44
  /**
39
- * Distinct brand for PositiveInteger so an Integer is not assignable to
45
+ * Distinct brand key for PositiveInteger so an Integer is not assignable to
40
46
  * PositiveInteger without going through the guard. PositiveInteger is a
41
47
  * subtype of Integer (it carries both brands), so it can be used wherever
42
48
  * Integer is expected.
43
- * @internal
49
+ *
50
+ * String-literal const (not `unique symbol`) so that independent
51
+ * declaration rollups (root vs subpath) produce structurally compatible
52
+ * branded types.
53
+ *
54
+ * For internal use only — may be removed in a future release.
55
+ *
56
+ * @public
44
57
  */
45
- declare const __positiveIntegerBrand: unique symbol;
58
+ export declare const __positiveIntegerBrand: '__positiveIntegerBrand';
46
59
 
47
60
  /**
48
- * Opaque type-tag symbol used by SDK scalar types to carry Stripe type metadata.
61
+ * Opaque type-tag key used by SDK scalar types to carry Stripe type metadata.
49
62
  *
50
63
  * @remarks
51
64
  * You do not need to use this directly — it is already embedded in
52
- * branded values returned by factory functions like {@link (Integer:type)}.create().
65
+ * branded values returned by factory functions like {@link (Integer:type)}.from().
66
+ *
67
+ * String-literal const (not `unique symbol`) so that independent
68
+ * declaration rollups (root vs subpath) produce structurally compatible
69
+ * branded types.
53
70
  *
54
71
  * @public
55
72
  */
56
- export declare const __stripeType: unique symbol;
73
+ export declare const __stripeType: '__stripeType';
57
74
 
58
75
  /** @public */
59
76
  declare type AnyTimeRange = {
@@ -159,7 +176,7 @@ declare namespace Billing {
159
176
  }
160
177
  export { Billing }
161
178
 
162
- /** The type of the opaque brand symbol used as a property key in SDK branded types. @public */
179
+ /** The type of the opaque brand key used as a property key in SDK branded types. @public */
163
180
  export declare type BrandSymbol = typeof __brand;
164
181
 
165
182
  /**
@@ -625,52 +642,52 @@ export declare interface Decimal {
625
642
  * Return the sum of this value and `other`.
626
643
  * @public
627
644
  */
628
- add(other: Decimal): Decimal;
645
+ add(other: DecimalLike): Decimal;
629
646
  /**
630
647
  * Return the difference of this value and `other`.
631
648
  * @public
632
649
  */
633
- sub(other: Decimal): Decimal;
650
+ sub(other: DecimalLike): Decimal;
634
651
  /**
635
652
  * Return the product of this value and `other`.
636
653
  * @public
637
654
  */
638
- mul(other: Decimal): Decimal;
655
+ mul(other: DecimalLike): Decimal;
639
656
  /**
640
657
  * Return the quotient of this value divided by `other`.
641
658
  * @public
642
659
  */
643
- div(other: Decimal, precision: number, direction: RoundDirection): Decimal;
660
+ div(other: DecimalLike, precision: number, direction: RoundDirection): Decimal;
644
661
  /**
645
662
  * Three-way comparison: returns `-1`, `0`, or `1`.
646
663
  * @public
647
664
  */
648
- cmp(other: Decimal): -1 | 0 | 1;
665
+ cmp(other: DecimalLike): -1 | 0 | 1;
649
666
  /**
650
667
  * Return `true` if this value is numerically equal to `other`.
651
668
  * @public
652
669
  */
653
- eq(other: Decimal): boolean;
670
+ eq(other: DecimalLike): boolean;
654
671
  /**
655
672
  * Return `true` if this value is strictly less than `other`.
656
673
  * @public
657
674
  */
658
- lt(other: Decimal): boolean;
675
+ lt(other: DecimalLike): boolean;
659
676
  /**
660
677
  * Return `true` if this value is less than or equal to `other`.
661
678
  * @public
662
679
  */
663
- lte(other: Decimal): boolean;
680
+ lte(other: DecimalLike): boolean;
664
681
  /**
665
682
  * Return `true` if this value is strictly greater than `other`.
666
683
  * @public
667
684
  */
668
- gt(other: Decimal): boolean;
685
+ gt(other: DecimalLike): boolean;
669
686
  /**
670
687
  * Return `true` if this value is greater than or equal to `other`.
671
688
  * @public
672
689
  */
673
- gte(other: Decimal): boolean;
690
+ gte(other: DecimalLike): boolean;
674
691
  /**
675
692
  * Return `true` if this value is exactly zero.
676
693
  * @public
@@ -721,6 +738,11 @@ export declare interface Decimal {
721
738
  * @public
722
739
  */
723
740
  toFixed(decimalPlaces: number, direction: RoundDirection): string;
741
+ /**
742
+ * Convert to an {@link (Integer:type)} by rounding.
743
+ * @public
744
+ */
745
+ toInteger(direction: RoundDirection): Integer;
724
746
  /**
725
747
  * Rejects implicit coercion; explicit `String(d)` and template literals still work.
726
748
  * @public
@@ -738,10 +760,31 @@ export declare interface Decimal {
738
760
  *
739
761
  * @public
740
762
  */
741
- export declare const Decimal: {
742
- from(value: bigint | number | string): Decimal;
743
- zero: Decimal;
744
- };
763
+ export declare const Decimal: DecimalCompanion;
764
+
765
+ /** @public */
766
+ export declare interface DecimalCompanion {
767
+ /** Type guard: narrows `unknown` to `Decimal`. @public */
768
+ is(value: unknown): value is Decimal;
769
+ /** Assertion guard: throws if not a `Decimal`. @public */
770
+ assert(value: unknown): asserts value is Decimal;
771
+ /** Create a Decimal from a {@link DecimalLike} value. @public */
772
+ from(value: DecimalLike): Decimal;
773
+ /** The Decimal value `0`. @public */
774
+ readonly zero: Decimal;
775
+ }
776
+
777
+ /**
778
+ * Values that can be coerced to a `Decimal` via `Decimal.from()`.
779
+ *
780
+ * @remarks
781
+ * This union is accepted by `Decimal.from()` and by all arithmetic and
782
+ * comparison methods on `Decimal` instances. Non-Decimal values are
783
+ * coerced via `Decimal.from()` before the operation.
784
+ *
785
+ * @public
786
+ */
787
+ export declare type DecimalLike = bigint | Decimal | Integer | number | string;
745
788
 
746
789
  /**
747
790
  * Precision specification for `Decimal.round()`.
@@ -799,6 +842,18 @@ export declare const DecimalRoundingPresets: Readonly<{
799
842
  }>;
800
843
  }>;
801
844
 
845
+ /**
846
+ * Recursively converts a type to a deeply-readonly version.
847
+ *
848
+ * Primitive types (`string`, `number`, `boolean`, `bigint`, `symbol`,
849
+ * `undefined`, `null`) are returned as-is. Arrays become `readonly` arrays
850
+ * of deeply-readonly elements. Object types have each property marked
851
+ * `readonly`, and the type of each property is recursively transformed.
852
+ *
853
+ * @public
854
+ */
855
+ export declare type DeepReadonly<T> = T extends bigint | boolean | null | number | string | symbol | undefined ? T : T extends readonly (infer Item)[] ? readonly DeepReadonly<Item>[] : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
856
+
802
857
  /**
803
858
  * The IEEE 754 decimal128 coefficient size (34 digits) — the recommended
804
859
  * precision for `Decimal.div()` when full precision is desired.
@@ -1109,11 +1164,26 @@ export declare type Integer = {
1109
1164
  readonly [__stripeType]: 'int';
1110
1165
  } & number;
1111
1166
 
1112
- /** Factory and type guard for {@link (Integer:type)} branded values. @public */
1113
- export declare const Integer: {
1114
- from: (value: number, rounding: IntegerRoundDirection) => Integer;
1115
- is: (value: number) => value is Integer;
1116
- };
1167
+ /** Factory, type guard, and utilities for {@link (Integer:type)} branded values. @public */
1168
+ export declare const Integer: IntegerCompanion;
1169
+
1170
+ /** @public */
1171
+ export declare interface IntegerCompanion {
1172
+ /** The Integer value `0`. @public */
1173
+ readonly zero: Integer;
1174
+ /** Type guard: narrows `unknown` to {@link (Integer:type)}. @public */
1175
+ is(value: unknown): value is Integer;
1176
+ /** Assertion guard: throws if not an {@link (Integer:type)}. @public */
1177
+ assert(value: unknown): asserts value is Integer;
1178
+ /** Coerce a value to {@link (Integer:type)} by rounding. @public */
1179
+ from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): Integer;
1180
+ /** Lossless conversion to `Decimal`. @public */
1181
+ toDecimal(value: Integer): Decimal;
1182
+ /** Type guard: narrows {@link (Integer:type)} to {@link (PositiveInteger:type)}. @public */
1183
+ isPositive(value: Integer): value is PositiveInteger;
1184
+ /** Assertion guard: throws if the Integer is negative. @public */
1185
+ assertIsPositive(value: Integer): asserts value is PositiveInteger;
1186
+ }
1117
1187
 
1118
1188
  /**
1119
1189
  * Rounding directions for coercing a number to an integer.
@@ -1244,25 +1314,6 @@ declare interface InvoiceCollectionSetting<Config> {
1244
1314
  collectionOverride: InvoiceCollectionSetting.CollectionOverrideFunction<Config>;
1245
1315
  }
1246
1316
 
1247
- /**
1248
- * Check whether a value is a `Decimal` instance.
1249
- *
1250
- * @remarks
1251
- * Use this instead of `instanceof` — the underlying class is not
1252
- * publicly exported, so `instanceof` checks are not available to
1253
- * consumers.
1254
- *
1255
- * @example
1256
- * ```ts
1257
- * if (isDecimal(value)) {
1258
- * value.add(Decimal.from('1')); // value is Decimal
1259
- * }
1260
- * ```
1261
- *
1262
- * @public
1263
- */
1264
- export declare function isDecimal(value: unknown): value is Decimal;
1265
-
1266
1317
  /**
1267
1318
  * Returns `true` if `value` conforms to the `PromiseLike` contract:
1268
1319
  * a non-null object or function with a callable `then` method.
@@ -1374,11 +1425,18 @@ export declare type PositiveInteger = {
1374
1425
  readonly [__stripeType]: 'int';
1375
1426
  } & number;
1376
1427
 
1377
- /** Factory and type guard for {@link (PositiveInteger:type)} branded values. @public */
1378
- export declare const PositiveInteger: {
1379
- from: (value: number, rounding: IntegerRoundDirection) => PositiveInteger;
1380
- is: (value: number) => value is PositiveInteger;
1381
- };
1428
+ /** Factory, type guard, and utilities for {@link (PositiveInteger:type)} branded values. @public */
1429
+ export declare const PositiveInteger: PositiveIntegerCompanion;
1430
+
1431
+ /** @public */
1432
+ export declare interface PositiveIntegerCompanion {
1433
+ /** Type guard: narrows `unknown` to {@link (PositiveInteger:type)}. @public */
1434
+ is(value: unknown): value is PositiveInteger;
1435
+ /** Assertion guard: throws if not a {@link (PositiveInteger:type)}. @public */
1436
+ assert(value: unknown): asserts value is PositiveInteger;
1437
+ /** Coerce a value to {@link (PositiveInteger:type)} by rounding. Throws if negative. @public */
1438
+ from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): PositiveInteger;
1439
+ }
1382
1440
 
1383
1441
  /** @public */
1384
1442
  declare namespace Prorations {
@@ -1974,7 +2032,7 @@ export declare const Ref: { create: <T extends { readonly object: string }>(step
1974
2032
  /**
1975
2033
  * Wraps a transformer so that a `null` / `undefined` result throws
1976
2034
  * `WireParseError('Required field is missing')`, which `strategy.applyField`
1977
- * will catch and re-throw as WireReadError / WireWriteError with field context.
2035
+ * will catch and re-throw as _WireReadError / _WireWriteError with field context.
1978
2036
  *
1979
2037
  * The inner transformer runs first, so strategies that backfill absent values
1980
2038
  * (e.g. clock-aware `translateDateTime`) can satisfy the requirement.
@@ -2021,16 +2079,7 @@ export declare class _ShapeDescriptor<_S extends _ApplyStrategy = _ApplyStrategy
2021
2079
  constructor(typeName: string, fields: _FieldDescriptor[], oneofFields?: _OneofFieldDescriptor[]);
2022
2080
  }
2023
2081
 
2024
- /** A branded string representing a street address. @public */
2025
- export declare type StreetAddress = {
2026
- readonly [__brand]: 'StreetAddress';
2027
- readonly [__stripeType]: 'string';
2028
- } & string;
2029
-
2030
- /** Factory for creating {@link (StreetAddress:type)} branded values. @public */
2031
- export declare const StreetAddress: { create: (address: string) => StreetAddress };
2032
-
2033
- /** The type of the opaque Stripe type-tag symbol used in SDK scalar types. @public */
2082
+ /** The type of the opaque Stripe type-tag key used in SDK scalar types. @public */
2034
2083
  export declare type StripeTypeSymbol = typeof __stripeType;
2035
2084
 
2036
2085
  /**
@@ -2044,14 +2093,27 @@ declare interface TimeRange {
2044
2093
  endDate: Date;
2045
2094
  }
2046
2095
 
2047
- /** A branded string representing an ISO 8601 datetime. @public */
2048
- export declare type Timestamp = {
2049
- readonly [__brand]: 'Timestamp';
2050
- readonly [__stripeType]: 'string';
2051
- } & string;
2052
-
2053
- /** Factory for creating {@link (Timestamp:type)} branded values. @public */
2054
- export declare const Timestamp: { create: (value: string) => Timestamp };
2096
+ /**
2097
+ * Deep-freezes `value` and returns it typed as {@link DeepReadonly}`<T>`.
2098
+ *
2099
+ * Use this helper for module-scoped constant objects and arrays to satisfy
2100
+ * the `dsl/no-module-scoped-mutable-const` lint rule. Unlike `Object.freeze`,
2101
+ * which is shallow, `toConst` recursively freezes all nested objects and arrays.
2102
+ *
2103
+ * @example
2104
+ * ```typescript
2105
+ * import { toConst } from '@stripe/extensibility-sdk/stdlib';
2106
+ *
2107
+ * const DEFAULTS = toConst({ timeout: 30, retries: 3 });
2108
+ * // Type: { readonly timeout: 30; readonly retries: 3 }
2109
+ *
2110
+ * const STATUSES = toConst(['active', 'pending', 'cancelled']);
2111
+ * // Type: readonly ["active", "pending", "cancelled"]
2112
+ * ```
2113
+ *
2114
+ * @public
2115
+ */
2116
+ export declare function toConst<T>(value: T): DeepReadonly<T>;
2055
2117
 
2056
2118
  /**
2057
2119
  * Apply an element transform to each item in an array.
@@ -2175,9 +2237,9 @@ export declare class _UnionDescriptor<_S extends _ApplyStrategy = _ApplyStrategy
2175
2237
  * Indicates malformed or unexpected data from the proto infrastructure —
2176
2238
  * not a bug in the user's code.
2177
2239
  *
2178
- * @public
2240
+ * @internal
2179
2241
  */
2180
- export declare class WireReadError extends Error {
2242
+ export declare class _WireReadError extends Error {
2181
2243
  /**
2182
2244
  * Error class name for `instanceof`-free identification.
2183
2245
  * @internal
@@ -2190,9 +2252,9 @@ export declare class WireReadError extends Error {
2190
2252
  * Indicates that the user's code returned a value that cannot be translated
2191
2253
  * back to wire format.
2192
2254
  *
2193
- * @public
2255
+ * @internal
2194
2256
  */
2195
- export declare class WireWriteError extends Error {
2257
+ export declare class _WireWriteError extends Error {
2196
2258
  /**
2197
2259
  * Error class name for `instanceof`-free identification.
2198
2260
  * @internal