@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.
@@ -18405,7 +18405,7 @@ interface components {
18405
18405
  OrgInvitation: {
18406
18406
  /**
18407
18407
  * @description Invitation ID
18408
- * @example ivt_3Zb83qVQxkHMJPZ8VrJfQ2
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 ivt_3Zb83qVQxkHMJPZ8VrJfQ2
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 base58 IDs (used in all API responses and JWT pid claims).
19934
+ * prefixed TypeID strings (used in all API responses and JWT pid claims).
19935
19935
  *
19936
- * Same alphabet and encoding logic as the platform server.
19937
- * No external dependencies pure TypeScript.
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
- * // => 'user_3Zb83qVQxkHMJPZ8VrJfQ2'
19946
+ * // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
19945
19947
  *
19946
- * const uuid = decodeUserId('user_3Zb83qVQxkHMJPZ8VrJfQ2')
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 base58 user ID.
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 platform ID: `user_<base58>`
19956
+ * @returns Prefixed TypeID: `user_<crockford_base32>`
19955
19957
  */
19956
19958
  declare function encodeUserId(uuid: string): string;
19957
19959
  /**
19958
- * Decode a prefixed base58 user ID back to a raw UUID.
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 platform ID: `user_<base58>`
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;
@@ -18405,7 +18405,7 @@ interface components {
18405
18405
  OrgInvitation: {
18406
18406
  /**
18407
18407
  * @description Invitation ID
18408
- * @example ivt_3Zb83qVQxkHMJPZ8VrJfQ2
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 ivt_3Zb83qVQxkHMJPZ8VrJfQ2
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 base58 IDs (used in all API responses and JWT pid claims).
19934
+ * prefixed TypeID strings (used in all API responses and JWT pid claims).
19935
19935
  *
19936
- * Same alphabet and encoding logic as the platform server.
19937
- * No external dependencies pure TypeScript.
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
- * // => 'user_3Zb83qVQxkHMJPZ8VrJfQ2'
19946
+ * // => 'user_01h2xcejqtf2nbrexx3vqjhp41'
19945
19947
  *
19946
- * const uuid = decodeUserId('user_3Zb83qVQxkHMJPZ8VrJfQ2')
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 base58 user ID.
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 platform ID: `user_<base58>`
19956
+ * @returns Prefixed TypeID: `user_<crockford_base32>`
19955
19957
  */
19956
19958
  declare function encodeUserId(uuid: string): string;
19957
19959
  /**
19958
- * Decode a prefixed base58 user ID back to a raw UUID.
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 platform ID: `user_<base58>`
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;
@@ -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 encodeUserId(uuid) {
1987
- const hex = uuid.replace(/-/g, "");
1988
- if (hex.length !== 32)
1989
- throw new Error("Invalid UUID: expected 32 hex chars after stripping dashes");
1990
- let n = BigInt("0x" + hex);
1991
- let r = "";
1992
- while (n > 0n) {
1993
- r = B58[Number(n % 58n)] + r;
1994
- n /= 58n;
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 `user_${r}`;
2006
+ return n.toString(16).padStart(32, "0");
1997
2007
  }
1998
- function decodeUserId(prefixedId) {
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 enc) {
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 = {}) {