@sylphx/sdk 0.11.0 → 0.11.2
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.
- package/dist/index.d.ts +1588 -1226
- package/dist/index.mjs +2294 -1131
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.mjs +3 -0
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.mjs +57 -39
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.ts +15 -1
- package/dist/server/index.mjs +34 -3
- package/dist/server/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/react/index.mjs
CHANGED
|
@@ -526,14 +526,23 @@ var NotFoundError = class extends SylphxError {
|
|
|
526
526
|
function isSylphxError(error) {
|
|
527
527
|
return error instanceof SylphxError;
|
|
528
528
|
}
|
|
529
|
-
function getErrorMessage(error) {
|
|
529
|
+
function getErrorMessage(error, fallback = "An unknown error occurred") {
|
|
530
530
|
if (error instanceof Error) {
|
|
531
531
|
return error.message;
|
|
532
532
|
}
|
|
533
533
|
if (typeof error === "string") {
|
|
534
534
|
return error;
|
|
535
535
|
}
|
|
536
|
-
|
|
536
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
537
|
+
const message = error.message;
|
|
538
|
+
if (typeof message === "string") return message;
|
|
539
|
+
}
|
|
540
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
541
|
+
const response = error.response;
|
|
542
|
+
if (response?.data?.message) return response.data.message;
|
|
543
|
+
if (response?.data?.error) return response.data.error;
|
|
544
|
+
}
|
|
545
|
+
return fallback;
|
|
537
546
|
}
|
|
538
547
|
function toSylphxError(error) {
|
|
539
548
|
if (error instanceof SylphxError) {
|
|
@@ -2051,7 +2060,7 @@ function DeveloperSetupCard({ theme }) {
|
|
|
2051
2060
|
/* @__PURE__ */ jsxs(
|
|
2052
2061
|
"a",
|
|
2053
2062
|
{
|
|
2054
|
-
href: "https://sylphx.com/docs/
|
|
2063
|
+
href: "https://sylphx.com/docs/installation",
|
|
2055
2064
|
target: "_blank",
|
|
2056
2065
|
rel: "noopener noreferrer",
|
|
2057
2066
|
style: styles.docsButton,
|
|
@@ -17538,6 +17547,42 @@ function CheckIcon10({ color }) {
|
|
|
17538
17547
|
|
|
17539
17548
|
// src/react/ui/billing-management.tsx
|
|
17540
17549
|
import { useEffect as useEffect28, useState as useState36 } from "react";
|
|
17550
|
+
|
|
17551
|
+
// src/formatting.ts
|
|
17552
|
+
function formatCurrency(amount, optsOrCompact = false) {
|
|
17553
|
+
const opts = typeof optsOrCompact === "boolean" ? { compact: optsOrCompact } : optsOrCompact;
|
|
17554
|
+
const currency = (opts.currency ?? "USD").toUpperCase();
|
|
17555
|
+
const decimals = opts.decimals ?? 2;
|
|
17556
|
+
if (opts.compact && Math.abs(amount) >= 1e3) {
|
|
17557
|
+
return new Intl.NumberFormat("en-US", {
|
|
17558
|
+
style: "currency",
|
|
17559
|
+
currency,
|
|
17560
|
+
notation: "compact",
|
|
17561
|
+
minimumFractionDigits: 1,
|
|
17562
|
+
maximumFractionDigits: 1
|
|
17563
|
+
}).format(amount);
|
|
17564
|
+
}
|
|
17565
|
+
return new Intl.NumberFormat("en-US", {
|
|
17566
|
+
style: "currency",
|
|
17567
|
+
currency,
|
|
17568
|
+
minimumFractionDigits: decimals,
|
|
17569
|
+
maximumFractionDigits: decimals
|
|
17570
|
+
}).format(amount);
|
|
17571
|
+
}
|
|
17572
|
+
var relativeTimeFormatter = new Intl.RelativeTimeFormat("en", {
|
|
17573
|
+
numeric: "auto"
|
|
17574
|
+
});
|
|
17575
|
+
var TIME_DIVISIONS = [
|
|
17576
|
+
{ amount: 60, unit: "second" },
|
|
17577
|
+
{ amount: 60, unit: "minute" },
|
|
17578
|
+
{ amount: 24, unit: "hour" },
|
|
17579
|
+
{ amount: 7, unit: "day" },
|
|
17580
|
+
{ amount: 4.34524, unit: "week" },
|
|
17581
|
+
{ amount: 12, unit: "month" },
|
|
17582
|
+
{ amount: Number.POSITIVE_INFINITY, unit: "year" }
|
|
17583
|
+
];
|
|
17584
|
+
|
|
17585
|
+
// src/react/ui/billing-management.tsx
|
|
17541
17586
|
import { Fragment as Fragment20, jsx as jsx28, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
17542
17587
|
function InvoiceHistory({
|
|
17543
17588
|
theme = defaultTheme,
|
|
@@ -17557,12 +17602,7 @@ function InvoiceHistory({
|
|
|
17557
17602
|
}, []);
|
|
17558
17603
|
const totalPages = Math.ceil(invoices.length / pageSize);
|
|
17559
17604
|
const paginatedInvoices = invoices.slice((currentPage - 1) * pageSize, currentPage * pageSize);
|
|
17560
|
-
const
|
|
17561
|
-
return new Intl.NumberFormat("en-US", {
|
|
17562
|
-
style: "currency",
|
|
17563
|
-
currency: currency.toUpperCase()
|
|
17564
|
-
}).format(amount / 100);
|
|
17565
|
-
};
|
|
17605
|
+
const formatInvoice = (amountCents, currency) => formatCurrency(amountCents / 100, { currency });
|
|
17566
17606
|
const formatDate = (dateStr) => {
|
|
17567
17607
|
return new Date(dateStr).toLocaleDateString("en-US", {
|
|
17568
17608
|
year: "numeric",
|
|
@@ -17660,7 +17700,7 @@ function InvoiceHistory({
|
|
|
17660
17700
|
)
|
|
17661
17701
|
] }),
|
|
17662
17702
|
/* @__PURE__ */ jsx28("td", { style: tdStyle, children: formatDate(invoice.date) }),
|
|
17663
|
-
/* @__PURE__ */ jsx28("td", { style: tdStyle, children: /* @__PURE__ */ jsx28("span", { style: { fontWeight: 500 }, children:
|
|
17703
|
+
/* @__PURE__ */ jsx28("td", { style: tdStyle, children: /* @__PURE__ */ jsx28("span", { style: { fontWeight: 500 }, children: formatInvoice(invoice.amount, invoice.currency) }) }),
|
|
17664
17704
|
/* @__PURE__ */ jsx28("td", { style: tdStyle, children: /* @__PURE__ */ jsx28(
|
|
17665
17705
|
"span",
|
|
17666
17706
|
{
|
|
@@ -17954,12 +17994,7 @@ function UsageOverview({
|
|
|
17954
17994
|
useEffect28(() => {
|
|
17955
17995
|
injectGlobalStyles();
|
|
17956
17996
|
}, []);
|
|
17957
|
-
const
|
|
17958
|
-
return new Intl.NumberFormat("en-US", {
|
|
17959
|
-
style: "currency",
|
|
17960
|
-
currency: currency.toUpperCase()
|
|
17961
|
-
}).format(amount);
|
|
17962
|
-
};
|
|
17997
|
+
const format = (amount) => formatCurrency(amount, { currency });
|
|
17963
17998
|
const containerStyle = {
|
|
17964
17999
|
fontFamily: theme.fontFamily,
|
|
17965
18000
|
border: `1px solid ${theme.colorBorder}`,
|
|
@@ -17994,7 +18029,7 @@ function UsageOverview({
|
|
|
17994
18029
|
)
|
|
17995
18030
|
] }),
|
|
17996
18031
|
totalCost !== void 0 && /* @__PURE__ */ jsxs23("div", { style: { textAlign: "right" }, children: [
|
|
17997
|
-
/* @__PURE__ */ jsx28("div", { style: { fontSize: theme.fontSizeXl, fontWeight: 600 }, children:
|
|
18032
|
+
/* @__PURE__ */ jsx28("div", { style: { fontSize: theme.fontSizeXl, fontWeight: 600 }, children: format(totalCost) }),
|
|
17998
18033
|
/* @__PURE__ */ jsx28(
|
|
17999
18034
|
"div",
|
|
18000
18035
|
{
|
|
@@ -18048,7 +18083,7 @@ function UsageOverview({
|
|
|
18048
18083
|
item.limit.toLocaleString(),
|
|
18049
18084
|
" ",
|
|
18050
18085
|
item.unit,
|
|
18051
|
-
item.cost !== void 0 && ` \u2022 ${
|
|
18086
|
+
item.cost !== void 0 && ` \u2022 ${format(item.cost)}`
|
|
18052
18087
|
]
|
|
18053
18088
|
}
|
|
18054
18089
|
)
|
|
@@ -35315,41 +35350,24 @@ function useFeatureFlags2() {
|
|
|
35315
35350
|
}
|
|
35316
35351
|
function useFlag(flagKey, defaultValue = false) {
|
|
35317
35352
|
const { isEnabled, updateVersion } = useFeatureFlagsContext();
|
|
35318
|
-
return useMemo12(
|
|
35319
|
-
() => isEnabled(flagKey, defaultValue),
|
|
35320
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35321
|
-
[flagKey, defaultValue, isEnabled]
|
|
35322
|
-
);
|
|
35353
|
+
return useMemo12(() => isEnabled(flagKey, defaultValue), [flagKey, defaultValue, isEnabled]);
|
|
35323
35354
|
}
|
|
35324
35355
|
function useFlagString(flagKey, defaultValue = "") {
|
|
35325
35356
|
const { getString, updateVersion } = useFeatureFlagsContext();
|
|
35326
|
-
return useMemo12(
|
|
35327
|
-
() => getString(flagKey, defaultValue),
|
|
35328
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35329
|
-
[flagKey, defaultValue, getString]
|
|
35330
|
-
);
|
|
35357
|
+
return useMemo12(() => getString(flagKey, defaultValue), [flagKey, defaultValue, getString]);
|
|
35331
35358
|
}
|
|
35332
35359
|
function useFlagNumber(flagKey, defaultValue = 0) {
|
|
35333
35360
|
const { getNumber, updateVersion } = useFeatureFlagsContext();
|
|
35334
|
-
return useMemo12(
|
|
35335
|
-
() => getNumber(flagKey, defaultValue),
|
|
35336
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35337
|
-
[flagKey, defaultValue, getNumber]
|
|
35338
|
-
);
|
|
35361
|
+
return useMemo12(() => getNumber(flagKey, defaultValue), [flagKey, defaultValue, getNumber]);
|
|
35339
35362
|
}
|
|
35340
35363
|
function useFlagJSON(flagKey, defaultValue) {
|
|
35341
35364
|
const { getJSON, updateVersion } = useFeatureFlagsContext();
|
|
35342
|
-
return useMemo12(
|
|
35343
|
-
() => getJSON(flagKey, defaultValue),
|
|
35344
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35345
|
-
[flagKey, defaultValue, getJSON]
|
|
35346
|
-
);
|
|
35365
|
+
return useMemo12(() => getJSON(flagKey, defaultValue), [flagKey, defaultValue, getJSON]);
|
|
35347
35366
|
}
|
|
35348
35367
|
function useFlagEvaluation(flagKey, defaultValue, contextOverride) {
|
|
35349
35368
|
const { evaluate, updateVersion } = useFeatureFlagsContext();
|
|
35350
35369
|
return useMemo12(
|
|
35351
35370
|
() => evaluate(flagKey, defaultValue, contextOverride),
|
|
35352
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35353
35371
|
[flagKey, defaultValue, contextOverride, evaluate]
|
|
35354
35372
|
);
|
|
35355
35373
|
}
|