@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
package/dist/index.cjs CHANGED
@@ -29,10 +29,6 @@ __export(src_exports, {
29
29
  Integer: () => Integer,
30
30
  PositiveInteger: () => PositiveInteger,
31
31
  Ref: () => Ref,
32
- StreetAddress: () => StreetAddress,
33
- Timestamp: () => Timestamp,
34
- WireReadError: () => WireReadError,
35
- WireWriteError: () => WireWriteError,
36
32
  _ConfigEnum: () => _ConfigEnum,
37
33
  _JsonWireToType: () => _JsonWireToType,
38
34
  _ProtoEnum: () => _ProtoEnum,
@@ -40,6 +36,8 @@ __export(src_exports, {
40
36
  _ShapeDescriptor: () => _ShapeDescriptor,
41
37
  _TypeToProtoWire: () => _TypeToProtoWire,
42
38
  _UnionDescriptor: () => _UnionDescriptor,
39
+ _WireReadError: () => _WireReadError,
40
+ _WireWriteError: () => _WireWriteError,
43
41
  _apply: () => _apply,
44
42
  _applyConfig: () => _applyConfig,
45
43
  _applyIncoming: () => _applyIncoming,
@@ -55,123 +53,12 @@ __export(src_exports, {
55
53
  _translateMap: () => _translateMap,
56
54
  _translateShape: () => _translateShape,
57
55
  _translateUnion: () => _translateUnion,
58
- isDecimal: () => isDecimal
56
+ toConst: () => toConst
59
57
  });
60
58
  module.exports = __toCommonJS(src_exports);
61
59
 
62
60
  // src/stdlib/scalars.ts
63
61
  var import_core = require("@formspec/core");
64
- function roundToInteger(value, direction) {
65
- switch (direction) {
66
- case "ceil":
67
- return Math.ceil(value);
68
- case "floor":
69
- return Math.floor(value);
70
- case "round-down":
71
- return Math.trunc(value);
72
- case "round-up":
73
- return value >= 0 ? Math.ceil(value) : Math.floor(value);
74
- case "half-up":
75
- return value >= 0 ? Math.floor(value + 0.5) : Math.ceil(value - 0.5);
76
- default: {
77
- const _exhaustive = direction;
78
- throw new Error(`Unknown rounding direction: ${String(_exhaustive)}`);
79
- }
80
- }
81
- }
82
- var Integer = {
83
- /**
84
- * Type guard that narrows a `number` to {@link (Integer:type)}.
85
- *
86
- * @example
87
- * ```ts
88
- * const n: number = getCount();
89
- * if (Integer.is(n)) {
90
- * // n is Integer here
91
- * config.retryCount = n;
92
- * }
93
- * ```
94
- * @public
95
- */
96
- is: (value) => Number.isInteger(value),
97
- /**
98
- * Coerces a number to an {@link (Integer:type)} by rounding.
99
- * Throws if the value is not finite.
100
- *
101
- * @example
102
- * ```ts
103
- * const price = 9.99;
104
- * const rounded = Integer.from(price, 'floor'); // 9
105
- * const ceiled = Integer.from(price, 'ceil'); // 10
106
- * ```
107
- * @public
108
- */
109
- from: (value, rounding) => {
110
- if (!Number.isFinite(value)) {
111
- throw new Error(`Cannot round non-finite value ${String(value)} to an integer`);
112
- }
113
- return roundToInteger(value, rounding);
114
- }
115
- };
116
- var PositiveInteger = {
117
- /**
118
- * Type guard that narrows a `number` to {@link (PositiveInteger:type)}.
119
- *
120
- * @example
121
- * ```ts
122
- * const n: number = getRetryCount();
123
- * if (PositiveInteger.is(n)) {
124
- * // n is PositiveInteger here
125
- * config.maxRetries = n;
126
- * }
127
- * ```
128
- * @public
129
- */
130
- is: (value) => Number.isInteger(value) && value >= 0,
131
- /**
132
- * Coerces a number to a {@link (PositiveInteger:type)} by rounding.
133
- * Throws if the value is not finite or the rounded result is negative.
134
- *
135
- * @example
136
- * ```ts
137
- * const ratio = 2.7;
138
- * const count = PositiveInteger.from(ratio, 'floor'); // 2
139
- * ```
140
- * @public
141
- */
142
- from: (value, rounding) => {
143
- if (!Number.isFinite(value)) {
144
- throw new Error(`Cannot round non-finite value ${String(value)} to an integer`);
145
- }
146
- const rounded = roundToInteger(value, rounding) || 0;
147
- if (rounded < 0) {
148
- throw new Error(
149
- `Value ${String(value)} rounds to ${String(rounded)}, which is negative`
150
- );
151
- }
152
- return rounded;
153
- }
154
- };
155
- var StreetAddress = {
156
- create: (address) => {
157
- return address;
158
- }
159
- };
160
- var Timestamp = {
161
- create: (value) => {
162
- return value;
163
- }
164
- };
165
-
166
- // src/stdlib/refs.ts
167
- var Ref = {
168
- create: (step) => {
169
- return {
170
- type: step.object,
171
- id: step.id
172
- };
173
- }
174
- };
175
62
 
176
63
  // src/stdlib/decimal.ts
177
64
  var PLAIN_NOTATION_DIGIT_LIMIT = 30;
@@ -188,6 +75,9 @@ var DecimalRoundingPresets = Object.freeze({
188
75
  var DEFAULT_DIV_PRECISION = 34;
189
76
  var IMPLICIT_DECIMAL_COERCION_ERROR = "Implicit Decimal coercion is not allowed; use .add(), .sub(), .mul(), .div(), .toString(), or .toNumber() explicitly.";
190
77
  var MAX_EXPONENT = Number.MAX_SAFE_INTEGER;
78
+ function normalizeZero(value) {
79
+ return Object.is(value, -0) ? 0 : value;
80
+ }
191
81
  var DECIMAL_BRAND = /* @__PURE__ */ Symbol.for(
192
82
  "stripe.apps-extensibility-sdk.Decimal"
193
83
  );
@@ -301,13 +191,13 @@ var DecimalImpl = class _DecimalImpl {
301
191
  /**
302
192
  * Return the sum of this value and `other`.
303
193
  *
304
- * @param other - The addend.
194
+ * @param other - The addend. Accepts any {@link DecimalLike} value.
305
195
  * @returns A new {@link Decimal} equal to `this + other`.
306
196
  *
307
197
  * @public
308
198
  */
309
199
  add(other) {
310
- const otherImpl = toImpl(other);
200
+ const otherImpl = coerceToImpl(other);
311
201
  if (this.#exponent === otherImpl.#exponent) {
312
202
  return toDecimal(
313
203
  new _DecimalImpl(this.#coefficient + otherImpl.#coefficient, this.#exponent)
@@ -334,13 +224,13 @@ var DecimalImpl = class _DecimalImpl {
334
224
  /**
335
225
  * Return the difference of this value and `other`.
336
226
  *
337
- * @param other - The subtrahend.
227
+ * @param other - The subtrahend. Accepts any {@link DecimalLike} value.
338
228
  * @returns A new {@link Decimal} equal to `this - other`.
339
229
  *
340
230
  * @public
341
231
  */
342
232
  sub(other) {
343
- const otherImpl = toImpl(other);
233
+ const otherImpl = coerceToImpl(other);
344
234
  if (this.#exponent === otherImpl.#exponent) {
345
235
  return toDecimal(
346
236
  new _DecimalImpl(this.#coefficient - otherImpl.#coefficient, this.#exponent)
@@ -367,13 +257,13 @@ var DecimalImpl = class _DecimalImpl {
367
257
  /**
368
258
  * Return the product of this value and `other`.
369
259
  *
370
- * @param other - The multiplicand.
260
+ * @param other - The multiplicand. Accepts any {@link DecimalLike} value.
371
261
  * @returns A new {@link Decimal} equal to `this × other`.
372
262
  *
373
263
  * @public
374
264
  */
375
265
  mul(other) {
376
- const otherImpl = toImpl(other);
266
+ const otherImpl = coerceToImpl(other);
377
267
  return toDecimal(
378
268
  new _DecimalImpl(
379
269
  this.#coefficient * otherImpl.#coefficient,
@@ -400,7 +290,7 @@ var DecimalImpl = class _DecimalImpl {
400
290
  * Decimal.from('5').div(Decimal.from('2'), 0, 'half-even'); // "2"
401
291
  * ```
402
292
  *
403
- * @param other - The divisor. Must not be zero.
293
+ * @param other - The divisor. Must not be zero. Accepts any {@link DecimalLike} value.
404
294
  * @param precision - Maximum number of decimal digits in the result.
405
295
  * @param direction - How to round when the exact quotient cannot
406
296
  * be represented at the requested precision.
@@ -415,7 +305,7 @@ var DecimalImpl = class _DecimalImpl {
415
305
  if (precision < 0 || !Number.isInteger(precision)) {
416
306
  throw new Error("precision must be a non-negative integer");
417
307
  }
418
- const otherImpl = toImpl(other);
308
+ const otherImpl = coerceToImpl(other);
419
309
  if (otherImpl.#coefficient === 0n) {
420
310
  throw new Error("Division by zero");
421
311
  }
@@ -457,13 +347,13 @@ var DecimalImpl = class _DecimalImpl {
457
347
  * a.cmp(a); // 0
458
348
  * ```
459
349
  *
460
- * @param other - The value to compare against.
350
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
461
351
  * @returns `-1` if `this < other`, `0` if equal, `1` if `this > other`.
462
352
  *
463
353
  * @public
464
354
  */
465
355
  cmp(other) {
466
- const otherImpl = toImpl(other);
356
+ const otherImpl = coerceToImpl(other);
467
357
  if (this.#exponent === otherImpl.#exponent) {
468
358
  if (this.#coefficient < otherImpl.#coefficient) return -1;
469
359
  if (this.#coefficient > otherImpl.#coefficient) return 1;
@@ -486,7 +376,7 @@ var DecimalImpl = class _DecimalImpl {
486
376
  /**
487
377
  * Return `true` if this value is numerically equal to `other`.
488
378
  *
489
- * @param other - The value to compare against.
379
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
490
380
  * @returns `true` if `this === other` in value, `false` otherwise.
491
381
  *
492
382
  * @public
@@ -497,7 +387,7 @@ var DecimalImpl = class _DecimalImpl {
497
387
  /**
498
388
  * Return `true` if this value is strictly less than `other`.
499
389
  *
500
- * @param other - The value to compare against.
390
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
501
391
  * @returns `true` if `this < other`, `false` otherwise.
502
392
  *
503
393
  * @public
@@ -508,7 +398,7 @@ var DecimalImpl = class _DecimalImpl {
508
398
  /**
509
399
  * Return `true` if this value is less than or equal to `other`.
510
400
  *
511
- * @param other - The value to compare against.
401
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
512
402
  * @returns `true` if `this ≤ other`, `false` otherwise.
513
403
  *
514
404
  * @public
@@ -519,7 +409,7 @@ var DecimalImpl = class _DecimalImpl {
519
409
  /**
520
410
  * Return `true` if this value is strictly greater than `other`.
521
411
  *
522
- * @param other - The value to compare against.
412
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
523
413
  * @returns `true` if `this > other`, `false` otherwise.
524
414
  *
525
415
  * @public
@@ -530,7 +420,7 @@ var DecimalImpl = class _DecimalImpl {
530
420
  /**
531
421
  * Return `true` if this value is greater than or equal to `other`.
532
422
  *
533
- * @param other - The value to compare against.
423
+ * @param other - The value to compare against. Accepts any {@link DecimalLike} value.
534
424
  * @returns `true` if `this ≥ other`, `false` otherwise.
535
425
  *
536
426
  * @public
@@ -829,6 +719,38 @@ var DecimalImpl = class _DecimalImpl {
829
719
  return formatFixed(scaled);
830
720
  }
831
721
  }
722
+ /**
723
+ * Convert this value to an {@link (Integer:type)} by rounding.
724
+ *
725
+ * @remarks
726
+ * The rounding direction is always required — no invisible defaults
727
+ * in financial code.
728
+ *
729
+ * @example
730
+ * ```ts
731
+ * Decimal.from('2.7').toInteger('floor'); // 2
732
+ * Decimal.from('2.5').toInteger('half-up'); // 3
733
+ * Decimal.from('2.5').toInteger('half-even'); // 2
734
+ * ```
735
+ *
736
+ * @param direction - How to round when the value is not a whole number.
737
+ * @returns A branded {@link (Integer:type)} value.
738
+ * @throws Error if the rounded value is too large to represent as
739
+ * a JavaScript `number`.
740
+ *
741
+ * @public
742
+ */
743
+ toInteger(direction) {
744
+ const fixed = this.toFixed(0, direction);
745
+ const num = Number(fixed);
746
+ if (!Number.isFinite(num) || !Number.isSafeInteger(num)) {
747
+ throw new Error(
748
+ `Decimal value ${fixed} cannot be exactly represented as a JavaScript integer`
749
+ );
750
+ }
751
+ const normalized = normalizeZero(num);
752
+ return normalized;
753
+ }
832
754
  /**
833
755
  * Reject implicit arithmetic-style coercion while preserving explicit
834
756
  * stringification.
@@ -869,23 +791,59 @@ var DecimalImpl = class _DecimalImpl {
869
791
  function toImpl(d) {
870
792
  return d;
871
793
  }
794
+ function coerceToImpl(value) {
795
+ if (isDecimal(value)) {
796
+ return toImpl(value);
797
+ }
798
+ return toImpl(Decimal.from(value));
799
+ }
872
800
  function toDecimal(impl) {
873
801
  return impl;
874
802
  }
875
803
  function isDecimal(value) {
876
- return typeof value === "object" && value !== null && DECIMAL_BRAND in value;
804
+ return typeof value === "object" && value !== null && DECIMAL_BRAND in value && // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- symbol key access requires cast
805
+ value[DECIMAL_BRAND] === true;
806
+ }
807
+ function assertIsDecimal(value) {
808
+ if (!isDecimal(value)) {
809
+ throw new Error(`Expected a Decimal, got ${typeof value}`);
810
+ }
877
811
  }
878
812
  var Decimal = {
879
813
  /**
880
- * Create a `Decimal` from a string, number, or bigint.
814
+ * Type guard that narrows an unknown value to {@link (Decimal:type)}.
815
+ *
816
+ * @example
817
+ * ```ts
818
+ * if (Decimal.is(value)) {
819
+ * value.add(1); // value is Decimal
820
+ * }
821
+ * ```
822
+ * @public
823
+ */
824
+ is: isDecimal,
825
+ /**
826
+ * Assertion guard that throws if the value is not a {@link (Decimal:type)}.
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * Decimal.assert(value);
831
+ * value.add(1); // value is Decimal
832
+ * ```
833
+ * @public
834
+ */
835
+ assert: assertIsDecimal,
836
+ /**
837
+ * Create a `Decimal` from a string, number, bigint, Integer, or Decimal.
881
838
  *
882
839
  * @remarks
840
+ * - **Decimal**: returned as-is (immutable passthrough).
883
841
  * - **string**: Parsed as a decimal literal. Accepts an optional sign,
884
842
  * integer digits, an optional fractional part, and an optional `e`/`E`
885
843
  * exponent. Leading/trailing whitespace is trimmed.
886
- * - **number**: Must be finite. Converted via `Number.prototype.toString()`
887
- * then parsed, so `Decimal.from(0.1)` produces `"0.1"` (not the
888
- * 53-bit binary approximation).
844
+ * - **number** (including Integer): Must be finite. Converted via
845
+ * `Number.prototype.toString()` then parsed, so `Decimal.from(0.1)`
846
+ * produces `"0.1"` (not the 53-bit binary approximation).
889
847
  * - **bigint**: Treated as an integer with exponent 0.
890
848
  *
891
849
  * @example
@@ -894,16 +852,21 @@ var Decimal = {
894
852
  * Decimal.from(42); // number
895
853
  * Decimal.from(100n); // bigint
896
854
  * Decimal.from('1.5e3'); // scientific notation → 1500
855
+ * Decimal.from(d); // Decimal passthrough
897
856
  * ```
898
857
  *
899
858
  * @param value - The value to convert.
900
- * @returns A new frozen `Decimal` instance.
859
+ * @returns A new frozen `Decimal` instance (or the same instance if
860
+ * already a Decimal).
901
861
  * @throws Error if `value` is a non-finite number, an empty
902
862
  * string, or a string that does not match the decimal literal grammar.
903
863
  *
904
864
  * @public
905
865
  */
906
866
  from(value) {
867
+ if (isDecimal(value)) {
868
+ return value;
869
+ }
907
870
  if (typeof value === "bigint") {
908
871
  return toDecimal(new DecimalImpl(value, 0));
909
872
  }
@@ -952,20 +915,277 @@ var Decimal = {
952
915
  zero: toDecimal(new DecimalImpl(0n, 0))
953
916
  };
954
917
 
918
+ // src/stdlib/scalars.ts
919
+ function roundToInteger(value, direction) {
920
+ switch (direction) {
921
+ case "ceil":
922
+ return Math.ceil(value);
923
+ case "floor":
924
+ return Math.floor(value);
925
+ case "round-down":
926
+ return Math.trunc(value);
927
+ case "round-up":
928
+ return value >= 0 ? Math.ceil(value) : Math.floor(value);
929
+ case "half-up":
930
+ return value >= 0 ? Math.floor(value + 0.5) : Math.ceil(value - 0.5);
931
+ default: {
932
+ const _exhaustive = direction;
933
+ throw new Error(`Unknown rounding direction: ${String(_exhaustive)}`);
934
+ }
935
+ }
936
+ }
937
+ function normalizeZero2(value) {
938
+ return Object.is(value, -0) ? 0 : value;
939
+ }
940
+ function assertIsInteger(value) {
941
+ if (!(typeof value === "number" && Number.isInteger(value))) {
942
+ throw new Error(
943
+ `Expected an integer, got ${typeof value === "number" ? String(value) : typeof value}`
944
+ );
945
+ }
946
+ }
947
+ function assertIsPositiveInteger(value) {
948
+ if (!(typeof value === "number" && Number.isInteger(value) && value >= 0)) {
949
+ throw new Error(
950
+ `Expected a non-negative integer, got ${typeof value === "number" ? String(value) : typeof value}`
951
+ );
952
+ }
953
+ }
954
+ function assertIntegerIsPositive(value) {
955
+ if (value < 0) {
956
+ throw new Error(`Expected a non-negative integer, got ${String(value)}`);
957
+ }
958
+ }
959
+ var Integer = {
960
+ /**
961
+ * The `Integer` value representing zero.
962
+ *
963
+ * @remarks
964
+ * Pre-allocated singleton — prefer `Integer.zero` over
965
+ * `Integer.from(0, 'floor')` to avoid an unnecessary call.
966
+ *
967
+ * @public
968
+ */
969
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-type-assertion -- branded type construction: 0 is trivially an integer
970
+ zero: 0,
971
+ /**
972
+ * Type guard that narrows an unknown value to {@link (Integer:type)}.
973
+ *
974
+ * @example
975
+ * ```ts
976
+ * const n: unknown = getCount();
977
+ * if (Integer.is(n)) {
978
+ * // n is Integer here
979
+ * config.retryCount = n;
980
+ * }
981
+ * ```
982
+ * @public
983
+ */
984
+ is: (value) => typeof value === "number" && Number.isInteger(value),
985
+ /**
986
+ * Assertion guard that throws if the value is not an {@link (Integer:type)}.
987
+ *
988
+ * @example
989
+ * ```ts
990
+ * const n: unknown = getCount();
991
+ * Integer.assert(n);
992
+ * // n is Integer here
993
+ * ```
994
+ * @public
995
+ */
996
+ assert: assertIsInteger,
997
+ /**
998
+ * Coerces a value to an {@link (Integer:type)} by rounding.
999
+ *
1000
+ * @remarks
1001
+ * Accepts `number`, `string`, `Decimal`, or `Integer`. The rounding
1002
+ * direction is always required — no invisible defaults.
1003
+ *
1004
+ * - **number** (including Integer): must be finite and round to a
1005
+ * safe integer (`Number.isSafeInteger`). IEEE 754 negative zero is
1006
+ * normalized to positive zero.
1007
+ * - **string**: must be a valid numeric literal (not empty/whitespace).
1008
+ * Parsed via `Number()`, then rounded. The result must be a safe integer.
1009
+ * - **Decimal**: delegated to {@link Decimal.toInteger | Decimal.toInteger()}.
1010
+ *
1011
+ * @example
1012
+ * ```ts
1013
+ * Integer.from(9.99, 'floor'); // 9
1014
+ * Integer.from('1.5', 'ceil'); // 2
1015
+ * Integer.from(Decimal.from('2.7'), 'half-up'); // 3
1016
+ * ```
1017
+ *
1018
+ * @throws Error if the value is non-finite, an empty string, an
1019
+ * unparseable string, or rounds to a value outside the safe integer range.
1020
+ *
1021
+ * @public
1022
+ */
1023
+ from(value, rounding) {
1024
+ if (typeof value === "number") {
1025
+ if (!Number.isFinite(value)) {
1026
+ throw new Error(`Cannot round non-finite value ${String(value)} to an integer`);
1027
+ }
1028
+ const rounded = normalizeZero2(roundToInteger(value, rounding));
1029
+ if (!Number.isSafeInteger(rounded)) {
1030
+ throw new Error(
1031
+ `Value ${String(value)} rounds to ${String(rounded)}, which is outside the safe integer range`
1032
+ );
1033
+ }
1034
+ return rounded;
1035
+ }
1036
+ if (typeof value === "string") {
1037
+ if (value.trim() === "") {
1038
+ throw new Error("Cannot parse empty string as an integer");
1039
+ }
1040
+ const num = Number(value);
1041
+ if (!Number.isFinite(num)) {
1042
+ throw new Error(
1043
+ `Cannot parse "${value}" as a finite number for integer conversion`
1044
+ );
1045
+ }
1046
+ const rounded = normalizeZero2(roundToInteger(num, rounding));
1047
+ if (!Number.isSafeInteger(rounded)) {
1048
+ throw new Error(
1049
+ `Value "${value}" rounds to ${String(rounded)}, which is outside the safe integer range`
1050
+ );
1051
+ }
1052
+ return rounded;
1053
+ }
1054
+ if (isDecimal(value)) {
1055
+ return value.toInteger(rounding);
1056
+ }
1057
+ throw new Error(
1058
+ `Cannot convert ${typeof value} to Integer; expected string, number, or Decimal`
1059
+ );
1060
+ },
1061
+ /**
1062
+ * Convert an {@link (Integer:type)} to a {@link (Decimal:type)}.
1063
+ *
1064
+ * @remarks
1065
+ * This conversion is lossless — every JavaScript integer is exactly
1066
+ * representable as a Decimal.
1067
+ *
1068
+ * @example
1069
+ * ```ts
1070
+ * const dec = Integer.toDecimal(Integer.from(42, 'floor'));
1071
+ * dec.add(Decimal.from('0.5')); // 42.5
1072
+ * ```
1073
+ * @public
1074
+ */
1075
+ toDecimal(value) {
1076
+ return Decimal.from(value);
1077
+ },
1078
+ /**
1079
+ * Type guard that narrows an {@link (Integer:type)} to {@link (PositiveInteger:type)}.
1080
+ *
1081
+ * @example
1082
+ * ```ts
1083
+ * const n = Integer.from(count, 'floor');
1084
+ * if (Integer.isPositive(n)) {
1085
+ * // n is PositiveInteger here
1086
+ * }
1087
+ * ```
1088
+ * @public
1089
+ */
1090
+ isPositive: (value) => value >= 0,
1091
+ /**
1092
+ * Assertion guard that throws if an {@link (Integer:type)} is not a {@link (PositiveInteger:type)}.
1093
+ *
1094
+ * @example
1095
+ * ```ts
1096
+ * const n = Integer.from(count, 'floor');
1097
+ * Integer.assertIsPositive(n);
1098
+ * // n is PositiveInteger here
1099
+ * ```
1100
+ * @public
1101
+ */
1102
+ assertIsPositive: assertIntegerIsPositive
1103
+ };
1104
+ var PositiveInteger = {
1105
+ /**
1106
+ * Type guard that narrows an unknown value to {@link (PositiveInteger:type)}.
1107
+ *
1108
+ * @example
1109
+ * ```ts
1110
+ * const n: unknown = getRetryCount();
1111
+ * if (PositiveInteger.is(n)) {
1112
+ * // n is PositiveInteger here
1113
+ * config.maxRetries = n;
1114
+ * }
1115
+ * ```
1116
+ * @public
1117
+ */
1118
+ is: (value) => typeof value === "number" && Number.isInteger(value) && value >= 0,
1119
+ /**
1120
+ * Assertion guard that throws if the value is not a {@link (PositiveInteger:type)}.
1121
+ *
1122
+ * @example
1123
+ * ```ts
1124
+ * const n: unknown = getRetryCount();
1125
+ * PositiveInteger.assert(n);
1126
+ * // n is PositiveInteger here
1127
+ * ```
1128
+ * @public
1129
+ */
1130
+ assert: assertIsPositiveInteger,
1131
+ /**
1132
+ * Coerces a value to a {@link (PositiveInteger:type)} by rounding.
1133
+ *
1134
+ * @remarks
1135
+ * Delegates to {@link (Integer:variable).from | Integer.from()} for
1136
+ * rounding, then checks the result is non-negative. All error
1137
+ * conditions from `Integer.from()` apply (non-finite, empty string,
1138
+ * unsafe integer range), plus an additional check that the rounded
1139
+ * result is ≥ 0. IEEE 754 negative zero is normalized to positive zero.
1140
+ *
1141
+ * @example
1142
+ * ```ts
1143
+ * PositiveInteger.from(2.7, 'floor'); // 2
1144
+ * PositiveInteger.from('1.5', 'ceil'); // 2
1145
+ * PositiveInteger.from(Decimal.from('3.2'), 'half-up'); // 3
1146
+ * ```
1147
+ *
1148
+ * @throws Error if the value is non-finite, unparseable, outside the
1149
+ * safe integer range, or rounds to a negative number.
1150
+ *
1151
+ * @public
1152
+ */
1153
+ from(value, rounding) {
1154
+ const rounded = Integer.from(value, rounding);
1155
+ const normalized = normalizeZero2(rounded);
1156
+ if (normalized < 0) {
1157
+ throw new Error(
1158
+ `Value ${String(value)} rounds to ${String(normalized)}, which is negative`
1159
+ );
1160
+ }
1161
+ return normalized;
1162
+ }
1163
+ };
1164
+
1165
+ // src/stdlib/refs.ts
1166
+ var Ref = {
1167
+ create: (step) => {
1168
+ return {
1169
+ type: step.object,
1170
+ id: step.id
1171
+ };
1172
+ }
1173
+ };
1174
+
955
1175
  // src/stdlib/types.ts
956
- var WireReadError = class extends Error {
1176
+ var _WireReadError = class extends Error {
957
1177
  /**
958
1178
  * Error class name for `instanceof`-free identification.
959
1179
  * @internal
960
1180
  */
961
- name = "WireReadError";
1181
+ name = "_WireReadError";
962
1182
  };
963
- var WireWriteError = class extends Error {
1183
+ var _WireWriteError = class extends Error {
964
1184
  /**
965
1185
  * Error class name for `instanceof`-free identification.
966
1186
  * @internal
967
1187
  */
968
- name = "WireWriteError";
1188
+ name = "_WireWriteError";
969
1189
  };
970
1190
  var WireParseError = class extends Error {
971
1191
  name = "WireParseError";
@@ -1172,7 +1392,7 @@ function enumLookup(spec, value, direction) {
1172
1392
  var _ProtoWireToType = {
1173
1393
  _brand: "ProtoWireToType",
1174
1394
  createNotObjectError(loc, received) {
1175
- return new WireReadError(`${loc}: Expected an object but received ${received}`);
1395
+ return new _WireReadError(`${loc}: Expected an object but received ${received}`);
1176
1396
  },
1177
1397
  applyField(typeName, desc, input, strategy) {
1178
1398
  const from = desc.wire ?? desc.type;
@@ -1182,7 +1402,7 @@ var _ProtoWireToType = {
1182
1402
  return [to, (desc.transform ?? _identity)(strategy, raw)];
1183
1403
  } catch (e) {
1184
1404
  if (e instanceof WireParseError)
1185
- throw new WireReadError(`${typeName}.${desc.type}: ${e.message}`);
1405
+ throw new _WireReadError(`${typeName}.${desc.type}: ${e.message}`);
1186
1406
  throw e;
1187
1407
  }
1188
1408
  },
@@ -1237,7 +1457,7 @@ var _ProtoWireToType = {
1237
1457
  }
1238
1458
  }
1239
1459
  const loc = descriptor.typeName || "union";
1240
- throw new WireReadError(`${loc}: No variant set`);
1460
+ throw new _WireReadError(`${loc}: No variant set`);
1241
1461
  },
1242
1462
  applyOneofField(typeName, oneof, input, strategy, result, excludeWireKeys) {
1243
1463
  applyOneofFieldIncoming(typeName, oneof, input, strategy, result, excludeWireKeys);
@@ -1246,7 +1466,7 @@ var _ProtoWireToType = {
1246
1466
  var _TypeToProtoWire = {
1247
1467
  _brand: "TypeToProtoWire",
1248
1468
  createNotObjectError(loc, received) {
1249
- return new WireWriteError(`${loc}: Expected an object but received ${received}`);
1469
+ return new _WireWriteError(`${loc}: Expected an object but received ${received}`);
1250
1470
  },
1251
1471
  applyField(typeName, desc, input, strategy) {
1252
1472
  const from = desc.type;
@@ -1256,7 +1476,7 @@ var _TypeToProtoWire = {
1256
1476
  return [to, (desc.transform ?? _identity)(strategy, raw)];
1257
1477
  } catch (e) {
1258
1478
  if (e instanceof WireParseError)
1259
- throw new WireWriteError(`${typeName}.${desc.type}: ${e.message}`);
1479
+ throw new _WireWriteError(`${typeName}.${desc.type}: ${e.message}`);
1260
1480
  throw e;
1261
1481
  }
1262
1482
  },
@@ -1296,20 +1516,20 @@ var _TypeToProtoWire = {
1296
1516
  const discriminant = sdk[descriptor.discriminantFieldName];
1297
1517
  if (typeof discriminant !== "string") {
1298
1518
  const loc = descriptor.typeName || "union";
1299
- throw new WireWriteError(
1519
+ throw new _WireWriteError(
1300
1520
  `${loc}: Expected a string '${descriptor.discriminantFieldName}' discriminant but received ${discriminant === void 0 ? "undefined" : typeof discriminant}`
1301
1521
  );
1302
1522
  }
1303
1523
  if (discriminant === "other") {
1304
1524
  const loc = descriptor.typeName || "union";
1305
- throw new WireWriteError(
1525
+ throw new _WireWriteError(
1306
1526
  `${loc}: Cannot serialize 'other' variant back to wire format`
1307
1527
  );
1308
1528
  }
1309
1529
  const branch = descriptor.branches.find((b) => b.typeKey === discriminant);
1310
1530
  if (!branch) {
1311
1531
  const loc = descriptor.typeName || "union";
1312
- throw new WireWriteError(`${loc}: Unknown variant '${discriminant}'`);
1532
+ throw new _WireWriteError(`${loc}: Unknown variant '${discriminant}'`);
1313
1533
  }
1314
1534
  const branchData = _apply(
1315
1535
  new _ShapeDescriptor(descriptor.typeName, branch.shape),
@@ -1338,7 +1558,7 @@ function _configAppContextFromContext(ctx) {
1338
1558
  var _JsonWireToType = {
1339
1559
  _brand: "JsonWireToType",
1340
1560
  createNotObjectError(loc, received) {
1341
- return new WireReadError(`${loc}: Expected an object but received ${received}`);
1561
+ return new _WireReadError(`${loc}: Expected an object but received ${received}`);
1342
1562
  },
1343
1563
  applyField(typeName, desc, input, strategy) {
1344
1564
  const key = desc.type;
@@ -1347,7 +1567,7 @@ var _JsonWireToType = {
1347
1567
  return [key, (desc.transform ?? _identity)(strategy, raw)];
1348
1568
  } catch (e) {
1349
1569
  if (e instanceof WireParseError)
1350
- throw new WireReadError(`${typeName}.${desc.type}: ${e.message}`);
1570
+ throw new _WireReadError(`${typeName}.${desc.type}: ${e.message}`);
1351
1571
  throw e;
1352
1572
  }
1353
1573
  },
@@ -1402,7 +1622,7 @@ function applyOneofFieldIncoming(typeName, oneof, input, strategy, result, exclu
1402
1622
  }
1403
1623
  } catch (e) {
1404
1624
  if (e instanceof WireParseError) {
1405
- throw new WireReadError(
1625
+ throw new _WireReadError(
1406
1626
  `${typeName}.${oneof.discriminant}(${branch.typeKey}): ${e.message}`
1407
1627
  );
1408
1628
  }
@@ -1420,30 +1640,30 @@ function applyOneofFieldIncoming(typeName, oneof, input, strategy, result, exclu
1420
1640
  }
1421
1641
  }
1422
1642
  if (!oneof.optional) {
1423
- throw new WireReadError(`${typeName}.${oneof.discriminant}: no variant set`);
1643
+ throw new _WireReadError(`${typeName}.${oneof.discriminant}: no variant set`);
1424
1644
  }
1425
1645
  }
1426
1646
  function applyOneofFieldOutgoing(typeName, oneof, input, strategy, result) {
1427
1647
  const discriminant = Object.hasOwn(input, oneof.discriminant) ? input[oneof.discriminant] : void 0;
1428
1648
  if (discriminant === void 0 || discriminant === null) {
1429
1649
  if (!oneof.optional) {
1430
- throw new WireWriteError(`${typeName}.${oneof.discriminant}: no variant set`);
1650
+ throw new _WireWriteError(`${typeName}.${oneof.discriminant}: no variant set`);
1431
1651
  }
1432
1652
  return;
1433
1653
  }
1434
1654
  if (typeof discriminant !== "string") {
1435
- throw new WireWriteError(
1655
+ throw new _WireWriteError(
1436
1656
  `${typeName}.${oneof.discriminant}: expected string discriminant but received ${typeof discriminant}`
1437
1657
  );
1438
1658
  }
1439
1659
  if (discriminant === "other") {
1440
- throw new WireWriteError(
1660
+ throw new _WireWriteError(
1441
1661
  `${typeName}.${oneof.discriminant}: cannot serialize 'other' variant back to wire format`
1442
1662
  );
1443
1663
  }
1444
1664
  const branch = oneof.branches.find((b) => b.typeKey === discriminant);
1445
1665
  if (!branch) {
1446
- throw new WireWriteError(
1666
+ throw new _WireWriteError(
1447
1667
  `${typeName}.${oneof.discriminant}: unknown variant '${discriminant}'`
1448
1668
  );
1449
1669
  }
@@ -1453,7 +1673,7 @@ function applyOneofFieldOutgoing(typeName, oneof, input, strategy, result) {
1453
1673
  result[branch.wireKey] = transformed ?? {};
1454
1674
  } catch (e) {
1455
1675
  if (e instanceof WireParseError) {
1456
- throw new WireWriteError(
1676
+ throw new _WireWriteError(
1457
1677
  `${typeName}.${oneof.discriminant}(${branch.typeKey}): ${e.message}`
1458
1678
  );
1459
1679
  }
@@ -1485,6 +1705,23 @@ function _applyConfig(descriptor, inputObject, appCtx) {
1485
1705
  return _apply(descriptor, strategy, inputObject);
1486
1706
  }
1487
1707
 
1708
+ // src/stdlib/to-const.ts
1709
+ function toConst(value) {
1710
+ if (value === null || typeof value !== "object") {
1711
+ return value;
1712
+ }
1713
+ if (Array.isArray(value)) {
1714
+ for (const item of value) {
1715
+ toConst(item);
1716
+ }
1717
+ return Object.freeze(value);
1718
+ }
1719
+ for (const key of Object.keys(value)) {
1720
+ toConst(value[key]);
1721
+ }
1722
+ return Object.freeze(value);
1723
+ }
1724
+
1488
1725
  // src/extensions/billing/index.ts
1489
1726
  var billing_exports = {};
1490
1727
  __export(billing_exports, {
@@ -3806,10 +4043,6 @@ var CustomAction2;
3806
4043
  Integer,
3807
4044
  PositiveInteger,
3808
4045
  Ref,
3809
- StreetAddress,
3810
- Timestamp,
3811
- WireReadError,
3812
- WireWriteError,
3813
4046
  _ConfigEnum,
3814
4047
  _JsonWireToType,
3815
4048
  _ProtoEnum,
@@ -3817,6 +4050,8 @@ var CustomAction2;
3817
4050
  _ShapeDescriptor,
3818
4051
  _TypeToProtoWire,
3819
4052
  _UnionDescriptor,
4053
+ _WireReadError,
4054
+ _WireWriteError,
3820
4055
  _apply,
3821
4056
  _applyConfig,
3822
4057
  _applyIncoming,
@@ -3832,5 +4067,5 @@ var CustomAction2;
3832
4067
  _translateMap,
3833
4068
  _translateShape,
3834
4069
  _translateUnion,
3835
- isDecimal
4070
+ toConst
3836
4071
  });