@star-insure/sdk 2.5.2 → 3.0.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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@star-insure/sdk",
3
3
  "description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
4
4
  "author": "alexclark_nz",
5
- "version": "2.5.2",
5
+ "version": "3.0.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/src/lib/auth.tsx CHANGED
@@ -14,5 +14,15 @@ interface AppPage extends Page {
14
14
  export function useAuth(): AuthContext {
15
15
  const { props } = usePage() as AppPage;
16
16
 
17
- return props.auth;
17
+ /**
18
+ * Check if the user has permission to perform the given ability.
19
+ */
20
+ function can(ability: string): boolean {
21
+ return props.auth.permissions.includes(ability);
22
+ }
23
+
24
+ return {
25
+ ...props.auth,
26
+ can,
27
+ };
18
28
  }
@@ -1,11 +1,37 @@
1
- import { User, Group } from "../models";
1
+ export type UserContext =
2
+ | 'staff'
3
+ | 'broker'
4
+ | 'agent'
5
+ | 'security'
6
+ | 'customer';
2
7
 
3
- export type UserContext = 'administrator' | 'staff' | 'broker' | 'agent' | 'security' | 'customer';
8
+ type AuthUser = {
9
+ id: number;
10
+ name: string;
11
+ email: string;
12
+ is_group_admin: boolean;
13
+ umbrella_filter?: string;
14
+ oracle_user_id?: string;
15
+ groups: AuthGroup[];
16
+ };
17
+
18
+ type AuthGroup = {
19
+ id: number;
20
+ name: string;
21
+ code: string;
22
+ role: AuthRole;
23
+ };
24
+
25
+ type AuthRole = {
26
+ name: string;
27
+ context: string;
28
+ };
4
29
 
5
30
  export interface AuthContext {
6
- user?: User;
7
- context?: UserContext;
8
- group?: Group;
9
- permissions: string[];
10
- is_app?: boolean;
31
+ user?: AuthUser;
32
+ context: UserContext;
33
+ group?: AuthGroup;
34
+ permissions: string[];
35
+ is_app?: boolean;
36
+ can: (permission: string) => boolean;
11
37
  }
@@ -1,14 +1,15 @@
1
- import { Group } from ".";
1
+ import { Group } from '.';
2
2
 
3
3
  export interface User {
4
- id: number;
5
- oracle_user_id?: string;
6
- name: string;
7
- email: string;
8
- mobile?: string;
9
- direct_dial?: string;
10
- position?: string;
11
- is_group_admin?: boolean;
12
- umbrella_filter?: string;
13
- groups?: Group[];
4
+ id: number;
5
+ oracle_user_id?: string;
6
+ name: string;
7
+ email: string;
8
+ mobile?: string;
9
+ direct_dial?: string;
10
+ position?: string;
11
+ is_group_admin?: boolean;
12
+ umbrella_filter?: string;
13
+ groups?: Group[];
14
+ permissions?: string[];
14
15
  }