@messenger-box/platform-client 10.0.3-alpha.16 → 10.0.3-alpha.160

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/lib/graphql/fragments/post-message.gql +36 -0
  3. package/lib/graphql/id-generation.js.map +1 -1
  4. package/lib/graphql/index.js.map +1 -1
  5. package/lib/graphql/mutations/channel-mutation.gql +5 -0
  6. package/lib/graphql/mutations/messages-mutation.gql +29 -0
  7. package/lib/graphql/policies/channel-policies.d.ts.map +1 -1
  8. package/lib/graphql/policies/channel-policies.js +150 -2
  9. package/lib/graphql/policies/channel-policies.js.map +1 -1
  10. package/lib/graphql/policies/messages-policies.d.ts.map +1 -1
  11. package/lib/graphql/policies/messages-policies.js +229 -37
  12. package/lib/graphql/policies/messages-policies.js.map +1 -1
  13. package/lib/graphql/policies/post-thread-policies.d.ts.map +1 -1
  14. package/lib/graphql/policies/post-thread-policies.js +136 -31
  15. package/lib/graphql/policies/post-thread-policies.js.map +1 -1
  16. package/lib/graphql/policies/posts-policies.js.map +1 -1
  17. package/lib/graphql/policies/teams-policies.d.ts.map +1 -1
  18. package/lib/graphql/policies/teams-policies.js +13 -1
  19. package/lib/graphql/policies/teams-policies.js.map +1 -1
  20. package/lib/graphql/policies/user-account-policies.js.map +1 -1
  21. package/lib/graphql/policies/user-policies.js.map +1 -1
  22. package/lib/graphql/queries/channels-by-user.gql +26 -0
  23. package/lib/graphql/queries/messages.gql +2 -2
  24. package/lib/graphql/queries/organization-query.gql +70 -35
  25. package/lib/graphql/queries/post-thread-message.gql +4 -0
  26. package/lib/graphql/queries/teams-query.gql +29 -29
  27. package/lib/graphql/queries/user-account.gql +1 -1
  28. package/lib/graphql/queries/users.gql +1 -1
  29. package/lib/graphql/schema/index.js.map +1 -1
  30. package/lib/graphql/subscription/fileUpdated.gql +11 -0
  31. package/lib/graphql/subscription/sandboxError.gql +17 -0
  32. package/lib/hooks/use-base-file-upload.hook.d.ts.map +1 -1
  33. package/lib/hooks/use-upload-file.hook.d.ts +1 -1
  34. package/lib/hooks/use-upload-file.hook.d.ts.map +1 -1
  35. package/lib/hooks/use-upload-file.hook.js +1 -1
  36. package/lib/hooks/use-upload-file.hook.js.map +1 -1
  37. package/lib/hooks/use-upload-file.hook.native.d.ts +1 -1
  38. package/lib/hooks/use-upload-file.hook.native.d.ts.map +1 -1
  39. package/lib/hooks/use-upload-file.hook.native.js +1 -1
  40. package/lib/hooks/use-upload-file.hook.native.js.map +1 -1
  41. package/lib/hooks/use-upload-files.hook.d.ts +1 -1
  42. package/lib/hooks/use-upload-files.hook.d.ts.map +1 -1
  43. package/lib/hooks/use-upload-files.hook.js +1 -1
  44. package/lib/hooks/use-upload-files.hook.js.map +1 -1
  45. package/lib/hooks/use-upload-files.hook.native.d.ts +1 -1
  46. package/lib/hooks/use-upload-files.hook.native.d.ts.map +1 -1
  47. package/lib/hooks/use-upload-files.hook.native.js +1 -1
  48. package/lib/hooks/use-upload-files.hook.native.js.map +1 -1
  49. package/lib/utils/index.d.ts.map +1 -1
  50. package/lib/utils/index.js.map +1 -1
  51. package/package.json +4 -4
  52. package/src/graphql/fragments/post-message.gql +36 -0
  53. package/src/graphql/mutations/channel-mutation.gql +5 -0
  54. package/src/graphql/mutations/messages-mutation.gql +3 -0
  55. package/src/graphql/policies/channel-policies.ts +148 -2
  56. package/src/graphql/policies/messages-policies.ts +251 -39
  57. package/src/graphql/policies/post-thread-policies.ts +151 -31
  58. package/src/graphql/policies/teams-policies.ts +13 -1
  59. package/src/graphql/queries/channels-by-user.gql +26 -0
  60. package/src/graphql/queries/messages.gql +2 -2
  61. package/src/graphql/queries/organization-query.gql +70 -35
  62. package/src/graphql/queries/post-thread-message.gql +4 -0
  63. package/src/graphql/queries/teams-query.gql +29 -29
  64. package/src/graphql/queries/user-account.gql +1 -1
  65. package/src/graphql/queries/users.gql +1 -1
  66. package/src/graphql/subscription/fileUpdated.gql +11 -0
  67. package/src/hooks/use-upload-file.hook.native.ts +1 -1
  68. package/src/hooks/use-upload-file.hook.ts +1 -1
  69. package/src/hooks/use-upload-files.hook.native.ts +1 -1
  70. package/src/hooks/use-upload-files.hook.ts +1 -1
@@ -1,57 +1,177 @@
1
1
  import { TypePolicies } from '@apollo/client';
2
+ import { gql } from '@apollo/client';
3
+
4
+ // Define the fragment we'll use for cache operations
5
+ const POST_THREAD_FRAGMENT = gql`
6
+ fragment PostThreadInfo on PostThread {
7
+ replies
8
+ replyCount
9
+ lastReplyAt
10
+ updatedAt
11
+ }
12
+ `;
2
13
 
3
14
  export const postThreadPolicies: TypePolicies = {
4
15
  ThreadMessages: {
5
- // keyFields: ['messagesRefId'],
6
- //keyFields: [],
7
16
  keyFields: ['data', ['channel', ['id']]],
8
17
  fields: {
9
18
  data: {
10
- // keyArgs: false,
11
- // merge: (existing = [], incoming = [], { readField, mergeObjects }) => {
12
- // return existing ? [...existing, ...incoming] : incoming;
13
- // // console.log('existing', existing);
14
- // // console.log('incoming', incoming);
15
- // // const merged = [...incoming];
16
- // // const existingIds = existing.map((item) => readField<String>('id', item));
17
- // // merged.forEach((item, index) => {
18
- // // const itemId = readField<String>('id', item);
19
- // // const existingIndex = existingIds.findIndex((id) => id === itemId);
20
- // // if (existingIndex !== -1) {
21
- // // merged[index] = mergeObjects(existing[existingIndex], merged[index]);
22
- // // }
23
- // // });
24
- // // return merged;
25
- // },
19
+ merge: (existing = [], incoming = [], { readField }) => {
20
+ // Create a map for efficient lookups
21
+ const threadMap = new Map();
22
+
23
+ // Store existing threads
24
+ if (existing && existing.length > 0) {
25
+ for (const item of existing) {
26
+ const id = readField('id', item);
27
+ if (id) threadMap.set(id, item);
28
+ }
29
+ }
30
+
31
+ // Add or update with incoming threads
32
+ if (incoming && incoming.length > 0) {
33
+ for (const item of incoming) {
34
+ const id = readField('id', item);
35
+ if (id) threadMap.set(id, item);
36
+ }
37
+ }
38
+
39
+ // Convert back to array
40
+ return Array.from(threadMap.values());
41
+ },
26
42
  },
27
43
  totalCount: {
28
- // keyArgs: false,
29
- // merge(existing, incoming) {
30
- // return existing && existing > incoming ? existing : incoming;
31
- // },
44
+ merge(existing, incoming) {
45
+ // Take the higher of the two counts
46
+ return incoming !== undefined ? Math.max(existing || 0, incoming) : existing;
47
+ },
32
48
  },
33
49
  },
34
50
  },
35
51
  Query: {
36
52
  fields: {
37
53
  threadMessages: {
38
- // keyArgs: ['channelId', 'parentId', 'limit', 'skip'],
39
54
  keyArgs: ['channelId'],
40
- //keyArgs: false,
41
- merge(existing, incoming) {
42
- // debugger;
55
+ merge(existing, incoming, { readField }) {
56
+ if (!existing) return incoming;
57
+ if (!incoming) return existing;
58
+
43
59
  return {
44
60
  ...incoming,
45
- data: [...(existing?.data ?? []), ...(incoming.data ?? [])],
61
+ data: [...(existing?.data || []), ...(incoming.data || [])].filter(
62
+ (item, index, self) =>
63
+ // Filter out duplicates
64
+ index === self.findIndex((t) => readField('id', t) === readField('id', item)),
65
+ ),
46
66
  };
47
67
  },
48
68
  },
49
69
  getPostThread: {
50
- // keyArgs: ['channelId', 'parentId', 'limit', 'skip'],
51
- keyArgs: ['channelId', 'postParentId', 'limit', 'skip', 'role'],
70
+ keyArgs: ['channelId', 'postParentId', 'role'],
52
71
  merge(existing, incoming, { mergeObjects }) {
53
- // debugger;
54
- return mergeObjects(existing, incoming);
72
+ if (!existing) return incoming;
73
+ if (!incoming) return existing;
74
+
75
+ // Carefully merge the two objects
76
+ const result = mergeObjects(existing, incoming);
77
+
78
+ // Special handling for replies to avoid duplicates
79
+ if (existing.replies && incoming.replies) {
80
+ const uniqueReplies = new Map();
81
+
82
+ // Add existing replies
83
+ for (const reply of existing.replies) {
84
+ uniqueReplies.set(reply.id, reply);
85
+ }
86
+
87
+ // Add incoming replies, overwriting existing ones
88
+ for (const reply of incoming.replies) {
89
+ uniqueReplies.set(reply.id, reply);
90
+ }
91
+
92
+ // Replace replies with deduplicated list
93
+ result.replies = Array.from(uniqueReplies.values());
94
+ }
95
+
96
+ return result;
97
+ },
98
+ },
99
+ },
100
+ },
101
+ // Mutation: {
102
+ // fields: {
103
+ // createPostThread: {
104
+ // merge(existing, incoming, { cache, args, readField }) {
105
+ // // Early return if not enough data
106
+ // if (!incoming?.lastMessage || !incoming?.data || !args?.channelId || !args?.postParentId) {
107
+ // return incoming;
108
+ // }
109
+
110
+ // try {
111
+ // // Use type policies to handle the cache update instead of direct manipulation
112
+ // const queryRef = cache.identify({
113
+ // __typename: 'Query',
114
+ // getPostThread: {
115
+ // channelId: args.channelId,
116
+ // postParentId: args.postParentId,
117
+ // role: args.threadMessageInput?.role
118
+ // }
119
+ // });
120
+
121
+ // // Use cache.modify which doesn't require fragments
122
+ // if (queryRef) {
123
+ // cache.modify({
124
+ // id: queryRef,
125
+ // fields: {
126
+ // getPostThread(existingThread = {}) {
127
+ // if (!existingThread) return existingThread;
128
+
129
+ // // Create a new object with the updated properties
130
+ // return {
131
+ // ...existingThread,
132
+ // replies: [incoming.lastMessage, ...(existingThread.replies || [])],
133
+ // replyCount: (existingThread.replyCount || 0) + 1,
134
+ // lastReplyAt: incoming.lastMessage.createdAt,
135
+ // updatedAt: incoming.lastMessage.createdAt
136
+ // };
137
+ // }
138
+ // }
139
+ // });
140
+ // }
141
+ // } catch (error) {
142
+ // console.error('Error updating cache in createPostThread policy:', error);
143
+ // }
144
+
145
+ // return incoming;
146
+ // },
147
+ // },
148
+ // },
149
+ // },
150
+ PostThread: {
151
+ fields: {
152
+ replies: {
153
+ merge(existing = [], incoming = [], { readField }) {
154
+ // Use a map for fast deduplication
155
+ const replyMap = new Map();
156
+
157
+ // Add existing replies
158
+ if (existing && existing.length > 0) {
159
+ for (const reply of existing) {
160
+ const id = readField('id', reply);
161
+ if (id) replyMap.set(id, reply);
162
+ }
163
+ }
164
+
165
+ // Add or update with incoming replies
166
+ if (incoming && incoming.length > 0) {
167
+ for (const reply of incoming) {
168
+ const id = readField('id', reply);
169
+ if (id) replyMap.set(id, reply);
170
+ }
171
+ }
172
+
173
+ // Convert back to array
174
+ return Array.from(replyMap.values());
55
175
  },
56
176
  },
57
177
  },
@@ -2,6 +2,18 @@ import { TypePolicies } from '@apollo/client';
2
2
 
3
3
  export const teamPolicies: TypePolicies = {
4
4
  Query: {
5
- fields: {},
5
+ fields: {
6
+ getOrganizationTeams: {
7
+ merge(existing = [], incoming) {
8
+ return incoming;
9
+ },
10
+ read(existing) {
11
+ return existing;
12
+ },
13
+ },
14
+ },
15
+ },
16
+ AccountTeam: {
17
+ keyFields: ['id'],
6
18
  },
7
19
  };
@@ -14,6 +14,32 @@ query GetChannelsByUser($role: String, $criteria: AnyObject, $limit: Int, $skip:
14
14
  creator {
15
15
  ...MessengerUser
16
16
  }
17
+ lastPostAt
18
+ createdAt
19
+ updatedAt
20
+ }
21
+ }
22
+
23
+
24
+ query GetChannelsByUserWithLastMessage($role: String, $criteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort) {
25
+ channelsByUser(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
26
+ id
27
+ title
28
+ description
29
+ type
30
+ displayName
31
+ members {
32
+ id
33
+ user {
34
+ ...MessengerUser
35
+ }
36
+ }
37
+ creator {
38
+ ...MessengerUser
39
+ }
40
+ lastMessage {
41
+ ...Post
42
+ }
17
43
  createdAt
18
44
  updatedAt
19
45
  }
@@ -1,5 +1,5 @@
1
- query Messages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
2
- messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "messages", filter: ["channelId","skip"]){
1
+ query Messages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort, $props: AnyObject) {
2
+ messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort, props: $props) @connection(key: "messages", filter: ["channelId","skip"]){
3
3
  messagesRefId @client
4
4
  data{
5
5
  ...Post
@@ -1,56 +1,91 @@
1
1
  query GetOrganizationDetail($where: OrgDetailWhere!) {
2
2
  getOrganizationDetail(where: $where) {
3
- createdAt
4
- description
5
3
  id
4
+ name
5
+ title
6
+ description
7
+ picture
8
+ orgUserCount
9
+ status
10
+ periodStart
11
+ periodStop
12
+ createdAt
13
+ updatedAt
14
+ billingEmail
15
+ stripeId
16
+ stripeSubscription
17
+ erpId
18
+ costCenter
19
+ legalEntityName
20
+ taxId
21
+ organizationType
22
+ organizationCategory
23
+ settings
6
24
  invitations {
7
- active
8
- acceptedAt
9
- createdAt
25
+ id
10
26
  email
27
+ roles
28
+ status
11
29
  fullName
12
- id
13
- invitedBy
14
- teamId
15
- updatedAt
16
- tokenExpiration
17
- role
18
30
  inviteCount
31
+ invitedBy {
32
+ id
33
+ email
34
+ username
35
+ givenName
36
+ familyName
37
+ picture
38
+ }
39
+ inviteLink
40
+ createdAt
41
+ updatedAt
42
+ acceptedAt
43
+ sent
44
+ expiresAt
45
+ team {
46
+ id
47
+ name
48
+ title
49
+ }
19
50
  }
20
- name
21
- orgMembers {
51
+ members {
52
+ id
53
+ email
54
+ displayName
55
+ roles
56
+ status
57
+ lastVisited
58
+ joinedAt
59
+ createdAt
60
+ updatedAt
22
61
  crossCheckEmail
23
- inactive
24
- orgName
25
62
  user {
63
+ id
26
64
  email
65
+ username
66
+ givenName
67
+ familyName
68
+ picture
27
69
  alias
28
70
  emailVerified
29
- id
30
- username
31
71
  }
32
- roles
33
- userId
34
72
  }
35
- orgUserCount
36
- periodStart
37
- periodStop
38
- picture
39
- status
40
- title
41
- updatedAt
42
73
  }
43
74
  }
44
75
 
45
-
46
-
47
-
48
- query GetOrganizationMembersWithChannels($orgName: String,$role: String, $channelCriteria: AnyObject,$offset: Int, $limit: Int, $sort: Sort) {
49
- getOrganizationMembers(offset: $offset, limit: $limit, orgName: $orgName) {
76
+ query GetOrganizationMembersWithChannels($orgId: ID, $orgName: String, $role: String, $channelCriteria: AnyObject, $offset: Int, $limit: Int, $sort: Sort) {
77
+ getOrganizationMembers(offset: $offset, limit: $limit, orgId: $orgId, orgName: $orgName) {
50
78
  totalCount
51
79
  data {
80
+ _id
52
81
  userId
53
82
  roles
83
+ inactive
84
+ orgName
85
+ crossCheckEmail
86
+ teamNames
87
+ lastVisited
88
+ isSelf
54
89
  user {
55
90
  id
56
91
  givenName
@@ -59,11 +94,11 @@ query GetOrganizationMembersWithChannels($orgName: String,$role: String, $channe
59
94
  username
60
95
  email
61
96
  alias
97
+ emailVerified
62
98
  }
63
- teamNames
64
99
  }
65
- }
66
- channelsByUser(role: $role, criteria: $channelCriteria, limit: $limit, skip: $offset, sort: $sort) {
100
+ }
101
+ channelsByUser(role: $role, criteria: $channelCriteria, limit: $limit, skip: $offset, sort: $sort) {
67
102
  id
68
103
  title
69
104
  description
@@ -85,6 +120,6 @@ query GetOrganizationMembersWithChannels($orgName: String,$role: String, $channe
85
120
  }
86
121
 
87
122
  query GetOrganizationSharableLink($teamId: String) {
88
- getOrganizationSharableLink(teamId: $teamId)
123
+ getOrganizationSharableLink(teamId: $teamId)
89
124
  }
90
125
 
@@ -18,3 +18,7 @@ query GetPostThread($postThreadId: ID, $channelId: ID, $postParentId: ID, $role:
18
18
  }
19
19
  }
20
20
  }
21
+
22
+ query ThreadMessagesCount($channelId: ID, $postParentId: ID, $role: String, $participantsIds: [String], $selectedFields: String, $isServiceThreads: Boolean) {
23
+ threadMessagesCount(channelId: $channelId, postParentId: $postParentId, role: $role, participantsIds: $participantsIds, selectedFields: $selectedFields, isServiceThreads: $isServiceThreads)
24
+ }
@@ -1,32 +1,32 @@
1
1
 
2
2
 
3
- query GetOrganizationTeam($orgName: String!, $teamName: String!) {
4
- getTeam(orgName: $orgName, teamName: $teamName) {
5
- title
6
- orgName
7
- name
8
- id
9
- createdAt
10
- updatedAt
11
- _id
12
- teamMembers:members {
13
- id
14
- name
15
- email
16
- username
17
- userId
18
- status
19
- role
3
+ query GetOrganizationTeam($orgName: String!, $teamId: ID!) {
4
+ getTeam(orgName: $orgName, teamId: $teamId) {
5
+ id
6
+ name
7
+ title
8
+ description
9
+ tags
10
+ createdAt
11
+ updatedAt
12
+ organization {
13
+ id
14
+ name
15
+ title
16
+ }
17
+ teamMembers:members {
18
+ id
19
+ roles
20
+ status
21
+ joinedAt
22
+ user {
23
+ id
24
+ email
25
+ username
26
+ givenName
27
+ familyName
28
+ picture
29
+ }
30
+ }
20
31
  }
21
- members {
22
- id
23
- name
24
- email
25
- username
26
- userId
27
- status
28
- role
29
- }
30
- }
31
- }
32
-
32
+ }
@@ -1,4 +1,4 @@
1
- query UserAccount($userId:String!){
1
+ query UserAccount($userId:ID!){
2
2
  getUserAccount(userId:$userId ){
3
3
  ...MessengerUser
4
4
  }
@@ -4,7 +4,7 @@ query GetAllUsers {
4
4
  }
5
5
  }
6
6
 
7
- query GetUserById($userId: String!) {
7
+ query GetUserById($userId: ID!) {
8
8
  getUserAccount(userId: $userId) {
9
9
  ...MinimalUser
10
10
  }
@@ -0,0 +1,11 @@
1
+ subscription FileUpdated($projectId: String!) {
2
+ fileUpdated(projectId: $projectId) {
3
+ projectId
4
+ messageId
5
+ filePath
6
+ content
7
+ operation
8
+ timestamp
9
+ syncStatus
10
+ }
11
+ }
@@ -1,4 +1,4 @@
1
- import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
1
+ import { useUploadFile as useBaseUploadFile } from '@adminide-stack/file-info-client/lib/hooks/use-file-upload.native.js';
2
2
  import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
3
3
 
4
4
  export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
@@ -1,4 +1,4 @@
1
- import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-upload-file.js';
1
+ import { useUploadFile as useBaseUploadFile } from '@adminide-stack/file-info-client/lib/hooks/use-upload-file.js';
2
2
  import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
3
3
 
4
4
  export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
@@ -1,4 +1,4 @@
1
- import { useUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
1
+ import { useUploadFile } from '@adminide-stack/file-info-client/lib/hooks/use-file-upload.native.js';
2
2
  import { useAttachUploadedFilesToMessageMutation, useCreateMessageFilesUploadLinkMutation } from 'common/graphql';
3
3
 
4
4
  export const useUploadFiles = (): ReturnType<typeof useUploadFile> =>
@@ -1,4 +1,4 @@
1
- import { useUploadFile } from '@container-stack/file-info-client/lib/hooks/use-upload-file.js';
1
+ import { useUploadFile } from '@adminide-stack/file-info-client/lib/hooks/use-upload-file.js';
2
2
  import { useAttachUploadedFilesToMessageMutation, useCreateMessageFilesUploadLinkMutation } from 'common/graphql';
3
3
 
4
4
  export const useUploadFiles = (): ReturnType<typeof useUploadFile> =>