@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/nextjs/index.js
CHANGED
|
@@ -34,6 +34,8 @@ __export(nextjs_exports, {
|
|
|
34
34
|
createSylphxMiddleware: () => createSylphxMiddleware,
|
|
35
35
|
currentUser: () => currentUser,
|
|
36
36
|
currentUserId: () => currentUserId,
|
|
37
|
+
decodeUserId: () => decodeUserId,
|
|
38
|
+
encodeUserId: () => encodeUserId,
|
|
37
39
|
getAuthCookies: () => getAuthCookies,
|
|
38
40
|
getAuthorizationUrl: () => getAuthorizationUrl,
|
|
39
41
|
getCookieNames: () => getCookieNames,
|
|
@@ -54,7 +56,7 @@ module.exports = __toCommonJS(nextjs_exports);
|
|
|
54
56
|
var import_server = require("next/server");
|
|
55
57
|
|
|
56
58
|
// src/constants.ts
|
|
57
|
-
var
|
|
59
|
+
var DEFAULT_SDK_API_HOST = "api.sylphx.com";
|
|
58
60
|
var SDK_PLATFORM = typeof window !== "undefined" ? "browser" : typeof process !== "undefined" && process.versions?.node ? "node" : "unknown";
|
|
59
61
|
var TOKEN_EXPIRY_BUFFER_MS = 3e4;
|
|
60
62
|
var SESSION_TOKEN_LIFETIME_SECONDS = 5 * 60;
|
|
@@ -399,7 +401,7 @@ async function handleCallback(request, ctx) {
|
|
|
399
401
|
return import_server.NextResponse.redirect(url);
|
|
400
402
|
}
|
|
401
403
|
try {
|
|
402
|
-
const res = await fetch(`${ctx.platformUrl}/
|
|
404
|
+
const res = await fetch(`${ctx.platformUrl}/v1/auth/token`, {
|
|
403
405
|
method: "POST",
|
|
404
406
|
headers: { "Content-Type": "application/json" },
|
|
405
407
|
body: JSON.stringify({
|
|
@@ -437,7 +439,7 @@ async function handleSignOut(request, ctx) {
|
|
|
437
439
|
const refreshToken = request.cookies.get(ctx.cookieNames.REFRESH)?.value;
|
|
438
440
|
if (refreshToken) {
|
|
439
441
|
try {
|
|
440
|
-
await fetch(`${ctx.platformUrl}/
|
|
442
|
+
await fetch(`${ctx.platformUrl}/v1/auth/revoke`, {
|
|
441
443
|
method: "POST",
|
|
442
444
|
headers: { "Content-Type": "application/json" },
|
|
443
445
|
body: JSON.stringify({
|
|
@@ -471,7 +473,7 @@ function handleToken(request, ctx) {
|
|
|
471
473
|
async function refreshTokens(refreshToken, ctx) {
|
|
472
474
|
ctx.log("Refreshing tokens");
|
|
473
475
|
try {
|
|
474
|
-
const res = await fetch(`${ctx.platformUrl}/
|
|
476
|
+
const res = await fetch(`${ctx.platformUrl}/v1/auth/token`, {
|
|
475
477
|
method: "POST",
|
|
476
478
|
headers: { "Content-Type": "application/json" },
|
|
477
479
|
body: JSON.stringify({
|
|
@@ -504,7 +506,7 @@ function createSylphxMiddleware(userConfig = {}) {
|
|
|
504
506
|
);
|
|
505
507
|
}
|
|
506
508
|
const secretKey = validateAndSanitizeSecretKey(rawSecretKey);
|
|
507
|
-
const platformUrl = (userConfig.platformUrl ||
|
|
509
|
+
const platformUrl = (userConfig.platformUrl || `https://${DEFAULT_SDK_API_HOST}`).trim();
|
|
508
510
|
const namespace = getCookieNamespace(secretKey);
|
|
509
511
|
const cookieNames = getCookieNames(namespace);
|
|
510
512
|
const config = {
|
|
@@ -600,7 +602,7 @@ function getNamespace(secretKey) {
|
|
|
600
602
|
// src/nextjs/server.ts
|
|
601
603
|
var import_react = require("react");
|
|
602
604
|
|
|
603
|
-
//
|
|
605
|
+
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
604
606
|
var encoder = new TextEncoder();
|
|
605
607
|
var decoder = new TextDecoder();
|
|
606
608
|
var MAX_INT32 = 2 ** 32;
|
|
@@ -626,7 +628,7 @@ function encode(string) {
|
|
|
626
628
|
return bytes;
|
|
627
629
|
}
|
|
628
630
|
|
|
629
|
-
//
|
|
631
|
+
// node_modules/jose/dist/webapi/lib/base64.js
|
|
630
632
|
function decodeBase64(encoded) {
|
|
631
633
|
if (Uint8Array.fromBase64) {
|
|
632
634
|
return Uint8Array.fromBase64(encoded);
|
|
@@ -639,7 +641,7 @@ function decodeBase64(encoded) {
|
|
|
639
641
|
return bytes;
|
|
640
642
|
}
|
|
641
643
|
|
|
642
|
-
//
|
|
644
|
+
// node_modules/jose/dist/webapi/util/base64url.js
|
|
643
645
|
function decode(input) {
|
|
644
646
|
if (Uint8Array.fromBase64) {
|
|
645
647
|
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
@@ -658,7 +660,7 @@ function decode(input) {
|
|
|
658
660
|
}
|
|
659
661
|
}
|
|
660
662
|
|
|
661
|
-
//
|
|
663
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
662
664
|
var JOSEError = class extends Error {
|
|
663
665
|
static code = "ERR_JOSE_GENERIC";
|
|
664
666
|
code = "ERR_JOSE_GENERIC";
|
|
@@ -718,7 +720,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
|
718
720
|
}
|
|
719
721
|
};
|
|
720
722
|
|
|
721
|
-
//
|
|
723
|
+
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
722
724
|
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
723
725
|
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
724
726
|
function getHashLength(hash) {
|
|
@@ -806,7 +808,7 @@ function checkSigCryptoKey(key, alg, usage) {
|
|
|
806
808
|
checkUsage(key, usage);
|
|
807
809
|
}
|
|
808
810
|
|
|
809
|
-
//
|
|
811
|
+
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
810
812
|
function message(msg, actual, ...types) {
|
|
811
813
|
types = types.filter(Boolean);
|
|
812
814
|
if (types.length > 2) {
|
|
@@ -831,7 +833,7 @@ function message(msg, actual, ...types) {
|
|
|
831
833
|
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
832
834
|
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
833
835
|
|
|
834
|
-
//
|
|
836
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
835
837
|
var isCryptoKey = (key) => {
|
|
836
838
|
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
837
839
|
return true;
|
|
@@ -844,7 +846,7 @@ var isCryptoKey = (key) => {
|
|
|
844
846
|
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
845
847
|
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
846
848
|
|
|
847
|
-
//
|
|
849
|
+
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
848
850
|
function isDisjoint(...headers) {
|
|
849
851
|
const sources = headers.filter(Boolean);
|
|
850
852
|
if (sources.length === 0 || sources.length === 1) {
|
|
@@ -867,7 +869,7 @@ function isDisjoint(...headers) {
|
|
|
867
869
|
return true;
|
|
868
870
|
}
|
|
869
871
|
|
|
870
|
-
//
|
|
872
|
+
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
871
873
|
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
872
874
|
function isObject(input) {
|
|
873
875
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
@@ -883,7 +885,7 @@ function isObject(input) {
|
|
|
883
885
|
return Object.getPrototypeOf(input) === proto;
|
|
884
886
|
}
|
|
885
887
|
|
|
886
|
-
//
|
|
888
|
+
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
887
889
|
function checkKeyLength(alg, key) {
|
|
888
890
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
889
891
|
const { modulusLength } = key.algorithm;
|
|
@@ -893,7 +895,7 @@ function checkKeyLength(alg, key) {
|
|
|
893
895
|
}
|
|
894
896
|
}
|
|
895
897
|
|
|
896
|
-
//
|
|
898
|
+
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
897
899
|
function subtleMapping(jwk) {
|
|
898
900
|
let algorithm;
|
|
899
901
|
let keyUsages;
|
|
@@ -1003,7 +1005,7 @@ async function jwkToKey(jwk) {
|
|
|
1003
1005
|
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1004
1006
|
}
|
|
1005
1007
|
|
|
1006
|
-
//
|
|
1008
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
1007
1009
|
async function importJWK(jwk, alg, options) {
|
|
1008
1010
|
if (!isObject(jwk)) {
|
|
1009
1011
|
throw new TypeError("JWK must be an object");
|
|
@@ -1039,7 +1041,7 @@ async function importJWK(jwk, alg, options) {
|
|
|
1039
1041
|
}
|
|
1040
1042
|
}
|
|
1041
1043
|
|
|
1042
|
-
//
|
|
1044
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1043
1045
|
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1044
1046
|
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1045
1047
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
@@ -1070,7 +1072,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
1070
1072
|
return new Set(protectedHeader.crit);
|
|
1071
1073
|
}
|
|
1072
1074
|
|
|
1073
|
-
//
|
|
1075
|
+
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1074
1076
|
function validateAlgorithms(option, algorithms) {
|
|
1075
1077
|
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
1076
1078
|
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
@@ -1081,13 +1083,13 @@ function validateAlgorithms(option, algorithms) {
|
|
|
1081
1083
|
return new Set(algorithms);
|
|
1082
1084
|
}
|
|
1083
1085
|
|
|
1084
|
-
//
|
|
1086
|
+
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
1085
1087
|
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
1086
1088
|
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
1087
1089
|
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
1088
1090
|
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
1089
1091
|
|
|
1090
|
-
//
|
|
1092
|
+
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1091
1093
|
var cache;
|
|
1092
1094
|
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1093
1095
|
cache ||= /* @__PURE__ */ new WeakMap();
|
|
@@ -1258,7 +1260,7 @@ async function normalizeKey(key, alg) {
|
|
|
1258
1260
|
throw new Error("unreachable");
|
|
1259
1261
|
}
|
|
1260
1262
|
|
|
1261
|
-
//
|
|
1263
|
+
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1262
1264
|
var tag = (key) => key?.[Symbol.toStringTag];
|
|
1263
1265
|
var jwkMatchesOp = (alg, key, usage) => {
|
|
1264
1266
|
if (key.use !== void 0) {
|
|
@@ -1378,7 +1380,7 @@ function checkKeyType(alg, key, usage) {
|
|
|
1378
1380
|
}
|
|
1379
1381
|
}
|
|
1380
1382
|
|
|
1381
|
-
//
|
|
1383
|
+
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
1382
1384
|
function subtleAlgorithm(alg, algorithm) {
|
|
1383
1385
|
const hash = `SHA-${alg.slice(-3)}`;
|
|
1384
1386
|
switch (alg) {
|
|
@@ -1410,7 +1412,7 @@ function subtleAlgorithm(alg, algorithm) {
|
|
|
1410
1412
|
}
|
|
1411
1413
|
}
|
|
1412
1414
|
|
|
1413
|
-
//
|
|
1415
|
+
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
1414
1416
|
async function getSigKey(alg, key, usage) {
|
|
1415
1417
|
if (key instanceof Uint8Array) {
|
|
1416
1418
|
if (!alg.startsWith("HS")) {
|
|
@@ -1422,7 +1424,7 @@ async function getSigKey(alg, key, usage) {
|
|
|
1422
1424
|
return key;
|
|
1423
1425
|
}
|
|
1424
1426
|
|
|
1425
|
-
//
|
|
1427
|
+
// node_modules/jose/dist/webapi/lib/verify.js
|
|
1426
1428
|
async function verify(alg, key, signature, data) {
|
|
1427
1429
|
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
1428
1430
|
checkKeyLength(alg, cryptoKey);
|
|
@@ -1434,7 +1436,7 @@ async function verify(alg, key, signature, data) {
|
|
|
1434
1436
|
}
|
|
1435
1437
|
}
|
|
1436
1438
|
|
|
1437
|
-
//
|
|
1439
|
+
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
1438
1440
|
async function flattenedVerify(jws, key, options) {
|
|
1439
1441
|
if (!isObject(jws)) {
|
|
1440
1442
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -1536,7 +1538,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
1536
1538
|
return result;
|
|
1537
1539
|
}
|
|
1538
1540
|
|
|
1539
|
-
//
|
|
1541
|
+
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1540
1542
|
async function compactVerify(jws, key, options) {
|
|
1541
1543
|
if (jws instanceof Uint8Array) {
|
|
1542
1544
|
jws = decoder.decode(jws);
|
|
@@ -1556,7 +1558,7 @@ async function compactVerify(jws, key, options) {
|
|
|
1556
1558
|
return result;
|
|
1557
1559
|
}
|
|
1558
1560
|
|
|
1559
|
-
//
|
|
1561
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1560
1562
|
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1561
1563
|
var minute = 60;
|
|
1562
1564
|
var hour = minute * 60;
|
|
@@ -1713,7 +1715,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
1713
1715
|
return payload;
|
|
1714
1716
|
}
|
|
1715
1717
|
|
|
1716
|
-
//
|
|
1718
|
+
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
1717
1719
|
async function jwtVerify(jwt, key, options) {
|
|
1718
1720
|
const verified = await compactVerify(jwt, key, options);
|
|
1719
1721
|
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
@@ -1727,6 +1729,69 @@ async function jwtVerify(jwt, key, options) {
|
|
|
1727
1729
|
return result;
|
|
1728
1730
|
}
|
|
1729
1731
|
|
|
1732
|
+
// src/lib/ids.ts
|
|
1733
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1734
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1735
|
+
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1736
|
+
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1737
|
+
function cb32Encode(hex) {
|
|
1738
|
+
const num = BigInt(`0x${hex}`);
|
|
1739
|
+
const chars = [];
|
|
1740
|
+
let n = num;
|
|
1741
|
+
for (let i = 0; i < 26; i++) {
|
|
1742
|
+
chars.unshift(CB32[Number(n & 0x1fn)]);
|
|
1743
|
+
n >>= 5n;
|
|
1744
|
+
}
|
|
1745
|
+
return chars.join("");
|
|
1746
|
+
}
|
|
1747
|
+
function cb32Decode(str) {
|
|
1748
|
+
if (str.length !== 26) return null;
|
|
1749
|
+
let n = 0n;
|
|
1750
|
+
for (const c of str.toLowerCase()) {
|
|
1751
|
+
const idx = CB32_MAP[c];
|
|
1752
|
+
if (idx === void 0) return null;
|
|
1753
|
+
n = n << 5n | BigInt(idx);
|
|
1754
|
+
}
|
|
1755
|
+
return n.toString(16).padStart(32, "0");
|
|
1756
|
+
}
|
|
1757
|
+
function b58Decode(str) {
|
|
1758
|
+
let n = 0n;
|
|
1759
|
+
for (const c of str) {
|
|
1760
|
+
const i = B58_MAP[c] ?? -1;
|
|
1761
|
+
if (i === -1) return null;
|
|
1762
|
+
n = n * 58n + BigInt(i);
|
|
1763
|
+
}
|
|
1764
|
+
const hex = n.toString(16).padStart(32, "0");
|
|
1765
|
+
return hex.length === 32 ? hex : null;
|
|
1766
|
+
}
|
|
1767
|
+
function hexToUuid(hex) {
|
|
1768
|
+
return [
|
|
1769
|
+
hex.slice(0, 8),
|
|
1770
|
+
hex.slice(8, 12),
|
|
1771
|
+
hex.slice(12, 16),
|
|
1772
|
+
hex.slice(16, 20),
|
|
1773
|
+
hex.slice(20)
|
|
1774
|
+
].join("-");
|
|
1775
|
+
}
|
|
1776
|
+
function encodeUserId(uuid) {
|
|
1777
|
+
const hex = uuid.replace(/-/g, "");
|
|
1778
|
+
if (hex.length !== 32)
|
|
1779
|
+
throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
|
|
1780
|
+
return `user_${cb32Encode(hex)}`;
|
|
1781
|
+
}
|
|
1782
|
+
function decodeUserId(prefixedId) {
|
|
1783
|
+
if (!prefixedId.startsWith("user_")) return null;
|
|
1784
|
+
const enc = prefixedId.slice(5);
|
|
1785
|
+
if (!enc) return null;
|
|
1786
|
+
if (enc.length === 26) {
|
|
1787
|
+
const hex2 = cb32Decode(enc);
|
|
1788
|
+
if (hex2) return hexToUuid(hex2);
|
|
1789
|
+
}
|
|
1790
|
+
const hex = b58Decode(enc);
|
|
1791
|
+
if (hex) return hexToUuid(hex);
|
|
1792
|
+
return null;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1730
1795
|
// src/server/index.ts
|
|
1731
1796
|
function isJwksResponse(data) {
|
|
1732
1797
|
return typeof data === "object" && data !== null && "keys" in data && Array.isArray(data.keys);
|
|
@@ -1735,7 +1800,7 @@ function isAccessTokenPayload(payload) {
|
|
|
1735
1800
|
return typeof payload.sub === "string" && typeof payload.email === "string" && typeof payload.app_id === "string" && typeof payload.iat === "number" && typeof payload.exp === "number";
|
|
1736
1801
|
}
|
|
1737
1802
|
var jwksCache = null;
|
|
1738
|
-
async function getJwks(platformUrl =
|
|
1803
|
+
async function getJwks(platformUrl = `https://${DEFAULT_SDK_API_HOST}`) {
|
|
1739
1804
|
const now = Date.now();
|
|
1740
1805
|
if (jwksCache && jwksCache.expiresAt > now) {
|
|
1741
1806
|
return jwksCache.keys;
|
|
@@ -1756,7 +1821,7 @@ async function getJwks(platformUrl = DEFAULT_PLATFORM_URL) {
|
|
|
1756
1821
|
return data.keys;
|
|
1757
1822
|
}
|
|
1758
1823
|
async function verifyAccessToken(token, options) {
|
|
1759
|
-
const platformUrl = options.platformUrl ||
|
|
1824
|
+
const platformUrl = options.platformUrl || `https://${DEFAULT_SDK_API_HOST}`;
|
|
1760
1825
|
const keys = await getJwks(platformUrl);
|
|
1761
1826
|
if (!keys.length) {
|
|
1762
1827
|
throw new Error("No keys in JWKS");
|
|
@@ -1773,6 +1838,7 @@ async function verifyAccessToken(token, options) {
|
|
|
1773
1838
|
}
|
|
1774
1839
|
return {
|
|
1775
1840
|
sub: payload.sub,
|
|
1841
|
+
pid: payload.pid,
|
|
1776
1842
|
email: payload.email,
|
|
1777
1843
|
name: payload.name,
|
|
1778
1844
|
picture: payload.picture,
|
|
@@ -1798,7 +1864,7 @@ function configureServer(config) {
|
|
|
1798
1864
|
const secretKey = validateAndSanitizeSecretKey(config.secretKey);
|
|
1799
1865
|
serverConfig = {
|
|
1800
1866
|
secretKey,
|
|
1801
|
-
platformUrl:
|
|
1867
|
+
platformUrl: `https://${DEFAULT_SDK_API_HOST}`.trim()
|
|
1802
1868
|
};
|
|
1803
1869
|
}
|
|
1804
1870
|
function getConfig() {
|
|
@@ -1811,7 +1877,7 @@ function getConfig() {
|
|
|
1811
1877
|
}
|
|
1812
1878
|
try {
|
|
1813
1879
|
const secretKey = validateAndSanitizeSecretKey(rawSecretKey);
|
|
1814
|
-
const platformUrl =
|
|
1880
|
+
const platformUrl = `https://${DEFAULT_SDK_API_HOST}`.trim();
|
|
1815
1881
|
serverConfig = { secretKey, platformUrl };
|
|
1816
1882
|
return serverConfig;
|
|
1817
1883
|
} catch (error) {
|
|
@@ -1837,10 +1903,11 @@ var auth = (0, import_react.cache)(async () => {
|
|
|
1837
1903
|
if (sessionToken && expiresAt && expiresAt > Date.now() + TOKEN_EXPIRY_BUFFER_MS) {
|
|
1838
1904
|
try {
|
|
1839
1905
|
const payload = await verifyAccessToken(sessionToken, config);
|
|
1906
|
+
const resolvedUserId = payload.pid ?? payload.sub;
|
|
1840
1907
|
return {
|
|
1841
|
-
userId:
|
|
1908
|
+
userId: resolvedUserId,
|
|
1842
1909
|
user: user || {
|
|
1843
|
-
id:
|
|
1910
|
+
id: resolvedUserId,
|
|
1844
1911
|
email: payload.email,
|
|
1845
1912
|
name: payload.name || null,
|
|
1846
1913
|
image: payload.picture || null,
|
|
@@ -1876,7 +1943,7 @@ async function handleCallback2(code) {
|
|
|
1876
1943
|
if (!config) {
|
|
1877
1944
|
throw new Error("Sylphx SDK not configured. Set SYLPHX_SECRET_KEY environment variable.");
|
|
1878
1945
|
}
|
|
1879
|
-
const response = await fetch(`${config.platformUrl}/
|
|
1946
|
+
const response = await fetch(`${config.platformUrl}/v1/auth/token`, {
|
|
1880
1947
|
method: "POST",
|
|
1881
1948
|
headers: { "Content-Type": "application/json" },
|
|
1882
1949
|
body: JSON.stringify({
|
|
@@ -1906,7 +1973,7 @@ async function signOut() {
|
|
|
1906
1973
|
const { refreshToken } = await getAuthCookies(namespace);
|
|
1907
1974
|
if (refreshToken) {
|
|
1908
1975
|
try {
|
|
1909
|
-
await fetch(`${config.platformUrl}/
|
|
1976
|
+
await fetch(`${config.platformUrl}/v1/auth/revoke`, {
|
|
1910
1977
|
method: "POST",
|
|
1911
1978
|
headers: { "Content-Type": "application/json" },
|
|
1912
1979
|
body: JSON.stringify({
|
|
@@ -1967,6 +2034,8 @@ async function getSessionToken() {
|
|
|
1967
2034
|
createSylphxMiddleware,
|
|
1968
2035
|
currentUser,
|
|
1969
2036
|
currentUserId,
|
|
2037
|
+
decodeUserId,
|
|
2038
|
+
encodeUserId,
|
|
1970
2039
|
getAuthCookies,
|
|
1971
2040
|
getAuthorizationUrl,
|
|
1972
2041
|
getCookieNames,
|