@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.js
CHANGED
|
@@ -59,6 +59,7 @@ __export(server_exports, {
|
|
|
59
59
|
isDevelopmentRuntime: () => isDevelopmentRuntime,
|
|
60
60
|
isProductionKey: () => isProductionKey,
|
|
61
61
|
isSecretKey: () => isSecretKey,
|
|
62
|
+
resetJwksCache: () => resetJwksCache,
|
|
62
63
|
validateAndSanitizeAppId: () => validateAndSanitizeAppId,
|
|
63
64
|
validateAndSanitizeKey: () => validateAndSanitizeKey,
|
|
64
65
|
validateAndSanitizeSecretKey: () => validateAndSanitizeSecretKey,
|
|
@@ -1208,7 +1209,7 @@ function resolvePlatformUrl(explicit) {
|
|
|
1208
1209
|
function resolveSecretKey(explicit) {
|
|
1209
1210
|
return explicit || process.env[ENV_SECRET_KEY];
|
|
1210
1211
|
}
|
|
1211
|
-
var SDK_API_PATH = `/api/
|
|
1212
|
+
var SDK_API_PATH = `/api/v1`;
|
|
1212
1213
|
var SDK_VERSION = "0.1.0";
|
|
1213
1214
|
var SDK_PLATFORM = typeof window !== "undefined" ? "browser" : typeof process !== "undefined" && process.versions?.node ? "node" : "unknown";
|
|
1214
1215
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -1613,6 +1614,7 @@ function createDeduplicationMiddleware(config = {}) {
|
|
|
1613
1614
|
deduped._dedupKey = key;
|
|
1614
1615
|
return deduped;
|
|
1615
1616
|
}
|
|
1617
|
+
;
|
|
1616
1618
|
request._dedupKey = key;
|
|
1617
1619
|
return request;
|
|
1618
1620
|
},
|
|
@@ -1636,30 +1638,24 @@ function createDeduplicationMiddleware(config = {}) {
|
|
|
1636
1638
|
var CircuitBreakerOpenError = class extends Error {
|
|
1637
1639
|
remainingMs;
|
|
1638
1640
|
constructor(remainingMs) {
|
|
1639
|
-
super(
|
|
1640
|
-
`Circuit breaker is open. Retry after ${Math.ceil(remainingMs / 1e3)}s`
|
|
1641
|
-
);
|
|
1641
|
+
super(`Circuit breaker is open. Retry after ${Math.ceil(remainingMs / 1e3)}s`);
|
|
1642
1642
|
this.name = "CircuitBreakerOpenError";
|
|
1643
1643
|
this.remainingMs = remainingMs;
|
|
1644
1644
|
}
|
|
1645
1645
|
};
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
}
|
|
1662
|
-
return circuitBreaker;
|
|
1646
|
+
function createCircuitBreakerInstance(config = {}) {
|
|
1647
|
+
return {
|
|
1648
|
+
state: "CLOSED",
|
|
1649
|
+
failures: [],
|
|
1650
|
+
openedAt: null,
|
|
1651
|
+
config: {
|
|
1652
|
+
enabled: config.enabled ?? true,
|
|
1653
|
+
failureThreshold: config.failureThreshold ?? CIRCUIT_BREAKER_FAILURE_THRESHOLD,
|
|
1654
|
+
windowMs: config.windowMs ?? CIRCUIT_BREAKER_WINDOW_MS,
|
|
1655
|
+
openDurationMs: config.openDurationMs ?? CIRCUIT_BREAKER_OPEN_DURATION_MS,
|
|
1656
|
+
isFailure: config.isFailure ?? ((status) => status >= 500 || status === 429)
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1663
1659
|
}
|
|
1664
1660
|
function recordFailure(cb) {
|
|
1665
1661
|
const now = Date.now();
|
|
@@ -1707,7 +1703,8 @@ function createCircuitBreakerMiddleware(config) {
|
|
|
1707
1703
|
}
|
|
1708
1704
|
};
|
|
1709
1705
|
}
|
|
1710
|
-
const cb =
|
|
1706
|
+
const cb = createCircuitBreakerInstance(config ?? {});
|
|
1707
|
+
_lastCircuitBreaker = cb;
|
|
1711
1708
|
return {
|
|
1712
1709
|
async onRequest({ request }) {
|
|
1713
1710
|
if (!cb.config.enabled) {
|
|
@@ -1732,6 +1729,7 @@ function createCircuitBreakerMiddleware(config) {
|
|
|
1732
1729
|
}
|
|
1733
1730
|
};
|
|
1734
1731
|
}
|
|
1732
|
+
var _lastCircuitBreaker = null;
|
|
1735
1733
|
var etagCache = /* @__PURE__ */ new Map();
|
|
1736
1734
|
function getETagCacheKey(request) {
|
|
1737
1735
|
return `${request.method}:${request.url}`;
|
|
@@ -1821,6 +1819,7 @@ function createETagMiddleware(config) {
|
|
|
1821
1819
|
}
|
|
1822
1820
|
};
|
|
1823
1821
|
}
|
|
1822
|
+
var retryBodyMap = /* @__PURE__ */ new WeakMap();
|
|
1824
1823
|
function createRetryMiddleware(retryConfig) {
|
|
1825
1824
|
if (retryConfig === false) {
|
|
1826
1825
|
return {
|
|
@@ -1836,27 +1835,22 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1836
1835
|
shouldRetry = isRetryableStatus,
|
|
1837
1836
|
timeout = DEFAULT_TIMEOUT_MS
|
|
1838
1837
|
} = retryConfig ?? {};
|
|
1839
|
-
let originalBody = null;
|
|
1840
1838
|
return {
|
|
1841
1839
|
async onRequest({ request }) {
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
body: originalBody,
|
|
1854
|
-
signal: controller.signal
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
return request;
|
|
1840
|
+
const body = request.body ? await request.clone().text() : null;
|
|
1841
|
+
const controller = new AbortController();
|
|
1842
|
+
setTimeout(() => controller.abort(), timeout);
|
|
1843
|
+
const newRequest = new Request(request.url, {
|
|
1844
|
+
method: request.method,
|
|
1845
|
+
headers: request.headers,
|
|
1846
|
+
body,
|
|
1847
|
+
signal: controller.signal
|
|
1848
|
+
});
|
|
1849
|
+
retryBodyMap.set(newRequest, body);
|
|
1850
|
+
return newRequest;
|
|
1858
1851
|
},
|
|
1859
1852
|
async onResponse({ response, request }) {
|
|
1853
|
+
const originalBody = retryBodyMap.get(request) ?? null;
|
|
1860
1854
|
let attempt = 0;
|
|
1861
1855
|
let currentResponse = response;
|
|
1862
1856
|
while (attempt < maxRetries && shouldRetry(currentResponse.status, attempt)) {
|
|
@@ -1876,16 +1870,19 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1876
1870
|
const newResponse = await fetch(retryRequest);
|
|
1877
1871
|
clearTimeout(timeoutId);
|
|
1878
1872
|
if (newResponse.ok || !shouldRetry(newResponse.status, attempt)) {
|
|
1873
|
+
retryBodyMap.delete(request);
|
|
1879
1874
|
return newResponse;
|
|
1880
1875
|
}
|
|
1881
1876
|
currentResponse = newResponse;
|
|
1882
1877
|
} catch (error) {
|
|
1883
1878
|
clearTimeout(timeoutId);
|
|
1884
1879
|
if (attempt >= maxRetries) {
|
|
1880
|
+
retryBodyMap.delete(request);
|
|
1885
1881
|
throw error;
|
|
1886
1882
|
}
|
|
1887
1883
|
}
|
|
1888
1884
|
}
|
|
1885
|
+
retryBodyMap.delete(request);
|
|
1889
1886
|
return currentResponse;
|
|
1890
1887
|
}
|
|
1891
1888
|
};
|
|
@@ -2338,6 +2335,9 @@ function isAccessTokenPayload(payload) {
|
|
|
2338
2335
|
return typeof payload.sub === "string" && typeof payload.email === "string" && typeof payload.app_id === "string" && typeof payload.iat === "number" && typeof payload.exp === "number";
|
|
2339
2336
|
}
|
|
2340
2337
|
var jwksCache = null;
|
|
2338
|
+
function resetJwksCache() {
|
|
2339
|
+
jwksCache = null;
|
|
2340
|
+
}
|
|
2341
2341
|
async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
2342
2342
|
const now = Date.now();
|
|
2343
2343
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
@@ -2721,6 +2721,7 @@ async function getDatabaseStatus(options) {
|
|
|
2721
2721
|
isDevelopmentRuntime,
|
|
2722
2722
|
isProductionKey,
|
|
2723
2723
|
isSecretKey,
|
|
2724
|
+
resetJwksCache,
|
|
2724
2725
|
validateAndSanitizeAppId,
|
|
2725
2726
|
validateAndSanitizeKey,
|
|
2726
2727
|
validateAndSanitizeSecretKey,
|