@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/nextjs/index.js
CHANGED
|
@@ -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) {
|