@robelest/convex-auth 0.0.4-preview.36 → 0.0.4-preview.37

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.
@@ -1,4 +1,4 @@
1
- import { vGroupDoc, vGroupInviteDoc, vGroupMemberDoc, vPaginated, vUserDoc, vUserEmailDoc } from "../component/model.js";
1
+ import { vGroupConnectionPolicy, vInviteStatus, vPaginated, vTag, vUserEmailSource } from "../component/model.js";
2
2
  import { v } from "convex/values";
3
3
 
4
4
  //#region src/server/validators.ts
@@ -15,18 +15,80 @@ import { v } from "convex/values";
15
15
  *
16
16
  * @module
17
17
  */
18
+ /** `Id<T>` at the type level, `v.string()` at runtime — for cross-component fields. */
19
+ const vIdString = (_table) => v.string();
18
20
  const docWithExtend = (fields, extend) => v.object({
19
21
  ...fields,
20
22
  extend: v.optional(extend)
21
23
  });
24
+ const userFieldsX = {
25
+ _id: vIdString("User"),
26
+ _creationTime: v.number(),
27
+ name: v.optional(v.string()),
28
+ image: v.optional(v.string()),
29
+ email: v.optional(v.string()),
30
+ emailVerificationTime: v.optional(v.number()),
31
+ phone: v.optional(v.string()),
32
+ phoneVerificationTime: v.optional(v.number()),
33
+ isAnonymous: v.optional(v.boolean()),
34
+ lastActiveGroup: v.optional(vIdString("Group")),
35
+ hasTotp: v.optional(v.boolean()),
36
+ extend: v.optional(v.any())
37
+ };
38
+ const groupFieldsX = {
39
+ _id: vIdString("Group"),
40
+ _creationTime: v.number(),
41
+ name: v.string(),
42
+ slug: v.optional(v.string()),
43
+ type: v.optional(v.string()),
44
+ parentGroupId: v.optional(vIdString("Group")),
45
+ rootGroupId: v.optional(vIdString("Group")),
46
+ isRoot: v.optional(v.boolean()),
47
+ tags: v.optional(v.array(vTag)),
48
+ policy: v.optional(vGroupConnectionPolicy),
49
+ extend: v.optional(v.any())
50
+ };
51
+ const memberFieldsX = {
52
+ _id: vIdString("GroupMember"),
53
+ _creationTime: v.number(),
54
+ groupId: vIdString("Group"),
55
+ userId: vIdString("User"),
56
+ role: v.optional(v.string()),
57
+ roleIds: v.optional(v.array(v.string())),
58
+ status: v.optional(v.string()),
59
+ extend: v.optional(v.any())
60
+ };
61
+ const inviteDocX = v.object({
62
+ _id: vIdString("GroupInvite"),
63
+ _creationTime: v.number(),
64
+ groupId: v.optional(vIdString("Group")),
65
+ invitedByUserId: v.optional(vIdString("User")),
66
+ email: v.optional(v.string()),
67
+ tokenHash: v.string(),
68
+ role: v.optional(v.string()),
69
+ roleIds: v.optional(v.array(v.string())),
70
+ status: vInviteStatus,
71
+ expiresTime: v.optional(v.number()),
72
+ acceptedByUserId: v.optional(vIdString("User")),
73
+ acceptedTime: v.optional(v.number()),
74
+ extend: v.optional(v.any())
75
+ });
76
+ const emailDocX = v.object({
77
+ _id: vIdString("UserEmail"),
78
+ _creationTime: v.number(),
79
+ userId: vIdString("User"),
80
+ email: v.string(),
81
+ verificationTime: v.optional(v.number()),
82
+ isPrimary: v.boolean(),
83
+ source: vUserEmailSource,
84
+ accountId: v.optional(vIdString("Account")),
85
+ provider: v.optional(v.string()),
86
+ connectionId: v.optional(vIdString("GroupConnection"))
87
+ });
22
88
  /**
23
89
  * Build the `auth.v.*` validator namespace from the consumer's `extend`
24
- * config.
25
- *
26
- * `vUserDoc`/`vGroupDoc`/`vGroupMemberDoc` already declare an
27
- * `extend: v.optional(v.any())` field; this rebuilds each with the
28
- * supplied validator so the inferred type carries the real shape while
29
- * the runtime validator still accepts the stored document.
90
+ * config. Each doc validator's `extend` field is rebuilt with the
91
+ * supplied validator so the inferred type carries the real shape.
30
92
  *
31
93
  * @typeParam TExtend - The consumer's per-table `extend` validators.
32
94
  * @param extend - The `extend` map from `createAuth` config. Defaults to
@@ -43,13 +105,13 @@ const docWithExtend = (fields, extend) => v.object({
43
105
  * ```
44
106
  */
45
107
  function buildAuthValidators(extend = {}) {
46
- const user = docWithExtend(vUserDoc.fields, extend.User ?? v.any());
108
+ const user = docWithExtend(userFieldsX, extend.User ?? v.any());
47
109
  return {
48
110
  user,
49
- group: docWithExtend(vGroupDoc.fields, extend.Group ?? v.any()),
50
- member: docWithExtend(vGroupMemberDoc.fields, extend.GroupMember ?? v.any()),
51
- invite: vGroupInviteDoc,
52
- email: vUserEmailDoc,
111
+ group: docWithExtend(groupFieldsX, extend.Group ?? v.any()),
112
+ member: docWithExtend(memberFieldsX, extend.GroupMember ?? v.any()),
113
+ invite: inviteDocX,
114
+ email: emailDocX,
53
115
  viewer: v.union(user, v.null()),
54
116
  list: vPaginated
55
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robelest/convex-auth",
3
- "version": "0.0.4-preview.36",
3
+ "version": "0.0.4-preview.37",
4
4
  "description": "Authentication for Convex",
5
5
  "keywords": [
6
6
  "auth",