@jsb188/app 1.1.5 → 1.1.6

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/utils/user.ts CHANGED
@@ -1,28 +1,8 @@
1
-
2
1
  /**
3
2
  * Types
4
3
  */
5
4
 
6
5
  type LightModeValue = 'LIGHT' | 'DARK' | 'SYSTEM';
7
- type FriendStatusEnum = 'BLOCKED' | 'DECLINED' | 'PENDING' | 'ACCEPTED';
8
-
9
- interface FriendFragment {
10
- myStatus: FriendStatusEnum;
11
- otherStatus: FriendStatusEnum;
12
- }
13
-
14
- interface FriendOptionsObj {
15
- friendButtonText: string;
16
- friendButtonIconName: string;
17
- friendStatusText: string;
18
- messageAllowed: boolean;
19
- options: {
20
- value: string;
21
- iconName: string;
22
- text: string;
23
- }[];
24
- }
25
-
26
6
  type PlusGroupEnum = 'NORMAL' | 'PERKS' | 'PLUS' | 'PRO';
27
7
 
28
8
  interface UserSubOutput {
@@ -68,7 +48,7 @@ export function updateLightMode(mode_: string | undefined, newValue: LightModeVa
68
48
  * Resolve user's online status for chat
69
49
  */
70
50
 
71
- export function resolveOnlineStatus(user: object, viewerUserId: number) {
51
+ export function resolveOnlineStatus(user: any, viewerUserId: number) {
72
52
  // console.log('..... RESOLVE ONLINE STATUS .....', user.id, viewerUserId, user.onlineStatus);
73
53
  if (
74
54
  // This check won't be valid if user is switching logins;
@@ -1,12 +0,0 @@
1
- // Organization constants
2
- // IMPORTANT NOTE: Array order must *never* change, indexes are used to create PDF URLs
3
-
4
- export const OPERATION_ENUMS = ['ARABLE', 'LIVESTOCK'];
5
-
6
- // Employee ACL
7
-
8
- export const ROLE_ENUMS = ['MEMBER', 'MANAGER', 'ADMIN', 'OWNER']; // first is default value
9
-
10
- // Role categories (used for reminders)
11
-
12
- export const ROLE_CATEGORY_ENUMS = ['EMPLOYEES_ONLY', 'MANAGERS_ONLY'];
package/constants/ws.ts DELETED
@@ -1,47 +0,0 @@
1
- const WS_ACTIONS = {
2
- // Socket connection
3
- connect: 'connect',
4
- disconnect: 'disconnect',
5
- auth: 'auth',
6
-
7
- // App
8
- alert: 'alrt',
9
- data_update: 'du',
10
-
11
- // User
12
- me: 'me:',
13
- user_status: 'us:',
14
-
15
- // Chats list
16
- chats_list: 'cl:',
17
-
18
- // Chat
19
- chat_join: 'cj:',
20
- chat_leave_all: 'cla',
21
- chat_typing: 'ct',
22
- chat_message: 'cm',
23
- chat_read: 'cr',
24
- chat_moderate: 'cmd',
25
-
26
- // Live chats
27
- live_list: 'll:',
28
- live_list_stop: 'lls',
29
- live_start: 'lsr',
30
- live_stop: 'lsp',
31
- live_join: 'uslj',
32
- live_leave: 'usll',
33
- live_users_list: 'lul',
34
-
35
- // Peer
36
- peer_call: 'pc:',
37
- peer_accept: 'pa:',
38
- peer_decline: 'pd:',
39
- peer_leave: 'pl',
40
- peer_join: 'pj',
41
- peer_speaking: 'ps',
42
- peer_user_id: 'pui',
43
- peer_users_sync: 'pus',
44
- peer_users_list: 'pul',
45
- };
46
-
47
- export default WS_ACTIONS;
@@ -1,94 +0,0 @@
1
- import { OPERATION_ENUMS, ROLE_ENUMS, ROLE_CATEGORY_ENUMS } from '../constants/organization.ts';
2
-
3
- /*
4
- * ACL
5
- */
6
-
7
- export type OrganizationRoleEnum = typeof ROLE_ENUMS[number];
8
- export type OrganizationOperationEnum = typeof OPERATION_ENUMS[number];
9
- export type OrganizationRoleCategoryEnum = typeof ROLE_CATEGORY_ENUMS[number];
10
-
11
- type ACLPermission = 0 | 1 | 2 | 3; // 0: no access, 1: read-only, 2: allow-write, 3: allow-manage
12
- type ACLPermissionEnum = 'NONE' | 'READ' | 'WRITE' | 'MANAGE';
13
-
14
- export interface OrganizationACL {
15
- id: string;
16
- billing: ACLPermission;
17
- logs: ACLPermission;
18
- members: ACLPermission;
19
- finances: ACLPermission;
20
- settings: ACLPermission;
21
- integrations: ACLPermission;
22
- digests: ACLPermission;
23
- reminders: ACLPermission;
24
- }
25
-
26
- export interface OrganizationACLGQLData {
27
- id: string;
28
- billing: ACLPermissionEnum;
29
- logs: ACLPermissionEnum;
30
- members: ACLPermissionEnum;
31
- finances: ACLPermissionEnum;
32
- settings: ACLPermissionEnum;
33
- integrations: ACLPermissionEnum;
34
- digests: ACLPermissionEnum;
35
- reminders: ACLPermissionEnum;
36
- }
37
-
38
- /**
39
- * Organization object
40
- */
41
-
42
- export interface OrganizationShortData {
43
- id: string;
44
- name: string;
45
- primary: boolean;
46
- acl: OrganizationACL;
47
- }
48
-
49
- export interface OrganizationData {
50
- id: number;
51
- stripeCustomerId: string | null;
52
- name: string;
53
- operation: OrganizationOperationEnum;
54
- dailyDigestTime: string | null;
55
- reminders: string | null;
56
- domains: string[] | null;
57
- settings?: {
58
- emoji: string | null;
59
- timeZone: string | null;
60
- }
61
- }
62
-
63
- /**
64
- * Full organization object with relationship
65
- */
66
-
67
- export interface OrganizationRelData {
68
- id: string;
69
- primary: boolean;
70
- role: OrganizationRoleEnum;
71
- acl: OrganizationACL;
72
- organization: OrganizationData;
73
- }
74
-
75
- /**
76
- * GraphQL data for organization relationship
77
- */
78
-
79
- export interface OrganizationGQLData {
80
- id: string;
81
- name: string;
82
- stripeCustomerId: string | null;
83
- reminders: string | null;
84
- domains: string[] | null;
85
- membersCount: number;
86
- }
87
-
88
- export interface OrganizationRelGQLData {
89
- id: string;
90
- primary: boolean;
91
- role: OrganizationRoleEnum;
92
- acl: OrganizationACLGQLData;
93
- organization: OrganizationGQLData;
94
- }
@@ -1,102 +0,0 @@
1
- import { OrganizationRelData, OrganizationRelGQLData } from '../types/organization.d';
2
-
3
- // Placeholder to match Server import
4
- type ViewerOrganization = any;
5
-
6
- const PERMISSION_TO_INT = {
7
- NONE: 0,
8
- READ: 1,
9
- WRITE: 2,
10
- MANAGE: 3,
11
- };
12
-
13
- const INT_TO_PERMISSION = Object.keys(PERMISSION_TO_INT);
14
-
15
- /**
16
- * Get default permissions by role
17
- */
18
-
19
- export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQLData | OrganizationRelData | ViewerOrganization) {
20
- const role = orgRel?.role || 'MEMBER';
21
- const acl: Record<string, any> = { ...orgRel?.acl };
22
-
23
- for (const key in acl) {
24
- if (typeof acl[key] === 'number') {
25
- acl[key] = INT_TO_PERMISSION[acl[key]] || 'NONE';
26
- }
27
- }
28
-
29
- // Also keep this synced with [resolvers/organizationTypeResolvers.ts]
30
-
31
- // 0 = "NONE"
32
- // 1 = "READ"
33
- // 2 = "WRITE"
34
- // 3 = "MANAGE"
35
-
36
- switch (role) {
37
- case 'ADMIN':
38
- case 'OWNER':
39
- return {
40
- billing: acl.billing || 'MANAGE',
41
- digests: acl.digests || 'MANAGE', // 2/3 = receive digests, 1 = only see from web app
42
- logs: acl.logs || 'MANAGE', // "READ" for logs does nothing
43
- viewData: acl.viewData || 'MANAGE', // This blocks access from users being able to read other people's logs
44
- members: acl.members || 'MANAGE',
45
- finances: acl.finances || 'MANAGE',
46
- settings: acl.settings || 'MANAGE',
47
- integrations: acl.integrations || 'MANAGE',
48
- reminders: acl.reminders || 'MANAGE',
49
- };
50
- case 'MANAGER':
51
- return {
52
- billing: acl.billing || 'READ',
53
- digests: acl.digests || 'WRITE', // 2/3 = receive digests, 1 = only see from web app
54
- logs: acl.logs || 'MANAGE', // "READ" for logs does nothing
55
- viewData: acl.viewData || 'MANAGE', // This blocks access from users being able to read other people's logs
56
- members: acl.members || 'WRITE',
57
- finances: acl.finances || 'READ',
58
- settings: acl.settings || 'READ',
59
- integrations: acl.integrations || 'NONE',
60
- reminders: acl.reminders || 'MANAGE',
61
- };
62
- case 'MEMBER':
63
- default:
64
- }
65
-
66
- return {
67
- billing: acl.billing || 'NONE',
68
- digests: acl.digests || 'NONE', // 2/3 = receive digests, 1 = only see from web app
69
- logs: acl.logs || 'WRITE', // "READ" for logs does nothing
70
- viewData: acl.viewData || 'NONE', // This blocks access from users being able to read other people's logs
71
- members: acl.members || 'READ',
72
- finances: acl.finances || 'NONE',
73
- settings: acl.settings || 'READ',
74
- integrations: acl.integrations || 'NONE',
75
- reminders: acl.reminders || 'WRITE',
76
- };
77
- }
78
-
79
- /**
80
- * Check if this account's ACL has required permissions for an action
81
- */
82
-
83
- export type ACLPermissionCheck = 'READ' | 'WRITE' | 'MANAGE';
84
- export type PermissionCheckFor = keyof ReturnType<typeof getDefaultPermissionsByRole>;
85
-
86
- export function checkACLPermission(
87
- orgRel: OrganizationRelGQLData | OrganizationRelData | ViewerOrganization,
88
- check: PermissionCheckFor,
89
- requiredPermission: ACLPermissionCheck,
90
- ): boolean | null {
91
- if (!orgRel) {
92
- return null;
93
- }
94
-
95
- const acl = getDefaultPermissionsByRole(orgRel);
96
-
97
- const requiredInt = PERMISSION_TO_INT[requiredPermission] || 4; // If invalid, it will always return false
98
- const permission = acl[check] as ACLPermissionCheck;
99
- const acccountPermissionInt = PERMISSION_TO_INT[permission] || 0; // If invalid, it will always return false
100
-
101
- return acccountPermissionInt >= requiredInt;
102
- }