@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.
@@ -85,6 +85,7 @@ var JWK_CACHE_TTL_MS = 60 * 60 * 1e3;
85
85
  var ETAG_CACHE_TTL_MS = 5 * 60 * 1e3;
86
86
 
87
87
  // src/key-validation.ts
88
+ var PUBLIC_KEY_PATTERN = /^pk_(dev|stg|prod)_[a-z0-9]{12}_[a-f0-9]{32}$/;
88
89
  var APP_ID_PATTERN = /^app_(dev|stg|prod)_[a-z0-9_-]+$/;
89
90
  var SECRET_KEY_PATTERN = /^sk_(dev|stg|prod)_[a-z0-9_-]+$/;
90
91
  var ENV_PREFIX_MAP = {
@@ -175,6 +176,9 @@ function validateKeyForType(key, keyType, pattern, envVarName) {
175
176
  issues: [...issues, "invalid-format"]
176
177
  };
177
178
  }
179
+ function validatePublicKey(key) {
180
+ return validateKeyForType(key, "publicKey", PUBLIC_KEY_PATTERN, "NEXT_PUBLIC_SYLPHX_KEY");
181
+ }
178
182
  function validateAppId(key) {
179
183
  return validateKeyForType(key, "appId", APP_ID_PATTERN, "NEXT_PUBLIC_SYLPHX_APP_ID");
180
184
  }
@@ -203,22 +207,23 @@ function validateAndSanitizeSecretKey(key) {
203
207
  }
204
208
  function detectEnvironment(key) {
205
209
  const sanitized = key.trim().toLowerCase();
210
+ if (sanitized.startsWith("pk_")) {
211
+ const result = validatePublicKey(sanitized);
212
+ if (!result.valid) throw new Error(result.error);
213
+ return result.environment;
214
+ }
206
215
  if (sanitized.startsWith("sk_")) {
207
216
  const result = validateSecretKey(sanitized);
208
- if (!result.valid) {
209
- throw new Error(result.error);
210
- }
217
+ if (!result.valid) throw new Error(result.error);
211
218
  return result.environment;
212
219
  }
213
220
  if (sanitized.startsWith("app_")) {
214
221
  const result = validateAppId(sanitized);
215
- if (!result.valid) {
216
- throw new Error(result.error);
217
- }
222
+ if (!result.valid) throw new Error(result.error);
218
223
  return result.environment;
219
224
  }
220
225
  throw new Error(
221
- `[Sylphx] Invalid key format. Key must start with 'sk_' (secret) or 'app_' (App ID).`
226
+ `[Sylphx] Invalid key format. Key must start with 'pk_' (publishable), 'sk_' (secret), or 'app_' (legacy App ID).`
222
227
  );
223
228
  }
224
229
  function getCookieNamespace(secretKey) {