@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
@@ -1,48 +1,70 @@
1
+ /**
2
+ * @deprecated Import from `@stripe/extensibility-sdk` instead.
3
+ * @packageDocumentation
4
+ */
5
+
1
6
  import { __integerBrand } from '@formspec/core';
2
7
 
3
8
  /**
4
- * Opaque brand symbol used as a property key in SDK branded types.
9
+ * Opaque brand key used as a property key in SDK branded types.
5
10
  *
6
11
  * @remarks
7
12
  * You do not need to use this directly — it is already embedded in
8
- * branded values returned by factory functions like {@link (Integer:type)}.create().
9
- * The `unique symbol` key makes the brand non-enumerable and impossible
10
- * to forge without access to this symbol.
13
+ * branded values returned by factory functions like {@link (Integer:type)}.from().
14
+ *
15
+ * String-literal const (not `unique symbol`) so that independent
16
+ * declaration rollups (root vs subpath) produce structurally compatible
17
+ * branded types.
11
18
  *
12
19
  * @public
13
20
  */
14
- export declare const __brand: unique symbol;
21
+ export declare const __brand: '__brand';
15
22
 
16
23
  /**
17
- * Unique brand symbol for the {@link Decimal} type.
24
+ * Unique brand key for the `Decimal` type.
18
25
  *
19
- * Using a dedicated symbol (rather than the shared `__brand`) lets formspec's
26
+ * Using a dedicated key (rather than the shared `__brand`) lets formspec's
20
27
  * structural brand-detection distinguish `Decimal` from other SDK branded
21
- * types (e.g., `Ref`, `StreetAddress`) that also carry `[__brand]`.
28
+ * types (e.g., `Ref`) that also carry `[__brand]`.
29
+ *
30
+ * String-literal const (not `unique symbol`) so that independent
31
+ * declaration rollups (root vs subpath) produce structurally compatible
32
+ * branded types.
22
33
  *
23
34
  * @internal
24
35
  */
25
- declare const __decimalBrand: unique symbol;
36
+ export declare const __decimalBrand: '__decimalBrand';
26
37
 
27
38
  /**
28
- * Distinct brand for PositiveInteger so an Integer is not assignable to
39
+ * Distinct brand key for PositiveInteger so an Integer is not assignable to
29
40
  * PositiveInteger without going through the guard. PositiveInteger is a
30
41
  * subtype of Integer (it carries both brands), so it can be used wherever
31
42
  * Integer is expected.
32
- * @internal
43
+ *
44
+ * String-literal const (not `unique symbol`) so that independent
45
+ * declaration rollups (root vs subpath) produce structurally compatible
46
+ * branded types.
47
+ *
48
+ * For internal use only — may be removed in a future release.
49
+ *
50
+ * @public
33
51
  */
34
- declare const __positiveIntegerBrand: unique symbol;
52
+ export declare const __positiveIntegerBrand: '__positiveIntegerBrand';
35
53
 
36
54
  /**
37
- * Opaque type-tag symbol used by SDK scalar types to carry Stripe type metadata.
55
+ * Opaque type-tag key used by SDK scalar types to carry Stripe type metadata.
38
56
  *
39
57
  * @remarks
40
58
  * You do not need to use this directly — it is already embedded in
41
- * branded values returned by factory functions like {@link (Integer:type)}.create().
59
+ * branded values returned by factory functions like {@link (Integer:type)}.from().
60
+ *
61
+ * String-literal const (not `unique symbol`) so that independent
62
+ * declaration rollups (root vs subpath) produce structurally compatible
63
+ * branded types.
42
64
  *
43
65
  * @public
44
66
  */
45
- export declare const __stripeType: unique symbol;
67
+ export declare const __stripeType: '__stripeType';
46
68
 
47
69
  /**
48
70
  * Apply a strategy to a field array, transforming each field.
@@ -113,7 +135,7 @@ export declare interface _ApplyStrategy {
113
135
  applyOneofField(typeName: string, oneof: _OneofFieldDescriptor, input: Record<string, unknown>, strategy: _ApplyStrategy, result: Record<string, unknown>, excludeWireKeys: Set<string>): void;
114
136
  }
115
137
 
116
- /** The type of the opaque brand symbol used as a property key in SDK branded types. @public */
138
+ /** The type of the opaque brand key used as a property key in SDK branded types. @public */
117
139
  export declare type BrandSymbol = typeof __brand;
118
140
 
119
141
  /**
@@ -213,52 +235,52 @@ export declare interface Decimal {
213
235
  * Return the sum of this value and `other`.
214
236
  * @public
215
237
  */
216
- add(other: Decimal): Decimal;
238
+ add(other: DecimalLike): Decimal;
217
239
  /**
218
240
  * Return the difference of this value and `other`.
219
241
  * @public
220
242
  */
221
- sub(other: Decimal): Decimal;
243
+ sub(other: DecimalLike): Decimal;
222
244
  /**
223
245
  * Return the product of this value and `other`.
224
246
  * @public
225
247
  */
226
- mul(other: Decimal): Decimal;
248
+ mul(other: DecimalLike): Decimal;
227
249
  /**
228
250
  * Return the quotient of this value divided by `other`.
229
251
  * @public
230
252
  */
231
- div(other: Decimal, precision: number, direction: RoundDirection): Decimal;
253
+ div(other: DecimalLike, precision: number, direction: RoundDirection): Decimal;
232
254
  /**
233
255
  * Three-way comparison: returns `-1`, `0`, or `1`.
234
256
  * @public
235
257
  */
236
- cmp(other: Decimal): -1 | 0 | 1;
258
+ cmp(other: DecimalLike): -1 | 0 | 1;
237
259
  /**
238
260
  * Return `true` if this value is numerically equal to `other`.
239
261
  * @public
240
262
  */
241
- eq(other: Decimal): boolean;
263
+ eq(other: DecimalLike): boolean;
242
264
  /**
243
265
  * Return `true` if this value is strictly less than `other`.
244
266
  * @public
245
267
  */
246
- lt(other: Decimal): boolean;
268
+ lt(other: DecimalLike): boolean;
247
269
  /**
248
270
  * Return `true` if this value is less than or equal to `other`.
249
271
  * @public
250
272
  */
251
- lte(other: Decimal): boolean;
273
+ lte(other: DecimalLike): boolean;
252
274
  /**
253
275
  * Return `true` if this value is strictly greater than `other`.
254
276
  * @public
255
277
  */
256
- gt(other: Decimal): boolean;
278
+ gt(other: DecimalLike): boolean;
257
279
  /**
258
280
  * Return `true` if this value is greater than or equal to `other`.
259
281
  * @public
260
282
  */
261
- gte(other: Decimal): boolean;
283
+ gte(other: DecimalLike): boolean;
262
284
  /**
263
285
  * Return `true` if this value is exactly zero.
264
286
  * @public
@@ -309,6 +331,11 @@ export declare interface Decimal {
309
331
  * @public
310
332
  */
311
333
  toFixed(decimalPlaces: number, direction: RoundDirection): string;
334
+ /**
335
+ * Convert to an {@link (Integer:type)} by rounding.
336
+ * @public
337
+ */
338
+ toInteger(direction: RoundDirection): Integer;
312
339
  /**
313
340
  * Rejects implicit coercion; explicit `String(d)` and template literals still work.
314
341
  * @public
@@ -326,10 +353,31 @@ export declare interface Decimal {
326
353
  *
327
354
  * @public
328
355
  */
329
- export declare const Decimal: {
330
- from(value: bigint | number | string): Decimal;
331
- zero: Decimal;
332
- };
356
+ export declare const Decimal: DecimalCompanion;
357
+
358
+ /** @public */
359
+ export declare interface DecimalCompanion {
360
+ /** Type guard: narrows `unknown` to `Decimal`. @public */
361
+ is(value: unknown): value is Decimal;
362
+ /** Assertion guard: throws if not a `Decimal`. @public */
363
+ assert(value: unknown): asserts value is Decimal;
364
+ /** Create a Decimal from a {@link DecimalLike} value. @public */
365
+ from(value: DecimalLike): Decimal;
366
+ /** The Decimal value `0`. @public */
367
+ readonly zero: Decimal;
368
+ }
369
+
370
+ /**
371
+ * Values that can be coerced to a `Decimal` via `Decimal.from()`.
372
+ *
373
+ * @remarks
374
+ * This union is accepted by `Decimal.from()` and by all arithmetic and
375
+ * comparison methods on `Decimal` instances. Non-Decimal values are
376
+ * coerced via `Decimal.from()` before the operation.
377
+ *
378
+ * @public
379
+ */
380
+ export declare type DecimalLike = bigint | Decimal | Integer | number | string;
333
381
 
334
382
  /**
335
383
  * Precision specification for `Decimal.round()`.
@@ -387,6 +435,18 @@ export declare const DecimalRoundingPresets: Readonly<{
387
435
  }>;
388
436
  }>;
389
437
 
438
+ /**
439
+ * Recursively converts a type to a deeply-readonly version.
440
+ *
441
+ * Primitive types (`string`, `number`, `boolean`, `bigint`, `symbol`,
442
+ * `undefined`, `null`) are returned as-is. Arrays become `readonly` arrays
443
+ * of deeply-readonly elements. Object types have each property marked
444
+ * `readonly`, and the type of each property is recursively transformed.
445
+ *
446
+ * @public
447
+ */
448
+ 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;
449
+
390
450
  /**
391
451
  * The IEEE 754 decimal128 coefficient size (34 digits) — the recommended
392
452
  * precision for `Decimal.div()` when full precision is desired.
@@ -469,11 +529,26 @@ export declare type Integer = {
469
529
  readonly [__stripeType]: 'int';
470
530
  } & number;
471
531
 
472
- /** Factory and type guard for {@link (Integer:type)} branded values. @public */
473
- export declare const Integer: {
474
- from: (value: number, rounding: IntegerRoundDirection) => Integer;
475
- is: (value: number) => value is Integer;
476
- };
532
+ /** Factory, type guard, and utilities for {@link (Integer:type)} branded values. @public */
533
+ export declare const Integer: IntegerCompanion;
534
+
535
+ /** @public */
536
+ export declare interface IntegerCompanion {
537
+ /** The Integer value `0`. @public */
538
+ readonly zero: Integer;
539
+ /** Type guard: narrows `unknown` to {@link (Integer:type)}. @public */
540
+ is(value: unknown): value is Integer;
541
+ /** Assertion guard: throws if not an {@link (Integer:type)}. @public */
542
+ assert(value: unknown): asserts value is Integer;
543
+ /** Coerce a value to {@link (Integer:type)} by rounding. @public */
544
+ from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): Integer;
545
+ /** Lossless conversion to `Decimal`. @public */
546
+ toDecimal(value: Integer): Decimal;
547
+ /** Type guard: narrows {@link (Integer:type)} to {@link (PositiveInteger:type)}. @public */
548
+ isPositive(value: Integer): value is PositiveInteger;
549
+ /** Assertion guard: throws if the Integer is negative. @public */
550
+ assertIsPositive(value: Integer): asserts value is PositiveInteger;
551
+ }
477
552
 
478
553
  /**
479
554
  * Rounding directions for coercing a number to an integer.
@@ -492,25 +567,6 @@ export declare const Integer: {
492
567
  */
493
568
  export declare type IntegerRoundDirection = 'ceil' | 'floor' | 'half-up' | 'round-down' | 'round-up';
494
569
 
495
- /**
496
- * Check whether a value is a `Decimal` instance.
497
- *
498
- * @remarks
499
- * Use this instead of `instanceof` — the underlying class is not
500
- * publicly exported, so `instanceof` checks are not available to
501
- * consumers.
502
- *
503
- * @example
504
- * ```ts
505
- * if (isDecimal(value)) {
506
- * value.add(Decimal.from('1')); // value is Decimal
507
- * }
508
- * ```
509
- *
510
- * @public
511
- */
512
- export declare function isDecimal(value: unknown): value is Decimal;
513
-
514
570
  /**
515
571
  * Returns `true` if `value` conforms to the `PromiseLike` contract:
516
572
  * a non-null object or function with a callable `then` method.
@@ -603,11 +659,18 @@ export declare type PositiveInteger = {
603
659
  readonly [__stripeType]: 'int';
604
660
  } & number;
605
661
 
606
- /** Factory and type guard for {@link (PositiveInteger:type)} branded values. @public */
607
- export declare const PositiveInteger: {
608
- from: (value: number, rounding: IntegerRoundDirection) => PositiveInteger;
609
- is: (value: number) => value is PositiveInteger;
610
- };
662
+ /** Factory, type guard, and utilities for {@link (PositiveInteger:type)} branded values. @public */
663
+ export declare const PositiveInteger: PositiveIntegerCompanion;
664
+
665
+ /** @public */
666
+ export declare interface PositiveIntegerCompanion {
667
+ /** Type guard: narrows `unknown` to {@link (PositiveInteger:type)}. @public */
668
+ is(value: unknown): value is PositiveInteger;
669
+ /** Assertion guard: throws if not a {@link (PositiveInteger:type)}. @public */
670
+ assert(value: unknown): asserts value is PositiveInteger;
671
+ /** Coerce a value to {@link (PositiveInteger:type)} by rounding. Throws if negative. @public */
672
+ from(value: Decimal | Integer | number | string, rounding: IntegerRoundDirection): PositiveInteger;
673
+ }
611
674
 
612
675
  /**
613
676
  * Bidirectional enum spec for proto-backed enums. Accepts a single
@@ -686,7 +749,7 @@ export declare const Ref: { create: <T extends { readonly object: string }>(step
686
749
  /**
687
750
  * Wraps a transformer so that a `null` / `undefined` result throws
688
751
  * `WireParseError('Required field is missing')`, which `strategy.applyField`
689
- * will catch and re-throw as WireReadError / WireWriteError with field context.
752
+ * will catch and re-throw as _WireReadError / _WireWriteError with field context.
690
753
  *
691
754
  * The inner transformer runs first, so strategies that backfill absent values
692
755
  * (e.g. clock-aware `translateDateTime`) can satisfy the requirement.
@@ -733,26 +796,30 @@ export declare class _ShapeDescriptor<_S extends _ApplyStrategy = _ApplyStrategy
733
796
  constructor(typeName: string, fields: _FieldDescriptor[], oneofFields?: _OneofFieldDescriptor[]);
734
797
  }
735
798
 
736
- /** A branded string representing a street address. @public */
737
- export declare type StreetAddress = {
738
- readonly [__brand]: 'StreetAddress';
739
- readonly [__stripeType]: 'string';
740
- } & string;
741
-
742
- /** Factory for creating {@link (StreetAddress:type)} branded values. @public */
743
- export declare const StreetAddress: { create: (address: string) => StreetAddress };
744
-
745
- /** The type of the opaque Stripe type-tag symbol used in SDK scalar types. @public */
799
+ /** The type of the opaque Stripe type-tag key used in SDK scalar types. @public */
746
800
  export declare type StripeTypeSymbol = typeof __stripeType;
747
801
 
748
- /** A branded string representing an ISO 8601 datetime. @public */
749
- export declare type Timestamp = {
750
- readonly [__brand]: 'Timestamp';
751
- readonly [__stripeType]: 'string';
752
- } & string;
753
-
754
- /** Factory for creating {@link (Timestamp:type)} branded values. @public */
755
- export declare const Timestamp: { create: (value: string) => Timestamp };
802
+ /**
803
+ * Deep-freezes `value` and returns it typed as {@link DeepReadonly}`<T>`.
804
+ *
805
+ * Use this helper for module-scoped constant objects and arrays to satisfy
806
+ * the `dsl/no-module-scoped-mutable-const` lint rule. Unlike `Object.freeze`,
807
+ * which is shallow, `toConst` recursively freezes all nested objects and arrays.
808
+ *
809
+ * @example
810
+ * ```typescript
811
+ * import { toConst } from '@stripe/extensibility-sdk/stdlib';
812
+ *
813
+ * const DEFAULTS = toConst({ timeout: 30, retries: 3 });
814
+ * // Type: { readonly timeout: 30; readonly retries: 3 }
815
+ *
816
+ * const STATUSES = toConst(['active', 'pending', 'cancelled']);
817
+ * // Type: readonly ["active", "pending", "cancelled"]
818
+ * ```
819
+ *
820
+ * @public
821
+ */
822
+ export declare function toConst<T>(value: T): DeepReadonly<T>;
756
823
 
757
824
  /**
758
825
  * Apply an element transform to each item in an array.
@@ -876,9 +943,9 @@ export declare class _UnionDescriptor<_S extends _ApplyStrategy = _ApplyStrategy
876
943
  * Indicates malformed or unexpected data from the proto infrastructure —
877
944
  * not a bug in the user's code.
878
945
  *
879
- * @public
946
+ * @internal
880
947
  */
881
- export declare class WireReadError extends Error {
948
+ export declare class _WireReadError extends Error {
882
949
  /**
883
950
  * Error class name for `instanceof`-free identification.
884
951
  * @internal
@@ -891,9 +958,9 @@ export declare class WireReadError extends Error {
891
958
  * Indicates that the user's code returned a value that cannot be translated
892
959
  * back to wire format.
893
960
  *
894
- * @public
961
+ * @internal
895
962
  */
896
- export declare class WireWriteError extends Error {
963
+ export declare class _WireWriteError extends Error {
897
964
  /**
898
965
  * Error class name for `instanceof`-free identification.
899
966
  * @internal