@sylphx/sdk 0.3.4 → 0.3.5

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.
@@ -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_' (App ID) or 'sk_' (Secret Key), followed by environment (dev/stg/prod) and identifier. Got: ${key.slice(0, 20)}...` : "API key is required but was not provided.",
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
  }