@amityco/ts-sdk 6.26.3 → 6.27.1-061592b.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/.env +26 -26
- package/dist/@types/core/model.d.ts +5 -5
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/ad.d.ts +14 -2
- package/dist/@types/domains/ad.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +6 -0
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +4 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +3 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/adRepository/api/getNetworkAds.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +2 -2
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +11 -5
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts +10 -5
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/api/renewal.d.ts.map +1 -1
- package/dist/client/api/setUploadedFileAccessType.d.ts +2 -0
- package/dist/client/api/setUploadedFileAccessType.d.ts.map +1 -0
- package/dist/client/events/index.d.ts +1 -0
- package/dist/client/events/index.d.ts.map +1 -1
- package/dist/client/events/onNetworkActivities.d.ts +11 -0
- package/dist/client/events/onNetworkActivities.d.ts.map +1 -0
- package/dist/client/utils/GlobalFileAccessType.d.ts +10 -0
- package/dist/client/utils/GlobalFileAccessType.d.ts.map +1 -0
- package/dist/client/utils/NetworkActivitiesWatcher.d.ts +12 -0
- package/dist/client/utils/NetworkActivitiesWatcher.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments.d.ts +1 -1
- package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +7 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/fileRepository/api/createFile.d.ts.map +1 -1
- package/dist/fileRepository/api/createImage.d.ts.map +1 -1
- package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
- package/dist/index.cjs.js +898 -688
- package/dist/index.esm.js +729 -517
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/api/createMessage.d.ts +7 -25
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts +4 -4
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +1 -1
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/api/updatePost.d.ts +1 -1
- package/dist/postRepository/api/updatePost.d.ts.map +1 -1
- package/dist/postRepository/internalApi/getPost.d.ts +5 -0
- package/dist/postRepository/internalApi/getPost.d.ts.map +1 -0
- package/dist/postRepository/internalApi/index.d.ts +13 -0
- package/dist/postRepository/internalApi/index.d.ts.map +1 -0
- package/dist/postRepository/observers/getPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts +12 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts +2 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -0
- package/dist/utils/linkedObject/adLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/adLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/categoryLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -1
- package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts +3 -3
- package/package.json +1 -1
- package/src/@types/core/model.ts +5 -5
- package/src/@types/core/payload.ts +1 -1
- package/src/@types/domains/ad.ts +17 -6
- package/src/@types/domains/file.ts +8 -0
- package/src/@types/domains/message.ts +6 -1
- package/src/@types/domains/post.ts +3 -4
- package/src/adRepository/api/getNetworkAds.ts +22 -8
- package/src/analytic/service/analytic/AnalyticsEngine.ts +2 -2
- package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +45 -27
- package/src/client/api/getToken.ts +15 -7
- package/src/client/api/index.ts +2 -0
- package/src/client/api/login.ts +11 -7
- package/src/client/api/logout.ts +4 -0
- package/src/client/api/renewal.ts +6 -1
- package/src/client/api/setUploadedFileAccessType.ts +5 -0
- package/src/client/api/tests/getToken.test.ts +3 -3
- package/src/client/events/index.ts +2 -0
- package/src/client/events/onNetworkActivities.ts +14 -0
- package/src/client/utils/GlobalFileAccessType.ts +23 -0
- package/src/client/utils/NetworkActivitiesWatcher.ts +31 -0
- package/src/commentRepository/observers/getComments.ts +1 -1
- package/src/communityRepository/utils/payload.ts +19 -3
- package/src/core/model/idResolvers.ts +1 -1
- package/src/core/transports/http.ts +25 -1
- package/src/fileRepository/api/createFile.ts +4 -0
- package/src/fileRepository/api/createImage.ts +4 -0
- package/src/fileRepository/api/createVideo.ts +4 -0
- package/src/fileRepository/api/uploadFile.ts +4 -0
- package/src/fileRepository/api/uploadImage.ts +4 -0
- package/src/fileRepository/api/uploadVideo.ts +4 -0
- package/src/messageRepository/api/createMessage.ts +83 -98
- package/src/messageRepository/events/onMessageCreated.ts +12 -6
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +26 -24
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +3 -2
- package/src/messageRepository/observers/observeMessages.ts +3 -3
- package/src/messageRepository/utils/prepareMessagePayload.ts +1 -1
- package/src/postRepository/internalApi/getPost.ts +65 -0
- package/src/postRepository/internalApi/index.ts +16 -0
- package/src/postRepository/observers/getPost.ts +8 -1
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +190 -0
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +45 -0
- package/src/postRepository/observers/getPosts/PostQueryStreamController.ts +102 -0
- package/src/postRepository/observers/getPosts/enums.ts +11 -0
- package/src/postRepository/observers/getPosts.ts +6 -197
- package/src/postRepository/utils/payload.ts +17 -0
- package/src/utils/linkedObject/adLinkedObject.ts +11 -11
- package/src/utils/linkedObject/categoryLinkedObject.ts +6 -28
- package/src/utils/linkedObject/userLinkedObject.ts +8 -27
|
@@ -21,19 +21,19 @@ export class AnalyticsEventCapturer {
|
|
|
21
21
|
_bufferNewSeenStoryReferenceIds: Amity.Story['referenceId'][] = [];
|
|
22
22
|
|
|
23
23
|
isAbleToEnqueue({
|
|
24
|
-
|
|
24
|
+
uniqueId,
|
|
25
25
|
expireTime,
|
|
26
26
|
isHighPriority = false,
|
|
27
27
|
}: {
|
|
28
|
-
|
|
28
|
+
uniqueId: string;
|
|
29
29
|
expireTime: number;
|
|
30
30
|
isHighPriority?: boolean;
|
|
31
31
|
}) {
|
|
32
32
|
const now = new Date();
|
|
33
33
|
|
|
34
34
|
const getRecentViewedDate = () => {
|
|
35
|
-
if (isHighPriority) return this._recentHighPriorityViewed[
|
|
36
|
-
return this._recentViewed[
|
|
35
|
+
if (isHighPriority) return this._recentHighPriorityViewed[uniqueId];
|
|
36
|
+
return this._recentViewed[uniqueId];
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const recentViewedDate = getRecentViewedDate() || new Date(DAY * -1);
|
|
@@ -48,13 +48,20 @@ export class AnalyticsEventCapturer {
|
|
|
48
48
|
return true;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
markAs(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
markAs({
|
|
52
|
+
uniqueId,
|
|
53
|
+
contentId,
|
|
54
|
+
contentType,
|
|
55
|
+
activityType,
|
|
56
|
+
metadata,
|
|
57
|
+
}: {
|
|
58
|
+
uniqueId: string;
|
|
59
|
+
contentId: string;
|
|
60
|
+
contentType: Amity.AnalyticEventContentType;
|
|
61
|
+
activityType: Amity.AnalyticEventActivityType;
|
|
62
|
+
metadata?: Record<string, string>;
|
|
63
|
+
}) {
|
|
64
|
+
if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime })) return;
|
|
58
65
|
|
|
59
66
|
const now = new Date();
|
|
60
67
|
|
|
@@ -72,7 +79,7 @@ export class AnalyticsEventCapturer {
|
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
const analyticItem: Amity.AnalyticEventModel = {
|
|
75
|
-
contentId
|
|
82
|
+
contentId,
|
|
76
83
|
contentType,
|
|
77
84
|
activityType,
|
|
78
85
|
timestamp: now.toISOString(),
|
|
@@ -85,11 +92,16 @@ export class AnalyticsEventCapturer {
|
|
|
85
92
|
currentData.event.push(analyticItem);
|
|
86
93
|
|
|
87
94
|
upsertInCache(ANALYTIC_CACHE_KEY, currentData);
|
|
88
|
-
this._recentViewed[
|
|
95
|
+
this._recentViewed[uniqueId] = now;
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
markPostAsViewed(postId: Amity.InternalPost['postId']) {
|
|
92
|
-
this.markAs(
|
|
99
|
+
this.markAs({
|
|
100
|
+
uniqueId: postId,
|
|
101
|
+
contentId: postId,
|
|
102
|
+
contentType: Amity.AnalyticEventContentType.Post,
|
|
103
|
+
activityType: Amity.AnalyticEventActivityType.View,
|
|
104
|
+
});
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
markStory(story: Amity.InternalStory, activityType: Amity.AnalyticEventActivityType) {
|
|
@@ -99,7 +111,7 @@ export class AnalyticsEventCapturer {
|
|
|
99
111
|
|
|
100
112
|
if (
|
|
101
113
|
!this.isAbleToEnqueue({
|
|
102
|
-
|
|
114
|
+
uniqueId: story.storyId,
|
|
103
115
|
expireTime: expireTime.getTime(),
|
|
104
116
|
isHighPriority: true,
|
|
105
117
|
})
|
|
@@ -179,29 +191,35 @@ export class AnalyticsEventCapturer {
|
|
|
179
191
|
this.markStory(story, Amity.AnalyticEventActivityType.Click);
|
|
180
192
|
}
|
|
181
193
|
|
|
182
|
-
markAdAsViewed(ad: Amity.
|
|
194
|
+
markAdAsViewed(ad: Amity.InternalAd, placement: Amity.AdPlacement) {
|
|
183
195
|
const metadata = {
|
|
184
196
|
placement,
|
|
185
197
|
};
|
|
186
198
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
const activityType = Amity.AnalyticEventActivityType.View;
|
|
200
|
+
|
|
201
|
+
this.markAs({
|
|
202
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
203
|
+
contentId: ad.adId,
|
|
204
|
+
contentType: Amity.AnalyticEventContentType.Ad,
|
|
205
|
+
activityType,
|
|
191
206
|
metadata,
|
|
192
|
-
);
|
|
207
|
+
});
|
|
193
208
|
}
|
|
194
209
|
|
|
195
|
-
markAdAsClicked(ad: Amity.
|
|
210
|
+
markAdAsClicked(ad: Amity.InternalAd, placement: Amity.AdPlacement) {
|
|
196
211
|
const metadata = {
|
|
197
212
|
placement,
|
|
198
213
|
};
|
|
199
214
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
215
|
+
const activityType = Amity.AnalyticEventActivityType.Click;
|
|
216
|
+
|
|
217
|
+
this.markAs({
|
|
218
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
219
|
+
contentId: ad.adId,
|
|
220
|
+
contentType: Amity.AnalyticEventContentType.Ad,
|
|
221
|
+
activityType,
|
|
204
222
|
metadata,
|
|
205
|
-
);
|
|
223
|
+
});
|
|
206
224
|
}
|
|
207
225
|
}
|
|
@@ -14,11 +14,17 @@ import { getDeviceInfo } from '~/core/device';
|
|
|
14
14
|
* @category Client API
|
|
15
15
|
* @hidden
|
|
16
16
|
*/
|
|
17
|
-
export const getToken = async (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
export const getToken = async ({
|
|
18
|
+
params,
|
|
19
|
+
options,
|
|
20
|
+
}: {
|
|
21
|
+
params: {
|
|
22
|
+
userId: Amity.InternalUser['userId'];
|
|
23
|
+
displayName?: Amity.InternalUser['displayName'];
|
|
24
|
+
authToken?: string;
|
|
25
|
+
deviceId: Amity.Device['deviceId'];
|
|
26
|
+
};
|
|
27
|
+
options?: { setAccessTokenCookie?: boolean };
|
|
22
28
|
}) => {
|
|
23
29
|
const client = getActiveClient();
|
|
24
30
|
client.log('client/api/getToken', params);
|
|
@@ -32,8 +38,10 @@ export const getToken = async (params: {
|
|
|
32
38
|
deviceInfo,
|
|
33
39
|
},
|
|
34
40
|
{
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
headers: {
|
|
42
|
+
'X-API-Key': client.apiKey,
|
|
43
|
+
'set-access-token-cookie': options?.setAccessTokenCookie || false,
|
|
44
|
+
},
|
|
37
45
|
},
|
|
38
46
|
);
|
|
39
47
|
|
package/src/client/api/index.ts
CHANGED
package/src/client/api/login.ts
CHANGED
|
@@ -18,8 +18,6 @@ import { getActiveClient } from './activeClient';
|
|
|
18
18
|
import { terminateClient } from './terminateClient';
|
|
19
19
|
import { setActiveUser } from './activeUser';
|
|
20
20
|
|
|
21
|
-
import { setSessionState } from './setSessionState';
|
|
22
|
-
|
|
23
21
|
import { onClientBanned } from '../events';
|
|
24
22
|
import { onTokenExpired } from '../events/onTokenExpired';
|
|
25
23
|
import { onTokenTerminated } from '../events/onTokenTerminated';
|
|
@@ -29,6 +27,7 @@ import { removeChannelMarkerCache } from '../utils/removeChannelMarkerCache';
|
|
|
29
27
|
import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
|
|
30
28
|
import { startMarkerSync } from '../utils/markerSyncEngine';
|
|
31
29
|
import { ASCError } from '~/core/errors';
|
|
30
|
+
import SessionWatcher from '../utils/SessionWatcher';
|
|
32
31
|
|
|
33
32
|
/*
|
|
34
33
|
* declared earlier to accomodate case when logging in with a different user
|
|
@@ -92,9 +91,14 @@ export const login = async (
|
|
|
92
91
|
|
|
93
92
|
try {
|
|
94
93
|
const { users } = await setClientToken({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
params: {
|
|
95
|
+
...params,
|
|
96
|
+
displayName: params?.displayName,
|
|
97
|
+
deviceId: params?.deviceId || defaultDeviceId,
|
|
98
|
+
},
|
|
99
|
+
options: {
|
|
100
|
+
setAccessTokenCookie: true,
|
|
101
|
+
},
|
|
98
102
|
});
|
|
99
103
|
|
|
100
104
|
const user = users.find(u => u.userId === params.userId);
|
|
@@ -139,7 +143,7 @@ export const login = async (
|
|
|
139
143
|
* if getting token failed session state reverts to initial state when app
|
|
140
144
|
* is first launched
|
|
141
145
|
*/
|
|
142
|
-
setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
|
|
146
|
+
SessionWatcher.getInstance().setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
|
|
143
147
|
|
|
144
148
|
// pass error down tree so the calling function handle it
|
|
145
149
|
throw error;
|
|
@@ -181,7 +185,7 @@ export const login = async (
|
|
|
181
185
|
}),
|
|
182
186
|
|
|
183
187
|
onTokenExpired(state => {
|
|
184
|
-
setSessionState(state);
|
|
188
|
+
SessionWatcher.getInstance().setSessionState(state);
|
|
185
189
|
|
|
186
190
|
logout();
|
|
187
191
|
|
package/src/client/api/logout.ts
CHANGED
|
@@ -60,6 +60,10 @@ export const logout = async (): Promise<boolean> => {
|
|
|
60
60
|
};
|
|
61
61
|
client.ws.io.opts.query = { token: '' };
|
|
62
62
|
|
|
63
|
+
if (typeof document !== 'undefined') {
|
|
64
|
+
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
65
|
+
}
|
|
66
|
+
|
|
63
67
|
/*
|
|
64
68
|
* Cache should be usable if tokenExpired
|
|
65
69
|
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#SDK-usability-based-on-Session-State
|
|
@@ -40,7 +40,12 @@ export const renewal = (): Amity.AccessTokenRenewal => {
|
|
|
40
40
|
} else {
|
|
41
41
|
// about to expire
|
|
42
42
|
|
|
43
|
-
await refreshToken(
|
|
43
|
+
await refreshToken({
|
|
44
|
+
params,
|
|
45
|
+
options: {
|
|
46
|
+
setAccessTokenCookie: true,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
tokenRenewed = true;
|
|
@@ -13,7 +13,7 @@ describe('getToken', () => {
|
|
|
13
13
|
const mockApi = jest.fn().mockResolvedValue(sessionResponse);
|
|
14
14
|
client.http.post = mockApi;
|
|
15
15
|
|
|
16
|
-
await getToken(params);
|
|
16
|
+
await getToken({ params });
|
|
17
17
|
const [recieved] = mockApi.mock.lastCall;
|
|
18
18
|
|
|
19
19
|
expect(recieved).toBe(expected);
|
|
@@ -23,7 +23,7 @@ describe('getToken', () => {
|
|
|
23
23
|
const expected = sessionResponse.data;
|
|
24
24
|
client.http.post = jest.fn().mockResolvedValue(sessionResponse);
|
|
25
25
|
|
|
26
|
-
const recieved = await getToken(params);
|
|
26
|
+
const recieved = await getToken({ params });
|
|
27
27
|
|
|
28
28
|
expect(recieved).toStrictEqual(expected);
|
|
29
29
|
});
|
|
@@ -31,6 +31,6 @@ describe('getToken', () => {
|
|
|
31
31
|
test('it should throw error', async () => {
|
|
32
32
|
client.http.post = jest.fn().mockRejectedValue(new Error('error'));
|
|
33
33
|
|
|
34
|
-
await expect(getToken(params)).rejects.toThrow();
|
|
34
|
+
await expect(getToken({ params })).rejects.toThrow();
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import NetworkActivitiesWatcher from '~/client/utils/NetworkActivitiesWatcher';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
6
|
+
*
|
|
7
|
+
* @param callback The function to call when the event was fired
|
|
8
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9
|
+
*
|
|
10
|
+
* @category Client Events
|
|
11
|
+
*/
|
|
12
|
+
export const onNetworkActivities = (
|
|
13
|
+
callback: (request: Request, response: Response) => void,
|
|
14
|
+
): Amity.Unsubscriber => NetworkActivitiesWatcher.getInstance().onNetworkActivities(callback);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FileAccessTypeEnum } from '~/@types';
|
|
2
|
+
|
|
3
|
+
export class GlobalFileAccessType {
|
|
4
|
+
#fileAccessType: Amity.FileAccessType = FileAccessTypeEnum.PUBLIC;
|
|
5
|
+
|
|
6
|
+
public setFileAccessType(fileAccessType: Amity.FileAccessType) {
|
|
7
|
+
this.#fileAccessType = fileAccessType;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public getFileAccessType() {
|
|
11
|
+
return this.#fileAccessType;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let instance: GlobalFileAccessType;
|
|
16
|
+
export default {
|
|
17
|
+
getInstance: () => {
|
|
18
|
+
if (!instance) {
|
|
19
|
+
instance = new GlobalFileAccessType();
|
|
20
|
+
}
|
|
21
|
+
return instance;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type NetworkActivitiesCallback = (request: Request, response: Response) => void;
|
|
2
|
+
|
|
3
|
+
class NetworkActivitiesWatcher {
|
|
4
|
+
private _listener = new Map<NetworkActivitiesCallback, NetworkActivitiesCallback>();
|
|
5
|
+
|
|
6
|
+
onNetworkActivities(callback: NetworkActivitiesCallback) {
|
|
7
|
+
this._listener.set(callback, callback);
|
|
8
|
+
return () => {
|
|
9
|
+
this._listener.delete(callback);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setNetworkActivities(request: Request, response: Response) {
|
|
14
|
+
this._listener.forEach(cb => cb(request, response));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
destroy() {
|
|
18
|
+
this._listener.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let instance: NetworkActivitiesWatcher;
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
getInstance: () => {
|
|
26
|
+
if (!instance) {
|
|
27
|
+
instance = new NetworkActivitiesWatcher();
|
|
28
|
+
}
|
|
29
|
+
return instance;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -28,7 +28,7 @@ import { CommentLiveCollectionController } from './getComments/CommentLiveCollec
|
|
|
28
28
|
*/
|
|
29
29
|
export const getComments = (
|
|
30
30
|
params: Amity.CommentLiveCollection,
|
|
31
|
-
callback: Amity.LiveCollectionCallback<Amity.
|
|
31
|
+
callback: Amity.LiveCollectionCallback<Amity.Comment>,
|
|
32
32
|
config?: Amity.LiveCollectionConfig,
|
|
33
33
|
): Amity.Unsubscriber => {
|
|
34
34
|
const { log, cache } = getActiveClient();
|
|
@@ -30,9 +30,13 @@ const convertCommunityUsersToUniqueObject = (
|
|
|
30
30
|
return result;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
export const convertCommunityPayload = (rawPayload: {
|
|
34
|
+
communities: Amity.RawCommunity[];
|
|
35
|
+
communityUsers: Amity.RawMembership<'community'>[];
|
|
36
|
+
}): {
|
|
37
|
+
communities: Amity.Community[];
|
|
38
|
+
communityUsers: Amity.Membership<'community'>[];
|
|
39
|
+
} => {
|
|
36
40
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
37
41
|
const communities = rawPayload.communities.map<Amity.Community>(
|
|
38
42
|
({ needApprovalOnPostCreation, onlyAdminCanPost, ...restCommunityPayload }) => ({
|
|
@@ -72,6 +76,18 @@ export const prepareCommunityPayload = (
|
|
|
72
76
|
};
|
|
73
77
|
};
|
|
74
78
|
|
|
79
|
+
export const prepareCommunityPayload = (
|
|
80
|
+
rawPayload: Amity.CommunityPayload,
|
|
81
|
+
): Amity.ProcessedCommunityPayload => {
|
|
82
|
+
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...rawPayload,
|
|
86
|
+
communities,
|
|
87
|
+
communityUsers,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
75
91
|
export const prepareCommunityRequest = <
|
|
76
92
|
T extends {
|
|
77
93
|
postSetting?: Amity.Community['postSetting'];
|
|
@@ -18,7 +18,7 @@ const idResolvers: Resolvers = {
|
|
|
18
18
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
19
19
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
20
20
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
21
|
-
message: ({ messageId }) => messageId,
|
|
21
|
+
message: ({ messageId, referenceId }) => referenceId ?? messageId,
|
|
22
22
|
|
|
23
23
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
24
24
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
@@ -5,6 +5,7 @@ import { ASCError } from '~/core/errors';
|
|
|
5
5
|
|
|
6
6
|
import { fireEvent } from '../events';
|
|
7
7
|
import { unwrapPayload } from './utils';
|
|
8
|
+
import NetworkActivitiesWatcher from '~/client/utils/NetworkActivitiesWatcher';
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
* Defined here as transport is a private module. Also, outside of this module
|
|
@@ -131,7 +132,30 @@ export const createHttpTransport = (endpoint: string) => {
|
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
instance.interceptors.response.use(
|
|
134
|
-
response =>
|
|
135
|
+
response => {
|
|
136
|
+
const headers = new Headers();
|
|
137
|
+
|
|
138
|
+
Object.entries(response.headers).forEach(([key, value]) => {
|
|
139
|
+
if (typeof value === 'string') {
|
|
140
|
+
headers.append(key, value);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
NetworkActivitiesWatcher.getInstance().setNetworkActivities(
|
|
145
|
+
new Request(response.request.url, {
|
|
146
|
+
method: response.request.method,
|
|
147
|
+
headers: response.request.headers,
|
|
148
|
+
body: response.request.data,
|
|
149
|
+
}),
|
|
150
|
+
new Response(response.data, {
|
|
151
|
+
status: response.status,
|
|
152
|
+
statusText: response.statusText,
|
|
153
|
+
headers,
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return response;
|
|
158
|
+
},
|
|
135
159
|
error => {
|
|
136
160
|
const { response } = error;
|
|
137
161
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* ```js
|
|
@@ -28,6 +29,9 @@ export const createFile = async <T extends Amity.FileType = any>(
|
|
|
28
29
|
|
|
29
30
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
30
31
|
|
|
32
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
33
|
+
formData.append('accessType', accessType);
|
|
34
|
+
|
|
31
35
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
32
36
|
|
|
33
37
|
const headers =
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* ```js
|
|
@@ -27,6 +28,9 @@ export const createImage = async (
|
|
|
27
28
|
|
|
28
29
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
29
30
|
|
|
31
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
32
|
+
formData.append('accessType', accessType);
|
|
33
|
+
|
|
30
34
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
31
35
|
|
|
32
36
|
const headers =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* ```js
|
|
@@ -30,6 +31,9 @@ export const createVideo = async (
|
|
|
30
31
|
|
|
31
32
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
32
33
|
|
|
34
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
35
|
+
formData.append('accessType', accessType);
|
|
36
|
+
|
|
33
37
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
34
38
|
|
|
35
39
|
if (feedType) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
5
|
|
|
5
6
|
/* begin_public_function
|
|
6
7
|
id: file.upload.file
|
|
@@ -31,6 +32,9 @@ export const uploadFile = async <T extends Amity.FileType = any>(
|
|
|
31
32
|
|
|
32
33
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
33
34
|
|
|
35
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
36
|
+
formData.append('accessType', accessType);
|
|
37
|
+
|
|
34
38
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
35
39
|
|
|
36
40
|
const headers =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
5
|
|
|
5
6
|
/* begin_public_function
|
|
6
7
|
id: file.upload.image
|
|
@@ -31,6 +32,9 @@ export const uploadImage = async (
|
|
|
31
32
|
|
|
32
33
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
33
34
|
|
|
35
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
36
|
+
formData.append('accessType', accessType);
|
|
37
|
+
|
|
34
38
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
35
39
|
|
|
36
40
|
const headers =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
5
|
|
|
5
6
|
/* begin_public_function
|
|
6
7
|
id: file.upload.video, file.upload.audio
|
|
@@ -33,6 +34,9 @@ export const uploadVideo = async (
|
|
|
33
34
|
|
|
34
35
|
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
35
36
|
|
|
37
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
38
|
+
formData.append('accessType', accessType);
|
|
39
|
+
|
|
36
40
|
formData.append('preferredFilename', (files[0] as File).name);
|
|
37
41
|
|
|
38
42
|
if (feedType) {
|