@sylphx/sdk 0.3.3 → 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/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.cts +14 -11
- package/dist/nextjs/index.d.ts +14 -11
- package/dist/nextjs/index.js +43 -15
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +43 -15
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +2 -2
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +14 -11
- package/dist/server/index.d.ts +14 -11
- package/dist/server/index.js +43 -15
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +43 -15
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1906,31 +1906,41 @@ function createDynamicRestClient(config) {
|
|
|
1906
1906
|
}
|
|
1907
1907
|
|
|
1908
1908
|
// src/lib/ids.ts
|
|
1909
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1910
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1909
1911
|
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1910
1912
|
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1911
|
-
function
|
|
1912
|
-
const
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
let
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
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);
|
|
1920
1930
|
}
|
|
1921
|
-
return
|
|
1931
|
+
return n.toString(16).padStart(32, "0");
|
|
1922
1932
|
}
|
|
1923
|
-
function
|
|
1924
|
-
if (!prefixedId.startsWith("user_")) return null;
|
|
1925
|
-
const enc = prefixedId.slice(5);
|
|
1926
|
-
if (!enc) return null;
|
|
1933
|
+
function b58Decode(str) {
|
|
1927
1934
|
let n = 0n;
|
|
1928
|
-
for (const c of
|
|
1935
|
+
for (const c of str) {
|
|
1929
1936
|
const i = B58_MAP[c] ?? -1;
|
|
1930
1937
|
if (i === -1) return null;
|
|
1931
1938
|
n = n * 58n + BigInt(i);
|
|
1932
1939
|
}
|
|
1933
1940
|
const hex = n.toString(16).padStart(32, "0");
|
|
1941
|
+
return hex.length === 32 ? hex : null;
|
|
1942
|
+
}
|
|
1943
|
+
function hexToUuid(hex) {
|
|
1934
1944
|
return [
|
|
1935
1945
|
hex.slice(0, 8),
|
|
1936
1946
|
hex.slice(8, 12),
|
|
@@ -1939,6 +1949,24 @@ function decodeUserId(prefixedId) {
|
|
|
1939
1949
|
hex.slice(20)
|
|
1940
1950
|
].join("-");
|
|
1941
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
|
+
}
|
|
1942
1970
|
|
|
1943
1971
|
// src/server/ai.ts
|
|
1944
1972
|
function createAI(options = {}) {
|