@amityco/ts-sdk 7.4.1-b9f48528.0 → 7.4.1-d23fab2f.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.
Files changed (175) hide show
  1. package/dist/@types/core/events.d.ts +3 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +8 -4
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/community.d.ts +5 -1
  8. package/dist/@types/domains/community.d.ts.map +1 -1
  9. package/dist/@types/domains/invitation.d.ts +43 -0
  10. package/dist/@types/domains/invitation.d.ts.map +1 -0
  11. package/dist/@types/index.d.ts +1 -0
  12. package/dist/@types/index.d.ts.map +1 -1
  13. package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
  14. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  15. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  16. package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
  17. package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
  18. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  19. package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
  20. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts +1 -1
  21. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts.map +1 -1
  22. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts +1 -1
  23. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts.map +1 -1
  24. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts +1 -1
  25. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts.map +1 -1
  26. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts +1 -1
  27. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts.map +1 -1
  28. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts +1 -1
  29. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts.map +1 -1
  30. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts +1 -1
  31. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts.map +1 -1
  32. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts +1 -1
  33. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts.map +1 -1
  34. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts +1 -1
  35. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts.map +1 -1
  36. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts +1 -1
  37. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts.map +1 -1
  38. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +1 -1
  39. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -1
  40. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +1 -1
  41. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -1
  42. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +1 -1
  43. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -1
  44. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +1 -1
  45. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -1
  46. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +1 -1
  47. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
  48. package/dist/communityRepository/communityMembership/events/utils.d.ts +2 -2
  49. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  50. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +2 -2
  51. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
  52. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +2 -2
  53. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -1
  54. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +1 -1
  55. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -1
  56. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +1 -1
  57. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -1
  58. package/dist/communityRepository/events/onCommunityCreated.d.ts +1 -1
  59. package/dist/communityRepository/events/onCommunityCreated.d.ts.map +1 -1
  60. package/dist/communityRepository/events/onCommunityDeleted.d.ts +1 -1
  61. package/dist/communityRepository/events/onCommunityDeleted.d.ts.map +1 -1
  62. package/dist/communityRepository/events/onCommunityUpdated.d.ts +1 -1
  63. package/dist/communityRepository/events/onCommunityUpdated.d.ts.map +1 -1
  64. package/dist/communityRepository/events/utils.d.ts +1 -1
  65. package/dist/communityRepository/events/utils.d.ts.map +1 -1
  66. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +2 -2
  67. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
  68. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +2 -2
  69. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -1
  70. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +2 -2
  71. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -1
  72. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +2 -2
  73. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
  74. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +2 -2
  75. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -1
  76. package/dist/communityRepository/utils/communityWithMembership.d.ts +1 -1
  77. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  78. package/dist/communityRepository/utils/payload.d.ts +1 -1
  79. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  80. package/dist/core/events.d.ts +3 -3
  81. package/dist/core/events.d.ts.map +1 -1
  82. package/dist/core/model/idResolvers.d.ts.map +1 -1
  83. package/dist/core/model/index.d.ts.map +1 -1
  84. package/dist/index.cjs.js +266 -51
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.esm.js +248 -34
  88. package/dist/index.umd.js +4 -4
  89. package/dist/invitationRepository/events/index.d.ts +2 -0
  90. package/dist/invitationRepository/events/index.d.ts.map +1 -0
  91. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +17 -0
  92. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -0
  93. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +17 -0
  94. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -0
  95. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +17 -0
  96. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -0
  97. package/dist/invitationRepository/index.d.ts +2 -0
  98. package/dist/invitationRepository/index.d.ts.map +1 -0
  99. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts +16 -0
  100. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts.map +1 -0
  101. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +16 -0
  102. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +1 -0
  103. package/dist/invitationRepository/internalApi/createInvitations.d.ts +21 -0
  104. package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -0
  105. package/dist/invitationRepository/internalApi/index.d.ts +5 -0
  106. package/dist/invitationRepository/internalApi/index.d.ts.map +1 -0
  107. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts +16 -0
  108. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts.map +1 -0
  109. package/dist/utils/linkedObject/communityLinkedObject.d.ts +2 -0
  110. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -0
  111. package/dist/utils/linkedObject/index.d.ts +2 -0
  112. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  113. package/dist/utils/linkedObject/invitationLinkedObject.d.ts +2 -0
  114. package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -0
  115. package/dist/utils/tests/dummy/post.d.ts +3 -3
  116. package/package.json +1 -1
  117. package/src/@types/core/events.ts +4 -0
  118. package/src/@types/core/model.ts +5 -1
  119. package/src/@types/core/payload.ts +9 -4
  120. package/src/@types/domains/community.ts +10 -1
  121. package/src/@types/domains/invitation.ts +52 -0
  122. package/src/@types/index.ts +1 -0
  123. package/src/communityRepository/api/createCommunity.ts +2 -1
  124. package/src/communityRepository/api/getCommunities.ts +2 -1
  125. package/src/communityRepository/api/getCommunity.ts +4 -1
  126. package/src/communityRepository/api/getRecommendedCommunities.ts +2 -1
  127. package/src/communityRepository/api/getTrendingCommunities.ts +2 -1
  128. package/src/communityRepository/api/queryCommunities.ts +6 -1
  129. package/src/communityRepository/api/updateCommunity.ts +4 -1
  130. package/src/communityRepository/communityMembership/events/onCommunityJoined.ts +1 -1
  131. package/src/communityRepository/communityMembership/events/onCommunityLeft.ts +1 -1
  132. package/src/communityRepository/communityMembership/events/onCommunityUserAdded.ts +1 -1
  133. package/src/communityRepository/communityMembership/events/onCommunityUserBanned.ts +1 -1
  134. package/src/communityRepository/communityMembership/events/onCommunityUserChanged.ts +1 -1
  135. package/src/communityRepository/communityMembership/events/onCommunityUserRemoved.ts +1 -1
  136. package/src/communityRepository/communityMembership/events/onCommunityUserRoleAdded.ts +1 -1
  137. package/src/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.ts +1 -1
  138. package/src/communityRepository/communityMembership/events/onCommunityUserUnbanned.ts +1 -1
  139. package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +1 -1
  140. package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +1 -1
  141. package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +1 -1
  142. package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +1 -1
  143. package/src/communityRepository/communityMembership/events/onUserDeleted.ts +3 -1
  144. package/src/communityRepository/communityMembership/events/utils.ts +2 -2
  145. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +8 -2
  146. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +8 -2
  147. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +1 -1
  148. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +1 -1
  149. package/src/communityRepository/events/onCommunityCreated.ts +1 -1
  150. package/src/communityRepository/events/onCommunityDeleted.ts +1 -1
  151. package/src/communityRepository/events/onCommunityUpdated.ts +1 -1
  152. package/src/communityRepository/events/utils.ts +1 -1
  153. package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +2 -2
  154. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +2 -2
  155. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +2 -2
  156. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +2 -2
  157. package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +2 -2
  158. package/src/communityRepository/utils/communityWithMembership.ts +8 -4
  159. package/src/communityRepository/utils/payload.ts +1 -1
  160. package/src/core/model/idResolvers.ts +2 -0
  161. package/src/core/model/index.ts +2 -0
  162. package/src/index.ts +2 -0
  163. package/src/invitationRepository/events/index.ts +1 -0
  164. package/src/invitationRepository/events/onLocalInvitationCreated.ts +33 -0
  165. package/src/invitationRepository/events/onLocalInvitationDeleted.ts +33 -0
  166. package/src/invitationRepository/events/onLocalInvitationUpdated.ts +33 -0
  167. package/src/invitationRepository/index.ts +1 -0
  168. package/src/invitationRepository/internalApi/acceptInvitation.ts +45 -0
  169. package/src/invitationRepository/internalApi/cancelInvitation.ts +44 -0
  170. package/src/invitationRepository/internalApi/createInvitations.ts +46 -0
  171. package/src/invitationRepository/internalApi/index.ts +4 -0
  172. package/src/invitationRepository/internalApi/rejectInvitation.ts +45 -0
  173. package/src/utils/linkedObject/communityLinkedObject.ts +16 -0
  174. package/src/utils/linkedObject/index.ts +4 -0
  175. package/src/utils/linkedObject/invitationLinkedObject.ts +20 -0
@@ -1,5 +1,5 @@
1
1
  import { createLocalCommunityMemberEventSubscriber } from './utils';
2
2
 
3
3
  export const onLocalCommunityLeft = (
4
- callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
4
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
5
5
  ) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
@@ -16,5 +16,5 @@ import { createLocalCommunityMemberEventSubscriber } from './utils';
16
16
  * @category Community Events
17
17
  */
18
18
  export const onLocalCommunityUserAdded = (
19
- callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
19
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
20
20
  ) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
@@ -16,5 +16,5 @@ import { createLocalCommunityMemberEventSubscriber } from './utils';
16
16
  * @category Community Events
17
17
  */
18
18
  export const onLocalCommunityUserRemoved = (
19
- callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
19
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
20
20
  ) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
@@ -22,7 +22,9 @@ import { getResolver } from '~/core/model';
22
22
  */
23
23
  export const onUserDeleted =
24
24
  (communityId: string) =>
25
- (callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void) => {
25
+ (
26
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
27
+ ) => {
26
28
  const client = getActiveClient();
27
29
 
28
30
  const filter = (payload: Amity.UserPayload) => {
@@ -53,7 +53,7 @@ function getEventRelatedMember(
53
53
 
54
54
  export const createCommunityMemberEventSubscriber = (
55
55
  event: keyof Amity.MqttCommunityUserEvents,
56
- callback: (community: Amity.Community, members: Amity.Membership<'community'>[]) => void,
56
+ callback: (community: Amity.InternalCommunity, members: Amity.Membership<'community'>[]) => void,
57
57
  ) => {
58
58
  const client = getActiveClient();
59
59
 
@@ -102,7 +102,7 @@ export const createCommunityMemberEventSubscriber = (
102
102
 
103
103
  export const createLocalCommunityMemberEventSubscriber = (
104
104
  event: keyof Amity.LocalCommunityEvents,
105
- callback: (community: Amity.Community, members: Amity.Membership<'community'>[]) => void,
105
+ callback: (community: Amity.InternalCommunity, members: Amity.Membership<'community'>[]) => void,
106
106
  ) => {
107
107
  const client = getActiveClient();
108
108
 
@@ -70,7 +70,10 @@ export class CommunityMembersQueryStreamController extends QueryStreamController
70
70
  }
71
71
 
72
72
  reactor(action: EnumCommunityMemberActions) {
73
- return (community: Amity.Community, communityMembers: Amity.Membership<'community'>[]) => {
73
+ return (
74
+ community: Amity.InternalCommunity,
75
+ communityMembers: Amity.Membership<'community'>[],
76
+ ) => {
74
77
  const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(
75
78
  this.cacheKey,
76
79
  )?.data;
@@ -97,7 +100,10 @@ export class CommunityMembersQueryStreamController extends QueryStreamController
97
100
  subscribeRTE(
98
101
  createSubscriber: {
99
102
  fn: (
100
- reactor: (channel: Amity.Community, communityUser: Amity.Membership<'community'>[]) => void,
103
+ reactor: (
104
+ channel: Amity.InternalCommunity,
105
+ communityUser: Amity.Membership<'community'>[],
106
+ ) => void,
101
107
  ) => Amity.Unsubscriber;
102
108
  action: EnumCommunityMemberActions;
103
109
  }[],
@@ -70,7 +70,10 @@ export class SearchCommunityMembersQueryStreamController extends QueryStreamCont
70
70
  }
71
71
 
72
72
  reactor(action: EnumCommunityMemberActions) {
73
- return (community: Amity.Community, communityMembers: Amity.Membership<'community'>[]) => {
73
+ return (
74
+ community: Amity.InternalCommunity,
75
+ communityMembers: Amity.Membership<'community'>[],
76
+ ) => {
74
77
  const collection = pullFromCache<Amity.SearchCommunityMemberLiveCollectionCache>(
75
78
  this.cacheKey,
76
79
  )?.data;
@@ -95,7 +98,10 @@ export class SearchCommunityMembersQueryStreamController extends QueryStreamCont
95
98
  subscribeRTE(
96
99
  createSubscriber: {
97
100
  fn: (
98
- reactor: (channel: Amity.Community, communityUser: Amity.Membership<'community'>[]) => void,
101
+ reactor: (
102
+ channel: Amity.InternalCommunity,
103
+ communityUser: Amity.Membership<'community'>[],
104
+ ) => void,
99
105
  ) => Amity.Unsubscriber;
100
106
  action: EnumCommunityMemberActions;
101
107
  }[],
@@ -17,7 +17,7 @@ import { createEventSubscriber } from '~/core/events';
17
17
  * @category Community Events
18
18
  */
19
19
  export const onLocalCommunityRoleAdded = (
20
- callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
20
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
21
21
  ): Amity.Unsubscriber => {
22
22
  const client = getActiveClient();
23
23
 
@@ -17,7 +17,7 @@ import { createEventSubscriber } from '~/core/events';
17
17
  * @category Community Events
18
18
  */
19
19
  export const onLocalCommunityRoleRemoved = (
20
- callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
20
+ callback: (community: Amity.InternalCommunity, member: Amity.Membership<'community'>[]) => void,
21
21
  ): Amity.Unsubscriber => {
22
22
  const client = getActiveClient();
23
23
 
@@ -15,5 +15,5 @@ import { createCommunityEventSubscriber } from './utils';
15
15
  *
16
16
  * @category Community Events
17
17
  */
18
- export const onCommunityCreated = (callback: Amity.Listener<Amity.Community>) =>
18
+ export const onCommunityCreated = (callback: Amity.Listener<Amity.InternalCommunity>) =>
19
19
  createCommunityEventSubscriber('community.created', callback);
@@ -15,5 +15,5 @@ import { createCommunityEventSubscriber } from './utils';
15
15
  *
16
16
  * @category Community Events
17
17
  */
18
- export const onCommunityDeleted = (callback: Amity.Listener<Amity.Community>) =>
18
+ export const onCommunityDeleted = (callback: Amity.Listener<Amity.InternalCommunity>) =>
19
19
  createCommunityEventSubscriber('community.deleted', callback);
@@ -15,5 +15,5 @@ import { createCommunityEventSubscriber } from './utils';
15
15
  *
16
16
  * @category Community Events
17
17
  */
18
- export const onCommunityUpdated = (callback: Amity.Listener<Amity.Community>) =>
18
+ export const onCommunityUpdated = (callback: Amity.Listener<Amity.InternalCommunity>) =>
19
19
  createCommunityEventSubscriber('community.updated', callback);
@@ -7,7 +7,7 @@ import { prepareCommunityPayload } from '../utils';
7
7
 
8
8
  export const createCommunityEventSubscriber = (
9
9
  event: keyof Amity.MqttCommunityEvents,
10
- callback: Amity.Listener<Amity.Community>,
10
+ callback: Amity.Listener<Amity.InternalCommunity>,
11
11
  ) => {
12
12
  const client = getActiveClient();
13
13
 
@@ -60,7 +60,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
60
60
  }
61
61
 
62
62
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
63
- return (community: Amity.Community) => {
63
+ return (community: Amity.InternalCommunity) => {
64
64
  const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
65
65
  if (!collection) return;
66
66
 
@@ -76,7 +76,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
76
76
 
77
77
  subscribeRTE(
78
78
  createSubscriber: {
79
- fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
79
+ fn: (reactor: (channel: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
80
80
  action: EnumCommunityActions | EnumCommunityMemberActions;
81
81
  }[],
82
82
  ) {
@@ -66,7 +66,7 @@ export class RecommendedCommunitiesQueryStreamController extends QueryStreamCont
66
66
  }
67
67
 
68
68
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
69
- return (community: Amity.Community) => {
69
+ return (community: Amity.InternalCommunity) => {
70
70
  const collection = pullFromCache<Amity.RecommendedCommunityLiveCollectionCache>(
71
71
  this.cacheKey,
72
72
  )?.data;
@@ -79,7 +79,7 @@ export class RecommendedCommunitiesQueryStreamController extends QueryStreamCont
79
79
 
80
80
  subscribeRTE(
81
81
  createSubscriber: {
82
- fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
82
+ fn: (reactor: (channel: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
83
83
  action: EnumCommunityActions | EnumCommunityMemberActions;
84
84
  }[],
85
85
  ) {
@@ -64,7 +64,7 @@ export class TrendingCommunitiesQueryStreamController extends QueryStreamControl
64
64
  }
65
65
 
66
66
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
67
- return (community: Amity.Community) => {
67
+ return (community: Amity.InternalCommunity) => {
68
68
  const collection = pullFromCache<Amity.TrendingCommunityLiveCollectionCache>(
69
69
  this.cacheKey,
70
70
  )?.data;
@@ -77,7 +77,7 @@ export class TrendingCommunitiesQueryStreamController extends QueryStreamControl
77
77
 
78
78
  subscribeRTE(
79
79
  createSubscriber: {
80
- fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
80
+ fn: (reactor: (channel: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
81
81
  action: EnumCommunityActions | EnumCommunityMemberActions;
82
82
  }[],
83
83
  ) {
@@ -60,7 +60,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
60
60
  }
61
61
 
62
62
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
63
- return (community: Amity.Community) => {
63
+ return (community: Amity.InternalCommunity) => {
64
64
  const collection = pullFromCache<Amity.SearchCommunityLiveCollectionCache>(
65
65
  this.cacheKey,
66
66
  )?.data;
@@ -73,7 +73,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
73
73
 
74
74
  subscribeRTE(
75
75
  createSubscriber: {
76
- fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
76
+ fn: (reactor: (channel: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
77
77
  action: EnumCommunityActions | EnumCommunityMemberActions;
78
78
  }[],
79
79
  ) {
@@ -63,7 +63,7 @@ export class SemanticSearchCommunityQueryStreamController extends QueryStreamCon
63
63
  }
64
64
 
65
65
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
66
- return (community: Amity.Community) => {
66
+ return (community: Amity.InternalCommunity) => {
67
67
  const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
68
68
  if (!collection) return;
69
69
 
@@ -77,7 +77,7 @@ export class SemanticSearchCommunityQueryStreamController extends QueryStreamCon
77
77
 
78
78
  subscribeRTE(
79
79
  createSubscriber: {
80
- fn: (reactor: (community: Amity.Community) => void) => Amity.Unsubscriber;
80
+ fn: (reactor: (community: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
81
81
  action: EnumCommunityActions | EnumCommunityMemberActions;
82
82
  }[],
83
83
  ) {
@@ -12,7 +12,7 @@ function isMember(membership: Amity.Membership<'community'>['communityMembership
12
12
  * checks if currently logged in user is part of the community
13
13
  */
14
14
  function isCurrentUserPartOfCommunity(
15
- c: Amity.Community,
15
+ c: Amity.InternalCommunity,
16
16
  m: Amity.Membership<'community'>,
17
17
  ): boolean {
18
18
  const { userId } = getActiveUser();
@@ -28,11 +28,15 @@ function isCurrentUserPartOfCommunity(
28
28
  * Althought this can be calculated, it's not scalable.
29
29
  */
30
30
  export function updateMembershipStatus(
31
- communities: Amity.Community[],
31
+ communities: Amity.RawCommunity[],
32
32
  communityUsers: Amity.Membership<'community'>[],
33
- ): Amity.Community[] {
33
+ ): Amity.InternalCommunity[] {
34
34
  return communities.map(c => {
35
- const cachedCommunity = pullFromCache<Amity.Community>(['community', 'get', c.communityId]);
35
+ const cachedCommunity = pullFromCache<Amity.InternalCommunity>([
36
+ 'community',
37
+ 'get',
38
+ c.communityId,
39
+ ]);
36
40
  if (cachedCommunity?.data && cachedCommunity?.data.hasOwnProperty('isJoined')) {
37
41
  return {
38
42
  ...cachedCommunity.data,
@@ -13,7 +13,7 @@ const getMatchPostSetting = (value: {
13
13
  ) ?? DefaultCommunityPostSetting;
14
14
 
15
15
  export function addPostSetting({ communities }: { communities: Amity.RawCommunity[] }) {
16
- return communities.map<Amity.Community>(
16
+ return communities.map<Amity.InternalCommunity>(
17
17
  ({ needApprovalOnPostCreation, onlyAdminCanPost, ...restCommunityPayload }) => ({
18
18
  postSetting: getMatchPostSetting({
19
19
  needApprovalOnPostCreation,
@@ -64,6 +64,8 @@ const idResolvers: Resolvers = {
64
64
 
65
65
  notificationTrayItem: ({ _id }) => _id,
66
66
  notificationTraySeen: ({ userId }) => userId,
67
+
68
+ invitation: ({ _id }) => _id,
67
69
  };
68
70
 
69
71
  /**
@@ -54,6 +54,8 @@ export const PAYLOAD2MODEL: Record<string, Amity.Domain> = {
54
54
  pins: 'pin',
55
55
 
56
56
  notificationTrayItems: 'notificationTrayItem',
57
+
58
+ invitations: 'invitation',
57
59
  };
58
60
 
59
61
  /** hidden */
package/src/index.ts CHANGED
@@ -51,3 +51,5 @@ export * as AdRepository from './adRepository';
51
51
  export * from './external/api';
52
52
 
53
53
  export * as notificationTray from './notificationTray';
54
+
55
+ export * as InvitationRepository from './invitationRepository';
@@ -0,0 +1 @@
1
+ export * from './onLocalInvitationCreated';
@@ -0,0 +1,33 @@
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
+ import { createEventSubscriber } from '~/core/events';
3
+
4
+ /**
5
+ * ```js
6
+ * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
7
+ * const dispose = onLocalInvitationCreated(data => {
8
+ * // ...
9
+ * })
10
+ * ```
11
+ *
12
+ * Fired when an {@link Amity.InvitationPayload} has been created
13
+ *
14
+ * @param callback The function to call when the event was fired
15
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
16
+ *
17
+ * @category Invitation Events
18
+ */
19
+ export const onLocalInvitationCreated = (
20
+ callback: Amity.Listener<Amity.InvitationPayload>,
21
+ ): Amity.Unsubscriber => {
22
+ const client = getActiveClient();
23
+
24
+ const disposers = [
25
+ createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload =>
26
+ callback(payload),
27
+ ),
28
+ ];
29
+
30
+ return () => {
31
+ disposers.forEach(fn => fn());
32
+ };
33
+ };
@@ -0,0 +1,33 @@
1
+ import { createEventSubscriber } from '~/core/events';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+
4
+ /**
5
+ * ```js
6
+ * import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
7
+ * const dispose = onLocalInvitationDeleted(data => {
8
+ * // ...
9
+ * })
10
+ * ```
11
+ *
12
+ * Fired when an {@link Amity.InvitationPayload} has been deleted
13
+ *
14
+ * @param callback The function to call when the event was fired
15
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
16
+ *
17
+ * @category Invitation Events
18
+ */
19
+ export const onLocalInvitationDeleted = (
20
+ callback: Amity.Listener<Amity.InvitationPayload>,
21
+ ): Amity.Unsubscriber => {
22
+ const client = getActiveClient();
23
+
24
+ const disposers = [
25
+ createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload =>
26
+ callback(payload),
27
+ ),
28
+ ];
29
+
30
+ return () => {
31
+ disposers.forEach(fn => fn());
32
+ };
33
+ };
@@ -0,0 +1,33 @@
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
+ import { createEventSubscriber } from '~/core/events';
3
+
4
+ /**
5
+ * ```js
6
+ * import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
7
+ * const dispose = onLocalInvitationUpdated(data => {
8
+ * // ...
9
+ * })
10
+ * ```
11
+ *
12
+ * Fired when an {@link Amity.InvitationPayload} has been updated
13
+ *
14
+ * @param callback The function to call when the event was fired
15
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
16
+ *
17
+ * @category Invitation Events
18
+ */
19
+ export const onLocalInvitationUpdated = (
20
+ callback: Amity.Listener<Amity.InvitationPayload>,
21
+ ): Amity.Unsubscriber => {
22
+ const client = getActiveClient();
23
+
24
+ const disposers = [
25
+ createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload =>
26
+ callback(payload),
27
+ ),
28
+ ];
29
+
30
+ return () => {
31
+ disposers.forEach(fn => fn());
32
+ };
33
+ };
@@ -0,0 +1 @@
1
+ export * from './events';
@@ -0,0 +1,45 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { pullFromCache, upsertInCache } from '~/cache/api';
4
+ import { InvitationStatusEnum } from '~/@types';
5
+
6
+ /* begin_public_function
7
+ id: invitation.accept
8
+ */
9
+ /**
10
+ * ```js
11
+ * import { acceptInvitation } from '@amityco/ts-sdk'
12
+ * const isAccepted = await acceptInvitation(invitationId)
13
+ * ```
14
+ *
15
+ * Accepts a {@link Amity.Invitation} object
16
+ *
17
+ * @param invitationId the {@link Amity.Invitation} to accept
18
+ * @returns A success boolean if the {@link Amity.Invitation} was accepted
19
+ *
20
+ * @category Invitation API
21
+ * @async
22
+ */
23
+ export const acceptInvitation = async (invitationId: Amity.Invitation['_id']): Promise<boolean> => {
24
+ const client = getActiveClient();
25
+ client.log('invitation/acceptInvitation', invitationId);
26
+
27
+ const { data } = await client.http.post<{ success: boolean }>(
28
+ `/api/v1/invitations/${invitationId}/accept`,
29
+ );
30
+
31
+ const invitation = pullFromCache<Amity.InternalInvitation>([
32
+ 'invitation',
33
+ 'get',
34
+ invitationId,
35
+ ])?.data;
36
+
37
+ if (invitation) {
38
+ upsertInCache(['invitation', 'get', invitationId], { status: InvitationStatusEnum.Approved });
39
+
40
+ fireEvent('local.invitation.updated', { invitations: [invitation] });
41
+ }
42
+
43
+ return data.success;
44
+ };
45
+ /* end_public_function */
@@ -0,0 +1,44 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { dropFromCache, pullFromCache } from '~/cache/api';
3
+ import { getActiveClient } from '~/client/api/activeClient';
4
+
5
+ /* begin_public_function
6
+ id: invitation.cancel
7
+ */
8
+ /**
9
+ * ```js
10
+ * import { cancelInvitation } from '@amityco/ts-sdk'
11
+ * const isCanceled = await cancelInvitation(invitationId)
12
+ * ```
13
+ *
14
+ * Cancels a {@link Amity.Invitation} object
15
+ *
16
+ * @param invitationId the {@link Amity.Invitation} to cancel
17
+ * @returns A success boolean if the {@link Amity.Invitation} was canceled
18
+ *
19
+ * @category Invitation API
20
+ * @async
21
+ */
22
+ export const cancelInvitation = async (invitationId: Amity.Invitation['_id']): Promise<boolean> => {
23
+ const client = getActiveClient();
24
+ client.log('invitation/cancelInvitation', invitationId);
25
+
26
+ const { data } = await client.http.delete<{ success: boolean }>(
27
+ `/api/v1/invitations/${invitationId}`,
28
+ );
29
+
30
+ const invitation = pullFromCache<Amity.InternalInvitation>([
31
+ 'invitation',
32
+ 'get',
33
+ invitationId,
34
+ ])?.data;
35
+
36
+ if (invitation) {
37
+ dropFromCache(['invitation', 'get', invitationId]);
38
+
39
+ fireEvent('local.invitation.deleted', { invitations: [invitation] });
40
+ }
41
+
42
+ return data.success;
43
+ };
44
+ /* end_public_function */
@@ -0,0 +1,46 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { ingestInCache } from '~/cache/api/ingestInCache';
4
+
5
+ /* begin_public_function
6
+ id: invitation.createInvitations
7
+ */
8
+ /**
9
+ * ```js
10
+ * import { createInvitations } from '@amityco/ts-sdk'
11
+ * const created = await createInvitations({
12
+ * type: string,
13
+ * targetType: string,
14
+ * targetId: string,
15
+ * userIds: string[]
16
+ * }))
17
+ * ```
18
+ *
19
+ * Creates an {@link Amity.Invitation}
20
+ *
21
+ * @param bundle The data necessary to create a new {@link Amity.Invitation}
22
+ * @returns The newly created {@link Amity.Invitation}
23
+ *
24
+ * @category Invitation API
25
+ * @async
26
+ */
27
+ export const createInvitations = async (
28
+ bundle: Amity.CreateInvitations,
29
+ ): Promise<Amity.Cached<Amity.InternalInvitation[]>> => {
30
+ const client = getActiveClient();
31
+ client.log('invitation/createInvitations', bundle);
32
+
33
+ const { data } = await client.http.post<Amity.InvitationPayload>('/api/v1/invitations', bundle);
34
+
35
+ const cachedAt = client.cache && Date.now();
36
+
37
+ if (client.cache) ingestInCache(data, { cachedAt });
38
+
39
+ fireEvent('local.invitation.created', data);
40
+
41
+ return {
42
+ data: data.invitations,
43
+ cachedAt,
44
+ };
45
+ };
46
+ /* end_public_function */
@@ -0,0 +1,4 @@
1
+ export * from './createInvitations';
2
+ export * from './acceptInvitation';
3
+ export * from './rejectInvitation';
4
+ export * from './cancelInvitation';
@@ -0,0 +1,45 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { InvitationStatusEnum } from '~/@types';
3
+ import { pullFromCache, upsertInCache } from '~/cache/api';
4
+ import { getActiveClient } from '~/client/api/activeClient';
5
+
6
+ /* begin_public_function
7
+ id: invitation.reject
8
+ */
9
+ /**
10
+ * ```js
11
+ * import { rejectInvitation } from '@amityco/ts-sdk'
12
+ * const isRejected = await rejectInvitation(invitationId)
13
+ * ```
14
+ *
15
+ * Rejects a {@link Amity.Invitation} object
16
+ *
17
+ * @param invitationId the {@link Amity.Invitation} to reject
18
+ * @returns A success boolean if the {@link Amity.Invitation} was rejected
19
+ *
20
+ * @category Invitation API
21
+ * @async
22
+ */
23
+ export const rejectInvitation = async (invitationId: Amity.Invitation['_id']): Promise<boolean> => {
24
+ const client = getActiveClient();
25
+ client.log('invitation/rejectInvitation', invitationId);
26
+
27
+ const { data } = await client.http.post<{ success: boolean }>(
28
+ `/api/v1/invitations/${invitationId}/reject`,
29
+ );
30
+
31
+ const invitation = pullFromCache<Amity.InternalInvitation>([
32
+ 'invitation',
33
+ 'get',
34
+ invitationId,
35
+ ])?.data;
36
+
37
+ if (invitation) {
38
+ upsertInCache(['invitation', 'get', invitationId], { status: InvitationStatusEnum.Rejected });
39
+
40
+ fireEvent('local.invitation.updated', { invitations: [invitation] });
41
+ }
42
+
43
+ return data.success;
44
+ };
45
+ /* end_public_function */
@@ -0,0 +1,16 @@
1
+ import { InvitationTypeEnum } from '~/@types';
2
+ import { createInvitations } from '~/invitationRepository/internalApi';
3
+
4
+ export const communityLinkedObject = (community: Amity.RawCommunity): Amity.Community => {
5
+ return {
6
+ ...community,
7
+ createInvitations: async (userIds: string[]): Promise<void> => {
8
+ await createInvitations({
9
+ type: InvitationTypeEnum.CommunityMemberInvite,
10
+ targetType: 'community',
11
+ targetId: community.communityId,
12
+ userIds,
13
+ });
14
+ },
15
+ };
16
+ };
@@ -11,6 +11,8 @@ import { channelLinkedObject } from './channelLinkedObject';
11
11
  import { adLinkedObject } from './adLinkedObject';
12
12
  import { pinnedPostLinkedObject } from './pinnedPostLinkedObject';
13
13
  import { notificationTrayLinkedObject } from './notificationTrayLinkedObject';
14
+ import { communityLinkedObject } from './communityLinkedObject';
15
+ import { invitationLinkedObject } from './invitationLinkedObject';
14
16
 
15
17
  export const LinkedObject = {
16
18
  ad: adLinkedObject,
@@ -26,4 +28,6 @@ export const LinkedObject = {
26
28
  channel: channelLinkedObject,
27
29
  pinnedPost: pinnedPostLinkedObject,
28
30
  notificationTray: notificationTrayLinkedObject,
31
+ community: communityLinkedObject,
32
+ invitation: invitationLinkedObject,
29
33
  };