@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.mjs
CHANGED
|
@@ -31,6 +31,7 @@ var JWK_CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
|
31
31
|
var ETAG_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
32
32
|
|
|
33
33
|
// src/key-validation.ts
|
|
34
|
+
var PUBLIC_KEY_PATTERN = /^pk_(dev|stg|prod)_[a-z0-9]{12}_[a-f0-9]{32}$/;
|
|
34
35
|
var APP_ID_PATTERN = /^app_(dev|stg|prod)_[a-z0-9_-]+$/;
|
|
35
36
|
var SECRET_KEY_PATTERN = /^sk_(dev|stg|prod)_[a-z0-9_-]+$/;
|
|
36
37
|
var ENV_PREFIX_MAP = {
|
|
@@ -121,6 +122,9 @@ function validateKeyForType(key, keyType, pattern, envVarName) {
|
|
|
121
122
|
issues: [...issues, "invalid-format"]
|
|
122
123
|
};
|
|
123
124
|
}
|
|
125
|
+
function validatePublicKey(key) {
|
|
126
|
+
return validateKeyForType(key, "publicKey", PUBLIC_KEY_PATTERN, "NEXT_PUBLIC_SYLPHX_KEY");
|
|
127
|
+
}
|
|
124
128
|
function validateAppId(key) {
|
|
125
129
|
return validateKeyForType(key, "appId", APP_ID_PATTERN, "NEXT_PUBLIC_SYLPHX_APP_ID");
|
|
126
130
|
}
|
|
@@ -149,22 +153,23 @@ function validateAndSanitizeSecretKey(key) {
|
|
|
149
153
|
}
|
|
150
154
|
function detectEnvironment(key) {
|
|
151
155
|
const sanitized = key.trim().toLowerCase();
|
|
156
|
+
if (sanitized.startsWith("pk_")) {
|
|
157
|
+
const result = validatePublicKey(sanitized);
|
|
158
|
+
if (!result.valid) throw new Error(result.error);
|
|
159
|
+
return result.environment;
|
|
160
|
+
}
|
|
152
161
|
if (sanitized.startsWith("sk_")) {
|
|
153
162
|
const result = validateSecretKey(sanitized);
|
|
154
|
-
if (!result.valid)
|
|
155
|
-
throw new Error(result.error);
|
|
156
|
-
}
|
|
163
|
+
if (!result.valid) throw new Error(result.error);
|
|
157
164
|
return result.environment;
|
|
158
165
|
}
|
|
159
166
|
if (sanitized.startsWith("app_")) {
|
|
160
167
|
const result = validateAppId(sanitized);
|
|
161
|
-
if (!result.valid)
|
|
162
|
-
throw new Error(result.error);
|
|
163
|
-
}
|
|
168
|
+
if (!result.valid) throw new Error(result.error);
|
|
164
169
|
return result.environment;
|
|
165
170
|
}
|
|
166
171
|
throw new Error(
|
|
167
|
-
`[Sylphx] Invalid key format. Key must start with 'sk_' (secret) or 'app_' (App ID).`
|
|
172
|
+
`[Sylphx] Invalid key format. Key must start with 'pk_' (publishable), 'sk_' (secret), or 'app_' (legacy App ID).`
|
|
168
173
|
);
|
|
169
174
|
}
|
|
170
175
|
function getCookieNamespace(secretKey) {
|