kitcn 0.0.1 → 0.12.1

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 (93) hide show
  1. package/bin/intent.js +3 -0
  2. package/dist/aggregate/index.d.ts +388 -0
  3. package/dist/aggregate/index.js +37 -0
  4. package/dist/api-entry-BckXqaLb.js +66 -0
  5. package/dist/auth/client/index.d.ts +37 -0
  6. package/dist/auth/client/index.js +217 -0
  7. package/dist/auth/config/index.d.ts +45 -0
  8. package/dist/auth/config/index.js +24 -0
  9. package/dist/auth/generated/index.d.ts +2 -0
  10. package/dist/auth/generated/index.js +3 -0
  11. package/dist/auth/http/index.d.ts +64 -0
  12. package/dist/auth/http/index.js +461 -0
  13. package/dist/auth/index.d.ts +221 -0
  14. package/dist/auth/index.js +1398 -0
  15. package/dist/auth/nextjs/index.d.ts +50 -0
  16. package/dist/auth/nextjs/index.js +81 -0
  17. package/dist/auth-store-Cljlmdmi.js +197 -0
  18. package/dist/builder-CBdG5W6A.js +1974 -0
  19. package/dist/caller-factory-cTXNvYdz.js +216 -0
  20. package/dist/cli.mjs +13264 -0
  21. package/dist/codegen-lF80HSWu.mjs +3416 -0
  22. package/dist/context-utils-HPC5nXzx.d.ts +17 -0
  23. package/dist/create-schema-odyF4kCy.js +156 -0
  24. package/dist/create-schema-orm-DOyiNDCx.js +246 -0
  25. package/dist/crpc/index.d.ts +105 -0
  26. package/dist/crpc/index.js +169 -0
  27. package/dist/customFunctions-C0voKmtx.js +144 -0
  28. package/dist/error-BZEnI7Sq.js +41 -0
  29. package/dist/generated-contract-disabled-Cih4eITO.js +50 -0
  30. package/dist/generated-contract-disabled-D-sOFy92.d.ts +354 -0
  31. package/dist/http-types-DqJubRPJ.d.ts +292 -0
  32. package/dist/meta-utils-0Pu0Nrap.js +117 -0
  33. package/dist/middleware-BUybuv9n.d.ts +34 -0
  34. package/dist/middleware-C2qTZ3V7.js +84 -0
  35. package/dist/orm/index.d.ts +17 -0
  36. package/dist/orm/index.js +10713 -0
  37. package/dist/plugins/index.d.ts +2 -0
  38. package/dist/plugins/index.js +3 -0
  39. package/dist/procedure-caller-DtxLmGwA.d.ts +1467 -0
  40. package/dist/procedure-caller-MWcxhQDv.js +349 -0
  41. package/dist/query-context-B8o6-8kC.js +1518 -0
  42. package/dist/query-context-CFZqIvD7.d.ts +42 -0
  43. package/dist/query-options-Dw7cOyXl.js +121 -0
  44. package/dist/ratelimit/index.d.ts +269 -0
  45. package/dist/ratelimit/index.js +856 -0
  46. package/dist/ratelimit/react/index.d.ts +76 -0
  47. package/dist/ratelimit/react/index.js +183 -0
  48. package/dist/react/index.d.ts +1284 -0
  49. package/dist/react/index.js +2526 -0
  50. package/dist/rsc/index.d.ts +276 -0
  51. package/dist/rsc/index.js +233 -0
  52. package/dist/runtime-CtvJPkur.js +2453 -0
  53. package/dist/server/index.d.ts +5 -0
  54. package/dist/server/index.js +6 -0
  55. package/dist/solid/index.d.ts +1221 -0
  56. package/dist/solid/index.js +2940 -0
  57. package/dist/transformer-DtDhR3Lc.js +194 -0
  58. package/dist/types-BTb_4BaU.d.ts +42 -0
  59. package/dist/types-BiJE7qxR.d.ts +4 -0
  60. package/dist/types-DEJpkIhw.d.ts +88 -0
  61. package/dist/types-HhO_R6pd.d.ts +213 -0
  62. package/dist/validators-B7oIJCAp.js +279 -0
  63. package/dist/validators-vzRKjBJC.d.ts +88 -0
  64. package/dist/watcher.mjs +96 -0
  65. package/dist/where-clause-compiler-DdjN63Io.d.ts +4756 -0
  66. package/package.json +107 -34
  67. package/skills/convex/SKILL.md +486 -0
  68. package/skills/convex/references/features/aggregates.md +353 -0
  69. package/skills/convex/references/features/auth-admin.md +446 -0
  70. package/skills/convex/references/features/auth-organizations.md +1141 -0
  71. package/skills/convex/references/features/auth-polar.md +579 -0
  72. package/skills/convex/references/features/auth.md +470 -0
  73. package/skills/convex/references/features/create-plugins.md +153 -0
  74. package/skills/convex/references/features/http.md +676 -0
  75. package/skills/convex/references/features/migrations.md +162 -0
  76. package/skills/convex/references/features/orm.md +1166 -0
  77. package/skills/convex/references/features/react.md +657 -0
  78. package/skills/convex/references/features/scheduling.md +267 -0
  79. package/skills/convex/references/features/testing.md +209 -0
  80. package/skills/convex/references/setup/auth.md +501 -0
  81. package/skills/convex/references/setup/biome.md +190 -0
  82. package/skills/convex/references/setup/doc-guidelines.md +145 -0
  83. package/skills/convex/references/setup/index.md +761 -0
  84. package/skills/convex/references/setup/next.md +116 -0
  85. package/skills/convex/references/setup/react.md +175 -0
  86. package/skills/convex/references/setup/server.md +473 -0
  87. package/skills/convex/references/setup/start.md +67 -0
  88. package/LICENSE +0 -21
  89. package/README.md +0 -0
  90. package/dist/index.d.mts +0 -5
  91. package/dist/index.d.mts.map +0 -1
  92. package/dist/index.mjs +0 -6
  93. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,50 @@
1
+ import { I as ConvexContext, R as LazyCaller } from "../../procedure-caller-DtxLmGwA.js";
2
+ import { GetTokenOptions } from "@convex-dev/better-auth/utils";
3
+
4
+ //#region src/auth-nextjs/index.d.ts
5
+ /** Auth options for server-side calls. */
6
+ type AuthOptions = {
7
+ /** Enable/disable JWT caching. Default: true */jwtCache?: boolean; /** Custom function to detect UNAUTHORIZED errors. Default checks code property. */
8
+ isUnauthorized?: (error: unknown) => boolean; /** Expiration tolerance in seconds. */
9
+ expirationToleranceSeconds?: number;
10
+ };
11
+ type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
12
+ api: TApi;
13
+ convexSiteUrl: string;
14
+ convexUrl?: string; /** Auth options. JWT caching is enabled by default (set `auth.jwtCache: false` to disable). */
15
+ auth?: AuthOptions;
16
+ };
17
+ /**
18
+ * Create Convex caller factory with Better Auth integration for Next.js.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // server.ts
23
+ * export const { createContext, createCaller, handler } = convexBetterAuth({
24
+ * api,
25
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
26
+ * }); // JWT caching enabled by default
27
+ *
28
+ * // rsc.tsx
29
+ * const createRSCContext = cache(async () => {
30
+ * const heads = await headers();
31
+ * return createContext({ headers: heads });
32
+ * });
33
+ * export const caller = createCaller(createRSCContext);
34
+ *
35
+ * // app/page.tsx - single call!
36
+ * const posts = await caller.posts.list();
37
+ * ```
38
+ */
39
+ declare function convexBetterAuth<TApi extends Record<string, unknown>>(opts: ConvexBetterAuthOptions<TApi>): {
40
+ createCaller: (ctxFn: () => Promise<ConvexContext<TApi>>) => LazyCaller<TApi>;
41
+ createContext: (reqOpts: {
42
+ headers: Headers;
43
+ }) => Promise<ConvexContext<TApi>>;
44
+ handler: {
45
+ GET: (request: Request) => Promise<Response>;
46
+ POST: (request: Request) => Promise<Response>;
47
+ };
48
+ };
49
+ //#endregion
50
+ export { convexBetterAuth };
@@ -0,0 +1,81 @@
1
+ import { n as defaultIsUnauthorized } from "../../error-BZEnI7Sq.js";
2
+ import { t as createCallerFactory } from "../../caller-factory-cTXNvYdz.js";
3
+ import { getToken } from "@convex-dev/better-auth/utils";
4
+
5
+ //#region src/auth-nextjs/index.ts
6
+ /** biome-ignore-all lint/suspicious/noExplicitAny: lib */
7
+ /**
8
+ * Next.js + Better Auth wrapper for Convex caller factory.
9
+ * Uses @convex-dev/better-auth for token management.
10
+ */
11
+ const handler = (request, siteUrl) => {
12
+ const requestUrl = new URL(request.url);
13
+ const nextUrl = `${siteUrl}${requestUrl.pathname}${requestUrl.search}`;
14
+ const newRequest = new Request(nextUrl, request);
15
+ newRequest.headers.set("accept-encoding", "application/json");
16
+ newRequest.headers.set("host", new URL(siteUrl).host);
17
+ return fetch(newRequest, {
18
+ method: request.method,
19
+ redirect: "manual"
20
+ });
21
+ };
22
+ const nextJsHandler = (siteUrl) => ({
23
+ GET: (request) => handler(request, siteUrl),
24
+ POST: (request) => handler(request, siteUrl)
25
+ });
26
+ /**
27
+ * Create Convex caller factory with Better Auth integration for Next.js.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // server.ts
32
+ * export const { createContext, createCaller, handler } = convexBetterAuth({
33
+ * api,
34
+ * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
35
+ * }); // JWT caching enabled by default
36
+ *
37
+ * // rsc.tsx
38
+ * const createRSCContext = cache(async () => {
39
+ * const heads = await headers();
40
+ * return createContext({ headers: heads });
41
+ * });
42
+ * export const caller = createCaller(createRSCContext);
43
+ *
44
+ * // app/page.tsx - single call!
45
+ * const posts = await caller.posts.list();
46
+ * ```
47
+ */
48
+ function convexBetterAuth(opts) {
49
+ const auth = opts.auth ?? {};
50
+ const jwtCacheEnabled = auth.jwtCache !== false;
51
+ const { createContext, createCaller } = createCallerFactory({
52
+ api: opts.api,
53
+ auth: jwtCacheEnabled ? {
54
+ getToken: (siteUrl, headers, getTokenOpts) => {
55
+ const mutableHeaders = new Headers(headers);
56
+ mutableHeaders.delete("content-length");
57
+ mutableHeaders.delete("transfer-encoding");
58
+ mutableHeaders.set("accept-encoding", "identity");
59
+ return getToken(siteUrl, mutableHeaders, {
60
+ ...getTokenOpts,
61
+ jwtCache: {
62
+ enabled: true,
63
+ expirationToleranceSeconds: auth.expirationToleranceSeconds,
64
+ isAuthError: auth.isUnauthorized ?? defaultIsUnauthorized
65
+ }
66
+ });
67
+ },
68
+ isUnauthorized: auth.isUnauthorized ?? defaultIsUnauthorized
69
+ } : void 0,
70
+ convexSiteUrl: opts.convexSiteUrl,
71
+ convexUrl: opts.convexUrl
72
+ });
73
+ return {
74
+ createCaller,
75
+ createContext,
76
+ handler: nextJsHandler(opts.convexSiteUrl)
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ export { convexBetterAuth };
@@ -0,0 +1,197 @@
1
+ 'use client';
2
+ import { ConvexProviderWithAuth, useConvexAuth } from "convex/react";
3
+ import { createContext, useContext } from "react";
4
+ import { createAtomStore } from "jotai-x";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/crpc/error.ts
8
+ /**
9
+ * Client-side CRPC error.
10
+ * Mirrors backend CRPCError pattern with typed error codes.
11
+ */
12
+ var CRPCClientError = class extends Error {
13
+ name = "CRPCClientError";
14
+ code;
15
+ functionName;
16
+ constructor(opts) {
17
+ super(opts.message ?? `${opts.code}: ${opts.functionName}`);
18
+ this.code = opts.code;
19
+ this.functionName = opts.functionName;
20
+ }
21
+ };
22
+ /** Type guard for CRPCClientError */
23
+ const isCRPCClientError = (error) => error instanceof CRPCClientError;
24
+ /** Default unauthorized detection - checks UNAUTHORIZED code */
25
+ const defaultIsUnauthorized = (error) => {
26
+ if (!error || typeof error !== "object") return false;
27
+ if ("data" in error) {
28
+ const data = error.data;
29
+ if (data && typeof data === "object" && "code" in data) return data.code === "UNAUTHORIZED";
30
+ }
31
+ if ("code" in error) return error.code === "UNAUTHORIZED";
32
+ return false;
33
+ };
34
+
35
+ //#endregion
36
+ //#region src/react/auth-store.tsx
37
+ /**
38
+ * Auth Store - Generic auth state management with jotai-x
39
+ *
40
+ * Provides token storage and auth callback configuration.
41
+ * App configures handlers, lib hooks consume state.
42
+ */
43
+ const FetchAccessTokenContext = createContext(null);
44
+ /** Get fetchAccessToken from context (available immediately, no race condition) */
45
+ const useFetchAccessToken = () => useContext(FetchAccessTokenContext);
46
+ /**
47
+ * Context that holds auth result from ConvexAuthBridge.
48
+ * Allows @convex-dev/auth users to use skipUnauth queries without better-auth.
49
+ */
50
+ const ConvexAuthBridgeContext = createContext(null);
51
+ /** Get auth from bridge context (null if no bridge configured) */
52
+ const useConvexAuthBridge = () => useContext(ConvexAuthBridgeContext);
53
+ const AUTH_SESSION_SYNC_GRACE_MS = 1e4;
54
+ const isSessionSyncGraceActive = (sessionSyncGraceUntil) => typeof sessionSyncGraceUntil === "number" && sessionSyncGraceUntil > Date.now();
55
+ /** Decode JWT expiration (ms timestamp) from token */
56
+ function decodeJwtExp(token) {
57
+ try {
58
+ const payload = JSON.parse(atob(token.split(".")[1]));
59
+ return payload.exp ? payload.exp * 1e3 : null;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+ const { AuthProvider, useAuthStore, useAuthState, useAuthValue } = createAtomStore({
65
+ onMutationUnauthorized: () => {
66
+ throw new CRPCClientError({
67
+ code: "UNAUTHORIZED",
68
+ functionName: "mutation"
69
+ });
70
+ },
71
+ onQueryUnauthorized: () => {},
72
+ isUnauthorized: defaultIsUnauthorized,
73
+ token: null,
74
+ expiresAt: null,
75
+ isLoading: true,
76
+ isAuthenticated: false,
77
+ sessionSyncGraceUntil: null
78
+ }, {
79
+ name: "auth",
80
+ suppressWarnings: true
81
+ });
82
+ /**
83
+ * Safe wrapper around useConvexAuth that doesn't throw when used outside auth provider.
84
+ * Returns { isAuthenticated: false, isLoading: false } when no auth provider.
85
+ *
86
+ * Supports both:
87
+ * - better-auth users (via AuthProvider)
88
+ * - @convex-dev/auth users (via ConvexAuthBridge)
89
+ */
90
+ function useSafeConvexAuth() {
91
+ const authStore = useAuthStore();
92
+ const bridgeAuth = useConvexAuthBridge();
93
+ if (authStore.store) return useConvexAuth();
94
+ if (bridgeAuth !== null) return bridgeAuth;
95
+ return {
96
+ isAuthenticated: false,
97
+ isLoading: false
98
+ };
99
+ }
100
+ /**
101
+ * Internal bridge component. Use `ConvexProviderWithAuth` instead.
102
+ * @internal
103
+ */
104
+ function ConvexAuthBridge({ children }) {
105
+ const auth = useConvexAuth();
106
+ return /* @__PURE__ */ jsx(ConvexAuthBridgeContext.Provider, {
107
+ value: auth,
108
+ children
109
+ });
110
+ }
111
+ /**
112
+ * Convex provider with auth bridge for @convex-dev/auth users.
113
+ * Automatically wraps children with ConvexAuthBridge.
114
+ *
115
+ * @example
116
+ * ```tsx
117
+ * import { ConvexProviderWithAuth } from 'kitcn/react';
118
+ *
119
+ * <ConvexProviderWithAuth client={convex} useAuth={useAuthFromConvexDev}>
120
+ * <App />
121
+ * </ConvexProviderWithAuth>
122
+ * ```
123
+ */
124
+ function ConvexProviderWithAuth$1({ children, ...props }) {
125
+ return /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
126
+ ...props,
127
+ children: /* @__PURE__ */ jsx(ConvexAuthBridge, { children })
128
+ });
129
+ }
130
+ const useAuth = () => {
131
+ const authStore = useAuthStore();
132
+ const bridgeAuth = useConvexAuthBridge();
133
+ if (authStore.store) {
134
+ if (typeof window === "undefined") return {
135
+ hasSession: !!authStore.get("token"),
136
+ isAuthenticated: false,
137
+ isLoading: true
138
+ };
139
+ const { isLoading, isAuthenticated } = useConvexAuth();
140
+ return {
141
+ hasSession: !!useAuthValue("token"),
142
+ isAuthenticated,
143
+ isLoading
144
+ };
145
+ }
146
+ if (bridgeAuth !== null) return {
147
+ hasSession: false,
148
+ isAuthenticated: bridgeAuth.isAuthenticated,
149
+ isLoading: bridgeAuth.isLoading
150
+ };
151
+ return {
152
+ hasSession: false,
153
+ isAuthenticated: false,
154
+ isLoading: false
155
+ };
156
+ };
157
+ /** Check if user maybe has auth (optimistic, has token) */
158
+ const useMaybeAuth = () => {
159
+ const { hasSession } = useAuth();
160
+ return hasSession;
161
+ };
162
+ /** Check if user is authenticated (server-verified) */
163
+ const useIsAuth = () => {
164
+ const { isAuthenticated } = useAuth();
165
+ return isAuthenticated;
166
+ };
167
+ const useAuthGuard = () => {
168
+ const { isAuthenticated } = useSafeConvexAuth();
169
+ const onMutationUnauthorized = useAuthValue("onMutationUnauthorized");
170
+ return (callback) => {
171
+ if (!isAuthenticated) {
172
+ onMutationUnauthorized();
173
+ return true;
174
+ }
175
+ return callback ? void callback() : false;
176
+ };
177
+ };
178
+ /** Render children only when maybe has auth (optimistic) */
179
+ function MaybeAuthenticated({ children }) {
180
+ return useMaybeAuth() ? children : null;
181
+ }
182
+ /** Render children only when authenticated (server-verified) */
183
+ function Authenticated({ children }) {
184
+ return useIsAuth() ? children : null;
185
+ }
186
+ /** Render children only when maybe not auth (optimistic) */
187
+ function MaybeUnauthenticated({ children }) {
188
+ return useMaybeAuth() ? null : children;
189
+ }
190
+ /** Render children only when not authenticated (server-verified) */
191
+ function Unauthenticated({ children }) {
192
+ const { isAuthenticated, isLoading } = useAuth();
193
+ return isLoading || isAuthenticated ? null : children;
194
+ }
195
+
196
+ //#endregion
197
+ export { defaultIsUnauthorized as C, CRPCClientError as S, useConvexAuthBridge as _, ConvexProviderWithAuth$1 as a, useMaybeAuth as b, MaybeUnauthenticated as c, isSessionSyncGraceActive as d, useAuth as f, useAuthValue as g, useAuthStore as h, ConvexAuthBridge as i, Unauthenticated as l, useAuthState as m, AuthProvider as n, FetchAccessTokenContext as o, useAuthGuard as p, Authenticated as r, MaybeAuthenticated as s, AUTH_SESSION_SYNC_GRACE_MS as t, decodeJwtExp as u, useFetchAccessToken as v, isCRPCClientError as w, useSafeConvexAuth as x, useIsAuth as y };