@sylphx/sdk 0.3.2 → 0.3.4
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/README.md +15 -5
- package/dist/index.d.cts +16911 -5923
- package/dist/index.d.ts +16911 -5923
- package/dist/index.js +180 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +180 -143
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.cts +5380 -1201
- package/dist/nextjs/index.d.ts +5380 -1201
- package/dist/nextjs/index.js +106 -37
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +104 -37
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +5354 -1213
- package/dist/react/index.d.ts +5354 -1213
- package/dist/react/index.js +119 -97
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +119 -97
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +14371 -3312
- package/dist/server/index.d.ts +14371 -3312
- package/dist/server/index.js +110 -47
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +108 -47
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js +1 -1
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +3 -3
package/dist/server/index.js
CHANGED
|
@@ -36,8 +36,10 @@ __export(server_exports, {
|
|
|
36
36
|
createServerClient: () => createServerClient,
|
|
37
37
|
createStreams: () => createStreams,
|
|
38
38
|
createWebhookHandler: () => createWebhookHandler,
|
|
39
|
+
decodeUserId: () => decodeUserId,
|
|
39
40
|
detectEnvironment: () => detectEnvironment,
|
|
40
41
|
detectKeyType: () => detectKeyType,
|
|
42
|
+
encodeUserId: () => encodeUserId,
|
|
41
43
|
getAI: () => getAI,
|
|
42
44
|
getAppConfig: () => getAppConfig,
|
|
43
45
|
getAppMetadata: () => getAppMetadata,
|
|
@@ -71,7 +73,7 @@ __export(server_exports, {
|
|
|
71
73
|
});
|
|
72
74
|
module.exports = __toCommonJS(server_exports);
|
|
73
75
|
|
|
74
|
-
//
|
|
76
|
+
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
75
77
|
var encoder = new TextEncoder();
|
|
76
78
|
var decoder = new TextDecoder();
|
|
77
79
|
var MAX_INT32 = 2 ** 32;
|
|
@@ -97,7 +99,7 @@ function encode(string) {
|
|
|
97
99
|
return bytes;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
//
|
|
102
|
+
// node_modules/jose/dist/webapi/lib/base64.js
|
|
101
103
|
function decodeBase64(encoded) {
|
|
102
104
|
if (Uint8Array.fromBase64) {
|
|
103
105
|
return Uint8Array.fromBase64(encoded);
|
|
@@ -110,7 +112,7 @@ function decodeBase64(encoded) {
|
|
|
110
112
|
return bytes;
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
//
|
|
115
|
+
// node_modules/jose/dist/webapi/util/base64url.js
|
|
114
116
|
function decode(input) {
|
|
115
117
|
if (Uint8Array.fromBase64) {
|
|
116
118
|
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
@@ -129,7 +131,7 @@ function decode(input) {
|
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
//
|
|
134
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
133
135
|
var JOSEError = class extends Error {
|
|
134
136
|
static code = "ERR_JOSE_GENERIC";
|
|
135
137
|
code = "ERR_JOSE_GENERIC";
|
|
@@ -189,7 +191,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
|
189
191
|
}
|
|
190
192
|
};
|
|
191
193
|
|
|
192
|
-
//
|
|
194
|
+
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
193
195
|
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
194
196
|
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
195
197
|
function getHashLength(hash) {
|
|
@@ -277,7 +279,7 @@ function checkSigCryptoKey(key, alg, usage) {
|
|
|
277
279
|
checkUsage(key, usage);
|
|
278
280
|
}
|
|
279
281
|
|
|
280
|
-
//
|
|
282
|
+
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
281
283
|
function message(msg, actual, ...types) {
|
|
282
284
|
types = types.filter(Boolean);
|
|
283
285
|
if (types.length > 2) {
|
|
@@ -302,7 +304,7 @@ function message(msg, actual, ...types) {
|
|
|
302
304
|
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
303
305
|
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
304
306
|
|
|
305
|
-
//
|
|
307
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
306
308
|
var isCryptoKey = (key) => {
|
|
307
309
|
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
308
310
|
return true;
|
|
@@ -315,7 +317,7 @@ var isCryptoKey = (key) => {
|
|
|
315
317
|
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
316
318
|
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
317
319
|
|
|
318
|
-
//
|
|
320
|
+
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
319
321
|
function isDisjoint(...headers) {
|
|
320
322
|
const sources = headers.filter(Boolean);
|
|
321
323
|
if (sources.length === 0 || sources.length === 1) {
|
|
@@ -338,7 +340,7 @@ function isDisjoint(...headers) {
|
|
|
338
340
|
return true;
|
|
339
341
|
}
|
|
340
342
|
|
|
341
|
-
//
|
|
343
|
+
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
342
344
|
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
343
345
|
function isObject(input) {
|
|
344
346
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
@@ -354,7 +356,7 @@ function isObject(input) {
|
|
|
354
356
|
return Object.getPrototypeOf(input) === proto;
|
|
355
357
|
}
|
|
356
358
|
|
|
357
|
-
//
|
|
359
|
+
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
358
360
|
function checkKeyLength(alg, key) {
|
|
359
361
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
360
362
|
const { modulusLength } = key.algorithm;
|
|
@@ -364,7 +366,7 @@ function checkKeyLength(alg, key) {
|
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
//
|
|
369
|
+
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
368
370
|
function subtleMapping(jwk) {
|
|
369
371
|
let algorithm;
|
|
370
372
|
let keyUsages;
|
|
@@ -474,7 +476,7 @@ async function jwkToKey(jwk) {
|
|
|
474
476
|
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
475
477
|
}
|
|
476
478
|
|
|
477
|
-
//
|
|
479
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
478
480
|
async function importJWK(jwk, alg, options) {
|
|
479
481
|
if (!isObject(jwk)) {
|
|
480
482
|
throw new TypeError("JWK must be an object");
|
|
@@ -510,7 +512,7 @@ async function importJWK(jwk, alg, options) {
|
|
|
510
512
|
}
|
|
511
513
|
}
|
|
512
514
|
|
|
513
|
-
//
|
|
515
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
514
516
|
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
515
517
|
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
516
518
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
@@ -541,7 +543,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
541
543
|
return new Set(protectedHeader.crit);
|
|
542
544
|
}
|
|
543
545
|
|
|
544
|
-
//
|
|
546
|
+
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
545
547
|
function validateAlgorithms(option, algorithms) {
|
|
546
548
|
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
547
549
|
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
@@ -552,13 +554,13 @@ function validateAlgorithms(option, algorithms) {
|
|
|
552
554
|
return new Set(algorithms);
|
|
553
555
|
}
|
|
554
556
|
|
|
555
|
-
//
|
|
557
|
+
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
556
558
|
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
557
559
|
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
558
560
|
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
559
561
|
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
560
562
|
|
|
561
|
-
//
|
|
563
|
+
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
562
564
|
var cache;
|
|
563
565
|
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
564
566
|
cache ||= /* @__PURE__ */ new WeakMap();
|
|
@@ -729,7 +731,7 @@ async function normalizeKey(key, alg) {
|
|
|
729
731
|
throw new Error("unreachable");
|
|
730
732
|
}
|
|
731
733
|
|
|
732
|
-
//
|
|
734
|
+
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
733
735
|
var tag = (key) => key?.[Symbol.toStringTag];
|
|
734
736
|
var jwkMatchesOp = (alg, key, usage) => {
|
|
735
737
|
if (key.use !== void 0) {
|
|
@@ -849,7 +851,7 @@ function checkKeyType(alg, key, usage) {
|
|
|
849
851
|
}
|
|
850
852
|
}
|
|
851
853
|
|
|
852
|
-
//
|
|
854
|
+
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
853
855
|
function subtleAlgorithm(alg, algorithm) {
|
|
854
856
|
const hash = `SHA-${alg.slice(-3)}`;
|
|
855
857
|
switch (alg) {
|
|
@@ -881,7 +883,7 @@ function subtleAlgorithm(alg, algorithm) {
|
|
|
881
883
|
}
|
|
882
884
|
}
|
|
883
885
|
|
|
884
|
-
//
|
|
886
|
+
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
885
887
|
async function getSigKey(alg, key, usage) {
|
|
886
888
|
if (key instanceof Uint8Array) {
|
|
887
889
|
if (!alg.startsWith("HS")) {
|
|
@@ -893,7 +895,7 @@ async function getSigKey(alg, key, usage) {
|
|
|
893
895
|
return key;
|
|
894
896
|
}
|
|
895
897
|
|
|
896
|
-
//
|
|
898
|
+
// node_modules/jose/dist/webapi/lib/verify.js
|
|
897
899
|
async function verify(alg, key, signature, data) {
|
|
898
900
|
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
899
901
|
checkKeyLength(alg, cryptoKey);
|
|
@@ -905,7 +907,7 @@ async function verify(alg, key, signature, data) {
|
|
|
905
907
|
}
|
|
906
908
|
}
|
|
907
909
|
|
|
908
|
-
//
|
|
910
|
+
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
909
911
|
async function flattenedVerify(jws, key, options) {
|
|
910
912
|
if (!isObject(jws)) {
|
|
911
913
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -1007,7 +1009,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
1007
1009
|
return result;
|
|
1008
1010
|
}
|
|
1009
1011
|
|
|
1010
|
-
//
|
|
1012
|
+
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1011
1013
|
async function compactVerify(jws, key, options) {
|
|
1012
1014
|
if (jws instanceof Uint8Array) {
|
|
1013
1015
|
jws = decoder.decode(jws);
|
|
@@ -1027,7 +1029,7 @@ async function compactVerify(jws, key, options) {
|
|
|
1027
1029
|
return result;
|
|
1028
1030
|
}
|
|
1029
1031
|
|
|
1030
|
-
//
|
|
1032
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1031
1033
|
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1032
1034
|
var minute = 60;
|
|
1033
1035
|
var hour = minute * 60;
|
|
@@ -1184,7 +1186,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
1184
1186
|
return payload;
|
|
1185
1187
|
}
|
|
1186
1188
|
|
|
1187
|
-
//
|
|
1189
|
+
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
1188
1190
|
async function jwtVerify(jwt, key, options) {
|
|
1189
1191
|
const verified = await compactVerify(jwt, key, options);
|
|
1190
1192
|
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
@@ -1199,17 +1201,12 @@ async function jwtVerify(jwt, key, options) {
|
|
|
1199
1201
|
}
|
|
1200
1202
|
|
|
1201
1203
|
// src/constants.ts
|
|
1202
|
-
var DEFAULT_PLATFORM_URL = "https://sylphx.com";
|
|
1203
|
-
var ENV_PLATFORM_URL = "SYLPHX_PLATFORM_URL";
|
|
1204
|
-
var ENV_PLATFORM_URL_LEGACY = "SYLPHX_URL";
|
|
1205
1204
|
var ENV_SECRET_KEY = "SYLPHX_SECRET_KEY";
|
|
1206
|
-
function resolvePlatformUrl(explicit) {
|
|
1207
|
-
return (explicit || process.env[ENV_PLATFORM_URL] || process.env[ENV_PLATFORM_URL_LEGACY] || DEFAULT_PLATFORM_URL).trim();
|
|
1208
|
-
}
|
|
1209
1205
|
function resolveSecretKey(explicit) {
|
|
1210
1206
|
return explicit || process.env[ENV_SECRET_KEY];
|
|
1211
1207
|
}
|
|
1212
|
-
var SDK_API_PATH = `/
|
|
1208
|
+
var SDK_API_PATH = `/v1`;
|
|
1209
|
+
var DEFAULT_SDK_API_HOST = "api.sylphx.com";
|
|
1213
1210
|
var SDK_VERSION = "0.1.0";
|
|
1214
1211
|
var SDK_PLATFORM = typeof window !== "undefined" ? "browser" : typeof process !== "undefined" && process.versions?.node ? "node" : "unknown";
|
|
1215
1212
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -1932,7 +1929,7 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1932
1929
|
function validateClientConfig(config) {
|
|
1933
1930
|
return {
|
|
1934
1931
|
secretKey: validateAndSanitizeSecretKey(config.secretKey),
|
|
1935
|
-
baseUrl: (config.platformUrl ||
|
|
1932
|
+
baseUrl: (config.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim()
|
|
1936
1933
|
};
|
|
1937
1934
|
}
|
|
1938
1935
|
function createRestClient(config) {
|
|
@@ -1983,9 +1980,72 @@ function createDynamicRestClient(config) {
|
|
|
1983
1980
|
return client;
|
|
1984
1981
|
}
|
|
1985
1982
|
|
|
1983
|
+
// src/lib/ids.ts
|
|
1984
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1985
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1986
|
+
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1987
|
+
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1988
|
+
function cb32Encode(hex) {
|
|
1989
|
+
const num = BigInt(`0x${hex}`);
|
|
1990
|
+
const chars = [];
|
|
1991
|
+
let n = num;
|
|
1992
|
+
for (let i = 0; i < 26; i++) {
|
|
1993
|
+
chars.unshift(CB32[Number(n & 0x1fn)]);
|
|
1994
|
+
n >>= 5n;
|
|
1995
|
+
}
|
|
1996
|
+
return chars.join("");
|
|
1997
|
+
}
|
|
1998
|
+
function cb32Decode(str) {
|
|
1999
|
+
if (str.length !== 26) return null;
|
|
2000
|
+
let n = 0n;
|
|
2001
|
+
for (const c of str.toLowerCase()) {
|
|
2002
|
+
const idx = CB32_MAP[c];
|
|
2003
|
+
if (idx === void 0) return null;
|
|
2004
|
+
n = n << 5n | BigInt(idx);
|
|
2005
|
+
}
|
|
2006
|
+
return n.toString(16).padStart(32, "0");
|
|
2007
|
+
}
|
|
2008
|
+
function b58Decode(str) {
|
|
2009
|
+
let n = 0n;
|
|
2010
|
+
for (const c of str) {
|
|
2011
|
+
const i = B58_MAP[c] ?? -1;
|
|
2012
|
+
if (i === -1) return null;
|
|
2013
|
+
n = n * 58n + BigInt(i);
|
|
2014
|
+
}
|
|
2015
|
+
const hex = n.toString(16).padStart(32, "0");
|
|
2016
|
+
return hex.length === 32 ? hex : null;
|
|
2017
|
+
}
|
|
2018
|
+
function hexToUuid(hex) {
|
|
2019
|
+
return [
|
|
2020
|
+
hex.slice(0, 8),
|
|
2021
|
+
hex.slice(8, 12),
|
|
2022
|
+
hex.slice(12, 16),
|
|
2023
|
+
hex.slice(16, 20),
|
|
2024
|
+
hex.slice(20)
|
|
2025
|
+
].join("-");
|
|
2026
|
+
}
|
|
2027
|
+
function encodeUserId(uuid) {
|
|
2028
|
+
const hex = uuid.replace(/-/g, "");
|
|
2029
|
+
if (hex.length !== 32)
|
|
2030
|
+
throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
|
|
2031
|
+
return `user_${cb32Encode(hex)}`;
|
|
2032
|
+
}
|
|
2033
|
+
function decodeUserId(prefixedId) {
|
|
2034
|
+
if (!prefixedId.startsWith("user_")) return null;
|
|
2035
|
+
const enc = prefixedId.slice(5);
|
|
2036
|
+
if (!enc) return null;
|
|
2037
|
+
if (enc.length === 26) {
|
|
2038
|
+
const hex2 = cb32Decode(enc);
|
|
2039
|
+
if (hex2) return hexToUuid(hex2);
|
|
2040
|
+
}
|
|
2041
|
+
const hex = b58Decode(enc);
|
|
2042
|
+
if (hex) return hexToUuid(hex);
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1986
2046
|
// src/server/ai.ts
|
|
1987
2047
|
function createAI(options = {}) {
|
|
1988
|
-
const baseURL = (options.platformUrl ||
|
|
2048
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
1989
2049
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
1990
2050
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
1991
2051
|
const headers = {
|
|
@@ -2078,7 +2138,7 @@ function getAI() {
|
|
|
2078
2138
|
|
|
2079
2139
|
// src/server/kv.ts
|
|
2080
2140
|
function createKv(options = {}) {
|
|
2081
|
-
const platformUrl =
|
|
2141
|
+
const platformUrl = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2082
2142
|
const secretKey = validateAndSanitizeSecretKey(resolveSecretKey(options.secretKey));
|
|
2083
2143
|
const headers = {
|
|
2084
2144
|
"Content-Type": "application/json",
|
|
@@ -2267,7 +2327,7 @@ function getKv() {
|
|
|
2267
2327
|
|
|
2268
2328
|
// src/server/streams.ts
|
|
2269
2329
|
function createStreams(options = {}) {
|
|
2270
|
-
const baseURL = (options.platformUrl ||
|
|
2330
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2271
2331
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
2272
2332
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
2273
2333
|
const headers = {
|
|
@@ -2350,7 +2410,7 @@ var jwksCache = null;
|
|
|
2350
2410
|
function resetJwksCache() {
|
|
2351
2411
|
jwksCache = null;
|
|
2352
2412
|
}
|
|
2353
|
-
async function getJwks(platformUrl =
|
|
2413
|
+
async function getJwks(platformUrl = `https://${DEFAULT_SDK_API_HOST}`) {
|
|
2354
2414
|
const now = Date.now();
|
|
2355
2415
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
2356
2416
|
return jwksCache.keys;
|
|
@@ -2371,7 +2431,7 @@ async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
|
2371
2431
|
return data.keys;
|
|
2372
2432
|
}
|
|
2373
2433
|
async function verifyAccessToken(token, options) {
|
|
2374
|
-
const platformUrl = options.platformUrl ||
|
|
2434
|
+
const platformUrl = options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`;
|
|
2375
2435
|
const keys = await getJwks(platformUrl);
|
|
2376
2436
|
if (!keys.length) {
|
|
2377
2437
|
throw new Error("No keys in JWKS");
|
|
@@ -2388,6 +2448,7 @@ async function verifyAccessToken(token, options) {
|
|
|
2388
2448
|
}
|
|
2389
2449
|
return {
|
|
2390
2450
|
sub: payload.sub,
|
|
2451
|
+
pid: payload.pid,
|
|
2391
2452
|
email: payload.email,
|
|
2392
2453
|
name: payload.name,
|
|
2393
2454
|
picture: payload.picture,
|
|
@@ -2544,7 +2605,7 @@ function sanitizeOptions(options) {
|
|
|
2544
2605
|
return {
|
|
2545
2606
|
...options,
|
|
2546
2607
|
secretKey: validateAndSanitizeSecretKey(options.secretKey),
|
|
2547
|
-
platformUrl: (options.platformUrl ??
|
|
2608
|
+
platformUrl: (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim()
|
|
2548
2609
|
};
|
|
2549
2610
|
}
|
|
2550
2611
|
function sdkHeaders(secretKey) {
|
|
@@ -2559,7 +2620,7 @@ async function getOAuthProvidersWithInfo(options) {
|
|
|
2559
2620
|
return data.providers || [];
|
|
2560
2621
|
}
|
|
2561
2622
|
async function fetchOAuthProviders(options) {
|
|
2562
|
-
const baseURL = (options.platformUrl ??
|
|
2623
|
+
const baseURL = (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2563
2624
|
const appId = validateAndSanitizeAppId(options.appId);
|
|
2564
2625
|
return cachedFetch({
|
|
2565
2626
|
url: `${baseURL}/api/auth/providers`,
|
|
@@ -2569,7 +2630,7 @@ async function fetchOAuthProviders(options) {
|
|
|
2569
2630
|
});
|
|
2570
2631
|
}
|
|
2571
2632
|
async function getPlans(options) {
|
|
2572
|
-
const { secretKey, platformUrl =
|
|
2633
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2573
2634
|
return cachedFetch({
|
|
2574
2635
|
url: `${platformUrl}${SDK_API_PATH}/billing/plans`,
|
|
2575
2636
|
headers: sdkHeaders(secretKey),
|
|
@@ -2578,7 +2639,7 @@ async function getPlans(options) {
|
|
|
2578
2639
|
});
|
|
2579
2640
|
}
|
|
2580
2641
|
async function getConsentTypes(options) {
|
|
2581
|
-
const { secretKey, platformUrl =
|
|
2642
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2582
2643
|
return cachedFetch({
|
|
2583
2644
|
url: `${platformUrl}${SDK_API_PATH}/consent/types`,
|
|
2584
2645
|
headers: sdkHeaders(secretKey),
|
|
@@ -2587,7 +2648,7 @@ async function getConsentTypes(options) {
|
|
|
2587
2648
|
});
|
|
2588
2649
|
}
|
|
2589
2650
|
async function getFeatureFlags(options) {
|
|
2590
|
-
const { secretKey, platformUrl =
|
|
2651
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2591
2652
|
return cachedFetch({
|
|
2592
2653
|
url: `${platformUrl}${SDK_API_PATH}/flags`,
|
|
2593
2654
|
headers: sdkHeaders(secretKey),
|
|
@@ -2596,7 +2657,7 @@ async function getFeatureFlags(options) {
|
|
|
2596
2657
|
});
|
|
2597
2658
|
}
|
|
2598
2659
|
async function getAppMetadata(options) {
|
|
2599
|
-
const { secretKey, platformUrl =
|
|
2660
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2600
2661
|
return cachedFetch({
|
|
2601
2662
|
url: `${platformUrl}${SDK_API_PATH}/app`,
|
|
2602
2663
|
headers: sdkHeaders(secretKey),
|
|
@@ -2625,7 +2686,7 @@ async function getAppConfig(options) {
|
|
|
2625
2686
|
async function getReferralLeaderboard(options) {
|
|
2626
2687
|
const {
|
|
2627
2688
|
secretKey,
|
|
2628
|
-
platformUrl =
|
|
2689
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2629
2690
|
limit = 10,
|
|
2630
2691
|
period = "all"
|
|
2631
2692
|
} = sanitizeOptions(options);
|
|
@@ -2643,7 +2704,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2643
2704
|
const {
|
|
2644
2705
|
secretKey,
|
|
2645
2706
|
leaderboardId,
|
|
2646
|
-
platformUrl =
|
|
2707
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2647
2708
|
limit = 10
|
|
2648
2709
|
} = sanitizeOptions(options);
|
|
2649
2710
|
const url = new URL(
|
|
@@ -2664,7 +2725,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2664
2725
|
});
|
|
2665
2726
|
}
|
|
2666
2727
|
async function getDatabaseConnection(options) {
|
|
2667
|
-
const { secretKey, platformUrl =
|
|
2728
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2668
2729
|
try {
|
|
2669
2730
|
const response = await fetch(`${platformUrl}${SDK_API_PATH}/database/connection-string`, {
|
|
2670
2731
|
headers: sdkHeaders(secretKey),
|
|
@@ -2689,7 +2750,7 @@ async function getDatabaseConnection(options) {
|
|
|
2689
2750
|
}
|
|
2690
2751
|
}
|
|
2691
2752
|
async function getDatabaseStatus(options) {
|
|
2692
|
-
const { secretKey, platformUrl =
|
|
2753
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2693
2754
|
return cachedFetch({
|
|
2694
2755
|
url: `${platformUrl}${SDK_API_PATH}/database/status`,
|
|
2695
2756
|
headers: sdkHeaders(secretKey),
|
|
@@ -2710,8 +2771,10 @@ async function getDatabaseStatus(options) {
|
|
|
2710
2771
|
createServerClient,
|
|
2711
2772
|
createStreams,
|
|
2712
2773
|
createWebhookHandler,
|
|
2774
|
+
decodeUserId,
|
|
2713
2775
|
detectEnvironment,
|
|
2714
2776
|
detectKeyType,
|
|
2777
|
+
encodeUserId,
|
|
2715
2778
|
getAI,
|
|
2716
2779
|
getAppConfig,
|
|
2717
2780
|
getAppMetadata,
|