@sixb/client 0.1.22 → 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.
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-59f4fbnk.js → chunk-14c2tg81.js} +58 -13
- package/dist/chunk-14c2tg81.js.map +19 -0
- package/dist/{chunk-263m4e9p.js → chunk-1zthvcby.js} +11 -10
- package/dist/{chunk-263m4e9p.js.map → chunk-1zthvcby.js.map} +4 -4
- package/dist/{chunk-1v736aje.js → chunk-2ezmcce2.js} +1 -1
- package/dist/{chunk-tttfv49k.js → chunk-4xavy5bx.js} +2 -2
- package/dist/{chunk-tttfv49k.js.map → chunk-4xavy5bx.js.map} +1 -1
- package/dist/{chunk-k2j71x7a.js → chunk-fzpxv5j5.js} +2 -2
- package/dist/{chunk-k2j71x7a.js.map → chunk-fzpxv5j5.js.map} +1 -1
- package/dist/chunk-j9t5h44d.js.map +1 -1
- package/dist/{chunk-9gz30dxy.js → chunk-z28fxqd0.js} +1 -1
- package/dist/{chunk-9gz30dxy.js.map → chunk-z28fxqd0.js.map} +1 -1
- package/dist/connectors/queries.d.ts.map +1 -1
- package/dist/generated/@tanstack/react-query.gen.d.ts +142 -12
- package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/sdk.gen.d.ts +10 -4
- package/dist/generated/sdk.gen.d.ts.map +1 -1
- package/dist/generated/types.gen.d.ts +184 -41
- package/dist/generated/types.gen.d.ts.map +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +46 -6
- package/dist/hooks.js.map +5 -5
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/logs.js +3 -3
- package/dist/models.js +4 -2
- package/dist/models.js.map +1 -1
- package/dist/query.js +3 -3
- package/dist/users-hooks.d.ts +9 -5
- package/dist/users-hooks.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/generated/@tanstack/react-query.gen.ts +36 -3
- package/src/generated/index.ts +6 -0
- package/src/generated/sdk.gen.ts +75 -14
- package/src/generated/types.gen.ts +207 -49
- package/src/hooks.ts +1 -0
- package/src/users-hooks.ts +36 -5
- package/dist/chunk-59f4fbnk.js.map +0 -19
- /package/dist/{chunk-1v736aje.js.map → chunk-2ezmcce2.js.map} +0 -0
package/src/hooks.ts
CHANGED
package/src/users-hooks.ts
CHANGED
|
@@ -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:
|
|
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
|
|
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:
|
|
112
|
+
user: UserLookupInput,
|
|
82
113
|
options: UseUserOptions = {}
|
|
83
114
|
): UseQueryResult<GetUserResponse | null, Error> {
|
|
84
115
|
const providerClient = useSixbProviderClient()
|