@sublay/js 5.0.0 → 7.0.0
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/README.md +33 -4
- package/dist/core/client.d.ts +58 -2
- package/dist/core/multipart.d.ts +22 -0
- package/dist/index.d.mts +2525 -42
- package/dist/index.d.ts +29 -2
- package/dist/index.js +1746 -37
- package/dist/index.mjs +1746 -37
- package/dist/interfaces/AppNotification.d.ts +258 -0
- package/dist/interfaces/ChatMessage.d.ts +32 -0
- package/dist/interfaces/Collection.d.ts +10 -0
- package/dist/interfaces/Comment.d.ts +42 -0
- package/dist/interfaces/Connection.d.ts +67 -0
- package/dist/interfaces/Conversation.d.ts +25 -0
- package/dist/interfaces/ConversationMember.d.ts +16 -0
- package/dist/interfaces/Entity.d.ts +53 -0
- package/dist/interfaces/File.d.ts +39 -0
- package/dist/interfaces/Follow.d.ts +19 -0
- package/dist/interfaces/HostedApp.d.ts +11 -0
- package/dist/interfaces/ImageProcessing.d.ts +62 -0
- package/dist/interfaces/Mention.d.ts +12 -0
- package/dist/interfaces/OAuthIdentity.d.ts +13 -0
- package/dist/interfaces/Project.d.ts +14 -0
- package/dist/interfaces/Reaction.d.ts +23 -0
- package/dist/interfaces/Report.d.ts +32 -0
- package/dist/interfaces/Rule.d.ts +22 -0
- package/dist/interfaces/Space.d.ts +141 -0
- package/dist/interfaces/SpaceMember.d.ts +29 -0
- package/dist/interfaces/User.d.ts +39 -0
- package/dist/modules/app-notifications/countUnreadNotifications.d.ts +2 -0
- package/dist/modules/app-notifications/fetchNotifications.d.ts +8 -0
- package/dist/modules/app-notifications/index.d.ts +4 -0
- package/dist/modules/app-notifications/markAllNotificationsAsRead.d.ts +5 -0
- package/dist/modules/app-notifications/markNotificationAsRead.d.ts +5 -0
- package/dist/modules/auth/changePassword.d.ts +11 -0
- package/dist/modules/auth/index.d.ts +10 -0
- package/dist/modules/auth/requestNewAccessToken.d.ts +16 -0
- package/dist/modules/auth/requestPasswordReset.d.ts +5 -0
- package/dist/modules/auth/resetPassword.d.ts +6 -0
- package/dist/modules/auth/sendVerificationEmail.d.ts +13 -0
- package/dist/modules/auth/signIn.d.ts +12 -0
- package/dist/modules/auth/signOut.d.ts +9 -0
- package/dist/modules/auth/signUp.d.ts +24 -0
- package/dist/modules/auth/verifyEmail.d.ts +5 -0
- package/dist/modules/auth/verifyExternalUser.d.ts +11 -0
- package/dist/modules/chat/addMember.d.ts +8 -0
- package/dist/modules/chat/changeMemberRole.d.ts +9 -0
- package/dist/modules/chat/createDirectConversation.d.ts +7 -0
- package/dist/modules/chat/createGroupConversation.d.ts +10 -0
- package/dist/modules/chat/deleteConversation.d.ts +8 -0
- package/dist/modules/chat/deleteMessage.d.ts +11 -0
- package/dist/modules/chat/editMessage.d.ts +13 -0
- package/dist/modules/chat/getConversation.d.ts +6 -0
- package/dist/modules/chat/getMessage.d.ts +7 -0
- package/dist/modules/chat/getUnreadCount.d.ts +6 -0
- package/dist/modules/chat/index.d.ts +21 -0
- package/dist/modules/chat/leaveConversation.d.ts +7 -0
- package/dist/modules/chat/listConversations.d.ts +17 -0
- package/dist/modules/chat/listMembers.d.ts +10 -0
- package/dist/modules/chat/listMessages.d.ts +23 -0
- package/dist/modules/chat/listReactions.d.ts +27 -0
- package/dist/modules/chat/markAsRead.d.ts +9 -0
- package/dist/modules/chat/removeMember.d.ts +9 -0
- package/dist/modules/chat/reportMessage.d.ts +12 -0
- package/dist/modules/chat/sendMessage.d.ts +21 -0
- package/dist/modules/chat/toggleReaction.d.ts +16 -0
- package/dist/modules/chat/updateConversation.d.ts +12 -0
- package/dist/modules/collections/addEntityToCollection.d.ts +13 -0
- package/dist/modules/collections/createNewCollection.d.ts +8 -0
- package/dist/modules/collections/deleteCollection.d.ts +5 -0
- package/dist/modules/collections/fetchCollectionEntities.d.ts +13 -0
- package/dist/modules/collections/fetchRootCollection.d.ts +3 -0
- package/dist/modules/collections/fetchSubCollections.d.ts +6 -0
- package/dist/modules/collections/index.d.ts +8 -0
- package/dist/modules/collections/removeEntityFromCollection.d.ts +7 -0
- package/dist/modules/collections/updateCollection.d.ts +7 -0
- package/dist/modules/comments/addReaction.d.ts +8 -0
- package/dist/modules/comments/createComment.d.ts +15 -0
- package/dist/modules/comments/deleteComment.d.ts +5 -0
- package/dist/modules/comments/fetchComment.d.ts +3 -1
- package/dist/modules/comments/fetchCommentByForeignId.d.ts +3 -1
- package/dist/modules/comments/fetchManyComments.d.ts +14 -0
- package/dist/modules/comments/fetchReactions.d.ts +20 -0
- package/dist/modules/comments/getUserReaction.d.ts +9 -0
- package/dist/modules/comments/index.d.ts +10 -3
- package/dist/modules/comments/removeReaction.d.ts +6 -0
- package/dist/modules/comments/updateComment.d.ts +7 -0
- package/dist/modules/connections/acceptConnection.d.ts +6 -0
- package/dist/modules/connections/declineConnection.d.ts +6 -0
- package/dist/modules/connections/fetchConnections.d.ts +8 -0
- package/dist/modules/connections/fetchConnectionsCount.d.ts +3 -0
- package/dist/modules/connections/fetchReceivedPendingConnections.d.ts +8 -0
- package/dist/modules/connections/fetchSentPendingConnections.d.ts +8 -0
- package/dist/modules/connections/index.d.ts +7 -0
- package/dist/modules/connections/removeConnection.d.ts +5 -0
- package/dist/modules/entities/addReaction.d.ts +8 -0
- package/dist/modules/entities/createEntity.d.ts +7 -2
- package/dist/modules/entities/deleteEntity.d.ts +1 -1
- package/dist/modules/entities/fetchDrafts.d.ts +11 -0
- package/dist/modules/entities/fetchEntity.d.ts +3 -1
- package/dist/modules/entities/fetchEntityByForeignId.d.ts +3 -1
- package/dist/modules/entities/fetchEntityByShortId.d.ts +3 -1
- package/dist/modules/entities/fetchManyEntities.d.ts +11 -3
- package/dist/modules/entities/fetchReactions.d.ts +20 -0
- package/dist/modules/entities/fetchTopComment.d.ts +6 -0
- package/dist/modules/entities/getUserReaction.d.ts +9 -0
- package/dist/modules/entities/index.d.ts +15 -8
- package/dist/modules/entities/isEntitySaved.d.ts +12 -0
- package/dist/modules/entities/publishDraft.d.ts +6 -0
- package/dist/modules/entities/removeReaction.d.ts +6 -0
- package/dist/modules/entities/updateEntity.d.ts +6 -7
- package/dist/modules/follows/deleteFollow.d.ts +5 -0
- package/dist/modules/follows/fetchFollowers.d.ts +8 -0
- package/dist/modules/follows/fetchFollowersCount.d.ts +5 -0
- package/dist/modules/follows/fetchFollowing.d.ts +8 -0
- package/dist/modules/follows/fetchFollowingCount.d.ts +5 -0
- package/dist/modules/follows/index.d.ts +5 -0
- package/dist/modules/oauth/authorize.d.ts +25 -0
- package/dist/modules/oauth/index.d.ts +4 -0
- package/dist/modules/oauth/linkIdentity.d.ts +14 -0
- package/dist/modules/oauth/listIdentities.d.ts +4 -0
- package/dist/modules/oauth/unlinkIdentity.d.ts +12 -0
- package/dist/modules/reports/createReport.d.ts +9 -0
- package/dist/modules/reports/fetchModeratedReports.d.ts +12 -0
- package/dist/modules/reports/index.d.ts +2 -0
- package/dist/modules/search/askContent.d.ts +51 -0
- package/dist/modules/search/index.d.ts +4 -0
- package/dist/modules/search/searchContent.d.ts +17 -0
- package/dist/modules/search/searchSpaces.d.ts +11 -0
- package/dist/modules/search/searchUsers.d.ts +11 -0
- package/dist/modules/spaces/approveMembership.d.ts +7 -0
- package/dist/modules/spaces/banMember.d.ts +13 -0
- package/dist/modules/spaces/checkMyMembership.d.ts +6 -0
- package/dist/modules/spaces/checkSlugAvailability.d.ts +8 -0
- package/dist/modules/spaces/createRule.d.ts +8 -0
- package/dist/modules/spaces/createSpace.d.ts +13 -0
- package/dist/modules/spaces/declineMembership.d.ts +7 -0
- package/dist/modules/spaces/deleteRule.d.ts +7 -0
- package/dist/modules/spaces/deleteSpace.d.ts +6 -0
- package/dist/modules/spaces/fetchChildSpaces.d.ts +11 -0
- package/dist/modules/spaces/fetchDigestConfig.d.ts +6 -0
- package/dist/modules/spaces/fetchManyRules.d.ts +6 -0
- package/dist/modules/spaces/fetchManySpaces.d.ts +16 -0
- package/dist/modules/spaces/fetchRule.d.ts +7 -0
- package/dist/modules/spaces/fetchSpace.d.ts +6 -0
- package/dist/modules/spaces/fetchSpaceBreadcrumb.d.ts +6 -0
- package/dist/modules/spaces/fetchSpaceByShortId.d.ts +6 -0
- package/dist/modules/spaces/fetchSpaceBySlug.d.ts +6 -0
- package/dist/modules/spaces/fetchSpaceMembers.d.ts +10 -0
- package/dist/modules/spaces/fetchSpaceTeam.d.ts +6 -0
- package/dist/modules/spaces/fetchUserSpaces.d.ts +11 -0
- package/dist/modules/spaces/getSpaceConversation.d.ts +6 -0
- package/dist/modules/spaces/handleCommentReport.d.ts +14 -0
- package/dist/modules/spaces/handleEntityReport.d.ts +17 -0
- package/dist/modules/spaces/handleSpaceChatReport.d.ts +18 -0
- package/dist/modules/spaces/index.d.ts +36 -0
- package/dist/modules/spaces/joinSpace.d.ts +6 -0
- package/dist/modules/spaces/leaveSpace.d.ts +6 -0
- package/dist/modules/spaces/moderateSpaceChatMessage.d.ts +12 -0
- package/dist/modules/spaces/moderateSpaceComment.d.ts +9 -0
- package/dist/modules/spaces/moderateSpaceEntity.d.ts +12 -0
- package/dist/modules/spaces/reorderRules.d.ts +7 -0
- package/dist/modules/spaces/unbanMember.d.ts +13 -0
- package/dist/modules/spaces/updateDigestConfig.d.ts +11 -0
- package/dist/modules/spaces/updateMemberRole.d.ts +8 -0
- package/dist/modules/spaces/updateRule.d.ts +9 -0
- package/dist/modules/spaces/updateSpace.d.ts +12 -0
- package/dist/modules/storage/deleteFile.d.ts +5 -0
- package/dist/modules/storage/getFile.d.ts +34 -0
- package/dist/modules/storage/index.d.ts +4 -0
- package/dist/modules/storage/uploadFile.d.ts +30 -0
- package/dist/modules/storage/uploadImage.d.ts +41 -0
- package/dist/modules/users/checkUsernameAvailability.d.ts +8 -0
- package/dist/modules/users/createFollow.d.ts +7 -0
- package/dist/modules/users/deleteFollow.d.ts +6 -0
- package/dist/modules/users/fetchConnectionStatus.d.ts +10 -0
- package/dist/modules/users/fetchConnectionsByUserId.d.ts +9 -0
- package/dist/modules/users/fetchConnectionsCountByUserId.d.ts +6 -0
- package/dist/modules/users/fetchFollowStatus.d.ts +14 -0
- package/dist/modules/users/fetchFollowersByUserId.d.ts +9 -0
- package/dist/modules/users/fetchFollowersCountByUserId.d.ts +8 -0
- package/dist/modules/users/fetchFollowingByUserId.d.ts +9 -0
- package/dist/modules/users/fetchFollowingCountByUserId.d.ts +8 -0
- package/dist/modules/users/fetchUserByForeignId.d.ts +3 -7
- package/dist/modules/users/fetchUserById.d.ts +3 -1
- package/dist/modules/users/fetchUserByUsername.d.ts +7 -0
- package/dist/modules/users/fetchUserSuggestions.d.ts +6 -0
- package/dist/modules/users/index.d.ts +18 -3
- package/dist/modules/users/removeConnectionByUserId.d.ts +10 -0
- package/dist/modules/users/requestConnection.d.ts +11 -0
- package/dist/modules/users/updateUser.d.ts +32 -0
- package/package.json +6 -3
- package/CLAUDE.md +0 -339
- package/pnpm-workspace.yaml +0 -2
- package/src/core/client.ts +0 -15
- package/src/index.ts +0 -45
- package/src/interfaces/IPaginatedResponse.ts +0 -12
- package/src/modules/comments/fetchComment.ts +0 -14
- package/src/modules/comments/fetchCommentByForeignId.ts +0 -14
- package/src/modules/comments/index.ts +0 -4
- package/src/modules/entities/createEntity.ts +0 -27
- package/src/modules/entities/deleteEntity.ts +0 -14
- package/src/modules/entities/fetchEntity.ts +0 -14
- package/src/modules/entities/fetchEntityByForeignId.ts +0 -15
- package/src/modules/entities/fetchEntityByShortId.ts +0 -14
- package/src/modules/entities/fetchManyEntities.ts +0 -79
- package/src/modules/entities/index.ts +0 -17
- package/src/modules/entities/updateEntity.ts +0 -28
- package/src/modules/users/fetchUserByForeignId.ts +0 -40
- package/src/modules/users/fetchUserById.ts +0 -15
- package/src/modules/users/index.ts +0 -4
- 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
|
-
|
|
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
|
---
|
package/dist/core/client.d.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
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;
|