@sylphx/sdk 0.3.4 → 0.3.6
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.cts +71 -26
- package/dist/index.d.ts +71 -26
- package/dist/index.js +103 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -13
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.js +12 -7
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +12 -7
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +33 -35
- package/dist/react/index.d.ts +33 -35
- package/dist/react/index.js +23977 -24213
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +23836 -24083
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +21 -14
- package/dist/server/index.d.ts +21 -14
- package/dist/server/index.js +27 -10
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +27 -10
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1338,6 +1338,7 @@ function exponentialBackoff(attempt, baseDelay = BASE_RETRY_DELAY_MS, maxDelay =
|
|
|
1338
1338
|
}
|
|
1339
1339
|
|
|
1340
1340
|
// src/key-validation.ts
|
|
1341
|
+
var PUBLIC_KEY_PATTERN = /^pk_(dev|stg|prod)_[a-z0-9]{12}_[a-f0-9]{32}$/;
|
|
1341
1342
|
var APP_ID_PATTERN = /^app_(dev|stg|prod)_[a-z0-9_-]+$/;
|
|
1342
1343
|
var SECRET_KEY_PATTERN = /^sk_(dev|stg|prod)_[a-z0-9_-]+$/;
|
|
1343
1344
|
var ENV_PREFIX_MAP = {
|
|
@@ -1428,6 +1429,9 @@ function validateKeyForType(key, keyType, pattern, envVarName) {
|
|
|
1428
1429
|
issues: [...issues, "invalid-format"]
|
|
1429
1430
|
};
|
|
1430
1431
|
}
|
|
1432
|
+
function validatePublicKey(key) {
|
|
1433
|
+
return validateKeyForType(key, "publicKey", PUBLIC_KEY_PATTERN, "NEXT_PUBLIC_SYLPHX_KEY");
|
|
1434
|
+
}
|
|
1431
1435
|
function validateAppId(key) {
|
|
1432
1436
|
return validateKeyForType(key, "appId", APP_ID_PATTERN, "NEXT_PUBLIC_SYLPHX_APP_ID");
|
|
1433
1437
|
}
|
|
@@ -1456,22 +1460,23 @@ function validateAndSanitizeSecretKey(key) {
|
|
|
1456
1460
|
}
|
|
1457
1461
|
function detectEnvironment(key) {
|
|
1458
1462
|
const sanitized = key.trim().toLowerCase();
|
|
1463
|
+
if (sanitized.startsWith("pk_")) {
|
|
1464
|
+
const result = validatePublicKey(sanitized);
|
|
1465
|
+
if (!result.valid) throw new Error(result.error);
|
|
1466
|
+
return result.environment;
|
|
1467
|
+
}
|
|
1459
1468
|
if (sanitized.startsWith("sk_")) {
|
|
1460
1469
|
const result = validateSecretKey(sanitized);
|
|
1461
|
-
if (!result.valid)
|
|
1462
|
-
throw new Error(result.error);
|
|
1463
|
-
}
|
|
1470
|
+
if (!result.valid) throw new Error(result.error);
|
|
1464
1471
|
return result.environment;
|
|
1465
1472
|
}
|
|
1466
1473
|
if (sanitized.startsWith("app_")) {
|
|
1467
1474
|
const result = validateAppId(sanitized);
|
|
1468
|
-
if (!result.valid)
|
|
1469
|
-
throw new Error(result.error);
|
|
1470
|
-
}
|
|
1475
|
+
if (!result.valid) throw new Error(result.error);
|
|
1471
1476
|
return result.environment;
|
|
1472
1477
|
}
|
|
1473
1478
|
throw new Error(
|
|
1474
|
-
`[Sylphx] Invalid key format. Key must start with 'sk_' (secret) or 'app_' (App ID).`
|
|
1479
|
+
`[Sylphx] Invalid key format. Key must start with 'pk_' (publishable), 'sk_' (secret), or 'app_' (legacy App ID).`
|
|
1475
1480
|
);
|
|
1476
1481
|
}
|
|
1477
1482
|
function isDevelopmentKey(key) {
|
|
@@ -1487,6 +1492,7 @@ function getCookieNamespace(secretKey) {
|
|
|
1487
1492
|
}
|
|
1488
1493
|
function detectKeyType(key) {
|
|
1489
1494
|
const sanitized = key.trim().toLowerCase();
|
|
1495
|
+
if (sanitized.startsWith("pk_")) return "publicKey";
|
|
1490
1496
|
if (sanitized.startsWith("app_")) return "appId";
|
|
1491
1497
|
if (sanitized.startsWith("sk_")) return "secret";
|
|
1492
1498
|
return null;
|
|
@@ -1499,6 +1505,9 @@ function isSecretKey(key) {
|
|
|
1499
1505
|
}
|
|
1500
1506
|
function validateKey(key) {
|
|
1501
1507
|
const keyType = key ? detectKeyType(key) : null;
|
|
1508
|
+
if (keyType === "publicKey") {
|
|
1509
|
+
return validatePublicKey(key);
|
|
1510
|
+
}
|
|
1502
1511
|
if (keyType === "appId") {
|
|
1503
1512
|
return validateAppId(key);
|
|
1504
1513
|
}
|
|
@@ -1508,7 +1517,7 @@ function validateKey(key) {
|
|
|
1508
1517
|
return {
|
|
1509
1518
|
valid: false,
|
|
1510
1519
|
sanitizedKey: "",
|
|
1511
|
-
error: key ? `Invalid key format. Keys must start with 'app_' (
|
|
1520
|
+
error: key ? `Invalid key format. Keys must start with 'pk_' (publishable), 'app_' (legacy), or 'sk_' (secret), followed by environment (dev/stg/prod). Got: ${key.slice(0, 20)}...` : "API key is required but was not provided.",
|
|
1512
1521
|
issues: key ? ["invalid_format"] : ["missing"]
|
|
1513
1522
|
};
|
|
1514
1523
|
}
|
|
@@ -2507,14 +2516,18 @@ function createWebhookHandler(config) {
|
|
|
2507
2516
|
};
|
|
2508
2517
|
}
|
|
2509
2518
|
async function cachedFetch(params) {
|
|
2510
|
-
const { url, headers, fallback, label, revalidate = 60 } = params;
|
|
2519
|
+
const { url, headers, fallback, label, revalidate = 60, timeout = 3e3 } = params;
|
|
2511
2520
|
try {
|
|
2521
|
+
const controller = new AbortController();
|
|
2522
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
2512
2523
|
const response = await fetch(url, {
|
|
2513
2524
|
headers,
|
|
2525
|
+
signal: controller.signal,
|
|
2514
2526
|
// @ts-expect-error - Next.js extended fetch option
|
|
2515
2527
|
next: { revalidate }
|
|
2516
2528
|
// Next.js Data Cache with TTL
|
|
2517
2529
|
});
|
|
2530
|
+
clearTimeout(timer);
|
|
2518
2531
|
if (!response.ok) {
|
|
2519
2532
|
console.warn(`[Sylphx] Failed to fetch ${label}:`, response.status);
|
|
2520
2533
|
return fallback;
|
|
@@ -2522,7 +2535,11 @@ async function cachedFetch(params) {
|
|
|
2522
2535
|
const data = await response.json();
|
|
2523
2536
|
return data ?? fallback;
|
|
2524
2537
|
} catch (error) {
|
|
2525
|
-
|
|
2538
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
2539
|
+
console.warn(`[Sylphx] Timeout fetching ${label} (${timeout}ms)`);
|
|
2540
|
+
} else {
|
|
2541
|
+
console.warn(`[Sylphx] Failed to fetch ${label}:`, error);
|
|
2542
|
+
}
|
|
2526
2543
|
return fallback;
|
|
2527
2544
|
}
|
|
2528
2545
|
}
|