@ploykit/ui 0.1.1 → 0.4.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 (145) hide show
  1. package/README.md +183 -23
  2. package/dist/AppProviders.d.ts +15 -0
  3. package/dist/AppProviders.js +15 -0
  4. package/dist/components/ConfirmDialog.js +8 -2
  5. package/dist/components/CronInput.js +2 -2
  6. package/dist/components/DataTable.d.ts +12 -3
  7. package/dist/components/DataTable.js +7 -3
  8. package/dist/components/ErrorBoundary.js +1 -1
  9. package/dist/components/ImpersonationBanner.js +1 -1
  10. package/dist/components/NotificationBell.js +5 -5
  11. package/dist/components/OnboardingChecklist.js +3 -3
  12. package/dist/components/Page.js +1 -1
  13. package/dist/components/ReauthDialog.d.ts +15 -0
  14. package/dist/components/ReauthDialog.js +42 -0
  15. package/dist/components/SecretModal.d.ts +8 -1
  16. package/dist/components/SecretModal.js +6 -3
  17. package/dist/components/SettingsCard.js +2 -2
  18. package/dist/components/SiteBannerLayer.js +1 -1
  19. package/dist/components/StatusBadge.d.ts +4 -0
  20. package/dist/components/StatusBadge.js +7 -0
  21. package/dist/components/UserMenu.js +2 -2
  22. package/dist/components/WorkspaceSwitcher.js +4 -4
  23. package/dist/components/ui/alert-dialog.d.ts +2 -2
  24. package/dist/components/ui/alert-dialog.js +10 -9
  25. package/dist/components/ui/avatar.js +3 -2
  26. package/dist/components/ui/badge.d.ts +7 -0
  27. package/dist/components/ui/badge.js +33 -0
  28. package/dist/components/ui/breadcrumb.js +7 -7
  29. package/dist/components/ui/button.d.ts +8 -0
  30. package/dist/components/ui/button.js +34 -0
  31. package/dist/components/ui/card.d.ts +2 -4
  32. package/dist/components/ui/card.js +7 -7
  33. package/dist/components/ui/checkbox.js +3 -2
  34. package/dist/components/ui/dialog.d.ts +22 -14
  35. package/dist/components/ui/dialog.js +40 -25
  36. package/dist/components/ui/dropdown-menu.js +50 -0
  37. package/dist/components/ui/empty.d.ts +7 -9
  38. package/dist/components/ui/empty.js +6 -9
  39. package/dist/components/ui/field.js +10 -9
  40. package/dist/components/ui/input.d.ts +3 -0
  41. package/dist/components/ui/input.js +7 -0
  42. package/dist/components/ui/popover.js +3 -2
  43. package/dist/components/ui/progress.js +2 -1
  44. package/dist/components/ui/select.d.ts +20 -1
  45. package/dist/components/ui/select.js +28 -7
  46. package/dist/components/ui/separator.js +1 -0
  47. package/dist/components/ui/sheet.d.ts +9 -1
  48. package/dist/components/ui/sheet.js +11 -4
  49. package/dist/components/ui/sidebar.d.ts +2 -2
  50. package/dist/components/ui/sidebar.js +25 -34
  51. package/dist/components/ui/skeleton.d.ts +1 -2
  52. package/dist/components/ui/switch.js +1 -1
  53. package/dist/components/ui/tabs.js +3 -3
  54. package/dist/components/ui/textarea.d.ts +9 -0
  55. package/dist/components/ui/textarea.js +12 -0
  56. package/dist/components/ui/tooltip.js +1 -1
  57. package/dist/index.d.ts +10 -40
  58. package/dist/index.js +10 -26
  59. package/dist/layouts/AppShell.d.ts +1 -1
  60. package/dist/layouts/AppShell.js +23 -1
  61. package/dist/layouts/SettingsShell.d.ts +1 -1
  62. package/dist/layouts/SettingsShell.js +3 -3
  63. package/dist/pages/LandingPage.js +1 -1
  64. package/dist/pages/LoginPage.js +7 -7
  65. package/dist/pages/account/NotificationPreferencesPage.js +2 -2
  66. package/dist/pages/account/ProfileSettingsPage.js +7 -7
  67. package/dist/pages/account/SecuritySettingsPage.js +8 -8
  68. package/dist/pages/account/TokensPage.js +4 -4
  69. package/dist/pages/admin/AdminSettingsPage.js +5 -5
  70. package/dist/pages/admin/AdminShell.js +2 -2
  71. package/dist/pages/admin/AuditPage.js +3 -3
  72. package/dist/pages/admin/OrdersPage.js +4 -3
  73. package/dist/pages/admin/OverviewPage.js +4 -4
  74. package/dist/pages/admin/SSOPage.js +3 -3
  75. package/dist/pages/admin/UserDetailPage.js +6 -5
  76. package/dist/pages/admin/UsersPage.js +7 -6
  77. package/dist/pages/admin/WebhookDeliveriesPage.js +4 -3
  78. package/dist/pages/admin/WorkspaceDetailPage.js +5 -5
  79. package/dist/pages/admin/WorkspacesPage.js +4 -4
  80. package/dist/pages/admin/shared.js +1 -1
  81. package/dist/pages/auth/ForgotPasswordPage.js +3 -3
  82. package/dist/pages/auth/InviteAcceptPage.js +4 -4
  83. package/dist/pages/auth/RegisterPage.js +6 -6
  84. package/dist/pages/auth/ResetPasswordPage.js +4 -4
  85. package/dist/pages/auth/VerifyEmailPage.js +4 -4
  86. package/dist/pages/workspace/BillingPage.js +8 -7
  87. package/dist/pages/workspace/BillingSuccessPage.js +3 -3
  88. package/dist/pages/workspace/MembersPage.js +7 -6
  89. package/dist/pages/workspace/RolePermissionsPage.d.ts +3 -0
  90. package/dist/pages/workspace/RolePermissionsPage.js +118 -0
  91. package/dist/pages/workspace/SchedulesPage.js +5 -5
  92. package/dist/pages/workspace/UsagePage.d.ts +1 -1
  93. package/dist/pages/workspace/UsagePage.js +2 -2
  94. package/dist/pages/workspace/WebhooksPage.js +9 -9
  95. package/dist/pages/workspace/WorkspaceAuditPage.js +3 -3
  96. package/dist/pages/workspace/WorkspaceGeneralPage.js +7 -7
  97. package/package.json +9 -5
  98. package/dist/components/ui/Badge.d.ts +0 -13
  99. package/dist/components/ui/Badge.js +0 -21
  100. package/dist/components/ui/Button.d.ts +0 -10
  101. package/dist/components/ui/Button.js +0 -33
  102. package/dist/components/ui/Input.d.ts +0 -3
  103. package/dist/components/ui/Input.js +0 -10
  104. package/dist/components/ui/menu.js +0 -50
  105. package/dist/hooks/useApi.d.ts +0 -10
  106. package/dist/hooks/useApi.js +0 -11
  107. package/dist/hooks/useAudit.d.ts +0 -39
  108. package/dist/hooks/useAudit.js +0 -55
  109. package/dist/hooks/useAuth.d.ts +0 -1
  110. package/dist/hooks/useAuth.js +0 -4
  111. package/dist/hooks/useBilling.d.ts +0 -44
  112. package/dist/hooks/useBilling.js +0 -64
  113. package/dist/hooks/useLogin.d.ts +0 -10
  114. package/dist/hooks/useLogin.js +0 -39
  115. package/dist/hooks/useMembers.d.ts +0 -125
  116. package/dist/hooks/useMembers.js +0 -127
  117. package/dist/hooks/useNotificationPrefs.d.ts +0 -20
  118. package/dist/hooks/useNotificationPrefs.js +0 -42
  119. package/dist/hooks/usePasswordReset.d.ts +0 -5
  120. package/dist/hooks/usePasswordReset.js +0 -12
  121. package/dist/hooks/useSEO.d.ts +0 -6
  122. package/dist/hooks/useSEO.js +0 -14
  123. package/dist/hooks/useSessions.d.ts +0 -20
  124. package/dist/hooks/useSessions.js +0 -38
  125. package/dist/hooks/useSiteConfig.d.ts +0 -12
  126. package/dist/hooks/useSiteConfig.js +0 -11
  127. package/dist/hooks/useTokens.d.ts +0 -36
  128. package/dist/hooks/useTokens.js +0 -35
  129. package/dist/hooks/useUsage.d.ts +0 -20
  130. package/dist/hooks/useUsage.js +0 -21
  131. package/dist/hooks/useWorkspace.d.ts +0 -26
  132. package/dist/hooks/useWorkspace.js +0 -32
  133. package/dist/hooks/useZodForm.d.ts +0 -6
  134. package/dist/hooks/useZodForm.js +0 -6
  135. package/dist/hooks/ws.d.ts +0 -4
  136. package/dist/hooks/ws.js +0 -21
  137. package/dist/lib/perm.d.ts +0 -2
  138. package/dist/lib/perm.js +0 -7
  139. package/dist/lib/ws-query-bridge.d.ts +0 -7
  140. package/dist/lib/ws-query-bridge.js +0 -35
  141. package/dist/provider/PloykitProvider.d.ts +0 -50
  142. package/dist/provider/PloykitProvider.js +0 -240
  143. package/dist/realtime.d.ts +0 -3
  144. package/dist/realtime.js +0 -11
  145. /package/dist/components/ui/{menu.d.ts → dropdown-menu.d.ts} +0 -0
@@ -1,20 +0,0 @@
1
- export interface NotificationPreference {
2
- notification_type: string;
3
- email_enabled: boolean;
4
- in_app_enabled: boolean;
5
- updated_at: string;
6
- }
7
- export declare function useNotificationPrefs(): {
8
- prefs: NotificationPreference[];
9
- loading: boolean;
10
- error: Error | null;
11
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NotificationPreference[], Error>>;
12
- };
13
- export declare function useSetNotificationPref(): {
14
- setPref: (type: string, channels: {
15
- email_enabled?: boolean;
16
- in_app_enabled?: boolean;
17
- }) => Promise<NotificationPreference>;
18
- loading: boolean;
19
- error: Error | null;
20
- };
@@ -1,42 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
- import { api } from '@ploykit/client';
4
- import { queryKeys } from '../provider/PloykitProvider';
5
- export function useNotificationPrefs() {
6
- const q = useQuery({
7
- queryKey: queryKeys.notificationPrefs,
8
- queryFn: async () => {
9
- const data = await api.get('/api/notification-preferences');
10
- return data?.items ?? [];
11
- },
12
- });
13
- return { prefs: q.data ?? [], loading: q.isPending, error: q.error, refetch: q.refetch };
14
- }
15
- export function useSetNotificationPref() {
16
- const qc = useQueryClient();
17
- const m = useMutation({
18
- mutationFn: (v) => api.put(`/api/notification-preferences/${encodeURIComponent(v.type)}`, { email_enabled: v.email_enabled, in_app_enabled: v.in_app_enabled }),
19
- onMutate: async (v) => {
20
- await qc.cancelQueries({ queryKey: queryKeys.notificationPrefs });
21
- const prev = qc.getQueryData(queryKeys.notificationPrefs) ?? [];
22
- const existing = prev.find((p) => p.notification_type === v.type);
23
- const next = {
24
- notification_type: v.type,
25
- email_enabled: v.email_enabled ?? existing?.email_enabled ?? true,
26
- in_app_enabled: v.in_app_enabled ?? existing?.in_app_enabled ?? true,
27
- updated_at: new Date().toISOString(),
28
- };
29
- qc.setQueryData(queryKeys.notificationPrefs, existing
30
- ? prev.map((p) => (p.notification_type === v.type ? next : p))
31
- : [...prev, next]);
32
- return { prev };
33
- },
34
- onError: (_err, _v, ctx) => {
35
- if (ctx?.prev)
36
- qc.setQueryData(queryKeys.notificationPrefs, ctx.prev);
37
- },
38
- onSettled: () => qc.invalidateQueries({ queryKey: queryKeys.notificationPrefs }),
39
- });
40
- const setPref = useCallback((type, channels) => m.mutateAsync({ type, ...channels }), [m]);
41
- return { setPref, loading: m.isPending, error: m.error };
42
- }
@@ -1,5 +0,0 @@
1
- export interface UsePasswordResetResult {
2
- requestReset(email: string): Promise<void>;
3
- reset(email: string, token: string, newPassword: string): Promise<void>;
4
- }
5
- export declare function usePasswordReset(): UsePasswordResetResult;
@@ -1,12 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useApi } from './useApi';
3
- export function usePasswordReset() {
4
- const api = useApi();
5
- const requestReset = useCallback(async (email) => {
6
- await api.post('/auth/forgot-password', { email });
7
- }, [api]);
8
- const reset = useCallback(async (email, token, newPassword) => {
9
- await api.post('/auth/reset-password', { email, token, new_password: newPassword });
10
- }, [api]);
11
- return { requestReset, reset };
12
- }
@@ -1,6 +0,0 @@
1
- export interface SeoMeta {
2
- title?: string;
3
- description?: string;
4
- ogImage?: string;
5
- }
6
- export declare function useSEO(meta: SeoMeta): void;
@@ -1,14 +0,0 @@
1
- import { emitDirective } from '@ploykit/runtime';
2
- export function useSEO(meta) {
3
- const entries = [];
4
- if (meta.title)
5
- entries.push({ tag: 'title', children: meta.title });
6
- if (meta.description) {
7
- entries.push({ tag: 'meta', attrs: { name: 'description', content: meta.description } });
8
- }
9
- if (meta.ogImage) {
10
- entries.push({ tag: 'meta', attrs: { property: 'og:image', content: meta.ogImage } });
11
- entries.push({ tag: 'meta', attrs: { name: 'twitter:card', content: 'summary_large_image' } });
12
- }
13
- emitDirective('head', entries);
14
- }
@@ -1,20 +0,0 @@
1
- import type { components } from '@ploykit/client';
2
- export type SessionInfo = components['schemas']['SessionInfo'] & {
3
- current?: boolean;
4
- };
5
- export declare function useSessions(): {
6
- sessions: SessionInfo[];
7
- loading: boolean;
8
- error: Error | null;
9
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<SessionInfo[], Error>>;
10
- };
11
- export declare function useRevokeSession(): {
12
- revoke: (id: string) => Promise<void>;
13
- loading: boolean;
14
- error: Error | null;
15
- };
16
- export declare function useRevokeAllSessions(): {
17
- revokeAll: () => Promise<void>;
18
- loading: boolean;
19
- error: Error | null;
20
- };
@@ -1,38 +0,0 @@
1
- import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
- import { api } from '@ploykit/client';
3
- import { queryKeys } from '../provider/PloykitProvider';
4
- function normalize(data) {
5
- const list = Array.isArray(data) ? data : data?.items;
6
- return Array.isArray(list) ? list : [];
7
- }
8
- export function useSessions() {
9
- const q = useQuery({
10
- queryKey: queryKeys.sessions,
11
- queryFn: async () => normalize(await api.get('/auth/sessions')),
12
- });
13
- return { sessions: q.data ?? [], loading: q.isPending, error: q.error, refetch: q.refetch };
14
- }
15
- export function useRevokeSession() {
16
- const qc = useQueryClient();
17
- const m = useMutation({
18
- mutationFn: (id) => api.delete(`/auth/sessions/${id}`),
19
- onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.sessions }),
20
- });
21
- return {
22
- revoke: (id) => m.mutateAsync(id),
23
- loading: m.isPending,
24
- error: m.error,
25
- };
26
- }
27
- export function useRevokeAllSessions() {
28
- const qc = useQueryClient();
29
- const m = useMutation({
30
- mutationFn: () => api.delete('/auth/sessions'),
31
- onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.sessions }),
32
- });
33
- return {
34
- revokeAll: () => m.mutateAsync(),
35
- loading: m.isPending,
36
- error: m.error,
37
- };
38
- }
@@ -1,12 +0,0 @@
1
- export declare const SITE_CONFIG_QUERY_KEY: readonly ["site-config"];
2
- export interface SiteConfig {
3
- oauth_providers?: string[];
4
- billing_channels?: string[];
5
- banner_text?: string;
6
- banner_kind?: string;
7
- maintenance_mode?: string;
8
- allow_signup?: string;
9
- allowed_domains?: string;
10
- mail_mode?: string;
11
- }
12
- export declare function useSiteConfig(): import("@tanstack/react-query").UseQueryResult<SiteConfig, Error>;
@@ -1,11 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import { api } from '@ploykit/client';
3
- export const SITE_CONFIG_QUERY_KEY = ['site-config'];
4
- export function useSiteConfig() {
5
- return useQuery({
6
- queryKey: SITE_CONFIG_QUERY_KEY,
7
- queryFn: () => api.get('/config'),
8
- staleTime: 5 * 60_000,
9
- retry: false,
10
- });
11
- }
@@ -1,36 +0,0 @@
1
- import type { components } from '@ploykit/client';
2
- export type PAT = components['schemas']['PAT'];
3
- export type CreatePATResult = components['schemas']['CreatePATResponse'];
4
- export declare function useTokens(): {
5
- tokens: {
6
- id: string;
7
- name: string;
8
- prefix: string;
9
- expires_at?: string;
10
- last_used_at?: string;
11
- created_at: string;
12
- }[];
13
- loading: boolean;
14
- error: Error | null;
15
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
16
- id: string;
17
- name: string;
18
- prefix: string;
19
- expires_at?: string;
20
- last_used_at?: string;
21
- created_at: string;
22
- }[], Error>>;
23
- };
24
- export declare function useCreateToken(): {
25
- create: (name: string, ttlHours?: number) => Promise<{
26
- pat: components["schemas"]["PAT"];
27
- token: string;
28
- }>;
29
- loading: boolean;
30
- error: Error | null;
31
- };
32
- export declare function useRevokeToken(): {
33
- revoke: (id: string) => Promise<void>;
34
- loading: boolean;
35
- error: Error | null;
36
- };
@@ -1,35 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
- import { api } from '@ploykit/client';
4
- import { queryKeys } from '../provider/PloykitProvider';
5
- export function useTokens() {
6
- const q = useQuery({
7
- queryKey: queryKeys.tokens,
8
- queryFn: async () => {
9
- const data = await api.get('/api/tokens');
10
- return Array.isArray(data) ? data : [];
11
- },
12
- });
13
- return { tokens: q.data ?? [], loading: q.isPending, error: q.error, refetch: q.refetch };
14
- }
15
- export function useCreateToken() {
16
- const qc = useQueryClient();
17
- const m = useMutation({
18
- mutationFn: (v) => api.post('/api/tokens', v),
19
- onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.tokens }),
20
- });
21
- const create = useCallback((name, ttlHours) => m.mutateAsync({ name, ttl_hours: ttlHours }), [m]);
22
- return { create, loading: m.isPending, error: m.error };
23
- }
24
- export function useRevokeToken() {
25
- const qc = useQueryClient();
26
- const m = useMutation({
27
- mutationFn: (id) => api.delete(`/api/tokens/${id}`),
28
- onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.tokens }),
29
- });
30
- return {
31
- revoke: (id) => m.mutateAsync(id),
32
- loading: m.isPending,
33
- error: m.error,
34
- };
35
- }
@@ -1,20 +0,0 @@
1
- import type { components } from '@ploykit/client';
2
- export type PKUsageResp = components['schemas']['UsageResp'];
3
- export type PKUsageItem = components['schemas']['UsageItem'];
4
- export declare function useUsage(): {
5
- wsId: string;
6
- usage: {
7
- workspace_id: string;
8
- plan_code: string;
9
- period: string;
10
- items: components["schemas"]["UsageItem"][];
11
- } | null;
12
- loading: boolean;
13
- error: Error | null;
14
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
15
- workspace_id: string;
16
- plan_code: string;
17
- period: string;
18
- items: components["schemas"]["UsageItem"][];
19
- }, Error>>;
20
- };
@@ -1,21 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import { useApi } from './useApi';
3
- import { useWorkspace } from './useWorkspace';
4
- import { queryKeys } from '../provider/PloykitProvider';
5
- export function useUsage() {
6
- const { current } = useWorkspace();
7
- const api = useApi();
8
- const wsId = current?.id ?? '';
9
- const q = useQuery({
10
- queryKey: queryKeys.usage(wsId),
11
- queryFn: () => api.get('/api/usage'),
12
- enabled: !!wsId,
13
- });
14
- return {
15
- wsId,
16
- usage: wsId ? (q.data ?? null) : null,
17
- loading: !!wsId && q.isPending,
18
- error: q.error,
19
- refetch: q.refetch,
20
- };
21
- }
@@ -1,26 +0,0 @@
1
- import { type PKWorkspace } from '../provider/PloykitProvider';
2
- export declare function useWorkspace(): import("../provider/PloykitProvider").WorkspaceContextValue;
3
- export declare function useWorkspaceSwitch(): {
4
- current: ({
5
- id: string;
6
- slug: string;
7
- name: string;
8
- plan_code: string;
9
- created_at: string;
10
- } & {
11
- role: "owner" | "admin" | "member";
12
- }) | null;
13
- list: ({
14
- id: string;
15
- slug: string;
16
- name: string;
17
- plan_code: string;
18
- created_at: string;
19
- } & {
20
- role: "owner" | "admin" | "member";
21
- })[];
22
- switchTo: (id: string) => void;
23
- create: (name: string, slug: string) => Promise<PKWorkspace | null>;
24
- creating: boolean;
25
- error: unknown;
26
- };
@@ -1,32 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { useQueryClient } from '@tanstack/react-query';
3
- import { api } from '@ploykit/client';
4
- import { useAuthCtx, useWorkspaceCtx, queryKeys, } from '../provider/PloykitProvider';
5
- export function useWorkspace() {
6
- return useWorkspaceCtx();
7
- }
8
- export function useWorkspaceSwitch() {
9
- const { workspaces } = useAuthCtx();
10
- const { current, switchTo } = useWorkspaceCtx();
11
- const qc = useQueryClient();
12
- const [creating, setCreating] = useState(false);
13
- const [error, setError] = useState(null);
14
- const create = useCallback(async (name, slug) => {
15
- setCreating(true);
16
- setError(null);
17
- try {
18
- const ws = await api.post('/api/workspaces', { name, slug });
19
- await qc.invalidateQueries({ queryKey: queryKeys.workspace });
20
- switchTo(ws.id);
21
- return ws;
22
- }
23
- catch (e) {
24
- setError(e);
25
- return null;
26
- }
27
- finally {
28
- setCreating(false);
29
- }
30
- }, [qc, switchTo]);
31
- return { current, list: workspaces, switchTo, create, creating, error };
32
- }
@@ -1,6 +0,0 @@
1
- import { type FieldValues, type UseFormProps, type UseFormReturn } from 'react-hook-form';
2
- import type { ZodSchema } from 'zod';
3
- export interface ZodFormOptions<T extends FieldValues> extends UseFormProps<T> {
4
- schema: ZodSchema<T, T>;
5
- }
6
- export declare function useZodForm<T extends FieldValues>(opts: ZodFormOptions<T>): UseFormReturn<T>;
@@ -1,6 +0,0 @@
1
- import { zodResolver } from '@hookform/resolvers/zod';
2
- import { useForm } from 'react-hook-form';
3
- export function useZodForm(opts) {
4
- const { schema, ...rest } = opts;
5
- return useForm({ ...rest, resolver: zodResolver(schema) });
6
- }
@@ -1,4 +0,0 @@
1
- import type { FrameHandler, ScopePrefix, WsClient, WsStatus } from '@ploykit/client';
2
- export declare function useWsStatus(client: WsClient): WsStatus;
3
- export declare function useWsScope(prefix: ScopePrefix, id: string | undefined, client: WsClient): void;
4
- export declare function useWsFrame(type: string, handler: FrameHandler, client: WsClient): void;
package/dist/hooks/ws.js DELETED
@@ -1,21 +0,0 @@
1
- import { useEffect, useRef, useSyncExternalStore } from 'react';
2
- export function useWsStatus(client) {
3
- return useSyncExternalStore((cb) => client.onStatus(cb), () => client.status, () => 'idle');
4
- }
5
- export function useWsScope(prefix, id, client) {
6
- useEffect(() => {
7
- if (!id)
8
- return;
9
- return client.subscribe(prefix, id);
10
- }, [prefix, id, client]);
11
- }
12
- export function useWsFrame(type, handler, client) {
13
- const ref = useRef(handler);
14
- useEffect(() => {
15
- ref.current = handler;
16
- });
17
- useEffect(() => {
18
- const dispatch = (frame) => ref.current(frame);
19
- return client.on(type, dispatch);
20
- }, [type, client]);
21
- }
@@ -1,2 +0,0 @@
1
- export type Perm = 'admin' | 'owner';
2
- export declare function roleSatisfies(role: string | undefined, perm?: Perm): boolean;
package/dist/lib/perm.js DELETED
@@ -1,7 +0,0 @@
1
- export function roleSatisfies(role, perm) {
2
- if (perm === undefined)
3
- return true;
4
- if (perm === 'owner')
5
- return role === 'owner';
6
- return role === 'owner' || role === 'admin';
7
- }
@@ -1,7 +0,0 @@
1
- import type { QueryClient, QueryKey } from '@tanstack/react-query';
2
- import type { WsClient } from '@ploykit/client';
3
- export interface WsInvalidationRule {
4
- match: string | RegExp;
5
- invalidate: readonly QueryKey[];
6
- }
7
- export declare function bridgeWsToQuery(ws: WsClient, queryClient: QueryClient, rules: readonly WsInvalidationRule[]): () => void;
@@ -1,35 +0,0 @@
1
- function ruleMatches(rule, type) {
2
- if (typeof rule.match === 'string')
3
- return rule.match === type;
4
- rule.match.lastIndex = 0;
5
- return rule.match.test(type);
6
- }
7
- export function bridgeWsToQuery(ws, queryClient, rules) {
8
- let sawOpen = false;
9
- const offStatus = ws.onStatus((status) => {
10
- if (status !== 'open')
11
- return;
12
- if (!sawOpen) {
13
- sawOpen = true;
14
- return;
15
- }
16
- for (const rule of rules) {
17
- for (const key of rule.invalidate) {
18
- queryClient.invalidateQueries({ queryKey: key });
19
- }
20
- }
21
- });
22
- const offFrame = ws.on('*', (frame) => {
23
- for (const rule of rules) {
24
- if (!ruleMatches(rule, frame.type))
25
- continue;
26
- for (const key of rule.invalidate) {
27
- queryClient.invalidateQueries({ queryKey: key });
28
- }
29
- }
30
- });
31
- return () => {
32
- offStatus();
33
- offFrame();
34
- };
35
- }
@@ -1,50 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import { QueryClient } from '@tanstack/react-query';
3
- import type { APIUser, APIWorkspace, APISubscription, APIOrder, APIPlan } from '@ploykit/client';
4
- export declare const queryKeys: {
5
- auth: readonly ["auth"];
6
- me: readonly ["auth", "me"];
7
- sessions: readonly ["auth", "sessions"];
8
- tokens: readonly ["auth", "tokens"];
9
- workspace: readonly ["workspace"];
10
- workspaceList: readonly ["workspace", "list"];
11
- members: (wsId: string) => readonly ["workspace", string, "members"];
12
- invitations: (wsId: string) => readonly ["workspace", string, "invitations"];
13
- shareLinks: (wsId: string) => readonly ["workspace", string, "share-links"];
14
- myInvitations: readonly ["workspace", "my-invitations"];
15
- audit: (wsId: string, q: object) => readonly ["audit", string, object];
16
- usage: (wsId: string) => readonly ["usage", string];
17
- billing: readonly ["billing"];
18
- billingSubscription: (workspaceId: string) => readonly ["billing", "subscription", string];
19
- billingPlans: readonly ["billing", "plans"];
20
- notifications: readonly ["notifications"];
21
- notificationPrefs: readonly ["notifications", "preferences"];
22
- webhooks: (wsId: string) => readonly ["webhooks", string];
23
- admin: readonly ["admin"];
24
- };
25
- export type PKUser = APIUser;
26
- export type PKWorkspace = APIWorkspace;
27
- export type PKSubscription = APISubscription;
28
- export type PKOrder = APIOrder;
29
- export type PKPlan = APIPlan;
30
- export interface AuthContextValue {
31
- user: PKUser | null;
32
- workspaces: PKWorkspace[];
33
- loading: boolean;
34
- error: unknown;
35
- refresh(): Promise<void>;
36
- logout(): Promise<void>;
37
- }
38
- export declare const AuthContext: import("react").Context<AuthContextValue | null>;
39
- export interface WorkspaceContextValue {
40
- current: PKWorkspace | null;
41
- switchTo(id: string): void;
42
- clear(): void;
43
- }
44
- export declare const WorkspaceContext: import("react").Context<WorkspaceContextValue | null>;
45
- export declare function useAuthCtx(): AuthContextValue;
46
- export declare function useWorkspaceCtx(): WorkspaceContextValue;
47
- export declare function PloykitProvider({ children, queryClient }: {
48
- children: ReactNode;
49
- queryClient?: QueryClient;
50
- }): import("react").JSX.Element;