@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.d.cts
CHANGED
|
@@ -18405,7 +18405,7 @@ interface components {
|
|
|
18405
18405
|
OrgInvitation: {
|
|
18406
18406
|
/**
|
|
18407
18407
|
* @description Invitation ID
|
|
18408
|
-
* @example
|
|
18408
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
18409
18409
|
*/
|
|
18410
18410
|
id: string
|
|
18411
18411
|
/**
|
|
@@ -18475,7 +18475,7 @@ interface components {
|
|
|
18475
18475
|
/**
|
|
18476
18476
|
* Format: uuid
|
|
18477
18477
|
* @description Invitation token (ID)
|
|
18478
|
-
* @example
|
|
18478
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
18479
18479
|
*/
|
|
18480
18480
|
token: string
|
|
18481
18481
|
}
|
|
@@ -19931,33 +19931,36 @@ declare function isDevelopmentRuntime(): boolean;
|
|
|
19931
19931
|
* Platform ID utilities for the Sylphx SDK
|
|
19932
19932
|
*
|
|
19933
19933
|
* Converts between raw UUIDs (used internally / in JWT sub claims) and
|
|
19934
|
-
* prefixed
|
|
19934
|
+
* prefixed TypeID strings (used in all API responses and JWT pid claims).
|
|
19935
19935
|
*
|
|
19936
|
-
*
|
|
19937
|
-
*
|
|
19936
|
+
* Uses TypeID spec v0.3.0 (Crockford base32, case-insensitive).
|
|
19937
|
+
* Also accepts legacy base58 format for backward compatibility.
|
|
19938
|
+
*
|
|
19939
|
+
* No external dependencies — pure TypeScript implementation of Crockford base32.
|
|
19938
19940
|
*
|
|
19939
19941
|
* @example
|
|
19940
19942
|
* ```ts
|
|
19941
19943
|
* import { encodeUserId, decodeUserId } from '@sylphx/sdk/nextjs'
|
|
19942
19944
|
*
|
|
19943
19945
|
* const prefixed = encodeUserId('018f4a3b-1c2d-7000-9abc-def012345678')
|
|
19944
|
-
* // => '
|
|
19946
|
+
* // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
|
|
19945
19947
|
*
|
|
19946
|
-
* const uuid = decodeUserId('
|
|
19948
|
+
* const uuid = decodeUserId('user_01h2xcejqtf2nbrexx3vqjhp41')
|
|
19947
19949
|
* // => '018f4a3b-1c2d-7000-9abc-def012345678'
|
|
19948
19950
|
* ```
|
|
19949
19951
|
*/
|
|
19950
19952
|
/**
|
|
19951
|
-
* Encode a raw UUID as a prefixed
|
|
19953
|
+
* Encode a raw UUID as a prefixed TypeID user ID.
|
|
19952
19954
|
*
|
|
19953
19955
|
* @param uuid - Raw UUID string (with or without dashes)
|
|
19954
|
-
* @returns Prefixed
|
|
19956
|
+
* @returns Prefixed TypeID: `user_<crockford_base32>`
|
|
19955
19957
|
*/
|
|
19956
19958
|
declare function encodeUserId(uuid: string): string;
|
|
19957
19959
|
/**
|
|
19958
|
-
* Decode a prefixed
|
|
19960
|
+
* Decode a prefixed user ID back to a raw UUID.
|
|
19961
|
+
* Accepts both TypeID (current) and base58 (legacy) formats.
|
|
19959
19962
|
*
|
|
19960
|
-
* @param prefixedId - Prefixed
|
|
19963
|
+
* @param prefixedId - Prefixed user ID: `user_<encoded>`
|
|
19961
19964
|
* @returns Raw UUID string, or null if invalid
|
|
19962
19965
|
*/
|
|
19963
19966
|
declare function decodeUserId(prefixedId: string): string | null;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -18405,7 +18405,7 @@ interface components {
|
|
|
18405
18405
|
OrgInvitation: {
|
|
18406
18406
|
/**
|
|
18407
18407
|
* @description Invitation ID
|
|
18408
|
-
* @example
|
|
18408
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
18409
18409
|
*/
|
|
18410
18410
|
id: string
|
|
18411
18411
|
/**
|
|
@@ -18475,7 +18475,7 @@ interface components {
|
|
|
18475
18475
|
/**
|
|
18476
18476
|
* Format: uuid
|
|
18477
18477
|
* @description Invitation token (ID)
|
|
18478
|
-
* @example
|
|
18478
|
+
* @example inv_3Zb83qVQxkHMJPZ8VrJfQ2
|
|
18479
18479
|
*/
|
|
18480
18480
|
token: string
|
|
18481
18481
|
}
|
|
@@ -19931,33 +19931,36 @@ declare function isDevelopmentRuntime(): boolean;
|
|
|
19931
19931
|
* Platform ID utilities for the Sylphx SDK
|
|
19932
19932
|
*
|
|
19933
19933
|
* Converts between raw UUIDs (used internally / in JWT sub claims) and
|
|
19934
|
-
* prefixed
|
|
19934
|
+
* prefixed TypeID strings (used in all API responses and JWT pid claims).
|
|
19935
19935
|
*
|
|
19936
|
-
*
|
|
19937
|
-
*
|
|
19936
|
+
* Uses TypeID spec v0.3.0 (Crockford base32, case-insensitive).
|
|
19937
|
+
* Also accepts legacy base58 format for backward compatibility.
|
|
19938
|
+
*
|
|
19939
|
+
* No external dependencies — pure TypeScript implementation of Crockford base32.
|
|
19938
19940
|
*
|
|
19939
19941
|
* @example
|
|
19940
19942
|
* ```ts
|
|
19941
19943
|
* import { encodeUserId, decodeUserId } from '@sylphx/sdk/nextjs'
|
|
19942
19944
|
*
|
|
19943
19945
|
* const prefixed = encodeUserId('018f4a3b-1c2d-7000-9abc-def012345678')
|
|
19944
|
-
* // => '
|
|
19946
|
+
* // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
|
|
19945
19947
|
*
|
|
19946
|
-
* const uuid = decodeUserId('
|
|
19948
|
+
* const uuid = decodeUserId('user_01h2xcejqtf2nbrexx3vqjhp41')
|
|
19947
19949
|
* // => '018f4a3b-1c2d-7000-9abc-def012345678'
|
|
19948
19950
|
* ```
|
|
19949
19951
|
*/
|
|
19950
19952
|
/**
|
|
19951
|
-
* Encode a raw UUID as a prefixed
|
|
19953
|
+
* Encode a raw UUID as a prefixed TypeID user ID.
|
|
19952
19954
|
*
|
|
19953
19955
|
* @param uuid - Raw UUID string (with or without dashes)
|
|
19954
|
-
* @returns Prefixed
|
|
19956
|
+
* @returns Prefixed TypeID: `user_<crockford_base32>`
|
|
19955
19957
|
*/
|
|
19956
19958
|
declare function encodeUserId(uuid: string): string;
|
|
19957
19959
|
/**
|
|
19958
|
-
* Decode a prefixed
|
|
19960
|
+
* Decode a prefixed user ID back to a raw UUID.
|
|
19961
|
+
* Accepts both TypeID (current) and base58 (legacy) formats.
|
|
19959
19962
|
*
|
|
19960
|
-
* @param prefixedId - Prefixed
|
|
19963
|
+
* @param prefixedId - Prefixed user ID: `user_<encoded>`
|
|
19961
19964
|
* @returns Raw UUID string, or null if invalid
|
|
19962
19965
|
*/
|
|
19963
19966
|
declare function decodeUserId(prefixedId: string): string | null;
|
package/dist/server/index.js
CHANGED
|
@@ -1981,31 +1981,41 @@ function createDynamicRestClient(config) {
|
|
|
1981
1981
|
}
|
|
1982
1982
|
|
|
1983
1983
|
// src/lib/ids.ts
|
|
1984
|
+
var CB32 = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
1985
|
+
var CB32_MAP = Object.fromEntries([...CB32].map((c, i) => [c, i]));
|
|
1984
1986
|
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1985
1987
|
var B58_MAP = Object.fromEntries([...B58].map((c, i) => [c, i]));
|
|
1986
|
-
function
|
|
1987
|
-
const
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
let
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1988
|
+
function cb32Encode(hex) {
|
|
1989
|
+
const num = BigInt(`0x${hex}`);
|
|
1990
|
+
const chars = [];
|
|
1991
|
+
let n = num;
|
|
1992
|
+
for (let i = 0; i < 26; i++) {
|
|
1993
|
+
chars.unshift(CB32[Number(n & 0x1fn)]);
|
|
1994
|
+
n >>= 5n;
|
|
1995
|
+
}
|
|
1996
|
+
return chars.join("");
|
|
1997
|
+
}
|
|
1998
|
+
function cb32Decode(str) {
|
|
1999
|
+
if (str.length !== 26) return null;
|
|
2000
|
+
let n = 0n;
|
|
2001
|
+
for (const c of str.toLowerCase()) {
|
|
2002
|
+
const idx = CB32_MAP[c];
|
|
2003
|
+
if (idx === void 0) return null;
|
|
2004
|
+
n = n << 5n | BigInt(idx);
|
|
1995
2005
|
}
|
|
1996
|
-
return
|
|
2006
|
+
return n.toString(16).padStart(32, "0");
|
|
1997
2007
|
}
|
|
1998
|
-
function
|
|
1999
|
-
if (!prefixedId.startsWith("user_")) return null;
|
|
2000
|
-
const enc = prefixedId.slice(5);
|
|
2001
|
-
if (!enc) return null;
|
|
2008
|
+
function b58Decode(str) {
|
|
2002
2009
|
let n = 0n;
|
|
2003
|
-
for (const c of
|
|
2010
|
+
for (const c of str) {
|
|
2004
2011
|
const i = B58_MAP[c] ?? -1;
|
|
2005
2012
|
if (i === -1) return null;
|
|
2006
2013
|
n = n * 58n + BigInt(i);
|
|
2007
2014
|
}
|
|
2008
2015
|
const hex = n.toString(16).padStart(32, "0");
|
|
2016
|
+
return hex.length === 32 ? hex : null;
|
|
2017
|
+
}
|
|
2018
|
+
function hexToUuid(hex) {
|
|
2009
2019
|
return [
|
|
2010
2020
|
hex.slice(0, 8),
|
|
2011
2021
|
hex.slice(8, 12),
|
|
@@ -2014,6 +2024,24 @@ function decodeUserId(prefixedId) {
|
|
|
2014
2024
|
hex.slice(20)
|
|
2015
2025
|
].join("-");
|
|
2016
2026
|
}
|
|
2027
|
+
function encodeUserId(uuid) {
|
|
2028
|
+
const hex = uuid.replace(/-/g, "");
|
|
2029
|
+
if (hex.length !== 32)
|
|
2030
|
+
throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
|
|
2031
|
+
return `user_${cb32Encode(hex)}`;
|
|
2032
|
+
}
|
|
2033
|
+
function decodeUserId(prefixedId) {
|
|
2034
|
+
if (!prefixedId.startsWith("user_")) return null;
|
|
2035
|
+
const enc = prefixedId.slice(5);
|
|
2036
|
+
if (!enc) return null;
|
|
2037
|
+
if (enc.length === 26) {
|
|
2038
|
+
const hex2 = cb32Decode(enc);
|
|
2039
|
+
if (hex2) return hexToUuid(hex2);
|
|
2040
|
+
}
|
|
2041
|
+
const hex = b58Decode(enc);
|
|
2042
|
+
if (hex) return hexToUuid(hex);
|
|
2043
|
+
return null;
|
|
2044
|
+
}
|
|
2017
2045
|
|
|
2018
2046
|
// src/server/ai.ts
|
|
2019
2047
|
function createAI(options = {}) {
|