@amityco/ts-sdk 6.17.3-c7279f3.0 → 6.17.3
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/client/api/login.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts +1 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/index.cjs.js +105 -114
- package/dist/index.esm.js +105 -114
- package/dist/index.umd.js +2 -2
- package/dist/storyRepository/observers/getActiveStoriesByTarget.d.ts.map +1 -1
- package/dist/storyRepository/utils/convertRawToStory.d.ts +2 -2
- package/dist/storyRepository/utils/convertRawToStory.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/api/login.ts +29 -6
- package/src/client/api/logout.ts +5 -0
- package/src/client/utils/setClientToken.ts +1 -1
- package/src/commentRepository/api/deleteComment.ts +12 -29
- package/src/storyRepository/events/onStoryCreated.ts +1 -1
- package/src/storyRepository/observers/getActiveStoriesByTarget.ts +5 -11
- package/src/storyRepository/utils/convertRawToStory.ts +3 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getActiveStoriesByTarget.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/observers/getActiveStoriesByTarget.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,WAC3B,MAAM,uBAAuB,YAC3B,MAAM,sBAAsB,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"getActiveStoriesByTarget.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/observers/getActiveStoriesByTarget.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,WAC3B,MAAM,uBAAuB,YAC3B,MAAM,sBAAsB,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,eAyKhE,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const convertRawStoryToInternalStory: (rawData: Amity.RawStory
|
|
2
|
-
export declare const convertStoryRawToInternal: (data: Amity.StoryPayload
|
|
1
|
+
export declare const convertRawStoryToInternalStory: (rawData: Amity.RawStory) => Amity.InternalStory;
|
|
2
|
+
export declare const convertStoryRawToInternal: (data: Amity.StoryPayload) => Amity.StoryWithOptimisticPayload;
|
|
3
3
|
//# sourceMappingURL=convertRawToStory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertRawToStory.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/utils/convertRawToStory.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B,
|
|
1
|
+
{"version":3,"file":"convertRawToStory.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/utils/convertRawToStory.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B,YAAa,MAAM,QAAQ,KAAG,MAAM,aAK9E,CAAC;AAEF,eAAO,MAAM,yBAAyB,SAC9B,MAAM,YAAY,KACvB,MAAM,0BAIR,CAAC"}
|
package/package.json
CHANGED
package/src/client/api/login.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { onTokenTerminated } from '../events/onTokenTerminated';
|
|
|
25
25
|
import { setClientToken } from '../utils/setClientToken';
|
|
26
26
|
import { removeChannelMarkerCache } from '../utils/removeChannelMarkerCache';
|
|
27
27
|
import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
|
|
28
|
+
import { ASCError } from '~/core/errors';
|
|
28
29
|
|
|
29
30
|
/*
|
|
30
31
|
* declared earlier to accomodate case when logging in with a different user
|
|
@@ -84,12 +85,34 @@ export const login = async (
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
// default values
|
|
87
|
-
|
|
88
|
+
const defaultDeviceId = await getDeviceId();
|
|
88
89
|
|
|
89
90
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const { users } = await setClientToken({
|
|
92
|
+
...params,
|
|
93
|
+
displayName: params?.displayName || params.userId,
|
|
94
|
+
deviceId: params?.deviceId || defaultDeviceId,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const user = users.find(u => u.userId === params.userId);
|
|
98
|
+
|
|
99
|
+
if (user == null) {
|
|
100
|
+
throw new ASCError(
|
|
101
|
+
`${params.userId} has not been founded`,
|
|
102
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
103
|
+
Amity.ErrorLevel.ERROR,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (user.isDeleted) {
|
|
108
|
+
terminateClient(Amity.TokenTerminationReason.USER_DELETED);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (user.isGlobalBanned) {
|
|
113
|
+
terminateClient(Amity.TokenTerminationReason.GLOBAL_BAN);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
93
116
|
|
|
94
117
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
95
118
|
// wire websocket events to our event emitter
|
|
@@ -99,7 +122,7 @@ export const login = async (
|
|
|
99
122
|
client.ws.open();
|
|
100
123
|
});
|
|
101
124
|
|
|
102
|
-
client.userId =
|
|
125
|
+
client.userId = user.userId;
|
|
103
126
|
|
|
104
127
|
client.sessionHandler = sessionHandler;
|
|
105
128
|
|
|
@@ -113,7 +136,7 @@ export const login = async (
|
|
|
113
136
|
sessionHandler!,
|
|
114
137
|
);
|
|
115
138
|
|
|
116
|
-
setActiveUser(
|
|
139
|
+
setActiveUser(user);
|
|
117
140
|
} catch (error) {
|
|
118
141
|
/*
|
|
119
142
|
* if getting token failed session state reverts to initial state when app
|
package/src/client/api/logout.ts
CHANGED
|
@@ -53,6 +53,11 @@ export const logout = async (): Promise<boolean> => {
|
|
|
53
53
|
client.token = undefined;
|
|
54
54
|
|
|
55
55
|
client.http.defaults.headers.common.Authorization = '';
|
|
56
|
+
client.http.defaults.metadata = {
|
|
57
|
+
tokenExpiry: '',
|
|
58
|
+
isGlobalBanned: false,
|
|
59
|
+
isUserDeleted: false,
|
|
60
|
+
};
|
|
56
61
|
client.ws.io.opts.query = { token: '' };
|
|
57
62
|
|
|
58
63
|
/*
|
|
@@ -14,7 +14,7 @@ import { getToken } from '../api/getToken';
|
|
|
14
14
|
* @category private
|
|
15
15
|
* @async
|
|
16
16
|
*/
|
|
17
|
-
export const setClientToken = async (params: Parameters<typeof getToken>) => {
|
|
17
|
+
export const setClientToken = async (params: Parameters<typeof getToken>[0]) => {
|
|
18
18
|
const client = getActiveClient();
|
|
19
19
|
// begin establishing session
|
|
20
20
|
setSessionState(Amity.SessionStates.ESTABLISHING);
|
|
@@ -7,7 +7,6 @@ import { getPost } from '~/postRepository/api/getPost';
|
|
|
7
7
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
8
8
|
import { scheduleTask } from '~/core/microtasks';
|
|
9
9
|
|
|
10
|
-
import { getStoryByStoryId } from '~/storyRepository/internalApi/getStoryByStoryId';
|
|
11
10
|
import { getComment } from './getComment';
|
|
12
11
|
|
|
13
12
|
/* begin_public_function
|
|
@@ -49,36 +48,20 @@ export const deleteComment = async (
|
|
|
49
48
|
// to support hard deletion
|
|
50
49
|
const deleted = { ...comment.data, isDeleted: true };
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
const story = await getStoryByStoryId(comment.data.referenceId);
|
|
51
|
+
const post = await getPost(comment.data.referenceId);
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// @TODO: Need to separate Local / MQTT later
|
|
68
|
-
fireEvent('post.updated', {
|
|
69
|
-
posts: [post.data],
|
|
70
|
-
categories: [],
|
|
71
|
-
comments: [],
|
|
72
|
-
communities: [],
|
|
73
|
-
communityUsers: [],
|
|
74
|
-
feeds: [],
|
|
75
|
-
files: [],
|
|
76
|
-
postChildren: [],
|
|
77
|
-
users: [],
|
|
78
|
-
});
|
|
79
|
-
}
|
|
53
|
+
fireEvent('post.updated', {
|
|
54
|
+
posts: [post.data],
|
|
55
|
+
categories: [],
|
|
56
|
+
comments: [],
|
|
57
|
+
communities: [],
|
|
58
|
+
communityUsers: [],
|
|
59
|
+
feeds: [],
|
|
60
|
+
files: [],
|
|
61
|
+
postChildren: [],
|
|
62
|
+
users: [],
|
|
63
|
+
});
|
|
80
64
|
|
|
81
|
-
// @TODO: Need to separate Local / MQTT later
|
|
82
65
|
fireEvent('comment.deleted', {
|
|
83
66
|
comments: [deleted],
|
|
84
67
|
commentChildren: [],
|
|
@@ -8,7 +8,7 @@ export const onStoryCreated = (callback: Amity.Listener<Amity.InternalStory[]>)
|
|
|
8
8
|
|
|
9
9
|
const filter = async (payload: Amity.StoryPayload) => {
|
|
10
10
|
// Apply the necessary field for story payload
|
|
11
|
-
const convertPayload = convertStoryRawToInternal(payload
|
|
11
|
+
const convertPayload = convertStoryRawToInternal(payload);
|
|
12
12
|
ingestInCache(convertPayload);
|
|
13
13
|
callback(convertPayload.stories);
|
|
14
14
|
};
|
|
@@ -137,7 +137,6 @@ export const getActiveStoriesByTarget = (
|
|
|
137
137
|
|
|
138
138
|
const processNewData = (
|
|
139
139
|
result: Amity.InternalStory[] | undefined,
|
|
140
|
-
event: string,
|
|
141
140
|
initial = false,
|
|
142
141
|
loading = false,
|
|
143
142
|
error = false,
|
|
@@ -152,14 +151,9 @@ export const getActiveStoriesByTarget = (
|
|
|
152
151
|
};
|
|
153
152
|
|
|
154
153
|
if (result) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
} else {
|
|
159
|
-
data.data = initial
|
|
160
|
-
? result.map(getResolver('story'))
|
|
161
|
-
: [...new Set([...data.data, ...result.map(getResolver('story'))])];
|
|
162
|
-
}
|
|
154
|
+
data.data = initial
|
|
155
|
+
? result.map(getResolver('story'))
|
|
156
|
+
: [...new Set([...data.data, ...result.map(getResolver('story'))])];
|
|
163
157
|
}
|
|
164
158
|
|
|
165
159
|
pushToCache(cacheKey, data.data);
|
|
@@ -168,7 +162,7 @@ export const getActiveStoriesByTarget = (
|
|
|
168
162
|
};
|
|
169
163
|
|
|
170
164
|
const realtimeRouter = (event: Amity.StoryActionType) => (story: Amity.InternalStory[]) => {
|
|
171
|
-
processNewData(story
|
|
165
|
+
processNewData(story);
|
|
172
166
|
};
|
|
173
167
|
|
|
174
168
|
const reloadData = () => (newData: { referenceIds: Amity.Story['referenceId'][] }) => {
|
|
@@ -197,7 +191,7 @@ export const getActiveStoriesByTarget = (
|
|
|
197
191
|
const query = createQuery(_getActiveStoriesByTarget, params);
|
|
198
192
|
|
|
199
193
|
runQuery(query, ({ data: result, error, loading }) => {
|
|
200
|
-
processNewData(result,
|
|
194
|
+
processNewData(result, initial, loading, error);
|
|
201
195
|
});
|
|
202
196
|
};
|
|
203
197
|
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
2
2
|
|
|
3
|
-
export const convertRawStoryToInternalStory = (
|
|
4
|
-
rawData: Amity.RawStory,
|
|
5
|
-
isCreated = false,
|
|
6
|
-
): Amity.InternalStory => {
|
|
3
|
+
export const convertRawStoryToInternalStory = (rawData: Amity.RawStory): Amity.InternalStory => {
|
|
7
4
|
const { storyId, referenceId } = rawData;
|
|
8
5
|
|
|
9
|
-
if (
|
|
10
|
-
if (referenceId) return { ...rawData, syncState: Amity.SyncState.Synced };
|
|
11
|
-
}
|
|
12
|
-
|
|
6
|
+
if (referenceId) return { ...rawData, syncState: Amity.SyncState.Synced };
|
|
13
7
|
return { ...rawData, syncState: Amity.SyncState.Synced, referenceId: storyId };
|
|
14
8
|
};
|
|
15
9
|
|
|
16
10
|
export const convertStoryRawToInternal = (
|
|
17
11
|
data: Amity.StoryPayload,
|
|
18
|
-
isCreated = false,
|
|
19
12
|
): Amity.StoryWithOptimisticPayload => {
|
|
20
13
|
const { stories } = data;
|
|
21
|
-
const storiesData = stories.map(
|
|
14
|
+
const storiesData = stories.map(convertRawStoryToInternalStory);
|
|
22
15
|
return { ...data, stories: storiesData };
|
|
23
16
|
};
|