@fantastic.dev/better-stripe 0.60.1 → 0.62.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 (95) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -1
  3. package/dist/client/usage/index.d.ts +2 -0
  4. package/dist/client/usage/index.d.ts.map +1 -1
  5. package/dist/react/index.d.ts +17 -0
  6. package/dist/react/index.d.ts.map +1 -1
  7. package/dist/react/index.js +10 -0
  8. package/dist/react/index.js.map +1 -1
  9. package/dist/react/workflows/Pagination.d.ts +1 -0
  10. package/dist/react/workflows/Pagination.d.ts.map +1 -1
  11. package/dist/react/workflows/Pagination.js +1 -0
  12. package/dist/react/workflows/Pagination.js.map +1 -1
  13. package/dist/react/workflows/Usage.fixtures.d.ts +17 -0
  14. package/dist/react/workflows/Usage.fixtures.d.ts.map +1 -0
  15. package/dist/react/workflows/Usage.fixtures.js +79 -0
  16. package/dist/react/workflows/Usage.fixtures.js.map +1 -0
  17. package/dist/react/workflows/Usage.types.d.ts +25 -0
  18. package/dist/react/workflows/Usage.types.d.ts.map +1 -0
  19. package/dist/react/workflows/Usage.types.js +11 -0
  20. package/dist/react/workflows/Usage.types.js.map +1 -0
  21. package/dist/react/workflows/UsageAllowance.d.ts +14 -0
  22. package/dist/react/workflows/UsageAllowance.d.ts.map +1 -0
  23. package/dist/react/workflows/UsageAllowance.js +21 -0
  24. package/dist/react/workflows/UsageAllowance.js.map +1 -0
  25. package/dist/react/workflows/UsageBilling.d.ts +20 -0
  26. package/dist/react/workflows/UsageBilling.d.ts.map +1 -0
  27. package/dist/react/workflows/UsageBilling.js +40 -0
  28. package/dist/react/workflows/UsageBilling.js.map +1 -0
  29. package/dist/react/workflows/UsageConfiguration.d.ts +4 -0
  30. package/dist/react/workflows/UsageConfiguration.d.ts.map +1 -0
  31. package/dist/react/workflows/UsageConfiguration.js +19 -0
  32. package/dist/react/workflows/UsageConfiguration.js.map +1 -0
  33. package/dist/react/workflows/UsageConfiguration.types.d.ts +65 -0
  34. package/dist/react/workflows/UsageConfiguration.types.d.ts.map +1 -0
  35. package/dist/react/workflows/UsageConfiguration.types.js +2 -0
  36. package/dist/react/workflows/UsageConfiguration.types.js.map +1 -0
  37. package/dist/react/workflows/UsageCredits.d.ts +14 -0
  38. package/dist/react/workflows/UsageCredits.d.ts.map +1 -0
  39. package/dist/react/workflows/UsageCredits.js +25 -0
  40. package/dist/react/workflows/UsageCredits.js.map +1 -0
  41. package/dist/react/workflows/UsageHistory.d.ts +40 -0
  42. package/dist/react/workflows/UsageHistory.d.ts.map +1 -0
  43. package/dist/react/workflows/UsageHistory.js +74 -0
  44. package/dist/react/workflows/UsageHistory.js.map +1 -0
  45. package/dist/react/workflows/UsagePriceRow.d.ts +26 -0
  46. package/dist/react/workflows/UsagePriceRow.d.ts.map +1 -0
  47. package/dist/react/workflows/UsagePriceRow.js +40 -0
  48. package/dist/react/workflows/UsagePriceRow.js.map +1 -0
  49. package/dist/react/workflows/UsageSummary.d.ts +19 -0
  50. package/dist/react/workflows/UsageSummary.d.ts.map +1 -0
  51. package/dist/react/workflows/UsageSummary.js +54 -0
  52. package/dist/react/workflows/UsageSummary.js.map +1 -0
  53. package/dist/react/workflows/usage-configuration-validation.d.ts +4 -0
  54. package/dist/react/workflows/usage-configuration-validation.d.ts.map +1 -0
  55. package/dist/react/workflows/usage-configuration-validation.js +116 -0
  56. package/dist/react/workflows/usage-configuration-validation.js.map +1 -0
  57. package/dist/react/workflows/usage-format.d.ts +11 -0
  58. package/dist/react/workflows/usage-format.d.ts.map +1 -0
  59. package/dist/react/workflows/usage-format.js +43 -0
  60. package/dist/react/workflows/usage-format.js.map +1 -0
  61. package/dist/react/workflows/usage-scope.d.ts +5 -0
  62. package/dist/react/workflows/usage-scope.d.ts.map +1 -0
  63. package/dist/react/workflows/usage-scope.js +26 -0
  64. package/dist/react/workflows/usage-scope.js.map +1 -0
  65. package/dist/react/workflows/useUsageConfiguration.d.ts +4 -0
  66. package/dist/react/workflows/useUsageConfiguration.d.ts.map +1 -0
  67. package/dist/react/workflows/useUsageConfiguration.js +84 -0
  68. package/dist/react/workflows/useUsageConfiguration.js.map +1 -0
  69. package/docs/README.md +4 -0
  70. package/docs/react-api.md +6 -0
  71. package/docs/usage-configuration.md +150 -0
  72. package/docs/usage-react.md +182 -0
  73. package/package.json +4 -2
  74. package/src/client/usage/index.ts +3 -0
  75. package/src/react/index.ts +36 -0
  76. package/src/react/workflows/Pagination.tsx +2 -0
  77. package/src/react/workflows/Usage.fixtures.ts +88 -0
  78. package/src/react/workflows/Usage.test.tsx +373 -0
  79. package/src/react/workflows/Usage.types.ts +39 -0
  80. package/src/react/workflows/UsageAllowance.tsx +114 -0
  81. package/src/react/workflows/UsageBilling.tsx +90 -0
  82. package/src/react/workflows/UsageConfiguration.test.tsx +393 -0
  83. package/src/react/workflows/UsageConfiguration.tsx +135 -0
  84. package/src/react/workflows/UsageConfiguration.types.ts +67 -0
  85. package/src/react/workflows/UsageCredits.tsx +112 -0
  86. package/src/react/workflows/UsageHistory.test.tsx +206 -0
  87. package/src/react/workflows/UsageHistory.tsx +154 -0
  88. package/src/react/workflows/UsagePriceRow.test.tsx +140 -0
  89. package/src/react/workflows/UsagePriceRow.tsx +109 -0
  90. package/src/react/workflows/UsageSummary.tsx +204 -0
  91. package/src/react/workflows/usage-configuration-validation.test.ts +107 -0
  92. package/src/react/workflows/usage-configuration-validation.ts +152 -0
  93. package/src/react/workflows/usage-format.ts +48 -0
  94. package/src/react/workflows/usage-scope.ts +42 -0
  95. package/src/react/workflows/useUsageConfiguration.ts +99 -0
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UsageAvailability } from "../../client/usage/boundaries.js";
3
+ import type { UsageCreditBalance, UsageCreditPurchase } from "../../client/usage/creditTerms.js";
4
+ import type { UsageCreditReconciliation } from "../../client/usage/creditObservation.js";
5
+ export type UsageCreditsProps = {
6
+ balance: UsageAvailability<UsageCreditBalance> | undefined;
7
+ purchase?: UsageCreditPurchase | null;
8
+ currency?: string;
9
+ application?: UsageAvailability<UsageCreditReconciliation>;
10
+ className?: string;
11
+ children?: (state: Omit<UsageCreditsProps, "children" | "className">) => ReactNode;
12
+ };
13
+ export declare function UsageCredits({ balance, purchase, currency, application, children, className, }: UsageCreditsProps): import("react").JSX.Element;
14
+ //# sourceMappingURL=UsageCredits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageCredits.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/UsageCredits.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAEzF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,iBAAiB,CAAC,yBAAyB,CAAC,CAAC;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,WAAW,CAAC,KACrD,SAAS,CAAC;CAChB,CAAC;AACF,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,+BAqFnB"}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { formatUsageEstimate } from "./usage-format.js";
4
+ export function UsageCredits({ balance, purchase, currency, application, children, className, }) {
5
+ if (children)
6
+ return _jsx(_Fragment, { children: children({ balance, purchase, application, currency }) });
7
+ return (_jsxs("section", { "data-better-stripe": "usage-credits", className: className, "aria-label": "Prepaid credits", "aria-busy": balance === undefined, children: [_jsx("h2", { children: "Prepaid credits" }), !balance ? (_jsx("p", { role: "status", children: "Loading credit balance\u2026" })) : balance.status !== "available" ? (_jsxs("p", { role: "status", children: ["Credit balance ", balance.status, ". Verified backing is required."] })) : (_jsxs(_Fragment, { children: [_jsx("dl", { children: [
8
+ ["Available", balance.value.availableQuantity],
9
+ ["Reserved", balance.value.reservedQuantity],
10
+ ["Consumed", balance.value.consumedQuantity],
11
+ ["Expired", balance.value.expiredQuantity],
12
+ ["Frozen", balance.value.frozenQuantity],
13
+ ].map(([label, quantity]) => (_jsxs("div", { children: [_jsx("dt", { children: label }), _jsxs("dd", { children: [quantity, " ", balance.value.unit] })] }, label))) }), (balance.value.status === "held" ||
14
+ !/^0(?:\.0+)?$/.test(balance.value.frozenQuantity)) && (_jsx("p", { role: "status", children: "Credits held. Reconciliation is required." })), /^0(?:\.0+)?$/.test(balance.value.availableQuantity) && (_jsx("p", { role: "status", children: "Insufficient credits for new work. A server reservation must authorize consumption." }))] })), purchase && (_jsxs("p", { role: "status", children: [{
15
+ pending: "Payment pending. No units granted yet.",
16
+ ready: "Payment verified and original credit grant retained.",
17
+ frozen: "Purchase frozen. Recovery is required.",
18
+ canceled: "Purchase canceled.",
19
+ }[purchase.state], " ", "Purchase ", purchase.purchaseId, ": ", purchase.quantity, " units for", " ", formatUsageEstimate(String(purchase.amount), purchase.currency) ??
20
+ "unavailable amount", "."] })), application &&
21
+ (application.status === "available" ? (_jsxs("p", { role: "status", children: ["Credit application ", application.value.backing, ".", " ", application.value.reason
22
+ ? "Reconciliation is required."
23
+ : `Pending finalization amount: ${formatUsageEstimate(String(application.value.pendingFinalizationAmount), currency ?? (balance?.status === "available" ? balance.value.currency : purchase?.currency) ?? "") ?? "unavailable"}.`] })) : (_jsxs("p", { role: "status", children: ["Credit application ", application.status, ". Original invoice evidence is not yet verified."] }))), _jsx("p", { children: "No cash is collected by consuming credits. This balance is not withdrawable money." })] }));
24
+ }
25
+ //# sourceMappingURL=UsageCredits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageCredits.js","sourceRoot":"","sources":["../../../src/react/workflows/UsageCredits.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAQb,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAWxD,MAAM,UAAU,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,SAAS,GACS;IAClB,IAAI,QAAQ;QACV,OAAO,4BAAG,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,GAAI,CAAC;IACvE,OAAO,CACL,yCACqB,eAAe,EAClC,SAAS,EAAE,SAAS,gBACT,iBAAiB,eACjB,OAAO,KAAK,SAAS,aAEhC,2CAAwB,EACvB,CAAC,OAAO,CAAC,CAAC,CAAC,CACV,YAAG,IAAI,EAAC,QAAQ,6CAA4B,CAC7C,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,CACnC,aAAG,IAAI,EAAC,QAAQ,gCACE,OAAO,CAAC,MAAM,uCAC5B,CACL,CAAC,CAAC,CAAC,CACF,8BACE,uBAEI;4BACE,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC;4BAC9C,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC;4BAC5C,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC;4BAC5C,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC;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gC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,yBAAyB,CAAC,EAAE,QAAQ,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,aAAa,GAAG,IACjO,CACL,CAAC,CAAC,CAAC,CACF,aAAG,IAAI,EAAC,QAAQ,oCACM,WAAW,CAAC,MAAM,wDAEpC,CACL,CAAC,EACJ,6GAGI,IACI,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UsageAvailability } from "../../client/usage/boundaries.js";
3
+ import { type UsageViewScope } from "./Usage.types.js";
4
+ export type UsageHistoryPage<Row> = {
5
+ records: readonly Row[];
6
+ cursor: string | null;
7
+ isDone: boolean;
8
+ complete?: boolean;
9
+ };
10
+ export type UsageHistoryProps<Row> = {
11
+ scope: UsageViewScope;
12
+ /** Distinguish event, credit, allowance or delivery readers and their filters. */
13
+ historyKey: string;
14
+ load: (scope: UsageViewScope, page: {
15
+ cursor: string | null;
16
+ limit: number;
17
+ }) => Promise<UsageAvailability<UsageHistoryPage<Row>>>;
18
+ getKey: (record: Row) => string;
19
+ renderRecord: (record: Row) => ReactNode;
20
+ limit?: number;
21
+ label?: string;
22
+ className?: string;
23
+ children?: (state: ReturnType<typeof useUsageHistory<Row>>) => ReactNode;
24
+ };
25
+ export declare function useUsageHistory<Row>(props: Pick<UsageHistoryProps<Row>, "scope" | "historyKey" | "load" | "limit">): {
26
+ revision: number;
27
+ data: UsageAvailability<UsageHistoryPage<Row>> | undefined;
28
+ error: string | null;
29
+ isLoading: boolean;
30
+ refresh: () => void;
31
+ page: number;
32
+ canPrevious: boolean;
33
+ canNext: boolean;
34
+ isIncomplete: boolean;
35
+ isEmpty: boolean;
36
+ previous: () => void;
37
+ next: () => void;
38
+ };
39
+ export declare function UsageHistory<Row>(props: UsageHistoryProps<Row>): import("react").JSX.Element;
40
+ //# sourceMappingURL=UsageHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageHistory.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/UsageHistory.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAG1E,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,MAAM,MAAM,gBAAgB,CAAC,GAAG,IAAI;IAClC,OAAO,EAAE,SAAS,GAAG,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,iBAAiB,CAAC,GAAG,IAAI;IACnC,KAAK,EAAE,cAAc,CAAC;IACtB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,CACJ,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAC3C,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC;IAChC,YAAY,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,SAAS,CAAC;CAC1E,CAAC;AACF,wBAAgB,eAAe,CAAC,GAAG,EACjC,KAAK,EAAE,IAAI,CACT,iBAAiB,CAAC,GAAG,CAAC,EACtB,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,CAC1C;;;;;;;;;;;;;EA4DF;AACD,wBAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,+BAW9D"}
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useWorkflowResource } from "./useWorkflowResource.js";
4
+ import { Pagination, useCursorPagination } from "./Pagination.js";
5
+ import { usageViewKey } from "./Usage.types.js";
6
+ export function useUsageHistory(props) {
7
+ const limit = props.limit ?? 25;
8
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100)
9
+ throw new RangeError("Usage history page size must be 1–100");
10
+ const key = JSON.stringify([
11
+ usageViewKey(props.scope),
12
+ props.historyKey,
13
+ limit,
14
+ ]);
15
+ const navigation = useCursorPagination(key);
16
+ const resource = useWorkflowResource(async () => {
17
+ try {
18
+ const result = await props.load(props.scope, {
19
+ cursor: navigation.cursor,
20
+ limit,
21
+ });
22
+ if (result.status === "available" &&
23
+ (result.value.records.length > limit ||
24
+ (result.value.cursor !== null && result.value.cursor.length > 2048)))
25
+ throw new Error("Invalid history page");
26
+ return result;
27
+ }
28
+ catch {
29
+ throw new Error("History unavailable. Try again.");
30
+ }
31
+ }, JSON.stringify([key, navigation.cursor]));
32
+ const available = resource.data?.status === "available" ? resource.data.value : null;
33
+ const advancing = !!available &&
34
+ typeof available.cursor === "string" &&
35
+ available.cursor.length > 0 &&
36
+ !navigation.hasCursor(available.cursor);
37
+ const incomplete = available?.complete === false ||
38
+ (!!available && !available.isDone && !advancing);
39
+ const canNext = !!available && !available.isDone && advancing;
40
+ return {
41
+ ...resource,
42
+ page: navigation.page,
43
+ canPrevious: navigation.canPrevious,
44
+ canNext,
45
+ isIncomplete: incomplete,
46
+ isEmpty: !!available &&
47
+ available.records.length === 0 &&
48
+ available.isDone &&
49
+ !incomplete,
50
+ previous: () => {
51
+ if (!resource.isLoading)
52
+ navigation.previous();
53
+ },
54
+ next: () => {
55
+ if (!resource.isLoading && canNext)
56
+ navigation.next(available.cursor);
57
+ },
58
+ };
59
+ }
60
+ export function UsageHistory(props) {
61
+ return (_jsx(UsageHistoryBody, { ...props }, JSON.stringify([
62
+ usageViewKey(props.scope),
63
+ props.historyKey,
64
+ props.limit ?? 25,
65
+ ])));
66
+ }
67
+ function UsageHistoryBody(props) {
68
+ const state = useUsageHistory(props);
69
+ if (props.children)
70
+ return _jsx(_Fragment, { children: props.children(state) });
71
+ const available = state.data?.status === "available" ? state.data.value : null;
72
+ return (_jsxs("section", { "data-better-stripe": "usage-history", className: props.className, "aria-label": props.label ?? "Usage history", "aria-busy": state.isLoading, children: [_jsx("h2", { children: props.label ?? "Usage history" }), _jsx("button", { type: "button", disabled: state.isLoading, onClick: state.refresh, children: "Refresh history" }), state.isLoading && _jsx("p", { role: "status", children: "Loading history\u2026" }), (state.isLoading || state.error) && available && (_jsx("p", { role: "status", children: "Displayed history may be stale." })), state.error && _jsx("p", { role: "alert", children: state.error }), state.data && state.data.status !== "available" && (_jsxs("p", { role: "status", children: ["History ", state.data.status, ". Original scoped history is required."] })), state.isIncomplete && (_jsx("p", { role: "status", children: "History incomplete. This page does not establish complete totals." })), state.isEmpty && _jsx("p", { children: "No history for this view." }), available && (_jsx("ol", { children: available.records.map((record) => (_jsx("li", { children: props.renderRecord(record) }, props.getKey(record)))) })), _jsx(Pagination, { page: state.page, canPrevious: state.canPrevious, canNext: state.canNext, isLoading: state.isLoading, onPrevious: state.previous, onNext: state.next })] }));
73
+ }
74
+ //# sourceMappingURL=UsageHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageHistory.js","sourceRoot":"","sources":["../../../src/react/workflows/UsageHistory.ts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KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAClD,aAAG,IAAI,EAAC,QAAQ,yBACL,KAAK,CAAC,IAAI,CAAC,MAAM,8CACxB,CACL,EACA,KAAK,CAAC,YAAY,IAAI,CACrB,YAAG,IAAI,EAAC,QAAQ,kFAEZ,CACL,EACA,KAAK,CAAC,OAAO,IAAI,oDAAgC,EACjD,SAAS,IAAI,CACZ,uBACG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACjC,uBAAgC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,IAAjD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAmC,CACjE,CAAC,GACC,CACN,EACD,KAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,UAAU,EAAE,KAAK,CAAC,QAAQ,EAC1B,MAAM,EAAE,KAAK,CAAC,IAAI,GAClB,IACM,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UsagePriceBinding } from "../../client/usage/catalogRead.js";
3
+ import { type PriceCardPrice } from "../components/PriceCard.js";
4
+ export type UsageCatalogPrice = {
5
+ kind: "fixed";
6
+ price: PriceCardPrice & {
7
+ usageType?: string;
8
+ billingScheme?: string;
9
+ transformQuantity?: unknown;
10
+ };
11
+ } | {
12
+ kind: "metered";
13
+ price: UsagePriceBinding;
14
+ } | {
15
+ kind: "unsupported";
16
+ reason: "tiered" | "transformed" | "other";
17
+ };
18
+ export type UsagePriceRowProps = {
19
+ value: UsageCatalogPrice;
20
+ productName?: string;
21
+ className?: string;
22
+ children?: (value: UsageCatalogPrice) => ReactNode;
23
+ };
24
+ /** Read-only catalog row. Only managed metered bindings carry original exact terms. */
25
+ export declare function UsagePriceRow({ value, className, productName, children, }: UsagePriceRowProps): import("react").JSX.Element;
26
+ //# sourceMappingURL=UsagePriceRow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsagePriceRow.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/UsagePriceRow.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5E,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,cAAc,GAAG;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,CAAC;CACH,GACD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAA;CAAE,CAAC;AACxE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,iBAAiB,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,SAAS,CAAC;CACpD,CAAC;AACF,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,WAAW,EACX,QAAQ,GACT,EAAE,kBAAkB,+BA+EpB"}
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { PriceCard } from "../components/PriceCard.js";
4
+ import { chargeAmountToDecimal } from "../../client/charge-currency.js";
5
+ import { formatUsageEstimate } from "./usage-format.js";
6
+ /** Read-only catalog row. Only managed metered bindings carry original exact terms. */
7
+ export function UsagePriceRow({ value, className, productName, children, }) {
8
+ if (children)
9
+ return _jsx(_Fragment, { children: children(value) });
10
+ let contents;
11
+ if (value.kind === "fixed") {
12
+ const price = value.price;
13
+ const supported = price.unitAmount != null &&
14
+ Number.isSafeInteger(price.unitAmount) &&
15
+ price.unitAmount >= 0 &&
16
+ chargeAmountToDecimal(price.unitAmount, price.currency) !== null &&
17
+ price.usageType !== "metered" &&
18
+ (!price.billingScheme || price.billingScheme === "per_unit") &&
19
+ price.transformQuantity == null;
20
+ contents = supported ? (_jsxs(_Fragment, { children: [_jsx("p", { children: "Fixed price" }), _jsx(PriceCard, { price: price, children: ({ formattedPrice }) => _jsx("p", { children: formattedPrice }) })] })) : (_jsx("p", { children: "Unsupported pricing terms. Read the original provider terms before configuration." }));
21
+ }
22
+ else if (value.kind === "unsupported") {
23
+ contents = (_jsxs("p", { children: [value.reason === "tiered"
24
+ ? "Unsupported tiered pricing"
25
+ : value.reason === "transformed"
26
+ ? "Unsupported transformed pricing"
27
+ : "Unsupported pricing terms", ". No fixed or zero price is inferred."] }));
28
+ }
29
+ else {
30
+ const { plan } = value.price;
31
+ const amount = formatUsageEstimate(plan.rate.unitAmountDecimal, plan.rate.currency);
32
+ contents = (_jsxs(_Fragment, { children: [_jsx("p", { children: plan.model === "included_overage"
33
+ ? "Included monthly units plus overages"
34
+ : plan.model === "prepaid"
35
+ ? "Prepaid paid credits"
36
+ : "Pay as you go" }), _jsxs("p", { children: ["Version ", plan.version, ". Monthly billing, sum aggregation."] }), _jsxs("p", { children: [amount ? `${amount} per ${plan.unit.name}` : "Rate unavailable", ". Quantity precision ", plan.unit.precision, "."] }), plan.model === "included_overage" && (_jsxs("p", { children: [plan.includedQuantity, " included per billing period. Graduated free tier, then overages."] })), plan.model === "prepaid" && (_jsx("p", { children: "Payment-backed issuer credits. Consumption is not a second cash collection." })), _jsxs("p", { children: [value.price.active ? "Active" : "Inactive", " immutable price"] })] }));
37
+ }
38
+ return (_jsxs("div", { className: className, "data-better-stripe": "usage-price-row", children: [productName && _jsx("h3", { children: productName }), contents] }));
39
+ }
40
+ //# sourceMappingURL=UsagePriceRow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsagePriceRow.js","sourceRoot":"","sources":["../../../src/react/workflows/UsagePriceRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,SAAS,EAAuB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAkBxD,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,WAAW,EACX,QAAQ,GACW;IACnB,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,CAAC,KAAK,CAAC,GAAI,CAAC;IAC5C,IAAI,QAAmB,CAAC;IACxB,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC1B,MAAM,SAAS,GACb,KAAK,CAAC,UAAU,IAAI,IAAI;YACxB,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC;YACtC,KAAK,CAAC,UAAU,IAAI,CAAC;YACrB,qBAAqB,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI;YAChE,KAAK,CAAC,SAAS,KAAK,SAAS;YAC7B,CAAC,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,KAAK,UAAU,CAAC;YAC5D,KAAK,CAAC,iBAAiB,IAAI,IAAI,CAAC;QAClC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CACrB,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AI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,wBAAqB,IAClE,CACJ,CAAC;IACJ,CAAC;IACD,OAAO,CACL,eAAK,SAAS,EAAE,SAAS,wBAAqB,iBAAiB,aAC5D,WAAW,IAAI,uBAAK,WAAW,GAAM,EACrC,QAAQ,IACL,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UsageAvailability } from "../../client/usage/boundaries.js";
3
+ import type { UsageLocalSummary } from "../../client/usage/summary.js";
4
+ import type { UsageAggregateObservation } from "../../client/usage/observationTypes.js";
5
+ import type { UsageViewScope } from "./Usage.types.js";
6
+ export type UsageSummaryProps = {
7
+ scope: UsageViewScope;
8
+ summary: UsageAvailability<UsageLocalSummary> | undefined;
9
+ provider?: UsageAggregateObservation;
10
+ className?: string;
11
+ children?: (state: {
12
+ summary: UsageSummaryProps["summary"];
13
+ provider: UsageSummaryProps["provider"];
14
+ isLoading: boolean;
15
+ isEmpty: boolean;
16
+ }) => ReactNode;
17
+ };
18
+ export declare function UsageSummary(props: UsageSummaryProps): import("react").JSX.Element;
19
+ //# sourceMappingURL=UsageSummary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageSummary.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/UsageSummary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;QACjB,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACtC,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACxC,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;KAClB,KAAK,SAAS,CAAC;CACjB,CAAC;AAeF,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,+BAyKpD"}
@@ -0,0 +1,54 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { usageSummaryMatches } from "./usage-scope.js";
4
+ import { formatUsageEstimate, formatUsageTime } from "./usage-format.js";
5
+ const models = {
6
+ pay_as_you_go: "Pay as you go",
7
+ included_overage: "Included monthly usage with overages",
8
+ prepaid: "Prepaid credits",
9
+ };
10
+ const deliveryLabels = {
11
+ queued: "Queued delivery",
12
+ sending: "Sending delivery",
13
+ provider_accepted: "Provider accepted",
14
+ rejected: "Rejected delivery",
15
+ unknown: "Unknown delivery",
16
+ held: "Held delivery",
17
+ canceled: "Canceled usage",
18
+ };
19
+ export function UsageSummary(props) {
20
+ const provider = props.provider?.status === "available" &&
21
+ (props.provider.value.period.start !== props.scope.period.start ||
22
+ props.provider.value.period.end !== props.scope.period.end)
23
+ ? {
24
+ status: "unavailable",
25
+ reason: "observation_scope_mismatch",
26
+ retryable: true,
27
+ }
28
+ : props.provider;
29
+ const summary = props.summary?.status === "available" &&
30
+ !usageSummaryMatches(props.scope, props.summary.value)
31
+ ? {
32
+ status: "unavailable",
33
+ reason: "observation_scope_mismatch",
34
+ retryable: true,
35
+ }
36
+ : props.summary;
37
+ const available = summary?.status === "available" ? summary.value : null;
38
+ if (props.children)
39
+ return (_jsx(_Fragment, { children: props.children({
40
+ summary,
41
+ provider,
42
+ isLoading: summary === undefined,
43
+ isEmpty: !!available?.complete && available.eventCount === 0,
44
+ }) }));
45
+ return (_jsxs("section", { "data-better-stripe": "usage-summary", className: props.className, "aria-label": "Usage summary", "aria-busy": summary === undefined, children: [_jsx("h2", { children: "Usage by meter" }), !summary ? (_jsx("p", { role: "status", children: "Loading usage\u2026" })) : summary.status !== "available" ? (_jsxs("p", { role: "status", children: ["Usage ", summary.status, ". Refresh when original usage evidence is available."] })) : (_jsxs(_Fragment, { children: [_jsxs("p", { children: ["Period ", formatUsageTime(summary.value.period.start), " to", " ", formatUsageTime(summary.value.period.end)] }), !summary.value.complete && (_jsx("p", { role: "status", children: "Local history incomplete. Totals are partial." })), summary.value.complete && summary.value.eventCount === 0 && (_jsx("p", { children: "No usage in this period." })), summary.value.groups.map((group) => (_jsxs("article", { "data-billing-model": group.binding.plan.model, children: [_jsxs("h3", { children: [group.binding.plan.unit.name, " \u00B7", " ", models[group.binding.plan.model]] }), _jsxs("p", { children: ["Plan ", group.binding.plan.key, ", version", " ", group.binding.plan.version] }), _jsxs("dl", { children: [_jsx("dt", { children: "Accepted usage" }), _jsxs("dd", { children: [group.acceptedQuantity, " ", group.binding.plan.unit.name] }), _jsx("dt", { children: "Billable after corrections" }), _jsxs("dd", { children: [group.effectiveQuantity, " ", group.binding.plan.unit.name] }), _jsx("dt", { children: "Provider accepted" }), _jsxs("dd", { children: [group.providerAcceptedQuantity, " ", group.binding.plan.unit.name] }), Object.entries(group.deliveryQuantities)
46
+ .filter(([kind, quantity]) => kind !== "provider_accepted" &&
47
+ !/^0(?:\.0+)?$/.test(quantity))
48
+ .map(([kind, quantity]) => (_jsxs("div", { children: [_jsx("dt", { children: deliveryLabels[kind] }), _jsxs("dd", { children: [quantity, " ", group.binding.plan.unit.name] })] }, kind)))] }), group.validationErrorEventCount > 0 && (_jsxs("p", { role: "status", children: ["Native validation rejected ", group.validationErrorEventCount, " ", "event(s)."] })), group.estimate.status === "available" ? (_jsxs("p", { children: ["Estimated usage charge:", " ", formatUsageEstimate(group.estimate.value.amountDecimal, group.estimate.value.currency) ?? "Unavailable"] })) : (_jsxs("p", { children: ["Estimate ", group.estimate.status, ". Complete original usage and pricing evidence is required."] })), group.included.status === "available" && (_jsxs("dl", { children: [_jsx("dt", { children: "Included units" }), _jsx("dd", { children: group.included.value.included }), _jsx("dt", { children: "Remaining included units" }), _jsx("dd", { children: group.included.value.remaining }), _jsx("dt", { children: "Overage units" }), _jsx("dd", { children: group.included.value.overage })] }))] }, JSON.stringify([
49
+ group.binding.stripePriceId,
50
+ group.subscription.subscriptionItemId,
51
+ group.subscription.period,
52
+ ])))), _jsx("p", { children: "Estimate only. Finalized invoices and verified payments determine billing." })] })), !provider || provider.status !== "available" ? (_jsxs("p", { role: "status", children: ["Native aggregation ", provider?.status ?? "unavailable", ". Refresh after provider ingestion."] })) : (_jsxs(_Fragment, { children: [_jsxs("p", { children: ["Native aggregate: ", provider.value.quantity] }), provider.value.stale && (_jsx("p", { role: "status", children: "Native aggregation stale." })), !provider.value.complete && (_jsx("p", { role: "status", children: "Native aggregation partial. More provider pages remain." })), _jsx("p", { children: "Aggregation may be delayed. Provider acceptance does not prove ingestion or payment." })] }))] }));
53
+ }
54
+ //# sourceMappingURL=UsageSummary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageSummary.js","sourceRoot":"","sources":["../../../src/react/workflows/UsageSummary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAazE,MAAM,MAAM,GAAG;IACb,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,sCAAsC;IACxD,OAAO,EAAE,iBAAiB;CAC3B,CAAC;AACF,MAAM,cAAc,GAAG;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Q,CAAC,MAAM,mEAE7B,CACL,EACA,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,WAAW,IAAI,CACxC,yBACE,0CAAuB,EACvB,uBAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAM,EACxC,oDAAiC,EACjC,uBAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,GAAM,EACzC,yCAAsB,EACtB,uBAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAM,IACpC,CACN,KA3EI,IAAI,CAAC,SAAS,CAAC;wBAClB,KAAK,CAAC,OAAO,CAAC,aAAa;wBAC3B,KAAK,CAAC,YAAY,CAAC,kBAAkB;wBACrC,KAAK,CAAC,YAAY,CAAC,MAAM;qBAC1B,CAAC,CAwEM,CACX,CAAC,EACF,qGAGI,IACH,CACJ,EACA,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,CAC9C,aAAG,IAAI,EAAC,QAAQ,oCACM,QAAQ,EAAE,MAAM,IAAI,aAAa,2CAEnD,CACL,CAAC,CAAC,CAAC,CACF,8BACE,8CAAsB,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAAK,EACjD,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,CACvB,YAAG,IAAI,EAAC,QAAQ,0CAA8B,CAC/C,EACA,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAAI,CAC3B,YAAG,IAAI,EAAC,QAAQ,wEAEZ,CACL,EACD,+GAGI,IACH,CACJ,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { UsageConfigurationFields, UsageConfigurationValue } from "./UsageConfiguration.types.js";
2
+ export declare function configurationFields(value: UsageConfigurationValue): UsageConfigurationFields;
3
+ export declare function validateConfiguration(fields: UsageConfigurationFields, meterId?: string): UsageConfigurationValue;
4
+ //# sourceMappingURL=usage-configuration-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-configuration-validation.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/usage-configuration-validation.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AAkBvC,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,uBAAuB,GAC7B,wBAAwB,CA0B1B;AACD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,MAAM,GACf,uBAAuB,CAwFzB"}
@@ -0,0 +1,116 @@
1
+ import { chargeAmountToDecimal, getChargeCurrencyMetadata, } from "../../client/charge-currency.js";
2
+ import { defineUsagePlan, parseUsageQuantity, } from "../../client/usage/contracts.js";
3
+ import { scaledUsageRate } from "../../client/usage/catalogMath.js";
4
+ import { creditCost } from "../../client/usage/creditTerms.js";
5
+ function invalid(message) {
6
+ throw new Error(message);
7
+ }
8
+ /** Exact major-currency input to the existing decimal minor-unit rate contract. */
9
+ function minorRate(price, currency) {
10
+ const metadata = getChargeCurrencyMetadata(currency);
11
+ if (!metadata)
12
+ return invalid("Choose a supported charge currency.");
13
+ if (!/^(0|[1-9]\d{0,13})(\.\d{1,14})?$/.test(price))
14
+ return invalid("Enter a nonnegative decimal price without rounding.");
15
+ const [whole, fraction = ""] = price.split(".");
16
+ const padded = fraction.padEnd(metadata.apiDecimals, "0");
17
+ const integer = BigInt(whole + padded.slice(0, metadata.apiDecimals)).toString();
18
+ const decimal = padded.slice(metadata.apiDecimals).replace(/0+$/, "");
19
+ return decimal ? `${integer}.${decimal}` : integer;
20
+ }
21
+ export function configurationFields(value) {
22
+ const { plan } = value;
23
+ const metadata = getChargeCurrencyMetadata(plan.rate.currency);
24
+ const [whole, fraction = ""] = plan.rate.unitAmountDecimal.split(".");
25
+ const scale = (metadata?.apiDecimals ?? 0) + fraction.length;
26
+ const digits = (whole + fraction).padStart(scale + 1, "0");
27
+ const integer = BigInt(scale ? digits.slice(0, -scale) : digits).toString();
28
+ const decimal = (scale ? digits.slice(-scale) : "").replace(/0+$/, "");
29
+ const formatted = metadata
30
+ ? integer +
31
+ (decimal ? `.${decimal}` : metadata.displayDecimals ? ".00" : "")
32
+ : "";
33
+ return {
34
+ model: plan.model,
35
+ key: plan.key,
36
+ version: plan.version,
37
+ unit: plan.unit.name,
38
+ precision: String(plan.unit.precision),
39
+ currency: plan.rate.currency,
40
+ price: formatted,
41
+ included: plan.model === "included_overage" ? plan.includedQuantity : "1000",
42
+ packageQuantity: value.creditPackage?.quantity ?? "100",
43
+ eventName: value.eventName,
44
+ displayName: value.displayName,
45
+ };
46
+ }
47
+ export function validateConfiguration(fields, meterId) {
48
+ const precision = Number(fields.precision);
49
+ if (!/^[0-6]$/.test(fields.precision))
50
+ return invalid("Quantity precision must be between 0 and 6.");
51
+ if (!fields.key.trim() ||
52
+ fields.key.length > 100 ||
53
+ !fields.version.trim() ||
54
+ fields.version.length > 100)
55
+ return invalid("Enter a plan key and a new version, each at most 100 characters.");
56
+ if (!fields.unit.trim() || fields.unit.length > 100)
57
+ return invalid("Enter a billable unit name of at most 100 characters.");
58
+ if (!/^[\w.-]{1,100}$/.test(fields.eventName) ||
59
+ !fields.displayName.trim() ||
60
+ fields.displayName.length > 100)
61
+ return invalid("Enter a valid meter event name and display name, each at most 100 characters.");
62
+ const currency = fields.currency.toLowerCase();
63
+ const rate = minorRate(fields.price, currency);
64
+ try {
65
+ scaledUsageRate(rate, precision);
66
+ }
67
+ catch {
68
+ return invalid("The rate exceeds native decimal precision or amount bounds. Change the rate or quantity precision.");
69
+ }
70
+ const common = {
71
+ key: fields.key,
72
+ version: fields.version,
73
+ unit: { name: fields.unit, precision },
74
+ rate: { currency, unitAmountDecimal: rate },
75
+ };
76
+ if (fields.model === "included_overage") {
77
+ try {
78
+ const included = BigInt(parseUsageQuantity(fields.included, precision).scaledQuantity);
79
+ if (included < 1n || included > BigInt(Number.MAX_SAFE_INTEGER))
80
+ throw new Error();
81
+ }
82
+ catch {
83
+ return invalid("Included units must be positive, exact at the selected precision and within native tier bounds.");
84
+ }
85
+ }
86
+ const plan = defineUsagePlan(fields.model === "included_overage"
87
+ ? {
88
+ ...common,
89
+ model: fields.model,
90
+ includedQuantity: fields.included,
91
+ reset: "billing_period",
92
+ }
93
+ : fields.model === "prepaid"
94
+ ? { ...common, model: fields.model, insufficientBalance: "reject" }
95
+ : { ...common, model: fields.model });
96
+ let creditPackage;
97
+ if (plan.model === "prepaid") {
98
+ try {
99
+ const quantity = parseUsageQuantity(fields.packageQuantity, precision);
100
+ if (chargeAmountToDecimal(creditCost(plan, quantity.scaledQuantity), currency) === null)
101
+ throw new Error();
102
+ creditPackage = { quantity: quantity.quantity, topUp: "manual" };
103
+ }
104
+ catch {
105
+ return invalid("Paid credits require a positive package quantity with whole minor currency backing and supported charge increments, within the native payment bound.");
106
+ }
107
+ }
108
+ return {
109
+ plan,
110
+ eventName: fields.eventName,
111
+ displayName: fields.displayName,
112
+ ...(meterId ? { meterId } : {}),
113
+ ...(creditPackage ? { creditPackage } : {}),
114
+ };
115
+ }
116
+ //# sourceMappingURL=usage-configuration-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-configuration-validation.js","sourceRoot":"","sources":["../../../src/react/workflows/usage-configuration-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAK/D,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AACD,mFAAmF;AACnF,SAAS,SAAS,CAAC,KAAa,EAAE,QAAgB;IAChD,MAAM,QAAQ,GAAG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,cAAc,CAAC,EACzC,QAAQ,CACT,KAAK,IAAI;gBAEV,MAAM,IAAI,KAAK,EAAE,CAAC;YACpB,aAAa,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACnE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,OAAO,CACZ,sJAAsJ,CACvJ,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Native metered rates/estimates use minor currency decimals. Preserve fractional cents and large quantities. */
2
+ export declare function formatUsageEstimate(amountDecimal: string, currency: string): string | null;
3
+ /** Normalize only the visual progress position; keep all visible quantities exact. */
4
+ export declare function allowanceProgress(value: {
5
+ consumedQuantity: string;
6
+ reservedQuantity: string;
7
+ includedQuantity: string;
8
+ }): number | null;
9
+ /** Numeric usage periods can exceed Date's supported display range. */
10
+ export declare function formatUsageTime(seconds: number): string;
11
+ //# sourceMappingURL=usage-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-format.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/usage-format.ts"],"names":[],"mappings":"AACA,kHAAkH;AAClH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAYf;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,GAAG,IAAI,CAehB;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKvD"}
@@ -0,0 +1,43 @@
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(amountDecimal, currency) {
4
+ const metadata = getChargeCurrencyMetadata(currency);
5
+ if (!metadata || !/^\d+(?:\.\d+)?$/.test(amountDecimal))
6
+ return null;
7
+ const [whole, fraction = ""] = amountDecimal.split(".");
8
+ const digits = (whole + fraction).replace(/^0+(?=\d)/, "");
9
+ const scale = metadata.apiDecimals + fraction.length;
10
+ const padded = digits.padStart(scale + 1, "0");
11
+ const major = scale ? padded.slice(0, -scale) : padded;
12
+ let minor = scale ? padded.slice(-scale).replace(/0+$/, "") : "";
13
+ if (metadata.displayDecimals === 0 && minor)
14
+ return null;
15
+ minor = minor.padEnd(metadata.displayDecimals, "0");
16
+ return `${major}${minor ? "." + minor : ""} ${metadata.currency.toUpperCase()}`;
17
+ }
18
+ /** Normalize only the visual progress position; keep all visible quantities exact. */
19
+ export function allowanceProgress(value) {
20
+ const quantities = [
21
+ value.consumedQuantity,
22
+ value.reservedQuantity,
23
+ value.includedQuantity,
24
+ ];
25
+ if (quantities.some((quantity) => !/^\d{1,18}(?:\.\d{1,6})?$/.test(quantity)))
26
+ return null;
27
+ const [consumed, reserved, included] = quantities.map((quantity) => {
28
+ const [whole, fraction = ""] = quantity.split(".");
29
+ return BigInt(whole + fraction.padEnd(6, "0"));
30
+ });
31
+ if (included === 0n)
32
+ return null;
33
+ const ratio = ((consumed + reserved) * 10000n) / included;
34
+ return Number(ratio > 10000n ? 10000n : ratio);
35
+ }
36
+ /** Numeric usage periods can exceed Date's supported display range. */
37
+ export function formatUsageTime(seconds) {
38
+ const value = new Date(seconds * 1000);
39
+ return Number.isFinite(value.getTime())
40
+ ? value.toISOString()
41
+ : "Time unavailable";
42
+ }
43
+ //# sourceMappingURL=usage-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-format.js","sourceRoot":"","sources":["../../../src/react/workflows/usage-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,kHAAkH;AAClH,MAAM,UAAU,mBAAmB,CACjC,aAAqB,EACrB,QAAgB;IAEhB,MAAM,QAAQ,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC;IACrD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvD,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,IAAI,QAAQ,CAAC,eAAe,KAAK,CAAC,IAAI,KAAK;QAAE,OAAO,IAAI,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AAM,KAAK,GAAG,IAAI,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACrC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE;QACrB,CAAC,CAAC,kBAAkB,CAAC;AACzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { UsageBillingSnapshot, UsageViewScope } from "./Usage.types.js";
2
+ import type { UsageLocalSummary } from "../../client/usage/summary.js";
3
+ export declare function usageSummaryMatches(scope: UsageViewScope, value: UsageLocalSummary): boolean;
4
+ export declare function usageSnapshotMatches(scope: UsageViewScope, value: UsageBillingSnapshot): boolean;
5
+ //# sourceMappingURL=usage-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-scope.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/usage-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,iBAAiB,WAczB;AACD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,oBAAoB,WAoB5B"}
@@ -0,0 +1,26 @@
1
+ export function usageSummaryMatches(scope, value) {
2
+ return (value.period.start === scope.period.start &&
3
+ value.period.end === scope.period.end &&
4
+ value.groups.every((group) => group.binding.plan.rate.currency.toLowerCase() ===
5
+ scope.currency.toLowerCase() &&
6
+ (group.estimate.status !== "available" ||
7
+ group.estimate.value.currency.toLowerCase() ===
8
+ scope.currency.toLowerCase())));
9
+ }
10
+ export function usageSnapshotMatches(scope, value) {
11
+ const periodMatches = (period) => period.start === scope.period.start && period.end === scope.period.end;
12
+ const currencyMatches = (currency) => currency.toLowerCase() === scope.currency.toLowerCase();
13
+ return ((value.summary.status !== "available" ||
14
+ usageSummaryMatches(scope, value.summary.value)) &&
15
+ (value.provider?.status !== "available" ||
16
+ periodMatches(value.provider.value.period)) &&
17
+ (value.allowance?.status !== "available" ||
18
+ !value.allowance.value ||
19
+ (periodMatches(value.allowance.value.period) &&
20
+ currencyMatches(value.allowance.value.committedEstimate.currency) &&
21
+ currencyMatches(value.allowance.value.projectedEstimate.currency))) &&
22
+ (value.credits?.status !== "available" ||
23
+ currencyMatches(value.credits.value.currency)) &&
24
+ (!value.purchase || currencyMatches(value.purchase.currency)));
25
+ }
26
+ //# sourceMappingURL=usage-scope.js.map