@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/dist/sdk.cjs.development.js +168 -158
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +168 -158
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/api/auth.d.ts +25 -5
- package/dist/types/models/auth/User.d.ts +2 -1
- package/package.json +1 -1
- package/src/lib/auth.tsx +11 -1
- package/src/types/api/auth.ts +33 -7
- package/src/types/models/auth/User.ts +12 -11
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": "
|
|
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
|
-
|
|
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
|
}
|
package/src/types/api/auth.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
export type UserContext =
|
|
2
|
+
| 'staff'
|
|
3
|
+
| 'broker'
|
|
4
|
+
| 'agent'
|
|
5
|
+
| 'security'
|
|
6
|
+
| 'customer';
|
|
2
7
|
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
}
|