@gopherium/react-auth 0.5.0 → 0.6.0

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.
@@ -5,7 +5,7 @@ declare const userSchema: z.ZodObject<{
5
5
  email: z.ZodString;
6
6
  name: z.ZodString;
7
7
  disabled: z.ZodBoolean;
8
- rank: z.ZodDefault<z.ZodString>;
8
+ role: z.ZodDefault<z.ZodString>;
9
9
  created_at: z.ZodCoercedDate<unknown>;
10
10
  }, z.core.$strip>;
11
11
  export type User = z.infer<typeof userSchema>;
@@ -13,7 +13,7 @@ export interface NewUser {
13
13
  email: string;
14
14
  name: string;
15
15
  password: string;
16
- rank?: string;
16
+ role?: string;
17
17
  }
18
18
  /**
19
19
  * EmailTakenError is thrown when a new user's email is already in use.
@@ -27,18 +27,18 @@ export declare class EmailTakenError extends Error {
27
27
  export declare class ValidationError extends Error {
28
28
  }
29
29
  /**
30
- * RankRefusedError is thrown when the actor holds no rank the server admits.
30
+ * RoleRefusedError is thrown when the actor holds no role the server admits.
31
31
  */
32
- export declare class RankRefusedError extends Error {
32
+ export declare class RoleRefusedError extends Error {
33
33
  }
34
34
  /**
35
- * SelfRankError is thrown when an account changes its own rank.
35
+ * SelfRoleError is thrown when an account changes its own role.
36
36
  */
37
- export declare class SelfRankError extends Error {
37
+ export declare class SelfRoleError extends Error {
38
38
  }
39
39
  /**
40
40
  * LastPrivilegedError is thrown when a write would leave no enabled
41
- * account holding a privileged rank.
41
+ * account holding a privileged role.
42
42
  */
43
43
  export declare class LastPrivilegedError extends Error {
44
44
  }
@@ -61,9 +61,9 @@ export declare function createUser(input: NewUser): Promise<User>;
61
61
  */
62
62
  export declare function setUserDisabled(id: string, disabled: boolean): Promise<void>;
63
63
  /**
64
- * Sets the rank an account holds.
64
+ * Sets the role an account holds.
65
65
  * @param id - The identifier of the account to update.
66
- * @param rank - The rank the account is to hold.
66
+ * @param role - The role the account is to hold.
67
67
  */
68
- export declare function setUserRank(id: string, rank: string): Promise<void>;
68
+ export declare function setUserRole(id: string, role: string): Promise<void>;
69
69
  export {};
@@ -10,7 +10,7 @@ const userSchema = z.object({
10
10
  email: z.string(),
11
11
  name: z.string(),
12
12
  disabled: z.boolean(),
13
- rank: z.string().default(''),
13
+ role: z.string().default(''),
14
14
  created_at: z.coerce.date(),
15
15
  });
16
16
  /**
@@ -25,18 +25,18 @@ export class EmailTakenError extends Error {
25
25
  export class ValidationError extends Error {
26
26
  }
27
27
  /**
28
- * RankRefusedError is thrown when the actor holds no rank the server admits.
28
+ * RoleRefusedError is thrown when the actor holds no role the server admits.
29
29
  */
30
- export class RankRefusedError extends Error {
30
+ export class RoleRefusedError extends Error {
31
31
  }
32
32
  /**
33
- * SelfRankError is thrown when an account changes its own rank.
33
+ * SelfRoleError is thrown when an account changes its own role.
34
34
  */
35
- export class SelfRankError extends Error {
35
+ export class SelfRoleError extends Error {
36
36
  }
37
37
  /**
38
38
  * LastPrivilegedError is thrown when a write would leave no enabled
39
- * account holding a privileged rank.
39
+ * account holding a privileged role.
40
40
  */
41
41
  export class LastPrivilegedError extends Error {
42
42
  }
@@ -114,15 +114,15 @@ async function restSetUserDisabled(id, disabled) {
114
114
  }
115
115
  }
116
116
  /**
117
- * Writes the rank an account holds over REST.
117
+ * Writes the role an account holds over REST.
118
118
  * @param id - The identifier of the account to update.
119
- * @param rank - The rank the account is to hold.
119
+ * @param role - The role the account is to hold.
120
120
  */
121
- async function restSetUserRank(id, rank) {
122
- const response = await fetch(`/api/users/${id}/rank`, {
121
+ async function restSetUserRole(id, role) {
122
+ const response = await fetch(`/api/users/${id}/role`, {
123
123
  method: 'PUT',
124
124
  headers: { 'Content-Type': 'application/json' },
125
- body: JSON.stringify({ rank }),
125
+ body: JSON.stringify({ role }),
126
126
  });
127
127
  if (response.ok) {
128
128
  return;
@@ -131,16 +131,16 @@ async function restSetUserRank(id, rank) {
131
131
  throw new UnauthorizedError('session expired');
132
132
  }
133
133
  const refusal = await refusalOf(response);
134
- if (refusal.code === 'rank_insufficient') {
135
- throw new RankRefusedError(refusal.message);
134
+ if (refusal.code === 'role_insufficient') {
135
+ throw new RoleRefusedError(refusal.message);
136
136
  }
137
- if (refusal.code === 'self_rank_refused') {
138
- throw new SelfRankError(refusal.message);
137
+ if (refusal.code === 'self_role_refused') {
138
+ throw new SelfRoleError(refusal.message);
139
139
  }
140
140
  if (refusal.code === 'last_privileged_refused') {
141
141
  throw new LastPrivilegedError(refusal.message);
142
142
  }
143
- throw new Error(`updating rank failed with status ${response.status}`);
143
+ throw new Error(`updating role failed with status ${response.status}`);
144
144
  }
145
145
  /**
146
146
  * Returns the code and message a refused response carries.
@@ -181,10 +181,10 @@ export async function setUserDisabled(id, disabled) {
181
181
  await resolveTransport('setUserDisabled', restSetUserDisabled)(id, disabled);
182
182
  }
183
183
  /**
184
- * Sets the rank an account holds.
184
+ * Sets the role an account holds.
185
185
  * @param id - The identifier of the account to update.
186
- * @param rank - The rank the account is to hold.
186
+ * @param role - The role the account is to hold.
187
187
  */
188
- export async function setUserRank(id, rank) {
189
- await resolveTransport('setUserRank', restSetUserRank)(id, rank);
188
+ export async function setUserRole(id, role) {
189
+ await resolveTransport('setUserRole', restSetUserRole)(id, role);
190
190
  }
package/dist/api.d.ts CHANGED
@@ -3,7 +3,7 @@ declare const userSchema: z.ZodObject<{
3
3
  id: z.ZodString;
4
4
  email: z.ZodString;
5
5
  name: z.ZodString;
6
- rank: z.ZodDefault<z.ZodString>;
6
+ role: z.ZodDefault<z.ZodString>;
7
7
  }, z.core.$strip>;
8
8
  export type User = z.infer<typeof userSchema>;
9
9
  /**
package/dist/api.js CHANGED
@@ -5,7 +5,7 @@ const userSchema = z.object({
5
5
  id: z.string(),
6
6
  email: z.string(),
7
7
  name: z.string(),
8
- rank: z.string().default(''),
8
+ role: z.string().default(''),
9
9
  });
10
10
  /**
11
11
  * InvalidCredentialsError is thrown when the backend rejects a login.
package/dist/session.d.ts CHANGED
@@ -10,7 +10,7 @@ export declare function useSession(): import("@tanstack/react-query").UseQueryRe
10
10
  id: string;
11
11
  email: string;
12
12
  name: string;
13
- rank: string;
13
+ role: string;
14
14
  } | null>, Error>;
15
15
  /**
16
16
  * Ends the current session and drops all cached data belonging to the
@@ -12,16 +12,16 @@ export declare function installTestEnvironment(): void;
12
12
  */
13
13
  export declare const defaultUser: User;
14
14
  /**
15
- * Returns a canned account holding the given rank, one identifier per rank.
16
- * @param rank - The rank the account holds.
15
+ * Returns a canned account holding the given role, one identifier per role.
16
+ * @param role - The role the account holds.
17
17
  * @returns The account.
18
18
  */
19
- export declare function rankedUser(rank: string): User;
19
+ export declare function userWithRole(role: string): User;
20
20
  /**
21
- * Accepts a rank change.
21
+ * Accepts a role change.
22
22
  * @returns The msw handler.
23
23
  */
24
- export declare function rankOk(): import("msw").HttpHandler;
24
+ export declare function roleOk(): import("msw").HttpHandler;
25
25
  /**
26
26
  * Seeds the cached session so components render signed in without a fetch.
27
27
  * @param client - The query client under test.
@@ -25,33 +25,33 @@ export const defaultUser = {
25
25
  id: '0198b2f0-0000-7000-8000-000000000001',
26
26
  email: 'grace@example.com',
27
27
  name: 'Grace Hopper',
28
- rank: '',
28
+ role: '',
29
29
  };
30
30
  /**
31
- * Returns a canned account holding the given rank, one identifier per rank.
32
- * @param rank - The rank the account holds.
31
+ * Returns a canned account holding the given role, one identifier per role.
32
+ * @param role - The role the account holds.
33
33
  * @returns The account.
34
34
  */
35
- export function rankedUser(rank) {
35
+ export function userWithRole(role) {
36
36
  let held = 2166136261;
37
- for (const letter of rank) {
37
+ for (const letter of role) {
38
38
  held ^= letter.charCodeAt(0);
39
39
  held = Math.imul(held, 16777619);
40
40
  }
41
41
  held >>>= 0;
42
42
  return {
43
43
  id: `0198b2f0-0000-7000-8000-${String(held).padStart(12, '0')}`,
44
- email: `${rank}@example.com`,
45
- name: `Maria Perez the ${rank}`,
46
- rank,
44
+ email: `${role}@example.com`,
45
+ name: `Maria Perez the ${role}`,
46
+ role,
47
47
  };
48
48
  }
49
49
  /**
50
- * Accepts a rank change.
50
+ * Accepts a role change.
51
51
  * @returns The msw handler.
52
52
  */
53
- export function rankOk() {
54
- return http.put('/api/users/:id/rank', () => new HttpResponse(null, { status: 204 }));
53
+ export function roleOk() {
54
+ return http.put('/api/users/:id/role', () => new HttpResponse(null, { status: 204 }));
55
55
  }
56
56
  /**
57
57
  * Seeds the cached session so components render signed in without a fetch.
@@ -14,7 +14,7 @@ export interface AuthTransport {
14
14
  fetchUsers(signal?: AbortSignal): Promise<Account[]>;
15
15
  createUser(input: NewUser): Promise<Account>;
16
16
  setUserDisabled(id: string, disabled: boolean): Promise<void>;
17
- setUserRank(id: string, rank: string): Promise<void>;
17
+ setUserRole(id: string, role: string): Promise<void>;
18
18
  }
19
19
  /**
20
20
  * Replaces backend calls with the given implementations, keeping the REST
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/react-auth",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Session authentication for React apps backed by gouncer's authkit.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",