@robelest/convex-auth 0.0.4-preview.0 → 0.0.4-preview.2

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 (49) hide show
  1. package/README.md +31 -0
  2. package/dist/component/_generated/api.d.ts +2 -0
  3. package/dist/component/_generated/api.d.ts.map +1 -1
  4. package/dist/component/_generated/api.js.map +1 -1
  5. package/dist/component/convex.config.d.ts +2 -2
  6. package/dist/component/convex.config.d.ts.map +1 -1
  7. package/dist/component/functions.d.ts +23 -0
  8. package/dist/component/functions.d.ts.map +1 -0
  9. package/dist/component/functions.js +32 -0
  10. package/dist/component/functions.js.map +1 -0
  11. package/dist/component/public.d.ts +81 -835
  12. package/dist/component/public.d.ts.map +1 -1
  13. package/dist/component/public.js +1 -1
  14. package/dist/component/public.js.map +1 -1
  15. package/dist/component/schema.d.ts +34 -34
  16. package/dist/component/server/auth.d.ts +49 -48
  17. package/dist/component/server/auth.d.ts.map +1 -1
  18. package/dist/component/server/implementation/index.d.ts +5 -5
  19. package/dist/component/server/implementation/types.d.ts +1 -1
  20. package/dist/server/auth.d.ts +48 -48
  21. package/dist/server/implementation/index.d.ts +20 -20
  22. package/dist/server/implementation/index.d.ts.map +1 -1
  23. package/dist/server/implementation/mutations/account.d.ts +8 -8
  24. package/dist/server/implementation/mutations/code.d.ts +12 -12
  25. package/dist/server/implementation/mutations/code.d.ts.map +1 -1
  26. package/dist/server/implementation/mutations/index.d.ts +104 -104
  27. package/dist/server/implementation/mutations/index.d.ts.map +1 -1
  28. package/dist/server/implementation/mutations/invalidate.d.ts +4 -4
  29. package/dist/server/implementation/mutations/oauth.d.ts +8 -8
  30. package/dist/server/implementation/mutations/refresh.d.ts +3 -3
  31. package/dist/server/implementation/mutations/refresh.d.ts.map +1 -1
  32. package/dist/server/implementation/mutations/register.d.ts +11 -11
  33. package/dist/server/implementation/mutations/register.d.ts.map +1 -1
  34. package/dist/server/implementation/mutations/retrieve.d.ts +8 -8
  35. package/dist/server/implementation/mutations/signature.d.ts +4 -4
  36. package/dist/server/implementation/mutations/signature.d.ts.map +1 -1
  37. package/dist/server/implementation/mutations/signin.d.ts +5 -5
  38. package/dist/server/implementation/mutations/signin.d.ts.map +1 -1
  39. package/dist/server/implementation/mutations/verify.d.ts +3 -3
  40. package/dist/server/providers.d.ts +8 -8
  41. package/dist/server/providers.d.ts.map +1 -1
  42. package/dist/server/version.d.ts +1 -1
  43. package/dist/server/version.js +1 -1
  44. package/dist/server/version.js.map +1 -1
  45. package/package.json +4 -3
  46. package/src/component/_generated/api.ts +2 -0
  47. package/src/component/functions.ts +88 -0
  48. package/src/component/public.ts +1 -1
  49. package/src/server/version.ts +1 -1
package/README.md CHANGED
@@ -6,6 +6,7 @@ Component-first authentication for [Convex](https://convex.dev). One component,
6
6
 
7
7
  - **Class-based API** — `new Auth(components.auth, { providers })` gives you everything.
8
8
  - **OAuth via Arctic** — 50+ providers through [Arctic](https://arcticjs.dev), zero-dependency OAuth 2.0.
9
+ - **Fluent Convex builders (recommended)** — cleaner auth-aware API handling with middleware and explicit `.public()` / `.internal()` exports.
9
10
  - **Password, passkeys, TOTP, magic links, OTP, phone, anonymous** — all built in.
10
11
  - **Device Authorization (RFC 8628)** — authenticate CLIs, smart TVs, and IoT devices.
11
12
  - **API keys** — scoped permissions, SHA-256 hashed storage, optional rate limiting.
@@ -19,6 +20,9 @@ Component-first authentication for [Convex](https://convex.dev). One component,
19
20
  npm install @robelest/convex-auth
20
21
  ```
21
22
 
23
+ > Renamed package: if you are migrating from earlier previews, replace
24
+ > `@convex-dev/auth` with `@robelest/convex-auth` in imports and CLI commands.
25
+
22
26
  ## Quick Start
23
27
 
24
28
  ```bash
@@ -66,6 +70,33 @@ auth.http.add(http);
66
70
  export default http;
67
71
  ```
68
72
 
73
+ ## Recommended Convex API Handling (`fluent-convex`)
74
+
75
+ For new projects, we recommend `fluent-convex` for auth middleware composition and cleaner API exports.
76
+
77
+ ```ts
78
+ // convex/functions.ts
79
+ import { createBuilder } from "fluent-convex";
80
+ import { WithZod } from "fluent-convex/zod";
81
+ import type { DataModel } from "./_generated/dataModel";
82
+ import { auth } from "./auth";
83
+
84
+ const convex = createBuilder<DataModel>();
85
+
86
+ const withRequiredAuth = convex.createMiddleware<any, { auth: any }>(
87
+ async (ctx, next) => {
88
+ const userId = await auth.user.require(ctx);
89
+ const user = await auth.user.get(ctx, userId);
90
+ return next({ ...ctx, auth: { ...ctx.auth, userId, user } });
91
+ },
92
+ );
93
+
94
+ export const query = convex.query().use(withRequiredAuth).extend(WithZod);
95
+ export const mutation = convex.mutation().use(withRequiredAuth).extend(WithZod);
96
+ ```
97
+
98
+ `AuthCtx` from `@robelest/convex-auth/component` remains supported if your project already uses `convex-helpers`.
99
+
69
100
  ## Providers
70
101
 
71
102
  | Provider | Import |
@@ -1,9 +1,11 @@
1
+ import { functions_d_exports } from "../functions.js";
1
2
  import { index_d_exports } from "../index.js";
2
3
  import { public_d_exports } from "../public.js";
3
4
  import { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
4
5
 
5
6
  //#region src/component/_generated/api.d.ts
6
7
  declare const fullApi: ApiFromModules<{
8
+ functions: typeof functions_d_exports;
7
9
  index: typeof index_d_exports;
8
10
  public: typeof public_d_exports;
9
11
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","names":[],"sources":["../../../src/component/_generated/api.ts"],"mappings":";;;;;cAoBM,OAAA,EAAS,cAAA;EACb,KAAA,SAAc,eAAA;EACd,MAAA,SAAe,gBAAA;AAAA;;;;;;AAWjB;;;cAAa,GAAA,EAAK,SAAA,QACT,OAAA,EACP,iBAAA;;;;;;;;;cAWW,QAAA,EAAU,SAAA,QACd,OAAA,EACP,iBAAA;AAAA,cAGW,UAAA"}
1
+ {"version":3,"file":"api.d.ts","names":[],"sources":["../../../src/component/_generated/api.ts"],"mappings":";;;;;;cAqBM,OAAA,EAAS,cAAA;EACb,SAAA,SAAkB,mBAAA;EAClB,KAAA,SAAc,eAAA;EACd,MAAA,SAAe,gBAAA;AAAA;;;;;;;;AAWjB;cAAa,GAAA,EAAK,SAAA,QACT,OAAA,EACP,iBAAA;;;;;;;;;cAWW,QAAA,EAAU,SAAA,QACd,OAAA,EACP,iBAAA;AAAA,cAGW,UAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","names":[],"sources":["../../../src/component/_generated/api.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated `api` utility.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type * as index from \"../index.js\";\nimport type * as public_ from \"../public.js\";\n\nimport type {\n ApiFromModules,\n FilterApi,\n FunctionReference,\n} from \"convex/server\";\nimport { anyApi, componentsGeneric } from \"convex/server\";\n\nconst fullApi: ApiFromModules<{\n index: typeof index;\n public: typeof public_;\n}> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's public API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = api.myModule.myFunction;\n * ```\n */\nexport const api: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"public\">\n> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's internal API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = internal.myModule.myFunction;\n * ```\n */\nexport const internal: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"internal\">\n> = anyApi as any;\n\nexport const components = componentsGeneric() as unknown as {};\n"],"mappings":";;;;;;;;;;;AAiCA,MAAa,MAGT;;;;;;;;;AAUJ,MAAa,WAGT;AAEJ,MAAa,aAAa,mBAAmB"}
1
+ {"version":3,"file":"api.js","names":[],"sources":["../../../src/component/_generated/api.ts"],"sourcesContent":["/* eslint-disable */\n/**\n * Generated `api` utility.\n *\n * THIS CODE IS AUTOMATICALLY GENERATED.\n *\n * To regenerate, run `npx convex dev`.\n * @module\n */\n\nimport type * as functions from \"../functions.js\";\nimport type * as index from \"../index.js\";\nimport type * as public_ from \"../public.js\";\n\nimport type {\n ApiFromModules,\n FilterApi,\n FunctionReference,\n} from \"convex/server\";\nimport { anyApi, componentsGeneric } from \"convex/server\";\n\nconst fullApi: ApiFromModules<{\n functions: typeof functions;\n index: typeof index;\n public: typeof public_;\n}> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's public API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = api.myModule.myFunction;\n * ```\n */\nexport const api: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"public\">\n> = anyApi as any;\n\n/**\n * A utility for referencing Convex functions in your app's internal API.\n *\n * Usage:\n * ```js\n * const myFunctionReference = internal.myModule.myFunction;\n * ```\n */\nexport const internal: FilterApi<\n typeof fullApi,\n FunctionReference<any, \"internal\">\n> = anyApi as any;\n\nexport const components = componentsGeneric() as unknown as {};\n"],"mappings":";;;;;;;;;;;AAmCA,MAAa,MAGT;;;;;;;;;AAUJ,MAAa,WAGT;AAEJ,MAAa,aAAa,mBAAmB"}
@@ -1,7 +1,7 @@
1
- import * as convex_server0 from "convex/server";
1
+ import * as convex_server15 from "convex/server";
2
2
 
3
3
  //#region src/component/convex.config.d.ts
4
- declare const component: convex_server0.ComponentDefinition<any>;
4
+ declare const component: convex_server15.ComponentDefinition<any>;
5
5
  //#endregion
6
6
  export { component as default };
7
7
  //# sourceMappingURL=convex.config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convex.config.d.ts","names":[],"sources":["../../src/component/convex.config.ts"],"mappings":";;;cAEM,SAAA,EAAmC,cAAA,CAA1B,mBAAA"}
1
+ {"version":3,"file":"convex.config.d.ts","names":[],"sources":["../../src/component/convex.config.ts"],"mappings":";;;cAEM,SAAA,EAAmC,eAAA,CAA1B,mBAAA"}
@@ -0,0 +1,23 @@
1
+ import { ActionCtx, MutationCtx, QueryCtx } from "./_generated/server.js";
2
+ import { GenericValidator, Infer, ObjectType, PropertyValidators } from "convex/values";
3
+
4
+ //#region src/component/functions.d.ts
5
+ declare namespace functions_d_exports {
6
+ export { action, internalAction, internalMutation, internalQuery, mutation, query };
7
+ }
8
+ type ArgsValidator = PropertyValidators | GenericValidator;
9
+ type ArgsFor<TArgs extends ArgsValidator | undefined> = TArgs extends PropertyValidators ? ObjectType<TArgs> : TArgs extends GenericValidator ? Infer<TArgs> : any;
10
+ type BaseFunctionConfig<Ctx, TArgs extends ArgsValidator | undefined> = {
11
+ args?: TArgs;
12
+ returns?: GenericValidator;
13
+ handler: (ctx: Ctx, args: ArgsFor<TArgs>) => Promise<any> | any;
14
+ };
15
+ declare function query<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<QueryCtx, TArgs>): any;
16
+ declare function mutation<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<MutationCtx, TArgs>): any;
17
+ declare function internalQuery<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<QueryCtx, TArgs>): any;
18
+ declare function internalMutation<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<MutationCtx, TArgs>): any;
19
+ declare function action<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<ActionCtx, TArgs>): any;
20
+ declare function internalAction<TArgs extends ArgsValidator | undefined>(config: BaseFunctionConfig<ActionCtx, TArgs>): any;
21
+ //#endregion
22
+ export { action, functions_d_exports, internalAction, internalMutation, internalQuery, mutation, query };
23
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.d.ts","names":[],"sources":["../../src/component/functions.ts"],"mappings":";;;;;;;KAYK,aAAA,GAAgB,kBAAA,GAAqB,gBAAA;AAAA,KAErC,OAAA,eAAsB,aAAA,gBACzB,KAAA,SAAc,kBAAA,GACV,UAAA,CAAW,KAAA,IACX,KAAA,SAAc,gBAAA,GACZ,KAAA,CAAM,KAAA;AAAA,KAGT,kBAAA,oBAAsC,aAAA;EACzC,IAAA,GAAO,KAAA;EACP,OAAA,GAAU,gBAAA;EACV,OAAA,GAAU,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,OAAA,CAAQ,KAAA,MAAW,OAAA;AAAA;AAAA,iBAiB/B,KAAA,eAAoB,aAAA,aAAA,CAClC,MAAA,EAAQ,kBAAA,CAAmB,QAAA,EAAU,KAAA;AAAA,iBAOvB,QAAA,eAAuB,aAAA,aAAA,CACrC,MAAA,EAAQ,kBAAA,CAAmB,WAAA,EAAa,KAAA;AAAA,iBAO1B,aAAA,eAA4B,aAAA,aAAA,CAC1C,MAAA,EAAQ,kBAAA,CAAmB,QAAA,EAAU,KAAA;AAAA,iBAOvB,gBAAA,eAA+B,aAAA,aAAA,CAC7C,MAAA,EAAQ,kBAAA,CAAmB,WAAA,EAAa,KAAA;AAAA,iBAO1B,MAAA,eAAqB,aAAA,aAAA,CACnC,MAAA,EAAQ,kBAAA,CAAmB,SAAA,EAAW,KAAA;AAAA,iBAOxB,cAAA,eAA6B,aAAA,aAAA,CAC3C,MAAA,EAAQ,kBAAA,CAAmB,SAAA,EAAW,KAAA"}
@@ -0,0 +1,32 @@
1
+ import { createBuilder } from "fluent-convex";
2
+
3
+ //#region src/component/functions.ts
4
+ const convex = createBuilder();
5
+ function withValidation(builder, config) {
6
+ let current = builder;
7
+ if (config.args !== void 0) current = current.input(config.args);
8
+ if (config.returns !== void 0) current = current.returns(config.returns);
9
+ return current;
10
+ }
11
+ function query(config) {
12
+ return withValidation(convex.query(), config).handler(config.handler).public();
13
+ }
14
+ function mutation(config) {
15
+ return withValidation(convex.mutation(), config).handler(config.handler).public();
16
+ }
17
+ function internalQuery(config) {
18
+ return withValidation(convex.query(), config).handler(config.handler).internal();
19
+ }
20
+ function internalMutation(config) {
21
+ return withValidation(convex.mutation(), config).handler(config.handler).internal();
22
+ }
23
+ function action(config) {
24
+ return withValidation(convex.action(), config).handler(config.handler).public();
25
+ }
26
+ function internalAction(config) {
27
+ return withValidation(convex.action(), config).handler(config.handler).internal();
28
+ }
29
+
30
+ //#endregion
31
+ export { action, internalAction, internalMutation, internalQuery, mutation, query };
32
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","names":[],"sources":["../../src/component/functions.ts"],"sourcesContent":["import { createBuilder } from \"fluent-convex\";\nimport type {\n GenericValidator,\n Infer,\n ObjectType,\n PropertyValidators,\n} from \"convex/values\";\nimport type { DataModel } from \"./_generated/dataModel\";\nimport type { ActionCtx, MutationCtx, QueryCtx } from \"./_generated/server\";\n\nconst convex = createBuilder<DataModel>();\n\ntype ArgsValidator = PropertyValidators | GenericValidator;\n\ntype ArgsFor<TArgs extends ArgsValidator | undefined> =\n TArgs extends PropertyValidators\n ? ObjectType<TArgs>\n : TArgs extends GenericValidator\n ? Infer<TArgs>\n : any;\n\ntype BaseFunctionConfig<Ctx, TArgs extends ArgsValidator | undefined> = {\n args?: TArgs;\n returns?: GenericValidator;\n handler: (ctx: Ctx, args: ArgsFor<TArgs>) => Promise<any> | any;\n};\n\nfunction withValidation(\n builder: any,\n config: { args?: ArgsValidator; returns?: GenericValidator },\n) {\n let current = builder;\n if (config.args !== undefined) {\n current = current.input(config.args);\n }\n if (config.returns !== undefined) {\n current = current.returns(config.returns);\n }\n return current;\n}\n\nexport function query<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<QueryCtx, TArgs>,\n) {\n return withValidation(convex.query(), config)\n .handler(config.handler)\n .public();\n}\n\nexport function mutation<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<MutationCtx, TArgs>,\n) {\n return withValidation(convex.mutation(), config)\n .handler(config.handler)\n .public();\n}\n\nexport function internalQuery<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<QueryCtx, TArgs>,\n) {\n return withValidation(convex.query(), config)\n .handler(config.handler)\n .internal();\n}\n\nexport function internalMutation<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<MutationCtx, TArgs>,\n) {\n return withValidation(convex.mutation(), config)\n .handler(config.handler)\n .internal();\n}\n\nexport function action<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<ActionCtx, TArgs>,\n) {\n return withValidation(convex.action(), config)\n .handler(config.handler)\n .public();\n}\n\nexport function internalAction<TArgs extends ArgsValidator | undefined>(\n config: BaseFunctionConfig<ActionCtx, TArgs>,\n) {\n return withValidation(convex.action(), config)\n .handler(config.handler)\n .internal();\n}\n"],"mappings":";;;AAUA,MAAM,SAAS,eAA0B;AAiBzC,SAAS,eACP,SACA,QACA;CACA,IAAI,UAAU;AACd,KAAI,OAAO,SAAS,OAClB,WAAU,QAAQ,MAAM,OAAO,KAAK;AAEtC,KAAI,OAAO,YAAY,OACrB,WAAU,QAAQ,QAAQ,OAAO,QAAQ;AAE3C,QAAO;;AAGT,SAAgB,MACd,QACA;AACA,QAAO,eAAe,OAAO,OAAO,EAAE,OAAO,CAC1C,QAAQ,OAAO,QAAQ,CACvB,QAAQ;;AAGb,SAAgB,SACd,QACA;AACA,QAAO,eAAe,OAAO,UAAU,EAAE,OAAO,CAC7C,QAAQ,OAAO,QAAQ,CACvB,QAAQ;;AAGb,SAAgB,cACd,QACA;AACA,QAAO,eAAe,OAAO,OAAO,EAAE,OAAO,CAC1C,QAAQ,OAAO,QAAQ,CACvB,UAAU;;AAGf,SAAgB,iBACd,QACA;AACA,QAAO,eAAe,OAAO,UAAU,EAAE,OAAO,CAC7C,QAAQ,OAAO,QAAQ,CACvB,UAAU;;AAGf,SAAgB,OACd,QACA;AACA,QAAO,eAAe,OAAO,QAAQ,EAAE,OAAO,CAC3C,QAAQ,OAAO,QAAQ,CACvB,QAAQ;;AAGb,SAAgB,eACd,QACA;AACA,QAAO,eAAe,OAAO,QAAQ,EAAE,OAAO,CAC3C,QAAQ,OAAO,QAAQ,CACvB,UAAU"}