@sixb/client 0.1.23 → 0.1.24

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 (44) hide show
  1. package/dist/browser.js +2 -2
  2. package/dist/browser.js.map +1 -1
  3. package/dist/{chunk-59f4fbnk.js → chunk-14c2tg81.js} +58 -13
  4. package/dist/chunk-14c2tg81.js.map +19 -0
  5. package/dist/{chunk-263m4e9p.js → chunk-1zthvcby.js} +11 -10
  6. package/dist/{chunk-263m4e9p.js.map → chunk-1zthvcby.js.map} +4 -4
  7. package/dist/{chunk-1v736aje.js → chunk-2ezmcce2.js} +1 -1
  8. package/dist/{chunk-tttfv49k.js → chunk-4xavy5bx.js} +2 -2
  9. package/dist/{chunk-tttfv49k.js.map → chunk-4xavy5bx.js.map} +1 -1
  10. package/dist/{chunk-k2j71x7a.js → chunk-fzpxv5j5.js} +2 -2
  11. package/dist/{chunk-k2j71x7a.js.map → chunk-fzpxv5j5.js.map} +1 -1
  12. package/dist/chunk-j9t5h44d.js.map +1 -1
  13. package/dist/{chunk-9gz30dxy.js → chunk-z28fxqd0.js} +1 -1
  14. package/dist/{chunk-9gz30dxy.js.map → chunk-z28fxqd0.js.map} +1 -1
  15. package/dist/connectors/queries.d.ts.map +1 -1
  16. package/dist/generated/@tanstack/react-query.gen.d.ts +130 -12
  17. package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -1
  18. package/dist/generated/index.d.ts +2 -2
  19. package/dist/generated/index.d.ts.map +1 -1
  20. package/dist/generated/sdk.gen.d.ts +10 -4
  21. package/dist/generated/sdk.gen.d.ts.map +1 -1
  22. package/dist/generated/types.gen.d.ts +172 -41
  23. package/dist/generated/types.gen.d.ts.map +1 -1
  24. package/dist/hooks.d.ts +1 -1
  25. package/dist/hooks.d.ts.map +1 -1
  26. package/dist/hooks.js +46 -6
  27. package/dist/hooks.js.map +5 -5
  28. package/dist/index.js +8 -6
  29. package/dist/index.js.map +1 -1
  30. package/dist/logs.js +3 -3
  31. package/dist/models.js +4 -2
  32. package/dist/models.js.map +1 -1
  33. package/dist/query.js +3 -3
  34. package/dist/users-hooks.d.ts +9 -5
  35. package/dist/users-hooks.d.ts.map +1 -1
  36. package/package.json +2 -2
  37. package/src/generated/@tanstack/react-query.gen.ts +36 -3
  38. package/src/generated/index.ts +6 -0
  39. package/src/generated/sdk.gen.ts +75 -14
  40. package/src/generated/types.gen.ts +185 -41
  41. package/src/hooks.ts +1 -0
  42. package/src/users-hooks.ts +36 -5
  43. package/dist/chunk-59f4fbnk.js.map +0 -19
  44. /package/dist/{chunk-1v736aje.js.map → chunk-2ezmcce2.js.map} +0 -0
package/src/hooks.ts CHANGED
@@ -37,6 +37,7 @@ export {
37
37
  useAgentRunStream,
38
38
  } from "./useAgentRunStream"
39
39
  export {
40
+ type UserLookupInput,
40
41
  type UseUserOptions,
41
42
  type UseUsersOptions,
42
43
  userQueryOptions,
@@ -33,11 +33,18 @@ export function usersQueryOptions(options: UseUsersOptions = {}) {
33
33
  })
34
34
  }
35
35
 
36
+ /** A member by user reference, id, or email: the email matches exactly, ignoring case. */
37
+ export type UserLookupInput = UserRef | string | { readonly email: string }
38
+
36
39
  /**
37
40
  * Query options for one member, for prefetching or `useQuery`. The data is `null` when no member
38
- * has this id or the reader cannot read the directory.
41
+ * has this id or email, or the reader cannot read the directory.
39
42
  */
40
- export function userQueryOptions(user: UserRef | string, options: UseUserOptions = {}) {
43
+ export function userQueryOptions(user: UserLookupInput, options: UseUserOptions = {}) {
44
+ if (typeof user === "object" && "email" in user) {
45
+ return userByEmailQueryOptions(user.email, options)
46
+ }
47
+
41
48
  const { client, ...extras } = options
42
49
  const path = { userId: typeof user === "string" ? user : user.id }
43
50
 
@@ -63,6 +70,30 @@ export function userQueryOptions(user: UserRef | string, options: UseUserOptions
63
70
  })
64
71
  }
65
72
 
73
+ function userByEmailQueryOptions(email: string, options: UseUserOptions) {
74
+ const { client, ...extras } = options
75
+ // The server ignores case, so the cache does too.
76
+ const query = { email: email.trim().toLowerCase() }
77
+
78
+ return queryOptions<GetUserResponse | null, Error>({
79
+ ...extras,
80
+ queryKey: [{ _id: "user", query }] as const,
81
+ queryFn: async ({ signal }) => {
82
+ const { data, error, response } = await listUsers({
83
+ client,
84
+ query,
85
+ signal,
86
+ responseStyle: "fields",
87
+ throwOnError: false,
88
+ })
89
+ if (response?.status === 403) return null
90
+ if (error !== undefined) throw error
91
+
92
+ return data.users[0] ?? null
93
+ },
94
+ })
95
+ }
96
+
66
97
  /**
67
98
  * One page of the project's member directory, active members by default. Pass `status: "all"`
68
99
  * to include suspended members. Reading it requires `can.view(project.users)`.
@@ -74,11 +105,11 @@ export function useUsers(options: UseUsersOptions = {}): UseQueryResult<ListUser
74
105
  }
75
106
 
76
107
  /**
77
- * One member of the directory, from a user reference or an id: `null` when no member has it, or
78
- * without `can.view(project.users)`.
108
+ * One member of the directory, from a user reference, an id, or `{ email }`: `null` when no member
109
+ * has it, or without `can.view(project.users)`.
79
110
  */
80
111
  export function useUser(
81
- user: UserRef | string,
112
+ user: UserLookupInput,
82
113
  options: UseUserOptions = {}
83
114
  ): UseQueryResult<GetUserResponse | null, Error> {
84
115
  const providerClient = useSixbProviderClient()