@fantastic.dev/better-stripe 0.60.0 → 0.61.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 (193) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -1
  3. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +26 -6
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  5. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +13 -3
  6. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  7. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +26 -6
  8. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  9. package/dist/client/connect/payoutSyncTestHelpers.d.ts +13 -3
  10. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  11. package/dist/client/usage/creditCapacity.d.ts.map +1 -1
  12. package/dist/client/usage/creditCapacity.js +7 -1
  13. package/dist/client/usage/creditCapacity.js.map +1 -1
  14. package/dist/client/usage/creditClient.d.ts +3 -0
  15. package/dist/client/usage/creditClient.d.ts.map +1 -1
  16. package/dist/client/usage/creditDelivery.d.ts.map +1 -1
  17. package/dist/client/usage/creditDelivery.js +4 -1
  18. package/dist/client/usage/creditDelivery.js.map +1 -1
  19. package/dist/client/usage/creditLifecycle.d.ts.map +1 -1
  20. package/dist/client/usage/creditLifecycle.js +2 -1
  21. package/dist/client/usage/creditLifecycle.js.map +1 -1
  22. package/dist/client/usage/creditNative.d.ts +3 -0
  23. package/dist/client/usage/creditNative.d.ts.map +1 -1
  24. package/dist/client/usage/creditNative.js +3 -0
  25. package/dist/client/usage/creditNative.js.map +1 -1
  26. package/dist/client/usage/creditProvider.d.ts.map +1 -1
  27. package/dist/client/usage/creditProvider.js +2 -1
  28. package/dist/client/usage/creditProvider.js.map +1 -1
  29. package/dist/client/usage/creditRead.d.ts +1 -0
  30. package/dist/client/usage/creditRead.d.ts.map +1 -1
  31. package/dist/client/usage/creditReconciliation.d.ts.map +1 -1
  32. package/dist/client/usage/creditReconciliation.js +11 -3
  33. package/dist/client/usage/creditReconciliation.js.map +1 -1
  34. package/dist/client/usage/creditSettlement.fixtures.d.ts +1 -0
  35. package/dist/client/usage/creditSettlement.fixtures.d.ts.map +1 -1
  36. package/dist/client/usage/creditTransport.fixtures.d.ts +1 -0
  37. package/dist/client/usage/creditTransport.fixtures.d.ts.map +1 -1
  38. package/dist/client/usage/creditTransport.fixtures.js +2 -1
  39. package/dist/client/usage/creditTransport.fixtures.js.map +1 -1
  40. package/dist/client/usage/index.d.ts +2 -0
  41. package/dist/client/usage/index.d.ts.map +1 -1
  42. package/dist/client/usage/subscriptionCancellation.d.ts.map +1 -1
  43. package/dist/client/usage/subscriptionCancellation.js +3 -2
  44. package/dist/client/usage/subscriptionCancellation.js.map +1 -1
  45. package/dist/client/usage/subscriptionCheckout.d.ts.map +1 -1
  46. package/dist/client/usage/subscriptionCheckout.js +3 -2
  47. package/dist/client/usage/subscriptionCheckout.js.map +1 -1
  48. package/dist/client/usage/subscriptionLifecycle.d.ts +1 -0
  49. package/dist/client/usage/subscriptionLifecycle.d.ts.map +1 -1
  50. package/dist/client/usage/subscriptionLifecycle.js +3 -2
  51. package/dist/client/usage/subscriptionLifecycle.js.map +1 -1
  52. package/dist/client/usage/subscriptionProvider.d.ts +2 -0
  53. package/dist/client/usage/subscriptionProvider.d.ts.map +1 -1
  54. package/dist/client/usage/subscriptionProvider.js +9 -2
  55. package/dist/client/usage/subscriptionProvider.js.map +1 -1
  56. package/dist/component/_generated/component.d.ts +21 -0
  57. package/dist/component/_generated/component.d.ts.map +1 -1
  58. package/dist/component/earnings/triggers.d.ts +16 -6
  59. package/dist/component/earnings/triggers.d.ts.map +1 -1
  60. package/dist/component/schema.d.ts +13 -3
  61. package/dist/component/usage/allowance.fixtures.d.ts +4212 -0
  62. package/dist/component/usage/allowance.fixtures.d.ts.map +1 -0
  63. package/dist/component/usage/allowance.fixtures.js +67 -0
  64. package/dist/component/usage/allowance.fixtures.js.map +1 -0
  65. package/dist/component/usageCredits/accounting.fixtures.d.ts +4235 -0
  66. package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -0
  67. package/dist/component/usageCredits/accounting.fixtures.js +89 -0
  68. package/dist/component/usageCredits/accounting.fixtures.js.map +1 -0
  69. package/dist/component/usageCredits/helpers.d.ts +7 -0
  70. package/dist/component/usageCredits/helpers.d.ts.map +1 -1
  71. package/dist/component/usageCredits/helpers.js +5 -0
  72. package/dist/component/usageCredits/helpers.js.map +1 -1
  73. package/dist/component/usageCredits/mutations.d.ts +6 -0
  74. package/dist/component/usageCredits/mutations.d.ts.map +1 -1
  75. package/dist/component/usageCredits/mutations.js +70 -7
  76. package/dist/component/usageCredits/mutations.js.map +1 -1
  77. package/dist/component/usageCredits/purchase.d.ts +1 -0
  78. package/dist/component/usageCredits/purchase.d.ts.map +1 -1
  79. package/dist/component/usageCredits/queries.d.ts +10 -0
  80. package/dist/component/usageCredits/queries.d.ts.map +1 -1
  81. package/dist/component/usageCredits/schema.d.ts +24 -4
  82. package/dist/component/usageCredits/schema.d.ts.map +1 -1
  83. package/dist/component/usageCredits/schema.js +4 -0
  84. package/dist/component/usageCredits/schema.js.map +1 -1
  85. package/dist/component/usageSubscriptions/history.d.ts.map +1 -1
  86. package/dist/component/usageSubscriptions/history.js +3 -1
  87. package/dist/component/usageSubscriptions/history.js.map +1 -1
  88. package/dist/component/usageSubscriptions/mutations.d.ts +5 -0
  89. package/dist/component/usageSubscriptions/mutations.d.ts.map +1 -1
  90. package/dist/component/usageSubscriptions/mutations.js +19 -0
  91. package/dist/component/usageSubscriptions/mutations.js.map +1 -1
  92. package/dist/component/usageSubscriptions/queries.d.ts +2 -0
  93. package/dist/component/usageSubscriptions/queries.d.ts.map +1 -1
  94. package/dist/component/usageSubscriptions/schema.d.ts +7 -2
  95. package/dist/component/usageSubscriptions/schema.d.ts.map +1 -1
  96. package/dist/component/usageSubscriptions/schema.js +1 -0
  97. package/dist/component/usageSubscriptions/schema.js.map +1 -1
  98. package/dist/react/index.d.ts +12 -0
  99. package/dist/react/index.d.ts.map +1 -1
  100. package/dist/react/index.js +7 -0
  101. package/dist/react/index.js.map +1 -1
  102. package/dist/react/workflows/Pagination.d.ts +1 -0
  103. package/dist/react/workflows/Pagination.d.ts.map +1 -1
  104. package/dist/react/workflows/Pagination.js +1 -0
  105. package/dist/react/workflows/Pagination.js.map +1 -1
  106. package/dist/react/workflows/Usage.fixtures.d.ts +17 -0
  107. package/dist/react/workflows/Usage.fixtures.d.ts.map +1 -0
  108. package/dist/react/workflows/Usage.fixtures.js +79 -0
  109. package/dist/react/workflows/Usage.fixtures.js.map +1 -0
  110. package/dist/react/workflows/Usage.types.d.ts +25 -0
  111. package/dist/react/workflows/Usage.types.d.ts.map +1 -0
  112. package/dist/react/workflows/Usage.types.js +11 -0
  113. package/dist/react/workflows/Usage.types.js.map +1 -0
  114. package/dist/react/workflows/UsageAllowance.d.ts +14 -0
  115. package/dist/react/workflows/UsageAllowance.d.ts.map +1 -0
  116. package/dist/react/workflows/UsageAllowance.js +21 -0
  117. package/dist/react/workflows/UsageAllowance.js.map +1 -0
  118. package/dist/react/workflows/UsageBilling.d.ts +20 -0
  119. package/dist/react/workflows/UsageBilling.d.ts.map +1 -0
  120. package/dist/react/workflows/UsageBilling.js +40 -0
  121. package/dist/react/workflows/UsageBilling.js.map +1 -0
  122. package/dist/react/workflows/UsageCredits.d.ts +14 -0
  123. package/dist/react/workflows/UsageCredits.d.ts.map +1 -0
  124. package/dist/react/workflows/UsageCredits.js +25 -0
  125. package/dist/react/workflows/UsageCredits.js.map +1 -0
  126. package/dist/react/workflows/UsageHistory.d.ts +40 -0
  127. package/dist/react/workflows/UsageHistory.d.ts.map +1 -0
  128. package/dist/react/workflows/UsageHistory.js +74 -0
  129. package/dist/react/workflows/UsageHistory.js.map +1 -0
  130. package/dist/react/workflows/UsageSummary.d.ts +19 -0
  131. package/dist/react/workflows/UsageSummary.d.ts.map +1 -0
  132. package/dist/react/workflows/UsageSummary.js +54 -0
  133. package/dist/react/workflows/UsageSummary.js.map +1 -0
  134. package/dist/react/workflows/usage-format.d.ts +11 -0
  135. package/dist/react/workflows/usage-format.d.ts.map +1 -0
  136. package/dist/react/workflows/usage-format.js +43 -0
  137. package/dist/react/workflows/usage-format.js.map +1 -0
  138. package/dist/react/workflows/usage-scope.d.ts +5 -0
  139. package/dist/react/workflows/usage-scope.d.ts.map +1 -0
  140. package/dist/react/workflows/usage-scope.js +26 -0
  141. package/dist/react/workflows/usage-scope.js.map +1 -0
  142. package/docs/README.md +4 -0
  143. package/docs/react-api.md +4 -0
  144. package/docs/usage-credits.md +6 -1
  145. package/docs/usage-react.md +182 -0
  146. package/docs/usage-security.md +130 -0
  147. package/package.json +3 -1
  148. package/src/client/usage/creditBackingIsolation.test.ts +110 -0
  149. package/src/client/usage/creditCapacity.test.ts +80 -1
  150. package/src/client/usage/creditCapacity.ts +10 -1
  151. package/src/client/usage/creditDelivery.ts +4 -0
  152. package/src/client/usage/creditLifecycle.ts +2 -0
  153. package/src/client/usage/creditNative.ts +5 -0
  154. package/src/client/usage/creditProofBounds.test.ts +187 -0
  155. package/src/client/usage/creditProvider.test.ts +74 -0
  156. package/src/client/usage/creditProvider.ts +2 -0
  157. package/src/client/usage/creditReconciliation.ts +18 -3
  158. package/src/client/usage/creditTransport.fixtures.ts +2 -1
  159. package/src/client/usage/index.ts +3 -0
  160. package/src/client/usage/subscriptionCancellation.ts +3 -2
  161. package/src/client/usage/subscriptionCheckout.ts +7 -2
  162. package/src/client/usage/subscriptionClient.test.ts +60 -1
  163. package/src/client/usage/subscriptionLifecycle.ts +3 -2
  164. package/src/client/usage/subscriptionProvider.ts +27 -3
  165. package/src/component/_generated/component.ts +40 -1
  166. package/src/component/usage/allowance.fixtures.ts +77 -0
  167. package/src/component/usage/allowance.test.ts +3 -66
  168. package/src/component/usage/allowanceBounds.test.ts +79 -0
  169. package/src/component/usage/historyIsolation.test.ts +124 -0
  170. package/src/component/usageCredits/accounting.fixtures.ts +96 -0
  171. package/src/component/usageCredits/accounting.test.ts +176 -82
  172. package/src/component/usageCredits/freshness.test.ts +33 -0
  173. package/src/component/usageCredits/helpers.ts +8 -0
  174. package/src/component/usageCredits/mutations.ts +83 -5
  175. package/src/component/usageCredits/quotas.test.ts +63 -0
  176. package/src/component/usageCredits/schema.ts +10 -0
  177. package/src/component/usageSubscriptions/history.test.ts +57 -0
  178. package/src/component/usageSubscriptions/history.ts +3 -1
  179. package/src/component/usageSubscriptions/mutations.ts +23 -0
  180. package/src/component/usageSubscriptions/schema.ts +1 -0
  181. package/src/react/index.ts +20 -0
  182. package/src/react/workflows/Pagination.tsx +2 -0
  183. package/src/react/workflows/Usage.fixtures.ts +88 -0
  184. package/src/react/workflows/Usage.test.tsx +373 -0
  185. package/src/react/workflows/Usage.types.ts +39 -0
  186. package/src/react/workflows/UsageAllowance.tsx +114 -0
  187. package/src/react/workflows/UsageBilling.tsx +90 -0
  188. package/src/react/workflows/UsageCredits.tsx +112 -0
  189. package/src/react/workflows/UsageHistory.test.tsx +206 -0
  190. package/src/react/workflows/UsageHistory.tsx +154 -0
  191. package/src/react/workflows/UsageSummary.tsx +204 -0
  192. package/src/react/workflows/usage-format.ts +48 -0
  193. package/src/react/workflows/usage-scope.ts +42 -0
@@ -0,0 +1,204 @@
1
+ "use client";
2
+ import { usageSummaryMatches } from "./usage-scope.js";
3
+ import type { ReactNode } from "react";
4
+ import type { UsageAvailability } from "../../client/usage/boundaries.js";
5
+ import type { UsageLocalSummary } from "../../client/usage/summary.js";
6
+ import type { UsageAggregateObservation } from "../../client/usage/observationTypes.js";
7
+ import type { UsageViewScope } from "./Usage.types.js";
8
+ import { formatUsageEstimate, formatUsageTime } from "./usage-format.js";
9
+ export type UsageSummaryProps = {
10
+ scope: UsageViewScope;
11
+ summary: UsageAvailability<UsageLocalSummary> | undefined;
12
+ provider?: UsageAggregateObservation;
13
+ className?: string;
14
+ children?: (state: {
15
+ summary: UsageSummaryProps["summary"];
16
+ provider: UsageSummaryProps["provider"];
17
+ isLoading: boolean;
18
+ isEmpty: boolean;
19
+ }) => ReactNode;
20
+ };
21
+ const models = {
22
+ pay_as_you_go: "Pay as you go",
23
+ included_overage: "Included monthly usage with overages",
24
+ prepaid: "Prepaid credits",
25
+ };
26
+ const deliveryLabels = {
27
+ queued: "Queued delivery",
28
+ sending: "Sending delivery",
29
+ provider_accepted: "Provider accepted",
30
+ rejected: "Rejected delivery",
31
+ unknown: "Unknown delivery",
32
+ held: "Held delivery",
33
+ canceled: "Canceled usage",
34
+ };
35
+ export function UsageSummary(props: UsageSummaryProps) {
36
+ const provider =
37
+ props.provider?.status === "available" &&
38
+ (props.provider.value.period.start !== props.scope.period.start ||
39
+ props.provider.value.period.end !== props.scope.period.end)
40
+ ? {
41
+ status: "unavailable" as const,
42
+ reason: "observation_scope_mismatch",
43
+ retryable: true,
44
+ }
45
+ : props.provider;
46
+ const summary =
47
+ props.summary?.status === "available" &&
48
+ !usageSummaryMatches(props.scope, props.summary.value)
49
+ ? {
50
+ status: "unavailable" as const,
51
+ reason: "observation_scope_mismatch",
52
+ retryable: true,
53
+ }
54
+ : props.summary;
55
+ const available = summary?.status === "available" ? summary.value : null;
56
+ if (props.children)
57
+ return (
58
+ <>
59
+ {props.children({
60
+ summary,
61
+ provider,
62
+ isLoading: summary === undefined,
63
+ isEmpty: !!available?.complete && available.eventCount === 0,
64
+ })}
65
+ </>
66
+ );
67
+ return (
68
+ <section
69
+ data-better-stripe="usage-summary"
70
+ className={props.className}
71
+ aria-label="Usage summary"
72
+ aria-busy={summary === undefined}
73
+ >
74
+ <h2>Usage by meter</h2>
75
+ {!summary ? (
76
+ <p role="status">Loading usage…</p>
77
+ ) : summary.status !== "available" ? (
78
+ <p role="status">
79
+ Usage {summary.status}. Refresh when original usage evidence is
80
+ available.
81
+ </p>
82
+ ) : (
83
+ <>
84
+ <p>
85
+ Period {formatUsageTime(summary.value.period.start)} to{" "}
86
+ {formatUsageTime(summary.value.period.end)}
87
+ </p>
88
+ {!summary.value.complete && (
89
+ <p role="status">Local history incomplete. Totals are partial.</p>
90
+ )}
91
+ {summary.value.complete && summary.value.eventCount === 0 && (
92
+ <p>No usage in this period.</p>
93
+ )}
94
+ {summary.value.groups.map((group) => (
95
+ <article
96
+ key={JSON.stringify([
97
+ group.binding.stripePriceId,
98
+ group.subscription.subscriptionItemId,
99
+ group.subscription.period,
100
+ ])}
101
+ data-billing-model={group.binding.plan.model}
102
+ >
103
+ <h3>
104
+ {group.binding.plan.unit.name} ·{" "}
105
+ {models[group.binding.plan.model]}
106
+ </h3>
107
+ <p>
108
+ Plan {group.binding.plan.key}, version{" "}
109
+ {group.binding.plan.version}
110
+ </p>
111
+ <dl>
112
+ <dt>Accepted usage</dt>
113
+ <dd>
114
+ {group.acceptedQuantity} {group.binding.plan.unit.name}
115
+ </dd>
116
+ <dt>Billable after corrections</dt>
117
+ <dd>
118
+ {group.effectiveQuantity} {group.binding.plan.unit.name}
119
+ </dd>
120
+ <dt>Provider accepted</dt>
121
+ <dd>
122
+ {group.providerAcceptedQuantity}{" "}
123
+ {group.binding.plan.unit.name}
124
+ </dd>
125
+ {Object.entries(group.deliveryQuantities)
126
+ .filter(
127
+ ([kind, quantity]) =>
128
+ kind !== "provider_accepted" &&
129
+ !/^0(?:\.0+)?$/.test(quantity),
130
+ )
131
+ .map(([kind, quantity]) => (
132
+ <div key={kind}>
133
+ <dt>
134
+ {deliveryLabels[kind as keyof typeof deliveryLabels]}
135
+ </dt>
136
+ <dd>
137
+ {quantity} {group.binding.plan.unit.name}
138
+ </dd>
139
+ </div>
140
+ ))}
141
+ </dl>
142
+ {group.validationErrorEventCount > 0 && (
143
+ <p role="status">
144
+ Native validation rejected {group.validationErrorEventCount}{" "}
145
+ event(s).
146
+ </p>
147
+ )}
148
+ {group.estimate.status === "available" ? (
149
+ <p>
150
+ Estimated usage charge:{" "}
151
+ {formatUsageEstimate(
152
+ group.estimate.value.amountDecimal,
153
+ group.estimate.value.currency,
154
+ ) ?? "Unavailable"}
155
+ </p>
156
+ ) : (
157
+ <p>
158
+ Estimate {group.estimate.status}. Complete original usage and
159
+ pricing evidence is required.
160
+ </p>
161
+ )}
162
+ {group.included.status === "available" && (
163
+ <dl>
164
+ <dt>Included units</dt>
165
+ <dd>{group.included.value.included}</dd>
166
+ <dt>Remaining included units</dt>
167
+ <dd>{group.included.value.remaining}</dd>
168
+ <dt>Overage units</dt>
169
+ <dd>{group.included.value.overage}</dd>
170
+ </dl>
171
+ )}
172
+ </article>
173
+ ))}
174
+ <p>
175
+ Estimate only. Finalized invoices and verified payments determine
176
+ billing.
177
+ </p>
178
+ </>
179
+ )}
180
+ {!provider || provider.status !== "available" ? (
181
+ <p role="status">
182
+ Native aggregation {provider?.status ?? "unavailable"}. Refresh after
183
+ provider ingestion.
184
+ </p>
185
+ ) : (
186
+ <>
187
+ <p>Native aggregate: {provider.value.quantity}</p>
188
+ {provider.value.stale && (
189
+ <p role="status">Native aggregation stale.</p>
190
+ )}
191
+ {!provider.value.complete && (
192
+ <p role="status">
193
+ Native aggregation partial. More provider pages remain.
194
+ </p>
195
+ )}
196
+ <p>
197
+ Aggregation may be delayed. Provider acceptance does not prove
198
+ ingestion or payment.
199
+ </p>
200
+ </>
201
+ )}
202
+ </section>
203
+ );
204
+ }
@@ -0,0 +1,48 @@
1
+ import { getChargeCurrencyMetadata } from "../../client/charge-currency.js";
2
+ /** Native metered rates/estimates use minor currency decimals. Preserve fractional cents and large quantities. */
3
+ export function formatUsageEstimate(
4
+ amountDecimal: string,
5
+ currency: string,
6
+ ): string | null {
7
+ const metadata = getChargeCurrencyMetadata(currency);
8
+ if (!metadata || !/^\d+(?:\.\d+)?$/.test(amountDecimal)) return null;
9
+ const [whole, fraction = ""] = amountDecimal.split(".");
10
+ const digits = (whole + fraction).replace(/^0+(?=\d)/, "");
11
+ const scale = metadata.apiDecimals + fraction.length;
12
+ const padded = digits.padStart(scale + 1, "0");
13
+ const major = scale ? padded.slice(0, -scale) : padded;
14
+ let minor = scale ? padded.slice(-scale).replace(/0+$/, "") : "";
15
+ if (metadata.displayDecimals === 0 && minor) return null;
16
+ minor = minor.padEnd(metadata.displayDecimals, "0");
17
+ return `${major}${minor ? "." + minor : ""} ${metadata.currency.toUpperCase()}`;
18
+ }
19
+
20
+ /** Normalize only the visual progress position; keep all visible quantities exact. */
21
+ export function allowanceProgress(value: {
22
+ consumedQuantity: string;
23
+ reservedQuantity: string;
24
+ includedQuantity: string;
25
+ }): number | null {
26
+ const quantities = [
27
+ value.consumedQuantity,
28
+ value.reservedQuantity,
29
+ value.includedQuantity,
30
+ ];
31
+ if (quantities.some((quantity) => !/^\d{1,18}(?:\.\d{1,6})?$/.test(quantity)))
32
+ return null;
33
+ const [consumed, reserved, included] = quantities.map((quantity) => {
34
+ const [whole, fraction = ""] = quantity.split(".");
35
+ return BigInt(whole + fraction.padEnd(6, "0"));
36
+ });
37
+ if (included === 0n) return null;
38
+ const ratio = ((consumed + reserved) * 10000n) / included;
39
+ return Number(ratio > 10000n ? 10000n : ratio);
40
+ }
41
+
42
+ /** Numeric usage periods can exceed Date's supported display range. */
43
+ export function formatUsageTime(seconds: number): string {
44
+ const value = new Date(seconds * 1000);
45
+ return Number.isFinite(value.getTime())
46
+ ? value.toISOString()
47
+ : "Time unavailable";
48
+ }
@@ -0,0 +1,42 @@
1
+ import type { UsageBillingSnapshot, UsageViewScope } from "./Usage.types.js";
2
+ import type { UsageLocalSummary } from "../../client/usage/summary.js";
3
+ export function usageSummaryMatches(
4
+ scope: UsageViewScope,
5
+ value: UsageLocalSummary,
6
+ ) {
7
+ return (
8
+ value.period.start === scope.period.start &&
9
+ value.period.end === scope.period.end &&
10
+ value.groups.every(
11
+ (group) =>
12
+ group.binding.plan.rate.currency.toLowerCase() ===
13
+ scope.currency.toLowerCase() &&
14
+ (group.estimate.status !== "available" ||
15
+ group.estimate.value.currency.toLowerCase() ===
16
+ scope.currency.toLowerCase()),
17
+ )
18
+ );
19
+ }
20
+ export function usageSnapshotMatches(
21
+ scope: UsageViewScope,
22
+ value: UsageBillingSnapshot,
23
+ ) {
24
+ const periodMatches = (period: { start: number; end: number }) =>
25
+ period.start === scope.period.start && period.end === scope.period.end;
26
+ const currencyMatches = (currency: string) =>
27
+ currency.toLowerCase() === scope.currency.toLowerCase();
28
+ return (
29
+ (value.summary.status !== "available" ||
30
+ usageSummaryMatches(scope, value.summary.value)) &&
31
+ (value.provider?.status !== "available" ||
32
+ periodMatches(value.provider.value.period)) &&
33
+ (value.allowance?.status !== "available" ||
34
+ !value.allowance.value ||
35
+ (periodMatches(value.allowance.value.period) &&
36
+ currencyMatches(value.allowance.value.committedEstimate.currency) &&
37
+ currencyMatches(value.allowance.value.projectedEstimate.currency))) &&
38
+ (value.credits?.status !== "available" ||
39
+ currencyMatches(value.credits.value.currency)) &&
40
+ (!value.purchase || currencyMatches(value.purchase.currency))
41
+ );
42
+ }