@sublay/js 5.0.0 → 7.0.1

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.
Files changed (211) hide show
  1. package/README.md +33 -4
  2. package/dist/core/client.d.ts +58 -2
  3. package/dist/core/multipart.d.ts +22 -0
  4. package/dist/index.d.mts +2508 -42
  5. package/dist/index.d.ts +29 -2
  6. package/dist/index.js +1746 -37
  7. package/dist/index.mjs +1746 -37
  8. package/dist/interfaces/AppNotification.d.ts +258 -0
  9. package/dist/interfaces/ChatMessage.d.ts +32 -0
  10. package/dist/interfaces/Collection.d.ts +10 -0
  11. package/dist/interfaces/Comment.d.ts +42 -0
  12. package/dist/interfaces/Connection.d.ts +67 -0
  13. package/dist/interfaces/Conversation.d.ts +25 -0
  14. package/dist/interfaces/ConversationMember.d.ts +16 -0
  15. package/dist/interfaces/Entity.d.ts +53 -0
  16. package/dist/interfaces/File.d.ts +39 -0
  17. package/dist/interfaces/Follow.d.ts +19 -0
  18. package/dist/interfaces/HostedApp.d.ts +11 -0
  19. package/dist/interfaces/ImageProcessing.d.ts +62 -0
  20. package/dist/interfaces/Mention.d.ts +12 -0
  21. package/dist/interfaces/OAuthIdentity.d.ts +13 -0
  22. package/dist/interfaces/Project.d.ts +14 -0
  23. package/dist/interfaces/Reaction.d.ts +23 -0
  24. package/dist/interfaces/Report.d.ts +32 -0
  25. package/dist/interfaces/Rule.d.ts +22 -0
  26. package/dist/interfaces/Space.d.ts +141 -0
  27. package/dist/interfaces/SpaceMember.d.ts +29 -0
  28. package/dist/interfaces/User.d.ts +39 -0
  29. package/dist/modules/app-notifications/countUnreadNotifications.d.ts +2 -0
  30. package/dist/modules/app-notifications/fetchNotifications.d.ts +8 -0
  31. package/dist/modules/app-notifications/index.d.ts +4 -0
  32. package/dist/modules/app-notifications/markAllNotificationsAsRead.d.ts +5 -0
  33. package/dist/modules/app-notifications/markNotificationAsRead.d.ts +5 -0
  34. package/dist/modules/auth/changePassword.d.ts +11 -0
  35. package/dist/modules/auth/index.d.ts +10 -0
  36. package/dist/modules/auth/requestNewAccessToken.d.ts +16 -0
  37. package/dist/modules/auth/requestPasswordReset.d.ts +5 -0
  38. package/dist/modules/auth/resetPassword.d.ts +6 -0
  39. package/dist/modules/auth/sendVerificationEmail.d.ts +13 -0
  40. package/dist/modules/auth/signIn.d.ts +12 -0
  41. package/dist/modules/auth/signOut.d.ts +9 -0
  42. package/dist/modules/auth/signUp.d.ts +24 -0
  43. package/dist/modules/auth/verifyEmail.d.ts +5 -0
  44. package/dist/modules/auth/verifyExternalUser.d.ts +11 -0
  45. package/dist/modules/chat/addMember.d.ts +8 -0
  46. package/dist/modules/chat/changeMemberRole.d.ts +9 -0
  47. package/dist/modules/chat/createDirectConversation.d.ts +7 -0
  48. package/dist/modules/chat/createGroupConversation.d.ts +10 -0
  49. package/dist/modules/chat/deleteConversation.d.ts +8 -0
  50. package/dist/modules/chat/deleteMessage.d.ts +11 -0
  51. package/dist/modules/chat/editMessage.d.ts +13 -0
  52. package/dist/modules/chat/getConversation.d.ts +6 -0
  53. package/dist/modules/chat/getMessage.d.ts +7 -0
  54. package/dist/modules/chat/getUnreadCount.d.ts +6 -0
  55. package/dist/modules/chat/index.d.ts +21 -0
  56. package/dist/modules/chat/leaveConversation.d.ts +7 -0
  57. package/dist/modules/chat/listConversations.d.ts +17 -0
  58. package/dist/modules/chat/listMembers.d.ts +10 -0
  59. package/dist/modules/chat/listMessages.d.ts +23 -0
  60. package/dist/modules/chat/listReactions.d.ts +23 -0
  61. package/dist/modules/chat/markAsRead.d.ts +9 -0
  62. package/dist/modules/chat/removeMember.d.ts +9 -0
  63. package/dist/modules/chat/reportMessage.d.ts +12 -0
  64. package/dist/modules/chat/sendMessage.d.ts +21 -0
  65. package/dist/modules/chat/toggleReaction.d.ts +16 -0
  66. package/dist/modules/chat/updateConversation.d.ts +12 -0
  67. package/dist/modules/collections/addEntityToCollection.d.ts +13 -0
  68. package/dist/modules/collections/createNewCollection.d.ts +8 -0
  69. package/dist/modules/collections/deleteCollection.d.ts +5 -0
  70. package/dist/modules/collections/fetchCollectionEntities.d.ts +13 -0
  71. package/dist/modules/collections/fetchRootCollection.d.ts +3 -0
  72. package/dist/modules/collections/fetchSubCollections.d.ts +6 -0
  73. package/dist/modules/collections/index.d.ts +8 -0
  74. package/dist/modules/collections/removeEntityFromCollection.d.ts +7 -0
  75. package/dist/modules/collections/updateCollection.d.ts +7 -0
  76. package/dist/modules/comments/addReaction.d.ts +8 -0
  77. package/dist/modules/comments/createComment.d.ts +15 -0
  78. package/dist/modules/comments/deleteComment.d.ts +5 -0
  79. package/dist/modules/comments/fetchComment.d.ts +3 -1
  80. package/dist/modules/comments/fetchCommentByForeignId.d.ts +3 -1
  81. package/dist/modules/comments/fetchManyComments.d.ts +14 -0
  82. package/dist/modules/comments/fetchReactions.d.ts +15 -0
  83. package/dist/modules/comments/getUserReaction.d.ts +9 -0
  84. package/dist/modules/comments/index.d.ts +10 -3
  85. package/dist/modules/comments/removeReaction.d.ts +6 -0
  86. package/dist/modules/comments/updateComment.d.ts +7 -0
  87. package/dist/modules/connections/acceptConnection.d.ts +6 -0
  88. package/dist/modules/connections/declineConnection.d.ts +6 -0
  89. package/dist/modules/connections/fetchConnections.d.ts +8 -0
  90. package/dist/modules/connections/fetchConnectionsCount.d.ts +3 -0
  91. package/dist/modules/connections/fetchReceivedPendingConnections.d.ts +8 -0
  92. package/dist/modules/connections/fetchSentPendingConnections.d.ts +8 -0
  93. package/dist/modules/connections/index.d.ts +7 -0
  94. package/dist/modules/connections/removeConnection.d.ts +5 -0
  95. package/dist/modules/entities/addReaction.d.ts +8 -0
  96. package/dist/modules/entities/createEntity.d.ts +7 -2
  97. package/dist/modules/entities/deleteEntity.d.ts +1 -1
  98. package/dist/modules/entities/fetchDrafts.d.ts +11 -0
  99. package/dist/modules/entities/fetchEntity.d.ts +3 -1
  100. package/dist/modules/entities/fetchEntityByForeignId.d.ts +3 -1
  101. package/dist/modules/entities/fetchEntityByShortId.d.ts +3 -1
  102. package/dist/modules/entities/fetchManyEntities.d.ts +11 -3
  103. package/dist/modules/entities/fetchReactions.d.ts +15 -0
  104. package/dist/modules/entities/fetchTopComment.d.ts +6 -0
  105. package/dist/modules/entities/getUserReaction.d.ts +9 -0
  106. package/dist/modules/entities/index.d.ts +15 -8
  107. package/dist/modules/entities/isEntitySaved.d.ts +12 -0
  108. package/dist/modules/entities/publishDraft.d.ts +6 -0
  109. package/dist/modules/entities/removeReaction.d.ts +6 -0
  110. package/dist/modules/entities/updateEntity.d.ts +6 -7
  111. package/dist/modules/follows/deleteFollow.d.ts +5 -0
  112. package/dist/modules/follows/fetchFollowers.d.ts +8 -0
  113. package/dist/modules/follows/fetchFollowersCount.d.ts +5 -0
  114. package/dist/modules/follows/fetchFollowing.d.ts +8 -0
  115. package/dist/modules/follows/fetchFollowingCount.d.ts +5 -0
  116. package/dist/modules/follows/index.d.ts +5 -0
  117. package/dist/modules/oauth/authorize.d.ts +25 -0
  118. package/dist/modules/oauth/index.d.ts +4 -0
  119. package/dist/modules/oauth/linkIdentity.d.ts +14 -0
  120. package/dist/modules/oauth/listIdentities.d.ts +4 -0
  121. package/dist/modules/oauth/unlinkIdentity.d.ts +12 -0
  122. package/dist/modules/reports/createReport.d.ts +9 -0
  123. package/dist/modules/reports/fetchModeratedReports.d.ts +12 -0
  124. package/dist/modules/reports/index.d.ts +2 -0
  125. package/dist/modules/search/askContent.d.ts +51 -0
  126. package/dist/modules/search/index.d.ts +4 -0
  127. package/dist/modules/search/searchContent.d.ts +17 -0
  128. package/dist/modules/search/searchSpaces.d.ts +11 -0
  129. package/dist/modules/search/searchUsers.d.ts +11 -0
  130. package/dist/modules/spaces/approveMembership.d.ts +7 -0
  131. package/dist/modules/spaces/banMember.d.ts +13 -0
  132. package/dist/modules/spaces/checkMyMembership.d.ts +6 -0
  133. package/dist/modules/spaces/checkSlugAvailability.d.ts +8 -0
  134. package/dist/modules/spaces/createRule.d.ts +8 -0
  135. package/dist/modules/spaces/createSpace.d.ts +13 -0
  136. package/dist/modules/spaces/declineMembership.d.ts +7 -0
  137. package/dist/modules/spaces/deleteRule.d.ts +7 -0
  138. package/dist/modules/spaces/deleteSpace.d.ts +6 -0
  139. package/dist/modules/spaces/fetchChildSpaces.d.ts +11 -0
  140. package/dist/modules/spaces/fetchDigestConfig.d.ts +6 -0
  141. package/dist/modules/spaces/fetchManyRules.d.ts +6 -0
  142. package/dist/modules/spaces/fetchManySpaces.d.ts +16 -0
  143. package/dist/modules/spaces/fetchRule.d.ts +7 -0
  144. package/dist/modules/spaces/fetchSpace.d.ts +6 -0
  145. package/dist/modules/spaces/fetchSpaceBreadcrumb.d.ts +6 -0
  146. package/dist/modules/spaces/fetchSpaceByShortId.d.ts +6 -0
  147. package/dist/modules/spaces/fetchSpaceBySlug.d.ts +6 -0
  148. package/dist/modules/spaces/fetchSpaceMembers.d.ts +10 -0
  149. package/dist/modules/spaces/fetchSpaceTeam.d.ts +6 -0
  150. package/dist/modules/spaces/fetchUserSpaces.d.ts +11 -0
  151. package/dist/modules/spaces/getSpaceConversation.d.ts +6 -0
  152. package/dist/modules/spaces/handleCommentReport.d.ts +14 -0
  153. package/dist/modules/spaces/handleEntityReport.d.ts +17 -0
  154. package/dist/modules/spaces/handleSpaceChatReport.d.ts +18 -0
  155. package/dist/modules/spaces/index.d.ts +36 -0
  156. package/dist/modules/spaces/joinSpace.d.ts +6 -0
  157. package/dist/modules/spaces/leaveSpace.d.ts +6 -0
  158. package/dist/modules/spaces/moderateSpaceChatMessage.d.ts +12 -0
  159. package/dist/modules/spaces/moderateSpaceComment.d.ts +9 -0
  160. package/dist/modules/spaces/moderateSpaceEntity.d.ts +12 -0
  161. package/dist/modules/spaces/reorderRules.d.ts +7 -0
  162. package/dist/modules/spaces/unbanMember.d.ts +13 -0
  163. package/dist/modules/spaces/updateDigestConfig.d.ts +11 -0
  164. package/dist/modules/spaces/updateMemberRole.d.ts +8 -0
  165. package/dist/modules/spaces/updateRule.d.ts +9 -0
  166. package/dist/modules/spaces/updateSpace.d.ts +12 -0
  167. package/dist/modules/storage/deleteFile.d.ts +5 -0
  168. package/dist/modules/storage/getFile.d.ts +34 -0
  169. package/dist/modules/storage/index.d.ts +4 -0
  170. package/dist/modules/storage/uploadFile.d.ts +30 -0
  171. package/dist/modules/storage/uploadImage.d.ts +41 -0
  172. package/dist/modules/users/checkUsernameAvailability.d.ts +8 -0
  173. package/dist/modules/users/createFollow.d.ts +7 -0
  174. package/dist/modules/users/deleteFollow.d.ts +6 -0
  175. package/dist/modules/users/fetchConnectionStatus.d.ts +10 -0
  176. package/dist/modules/users/fetchConnectionsByUserId.d.ts +9 -0
  177. package/dist/modules/users/fetchConnectionsCountByUserId.d.ts +6 -0
  178. package/dist/modules/users/fetchFollowStatus.d.ts +14 -0
  179. package/dist/modules/users/fetchFollowersByUserId.d.ts +9 -0
  180. package/dist/modules/users/fetchFollowersCountByUserId.d.ts +8 -0
  181. package/dist/modules/users/fetchFollowingByUserId.d.ts +9 -0
  182. package/dist/modules/users/fetchFollowingCountByUserId.d.ts +8 -0
  183. package/dist/modules/users/fetchUserByForeignId.d.ts +3 -7
  184. package/dist/modules/users/fetchUserById.d.ts +3 -1
  185. package/dist/modules/users/fetchUserByUsername.d.ts +7 -0
  186. package/dist/modules/users/fetchUserSuggestions.d.ts +6 -0
  187. package/dist/modules/users/index.d.ts +18 -3
  188. package/dist/modules/users/removeConnectionByUserId.d.ts +10 -0
  189. package/dist/modules/users/requestConnection.d.ts +11 -0
  190. package/dist/modules/users/updateUser.d.ts +32 -0
  191. package/package.json +10 -7
  192. package/CLAUDE.md +0 -339
  193. package/pnpm-workspace.yaml +0 -2
  194. package/src/core/client.ts +0 -15
  195. package/src/index.ts +0 -45
  196. package/src/interfaces/IPaginatedResponse.ts +0 -12
  197. package/src/modules/comments/fetchComment.ts +0 -14
  198. package/src/modules/comments/fetchCommentByForeignId.ts +0 -14
  199. package/src/modules/comments/index.ts +0 -4
  200. package/src/modules/entities/createEntity.ts +0 -27
  201. package/src/modules/entities/deleteEntity.ts +0 -14
  202. package/src/modules/entities/fetchEntity.ts +0 -14
  203. package/src/modules/entities/fetchEntityByForeignId.ts +0 -15
  204. package/src/modules/entities/fetchEntityByShortId.ts +0 -14
  205. package/src/modules/entities/fetchManyEntities.ts +0 -79
  206. package/src/modules/entities/index.ts +0 -17
  207. package/src/modules/entities/updateEntity.ts +0 -28
  208. package/src/modules/users/fetchUserByForeignId.ts +0 -40
  209. package/src/modules/users/fetchUserById.ts +0 -15
  210. package/src/modules/users/index.ts +0 -4
  211. package/tsconfig.json +0 -14
package/README.md CHANGED
@@ -5,9 +5,7 @@
5
5
 
6
6
  > **Backend infrastructure for user-powered products.** Pre-modeled bundles for the layers every app ends up rebuilding — comments, notifications, files, search, chat, and more. Install what you need, call through one SDK. Build the part that's actually yours.
7
7
 
8
- Framework-agnostic JavaScript SDK for Sublay. For browser apps and JS runtimes that don't use React, or don't want the React provider tree.
9
-
10
- Exposes a single `SublayClient` with module namespaces for `users`, `entities`, and `comments`.
8
+ Framework-agnostic JavaScript SDK for Sublay. For browser apps and JS runtimes that don't use React, or don't want the React provider tree. It mirrors the Sublay v7 API surface — authenticated as an end user via a bearer token — without any React or state-management dependencies.
11
9
 
12
10
  ```bash
13
11
  npm install @sublay/js
@@ -16,13 +14,44 @@ npm install @sublay/js
16
14
  ```ts
17
15
  import { SublayClient } from "@sublay/js";
18
16
 
17
+ // SDK-managed auth: the SDK holds the tokens and auto-refreshes them on expiry.
19
18
  const sublay = await SublayClient.init({
20
19
  projectId: "your-project-id",
20
+ onAuthChange: (tokens) => {
21
+ // Persist tokens so the session survives a reload (called with null on sign-out).
22
+ },
21
23
  });
22
24
 
23
- const entities = await sublay.entities.list({ ... });
25
+ await sublay.auth.signIn({ email, password });
26
+
27
+ const { entities } = await sublay.entities.fetchManyEntities({
28
+ sortBy: "hot",
29
+ limit: 20,
30
+ });
24
31
  ```
25
32
 
33
+ **Two auth modes.** By default the SDK is *SDK-managed*: it stores the tokens in memory, attaches the bearer on every request, auto-refreshes on a 403, and fires `onAuthChange` so you can persist them. If your host app already owns the token (e.g. it's shared with another SDK), pass `getToken` to `init({ ... })` for *host-managed* mode — the SDK then reads the token from your hook on each request and never stores or refreshes it itself.
34
+
35
+ ### API surface
36
+
37
+ One `SublayClient` with 14 module namespaces (call them as `sublay.<module>.<fn>(...)`):
38
+
39
+ | Namespace | What it covers |
40
+ | --- | --- |
41
+ | `auth` | sign up / in / out, email verification, password reset, token refresh |
42
+ | `users` | profiles, username lookup, suggestions, updates, and the per-user follow/connection graph |
43
+ | `entities` | content CRUD, drafts, feeds (`fetchManyEntities`), reactions, saves |
44
+ | `comments` | threaded comments CRUD, reactions |
45
+ | `spaces` | communities: lifecycle, membership, roles, rules, digests, moderation |
46
+ | `collections` | saved-entity collections |
47
+ | `follows` / `connections` | the logged-in user's own follow graph and mutual connections |
48
+ | `appNotifications` | in-app notifications and unread counts |
49
+ | `reports` | submit reports, fetch the moderation queue |
50
+ | `search` | semantic `searchContent` / `searchUsers` / `searchSpaces`, plus streaming `askContent` |
51
+ | `storage` | file & image uploads, fetch, delete |
52
+ | `oauth` | OAuth sign-in/link (redirect flow) and identity management |
53
+ | `chat` | conversations, members, messages, reactions, read-state, reporting |
54
+
26
55
  See [docs.sublay.io](https://docs.sublay.io) for the full reference.
27
56
 
28
57
  ---
@@ -1,8 +1,64 @@
1
1
  import { AxiosInstance } from "axios";
2
+ export interface AuthTokens {
3
+ accessToken: string;
4
+ refreshToken: string;
5
+ }
2
6
  export interface ClientConfig {
3
7
  projectId: string;
8
+ /**
9
+ * Optional tokens to hydrate the SDK on init (SDK-managed mode) — e.g. tokens
10
+ * the host app persisted from a previous session.
11
+ */
12
+ initialTokens?: AuthTokens;
13
+ /**
14
+ * Optional async hook returning the current access token. **Providing it puts
15
+ * the SDK in "host-managed" mode**: the host owns the token and its refresh,
16
+ * and the SDK never stores or refreshes tokens itself.
17
+ */
18
+ getToken?: () => string | null | undefined | Promise<string | null | undefined>;
19
+ /**
20
+ * Called whenever the SDK sets, rotates, or clears tokens (SDK-managed mode
21
+ * only). Receives `null` on sign-out. Use it to persist tokens so a session
22
+ * survives a reload.
23
+ */
24
+ onAuthChange?: (tokens: AuthTokens | null) => void;
4
25
  }
5
26
  export declare class SublayHttpClient {
6
- instance: AxiosInstance;
7
- constructor({ projectId }: ClientConfig);
27
+ projectInstance: AxiosInstance;
28
+ private readonly baseURL;
29
+ private readonly hostManaged;
30
+ private readonly getToken?;
31
+ private readonly onAuthChange?;
32
+ private accessToken;
33
+ private refreshToken;
34
+ /** Shared so concurrent 403s trigger a single refresh (mutex). */
35
+ private refreshPromise;
36
+ constructor({ projectId, initialTokens, getToken, onAuthChange, }: ClientConfig);
37
+ /**
38
+ * The SDK's own in-memory access token (SDK-managed mode). Distinct from the
39
+ * `init({ getToken })` host hook, which supplies a token in host-managed mode.
40
+ */
41
+ getAccessToken(): string | null;
42
+ getRefreshToken(): string | null;
43
+ /**
44
+ * The `Authorization` header value (`Bearer <token>`) for the active auth
45
+ * mode, or `undefined` if there is no token. Host-managed mode reads the
46
+ * `getToken` hook; SDK-managed mode reads the in-memory access token. Use this
47
+ * for requests that bypass `projectInstance` (e.g. the SSE `askContent`
48
+ * stream, which needs `fetch` rather than axios).
49
+ */
50
+ getAuthHeader(): Promise<string | undefined>;
51
+ /** Store a full token pair (SDK-managed mode only; no-op when host-managed). */
52
+ setTokens(tokens: AuthTokens): void;
53
+ /** Update just the access token, e.g. after a refresh (no-op when host-managed). */
54
+ setAccessToken(accessToken: string): void;
55
+ /** Clear tokens and notify with null (SDK-managed mode only). */
56
+ clearTokens(): void;
57
+ /**
58
+ * Refresh the access token using the in-memory refresh token. A single shared
59
+ * promise (mutex) means concurrent 403s trigger only one network refresh. The
60
+ * call goes through a bare axios (not `projectInstance`) so it never re-enters
61
+ * the response interceptor. Returns the new access token, or null on failure.
62
+ */
63
+ private refreshAccessToken;
8
64
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Helpers for building `multipart/form-data` request bodies. Shared by every
3
+ * upload site (storage, chat messages, user avatar/banner) so they encode
4
+ * fields identically: object/array values are JSON-stringified (the server
5
+ * re-parses them), scalars are coerced to strings, and `undefined` is skipped.
6
+ *
7
+ * Do NOT set the request's `Content-Type` manually for these bodies — axios sets
8
+ * it to `undefined` for a `FormData` instance so the browser writes the
9
+ * multipart boundary itself.
10
+ */
11
+ /** Append a single field: skip `undefined`, JSON-stringify objects/arrays. */
12
+ export declare function appendField(form: FormData, key: string, value: unknown): void;
13
+ /** Append every own field of `fields` via {@link appendField}. */
14
+ export declare function appendFields(form: FormData, fields: Record<string, unknown>): void;
15
+ /**
16
+ * Append a file part under `field`. The multipart filename is, in order of
17
+ * precedence: an explicit `filename`, the `File`'s own name, then `fallback`.
18
+ */
19
+ export declare function appendFile(form: FormData, field: string, file: Blob | File, opts?: {
20
+ filename?: string;
21
+ fallback?: string;
22
+ }): void;