@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/nextjs/index.d.cts
CHANGED
|
@@ -4724,7 +4724,7 @@ interface components {
|
|
|
4724
4724
|
OrgInvitation: {
|
|
4725
4725
|
/**
|
|
4726
4726
|
* @description Invitation ID
|
|
4727
|
-
* @example
|
|
4727
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
4728
4728
|
*/
|
|
4729
4729
|
id: string
|
|
4730
4730
|
/**
|
|
@@ -4794,7 +4794,7 @@ interface components {
|
|
|
4794
4794
|
/**
|
|
4795
4795
|
* Format: uuid
|
|
4796
4796
|
* @description Invitation token (ID)
|
|
4797
|
-
* @example
|
|
4797
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
4798
4798
|
*/
|
|
4799
4799
|
token: string
|
|
4800
4800
|
}
|
|
@@ -6053,33 +6053,36 @@ declare const SESSION_TOKEN_LIFETIME_MS: number;
|
|
|
6053
6053
|
* Platform ID utilities for the Sylphx SDK
|
|
6054
6054
|
*
|
|
6055
6055
|
* Converts between raw UUIDs (used internally / in JWT sub claims) and
|
|
6056
|
-
* prefixed
|
|
6056
|
+
* prefixed TypeID strings (used in all API responses and JWT pid claims).
|
|
6057
6057
|
*
|
|
6058
|
-
*
|
|
6059
|
-
*
|
|
6058
|
+
* Uses TypeID spec v0.3.0 (Crockford base32, case-insensitive).
|
|
6059
|
+
* Also accepts legacy base58 format for backward compatibility.
|
|
6060
|
+
*
|
|
6061
|
+
* No external dependencies — pure TypeScript implementation of Crockford base32.
|
|
6060
6062
|
*
|
|
6061
6063
|
* @example
|
|
6062
6064
|
* ```ts
|
|
6063
6065
|
* import { encodeUserId, decodeUserId } from '@sylphx/sdk/nextjs'
|
|
6064
6066
|
*
|
|
6065
6067
|
* const prefixed = encodeUserId('018f4a3b-1c2d-7000-9abc-def012345678')
|
|
6066
|
-
* // => '
|
|
6068
|
+
* // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
|
|
6067
6069
|
*
|
|
6068
|
-
* const uuid = decodeUserId('
|
|
6070
|
+
* const uuid = decodeUserId('user_01h2xcejqtf2nbrexx3vqjhp41')
|
|
6069
6071
|
* // => '018f4a3b-1c2d-7000-9abc-def012345678'
|
|
6070
6072
|
* ```
|
|
6071
6073
|
*/
|
|
6072
6074
|
/**
|
|
6073
|
-
* Encode a raw UUID as a prefixed
|
|
6075
|
+
* Encode a raw UUID as a prefixed TypeID user ID.
|
|
6074
6076
|
*
|
|
6075
6077
|
* @param uuid - Raw UUID string (with or without dashes)
|
|
6076
|
-
* @returns Prefixed
|
|
6078
|
+
* @returns Prefixed TypeID: `user_<crockford_base32>`
|
|
6077
6079
|
*/
|
|
6078
6080
|
declare function encodeUserId(uuid: string): string;
|
|
6079
6081
|
/**
|
|
6080
|
-
* Decode a prefixed
|
|
6082
|
+
* Decode a prefixed user ID back to a raw UUID.
|
|
6083
|
+
* Accepts both TypeID (current) and base58 (legacy) formats.
|
|
6081
6084
|
*
|
|
6082
|
-
* @param prefixedId - Prefixed
|
|
6085
|
+
* @param prefixedId - Prefixed user ID: `user_<encoded>`
|
|
6083
6086
|
* @returns Raw UUID string, or null if invalid
|
|
6084
6087
|
*/
|
|
6085
6088
|
declare function decodeUserId(prefixedId: string): string | null;
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -4724,7 +4724,7 @@ interface components {
|
|
|
4724
4724
|
OrgInvitation: {
|
|
4725
4725
|
/**
|
|
4726
4726
|
* @description Invitation ID
|
|
4727
|
-
* @example
|
|
4727
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
4728
4728
|
*/
|
|
4729
4729
|
id: string
|
|
4730
4730
|
/**
|
|
@@ -4794,7 +4794,7 @@ interface components {
|
|
|
4794
4794
|
/**
|
|
4795
4795
|
* Format: uuid
|
|
4796
4796
|
* @description Invitation token (ID)
|
|
4797
|
-
* @example
|
|
4797
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
4798
4798
|
*/
|
|
4799
4799
|
token: string
|
|
4800
4800
|
}
|
|
@@ -6053,33 +6053,36 @@ declare const SESSION_TOKEN_LIFETIME_MS: number;
|
|
|
6053
6053
|
* Platform ID utilities for the Sylphx SDK
|
|
6054
6054
|
*
|
|
6055
6055
|
* Converts between raw UUIDs (used internally / in JWT sub claims) and
|
|
6056
|
-
* prefixed
|
|
6056
|
+
* prefixed TypeID strings (used in all API responses and JWT pid claims).
|
|
6057
6057
|
*
|
|
6058
|
-
*
|
|
6059
|
-
*
|
|
6058
|
+
* Uses TypeID spec v0.3.0 (Crockford base32, case-insensitive).
|
|
6059
|
+
* Also accepts legacy base58 format for backward compatibility.
|
|
6060
|
+
*
|
|
6061
|
+
* No external dependencies — pure TypeScript implementation of Crockford base32.
|
|
6060
6062
|
*
|
|
6061
6063
|
* @example
|
|
6062
6064
|
* ```ts
|
|
6063
6065
|
* import { encodeUserId, decodeUserId } from '@sylphx/sdk/nextjs'
|
|
6064
6066
|
*
|
|
6065
6067
|
* const prefixed = encodeUserId('018f4a3b-1c2d-7000-9abc-def012345678')
|
|
6066
|
-
* // => '
|
|
6068
|
+
* // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
|
|
6067
6069
|
*
|
|
6068
|
-
* const uuid = decodeUserId('
|
|
6070
|
+
* const uuid = decodeUserId('user_01h2xcejqtf2nbrexx3vqjhp41')
|
|
6069
6071
|
* // => '018f4a3b-1c2d-7000-9abc-def012345678'
|
|
6070
6072
|
* ```
|
|
6071
6073
|
*/
|
|
6072
6074
|
/**
|
|
6073
|
-
* Encode a raw UUID as a prefixed
|
|
6075
|
+
* Encode a raw UUID as a prefixed TypeID user ID.
|
|
6074
6076
|
*
|
|
6075
6077
|
* @param uuid - Raw UUID string (with or without dashes)
|
|
6076
|
-
* @returns Prefixed
|
|
6078
|
+
* @returns Prefixed TypeID: `user_<crockford_base32>`
|
|
6077
6079
|
*/
|
|
6078
6080
|
declare function encodeUserId(uuid: string): string;
|
|
6079
6081
|
/**
|
|
6080
|
-
* Decode a prefixed
|
|
6082
|
+
* Decode a prefixed user ID back to a raw UUID.
|
|
6083
|
+
* Accepts both TypeID (current) and base58 (legacy) formats.
|
|
6081
6084
|
*
|
|
6082
|
-
* @param prefixedId - Prefixed
|
|
6085
|
+
* @param prefixedId - Prefixed user ID: `user_<encoded>`
|
|
6083
6086
|
* @returns Raw UUID string, or null if invalid
|
|
6084
6087
|
*/
|
|
6085
6088
|
declare function decodeUserId(prefixedId: string): string | null;
|
package/dist/nextjs/index.js
CHANGED
|
@@ -1730,31 +1730,41 @@ async function jwtVerify(jwt, key, options) {
|
|
|
1730
1730
|
}
|
|
1731
1731
|
|
|
1732
1732
|
// src/lib/ids.ts
|
|
1733
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1734
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1733
1735
|
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1734
1736
|
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1735
|
-
function
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
let
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
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);
|
|
1744
1754
|
}
|
|
1745
|
-
return
|
|
1755
|
+
return n.toString(16).padStart(32, "0");
|
|
1746
1756
|
}
|
|
1747
|
-
function
|
|
1748
|
-
if (!prefixedId.startsWith("user_")) return null;
|
|
1749
|
-
const enc = prefixedId.slice(5);
|
|
1750
|
-
if (!enc) return null;
|
|
1757
|
+
function b58Decode(str) {
|
|
1751
1758
|
let n = 0n;
|
|
1752
|
-
for (const c of
|
|
1759
|
+
for (const c of str) {
|
|
1753
1760
|
const i = B58_MAP[c] ?? -1;
|
|
1754
1761
|
if (i === -1) return null;
|
|
1755
1762
|
n = n * 58n + BigInt(i);
|
|
1756
1763
|
}
|
|
1757
1764
|
const hex = n.toString(16).padStart(32, "0");
|
|
1765
|
+
return hex.length === 32 ? hex : null;
|
|
1766
|
+
}
|
|
1767
|
+
function hexToUuid(hex) {
|
|
1758
1768
|
return [
|
|
1759
1769
|
hex.slice(0, 8),
|
|
1760
1770
|
hex.slice(8, 12),
|
|
@@ -1763,6 +1773,24 @@ function decodeUserId(prefixedId) {
|
|
|
1763
1773
|
hex.slice(20)
|
|
1764
1774
|
].join("-");
|
|
1765
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
|
+
}
|
|
1766
1794
|
|
|
1767
1795
|
// src/server/index.ts
|
|
1768
1796
|
function isJwksResponse(data) {
|