@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.
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 +2525 -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 +27 -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 +20 -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 +20 -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 +6 -3
  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/CLAUDE.md DELETED
@@ -1,339 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- This is the **@sublay/js** package - the official JavaScript SDK for Sublay. It's a lightweight, framework-agnostic SDK designed for JavaScript/TypeScript projects that don't use React or don't need the full React setup from the monorepo packages.
8
-
9
- **Package Name**: @sublay/js
10
- **Version**: 5.0.0
11
- **Type**: JavaScript SDK library (published to npm)
12
-
13
- ## Development Commands
14
-
15
- ```bash
16
- # Build the package (TypeScript compilation + bundling)
17
- pnpm build
18
-
19
- # Generate TypeScript declaration files
20
- pnpm build:types
21
-
22
- # Build both (runs before publishing)
23
- pnpm prepare
24
-
25
- # Publish to npm with beta tag
26
- pnpm publish-beta
27
-
28
- # Publish to npm production
29
- pnpm publish-prod
30
- ```
31
-
32
- ## Core Architecture
33
-
34
- ### Module Structure
35
-
36
- The SDK is organized into 3 main API modules:
37
-
38
- ```
39
- src/
40
- ├── core/
41
- │ └── client.ts # HTTP client wrapper using axios
42
- ├── modules/
43
- │ ├── users/ # User operations (2 functions)
44
- │ │ ├── index.ts
45
- │ │ ├── fetchUserById.ts
46
- │ │ └── fetchUserByForeignId.ts
47
- │ ├── entities/ # Entity CRUD operations (7 functions)
48
- │ │ ├── index.ts
49
- │ │ ├── createEntity.ts
50
- │ │ ├── fetchEntity.ts
51
- │ │ ├── fetchEntityByForeignId.ts
52
- │ │ ├── fetchEntityByShortId.ts
53
- │ │ ├── fetchManyEntities.ts
54
- │ │ ├── updateEntity.ts
55
- │ │ └── deleteEntity.ts
56
- │ └── comments/ # Comment operations (2 functions)
57
- │ ├── index.ts
58
- │ ├── fetchComment.ts
59
- │ └── fetchCommentByForeignId.ts
60
- └── index.ts # Main entry point with SublayClient class
61
- ```
62
-
63
- ### HTTP Client
64
-
65
- Uses a custom `SublayHttpClient` class that wraps axios with pre-configured base URL:
66
- - **Base URL**: `https://api.sublay.io/api/v5/{projectId}`
67
- - **Headers**: Standard axios configuration
68
- - **Method**: GET/POST/PUT/DELETE operations
69
-
70
- ### Initialization Pattern
71
-
72
- ```typescript
73
- import { SublayClient } from '@sublay/js';
74
-
75
- const client = await SublayClient.init({
76
- projectId: "your-project-id"
77
- });
78
-
79
- // Client initializes and returns bound module functions
80
- ```
81
-
82
- **Factory Pattern**: Uses `SublayClient.init()` for initialization, which:
83
- 1. Creates an HTTP client instance with the project ID
84
- 2. Binds all module functions to the client
85
- 3. Returns the client with namespaced API methods
86
-
87
- ## API Modules & Features
88
-
89
- ### 1. Users Module (2 functions)
90
-
91
- **Functions**:
92
- - `client.users.fetchUserById({ userId })` - Fetch user by Sublay ID
93
- - `client.users.fetchUserByForeignId({ foreignId, name?, username?, avatar?, bio?, metadata?, secureMetadata? })` - Fetch user by external ID with optional user data
94
-
95
- **Features**:
96
- - Foreign ID support for external system integration
97
- - Optional user data creation on first fetch
98
- - Support for public and secure metadata
99
-
100
- ### 2. Entities Module (7 functions)
101
-
102
- Entities are the core content objects (posts, articles, products, listings, etc.).
103
-
104
- **Functions**:
105
- - `client.entities.createEntity(data)` - Create a new entity
106
- - `client.entities.fetchEntity({ entityId })` - Fetch by Sublay ID
107
- - `client.entities.fetchEntityByForeignId({ foreignId })` - Fetch by external system ID
108
- - `client.entities.fetchEntityByShortId({ shortId })` - Fetch by short/shareable ID
109
- - `client.entities.fetchManyEntities(filters)` - Advanced querying with extensive filters
110
- - `client.entities.updateEntity(data)` - Update entity
111
- - `client.entities.deleteEntity({ entityId })` - Delete entity
112
-
113
- **Create Entity Parameters**:
114
- - `foreignId` - External system ID for integration
115
- - `sourceId` - Source identifier (e.g., "blog", "shop")
116
- - `title` - Entity title
117
- - `content` - Main content/body
118
- - `attachments` - Media attachments (flexible structure)
119
- - `keywords` - Tags/categories
120
- - `location` - Geo-location (lat/lng or GeoJSON Point)
121
- - `metadata` - Custom metadata (up to 10KB)
122
- - `userId` - Author/creator ID
123
-
124
- **Advanced Filtering** (fetchManyEntities):
125
- Supports extensive filtering options:
126
- - **Sorting**: `hot`, `top`, `controversial`
127
- - **Timeframes**: `hour`, `day`, `week`, `month`, `year`, `all`
128
- - **Pagination**: `page`, `limit`
129
- - **Keywords**:
130
- - `keywords.includes` - Array of required tags
131
- - `keywords.excludes` - Array of excluded tags
132
- - **Metadata Filters**:
133
- - `metadata.includes` - Object of required key-value pairs
134
- - `metadata.excludes` - Object of excluded key-value pairs
135
- - `metadata.exists` - Array of required metadata keys
136
- - **Content Filters**:
137
- - `title.includes` / `title.excludes` - Title text filtering
138
- - `content.includes` / `content.excludes` - Content text filtering
139
- - **Attachment Filters**:
140
- - `attachments.has` - Entities with attachments
141
- - `attachments.hasNot` - Entities without attachments
142
- - **Location Filters**:
143
- - `location.latitude` / `location.longitude` - Geo-coordinates
144
- - `location.radius` - Radius in kilometers
145
- - **User Filters**:
146
- - `userId` - Filter by specific user
147
- - `followedOnly` - Only from users the current user follows
148
-
149
- ### 3. Comments Module (2 functions)
150
-
151
- **Functions**:
152
- - `client.comments.fetchComment({ commentId })` - Fetch comment by Sublay ID
153
- - `client.comments.fetchCommentByForeignId({ foreignId })` - Fetch comment by external ID
154
-
155
- **Note**: This module currently provides read-only access. Comment creation/updates are available in other SDK packages (@sublay/node) or through direct API calls.
156
-
157
- ## Key Design Patterns
158
-
159
- ### 1. Framework-Agnostic
160
- No dependencies on React, Vue, Angular, or any specific framework. Works with vanilla JavaScript, TypeScript, or any JavaScript framework.
161
-
162
- ### 2. Type Safety
163
- Full TypeScript support with type definitions, though return types are currently `any` with TODOs to add proper entity types in future versions.
164
-
165
- ### 3. Function Binding
166
- Module functions are bound to the HTTP client at initialization, providing a clean API without manually passing the client.
167
-
168
- ### 4. Foreign ID Support
169
- Seamless integration with existing systems through foreign ID mapping on all major resources.
170
-
171
- ### 5. Location Flexibility
172
- Supports both simple `{ lat, lng }` objects and GeoJSON Point format for geo-location data.
173
-
174
- ## Usage Examples
175
-
176
- ### Basic Initialization
177
-
178
- ```typescript
179
- import { SublayClient } from '@sublay/js';
180
-
181
- const client = await SublayClient.init({
182
- projectId: 'your-project-id'
183
- });
184
- ```
185
-
186
- ### Fetching Entities
187
-
188
- ```javascript
189
- // Fetch single entity
190
- const entity = await client.entities.fetchEntity({
191
- entityId: 'entity-123'
192
- });
193
-
194
- // Fetch by foreign ID
195
- const post = await client.entities.fetchEntityByForeignId({
196
- foreignId: 'blog-post-456'
197
- });
198
-
199
- // Fetch with advanced filters
200
- const trendingPosts = await client.entities.fetchManyEntities({
201
- sort: 'hot',
202
- timeframe: 'week',
203
- keywords: { includes: ['javascript', 'tutorial'] },
204
- attachments: { has: true },
205
- limit: 20,
206
- page: 1
207
- });
208
- ```
209
-
210
- ### Creating Entities
211
-
212
- ```javascript
213
- const newEntity = await client.entities.createEntity({
214
- foreignId: 'my-post-789',
215
- sourceId: 'blog',
216
- title: 'Getting Started with JavaScript',
217
- content: 'In this tutorial, we will learn...',
218
- keywords: ['javascript', 'tutorial', 'beginner'],
219
- userId: 'user-123',
220
- metadata: {
221
- category: 'programming',
222
- difficulty: 'beginner',
223
- readTime: 5
224
- }
225
- });
226
- ```
227
-
228
- ### Updating Entities
229
-
230
- ```javascript
231
- await client.entities.updateEntity({
232
- entityId: 'entity-123',
233
- title: 'Updated Title',
234
- content: 'Updated content...',
235
- keywords: ['updated', 'tags']
236
- });
237
- ```
238
-
239
- ### Geo-Location Filtering
240
-
241
- ```javascript
242
- // Find entities near a location
243
- const nearbyPosts = await client.entities.fetchManyEntities({
244
- location: {
245
- latitude: 40.7128,
246
- longitude: -74.0060,
247
- radius: 10 // 10km radius
248
- },
249
- limit: 50
250
- });
251
- ```
252
-
253
- ### Working with Users
254
-
255
- ```javascript
256
- // Fetch user by ID
257
- const user = await client.users.fetchUserById({
258
- userId: 'user-123'
259
- });
260
-
261
- // Fetch or create user by foreign ID
262
- const externalUser = await client.users.fetchUserByForeignId({
263
- foreignId: 'external-user-456',
264
- name: 'John Doe',
265
- username: 'johndoe',
266
- avatar: 'https://example.com/avatar.jpg',
267
- metadata: {
268
- source: 'external-system'
269
- }
270
- });
271
- ```
272
-
273
- ## Build & Publishing
274
-
275
- ### Build Configuration
276
- - **Build Tool**: tsup
277
- - **Output Formats**: CommonJS and ESM (dual package)
278
- - **Type Declarations**: Generated via TypeScript compiler
279
- - **Target**: Modern JavaScript (ES modules)
280
- - **Entry Point**: `src/index.ts`
281
-
282
- ### Output Structure
283
- ```
284
- dist/
285
- ├── index.js # Main bundle (CJS/ESM)
286
- └── index.d.ts # TypeScript declarations
287
- ```
288
-
289
- ### Publishing
290
- ```bash
291
- # Beta release
292
- pnpm publish-beta
293
-
294
- # Production release
295
- pnpm publish-prod
296
- ```
297
-
298
- **Package Exports**:
299
- - Main: `dist/index.js`
300
- - Types: `dist/index.d.ts`
301
-
302
- ## Use Cases
303
-
304
- This SDK is ideal for:
305
-
306
- 1. **Vanilla JavaScript Projects** - Plain JS applications without frameworks
307
- 2. **Non-React Frameworks** - Vue, Svelte, Angular, Solid, etc.
308
- 3. **Server-Side Rendering** - SSR applications without React
309
- 4. **Static Site Generators** - Eleventy, Hugo (with JavaScript), Astro (non-React)
310
- 5. **Chrome Extensions** - Browser extensions built with vanilla JS
311
- 6. **Electron Apps** - Desktop applications using web technologies
312
- 7. **Web Workers** - Background scripts and service workers
313
- 8. **Lightweight Integrations** - When you don't need the full React SDK overhead
314
-
315
- Essentially any JavaScript/TypeScript project that needs Sublay integration without React dependencies.
316
-
317
- ## Technical Details
318
-
319
- - **TypeScript**: Strict mode enabled
320
- - **Dependencies**: Only axios for HTTP requests
321
- - **API Version**: Uses v5 API endpoints
322
- - **Bundle Size**: Lightweight (no framework dependencies)
323
- - **Browser Support**: Modern browsers (ES6+)
324
- - **Node.js Support**: Yes (v14+)
325
-
326
- ## Important Notes
327
-
328
- - This SDK is **production-ready** (v5.0.0)
329
- - Requires a valid project ID from Sublay dashboard
330
- - Currently uses v5 API endpoints
331
- - Return types are typed as `any` (TODOs exist to add proper types)
332
- - No README.md file exists yet (documentation pending)
333
- - Comment module has limited functionality (read-only)
334
-
335
- ## Comparison with Other SDKs
336
-
337
- - **vs @sublay/node**: This SDK is lighter weight and framework-agnostic, while @sublay/node is optimized for Node.js server environments with more comprehensive API coverage
338
- - **vs @sublay/react-js**: This SDK has no React dependencies, making it suitable for non-React projects or when you don't need React hooks and components
339
- - **vs monorepo packages**: This SDK is standalone and simpler, while monorepo packages provide full React/React Native integration with hooks, contexts, and UI components
@@ -1,2 +0,0 @@
1
- allowBuilds:
2
- esbuild: true
@@ -1,15 +0,0 @@
1
- import axios, { AxiosInstance } from "axios";
2
-
3
- export interface ClientConfig {
4
- projectId: string;
5
- }
6
-
7
- export class SublayHttpClient {
8
- instance: AxiosInstance;
9
-
10
- constructor({ projectId }: ClientConfig) {
11
- this.instance = axios.create({
12
- baseURL: `https://api.sublay.io/api/v5/${projectId}`,
13
- });
14
- }
15
- }
package/src/index.ts DELETED
@@ -1,45 +0,0 @@
1
- import { SublayHttpClient, ClientConfig } from "./core/client";
2
- import * as Users from "./modules/users";
3
- import * as Entities from "./modules/entities";
4
- import * as Comments from "./modules/comments";
5
-
6
- type BoundModule<
7
- T extends Record<string, (client: SublayHttpClient, ...args: any[]) => any>
8
- > = {
9
- [K in keyof T]: (
10
- ...args: Parameters<T[K]> extends [any, ...infer R] ? R : never
11
- ) => ReturnType<T[K]>;
12
- };
13
-
14
- export class SublayClient {
15
- private http: SublayHttpClient;
16
-
17
- public users: BoundModule<typeof Users>;
18
- public entities: BoundModule<typeof Entities>;
19
- public comments: BoundModule<typeof Comments>;
20
-
21
- private constructor(http: SublayHttpClient) {
22
- this.http = http;
23
- this.users = bindModule(Users, this.http);
24
- this.entities = bindModule(Entities, this.http);
25
- this.comments = bindModule(Comments, this.http);
26
- }
27
-
28
- static async init(config: ClientConfig): Promise<SublayClient> {
29
- const http = new SublayHttpClient(config);
30
- return new SublayClient(http);
31
- }
32
- }
33
-
34
- function bindModule<
35
- T extends Record<string, (client: SublayHttpClient, ...args: any[]) => any>
36
- >(module: T, client: SublayHttpClient): BoundModule<T> {
37
- const bound: any = {};
38
- for (const key in module) {
39
- bound[key] = (...args: any[]) => module[key](client, ...args);
40
- }
41
- return bound;
42
- }
43
-
44
- // Export pagination types
45
- export type { PaginatedResponse, PaginationMetadata } from "./interfaces/IPaginatedResponse";
@@ -1,12 +0,0 @@
1
- export interface PaginationMetadata {
2
- page: number;
3
- pageSize: number;
4
- totalPages: number;
5
- totalItems: number;
6
- hasMore: boolean;
7
- }
8
-
9
- export interface PaginatedResponse<T> {
10
- data: T[];
11
- pagination: PaginationMetadata;
12
- }
@@ -1,14 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface FetchCommentProps {
4
- commentId: string;
5
- }
6
-
7
- export async function fetchComment(
8
- client: SublayHttpClient,
9
- data: FetchCommentProps
10
- ): Promise<any> {
11
- const path = `/comments/${data.commentId}`;
12
- const response = await client.instance.get<any>(path);
13
- return response.data;
14
- }
@@ -1,14 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface FetchCommentByForeignIdProps {
4
- foreignId: string;
5
- }
6
-
7
- export async function fetchCommentByForeignId(
8
- client: SublayHttpClient,
9
- data: FetchCommentByForeignIdProps
10
- ): Promise<any> {
11
- const path = `/comments/by-foreign-id`;
12
- const response = await client.instance.get<any>(path, { params: data });
13
- return response.data;
14
- }
@@ -1,4 +0,0 @@
1
- import { fetchComment } from "./fetchComment";
2
- import { fetchCommentByForeignId } from "./fetchCommentByForeignId";
3
-
4
- export { fetchComment, fetchCommentByForeignId };
@@ -1,27 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface CreateEntityProps {
4
- foreignId?: string;
5
- sourceId?: string;
6
- spaceId?: string;
7
- title?: string;
8
- content?: string;
9
- attachments?: Record<string, any>[];
10
- keywords?: string[];
11
- location?: {
12
- latitude: number;
13
- longitude: number;
14
- };
15
- metadata?: Record<string, any>;
16
- userId?: string;
17
- }
18
-
19
- // TODO: Replace "any" with Entity once we have types here too
20
- export async function createEntity(
21
- client: SublayHttpClient,
22
- data: CreateEntityProps
23
- ): Promise<any> {
24
- const path = `/entities`; // assuming client handles prefix like /{projectId}
25
- const response = await client.instance.post<any>(path, data);
26
- return response.data;
27
- }
@@ -1,14 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface DeleteEntityProps {
4
- entityId: string;
5
- }
6
-
7
- export async function deleteEntity(
8
- client: SublayHttpClient,
9
- data: DeleteEntityProps
10
- ): Promise<any> {
11
- const path = `/entities/${data.entityId}`;
12
- const response = await client.instance.delete<any>(path);
13
- return response.data;
14
- }
@@ -1,14 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface FetchEntityProps {
4
- entityId: string;
5
- }
6
-
7
- export async function fetchEntity(
8
- client: SublayHttpClient,
9
- data: FetchEntityProps
10
- ): Promise<any> {
11
- const path = `/entities/${data.entityId}`;
12
- const response = await client.instance.get<any>(path);
13
- return response.data;
14
- }
@@ -1,15 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface FetchEntityByForeignIdProps {
4
- foreignId: string;
5
- createIfNotFound?: boolean;
6
- }
7
-
8
- export async function fetchEntityByForeignId(
9
- client: SublayHttpClient,
10
- data: FetchEntityByForeignIdProps
11
- ): Promise<any> {
12
- const path = `/entities/by-foreign-id`;
13
- const response = await client.instance.get<any>(path, { params: data });
14
- return response.data;
15
- }
@@ -1,14 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface FetchEntityByShortIdProps {
4
- shortId: string;
5
- }
6
-
7
- export async function fetchEntityByShortId(
8
- client: SublayHttpClient,
9
- data: FetchEntityByShortIdProps
10
- ): Promise<any> {
11
- const path = `/entities/by-short-id`;
12
- const response = await client.instance.get<any>(path, { params: data });
13
- return response.data;
14
- }
@@ -1,79 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
- import { PaginatedResponse } from "../../interfaces/IPaginatedResponse";
3
-
4
- export interface KeywordsFilters {
5
- includes?: string[];
6
- doesNotInclude?: string[];
7
- }
8
-
9
- export interface MetadataFilters {
10
- includes?: { [key: string]: any };
11
- doesNotInclude?: { [key: string]: any };
12
- exists?: string[];
13
- doesNotExist?: string[];
14
- }
15
-
16
- export interface TextFilters {
17
- hasTitle?: "true" | "false";
18
- includes?: string | string[];
19
- doesNotInclude?: string | string[];
20
- }
21
-
22
- export interface AttachmentsFilters {
23
- hasAttachments?: "true" | "false";
24
- }
25
-
26
- export interface LocationFilters {
27
- latitude: string;
28
- longitude: string;
29
- radius: string;
30
- }
31
-
32
- export interface FetchManyEntitiesProps {
33
- sourceId?: string;
34
- spaceId?: string;
35
-
36
- // Sorting & Pagination
37
- sortBy?: "hot" | "top" | "controversial";
38
- page?: number;
39
- limit?: number;
40
-
41
- // Time-based filtering
42
- timeFrame?: "hour" | "day" | "week" | "month" | "year";
43
-
44
- userId?: string;
45
- followedOnly?: "true";
46
-
47
- // Keyword filters
48
- keywordsFilters?: KeywordsFilters;
49
-
50
- // Metadata filters
51
- metadataFilters?: MetadataFilters;
52
-
53
- // Title filtering
54
- titleFilters?: TextFilters;
55
-
56
- // Content filtering
57
- contentFilters?: {
58
- hasContent?: "true" | "false";
59
- includes?: string | string[];
60
- doesNotInclude?: string | string[];
61
- };
62
-
63
- // Media filtering
64
- attachmentsFilters?: AttachmentsFilters;
65
-
66
- // Location filtering
67
- locationFilters?: LocationFilters;
68
- }
69
-
70
- export async function fetchManyEntities(
71
- client: SublayHttpClient,
72
- data: FetchManyEntitiesProps
73
- ): Promise<PaginatedResponse<any>> {
74
- const path = `/entities`;
75
- const response = await client.instance.get<PaginatedResponse<any>>(path, {
76
- params: data,
77
- });
78
- return response.data;
79
- }
@@ -1,17 +0,0 @@
1
- import { createEntity } from "./createEntity";
2
- import { fetchEntity } from "./fetchEntity";
3
- import { fetchEntityByForeignId } from "./fetchEntityByForeignId";
4
- import { fetchEntityByShortId } from "./fetchEntityByShortId";
5
- import { fetchManyEntities } from "./fetchManyEntities";
6
- import { updateEntity } from "./updateEntity";
7
- import { deleteEntity } from "./deleteEntity";
8
-
9
- export {
10
- createEntity,
11
- fetchEntity,
12
- fetchEntityByForeignId,
13
- fetchEntityByShortId,
14
- fetchManyEntities,
15
- updateEntity,
16
- deleteEntity,
17
- };
@@ -1,28 +0,0 @@
1
- import { SublayHttpClient } from "../../core/client";
2
-
3
- export interface UpdateEntityProps {
4
- entityId: string;
5
- title?: string;
6
- content?: string;
7
- attachments?: Record<string, any>[];
8
- keywords?: string[];
9
- location?: {
10
- type: "Point";
11
- coordinates: [number, number]; // [longitude, latitude]
12
- };
13
- metadata?: Record<string, any>;
14
- mentions?: {
15
- id: string;
16
- username: string;
17
- }[];
18
- }
19
-
20
- export async function updateEntity(
21
- client: SublayHttpClient,
22
- data: UpdateEntityProps
23
- ): Promise<any> {
24
- const { entityId, ...restOfProps } = data;
25
- const path = `/entities/${data.entityId}`;
26
- const response = await client.instance.patch<any>(path, restOfProps);
27
- return response.data;
28
- }