@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
2
2
|
var encoder = new TextEncoder();
|
|
3
3
|
var decoder = new TextDecoder();
|
|
4
4
|
var MAX_INT32 = 2 ** 32;
|
|
@@ -24,7 +24,7 @@ function encode(string) {
|
|
|
24
24
|
return bytes;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// node_modules/jose/dist/webapi/lib/base64.js
|
|
28
28
|
function decodeBase64(encoded) {
|
|
29
29
|
if (Uint8Array.fromBase64) {
|
|
30
30
|
return Uint8Array.fromBase64(encoded);
|
|
@@ -37,7 +37,7 @@ function decodeBase64(encoded) {
|
|
|
37
37
|
return bytes;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
//
|
|
40
|
+
// node_modules/jose/dist/webapi/util/base64url.js
|
|
41
41
|
function decode(input) {
|
|
42
42
|
if (Uint8Array.fromBase64) {
|
|
43
43
|
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
@@ -56,7 +56,7 @@ function decode(input) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
//
|
|
59
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
60
60
|
var JOSEError = class extends Error {
|
|
61
61
|
static code = "ERR_JOSE_GENERIC";
|
|
62
62
|
code = "ERR_JOSE_GENERIC";
|
|
@@ -116,7 +116,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
//
|
|
119
|
+
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
120
120
|
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
121
121
|
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
122
122
|
function getHashLength(hash) {
|
|
@@ -204,7 +204,7 @@ function checkSigCryptoKey(key, alg, usage) {
|
|
|
204
204
|
checkUsage(key, usage);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
//
|
|
207
|
+
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
208
208
|
function message(msg, actual, ...types) {
|
|
209
209
|
types = types.filter(Boolean);
|
|
210
210
|
if (types.length > 2) {
|
|
@@ -229,7 +229,7 @@ function message(msg, actual, ...types) {
|
|
|
229
229
|
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
230
230
|
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
231
231
|
|
|
232
|
-
//
|
|
232
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
233
233
|
var isCryptoKey = (key) => {
|
|
234
234
|
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
235
235
|
return true;
|
|
@@ -242,7 +242,7 @@ var isCryptoKey = (key) => {
|
|
|
242
242
|
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
243
243
|
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
244
244
|
|
|
245
|
-
//
|
|
245
|
+
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
246
246
|
function isDisjoint(...headers) {
|
|
247
247
|
const sources = headers.filter(Boolean);
|
|
248
248
|
if (sources.length === 0 || sources.length === 1) {
|
|
@@ -265,7 +265,7 @@ function isDisjoint(...headers) {
|
|
|
265
265
|
return true;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
//
|
|
268
|
+
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
269
269
|
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
270
270
|
function isObject(input) {
|
|
271
271
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
@@ -281,7 +281,7 @@ function isObject(input) {
|
|
|
281
281
|
return Object.getPrototypeOf(input) === proto;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
//
|
|
284
|
+
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
285
285
|
function checkKeyLength(alg, key) {
|
|
286
286
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
287
287
|
const { modulusLength } = key.algorithm;
|
|
@@ -291,7 +291,7 @@ function checkKeyLength(alg, key) {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
//
|
|
294
|
+
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
295
295
|
function subtleMapping(jwk) {
|
|
296
296
|
let algorithm;
|
|
297
297
|
let keyUsages;
|
|
@@ -401,7 +401,7 @@ async function jwkToKey(jwk) {
|
|
|
401
401
|
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
//
|
|
404
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
405
405
|
async function importJWK(jwk, alg, options) {
|
|
406
406
|
if (!isObject(jwk)) {
|
|
407
407
|
throw new TypeError("JWK must be an object");
|
|
@@ -437,7 +437,7 @@ async function importJWK(jwk, alg, options) {
|
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
//
|
|
440
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
441
441
|
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
442
442
|
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
443
443
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
@@ -468,7 +468,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
468
468
|
return new Set(protectedHeader.crit);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
//
|
|
471
|
+
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
472
472
|
function validateAlgorithms(option, algorithms) {
|
|
473
473
|
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
474
474
|
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
@@ -479,13 +479,13 @@ function validateAlgorithms(option, algorithms) {
|
|
|
479
479
|
return new Set(algorithms);
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
//
|
|
482
|
+
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
483
483
|
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
484
484
|
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
485
485
|
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
486
486
|
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
487
487
|
|
|
488
|
-
//
|
|
488
|
+
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
489
489
|
var cache;
|
|
490
490
|
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
491
491
|
cache ||= /* @__PURE__ */ new WeakMap();
|
|
@@ -656,7 +656,7 @@ async function normalizeKey(key, alg) {
|
|
|
656
656
|
throw new Error("unreachable");
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
-
//
|
|
659
|
+
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
660
660
|
var tag = (key) => key?.[Symbol.toStringTag];
|
|
661
661
|
var jwkMatchesOp = (alg, key, usage) => {
|
|
662
662
|
if (key.use !== void 0) {
|
|
@@ -776,7 +776,7 @@ function checkKeyType(alg, key, usage) {
|
|
|
776
776
|
}
|
|
777
777
|
}
|
|
778
778
|
|
|
779
|
-
//
|
|
779
|
+
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
780
780
|
function subtleAlgorithm(alg, algorithm) {
|
|
781
781
|
const hash = `SHA-${alg.slice(-3)}`;
|
|
782
782
|
switch (alg) {
|
|
@@ -808,7 +808,7 @@ function subtleAlgorithm(alg, algorithm) {
|
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
810
|
|
|
811
|
-
//
|
|
811
|
+
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
812
812
|
async function getSigKey(alg, key, usage) {
|
|
813
813
|
if (key instanceof Uint8Array) {
|
|
814
814
|
if (!alg.startsWith("HS")) {
|
|
@@ -820,7 +820,7 @@ async function getSigKey(alg, key, usage) {
|
|
|
820
820
|
return key;
|
|
821
821
|
}
|
|
822
822
|
|
|
823
|
-
//
|
|
823
|
+
// node_modules/jose/dist/webapi/lib/verify.js
|
|
824
824
|
async function verify(alg, key, signature, data) {
|
|
825
825
|
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
826
826
|
checkKeyLength(alg, cryptoKey);
|
|
@@ -832,7 +832,7 @@ async function verify(alg, key, signature, data) {
|
|
|
832
832
|
}
|
|
833
833
|
}
|
|
834
834
|
|
|
835
|
-
//
|
|
835
|
+
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
836
836
|
async function flattenedVerify(jws, key, options) {
|
|
837
837
|
if (!isObject(jws)) {
|
|
838
838
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -934,7 +934,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
934
934
|
return result;
|
|
935
935
|
}
|
|
936
936
|
|
|
937
|
-
//
|
|
937
|
+
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
938
938
|
async function compactVerify(jws, key, options) {
|
|
939
939
|
if (jws instanceof Uint8Array) {
|
|
940
940
|
jws = decoder.decode(jws);
|
|
@@ -954,7 +954,7 @@ async function compactVerify(jws, key, options) {
|
|
|
954
954
|
return result;
|
|
955
955
|
}
|
|
956
956
|
|
|
957
|
-
//
|
|
957
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
958
958
|
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
959
959
|
var minute = 60;
|
|
960
960
|
var hour = minute * 60;
|
|
@@ -1111,7 +1111,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
1111
1111
|
return payload;
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
|
-
//
|
|
1114
|
+
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
1115
1115
|
async function jwtVerify(jwt, key, options) {
|
|
1116
1116
|
const verified = await compactVerify(jwt, key, options);
|
|
1117
1117
|
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
@@ -1126,17 +1126,12 @@ async function jwtVerify(jwt, key, options) {
|
|
|
1126
1126
|
}
|
|
1127
1127
|
|
|
1128
1128
|
// src/constants.ts
|
|
1129
|
-
var DEFAULT_PLATFORM_URL = "https://sylphx.com";
|
|
1130
|
-
var ENV_PLATFORM_URL = "SYLPHX_PLATFORM_URL";
|
|
1131
|
-
var ENV_PLATFORM_URL_LEGACY = "SYLPHX_URL";
|
|
1132
1129
|
var ENV_SECRET_KEY = "SYLPHX_SECRET_KEY";
|
|
1133
|
-
function resolvePlatformUrl(explicit) {
|
|
1134
|
-
return (explicit || process.env[ENV_PLATFORM_URL] || process.env[ENV_PLATFORM_URL_LEGACY] || DEFAULT_PLATFORM_URL).trim();
|
|
1135
|
-
}
|
|
1136
1130
|
function resolveSecretKey(explicit) {
|
|
1137
1131
|
return explicit || process.env[ENV_SECRET_KEY];
|
|
1138
1132
|
}
|
|
1139
|
-
var SDK_API_PATH = `/
|
|
1133
|
+
var SDK_API_PATH = `/v1`;
|
|
1134
|
+
var DEFAULT_SDK_API_HOST = "api.sylphx.com";
|
|
1140
1135
|
var SDK_VERSION = "0.1.0";
|
|
1141
1136
|
var SDK_PLATFORM = typeof window !== "undefined" ? "browser" : typeof process !== "undefined" && process.versions?.node ? "node" : "unknown";
|
|
1142
1137
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -1859,7 +1854,7 @@ function createRetryMiddleware(retryConfig) {
|
|
|
1859
1854
|
function validateClientConfig(config) {
|
|
1860
1855
|
return {
|
|
1861
1856
|
secretKey: validateAndSanitizeSecretKey(config.secretKey),
|
|
1862
|
-
baseUrl: (config.platformUrl ||
|
|
1857
|
+
baseUrl: (config.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim()
|
|
1863
1858
|
};
|
|
1864
1859
|
}
|
|
1865
1860
|
function createRestClient(config) {
|
|
@@ -1910,9 +1905,72 @@ function createDynamicRestClient(config) {
|
|
|
1910
1905
|
return client;
|
|
1911
1906
|
}
|
|
1912
1907
|
|
|
1908
|
+
// src/lib/ids.ts
|
|
1909
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1910
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1911
|
+
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1912
|
+
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1913
|
+
function cb32Encode(hex) {
|
|
1914
|
+
const num = BigInt(`0x${hex}`);
|
|
1915
|
+
const chars = [];
|
|
1916
|
+
let n = num;
|
|
1917
|
+
for (let i = 0; i < 26; i++) {
|
|
1918
|
+
chars.unshift(CB32[Number(n & 0x1fn)]);
|
|
1919
|
+
n >>= 5n;
|
|
1920
|
+
}
|
|
1921
|
+
return chars.join("");
|
|
1922
|
+
}
|
|
1923
|
+
function cb32Decode(str) {
|
|
1924
|
+
if (str.length !== 26) return null;
|
|
1925
|
+
let n = 0n;
|
|
1926
|
+
for (const c of str.toLowerCase()) {
|
|
1927
|
+
const idx = CB32_MAP[c];
|
|
1928
|
+
if (idx === void 0) return null;
|
|
1929
|
+
n = n << 5n | BigInt(idx);
|
|
1930
|
+
}
|
|
1931
|
+
return n.toString(16).padStart(32, "0");
|
|
1932
|
+
}
|
|
1933
|
+
function b58Decode(str) {
|
|
1934
|
+
let n = 0n;
|
|
1935
|
+
for (const c of str) {
|
|
1936
|
+
const i = B58_MAP[c] ?? -1;
|
|
1937
|
+
if (i === -1) return null;
|
|
1938
|
+
n = n * 58n + BigInt(i);
|
|
1939
|
+
}
|
|
1940
|
+
const hex = n.toString(16).padStart(32, "0");
|
|
1941
|
+
return hex.length === 32 ? hex : null;
|
|
1942
|
+
}
|
|
1943
|
+
function hexToUuid(hex) {
|
|
1944
|
+
return [
|
|
1945
|
+
hex.slice(0, 8),
|
|
1946
|
+
hex.slice(8, 12),
|
|
1947
|
+
hex.slice(12, 16),
|
|
1948
|
+
hex.slice(16, 20),
|
|
1949
|
+
hex.slice(20)
|
|
1950
|
+
].join("-");
|
|
1951
|
+
}
|
|
1952
|
+
function encodeUserId(uuid) {
|
|
1953
|
+
const hex = uuid.replace(/-/g, "");
|
|
1954
|
+
if (hex.length !== 32)
|
|
1955
|
+
throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
|
|
1956
|
+
return `user_${cb32Encode(hex)}`;
|
|
1957
|
+
}
|
|
1958
|
+
function decodeUserId(prefixedId) {
|
|
1959
|
+
if (!prefixedId.startsWith("user_")) return null;
|
|
1960
|
+
const enc = prefixedId.slice(5);
|
|
1961
|
+
if (!enc) return null;
|
|
1962
|
+
if (enc.length === 26) {
|
|
1963
|
+
const hex2 = cb32Decode(enc);
|
|
1964
|
+
if (hex2) return hexToUuid(hex2);
|
|
1965
|
+
}
|
|
1966
|
+
const hex = b58Decode(enc);
|
|
1967
|
+
if (hex) return hexToUuid(hex);
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1913
1971
|
// src/server/ai.ts
|
|
1914
1972
|
function createAI(options = {}) {
|
|
1915
|
-
const baseURL = (options.platformUrl ||
|
|
1973
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
1916
1974
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
1917
1975
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
1918
1976
|
const headers = {
|
|
@@ -2005,7 +2063,7 @@ function getAI() {
|
|
|
2005
2063
|
|
|
2006
2064
|
// src/server/kv.ts
|
|
2007
2065
|
function createKv(options = {}) {
|
|
2008
|
-
const platformUrl =
|
|
2066
|
+
const platformUrl = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2009
2067
|
const secretKey = validateAndSanitizeSecretKey(resolveSecretKey(options.secretKey));
|
|
2010
2068
|
const headers = {
|
|
2011
2069
|
"Content-Type": "application/json",
|
|
@@ -2194,7 +2252,7 @@ function getKv() {
|
|
|
2194
2252
|
|
|
2195
2253
|
// src/server/streams.ts
|
|
2196
2254
|
function createStreams(options = {}) {
|
|
2197
|
-
const baseURL = (options.platformUrl ||
|
|
2255
|
+
const baseURL = (options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2198
2256
|
const rawApiKey = options.secretKey || process.env.SYLPHX_SECRET_KEY;
|
|
2199
2257
|
const apiKey = validateAndSanitizeSecretKey(rawApiKey);
|
|
2200
2258
|
const headers = {
|
|
@@ -2277,7 +2335,7 @@ var jwksCache = null;
|
|
|
2277
2335
|
function resetJwksCache() {
|
|
2278
2336
|
jwksCache = null;
|
|
2279
2337
|
}
|
|
2280
|
-
async function getJwks(platformUrl =
|
|
2338
|
+
async function getJwks(platformUrl = `https://${DEFAULT_SDK_API_HOST}`) {
|
|
2281
2339
|
const now = Date.now();
|
|
2282
2340
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
2283
2341
|
return jwksCache.keys;
|
|
@@ -2298,7 +2356,7 @@ async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
|
2298
2356
|
return data.keys;
|
|
2299
2357
|
}
|
|
2300
2358
|
async function verifyAccessToken(token, options) {
|
|
2301
|
-
const platformUrl = options.platformUrl ||
|
|
2359
|
+
const platformUrl = options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`;
|
|
2302
2360
|
const keys = await getJwks(platformUrl);
|
|
2303
2361
|
if (!keys.length) {
|
|
2304
2362
|
throw new Error("No keys in JWKS");
|
|
@@ -2315,6 +2373,7 @@ async function verifyAccessToken(token, options) {
|
|
|
2315
2373
|
}
|
|
2316
2374
|
return {
|
|
2317
2375
|
sub: payload.sub,
|
|
2376
|
+
pid: payload.pid,
|
|
2318
2377
|
email: payload.email,
|
|
2319
2378
|
name: payload.name,
|
|
2320
2379
|
picture: payload.picture,
|
|
@@ -2471,7 +2530,7 @@ function sanitizeOptions(options) {
|
|
|
2471
2530
|
return {
|
|
2472
2531
|
...options,
|
|
2473
2532
|
secretKey: validateAndSanitizeSecretKey(options.secretKey),
|
|
2474
|
-
platformUrl: (options.platformUrl ??
|
|
2533
|
+
platformUrl: (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim()
|
|
2475
2534
|
};
|
|
2476
2535
|
}
|
|
2477
2536
|
function sdkHeaders(secretKey) {
|
|
@@ -2486,7 +2545,7 @@ async function getOAuthProvidersWithInfo(options) {
|
|
|
2486
2545
|
return data.providers || [];
|
|
2487
2546
|
}
|
|
2488
2547
|
async function fetchOAuthProviders(options) {
|
|
2489
|
-
const baseURL = (options.platformUrl ??
|
|
2548
|
+
const baseURL = (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
2490
2549
|
const appId = validateAndSanitizeAppId(options.appId);
|
|
2491
2550
|
return cachedFetch({
|
|
2492
2551
|
url: `${baseURL}/api/auth/providers`,
|
|
@@ -2496,7 +2555,7 @@ async function fetchOAuthProviders(options) {
|
|
|
2496
2555
|
});
|
|
2497
2556
|
}
|
|
2498
2557
|
async function getPlans(options) {
|
|
2499
|
-
const { secretKey, platformUrl =
|
|
2558
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2500
2559
|
return cachedFetch({
|
|
2501
2560
|
url: `${platformUrl}${SDK_API_PATH}/billing/plans`,
|
|
2502
2561
|
headers: sdkHeaders(secretKey),
|
|
@@ -2505,7 +2564,7 @@ async function getPlans(options) {
|
|
|
2505
2564
|
});
|
|
2506
2565
|
}
|
|
2507
2566
|
async function getConsentTypes(options) {
|
|
2508
|
-
const { secretKey, platformUrl =
|
|
2567
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2509
2568
|
return cachedFetch({
|
|
2510
2569
|
url: `${platformUrl}${SDK_API_PATH}/consent/types`,
|
|
2511
2570
|
headers: sdkHeaders(secretKey),
|
|
@@ -2514,7 +2573,7 @@ async function getConsentTypes(options) {
|
|
|
2514
2573
|
});
|
|
2515
2574
|
}
|
|
2516
2575
|
async function getFeatureFlags(options) {
|
|
2517
|
-
const { secretKey, platformUrl =
|
|
2576
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2518
2577
|
return cachedFetch({
|
|
2519
2578
|
url: `${platformUrl}${SDK_API_PATH}/flags`,
|
|
2520
2579
|
headers: sdkHeaders(secretKey),
|
|
@@ -2523,7 +2582,7 @@ async function getFeatureFlags(options) {
|
|
|
2523
2582
|
});
|
|
2524
2583
|
}
|
|
2525
2584
|
async function getAppMetadata(options) {
|
|
2526
|
-
const { secretKey, platformUrl =
|
|
2585
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2527
2586
|
return cachedFetch({
|
|
2528
2587
|
url: `${platformUrl}${SDK_API_PATH}/app`,
|
|
2529
2588
|
headers: sdkHeaders(secretKey),
|
|
@@ -2552,7 +2611,7 @@ async function getAppConfig(options) {
|
|
|
2552
2611
|
async function getReferralLeaderboard(options) {
|
|
2553
2612
|
const {
|
|
2554
2613
|
secretKey,
|
|
2555
|
-
platformUrl =
|
|
2614
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2556
2615
|
limit = 10,
|
|
2557
2616
|
period = "all"
|
|
2558
2617
|
} = sanitizeOptions(options);
|
|
@@ -2570,7 +2629,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2570
2629
|
const {
|
|
2571
2630
|
secretKey,
|
|
2572
2631
|
leaderboardId,
|
|
2573
|
-
platformUrl =
|
|
2632
|
+
platformUrl = `https://${DEFAULT_SDK_API_HOST}`,
|
|
2574
2633
|
limit = 10
|
|
2575
2634
|
} = sanitizeOptions(options);
|
|
2576
2635
|
const url = new URL(
|
|
@@ -2591,7 +2650,7 @@ async function getEngagementLeaderboard(options) {
|
|
|
2591
2650
|
});
|
|
2592
2651
|
}
|
|
2593
2652
|
async function getDatabaseConnection(options) {
|
|
2594
|
-
const { secretKey, platformUrl =
|
|
2653
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2595
2654
|
try {
|
|
2596
2655
|
const response = await fetch(`${platformUrl}${SDK_API_PATH}/database/connection-string`, {
|
|
2597
2656
|
headers: sdkHeaders(secretKey),
|
|
@@ -2616,7 +2675,7 @@ async function getDatabaseConnection(options) {
|
|
|
2616
2675
|
}
|
|
2617
2676
|
}
|
|
2618
2677
|
async function getDatabaseStatus(options) {
|
|
2619
|
-
const { secretKey, platformUrl =
|
|
2678
|
+
const { secretKey, platformUrl = `https://${DEFAULT_SDK_API_HOST}` } = sanitizeOptions(options);
|
|
2620
2679
|
return cachedFetch({
|
|
2621
2680
|
url: `${platformUrl}${SDK_API_PATH}/database/status`,
|
|
2622
2681
|
headers: sdkHeaders(secretKey),
|
|
@@ -2636,8 +2695,10 @@ export {
|
|
|
2636
2695
|
createServerClient,
|
|
2637
2696
|
createStreams,
|
|
2638
2697
|
createWebhookHandler,
|
|
2698
|
+
decodeUserId,
|
|
2639
2699
|
detectEnvironment,
|
|
2640
2700
|
detectKeyType,
|
|
2701
|
+
encodeUserId,
|
|
2641
2702
|
getAI,
|
|
2642
2703
|
getAppConfig,
|
|
2643
2704
|
getAppMetadata,
|