@ai-billing/nextjs 0.0.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 (93) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +50 -0
  3. package/dist/index.cjs +36 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +4 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +10 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/polar/CreditTopUpPolar.cjs +278 -0
  10. package/dist/polar/CreditTopUpPolar.cjs.map +1 -0
  11. package/dist/polar/CreditTopUpPolar.d.cts +9 -0
  12. package/dist/polar/CreditTopUpPolar.d.ts +9 -0
  13. package/dist/polar/CreditTopUpPolar.js +244 -0
  14. package/dist/polar/CreditTopUpPolar.js.map +1 -0
  15. package/dist/polar/CreditUsagePolar.cjs +133 -0
  16. package/dist/polar/CreditUsagePolar.cjs.map +1 -0
  17. package/dist/polar/CreditUsagePolar.d.cts +10 -0
  18. package/dist/polar/CreditUsagePolar.d.ts +10 -0
  19. package/dist/polar/CreditUsagePolar.js +107 -0
  20. package/dist/polar/CreditUsagePolar.js.map +1 -0
  21. package/dist/polar/createCheckout.cjs +47 -0
  22. package/dist/polar/createCheckout.cjs.map +1 -0
  23. package/dist/polar/createCheckout.d.cts +9 -0
  24. package/dist/polar/createCheckout.d.ts +9 -0
  25. package/dist/polar/createCheckout.js +23 -0
  26. package/dist/polar/createCheckout.js.map +1 -0
  27. package/dist/polar/fetchPolarConfig.cjs +52 -0
  28. package/dist/polar/fetchPolarConfig.cjs.map +1 -0
  29. package/dist/polar/fetchPolarConfig.d.cts +6 -0
  30. package/dist/polar/fetchPolarConfig.d.ts +6 -0
  31. package/dist/polar/fetchPolarConfig.js +28 -0
  32. package/dist/polar/fetchPolarConfig.js.map +1 -0
  33. package/dist/polar/fetchPolarUsage.cjs +64 -0
  34. package/dist/polar/fetchPolarUsage.cjs.map +1 -0
  35. package/dist/polar/fetchPolarUsage.d.cts +9 -0
  36. package/dist/polar/fetchPolarUsage.d.ts +9 -0
  37. package/dist/polar/fetchPolarUsage.js +40 -0
  38. package/dist/polar/fetchPolarUsage.js.map +1 -0
  39. package/dist/polar/fetchTopUpConfig.cjs +55 -0
  40. package/dist/polar/fetchTopUpConfig.cjs.map +1 -0
  41. package/dist/polar/fetchTopUpConfig.d.cts +10 -0
  42. package/dist/polar/fetchTopUpConfig.d.ts +10 -0
  43. package/dist/polar/fetchTopUpConfig.js +31 -0
  44. package/dist/polar/fetchTopUpConfig.js.map +1 -0
  45. package/dist/polar/types.cjs +17 -0
  46. package/dist/polar/types.cjs.map +1 -0
  47. package/dist/polar/types.d.cts +18 -0
  48. package/dist/polar/types.d.ts +18 -0
  49. package/dist/polar/types.js +1 -0
  50. package/dist/polar/types.js.map +1 -0
  51. package/dist/server.cjs +44 -0
  52. package/dist/server.cjs.map +1 -0
  53. package/dist/server.d.cts +8 -0
  54. package/dist/server.d.ts +8 -0
  55. package/dist/server.js +15 -0
  56. package/dist/server.js.map +1 -0
  57. package/dist/stripe/CreditUsageStripe.cjs +158 -0
  58. package/dist/stripe/CreditUsageStripe.cjs.map +1 -0
  59. package/dist/stripe/CreditUsageStripe.d.cts +11 -0
  60. package/dist/stripe/CreditUsageStripe.d.ts +11 -0
  61. package/dist/stripe/CreditUsageStripe.js +132 -0
  62. package/dist/stripe/CreditUsageStripe.js.map +1 -0
  63. package/dist/stripe/fetchStripeConfig.cjs +52 -0
  64. package/dist/stripe/fetchStripeConfig.cjs.map +1 -0
  65. package/dist/stripe/fetchStripeConfig.d.cts +6 -0
  66. package/dist/stripe/fetchStripeConfig.d.ts +6 -0
  67. package/dist/stripe/fetchStripeConfig.js +28 -0
  68. package/dist/stripe/fetchStripeConfig.js.map +1 -0
  69. package/dist/stripe/fetchStripeUsage.cjs +67 -0
  70. package/dist/stripe/fetchStripeUsage.cjs.map +1 -0
  71. package/dist/stripe/fetchStripeUsage.d.cts +9 -0
  72. package/dist/stripe/fetchStripeUsage.d.ts +9 -0
  73. package/dist/stripe/fetchStripeUsage.js +33 -0
  74. package/dist/stripe/fetchStripeUsage.js.map +1 -0
  75. package/dist/stripe/types.cjs +17 -0
  76. package/dist/stripe/types.cjs.map +1 -0
  77. package/dist/stripe/types.d.cts +9 -0
  78. package/dist/stripe/types.d.ts +9 -0
  79. package/dist/stripe/types.js +1 -0
  80. package/dist/stripe/types.js.map +1 -0
  81. package/dist/styles.cjs +83 -0
  82. package/dist/styles.cjs.map +1 -0
  83. package/dist/styles.d.cts +11 -0
  84. package/dist/styles.d.ts +11 -0
  85. package/dist/styles.js +53 -0
  86. package/dist/styles.js.map +1 -0
  87. package/dist/utils.cjs +53 -0
  88. package/dist/utils.cjs.map +1 -0
  89. package/dist/utils.d.cts +20 -0
  90. package/dist/utils.d.ts +20 -0
  91. package/dist/utils.js +26 -0
  92. package/dist/utils.js.map +1 -0
  93. package/package.json +82 -0
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var styles_exports = {};
20
+ __export(styles_exports, {
21
+ barLabels: () => barLabels,
22
+ barTrack: () => barTrack,
23
+ bigNumber: () => bigNumber,
24
+ cardBase: () => cardBase,
25
+ heading: () => heading,
26
+ mutedText: () => mutedText,
27
+ subLabel: () => subLabel
28
+ });
29
+ module.exports = __toCommonJS(styles_exports);
30
+ const cardBase = {
31
+ fontFamily: "inherit",
32
+ width: "100%",
33
+ boxSizing: "border-box",
34
+ background: "var(--card)",
35
+ color: "var(--card-foreground)",
36
+ border: "1px solid var(--border)",
37
+ borderRadius: "var(--radius, 0.75rem)",
38
+ padding: "20px 24px"
39
+ };
40
+ const heading = {
41
+ margin: "0 0 4px",
42
+ fontSize: "13px",
43
+ color: "var(--muted-foreground)"
44
+ };
45
+ const mutedText = {
46
+ margin: 0,
47
+ fontSize: "13px",
48
+ color: "var(--muted-foreground)"
49
+ };
50
+ const bigNumber = {
51
+ fontSize: "28px",
52
+ fontWeight: 700,
53
+ color: "var(--foreground)",
54
+ letterSpacing: "-0.5px"
55
+ };
56
+ const subLabel = {
57
+ fontSize: "14px",
58
+ color: "var(--muted-foreground)"
59
+ };
60
+ const barTrack = {
61
+ height: "6px",
62
+ borderRadius: "3px",
63
+ background: "var(--muted)",
64
+ overflow: "hidden",
65
+ marginBottom: "8px"
66
+ };
67
+ const barLabels = {
68
+ display: "flex",
69
+ justifyContent: "space-between",
70
+ fontSize: "12px",
71
+ color: "var(--muted-foreground)"
72
+ };
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ barLabels,
76
+ barTrack,
77
+ bigNumber,
78
+ cardBase,
79
+ heading,
80
+ mutedText,
81
+ subLabel
82
+ });
83
+ //# sourceMappingURL=styles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styles.ts"],"sourcesContent":["import type React from 'react';\n\nexport const cardBase: React.CSSProperties = {\n fontFamily: 'inherit',\n width: '100%',\n boxSizing: 'border-box',\n background: 'var(--card)',\n color: 'var(--card-foreground)',\n border: '1px solid var(--border)',\n borderRadius: 'var(--radius, 0.75rem)',\n padding: '20px 24px',\n};\n\nexport const heading: React.CSSProperties = {\n margin: '0 0 4px',\n fontSize: '13px',\n color: 'var(--muted-foreground)',\n};\n\nexport const mutedText: React.CSSProperties = {\n margin: 0,\n fontSize: '13px',\n color: 'var(--muted-foreground)',\n};\n\nexport const bigNumber: React.CSSProperties = {\n fontSize: '28px',\n fontWeight: 700,\n color: 'var(--foreground)',\n letterSpacing: '-0.5px',\n};\n\nexport const subLabel: React.CSSProperties = {\n fontSize: '14px',\n color: 'var(--muted-foreground)',\n};\n\nexport const barTrack: React.CSSProperties = {\n height: '6px',\n borderRadius: '3px',\n background: 'var(--muted)',\n overflow: 'hidden',\n marginBottom: '8px',\n};\n\nexport const barLabels: React.CSSProperties = {\n display: 'flex',\n justifyContent: 'space-between',\n fontSize: '12px',\n color: 'var(--muted-foreground)',\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,WAAgC;AAAA,EAC3C,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,SAAS;AACX;AAEO,MAAM,UAA+B;AAAA,EAC1C,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,YAAiC;AAAA,EAC5C,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,YAAiC;AAAA,EAC5C,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,eAAe;AACjB;AAEO,MAAM,WAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,WAAgC;AAAA,EAC3C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,cAAc;AAChB;AAEO,MAAM,YAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,OAAO;AACT;","names":[]}
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ declare const cardBase: React.CSSProperties;
4
+ declare const heading: React.CSSProperties;
5
+ declare const mutedText: React.CSSProperties;
6
+ declare const bigNumber: React.CSSProperties;
7
+ declare const subLabel: React.CSSProperties;
8
+ declare const barTrack: React.CSSProperties;
9
+ declare const barLabels: React.CSSProperties;
10
+
11
+ export { barLabels, barTrack, bigNumber, cardBase, heading, mutedText, subLabel };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ declare const cardBase: React.CSSProperties;
4
+ declare const heading: React.CSSProperties;
5
+ declare const mutedText: React.CSSProperties;
6
+ declare const bigNumber: React.CSSProperties;
7
+ declare const subLabel: React.CSSProperties;
8
+ declare const barTrack: React.CSSProperties;
9
+ declare const barLabels: React.CSSProperties;
10
+
11
+ export { barLabels, barTrack, bigNumber, cardBase, heading, mutedText, subLabel };
package/dist/styles.js ADDED
@@ -0,0 +1,53 @@
1
+ const cardBase = {
2
+ fontFamily: "inherit",
3
+ width: "100%",
4
+ boxSizing: "border-box",
5
+ background: "var(--card)",
6
+ color: "var(--card-foreground)",
7
+ border: "1px solid var(--border)",
8
+ borderRadius: "var(--radius, 0.75rem)",
9
+ padding: "20px 24px"
10
+ };
11
+ const heading = {
12
+ margin: "0 0 4px",
13
+ fontSize: "13px",
14
+ color: "var(--muted-foreground)"
15
+ };
16
+ const mutedText = {
17
+ margin: 0,
18
+ fontSize: "13px",
19
+ color: "var(--muted-foreground)"
20
+ };
21
+ const bigNumber = {
22
+ fontSize: "28px",
23
+ fontWeight: 700,
24
+ color: "var(--foreground)",
25
+ letterSpacing: "-0.5px"
26
+ };
27
+ const subLabel = {
28
+ fontSize: "14px",
29
+ color: "var(--muted-foreground)"
30
+ };
31
+ const barTrack = {
32
+ height: "6px",
33
+ borderRadius: "3px",
34
+ background: "var(--muted)",
35
+ overflow: "hidden",
36
+ marginBottom: "8px"
37
+ };
38
+ const barLabels = {
39
+ display: "flex",
40
+ justifyContent: "space-between",
41
+ fontSize: "12px",
42
+ color: "var(--muted-foreground)"
43
+ };
44
+ export {
45
+ barLabels,
46
+ barTrack,
47
+ bigNumber,
48
+ cardBase,
49
+ heading,
50
+ mutedText,
51
+ subLabel
52
+ };
53
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styles.ts"],"sourcesContent":["import type React from 'react';\n\nexport const cardBase: React.CSSProperties = {\n fontFamily: 'inherit',\n width: '100%',\n boxSizing: 'border-box',\n background: 'var(--card)',\n color: 'var(--card-foreground)',\n border: '1px solid var(--border)',\n borderRadius: 'var(--radius, 0.75rem)',\n padding: '20px 24px',\n};\n\nexport const heading: React.CSSProperties = {\n margin: '0 0 4px',\n fontSize: '13px',\n color: 'var(--muted-foreground)',\n};\n\nexport const mutedText: React.CSSProperties = {\n margin: 0,\n fontSize: '13px',\n color: 'var(--muted-foreground)',\n};\n\nexport const bigNumber: React.CSSProperties = {\n fontSize: '28px',\n fontWeight: 700,\n color: 'var(--foreground)',\n letterSpacing: '-0.5px',\n};\n\nexport const subLabel: React.CSSProperties = {\n fontSize: '14px',\n color: 'var(--muted-foreground)',\n};\n\nexport const barTrack: React.CSSProperties = {\n height: '6px',\n borderRadius: '3px',\n background: 'var(--muted)',\n overflow: 'hidden',\n marginBottom: '8px',\n};\n\nexport const barLabels: React.CSSProperties = {\n display: 'flex',\n justifyContent: 'space-between',\n fontSize: '12px',\n color: 'var(--muted-foreground)',\n};\n"],"mappings":"AAEO,MAAM,WAAgC;AAAA,EAC3C,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,SAAS;AACX;AAEO,MAAM,UAA+B;AAAA,EAC1C,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,YAAiC;AAAA,EAC5C,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,YAAiC;AAAA,EAC5C,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,eAAe;AACjB;AAEO,MAAM,WAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,OAAO;AACT;AAEO,MAAM,WAAgC;AAAA,EAC3C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,cAAc;AAChB;AAEO,MAAM,YAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,OAAO;AACT;","names":[]}
package/dist/utils.cjs ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var utils_exports = {};
20
+ __export(utils_exports, {
21
+ barColor: () => barColor,
22
+ fmt: () => fmt,
23
+ formatCents: () => formatCents,
24
+ taxMessages: () => taxMessages
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ function barColor(pct) {
28
+ if (pct >= 90) return "#ef4444";
29
+ if (pct >= 70) return "#f59e0b";
30
+ return "#22c55e";
31
+ }
32
+ function formatCents(cents) {
33
+ return `$${Math.round(cents / 100)}`;
34
+ }
35
+ function fmt(val, unit) {
36
+ const s = val.toLocaleString(void 0, { maximumFractionDigits: 9 });
37
+ if (unit === "$") return `$${s}`;
38
+ if (unit) return `${s} ${unit}`;
39
+ return s;
40
+ }
41
+ const taxMessages = {
42
+ inclusive: "Prices include tax",
43
+ exclusive: "Prices do not include tax. Tax will be added at checkout.",
44
+ location: "Tax calculated at checkout based on your location."
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ barColor,
49
+ fmt,
50
+ formatCents,
51
+ taxMessages
52
+ });
53
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Returns a color based on usage percentage.\n * green: below 70%, amber: 70%–89%, red: 90% and above\n * @param pct - usage percentage (0–100+)\n */\nexport function barColor(pct: number): string {\n if (pct >= 90) return '#ef4444';\n if (pct >= 70) return '#f59e0b';\n return '#22c55e';\n}\n\n/**\n * Converts cents to a dollar string, rounding to the nearest dollar.\n * @param cents - amount in cents\n */\nexport function formatCents(cents: number): string {\n return `$${Math.round(cents / 100)}`;\n}\n\n/**\n * Formats a number with locale separators and an optional unit string.\n * @param val - the number to format\n * @param unit - optional unit string ('$' adds prefix, any other string adds suffix)\n */\nexport function fmt(val: number, unit?: string): string {\n const s = val.toLocaleString(undefined, { maximumFractionDigits: 9 });\n if (unit === '$') return `$${s}`;\n if (unit) return `${s} ${unit}`;\n return s;\n}\n\nexport const taxMessages: Record<string, string> = {\n inclusive: 'Prices include tax',\n exclusive: 'Prices do not include tax. Tax will be added at checkout.',\n location: 'Tax calculated at checkout based on your location.',\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,SAAS,KAAqB;AAC5C,MAAI,OAAO,GAAI,QAAO;AACtB,MAAI,OAAO,GAAI,QAAO;AACtB,SAAO;AACT;AAMO,SAAS,YAAY,OAAuB;AACjD,SAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC;AACpC;AAOO,SAAS,IAAI,KAAa,MAAuB;AACtD,QAAM,IAAI,IAAI,eAAe,QAAW,EAAE,uBAAuB,EAAE,CAAC;AACpE,MAAI,SAAS,IAAK,QAAO,IAAI,CAAC;AAC9B,MAAI,KAAM,QAAO,GAAG,CAAC,IAAI,IAAI;AAC7B,SAAO;AACT;AAEO,MAAM,cAAsC;AAAA,EACjD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AACZ;","names":[]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Returns a color based on usage percentage.
3
+ * green: below 70%, amber: 70%–89%, red: 90% and above
4
+ * @param pct - usage percentage (0–100+)
5
+ */
6
+ declare function barColor(pct: number): string;
7
+ /**
8
+ * Converts cents to a dollar string, rounding to the nearest dollar.
9
+ * @param cents - amount in cents
10
+ */
11
+ declare function formatCents(cents: number): string;
12
+ /**
13
+ * Formats a number with locale separators and an optional unit string.
14
+ * @param val - the number to format
15
+ * @param unit - optional unit string ('$' adds prefix, any other string adds suffix)
16
+ */
17
+ declare function fmt(val: number, unit?: string): string;
18
+ declare const taxMessages: Record<string, string>;
19
+
20
+ export { barColor, fmt, formatCents, taxMessages };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Returns a color based on usage percentage.
3
+ * green: below 70%, amber: 70%–89%, red: 90% and above
4
+ * @param pct - usage percentage (0–100+)
5
+ */
6
+ declare function barColor(pct: number): string;
7
+ /**
8
+ * Converts cents to a dollar string, rounding to the nearest dollar.
9
+ * @param cents - amount in cents
10
+ */
11
+ declare function formatCents(cents: number): string;
12
+ /**
13
+ * Formats a number with locale separators and an optional unit string.
14
+ * @param val - the number to format
15
+ * @param unit - optional unit string ('$' adds prefix, any other string adds suffix)
16
+ */
17
+ declare function fmt(val: number, unit?: string): string;
18
+ declare const taxMessages: Record<string, string>;
19
+
20
+ export { barColor, fmt, formatCents, taxMessages };
package/dist/utils.js ADDED
@@ -0,0 +1,26 @@
1
+ function barColor(pct) {
2
+ if (pct >= 90) return "#ef4444";
3
+ if (pct >= 70) return "#f59e0b";
4
+ return "#22c55e";
5
+ }
6
+ function formatCents(cents) {
7
+ return `$${Math.round(cents / 100)}`;
8
+ }
9
+ function fmt(val, unit) {
10
+ const s = val.toLocaleString(void 0, { maximumFractionDigits: 9 });
11
+ if (unit === "$") return `$${s}`;
12
+ if (unit) return `${s} ${unit}`;
13
+ return s;
14
+ }
15
+ const taxMessages = {
16
+ inclusive: "Prices include tax",
17
+ exclusive: "Prices do not include tax. Tax will be added at checkout.",
18
+ location: "Tax calculated at checkout based on your location."
19
+ };
20
+ export {
21
+ barColor,
22
+ fmt,
23
+ formatCents,
24
+ taxMessages
25
+ };
26
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Returns a color based on usage percentage.\n * green: below 70%, amber: 70%–89%, red: 90% and above\n * @param pct - usage percentage (0–100+)\n */\nexport function barColor(pct: number): string {\n if (pct >= 90) return '#ef4444';\n if (pct >= 70) return '#f59e0b';\n return '#22c55e';\n}\n\n/**\n * Converts cents to a dollar string, rounding to the nearest dollar.\n * @param cents - amount in cents\n */\nexport function formatCents(cents: number): string {\n return `$${Math.round(cents / 100)}`;\n}\n\n/**\n * Formats a number with locale separators and an optional unit string.\n * @param val - the number to format\n * @param unit - optional unit string ('$' adds prefix, any other string adds suffix)\n */\nexport function fmt(val: number, unit?: string): string {\n const s = val.toLocaleString(undefined, { maximumFractionDigits: 9 });\n if (unit === '$') return `$${s}`;\n if (unit) return `${s} ${unit}`;\n return s;\n}\n\nexport const taxMessages: Record<string, string> = {\n inclusive: 'Prices include tax',\n exclusive: 'Prices do not include tax. Tax will be added at checkout.',\n location: 'Tax calculated at checkout based on your location.',\n};\n"],"mappings":"AAKO,SAAS,SAAS,KAAqB;AAC5C,MAAI,OAAO,GAAI,QAAO;AACtB,MAAI,OAAO,GAAI,QAAO;AACtB,SAAO;AACT;AAMO,SAAS,YAAY,OAAuB;AACjD,SAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC;AACpC;AAOO,SAAS,IAAI,KAAa,MAAuB;AACtD,QAAM,IAAI,IAAI,eAAe,QAAW,EAAE,uBAAuB,EAAE,CAAC;AACpE,MAAI,SAAS,IAAK,QAAO,IAAI,CAAC;AAC9B,MAAI,KAAM,QAAO,GAAG,CAAC,IAAI,IAAI;AAC7B,SAAO;AACT;AAEO,MAAM,cAAsC;AAAA,EACjD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AACZ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@ai-billing/nextjs",
3
+ "version": "0.0.0",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/narevai/ai-billing.git",
9
+ "directory": "packages/nextjs"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "require": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "./server": {
25
+ "import": {
26
+ "types": "./dist/server.d.ts",
27
+ "default": "./dist/server.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/server.d.cts",
31
+ "default": "./dist/server.cjs"
32
+ }
33
+ }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "check-types": "tsc --noEmit",
44
+ "lint": "oxlint",
45
+ "dev": "tsup --watch",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest",
48
+ "test:coverage": "vitest run --coverage",
49
+ "docs:generate": "typedoc --options typedoc.json",
50
+ "prepack": "node -e \"require('fs').copyFileSync('../../LICENSE', 'LICENSE')\"",
51
+ "postpack": "node -e \"require('fs').rmSync('LICENSE', { force: true })\""
52
+ },
53
+ "dependencies": {},
54
+ "devDependencies": {
55
+ "@ai-billing/typescript-config": "workspace:*",
56
+ "@types/node": "catalog:",
57
+ "@types/react": "catalog:",
58
+ "tsup": "catalog:",
59
+ "typescript": "catalog:",
60
+ "oxlint": "catalog:",
61
+ "typedoc": "catalog:",
62
+ "vitest": "catalog:"
63
+ },
64
+ "peerDependencies": {
65
+ "@polar-sh/sdk": "^0.46.7",
66
+ "next": ">=14",
67
+ "react": "^18 || ^19",
68
+ "react-dom": "^18 || ^19",
69
+ "stripe": "^21.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@polar-sh/sdk": {
73
+ "optional": true
74
+ },
75
+ "stripe": {
76
+ "optional": true
77
+ }
78
+ },
79
+ "engines": {
80
+ "node": ">=20.0.0"
81
+ }
82
+ }