@jamwidgets/core 0.1.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 +277 -0
- package/dist/index.d.ts +491 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1021 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
# @jamwidgets/core
|
|
2
|
+
|
|
3
|
+
> **Note:** This repo is a read-only mirror. Source lives in a private monorepo.
|
|
4
|
+
> For issues/PRs, please open them here and we'll sync changes back.
|
|
5
|
+
|
|
6
|
+
Framework-agnostic API client, types, and headless controllers for [JamWidgets](https://jamwidgets.com) widgets.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @jamwidgets/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This is the base package used by `@jamwidgets/astro`, `@jamwidgets/react`, and `@jamwidgets/solid`. Use it directly when building custom integrations or with any JavaScript framework.
|
|
15
|
+
|
|
16
|
+
## API Functions
|
|
17
|
+
|
|
18
|
+
### Comments
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { fetchComments, postComment } from "@jamwidgets/core";
|
|
22
|
+
|
|
23
|
+
// Fetch comments for a page
|
|
24
|
+
const comments = await fetchComments({
|
|
25
|
+
siteKey: "your-key",
|
|
26
|
+
pageId: "my-page",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Post a new comment
|
|
30
|
+
await postComment({
|
|
31
|
+
siteKey: "your-key",
|
|
32
|
+
pageId: "my-page",
|
|
33
|
+
authorName: "John",
|
|
34
|
+
content: "Great post!",
|
|
35
|
+
authorEmail: "john@example.com", // optional
|
|
36
|
+
parentId: "comment-id", // optional, for replies
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Reactions
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { fetchReactions, addReaction, removeReaction } from "@jamwidgets/core";
|
|
44
|
+
|
|
45
|
+
// Fetch reactions for a page
|
|
46
|
+
const { counts, userReactions } = await fetchReactions({
|
|
47
|
+
siteKey: "your-key",
|
|
48
|
+
pageId: "my-page",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Add a reaction
|
|
52
|
+
await addReaction({
|
|
53
|
+
siteKey: "your-key",
|
|
54
|
+
pageId: "my-page",
|
|
55
|
+
reactionType: "like", // or 'clap', 'heart', etc.
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Remove a reaction
|
|
59
|
+
await removeReaction({
|
|
60
|
+
siteKey: "your-key",
|
|
61
|
+
pageId: "my-page",
|
|
62
|
+
reactionType: "like",
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Forms
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { submitForm } from "@jamwidgets/core";
|
|
70
|
+
|
|
71
|
+
await submitForm({
|
|
72
|
+
siteKey: "your-key",
|
|
73
|
+
formSlug: "contact",
|
|
74
|
+
data: {
|
|
75
|
+
name: "John",
|
|
76
|
+
email: "john@example.com",
|
|
77
|
+
message: "Hello!",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Subscriptions
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { subscribe } from "@jamwidgets/core";
|
|
86
|
+
|
|
87
|
+
await subscribe({
|
|
88
|
+
siteKey: "your-key",
|
|
89
|
+
email: "user@example.com",
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Waitlist
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { joinWaitlist } from "@jamwidgets/core";
|
|
97
|
+
|
|
98
|
+
await joinWaitlist({
|
|
99
|
+
siteKey: "your-key",
|
|
100
|
+
email: "user@example.com",
|
|
101
|
+
name: "John", // optional
|
|
102
|
+
source: "homepage", // optional
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Feedback
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { submitFeedback } from "@jamwidgets/core";
|
|
110
|
+
|
|
111
|
+
await submitFeedback({
|
|
112
|
+
siteKey: "your-key",
|
|
113
|
+
type: "bug", // 'bug' | 'feature' | 'general'
|
|
114
|
+
content: "Found an issue...",
|
|
115
|
+
email: "user@example.com", // optional
|
|
116
|
+
pageUrl: "/about", // optional
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Polls
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { fetchPoll, votePoll } from "@jamwidgets/core";
|
|
124
|
+
|
|
125
|
+
// Fetch poll data
|
|
126
|
+
const poll = await fetchPoll({
|
|
127
|
+
siteKey: "your-key",
|
|
128
|
+
slug: "favorite-framework",
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Vote on a poll
|
|
132
|
+
await votePoll({
|
|
133
|
+
siteKey: "your-key",
|
|
134
|
+
slug: "favorite-framework",
|
|
135
|
+
selectedOptions: ["option-1", "option-2"],
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Views
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { getViewCounts, recordView } from "@jamwidgets/core";
|
|
143
|
+
|
|
144
|
+
// Get view counts
|
|
145
|
+
const { views, uniqueVisitors } = await getViewCounts({
|
|
146
|
+
siteKey: "your-key",
|
|
147
|
+
pageId: "my-page",
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Record a view
|
|
151
|
+
await recordView({
|
|
152
|
+
siteKey: "your-key",
|
|
153
|
+
pageId: "my-page",
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Announcements
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { fetchAnnouncements, dismissAnnouncement } from "@jamwidgets/core";
|
|
161
|
+
|
|
162
|
+
// Fetch active announcements
|
|
163
|
+
const announcements = await fetchAnnouncements({
|
|
164
|
+
siteKey: "your-key",
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Dismiss an announcement
|
|
168
|
+
await dismissAnnouncement({
|
|
169
|
+
siteKey: "your-key",
|
|
170
|
+
announcementId: 123,
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Posts
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { fetchPosts, fetchPost } from "@jamwidgets/core";
|
|
178
|
+
|
|
179
|
+
// Fetch all published posts
|
|
180
|
+
const posts = await fetchPosts({
|
|
181
|
+
siteKey: "your-key",
|
|
182
|
+
tag: "tutorials", // optional filter
|
|
183
|
+
limit: 10, // optional
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Fetch a single post
|
|
187
|
+
const post = await fetchPost({
|
|
188
|
+
siteKey: "your-key",
|
|
189
|
+
slug: "my-post",
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Headless Controllers
|
|
194
|
+
|
|
195
|
+
Controllers manage state without any DOM dependencies. Use them to build custom UI or integrate with any framework.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import {
|
|
199
|
+
SubscribeController,
|
|
200
|
+
FormController,
|
|
201
|
+
ReactionsController,
|
|
202
|
+
CommentsController,
|
|
203
|
+
WaitlistController,
|
|
204
|
+
FeedbackController,
|
|
205
|
+
PollController,
|
|
206
|
+
AnnouncementsController,
|
|
207
|
+
ViewCountsController,
|
|
208
|
+
} from "@jamwidgets/core";
|
|
209
|
+
|
|
210
|
+
// Example: Subscribe controller
|
|
211
|
+
const controller = new SubscribeController({ siteKey: "your-key" });
|
|
212
|
+
|
|
213
|
+
// Subscribe to state changes
|
|
214
|
+
controller.subscribe((state) => {
|
|
215
|
+
console.log(state.status); // 'idle' | 'loading' | 'success' | 'error'
|
|
216
|
+
console.log(state.message);
|
|
217
|
+
console.log(state.error);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Submit
|
|
221
|
+
await controller.submit("user@example.com");
|
|
222
|
+
|
|
223
|
+
// Reset
|
|
224
|
+
controller.reset();
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Available Controllers
|
|
228
|
+
|
|
229
|
+
| Controller | Purpose |
|
|
230
|
+
|------------|---------|
|
|
231
|
+
| `SubscribeController` | Email subscriptions |
|
|
232
|
+
| `FormController` | Form submissions |
|
|
233
|
+
| `ReactionsController` | Page reactions |
|
|
234
|
+
| `CommentsController` | Threaded comments |
|
|
235
|
+
| `WaitlistController` | Waitlist signups |
|
|
236
|
+
| `FeedbackController` | Feedback forms |
|
|
237
|
+
| `PollController` | Polls and voting |
|
|
238
|
+
| `AnnouncementsController` | Site announcements |
|
|
239
|
+
| `ViewCountsController` | Page view tracking |
|
|
240
|
+
|
|
241
|
+
## Visitor Management
|
|
242
|
+
|
|
243
|
+
Reactions and views track visitors using localStorage. For authenticated users, you can set a custom visitor ID:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { setVisitorId, getVisitorId } from "@jamwidgets/core";
|
|
247
|
+
|
|
248
|
+
// Set custom visitor ID (e.g., for logged-in users)
|
|
249
|
+
setVisitorId("user-123");
|
|
250
|
+
|
|
251
|
+
// Get current visitor ID
|
|
252
|
+
const visitorId = getVisitorId();
|
|
253
|
+
|
|
254
|
+
// Revert to localStorage-based ID
|
|
255
|
+
setVisitorId(null);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Types
|
|
259
|
+
|
|
260
|
+
All types are exported for TypeScript users:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import type {
|
|
264
|
+
JamWidgetsConfig,
|
|
265
|
+
Comment,
|
|
266
|
+
ReactionCounts,
|
|
267
|
+
JamWidgetsPost,
|
|
268
|
+
Poll,
|
|
269
|
+
Announcement,
|
|
270
|
+
FeedbackType,
|
|
271
|
+
ControllerStatus,
|
|
272
|
+
} from "@jamwidgets/core";
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## License
|
|
276
|
+
|
|
277
|
+
MIT
|