@amityco/ts-sdk 0.0.1-beta.18 → 0.0.1-beta.20
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/dist/@types/core/events.d.ts +1 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +5 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +5 -2
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +7 -7
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +1 -1
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +2 -0
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts +5 -4
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/external/api/createUserToken.d.ts +23 -0
- package/dist/external/api/createUserToken.d.ts.map +1 -0
- package/dist/external/api/index.d.ts +2 -0
- package/dist/external/api/index.d.ts.map +1 -0
- package/dist/file/api/createImage.d.ts +17 -0
- package/dist/file/api/createImage.d.ts.map +1 -0
- package/dist/file/api/index.d.ts +1 -0
- package/dist/file/api/index.d.ts.map +1 -1
- package/dist/index.cjs.js +11544 -6708
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +11524 -6693
- package/dist/index.umd.js +5 -5
- package/dist/poll/api/createPoll.d.ts +3 -1
- package/dist/poll/api/createPoll.d.ts.map +1 -1
- package/dist/reaction/api/index.d.ts +1 -0
- package/dist/reaction/api/index.d.ts.map +1 -1
- package/dist/reaction/api/queryReactions.d.ts +24 -0
- package/dist/reaction/api/queryReactions.d.ts.map +1 -0
- package/dist/user/events/index.d.ts +1 -0
- package/dist/user/events/index.d.ts.map +1 -1
- package/dist/user/events/onUserDeleted.d.ts +17 -0
- package/dist/user/events/onUserDeleted.d.ts.map +1 -0
- package/dist/user/observers/observeUser.d.ts +1 -1
- package/dist/user/observers/observeUser.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/@types/core/events.ts +1 -0
- package/src/@types/core/model.ts +2 -0
- package/src/@types/core/payload.ts +6 -0
- package/src/@types/domains/comment.ts +1 -0
- package/src/@types/domains/message.ts +10 -1
- package/src/@types/domains/reaction.ts +8 -8
- package/src/@types/domains/user.ts +1 -0
- package/src/channel/api/queryChannels.ts +2 -0
- package/src/client/api/connectClient.ts +17 -10
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/identifyModel.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/core/subscription.ts +10 -1
- package/src/external/api/createUserToken.ts +43 -0
- package/src/external/api/index.ts +1 -0
- package/src/file/api/createImage.ts +58 -0
- package/src/file/api/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/poll/api/createPoll.ts +3 -1
- package/src/reaction/api/index.ts +1 -0
- package/src/reaction/api/queryReactions.ts +52 -0
- package/src/user/events/index.ts +1 -0
- package/src/user/events/onUserDeleted.ts +19 -0
- package/src/user/events/utils.ts +1 -1
- package/src/user/observers/observeUser.ts +9 -2
|
@@ -19,5 +19,7 @@
|
|
|
19
19
|
* @category Poll API
|
|
20
20
|
* @async
|
|
21
21
|
*/
|
|
22
|
-
export declare const createPoll: (bundle: Pick<Amity.Poll, 'question' | '
|
|
22
|
+
export declare const createPoll: (bundle: Pick<Amity.Poll, 'question' | 'answerType' | 'closedIn'> & {
|
|
23
|
+
answers: Pick<Amity.PollAnswer, 'dataType' | 'data'>[];
|
|
24
|
+
}) => Promise<Amity.Cached<Amity.Poll>>;
|
|
23
25
|
//# sourceMappingURL=createPoll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/createPoll.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,UAAU,WACb,KAAK,MAAM,IAAI,EAAE,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"createPoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/createPoll.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,UAAU,WACb,KAAK,MAAM,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC,GAAG;IACjE,OAAO,EAAE,KAAK,MAAM,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC;CACxD,KACA,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAelC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { queryReactions } from '@amityco/ts-sdk'
|
|
4
|
+
* const { data: reactions, prevPage, nextPage } = await queryReactions({
|
|
5
|
+
* referenceId: 'postId',
|
|
6
|
+
* referenceType: 'post',
|
|
7
|
+
* })
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Queries a paginable list of {@link Amity.ReactionQuery} objects
|
|
11
|
+
*
|
|
12
|
+
* @param query The query parameters
|
|
13
|
+
* @returns A page of {@link Amity.Reaction} objects
|
|
14
|
+
*
|
|
15
|
+
* @reaction Reaction API
|
|
16
|
+
* @async
|
|
17
|
+
* */
|
|
18
|
+
export declare const queryReactions: (query: {
|
|
19
|
+
referenceId: Amity.Reaction['referenceId'];
|
|
20
|
+
referenceType: Amity.Reaction['referenceType'];
|
|
21
|
+
reactionName?: Amity.Reaction['reactionName'];
|
|
22
|
+
page?: Amity.Page;
|
|
23
|
+
}) => Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page>>;
|
|
24
|
+
//# sourceMappingURL=queryReactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryReactions.d.ts","sourceRoot":"","sources":["../../../src/reaction/api/queryReactions.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,cAAc,UAAiB;IAC1C,WAAW,EAAE,MAAM,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC/C,YAAY,CAAC,EAAE,MAAM,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;CACnB,KAAG,QAAQ,MAAM,KAAK,CAAC,MAAM,aAAa,EAAE,MAAM,IAAI,CAAC,CAyBvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/user/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAEhC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/user/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onUserDeleted(user => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when a {@link Amity.User} has been deleted
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category User Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onUserDeleted: (callback: Amity.Listener<Amity.User>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onUserDeleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onUserDeleted.d.ts","sourceRoot":"","sources":["../../../src/user/events/onUserDeleted.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,uBACb,CAAC"}
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* Observe all mutation on a given {@link Amity.User}
|
|
14
14
|
* @category User Observer
|
|
15
15
|
*/
|
|
16
|
-
export declare const observeUser: <Events extends ["onFetch", "onUpdate", "onFlagged", "onUnflagged", "onFlagCleared"]>(userId: string, callback: Amity.ObjectListener<Amity.Snapshot<Amity.User>, Events>) => Amity.Unsubscriber;
|
|
16
|
+
export declare const observeUser: <Events extends ["onFetch", "onUpdate", "onDelete", "onFlagged", "onUnflagged", "onFlagCleared"]>(userId: string, callback: Amity.ObjectListener<Amity.Snapshot<Amity.User>, Events>) => Amity.Unsubscriber;
|
|
17
17
|
//# sourceMappingURL=observeUser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observeUser.d.ts","sourceRoot":"","sources":["../../../src/user/observers/observeUser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observeUser.d.ts","sourceRoot":"","sources":["../../../src/user/observers/observeUser.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,4GAGd,MAAM,yEAEb,MAAM,YAkCR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amityco/ts-sdk",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.20",
|
|
4
4
|
"license": "CC-BY-ND-4.0",
|
|
5
5
|
"author": "amity.co <developers@amity.co> (https://amity.co)",
|
|
6
6
|
"description": "Amity Social Cloud Typescript SDK",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"watch": "rollup -w -c ./rollup.config.js"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@rollup/plugin-commonjs": "^
|
|
34
|
+
"@rollup/plugin-commonjs": "^21.0.3",
|
|
35
35
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
36
|
-
"@rollup/plugin-replace": "^
|
|
36
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
37
37
|
"@types/axios": "^0.14.0",
|
|
38
38
|
"@types/debug": "^4.1.5",
|
|
39
|
-
"@types/node": "^
|
|
39
|
+
"@types/node": "^17.0.23",
|
|
40
40
|
"@types/socket.io-client": "^1.4.34",
|
|
41
41
|
"chalk": "^4.1.2",
|
|
42
42
|
"concurrently": "^6.1.0",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
44
|
"rollup": "^2.56.3",
|
|
45
45
|
"rollup-plugin-terser": "^7.0.2",
|
|
46
|
-
"rollup-plugin-typescript2": "^0.
|
|
46
|
+
"rollup-plugin-typescript2": "^0.31.2",
|
|
47
47
|
"tslib": "^2.1.0",
|
|
48
|
-
"typescript": "^4.
|
|
48
|
+
"typescript": "^4.6.3"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@react-native-async-storage/async-storage": "^1.15.5",
|
|
@@ -94,6 +94,7 @@ declare global {
|
|
|
94
94
|
|
|
95
95
|
type MqttUserMessageEvents = {
|
|
96
96
|
'user.updated': Amity.UserPayload;
|
|
97
|
+
'user.deleted': Amity.UserPayload; // received from network topic
|
|
97
98
|
'user.flagged': Amity.UserPayload;
|
|
98
99
|
'user.unflagged': Amity.UserPayload;
|
|
99
100
|
'user.flagCleared': Amity.UserPayload;
|
package/src/@types/core/model.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare global {
|
|
|
21
21
|
post: Amity.Post;
|
|
22
22
|
comment: Amity.Comment;
|
|
23
23
|
poll: Amity.Poll;
|
|
24
|
+
reaction: Amity.Reaction;
|
|
24
25
|
|
|
25
26
|
stream: Amity.Stream;
|
|
26
27
|
|
|
@@ -50,6 +51,7 @@ declare global {
|
|
|
50
51
|
post: Pick<Amity.Post, 'postId'>;
|
|
51
52
|
comment: Pick<Amity.Comment, 'commentId'>;
|
|
52
53
|
poll: Pick<Amity.Poll, 'pollId'>;
|
|
54
|
+
reaction: Pick<Amity.Reaction, 'reactionId'>;
|
|
53
55
|
|
|
54
56
|
stream: Pick<Amity.Stream, 'streamId'>;
|
|
55
57
|
|
|
@@ -16,6 +16,7 @@ declare global {
|
|
|
16
16
|
comment: Amity.CommentPayload;
|
|
17
17
|
poll: Amity.PollPayload;
|
|
18
18
|
stream: Amity.StreamPayload;
|
|
19
|
+
reaction: Amity.ReactionPayload;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
type UserPayload = {
|
|
@@ -104,6 +105,11 @@ declare global {
|
|
|
104
105
|
polls: Amity.Poll[];
|
|
105
106
|
};
|
|
106
107
|
|
|
108
|
+
type ReactionPayload = {
|
|
109
|
+
reactions: Amity.ReactionQuery[];
|
|
110
|
+
users: Pick<Amity.User, 'userId' | 'displayName' | 'metadata'>[];
|
|
111
|
+
};
|
|
112
|
+
|
|
107
113
|
type GlobalFeedPayload = Amity.PostPayload;
|
|
108
114
|
|
|
109
115
|
type FollowersPayload = {
|
|
@@ -2,7 +2,15 @@ export {};
|
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
|
-
type MessageContentType = 'text' | 'file' | 'image';
|
|
5
|
+
type MessageContentType = 'text' | 'file' | 'image' | 'video' | 'audio' | 'custom';
|
|
6
|
+
|
|
7
|
+
type MessageContent<T extends Amity.MessageContentType = any> = T extends
|
|
8
|
+
| 'file'
|
|
9
|
+
| 'image'
|
|
10
|
+
| 'video'
|
|
11
|
+
| 'audio'
|
|
12
|
+
? { fileId: string }
|
|
13
|
+
: never;
|
|
6
14
|
|
|
7
15
|
type Message<T extends Amity.MessageContentType = any> = {
|
|
8
16
|
messageId: string;
|
|
@@ -17,6 +25,7 @@ declare global {
|
|
|
17
25
|
|
|
18
26
|
editedAt: Amity.timestamp;
|
|
19
27
|
} & Amity.Content<T, 'type'> &
|
|
28
|
+
Amity.MessageContent<T> &
|
|
20
29
|
Amity.Metadata &
|
|
21
30
|
Amity.Timestamps &
|
|
22
31
|
Amity.SoftDelete &
|
|
@@ -4,17 +4,13 @@ declare global {
|
|
|
4
4
|
namespace Amity {
|
|
5
5
|
type ReactableType = 'message' | 'post' | 'comment';
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type Reactor = {
|
|
8
8
|
reactionId: string;
|
|
9
|
-
userId: string;
|
|
10
9
|
reactionName: string;
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
userId: Amity.User['userId'];
|
|
11
|
+
} & Amity.CreatedAt;
|
|
13
12
|
|
|
14
|
-
type
|
|
15
|
-
reactions: Record<string, number>;
|
|
16
|
-
count: number;
|
|
17
|
-
};
|
|
13
|
+
type Reaction = Amity.Reactor & Amity.Relationship<ReactableType>;
|
|
18
14
|
|
|
19
15
|
type Reactable = {
|
|
20
16
|
reactionsCount: number;
|
|
@@ -25,5 +21,9 @@ declare global {
|
|
|
25
21
|
eventName: 'added' | 'removed';
|
|
26
22
|
};
|
|
27
23
|
};
|
|
24
|
+
|
|
25
|
+
type ReactionQuery = {
|
|
26
|
+
reactors: Reactor[];
|
|
27
|
+
} & Amity.Relationship<ReactableType>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -25,6 +25,8 @@ export const queryChannels = async (query?: {
|
|
|
25
25
|
membership?: 'all' | 'member' | 'notMember';
|
|
26
26
|
sortBy?: 'displayName' | 'firstCreated' | 'lastCreated';
|
|
27
27
|
types?: Amity.ChannelType;
|
|
28
|
+
tags?: Amity.Taggable['tags'];
|
|
29
|
+
excludeTags?: Amity.Taggable['tags'];
|
|
28
30
|
page?: Amity.Page;
|
|
29
31
|
}): Promise<Amity.Cached<Amity.Paged<Amity.Channel>>> => {
|
|
30
32
|
const client = getActiveClient();
|
|
@@ -9,6 +9,8 @@ import { setActiveUser } from './activeUser';
|
|
|
9
9
|
|
|
10
10
|
import { getToken } from './getToken';
|
|
11
11
|
import { onClientBanned } from '../events';
|
|
12
|
+
import { getNetworkTopic, subscribeTopic } from '~/core/subscription';
|
|
13
|
+
import { onUserDeleted } from '~/user/events/onUserDeleted';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* ```js
|
|
@@ -20,10 +22,11 @@ import { onClientBanned } from '../events';
|
|
|
20
22
|
*
|
|
21
23
|
* Connects an {@link Amity.Client} instance to ASC servers
|
|
22
24
|
*
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
25
|
+
* @param params the connect parameters
|
|
26
|
+
* @param params.userId the user ID for the current session
|
|
27
|
+
* @param params.displayName the user's displayName for the current session
|
|
28
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
29
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
27
30
|
* @returns a success boolean if connected
|
|
28
31
|
*
|
|
29
32
|
* @category Client API
|
|
@@ -39,7 +42,6 @@ export const connectClient = async (params: {
|
|
|
39
42
|
client.log('client/api/connectClient', { apiKey: client.apiKey, ...params });
|
|
40
43
|
|
|
41
44
|
// default values
|
|
42
|
-
params.displayName ??= params.userId;
|
|
43
45
|
params.deviceId ??= getDeviceId();
|
|
44
46
|
|
|
45
47
|
// @ts-ignore: in that particular case, typing can be
|
|
@@ -63,15 +65,20 @@ export const connectClient = async (params: {
|
|
|
63
65
|
client.ws.open();
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
const unsubscribe = onClientBanned(() => {
|
|
67
|
-
disconnectClient();
|
|
68
|
-
unsubscribe();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
68
|
client.userId = params.userId;
|
|
72
69
|
client.accessToken = accessToken;
|
|
73
70
|
|
|
74
71
|
setActiveUser(users[0]);
|
|
75
72
|
|
|
73
|
+
subscribeTopic(getNetworkTopic());
|
|
74
|
+
|
|
75
|
+
const subscriptions = [
|
|
76
|
+
onClientBanned(() => {
|
|
77
|
+
disconnectClient();
|
|
78
|
+
subscriptions.forEach(fn => fn());
|
|
79
|
+
}),
|
|
80
|
+
onUserDeleted(() => null),
|
|
81
|
+
];
|
|
82
|
+
|
|
76
83
|
return client.ws.connected;
|
|
77
84
|
};
|
package/src/core/model/index.ts
CHANGED
package/src/core/subscription.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
import { ASCError } from '~/core/errors';
|
|
3
3
|
import { proxyMqttEvents } from '~/core/events';
|
|
4
4
|
import { getActiveUser } from '~/client/api/activeUser';
|
|
@@ -73,6 +73,15 @@ export const getMyFollowingsTopic = (): string => {
|
|
|
73
73
|
return `${networkId}/membership/+/${user._id}/+`;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
/** @hidden */
|
|
77
|
+
export const getNetworkTopic = (): string => {
|
|
78
|
+
const user = getActiveUser();
|
|
79
|
+
|
|
80
|
+
const [networkId] = user.path.split('/user/');
|
|
81
|
+
|
|
82
|
+
return networkId;
|
|
83
|
+
};
|
|
84
|
+
|
|
76
85
|
let mqttAccessToken: string;
|
|
77
86
|
let mqttUserId: string;
|
|
78
87
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createHttpTransport } from '~/core/transports';
|
|
2
|
+
import { getDeviceInfo, getDeviceId } from '~/core/device';
|
|
3
|
+
import { API_REGIONS, computeUrl } from '~/client/utils/endpoints';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves accessToken info to use in Beta services
|
|
7
|
+
*
|
|
8
|
+
* @param apiKey for the Http Client instance
|
|
9
|
+
* @param apiRegion endpoint to connect to
|
|
10
|
+
* @param params The token parameters
|
|
11
|
+
* @param params.userId The userId to use to issue a token
|
|
12
|
+
* @param params.displayName The user's displayName
|
|
13
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
14
|
+
* @return An accessToken info object for the given userId
|
|
15
|
+
*
|
|
16
|
+
* @category External API
|
|
17
|
+
* @hidden
|
|
18
|
+
*/
|
|
19
|
+
export const createUserToken = async (
|
|
20
|
+
apiKey: string,
|
|
21
|
+
apiRegion: typeof API_REGIONS[keyof typeof API_REGIONS],
|
|
22
|
+
params: {
|
|
23
|
+
userId: Amity.User['userId'];
|
|
24
|
+
displayName?: Amity.User['displayName'];
|
|
25
|
+
authToken?: string;
|
|
26
|
+
},
|
|
27
|
+
) => {
|
|
28
|
+
const deviceId = getDeviceId();
|
|
29
|
+
const deviceInfo = await getDeviceInfo();
|
|
30
|
+
const http = createHttpTransport(computeUrl('http', apiRegion));
|
|
31
|
+
|
|
32
|
+
const { data } = await http.post<Amity.Tokens>(
|
|
33
|
+
'/api/v3/sessions',
|
|
34
|
+
{
|
|
35
|
+
...params,
|
|
36
|
+
deviceId,
|
|
37
|
+
deviceInfo: { ...deviceInfo, model: 'token management API on TS-SDK' },
|
|
38
|
+
},
|
|
39
|
+
{ headers: { 'X-API-Key': apiKey } },
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return { accessToken: data.accessToken };
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createUserToken';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { createImage } from '@amityco/ts-sdk'
|
|
8
|
+
* const created = await createImage(formData)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Creates an {@link Amity.File<'image'>}
|
|
12
|
+
*
|
|
13
|
+
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
14
|
+
* @param onProgress The callback to track the upload progress
|
|
15
|
+
* @returns The newly created {@link Amity.File<'image'>}
|
|
16
|
+
*
|
|
17
|
+
* @category File API
|
|
18
|
+
* @async
|
|
19
|
+
*/
|
|
20
|
+
export const createImage = async (
|
|
21
|
+
formData: FormData,
|
|
22
|
+
onProgress?: (percent: number) => void,
|
|
23
|
+
): Promise<Amity.Cached<Amity.File<'image'>[]>> => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
client.log('file/createImage', formData);
|
|
26
|
+
|
|
27
|
+
if (!formData.getAll('files').length)
|
|
28
|
+
throw new Error('The formData object must have a `files` key.');
|
|
29
|
+
|
|
30
|
+
const headers =
|
|
31
|
+
'getHeaders' in formData
|
|
32
|
+
? (formData as any).getHeaders()
|
|
33
|
+
: { 'content-type': 'multipart/form-data' };
|
|
34
|
+
|
|
35
|
+
const { data } = await client.http.post<Amity.CreateFilePayload<'image'>>(
|
|
36
|
+
'/api/v4/images',
|
|
37
|
+
formData,
|
|
38
|
+
{
|
|
39
|
+
headers,
|
|
40
|
+
onUploadProgress({ loaded, total }) {
|
|
41
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// API-FIX: payload should be serialized properly
|
|
47
|
+
// const { files } = data
|
|
48
|
+
|
|
49
|
+
const cachedAt = client.cache && Date.now();
|
|
50
|
+
if (client.cache) ingestInCache({ files: data }, { cachedAt });
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
data,
|
|
54
|
+
cachedAt,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// TODO: consider doing local creation with URL.createObjectURL()
|
package/src/file/api/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -24,7 +24,9 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
24
24
|
* @async
|
|
25
25
|
*/
|
|
26
26
|
export const createPoll = async (
|
|
27
|
-
bundle: Pick<Amity.Poll, 'question' | '
|
|
27
|
+
bundle: Pick<Amity.Poll, 'question' | 'answerType' | 'closedIn'> & {
|
|
28
|
+
answers: Pick<Amity.PollAnswer, 'dataType' | 'data'>[];
|
|
29
|
+
},
|
|
28
30
|
): Promise<Amity.Cached<Amity.Poll>> => {
|
|
29
31
|
const client = getActiveClient();
|
|
30
32
|
client.log('post/createPoll', bundle);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { toToken, toPage } from '~/core/query';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { queryReactions } from '@amityco/ts-sdk'
|
|
8
|
+
* const { data: reactions, prevPage, nextPage } = await queryReactions({
|
|
9
|
+
* referenceId: 'postId',
|
|
10
|
+
* referenceType: 'post',
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Queries a paginable list of {@link Amity.ReactionQuery} objects
|
|
15
|
+
*
|
|
16
|
+
* @param query The query parameters
|
|
17
|
+
* @returns A page of {@link Amity.Reaction} objects
|
|
18
|
+
*
|
|
19
|
+
* @reaction Reaction API
|
|
20
|
+
* @async
|
|
21
|
+
* */
|
|
22
|
+
export const queryReactions = async (query: {
|
|
23
|
+
referenceId: Amity.Reaction['referenceId'];
|
|
24
|
+
referenceType: Amity.Reaction['referenceType'];
|
|
25
|
+
reactionName?: Amity.Reaction['reactionName'];
|
|
26
|
+
page?: Amity.Page;
|
|
27
|
+
}): Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('reaction/queryReactions', query);
|
|
30
|
+
|
|
31
|
+
const { page = { limit: 10 }, ...params } = query ?? {};
|
|
32
|
+
|
|
33
|
+
const { data } = await client.http.get<{ results: Amity.ReactionPayload } & Amity.Pagination>(
|
|
34
|
+
`/api/v2/reactions`,
|
|
35
|
+
{
|
|
36
|
+
params: {
|
|
37
|
+
...params,
|
|
38
|
+
options: {
|
|
39
|
+
token: toToken(page, 'skiplimit'),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const { paging, results } = data;
|
|
46
|
+
const { reactions } = results;
|
|
47
|
+
|
|
48
|
+
const nextPage = toPage(paging.next);
|
|
49
|
+
const prevPage = toPage(paging.previous);
|
|
50
|
+
|
|
51
|
+
return { data: reactions, prevPage, nextPage };
|
|
52
|
+
};
|
package/src/user/events/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createUserEventSubscriber } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
6
|
+
* const dispose = onUserDeleted(user => {
|
|
7
|
+
* // ...
|
|
8
|
+
* })
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Fired when a {@link Amity.User} has been deleted
|
|
12
|
+
*
|
|
13
|
+
* @param callback The function to call when the event was fired
|
|
14
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
|
+
*
|
|
16
|
+
* @category User Events
|
|
17
|
+
*/
|
|
18
|
+
export const onUserDeleted = (callback: Amity.Listener<Amity.User>) =>
|
|
19
|
+
createUserEventSubscriber('user.deleted', callback);
|
package/src/user/events/utils.ts
CHANGED
|
@@ -3,7 +3,13 @@ import { createQuery, runQuery } from '~/core/query/query';
|
|
|
3
3
|
import { getActiveClient } from '~/client/api';
|
|
4
4
|
|
|
5
5
|
import { getUser } from '../api';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
onUserUpdated,
|
|
8
|
+
onUserDeleted,
|
|
9
|
+
onUserFlagged,
|
|
10
|
+
onUserUnflagged,
|
|
11
|
+
onUserFlagCleared,
|
|
12
|
+
} from '../events';
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* ```js
|
|
@@ -21,7 +27,7 @@ import { onUserUpdated, onUserFlagged, onUserUnflagged, onUserFlagCleared } from
|
|
|
21
27
|
* @category User Observer
|
|
22
28
|
*/
|
|
23
29
|
export const observeUser = <
|
|
24
|
-
Events extends ['onFetch', 'onUpdate', 'onFlagged', 'onUnflagged', 'onFlagCleared'],
|
|
30
|
+
Events extends ['onFetch', 'onUpdate', 'onDelete', 'onFlagged', 'onUnflagged', 'onFlagCleared'],
|
|
25
31
|
>(
|
|
26
32
|
userId: string,
|
|
27
33
|
callback: Amity.ObjectListener<Amity.Snapshot<Amity.User>, Events>,
|
|
@@ -47,6 +53,7 @@ export const observeUser = <
|
|
|
47
53
|
|
|
48
54
|
disposers.push(
|
|
49
55
|
onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')),
|
|
56
|
+
onUserDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')),
|
|
50
57
|
onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')),
|
|
51
58
|
onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')),
|
|
52
59
|
onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')),
|