@sylphx/sdk 0.0.1 → 0.2.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.
- package/README.md +247 -260
- package/dist/index.js +61 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -65
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.js +3668 -12695
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +3671 -12698
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.js +40 -39
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +39 -39
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js +1 -1
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +5 -6
- package/dist/index.d.cts +0 -13938
- package/dist/index.d.ts +0 -13938
- package/dist/nextjs/index.d.cts +0 -2089
- package/dist/nextjs/index.d.ts +0 -2089
- package/dist/react/index.d.cts +0 -14894
- package/dist/react/index.d.ts +0 -14894
- package/dist/server/index.d.cts +0 -9908
- package/dist/server/index.d.ts +0 -9908
- package/dist/web-analytics.d.cts +0 -90
- package/dist/web-analytics.d.ts +0 -90
package/dist/server/index.mjs
CHANGED
|
@@ -1136,7 +1136,7 @@ function resolvePlatformUrl(explicit) {
|
|
|
1136
1136
|
function resolveSecretKey(explicit) {
|
|
1137
1137
|
return explicit || process.env[ENV_SECRET_KEY];
|
|
1138
1138
|
}
|
|
1139
|
-
var SDK_API_PATH = `/api/
|
|
1139
|
+
var SDK_API_PATH = `/api/v1`;
|
|
1140
1140
|
var SDK_VERSION = "0.1.0";
|
|
1141
1141
|
var SDK_PLATFORM = typeof window !== "undefined" ? "browser" : typeof process !== "undefined" && process.versions?.node ? "node" : "unknown";
|
|
1142
1142
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -1541,6 +1541,7 @@ function createDeduplicationMiddleware(config = {}) {
|
|
|
1541
1541
|
deduped._dedupKey = key;
|
|
1542
1542
|
return deduped;
|
|
1543
1543
|
}
|
|
1544
|
+
;
|
|
1544
1545
|
request._dedupKey = key;
|
|
1545
1546
|
return request;
|
|
1546
1547
|
},
|
|
@@ -1564,30 +1565,24 @@ function createDeduplicationMiddleware(config = {}) {
|
|
|
1564
1565
|
var CircuitBreakerOpenError = class extends Error {
|
|
1565
1566
|
remainingMs;
|
|
1566
1567
|
constructor(remainingMs) {
|
|
1567
|
-
super(
|
|
1568
|
-
`Circuit breaker is open. Retry after ${Math.ceil(remainingMs / 1e3)}s`
|
|
1569
|
-
);
|
|
1568
|
+
super(`Circuit breaker is open. Retry after ${Math.ceil(remainingMs / 1e3)}s`);
|
|
1570
1569
|
this.name = "CircuitBreakerOpenError";
|
|
1571
1570
|
this.remainingMs = remainingMs;
|
|
1572
1571
|
}
|
|
1573
1572
|
};
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1588
|
-
};
|
|
1589
|
-
}
|
|
1590
|
-
return circuitBreaker;
|
|
1573
|
+
function createCircuitBreakerInstance(config = {}) {
|
|
1574
|
+
return {
|
|
1575
|
+
state: "CLOSED",
|
|
1576
|
+
failures: [],
|
|
1577
|
+
openedAt: null,
|
|
1578
|
+
config: {
|
|
1579
|
+
enabled: config.enabled ?? true,
|
|
1580
|
+
failureThreshold: config.failureThreshold ?? CIRCUIT_BREAKER_FAILURE_THRESHOLD,
|
|
1581
|
+
windowMs: config.windowMs ?? CIRCUIT_BREAKER_WINDOW_MS,
|
|
1582
|
+
openDurationMs: config.openDurationMs ?? CIRCUIT_BREAKER_OPEN_DURATION_MS,
|
|
1583
|
+
isFailure: config.isFailure ?? ((status) => status >= 500 || status === 429)
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1591
1586
|
}
|
|
1592
1587
|
function recordFailure(cb) {
|
|
1593
1588
|
const now = Date.now();
|
|
@@ -1635,7 +1630,8 @@ function createCircuitBreakerMiddleware(config) {
|
|
|
1635
1630
|
}
|
|
1636
1631
|
};
|
|
1637
1632
|
}
|
|
1638
|
-
const cb =
|
|
1633
|
+
const cb = createCircuitBreakerInstance(config ?? {});
|
|
1634
|
+
_lastCircuitBreaker = cb;
|
|
1639
1635
|
return {
|
|
1640
1636
|
async onRequest({ request }) {
|
|
1641
1637
|
if (!cb.config.enabled) {
|
|
@@ -1660,6 +1656,7 @@ function createCircuitBreakerMiddleware(config) {
|
|
|
1660
1656
|
}
|
|
1661
1657
|
};
|
|
1662
1658
|
}
|
|
1659
|
+
var _lastCircuitBreaker = null;
|
|
1663
1660
|
var etagCache = /* @__PURE__ */ new Map();
|
|
1664
1661
|
function getETagCacheKey(request) {
|
|
1665
1662
|
return `${request.method}:${request.url}`;
|
|
@@ -1749,6 +1746,7 @@ function createETagMiddleware(config) {
|
|
|
1749
1746
|
}
|
|
1750
1747
|
};
|
|
1751
1748
|
}
|
|
1749
|
+
var retryBodyMap = /* @__PURE__ */ new WeakMap();
|
|
1752
1750
|
function createRetryMiddleware(retryConfig) {
|
|
1753
1751
|
if (retryConfig === false) {
|
|
1754
1752
|
return {
|
|
@@ -1764,27 +1762,22 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1764
1762
|
shouldRetry = isRetryableStatus,
|
|
1765
1763
|
timeout = DEFAULT_TIMEOUT_MS
|
|
1766
1764
|
} = retryConfig ?? {};
|
|
1767
|
-
let originalBody = null;
|
|
1768
1765
|
return {
|
|
1769
1766
|
async onRequest({ request }) {
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
body: originalBody,
|
|
1782
|
-
signal: controller.signal
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
return request;
|
|
1767
|
+
const body = request.body ? await request.clone().text() : null;
|
|
1768
|
+
const controller = new AbortController();
|
|
1769
|
+
setTimeout(() => controller.abort(), timeout);
|
|
1770
|
+
const newRequest = new Request(request.url, {
|
|
1771
|
+
method: request.method,
|
|
1772
|
+
headers: request.headers,
|
|
1773
|
+
body,
|
|
1774
|
+
signal: controller.signal
|
|
1775
|
+
});
|
|
1776
|
+
retryBodyMap.set(newRequest, body);
|
|
1777
|
+
return newRequest;
|
|
1786
1778
|
},
|
|
1787
1779
|
async onResponse({ response, request }) {
|
|
1780
|
+
const originalBody = retryBodyMap.get(request) ?? null;
|
|
1788
1781
|
let attempt = 0;
|
|
1789
1782
|
let currentResponse = response;
|
|
1790
1783
|
while (attempt < maxRetries && shouldRetry(currentResponse.status, attempt)) {
|
|
@@ -1804,16 +1797,19 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1804
1797
|
const newResponse = await fetch(retryRequest);
|
|
1805
1798
|
clearTimeout(timeoutId);
|
|
1806
1799
|
if (newResponse.ok || !shouldRetry(newResponse.status, attempt)) {
|
|
1800
|
+
retryBodyMap.delete(request);
|
|
1807
1801
|
return newResponse;
|
|
1808
1802
|
}
|
|
1809
1803
|
currentResponse = newResponse;
|
|
1810
1804
|
} catch (error) {
|
|
1811
1805
|
clearTimeout(timeoutId);
|
|
1812
1806
|
if (attempt >= maxRetries) {
|
|
1807
|
+
retryBodyMap.delete(request);
|
|
1813
1808
|
throw error;
|
|
1814
1809
|
}
|
|
1815
1810
|
}
|
|
1816
1811
|
}
|
|
1812
|
+
retryBodyMap.delete(request);
|
|
1817
1813
|
return currentResponse;
|
|
1818
1814
|
}
|
|
1819
1815
|
};
|
|
@@ -2266,6 +2262,9 @@ function isAccessTokenPayload(payload) {
|
|
|
2266
2262
|
return typeof payload.sub === "string" && typeof payload.email === "string" && typeof payload.app_id === "string" && typeof payload.iat === "number" && typeof payload.exp === "number";
|
|
2267
2263
|
}
|
|
2268
2264
|
var jwksCache = null;
|
|
2265
|
+
function resetJwksCache() {
|
|
2266
|
+
jwksCache = null;
|
|
2267
|
+
}
|
|
2269
2268
|
async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
2270
2269
|
const now = Date.now();
|
|
2271
2270
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
@@ -2648,6 +2647,7 @@ export {
|
|
|
2648
2647
|
isDevelopmentRuntime,
|
|
2649
2648
|
isProductionKey,
|
|
2650
2649
|
isSecretKey,
|
|
2650
|
+
resetJwksCache,
|
|
2651
2651
|
validateAndSanitizeAppId,
|
|
2652
2652
|
validateAndSanitizeKey,
|
|
2653
2653
|
validateAndSanitizeSecretKey,
|