@sylphx/sdk 0.3.1 → 0.3.3
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 +25728 -0
- package/dist/index.d.ts +25728 -0
- package/dist/index.js +179 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +179 -142
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.cts +6237 -0
- package/dist/nextjs/index.d.ts +6237 -0
- package/dist/nextjs/index.js +78 -37
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +76 -37
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +19579 -0
- package/dist/react/index.d.ts +19579 -0
- package/dist/react/index.js +118 -96
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +118 -96
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +20930 -0
- package/dist/server/index.d.ts +20930 -0
- package/dist/server/index.js +82 -47
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +80 -47
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.d.cts +90 -0
- package/dist/web-analytics.d.ts +90 -0
- 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 -5
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,44 @@ function createDynamicRestClient(config) {
|
|
|
1983
1980
|
return client;
|
|
1984
1981
|
}
|
|
1985
1982
|
|
|
1983
|
+
// src/lib/ids.ts
|
|
1984
|
+
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1985
|
+
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1986
|
+
function encodeUserId(uuid) {
|
|
1987
|
+
const hex = uuid.replace(/-/g, "");
|
|
1988
|
+
if (hex.length !== 32)
|
|
1989
|
+
throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
|
|
1990
|
+
let n = BigInt("0x" + hex);
|
|
1991
|
+
let r = "";
|
|
1992
|
+
while (n > 0n) {
|
|
1993
|
+
r = B58[Number(n % 58n)] + r;
|
|
1994
|
+
n /= 58n;
|
|
1995
|
+
}
|
|
1996
|
+
return `user_${r}`;
|
|
1997
|
+
}
|
|
1998
|
+
function decodeUserId(prefixedId) {
|
|
1999
|
+
if (!prefixedId.startsWith("user_")) return null;
|
|
2000
|
+
const enc = prefixedId.slice(5);
|
|
2001
|
+
if (!enc) return null;
|
|
2002
|
+
let n = 0n;
|
|
2003
|
+
for (const c of enc) {
|
|
2004
|
+
const i = B58_MAP[c] ?? -1;
|
|
2005
|
+
if (i === -1) return null;
|
|
2006
|
+
n = n * 58n + BigInt(i);
|
|
2007
|
+
}
|
|
2008
|
+
const hex = n.toString(16).padStart(32, "0");
|
|
2009
|
+
return [
|
|
2010
|
+
hex.slice(0, 8),
|
|
2011
|
+
hex.slice(8, 12),
|
|
2012
|
+
hex.slice(12, 16),
|
|
2013
|
+
hex.slice(16, 20),
|
|
2014
|
+
hex.slice(20)
|
|
2015
|
+
].join("-");
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1986
2018
|
// src/server/ai.ts
|
|
1987
2019
|
function createAI(options = {}) {
|
|
1988
|
-
const baseURL = (options.platformUrl ||
|
|
2020
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
1989
2021
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
1990
2022
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
1991
2023
|
const headers = {
|
|
@@ -2078,7 +2110,7 @@ function getAI() {
|
|
|
2078
2110
|
|
|
2079
2111
|
// src/server/kv.ts
|
|
2080
2112
|
function createKv(options = {}) {
|
|
2081
|
-
const platformUrl =
|
|
2113
|
+
const platformUrl = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2082
2114
|
const secretKey = validateAndSanitizeSecretKey(resolveSecretKey(options.secretKey));
|
|
2083
2115
|
const headers = {
|
|
2084
2116
|
"Content-Type": "application/json",
|
|
@@ -2267,7 +2299,7 @@ function getKv() {
|
|
|
2267
2299
|
|
|
2268
2300
|
// src/server/streams.ts
|
|
2269
2301
|
function createStreams(options = {}) {
|
|
2270
|
-
const baseURL = (options.platformUrl ||
|
|
2302
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2271
2303
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
2272
2304
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
2273
2305
|
const headers = {
|
|
@@ -2350,7 +2382,7 @@ var jwksCache = null;
|
|
|
2350
2382
|
function resetJwksCache() {
|
|
2351
2383
|
jwksCache = null;
|
|
2352
2384
|
}
|
|
2353
|
-
async function getJwks(platformUrl =
|
|
2385
|
+
async function getJwks(platformUrl = `https://${DEFAULT_SDK_API_HOST}`) {
|
|
2354
2386
|
const now = Date.now();
|
|
2355
2387
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
2356
2388
|
return jwksCache.keys;
|
|
@@ -2371,7 +2403,7 @@ async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
|
2371
2403
|
return data.keys;
|
|
2372
2404
|
}
|
|
2373
2405
|
async function verifyAccessToken(token, options) {
|
|
2374
|
-
const platformUrl = options.platformUrl ||
|
|
2406
|
+
const platformUrl = options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`;
|
|
2375
2407
|
const keys = await getJwks(platformUrl);
|
|
2376
2408
|
if (!keys.length) {
|
|
2377
2409
|
throw new Error("No keys in JWKS");
|
|
@@ -2388,6 +2420,7 @@ async function verifyAccessToken(token, options) {
|
|
|
2388
2420
|
}
|
|
2389
2421
|
return {
|
|
2390
2422
|
sub: payload.sub,
|
|
2423
|
+
pid: payload.pid,
|
|
2391
2424
|
email: payload.email,
|
|
2392
2425
|
name: payload.name,
|
|
2393
2426
|
picture: payload.picture,
|
|
@@ -2544,7 +2577,7 @@ function sanitizeOptions(options) {
|
|
|
2544
2577
|
return {
|
|
2545
2578
|
...options,
|
|
2546
2579
|
secretKey: validateAndSanitizeSecretKey(options.secretKey),
|
|
2547
|
-
platformUrl: (options.platformUrl ??
|
|
2580
|
+
platformUrl: (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim()
|
|
2548
2581
|
};
|
|
2549
2582
|
}
|
|
2550
2583
|
function sdkHeaders(secretKey) {
|
|
@@ -2559,7 +2592,7 @@ async function getOAuthProvidersWithInfo(options) {
|
|
|
2559
2592
|
return data.providers || [];
|
|
2560
2593
|
}
|
|
2561
2594
|
async function fetchOAuthProviders(options) {
|
|
2562
|
-
const baseURL = (options.platformUrl ??
|
|
2595
|
+
const baseURL = (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2563
2596
|
const appId = validateAndSanitizeAppId(options.appId);
|
|
2564
2597
|
return cachedFetch({
|
|
2565
2598
|
url: `${baseURL}/api/auth/providers`,
|
|
@@ -2569,7 +2602,7 @@ async function fetchOAuthProviders(options) {
|
|
|
2569
2602
|
});
|
|
2570
2603
|
}
|
|
2571
2604
|
async function getPlans(options) {
|
|
2572
|
-
const { secretKey, platformUrl =
|
|
2605
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2573
2606
|
return cachedFetch({
|
|
2574
2607
|
url: `${platformUrl}${SDK_API_PATH}/billing/plans`,
|
|
2575
2608
|
headers: sdkHeaders(secretKey),
|
|
@@ -2578,7 +2611,7 @@ async function getPlans(options) {
|
|
|
2578
2611
|
});
|
|
2579
2612
|
}
|
|
2580
2613
|
async function getConsentTypes(options) {
|
|
2581
|
-
const { secretKey, platformUrl =
|
|
2614
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2582
2615
|
return cachedFetch({
|
|
2583
2616
|
url: `${platformUrl}${SDK_API_PATH}/consent/types`,
|
|
2584
2617
|
headers: sdkHeaders(secretKey),
|
|
@@ -2587,7 +2620,7 @@ async function getConsentTypes(options) {
|
|
|
2587
2620
|
});
|
|
2588
2621
|
}
|
|
2589
2622
|
async function getFeatureFlags(options) {
|
|
2590
|
-
const { secretKey, platformUrl =
|
|
2623
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2591
2624
|
return cachedFetch({
|
|
2592
2625
|
url: `${platformUrl}${SDK_API_PATH}/flags`,
|
|
2593
2626
|
headers: sdkHeaders(secretKey),
|
|
@@ -2596,7 +2629,7 @@ async function getFeatureFlags(options) {
|
|
|
2596
2629
|
});
|
|
2597
2630
|
}
|
|
2598
2631
|
async function getAppMetadata(options) {
|
|
2599
|
-
const { secretKey, platformUrl =
|
|
2632
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2600
2633
|
return cachedFetch({
|
|
2601
2634
|
url: `${platformUrl}${SDK_API_PATH}/app`,
|
|
2602
2635
|
headers: sdkHeaders(secretKey),
|
|
@@ -2625,7 +2658,7 @@ async function getAppConfig(options) {
|
|
|
2625
2658
|
async function getReferralLeaderboard(options) {
|
|
2626
2659
|
const {
|
|
2627
2660
|
secretKey,
|
|
2628
|
-
platformUrl =
|
|
2661
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2629
2662
|
limit = 10,
|
|
2630
2663
|
period = "all"
|
|
2631
2664
|
} = sanitizeOptions(options);
|
|
@@ -2643,7 +2676,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2643
2676
|
const {
|
|
2644
2677
|
secretKey,
|
|
2645
2678
|
leaderboardId,
|
|
2646
|
-
platformUrl =
|
|
2679
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2647
2680
|
limit = 10
|
|
2648
2681
|
} = sanitizeOptions(options);
|
|
2649
2682
|
const url = new URL(
|
|
@@ -2664,7 +2697,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2664
2697
|
});
|
|
2665
2698
|
}
|
|
2666
2699
|
async function getDatabaseConnection(options) {
|
|
2667
|
-
const { secretKey, platformUrl =
|
|
2700
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2668
2701
|
try {
|
|
2669
2702
|
const response = await fetch(`${platformUrl}${SDK_API_PATH}/database/connection-string`, {
|
|
2670
2703
|
headers: sdkHeaders(secretKey),
|
|
@@ -2689,7 +2722,7 @@ async function getDatabaseConnection(options) {
|
|
|
2689
2722
|
}
|
|
2690
2723
|
}
|
|
2691
2724
|
async function getDatabaseStatus(options) {
|
|
2692
|
-
const { secretKey, platformUrl =
|
|
2725
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2693
2726
|
return cachedFetch({
|
|
2694
2727
|
url: `${platformUrl}${SDK_API_PATH}/database/status`,
|
|
2695
2728
|
headers: sdkHeaders(secretKey),
|
|
@@ -2710,8 +2743,10 @@ async function getDatabaseStatus(options) {
|
|
|
2710
2743
|
createServerClient,
|
|
2711
2744
|
createStreams,
|
|
2712
2745
|
createWebhookHandler,
|
|
2746
|
+
decodeUserId,
|
|
2713
2747
|
detectEnvironment,
|
|
2714
2748
|
detectKeyType,
|
|
2749
|
+
encodeUserId,
|
|
2715
2750
|
getAI,
|
|
2716
2751
|
getAppConfig,
|
|
2717
2752
|
getAppMetadata,
|