uidex 0.6.0 → 0.8.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 (57) hide show
  1. package/README.md +3 -3
  2. package/dist/cli/cli.cjs +2502 -2253
  3. package/dist/cli/cli.cjs.map +1 -1
  4. package/dist/headless/index.cjs +86 -703
  5. package/dist/headless/index.cjs.map +1 -1
  6. package/dist/headless/index.d.cts +46 -22
  7. package/dist/headless/index.d.ts +46 -22
  8. package/dist/headless/index.js +86 -707
  9. package/dist/headless/index.js.map +1 -1
  10. package/dist/index.cjs +712 -4149
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +82 -366
  13. package/dist/index.d.ts +82 -366
  14. package/dist/index.js +708 -4156
  15. package/dist/index.js.map +1 -1
  16. package/dist/playwright/index.cjs +175 -0
  17. package/dist/playwright/index.cjs.map +1 -1
  18. package/dist/playwright/index.d.cts +2 -0
  19. package/dist/playwright/index.d.ts +2 -0
  20. package/dist/playwright/index.js +167 -0
  21. package/dist/playwright/index.js.map +1 -1
  22. package/dist/playwright/states-reporter.cjs +123 -0
  23. package/dist/playwright/states-reporter.cjs.map +1 -0
  24. package/dist/playwright/states-reporter.d.cts +46 -0
  25. package/dist/playwright/states-reporter.d.ts +46 -0
  26. package/dist/playwright/states-reporter.js +88 -0
  27. package/dist/playwright/states-reporter.js.map +1 -0
  28. package/dist/playwright/states.cjs +118 -0
  29. package/dist/playwright/states.cjs.map +1 -0
  30. package/dist/playwright/states.d.cts +120 -0
  31. package/dist/playwright/states.d.ts +120 -0
  32. package/dist/playwright/states.js +88 -0
  33. package/dist/playwright/states.js.map +1 -0
  34. package/dist/react/index.cjs +750 -4113
  35. package/dist/react/index.cjs.map +1 -1
  36. package/dist/react/index.d.cts +78 -278
  37. package/dist/react/index.d.ts +78 -278
  38. package/dist/react/index.js +748 -4135
  39. package/dist/react/index.js.map +1 -1
  40. package/dist/scan/index.cjs +2694 -1541
  41. package/dist/scan/index.cjs.map +1 -1
  42. package/dist/scan/index.d.cts +482 -19
  43. package/dist/scan/index.d.ts +482 -19
  44. package/dist/scan/index.js +2682 -1540
  45. package/dist/scan/index.js.map +1 -1
  46. package/package.json +14 -17
  47. package/templates/claude/SKILL.md +71 -0
  48. package/templates/claude/references/audit.md +43 -0
  49. package/templates/claude/{rules.md → references/conventions.md} +25 -28
  50. package/dist/cloud/index.cjs +0 -472
  51. package/dist/cloud/index.cjs.map +0 -1
  52. package/dist/cloud/index.d.cts +0 -82
  53. package/dist/cloud/index.d.ts +0 -82
  54. package/dist/cloud/index.js +0 -445
  55. package/dist/cloud/index.js.map +0 -1
  56. package/templates/claude/audit.md +0 -43
  57. /package/templates/claude/{api.md → references/api.md} +0 -0
@@ -1,82 +0,0 @@
1
- import { ReportPayload, ReportResult, IngestConfig, ReportListResponse, PinRecord, ArchiveReason } from '@uidex/api-client';
2
- export { ArchiveReason, IngestConfig, PinRecord, ReportListRecord, ReportListResponse, ReportPayload, ReportResult } from '@uidex/api-client';
3
-
4
- interface UserIdentity {
5
- id: string;
6
- name?: string;
7
- avatar?: string;
8
- }
9
-
10
- declare const DEFAULT_CLOUD_ENDPOINT = "https://app.uidex.dev";
11
- interface CloudOptions {
12
- projectKey: string;
13
- endpoint?: string;
14
- fetch?: typeof fetch;
15
- git?: {
16
- branch?: string;
17
- commit?: string;
18
- };
19
- }
20
- declare class CloudError extends Error {
21
- readonly status: number;
22
- readonly retryAfter?: number;
23
- readonly details?: unknown;
24
- constructor(message: string, options: {
25
- status: number;
26
- retryAfter?: number;
27
- details?: unknown;
28
- });
29
- }
30
- type RealtimePresenceUser = {
31
- userId: string;
32
- name: string;
33
- avatar: string | null;
34
- };
35
- type RealtimeChannelState = "connecting" | "connected" | "disconnected";
36
- interface RealtimeConnectOpts {
37
- user: UserIdentity;
38
- route: string;
39
- }
40
- interface RealtimeChannel {
41
- readonly state: RealtimeChannelState;
42
- connect(): void;
43
- disconnect(): void;
44
- joinRoute(route: string): void;
45
- onPresence(cb: (users: RealtimePresenceUser[]) => void): () => void;
46
- onPin(cb: (pin: PinRecord) => void): () => void;
47
- }
48
- interface CloudAdapter<TPayload = ReportPayload, TResult = ReportResult, TIntegrations = {
49
- getConfig(): Promise<IngestConfig>;
50
- getCachedConfig(): IngestConfig | null;
51
- }> {
52
- readonly reports: {
53
- submit(payload: TPayload): Promise<TResult>;
54
- list?(opts?: {
55
- page?: number;
56
- limit?: number;
57
- }): Promise<ReportListResponse>;
58
- };
59
- readonly integrations: TIntegrations;
60
- readonly realtime: {
61
- connect(opts: RealtimeConnectOpts): RealtimeChannel;
62
- };
63
- readonly pins: {
64
- list(params: {
65
- route?: string;
66
- entities?: string;
67
- }): Promise<PinRecord[]>;
68
- archive(reportId: string, reason?: ArchiveReason): Promise<void>;
69
- };
70
- }
71
-
72
- declare function cloud(options: CloudOptions): CloudAdapter;
73
-
74
- type RealtimeChannelOptions = {
75
- /** Builds the WebSocket URL on each (re)connect attempt. Allows the caller to refresh `route` query params. */
76
- buildUrl: () => string;
77
- /** Optional WebSocket constructor override (testing). Defaults to `globalThis.WebSocket`. */
78
- WebSocketImpl?: typeof WebSocket;
79
- };
80
- declare function createRealtimeChannel(options: RealtimeChannelOptions): RealtimeChannel;
81
-
82
- export { type CloudAdapter, CloudError, type CloudOptions, DEFAULT_CLOUD_ENDPOINT, type RealtimeChannel, type RealtimeChannelState, type RealtimeConnectOpts, type RealtimePresenceUser, cloud, createRealtimeChannel };
@@ -1,82 +0,0 @@
1
- import { ReportPayload, ReportResult, IngestConfig, ReportListResponse, PinRecord, ArchiveReason } from '@uidex/api-client';
2
- export { ArchiveReason, IngestConfig, PinRecord, ReportListRecord, ReportListResponse, ReportPayload, ReportResult } from '@uidex/api-client';
3
-
4
- interface UserIdentity {
5
- id: string;
6
- name?: string;
7
- avatar?: string;
8
- }
9
-
10
- declare const DEFAULT_CLOUD_ENDPOINT = "https://app.uidex.dev";
11
- interface CloudOptions {
12
- projectKey: string;
13
- endpoint?: string;
14
- fetch?: typeof fetch;
15
- git?: {
16
- branch?: string;
17
- commit?: string;
18
- };
19
- }
20
- declare class CloudError extends Error {
21
- readonly status: number;
22
- readonly retryAfter?: number;
23
- readonly details?: unknown;
24
- constructor(message: string, options: {
25
- status: number;
26
- retryAfter?: number;
27
- details?: unknown;
28
- });
29
- }
30
- type RealtimePresenceUser = {
31
- userId: string;
32
- name: string;
33
- avatar: string | null;
34
- };
35
- type RealtimeChannelState = "connecting" | "connected" | "disconnected";
36
- interface RealtimeConnectOpts {
37
- user: UserIdentity;
38
- route: string;
39
- }
40
- interface RealtimeChannel {
41
- readonly state: RealtimeChannelState;
42
- connect(): void;
43
- disconnect(): void;
44
- joinRoute(route: string): void;
45
- onPresence(cb: (users: RealtimePresenceUser[]) => void): () => void;
46
- onPin(cb: (pin: PinRecord) => void): () => void;
47
- }
48
- interface CloudAdapter<TPayload = ReportPayload, TResult = ReportResult, TIntegrations = {
49
- getConfig(): Promise<IngestConfig>;
50
- getCachedConfig(): IngestConfig | null;
51
- }> {
52
- readonly reports: {
53
- submit(payload: TPayload): Promise<TResult>;
54
- list?(opts?: {
55
- page?: number;
56
- limit?: number;
57
- }): Promise<ReportListResponse>;
58
- };
59
- readonly integrations: TIntegrations;
60
- readonly realtime: {
61
- connect(opts: RealtimeConnectOpts): RealtimeChannel;
62
- };
63
- readonly pins: {
64
- list(params: {
65
- route?: string;
66
- entities?: string;
67
- }): Promise<PinRecord[]>;
68
- archive(reportId: string, reason?: ArchiveReason): Promise<void>;
69
- };
70
- }
71
-
72
- declare function cloud(options: CloudOptions): CloudAdapter;
73
-
74
- type RealtimeChannelOptions = {
75
- /** Builds the WebSocket URL on each (re)connect attempt. Allows the caller to refresh `route` query params. */
76
- buildUrl: () => string;
77
- /** Optional WebSocket constructor override (testing). Defaults to `globalThis.WebSocket`. */
78
- WebSocketImpl?: typeof WebSocket;
79
- };
80
- declare function createRealtimeChannel(options: RealtimeChannelOptions): RealtimeChannel;
81
-
82
- export { type CloudAdapter, CloudError, type CloudOptions, DEFAULT_CLOUD_ENDPOINT, type RealtimeChannel, type RealtimeChannelState, type RealtimeConnectOpts, type RealtimePresenceUser, cloud, createRealtimeChannel };
@@ -1,445 +0,0 @@
1
- // src/cloud/client.ts
2
- import { createClient as createClient2, createConfig as createConfig2 } from "@hey-api/client-fetch";
3
-
4
- // ../api-client/src/client.gen.ts
5
- import {
6
- createClient,
7
- createConfig
8
- } from "@hey-api/client-fetch";
9
- var client = createClient(
10
- createConfig({
11
- baseUrl: "https://app.uidex.dev"
12
- })
13
- );
14
-
15
- // ../api-client/src/sdk.gen.ts
16
- var submitReport = (options) => {
17
- return (options.client ?? client).post({
18
- security: [
19
- {
20
- scheme: "bearer",
21
- type: "http"
22
- }
23
- ],
24
- url: "/api/ingest",
25
- ...options,
26
- headers: {
27
- "Content-Type": "application/json",
28
- ...options?.headers
29
- }
30
- });
31
- };
32
- var getIngestConfig = (options) => {
33
- return (options?.client ?? client).get({
34
- security: [
35
- {
36
- scheme: "bearer",
37
- type: "http"
38
- }
39
- ],
40
- url: "/api/ingest/config",
41
- ...options
42
- });
43
- };
44
- var listIngestReports = (options) => {
45
- return (options?.client ?? client).get({
46
- security: [
47
- {
48
- scheme: "bearer",
49
- type: "http"
50
- }
51
- ],
52
- url: "/api/ingest/reports",
53
- ...options
54
- });
55
- };
56
- var listPins = (options) => {
57
- return (options?.client ?? client).get({
58
- security: [
59
- {
60
- scheme: "bearer",
61
- type: "http"
62
- }
63
- ],
64
- url: "/api/ingest/pins",
65
- ...options
66
- });
67
- };
68
- var archivePin = (options) => {
69
- return (options.client ?? client).post({
70
- security: [
71
- {
72
- scheme: "bearer",
73
- type: "http"
74
- }
75
- ],
76
- url: "/api/ingest/pins/archive",
77
- ...options,
78
- headers: {
79
- "Content-Type": "application/json",
80
- ...options?.headers
81
- }
82
- });
83
- };
84
-
85
- // src/cloud/realtime.ts
86
- var RECONNECT_INITIAL_MS = 1e3;
87
- var RECONNECT_MAX_MS = 3e4;
88
- var CLOSE_CODE_AUTH_FAILED = 4001;
89
- function emit(listeners, value) {
90
- for (const cb of listeners) {
91
- try {
92
- cb(value);
93
- } catch {
94
- }
95
- }
96
- }
97
- function resolveWebSocket(override) {
98
- if (override) return override;
99
- if (typeof globalThis !== "undefined" && typeof globalThis.WebSocket === "function") {
100
- return globalThis.WebSocket;
101
- }
102
- throw new Error(
103
- "uidex/cloud: global WebSocket is not available; pass a `WebSocketImpl` override"
104
- );
105
- }
106
- function createRealtimeChannel(options) {
107
- const WS = resolveWebSocket(options.WebSocketImpl);
108
- const presenceListeners = /* @__PURE__ */ new Set();
109
- const pinListeners = /* @__PURE__ */ new Set();
110
- let ws = null;
111
- let state = "disconnected";
112
- let disposed = false;
113
- let reconnectAttempts = 0;
114
- let reconnectTimer = null;
115
- function clearReconnectTimer() {
116
- if (reconnectTimer !== null) {
117
- clearTimeout(reconnectTimer);
118
- reconnectTimer = null;
119
- }
120
- }
121
- function scheduleReconnect() {
122
- if (disposed) return;
123
- const delay = Math.min(
124
- RECONNECT_INITIAL_MS * 2 ** reconnectAttempts,
125
- RECONNECT_MAX_MS
126
- );
127
- reconnectAttempts += 1;
128
- state = "connecting";
129
- clearReconnectTimer();
130
- reconnectTimer = setTimeout(() => {
131
- reconnectTimer = null;
132
- openSocket();
133
- }, delay);
134
- }
135
- function handleMessage(event) {
136
- if (typeof event.data !== "string") return;
137
- let parsed;
138
- try {
139
- parsed = JSON.parse(event.data);
140
- } catch {
141
- return;
142
- }
143
- if (!parsed || typeof parsed !== "object") return;
144
- const msg = parsed;
145
- if (msg.type === "presence") {
146
- const p = msg;
147
- if (!Array.isArray(p.users)) return;
148
- const users = [];
149
- for (const raw of p.users) {
150
- if (!raw || typeof raw !== "object") continue;
151
- const u = raw;
152
- if (typeof u.userId !== "string" || typeof u.name !== "string") continue;
153
- users.push({
154
- userId: u.userId,
155
- name: u.name,
156
- avatar: typeof u.avatar === "string" ? u.avatar : null
157
- });
158
- }
159
- emit(presenceListeners, users);
160
- return;
161
- }
162
- if (msg.type === "pin") {
163
- const p = msg;
164
- if (typeof p.feedbackId !== "string" || !p.elementRef || typeof p.elementRef !== "object" || typeof p.elementRef.kind !== "string" || typeof p.elementRef.id !== "string" || !p.author || typeof p.author !== "object" || typeof p.body !== "string" || typeof p.reportType !== "string" || typeof p.reportSeverity !== "string" || typeof p.createdAt !== "string") {
165
- return;
166
- }
167
- const author = p.author;
168
- const elRef = p.elementRef;
169
- const pin = {
170
- id: p.feedbackId,
171
- entity: `${elRef.kind}:${elRef.id}`,
172
- reporter: {
173
- name: typeof author.name === "string" ? author.name : void 0,
174
- email: typeof author.email === "string" ? author.email : void 0
175
- },
176
- body: p.body,
177
- type: p.reportType,
178
- severity: p.reportSeverity,
179
- status: "open",
180
- createdAt: p.createdAt,
181
- url: ""
182
- };
183
- emit(pinListeners, pin);
184
- return;
185
- }
186
- }
187
- function openSocket() {
188
- if (disposed) return;
189
- state = "connecting";
190
- let url;
191
- try {
192
- url = options.buildUrl();
193
- } catch {
194
- state = "disconnected";
195
- return;
196
- }
197
- let socket;
198
- try {
199
- socket = new WS(url);
200
- } catch {
201
- scheduleReconnect();
202
- return;
203
- }
204
- ws = socket;
205
- socket.addEventListener("open", () => {
206
- if (ws !== socket) return;
207
- state = "connected";
208
- reconnectAttempts = 0;
209
- });
210
- socket.addEventListener("message", (event) => {
211
- if (ws !== socket) return;
212
- handleMessage(event);
213
- });
214
- socket.addEventListener("close", (event) => {
215
- if (ws !== socket) return;
216
- ws = null;
217
- const code = event.code;
218
- if (disposed || code === CLOSE_CODE_AUTH_FAILED) {
219
- state = "disconnected";
220
- return;
221
- }
222
- scheduleReconnect();
223
- });
224
- socket.addEventListener("error", () => {
225
- });
226
- }
227
- function connect() {
228
- if (disposed) {
229
- disposed = false;
230
- }
231
- if (ws) return;
232
- if (state === "connecting") return;
233
- reconnectAttempts = 0;
234
- openSocket();
235
- }
236
- function disconnect() {
237
- disposed = true;
238
- clearReconnectTimer();
239
- state = "disconnected";
240
- if (ws) {
241
- try {
242
- ws.close(1e3);
243
- } catch {
244
- }
245
- ws = null;
246
- }
247
- }
248
- function joinRoute(route) {
249
- emit(presenceListeners, []);
250
- if (ws && ws.readyState === WS.OPEN) {
251
- try {
252
- ws.send(JSON.stringify({ type: "join", route }));
253
- } catch {
254
- }
255
- }
256
- }
257
- function onPresence(cb) {
258
- presenceListeners.add(cb);
259
- return () => {
260
- presenceListeners.delete(cb);
261
- };
262
- }
263
- function onPin(cb) {
264
- pinListeners.add(cb);
265
- return () => {
266
- pinListeners.delete(cb);
267
- };
268
- }
269
- return {
270
- get state() {
271
- return state;
272
- },
273
- connect,
274
- disconnect,
275
- joinRoute,
276
- onPresence,
277
- onPin
278
- };
279
- }
280
-
281
- // src/cloud/types.ts
282
- var DEFAULT_CLOUD_ENDPOINT = "https://app.uidex.dev";
283
- var CloudError = class extends Error {
284
- status;
285
- retryAfter;
286
- details;
287
- constructor(message, options) {
288
- super(message);
289
- this.name = "CloudError";
290
- this.status = options.status;
291
- this.retryAfter = options.retryAfter;
292
- this.details = options.details;
293
- }
294
- };
295
-
296
- // src/cloud/client.ts
297
- function trimEndpoint(endpoint) {
298
- return endpoint.endsWith("/") ? endpoint.slice(0, -1) : endpoint;
299
- }
300
- function unwrap(result) {
301
- if (result.error !== void 0 || !result.data) {
302
- const status = result.response.status;
303
- const retryAfter = status === 429 ? parseRetryAfter(result.response.headers.get("Retry-After")) : void 0;
304
- const msg = result.error && typeof result.error === "object" && "error" in result.error && typeof result.error.error === "string" ? result.error.error : `Request failed (${status})`;
305
- throw new CloudError(msg, { status, retryAfter, details: result.error });
306
- }
307
- return result.data;
308
- }
309
- function parseRetryAfter(header) {
310
- if (!header) return void 0;
311
- const seconds = Number(header);
312
- if (Number.isFinite(seconds) && seconds >= 0) return seconds;
313
- const date = Date.parse(header);
314
- if (Number.isFinite(date)) {
315
- const delta = Math.ceil((date - Date.now()) / 1e3);
316
- return delta > 0 ? delta : 0;
317
- }
318
- return void 0;
319
- }
320
- function cloud(options) {
321
- let cachedConfig = null;
322
- let resolvedConfig = null;
323
- const projectKey = options.projectKey;
324
- if (!projectKey) {
325
- throw new Error("uidex/cloud: `projectKey` is required");
326
- }
327
- const endpoint = trimEndpoint(options.endpoint ?? DEFAULT_CLOUD_ENDPOINT);
328
- const git = options.git;
329
- const apiClient = createClient2(
330
- createConfig2({
331
- baseUrl: endpoint,
332
- ...options.fetch ? { fetch: options.fetch } : {},
333
- headers: { Authorization: `Bearer ${projectKey}` }
334
- })
335
- );
336
- async function submit(payload) {
337
- const enriched = git?.branch || git?.commit ? {
338
- ...payload,
339
- context: {
340
- ...payload.context,
341
- git: payload.context?.git ?? {
342
- branch: git.branch,
343
- commit: git.commit
344
- }
345
- }
346
- } : payload;
347
- const result = await submitReport({
348
- client: apiClient,
349
- body: enriched
350
- });
351
- return unwrap(result);
352
- }
353
- async function fetchConfig() {
354
- const result = await getIngestConfig({ client: apiClient });
355
- return unwrap(result);
356
- }
357
- function startFetch() {
358
- const promise = fetchConfig();
359
- promise.then(
360
- (config) => {
361
- resolvedConfig = config;
362
- },
363
- () => {
364
- }
365
- );
366
- return promise;
367
- }
368
- cachedConfig = startFetch();
369
- function getConfig() {
370
- return cachedConfig ?? (cachedConfig = startFetch());
371
- }
372
- function getCachedConfig() {
373
- return resolvedConfig;
374
- }
375
- function realtimeUrl(route, user) {
376
- const httpToWs = endpoint.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
377
- const params = new URLSearchParams();
378
- params.set("key", projectKey);
379
- params.set("route", route);
380
- params.set("userId", user.id);
381
- if (user.name) params.set("name", user.name);
382
- if (user.avatar) params.set("avatar", user.avatar);
383
- return `${httpToWs}/ws?${params.toString()}`;
384
- }
385
- function connectRealtime(opts) {
386
- if (!opts || !opts.user || typeof opts.user.id !== "string") {
387
- throw new TypeError("uidex/cloud: realtime.connect requires `user.id`");
388
- }
389
- let currentRoute = opts.route;
390
- const channel = createRealtimeChannel({
391
- buildUrl: () => realtimeUrl(currentRoute, opts.user)
392
- });
393
- const originalJoinRoute = channel.joinRoute;
394
- const wrapped = {
395
- get state() {
396
- return channel.state;
397
- },
398
- connect: () => channel.connect(),
399
- disconnect: () => channel.disconnect(),
400
- joinRoute: (route) => {
401
- currentRoute = route;
402
- originalJoinRoute(route);
403
- },
404
- onPresence: (cb) => channel.onPresence(cb),
405
- onPin: (cb) => channel.onPin(cb)
406
- };
407
- channel.connect();
408
- return wrapped;
409
- }
410
- async function listPins2(params) {
411
- const result = await listPins({
412
- client: apiClient,
413
- query: params
414
- });
415
- const data = unwrap(result);
416
- return data.pins;
417
- }
418
- async function archivePin2(reportId, reason) {
419
- const result = await archivePin({
420
- client: apiClient,
421
- body: { reportId, ...reason ? { reason } : {} }
422
- });
423
- unwrap(result);
424
- }
425
- async function listReports(opts) {
426
- const result = await listIngestReports({
427
- client: apiClient,
428
- query: opts
429
- });
430
- return unwrap(result);
431
- }
432
- return {
433
- reports: { submit, list: listReports },
434
- integrations: { getConfig, getCachedConfig },
435
- realtime: { connect: connectRealtime },
436
- pins: { list: listPins2, archive: archivePin2 }
437
- };
438
- }
439
- export {
440
- CloudError,
441
- DEFAULT_CLOUD_ENDPOINT,
442
- cloud,
443
- createRealtimeChannel
444
- };
445
- //# sourceMappingURL=index.js.map