reflet-sdk 0.1.5 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,297 +1,3 @@
1
- /**
2
- * Reflet SDK Types
3
- */
4
- interface RefletConfig {
5
- /** Your organization's public API key (fb_pub_xxx) */
6
- publicKey: string;
7
- /** API base URL (optional, defaults to Reflet production API) */
8
- baseUrl?: string;
9
- /** User identification for SSO */
10
- user?: RefletUser;
11
- /** Pre-signed user token (alternative to user object) */
12
- userToken?: string;
13
- }
14
- interface RefletUser {
15
- /** Unique identifier for the user in your system */
16
- id: string;
17
- /** User's email address */
18
- email?: string;
19
- /** User's display name */
20
- name?: string;
21
- /** URL to user's avatar image */
22
- avatar?: string;
23
- /** Additional metadata */
24
- metadata?: Record<string, unknown>;
25
- }
26
- interface OrganizationConfig {
27
- id: string;
28
- name: string;
29
- slug: string;
30
- description?: string;
31
- isPublic: boolean;
32
- settings?: OrganizationSettings;
33
- logo?: string;
34
- primaryColor?: string;
35
- statuses: OrganizationStatus[];
36
- }
37
- interface OrganizationSettings {
38
- allowAnonymousVoting?: boolean;
39
- requireApproval?: boolean;
40
- defaultStatus?: FeedbackStatus;
41
- }
42
- interface OrganizationStatus {
43
- id: string;
44
- name: string;
45
- color: string;
46
- icon?: string;
47
- order: number;
48
- }
49
- type FeedbackStatus = "open" | "under_review" | "planned" | "in_progress" | "completed" | "closed";
50
- interface FeedbackItem {
51
- id: string;
52
- title: string;
53
- description: string;
54
- status: FeedbackStatus;
55
- voteCount: number;
56
- commentCount: number;
57
- isPinned: boolean;
58
- hasVoted: boolean;
59
- createdAt: number;
60
- updatedAt: number;
61
- completedAt?: number;
62
- tags: FeedbackTag[];
63
- organizationStatus: {
64
- id: string;
65
- name: string;
66
- color: string;
67
- } | null;
68
- author: FeedbackAuthor | null;
69
- }
70
- interface FeedbackDetail extends FeedbackItem {
71
- isSubscribed: boolean;
72
- }
73
- interface FeedbackTag {
74
- id: string;
75
- name: string;
76
- color: string;
77
- }
78
- interface FeedbackAuthor {
79
- name?: string;
80
- email?: string;
81
- avatar?: string;
82
- isExternal: boolean;
83
- }
84
- interface FeedbackListResponse {
85
- items: FeedbackItem[];
86
- total: number;
87
- hasMore: boolean;
88
- }
89
- interface FeedbackListParams {
90
- /** Filter by custom status ID */
91
- statusId?: string;
92
- /** Filter by status name */
93
- status?: FeedbackStatus;
94
- /** Search in title and description */
95
- search?: string;
96
- /** Sort order */
97
- sortBy?: "votes" | "newest" | "oldest" | "comments";
98
- /** Number of items to return (max 100) */
99
- limit?: number;
100
- /** Offset for pagination */
101
- offset?: number;
102
- }
103
- interface CreateFeedbackParams {
104
- title: string;
105
- description: string;
106
- }
107
- interface CreateFeedbackResponse {
108
- feedbackId: string;
109
- isApproved: boolean;
110
- }
111
- interface VoteResponse {
112
- voted: boolean;
113
- voteCount: number;
114
- }
115
- interface Comment {
116
- id: string;
117
- body: string;
118
- isOfficial: boolean;
119
- author: FeedbackAuthor | null;
120
- replies: CommentReply[];
121
- createdAt: number;
122
- updatedAt: number;
123
- }
124
- interface CommentReply {
125
- id: string;
126
- body: string;
127
- isOfficial: boolean;
128
- author: FeedbackAuthor | null;
129
- createdAt: number;
130
- updatedAt: number;
131
- }
132
- interface AddCommentParams {
133
- feedbackId: string;
134
- body: string;
135
- parentId?: string;
136
- }
137
- interface AddCommentResponse {
138
- commentId: string;
139
- }
140
- interface SubscribeResponse {
141
- subscribed: boolean;
142
- alreadySubscribed?: boolean;
143
- }
144
- interface UnsubscribeResponse {
145
- unsubscribed: boolean;
146
- wasNotSubscribed?: boolean;
147
- }
148
- interface Roadmap {
149
- lanes: RoadmapLane[];
150
- }
151
- interface RoadmapLane {
152
- id: string;
153
- name: string;
154
- color: string;
155
- items: RoadmapItem[];
156
- }
157
- interface RoadmapItem {
158
- id: string;
159
- title: string;
160
- status: FeedbackStatus;
161
- voteCount: number;
162
- }
163
- interface ChangelogEntry {
164
- id: string;
165
- title: string;
166
- description?: string;
167
- version?: string;
168
- publishedAt?: number;
169
- feedback: {
170
- id: string;
171
- title: string;
172
- }[];
173
- }
174
- declare class RefletError extends Error {
175
- readonly status: number;
176
- readonly code?: string;
177
- constructor(message: string, status: number, code?: string);
178
- }
179
- declare class RefletAuthError extends RefletError {
180
- constructor(message: string);
181
- }
182
- declare class RefletValidationError extends RefletError {
183
- constructor(message: string);
184
- }
185
- declare class RefletNotFoundError extends RefletError {
186
- constructor(message: string);
187
- }
188
-
189
- /**
190
- * Reflet SDK Client
191
- *
192
- * @example
193
- * ```ts
194
- * import { Reflet } from 'reflet-sdk';
195
- *
196
- * const reflet = new Reflet({
197
- * publicKey: 'fb_pub_xxx',
198
- * user: { id: 'user_123', email: 'user@example.com', name: 'John' }
199
- * });
200
- *
201
- * // List feedback
202
- * const { items } = await reflet.list({ status: 'open' });
203
- *
204
- * // Vote on feedback
205
- * await reflet.vote('feedback_id');
206
- *
207
- * // Submit new feedback
208
- * await reflet.create({ title: 'Great idea', description: 'Details...' });
209
- * ```
210
- */
211
- declare class Reflet {
212
- private readonly publicKey;
213
- private readonly baseUrl;
214
- private userToken;
215
- private user;
216
- constructor(config: RefletConfig);
217
- /**
218
- * Update the user identification
219
- */
220
- setUser(user: RefletUser | undefined): void;
221
- /**
222
- * Set the user token directly (for server-signed tokens)
223
- */
224
- setUserToken(token: string | undefined): void;
225
- /**
226
- * Get the organization configuration
227
- */
228
- getConfig(): Promise<OrganizationConfig>;
229
- /**
230
- * List feedback items with optional filtering
231
- */
232
- list(params?: FeedbackListParams): Promise<FeedbackListResponse>;
233
- /**
234
- * Get a single feedback item by ID
235
- */
236
- get(feedbackId: string): Promise<FeedbackDetail>;
237
- /**
238
- * Create new feedback
239
- * Requires user identification
240
- */
241
- create(params: CreateFeedbackParams): Promise<CreateFeedbackResponse>;
242
- /**
243
- * Toggle vote on feedback
244
- * Requires user identification
245
- */
246
- vote(feedbackId: string, type?: "upvote" | "downvote"): Promise<VoteResponse>;
247
- /**
248
- * Get comments for a feedback item
249
- */
250
- getComments(feedbackId: string, sortBy?: "newest" | "oldest"): Promise<Comment[]>;
251
- /**
252
- * Add a comment to feedback
253
- * Requires user identification
254
- */
255
- comment(params: AddCommentParams): Promise<AddCommentResponse>;
256
- /**
257
- * Subscribe to feedback updates
258
- * Requires user identification
259
- */
260
- subscribe(feedbackId: string): Promise<SubscribeResponse>;
261
- /**
262
- * Unsubscribe from feedback updates
263
- * Requires user identification
264
- */
265
- unsubscribe(feedbackId: string): Promise<UnsubscribeResponse>;
266
- /**
267
- * Get roadmap data
268
- */
269
- getRoadmap(): Promise<Roadmap>;
270
- /**
271
- * Get changelog entries
272
- */
273
- getChangelog(limit?: number): Promise<ChangelogEntry[]>;
274
- /**
275
- * Build request headers with authentication
276
- */
277
- private buildHeaders;
278
- /**
279
- * Parse JSON response text safely
280
- */
281
- private parseJsonSafely;
282
- /**
283
- * Throw appropriate error based on status code
284
- */
285
- private throwHttpError;
286
- /**
287
- * Make an authenticated API request
288
- */
289
- private request;
290
- /**
291
- * Generate a simple user token for client-side use
292
- * Note: For production, use server-side token signing
293
- */
294
- private generateUserToken;
295
- }
296
-
297
- export { type AddCommentParams, type AddCommentResponse, type ChangelogEntry, type Comment, type CommentReply, type CreateFeedbackParams, type CreateFeedbackResponse, type FeedbackAuthor, type FeedbackDetail, type FeedbackItem, type FeedbackListParams, type FeedbackListResponse, type FeedbackStatus, type FeedbackTag, type OrganizationConfig, type OrganizationSettings, type OrganizationStatus, Reflet, RefletAuthError, type RefletConfig, RefletError, RefletNotFoundError, type RefletUser, RefletValidationError, type Roadmap, type RoadmapItem, type RoadmapLane, type SubscribeResponse, type UnsubscribeResponse, type VoteResponse };
1
+ import { A as SubscribeResponse, C as RefletNotFoundError, D as RoadmapItem, E as Roadmap, M as VoteResponse, O as RoadmapLane, S as RefletError, T as RefletValidationError, _ as OrganizationConfig, a as CommentReply, b as RefletAuthError, d as FeedbackDetail, f as FeedbackItem, g as FeedbackTag, h as FeedbackStatus, i as Comment, j as UnsubscribeResponse, l as FeedbackAuthor, m as FeedbackListResponse, n as AddCommentResponse, o as CreateFeedbackParams, p as FeedbackListParams, r as ChangelogEntry, s as CreateFeedbackResponse, t as AddCommentParams, v as OrganizationSettings, w as RefletUser, x as RefletConfig, y as OrganizationStatus } from "./types-UKPPJGrA.js";
2
+ import { t as Reflet } from "./client-CSyPxFPK.js";
3
+ export { type AddCommentParams, type AddCommentResponse, type ChangelogEntry, type Comment, type CommentReply, type CreateFeedbackParams, type CreateFeedbackResponse, type FeedbackAuthor, type FeedbackDetail, type FeedbackItem, type FeedbackListParams, type FeedbackListResponse, type FeedbackStatus, type FeedbackTag, type OrganizationConfig, type OrganizationSettings, type OrganizationStatus, Reflet, RefletAuthError, type RefletConfig, RefletError, RefletNotFoundError, type RefletUser, RefletValidationError, type Roadmap, type RoadmapItem, type RoadmapLane, type SubscribeResponse, type UnsubscribeResponse, type VoteResponse };
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export { Reflet, RefletAuthError, RefletError, RefletNotFoundError, RefletValidationError } from './chunk-GD7FQQBT.js';
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
1
+ import { a as RefletValidationError, i as RefletNotFoundError, n as RefletAuthError, r as RefletError, t as Reflet } from "./client-BYuSKJw5.js";
2
+ export { Reflet, RefletAuthError, RefletError, RefletNotFoundError, RefletValidationError };
@@ -0,0 +1,85 @@
1
+ import { t as Reflet } from "./client-BYuSKJw5.js";
2
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/react-context.tsx
5
+ const RefletContext = createContext(null);
6
+ /**
7
+ * Provider component for Reflet SDK
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { RefletProvider } from 'reflet-sdk/react';
12
+ *
13
+ * function App() {
14
+ * return (
15
+ * <RefletProvider
16
+ * publicKey="fb_pub_xxx"
17
+ * user={{ id: 'user_123', email: 'user@example.com', name: 'John' }}
18
+ * >
19
+ * <YourApp />
20
+ * </RefletProvider>
21
+ * );
22
+ * }
23
+ * ```
24
+ */
25
+ function RefletProvider({ publicKey, baseUrl, user: initialUser, userToken, children }) {
26
+ const [user, setUser] = useState(initialUser);
27
+ const [isReady, setIsReady] = useState(false);
28
+ const client = useMemo(() => {
29
+ return new Reflet({
30
+ baseUrl,
31
+ publicKey,
32
+ user,
33
+ userToken
34
+ });
35
+ }, [
36
+ publicKey,
37
+ baseUrl,
38
+ user,
39
+ userToken
40
+ ]);
41
+ useEffect(() => {
42
+ if (userToken) client.setUserToken(userToken);
43
+ else client.setUser(user);
44
+ }, [
45
+ client,
46
+ user,
47
+ userToken
48
+ ]);
49
+ useEffect(() => {
50
+ setIsReady(true);
51
+ }, []);
52
+ const value = useMemo(() => ({
53
+ baseUrl,
54
+ client,
55
+ isReady,
56
+ publicKey,
57
+ setUser,
58
+ user,
59
+ userToken
60
+ }), [
61
+ client,
62
+ publicKey,
63
+ baseUrl,
64
+ isReady,
65
+ user,
66
+ userToken
67
+ ]);
68
+ return /* @__PURE__ */ jsx(RefletContext.Provider, {
69
+ value,
70
+ children
71
+ });
72
+ }
73
+ function useRefletContext() {
74
+ const context = useContext(RefletContext);
75
+ if (!context) throw new Error("useRefletContext must be used within a RefletProvider");
76
+ return context;
77
+ }
78
+ function useRefletClient() {
79
+ const { client } = useRefletContext();
80
+ return client;
81
+ }
82
+ //#endregion
83
+ export { useRefletContext as i, RefletProvider as n, useRefletClient as r, RefletContext as t };
84
+
85
+ //# sourceMappingURL=react-context-DZw_HHjj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-context-DZw_HHjj.js","names":[],"sources":["../src/react-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { Reflet } from \"./client\";\nimport type { RefletConfig, RefletUser } from \"./types\";\n\n// ============================================\n// Context Types\n// ============================================\n\nexport interface RefletContextValue {\n baseUrl?: string;\n client: Reflet;\n isReady: boolean;\n publicKey: string;\n setUser: (user: RefletUser | undefined) => void;\n user: RefletUser | undefined;\n userToken: string | undefined;\n}\n\n// ============================================\n// Context\n// ============================================\n\nexport const RefletContext = createContext<RefletContextValue | null>(null);\n\n// ============================================\n// Provider\n// ============================================\n\nexport interface RefletProviderProps {\n /** API base URL (optional, defaults to Reflet production API) */\n baseUrl?: string;\n /** Children */\n children: ReactNode;\n /** Your organization's public API key */\n publicKey: string;\n /** Initial user identification */\n user?: RefletUser;\n /** Pre-signed user token (alternative to user) */\n userToken?: string;\n}\n\n/**\n * Provider component for Reflet SDK\n *\n * @example\n * ```tsx\n * import { RefletProvider } from 'reflet-sdk/react';\n *\n * function App() {\n * return (\n * <RefletProvider\n * publicKey=\"fb_pub_xxx\"\n * user={{ id: 'user_123', email: 'user@example.com', name: 'John' }}\n * >\n * <YourApp />\n * </RefletProvider>\n * );\n * }\n * ```\n */\nexport function RefletProvider({\n publicKey,\n baseUrl,\n user: initialUser,\n userToken,\n children,\n}: RefletProviderProps) {\n const [user, setUser] = useState<RefletUser | undefined>(initialUser);\n const [isReady, setIsReady] = useState(false);\n\n const client = useMemo(() => {\n const config: RefletConfig = {\n baseUrl,\n publicKey,\n user,\n userToken,\n };\n return new Reflet(config);\n }, [publicKey, baseUrl, user, userToken]);\n\n // Update client when user changes\n useEffect(() => {\n if (userToken) {\n client.setUserToken(userToken);\n } else {\n client.setUser(user);\n }\n }, [client, user, userToken]);\n\n // Mark as ready after mount\n useEffect(() => {\n setIsReady(true);\n }, []);\n\n const value = useMemo(\n () => ({\n baseUrl,\n client,\n isReady,\n publicKey,\n setUser,\n user,\n userToken,\n }),\n [client, publicKey, baseUrl, isReady, user, userToken]\n );\n\n return (\n <RefletContext.Provider value={value}>{children}</RefletContext.Provider>\n );\n}\n\n// ============================================\n// Hook to access context\n// ============================================\n\nexport function useRefletContext(): RefletContextValue {\n const context = useContext(RefletContext);\n if (!context) {\n throw new Error(\"useRefletContext must be used within a RefletProvider\");\n }\n return context;\n}\n\nexport function useRefletClient(): Reflet {\n const { client } = useRefletContext();\n return client;\n}\n"],"mappings":";;;;AA6BA,MAAa,gBAAgB,cAAyC,IAAI;;;;;;;;;;;;;;;;;;;;AAsC1E,SAAgB,eAAe,EAC7B,WACA,SACA,MAAM,aACN,WACA,YACsB;CACtB,MAAM,CAAC,MAAM,WAAW,SAAiC,WAAW;CACpE,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAE5C,MAAM,SAAS,cAAc;EAO3B,OAAO,IAAI,OAAO;GALhB;GACA;GACA;GACA;EAEqB,CAAC;CAC1B,GAAG;EAAC;EAAW;EAAS;EAAM;CAAS,CAAC;CAGxC,gBAAgB;EACd,IAAI,WACF,OAAO,aAAa,SAAS;OAE7B,OAAO,QAAQ,IAAI;CAEvB,GAAG;EAAC;EAAQ;EAAM;CAAS,CAAC;CAG5B,gBAAgB;EACd,WAAW,IAAI;CACjB,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,eACL;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EAAC;EAAQ;EAAW;EAAS;EAAS;EAAM;CAAS,CACvD;CAEA,OACE,oBAAC,cAAc,UAAf;EAA+B;EAAQ;CAAiC,CAAA;AAE5E;AAMA,SAAgB,mBAAuC;CACrD,MAAM,UAAU,WAAW,aAAa;CACxC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,uDAAuD;CAEzE,OAAO;AACT;AAEA,SAAgB,kBAA0B;CACxC,MAAM,EAAE,WAAW,iBAAiB;CACpC,OAAO;AACT"}