@amityco/ts-sdk 0.0.1-c868cef.0 → 0.0.1-cb052d5.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/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +6 -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/poll.d.ts +27 -0
- package/dist/@types/domains/poll.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +1 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/category/api/getCategory.d.ts +18 -2
- package/dist/category/api/getCategory.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +23 -11
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/channel/api/deleteChannel.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/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.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/createFile.d.ts +1 -1
- package/dist/file/api/createFile.d.ts.map +1 -1
- 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 +392 -17
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +384 -18
- package/dist/index.umd.js +5 -5
- package/dist/poll/api/closePoll.d.ts +16 -0
- package/dist/poll/api/closePoll.d.ts.map +1 -0
- package/dist/poll/api/createPoll.d.ts +25 -0
- package/dist/poll/api/createPoll.d.ts.map +1 -0
- package/dist/poll/api/deletePoll.d.ts +16 -0
- package/dist/poll/api/deletePoll.d.ts.map +1 -0
- package/dist/poll/api/getPoll.d.ts +32 -0
- package/dist/poll/api/getPoll.d.ts.map +1 -0
- package/dist/poll/api/index.d.ts +6 -0
- package/dist/poll/api/index.d.ts.map +1 -0
- package/dist/poll/api/votePoll.d.ts +17 -0
- package/dist/poll/api/votePoll.d.ts.map +1 -0
- package/dist/post/api/getPost.d.ts +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/model.ts +4 -0
- package/src/@types/core/payload.ts +7 -0
- package/src/@types/domains/comment.ts +1 -0
- package/src/@types/domains/poll.ts +32 -0
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/index.ts +2 -0
- package/src/category/api/getCategory.ts +45 -7
- package/src/category/api/queryCategories.ts +70 -13
- package/src/channel/api/deleteChannel.ts +0 -1
- package/src/channel/api/queryChannels.ts +2 -0
- package/src/client/api/connectClient.ts +5 -5
- package/src/core/model/idResolvers.ts +2 -0
- package/src/core/model/identifyModel.ts +2 -0
- package/src/core/model/index.ts +2 -0
- package/src/core/subscription.ts +1 -3
- package/src/external/api/createUserToken.ts +43 -0
- package/src/external/api/index.ts +1 -0
- package/src/file/api/createFile.ts +5 -5
- package/src/file/api/createImage.ts +58 -0
- package/src/file/api/index.ts +1 -0
- package/src/index.ts +7 -0
- package/src/poll/api/closePoll.ts +39 -0
- package/src/poll/api/createPoll.ts +45 -0
- package/src/poll/api/deletePoll.ts +36 -0
- package/src/poll/api/getPoll.ts +64 -0
- package/src/poll/api/index.ts +7 -0
- package/src/poll/api/votePoll.ts +41 -0
- package/src/post/api/getPost.ts +1 -1
- package/src/utils/env.ts +3 -1
package/dist/index.cjs.js
CHANGED
|
@@ -21,7 +21,9 @@ var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
|
21
21
|
|
|
22
22
|
var _a$1;
|
|
23
23
|
/* eslint-disable no-undef */
|
|
24
|
-
const theGlobal =
|
|
24
|
+
const theGlobal =
|
|
25
|
+
// eslint-disable-next-line no-nested-ternary
|
|
26
|
+
typeof globalThis === 'object' ? globalThis : typeof global === 'object' ? global : window;
|
|
25
27
|
const { process: safeProcess = {} } = theGlobal;
|
|
26
28
|
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
27
29
|
|
|
@@ -15071,22 +15073,22 @@ const onClientBanned = (callback) => {
|
|
|
15071
15073
|
*
|
|
15072
15074
|
* Connects an {@link Amity.Client} instance to ASC servers
|
|
15073
15075
|
*
|
|
15074
|
-
* @param
|
|
15075
|
-
* @param
|
|
15076
|
-
* @param
|
|
15077
|
-
* @param
|
|
15076
|
+
* @param params the connect parameters
|
|
15077
|
+
* @param params.userId the user ID for the current session
|
|
15078
|
+
* @param params.displayName the user's displayName for the current session
|
|
15079
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
15080
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
15078
15081
|
* @returns a success boolean if connected
|
|
15079
15082
|
*
|
|
15080
15083
|
* @category Client API
|
|
15081
15084
|
* @async
|
|
15082
15085
|
*/
|
|
15083
15086
|
const connectClient = async (params) => {
|
|
15084
|
-
var _a
|
|
15087
|
+
var _a;
|
|
15085
15088
|
const client = getActiveClient();
|
|
15086
15089
|
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey }, params));
|
|
15087
15090
|
// default values
|
|
15088
|
-
(_a = params.
|
|
15089
|
-
(_b = params.deviceId) !== null && _b !== void 0 ? _b : (params.deviceId = getDeviceId());
|
|
15091
|
+
(_a = params.deviceId) !== null && _a !== void 0 ? _a : (params.deviceId = getDeviceId());
|
|
15090
15092
|
// @ts-ignore: in that particular case, typing can be
|
|
15091
15093
|
// ignored since we enforce default values just before.
|
|
15092
15094
|
const { accessToken, users } = await getToken(params);
|
|
@@ -15155,9 +15157,7 @@ const getCommunityUserTopic = (path, level) => {
|
|
|
15155
15157
|
}
|
|
15156
15158
|
};
|
|
15157
15159
|
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
15158
|
-
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER
|
|
15159
|
-
? path
|
|
15160
|
-
: path.replace(/^(?<networkId>\w*)/, '$<networkId>/social'), level);
|
|
15160
|
+
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER ? path : path.replace(/^(\w*)/, '$1/social'), level);
|
|
15161
15161
|
const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
15162
15162
|
switch (level) {
|
|
15163
15163
|
case 'comment':
|
|
@@ -15585,9 +15585,11 @@ const idResolvers = {
|
|
|
15585
15585
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
15586
15586
|
message: ({ messageId }) => messageId,
|
|
15587
15587
|
community: ({ communityId }) => communityId,
|
|
15588
|
+
category: ({ categoryId }) => categoryId,
|
|
15588
15589
|
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
15589
15590
|
post: ({ postId }) => postId,
|
|
15590
15591
|
comment: ({ commentId }) => commentId,
|
|
15592
|
+
poll: ({ pollId }) => pollId,
|
|
15591
15593
|
stream: ({ streamId }) => streamId,
|
|
15592
15594
|
follow: ({ from, to }) => `${from}#${to}`,
|
|
15593
15595
|
followCount: ({ userId }) => userId,
|
|
@@ -15612,10 +15614,12 @@ const PAYLOAD2MODEL = {
|
|
|
15612
15614
|
channelUsers: 'channelUsers',
|
|
15613
15615
|
messages: 'message',
|
|
15614
15616
|
communities: 'community',
|
|
15617
|
+
categories: 'category',
|
|
15615
15618
|
communityUsers: 'communityUsers',
|
|
15616
15619
|
posts: 'post',
|
|
15617
15620
|
postChildren: 'post',
|
|
15618
15621
|
comments: 'comment',
|
|
15622
|
+
polls: 'poll',
|
|
15619
15623
|
videoStreamings: 'stream',
|
|
15620
15624
|
follows: 'follow',
|
|
15621
15625
|
followCounts: 'followCount',
|
|
@@ -16077,12 +16081,12 @@ getFile.locally = (fileId) => {
|
|
|
16077
16081
|
const createFile = async (formData, onProgress) => {
|
|
16078
16082
|
const client = getActiveClient();
|
|
16079
16083
|
client.log('file/createFile', formData);
|
|
16080
|
-
if (!formData.getAll('
|
|
16081
|
-
throw new Error('The formData object must have a `
|
|
16084
|
+
if (!formData.getAll('files').length)
|
|
16085
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16082
16086
|
const headers = 'getHeaders' in formData
|
|
16083
16087
|
? formData.getHeaders()
|
|
16084
16088
|
: { 'content-type': 'multipart/form-data' };
|
|
16085
|
-
const { data } = await client.http.post('/api/
|
|
16089
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
16086
16090
|
headers,
|
|
16087
16091
|
onUploadProgress({ loaded, total }) {
|
|
16088
16092
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -16094,7 +16098,7 @@ const createFile = async (formData, onProgress) => {
|
|
|
16094
16098
|
if (client.cache)
|
|
16095
16099
|
ingestInCache({ files: data }, { cachedAt });
|
|
16096
16100
|
return {
|
|
16097
|
-
data
|
|
16101
|
+
data,
|
|
16098
16102
|
cachedAt,
|
|
16099
16103
|
};
|
|
16100
16104
|
};
|
|
@@ -16175,6 +16179,47 @@ const createVideo = async (formData, onProgress) => {
|
|
|
16175
16179
|
};
|
|
16176
16180
|
// TODO: consider doing local creation with URL.createObjectURL()
|
|
16177
16181
|
|
|
16182
|
+
/**
|
|
16183
|
+
* ```js
|
|
16184
|
+
* import { createImage } from '@amityco/ts-sdk'
|
|
16185
|
+
* const created = await createImage(formData)
|
|
16186
|
+
* ```
|
|
16187
|
+
*
|
|
16188
|
+
* Creates an {@link Amity.File<'image'>}
|
|
16189
|
+
*
|
|
16190
|
+
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
16191
|
+
* @param onProgress The callback to track the upload progress
|
|
16192
|
+
* @returns The newly created {@link Amity.File<'image'>}
|
|
16193
|
+
*
|
|
16194
|
+
* @category File API
|
|
16195
|
+
* @async
|
|
16196
|
+
*/
|
|
16197
|
+
const createImage = async (formData, onProgress) => {
|
|
16198
|
+
const client = getActiveClient();
|
|
16199
|
+
client.log('file/createImage', formData);
|
|
16200
|
+
if (!formData.getAll('files').length)
|
|
16201
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16202
|
+
const headers = 'getHeaders' in formData
|
|
16203
|
+
? formData.getHeaders()
|
|
16204
|
+
: { 'content-type': 'multipart/form-data' };
|
|
16205
|
+
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
16206
|
+
headers,
|
|
16207
|
+
onUploadProgress({ loaded, total }) {
|
|
16208
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16209
|
+
},
|
|
16210
|
+
});
|
|
16211
|
+
// API-FIX: payload should be serialized properly
|
|
16212
|
+
// const { files } = data
|
|
16213
|
+
const cachedAt = client.cache && Date.now();
|
|
16214
|
+
if (client.cache)
|
|
16215
|
+
ingestInCache({ files: data }, { cachedAt });
|
|
16216
|
+
return {
|
|
16217
|
+
data,
|
|
16218
|
+
cachedAt,
|
|
16219
|
+
};
|
|
16220
|
+
};
|
|
16221
|
+
// TODO: consider doing local creation with URL.createObjectURL()
|
|
16222
|
+
|
|
16178
16223
|
/**
|
|
16179
16224
|
* ```js
|
|
16180
16225
|
* import { observeFile } from '@amityco/ts-sdk'
|
|
@@ -16889,7 +16934,7 @@ const getPost = async (postId) => {
|
|
|
16889
16934
|
/**
|
|
16890
16935
|
* ```js
|
|
16891
16936
|
* import { getPost } from '@amityco/ts-sdk'
|
|
16892
|
-
* const { data
|
|
16937
|
+
* const { data: post } = getPost.locally('foobar')
|
|
16893
16938
|
* ```
|
|
16894
16939
|
*
|
|
16895
16940
|
* Fetches a {@link Amity.Post} object from cache
|
|
@@ -18935,7 +18980,6 @@ const updateChannel = async (channelId, patch) => {
|
|
|
18935
18980
|
const deleteChannel = async (channelId) => {
|
|
18936
18981
|
const client = getActiveClient();
|
|
18937
18982
|
client.log('channel/deleteChannel', channelId);
|
|
18938
|
-
// API-FIX: This endpoint has not been implemented yet.
|
|
18939
18983
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
18940
18984
|
const deleted = await getChannel(channelId);
|
|
18941
18985
|
// no need for event, fired by server
|
|
@@ -19757,6 +19801,134 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19757
19801
|
};
|
|
19758
19802
|
};
|
|
19759
19803
|
|
|
19804
|
+
/**
|
|
19805
|
+
* ```js
|
|
19806
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19807
|
+
* const { data: categories, prevPage, nextPage } = await queryCategories()
|
|
19808
|
+
* ```
|
|
19809
|
+
*
|
|
19810
|
+
* Queries a paginable list of {@link Amity.Category} objects
|
|
19811
|
+
*
|
|
19812
|
+
* @param query The query parameters
|
|
19813
|
+
* @returns A page of {@link Amity.Category} objects
|
|
19814
|
+
*
|
|
19815
|
+
* @category Category API
|
|
19816
|
+
* @async
|
|
19817
|
+
* */
|
|
19818
|
+
const queryCategories = async (query) => {
|
|
19819
|
+
const client = getActiveClient();
|
|
19820
|
+
client.log('category/queryCategories', query);
|
|
19821
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
|
|
19822
|
+
const { data } = await client.http.get(`/api/v3/community-categories`, {
|
|
19823
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19824
|
+
token: toToken(page, 'skiplimit'),
|
|
19825
|
+
} }),
|
|
19826
|
+
});
|
|
19827
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19828
|
+
const { categories } = payload;
|
|
19829
|
+
const cachedAt = client.cache && Date.now();
|
|
19830
|
+
if (client.cache) {
|
|
19831
|
+
ingestInCache(payload, { cachedAt });
|
|
19832
|
+
const cacheKey = [
|
|
19833
|
+
'category',
|
|
19834
|
+
'query',
|
|
19835
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
19836
|
+
];
|
|
19837
|
+
pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
|
|
19838
|
+
}
|
|
19839
|
+
const nextPage = toPage(paging.next);
|
|
19840
|
+
const prevPage = toPage(paging.previous);
|
|
19841
|
+
return { data: categories, cachedAt, prevPage, nextPage };
|
|
19842
|
+
};
|
|
19843
|
+
/**
|
|
19844
|
+
* ```js
|
|
19845
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19846
|
+
* const { data: categories, prevPage, nextPage } = queryCategories.locally()
|
|
19847
|
+
* ```
|
|
19848
|
+
*
|
|
19849
|
+
* Queries a paginable list of {@link Amity.Category} objects from cache
|
|
19850
|
+
*
|
|
19851
|
+
* @param query The query parameters
|
|
19852
|
+
* @returns categories
|
|
19853
|
+
*
|
|
19854
|
+
* @category category API
|
|
19855
|
+
*/
|
|
19856
|
+
queryCategories.locally = (query) => {
|
|
19857
|
+
var _a, _b;
|
|
19858
|
+
const client = getActiveClient();
|
|
19859
|
+
client.log('category/queryCategories.locally', query);
|
|
19860
|
+
if (!client.cache)
|
|
19861
|
+
return;
|
|
19862
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _c, params = __rest(_c, ["page"]);
|
|
19863
|
+
const queryKey = ['category', 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19864
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19865
|
+
if (!(data === null || data === void 0 ? void 0 : data.categories.length))
|
|
19866
|
+
return;
|
|
19867
|
+
const categories = data.categories
|
|
19868
|
+
.map(categoryId => pullFromCache(['category', 'get', categoryId]))
|
|
19869
|
+
.filter(Boolean)
|
|
19870
|
+
.map(({ data }) => data);
|
|
19871
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19872
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19873
|
+
return categories.length === ((_b = data === null || data === void 0 ? void 0 : data.categories) === null || _b === void 0 ? void 0 : _b.length)
|
|
19874
|
+
? { data: categories, cachedAt, prevPage, nextPage }
|
|
19875
|
+
: undefined;
|
|
19876
|
+
};
|
|
19877
|
+
|
|
19878
|
+
/**
|
|
19879
|
+
* ```js
|
|
19880
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19881
|
+
* const { data: category } = await getCategory('foo')
|
|
19882
|
+
* ```
|
|
19883
|
+
*
|
|
19884
|
+
* Fetches a {@link Amity.Category} object
|
|
19885
|
+
*
|
|
19886
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19887
|
+
* @returns the associated {@link Amity.Category} object
|
|
19888
|
+
*
|
|
19889
|
+
* @category Category API
|
|
19890
|
+
* @async
|
|
19891
|
+
*/
|
|
19892
|
+
const getCategory = async (categoryId) => {
|
|
19893
|
+
const client = getActiveClient();
|
|
19894
|
+
client.log('category/getCategory', categoryId);
|
|
19895
|
+
const { data } = await client.http.get(`/api/v3/community-categories/${encodeURIComponent(categoryId)}`);
|
|
19896
|
+
const cachedAt = client.cache && Date.now();
|
|
19897
|
+
if (client.cache)
|
|
19898
|
+
ingestInCache(data, { cachedAt });
|
|
19899
|
+
const { categories } = data;
|
|
19900
|
+
return {
|
|
19901
|
+
data: categories.find(category => category.categoryId === categoryId),
|
|
19902
|
+
cachedAt,
|
|
19903
|
+
};
|
|
19904
|
+
};
|
|
19905
|
+
/**
|
|
19906
|
+
* ```js
|
|
19907
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19908
|
+
* const { data: category } = getCategory.locally('foobar')
|
|
19909
|
+
* ```
|
|
19910
|
+
*
|
|
19911
|
+
* Fetches a {@link Amity.Category} object from cache
|
|
19912
|
+
*
|
|
19913
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19914
|
+
* @returns the associated {@link Amity.Category} object
|
|
19915
|
+
*
|
|
19916
|
+
* @category Category API
|
|
19917
|
+
*/
|
|
19918
|
+
getCategory.locally = (categoryId) => {
|
|
19919
|
+
const client = getActiveClient();
|
|
19920
|
+
client.log('category/getCategory.locally', categoryId);
|
|
19921
|
+
if (!client.cache)
|
|
19922
|
+
return;
|
|
19923
|
+
const cached = pullFromCache(['category', 'get', categoryId]);
|
|
19924
|
+
if (!cached)
|
|
19925
|
+
return;
|
|
19926
|
+
return {
|
|
19927
|
+
data: cached.data,
|
|
19928
|
+
cachedAt: cached.cachedAt,
|
|
19929
|
+
};
|
|
19930
|
+
};
|
|
19931
|
+
|
|
19760
19932
|
/**
|
|
19761
19933
|
* ```js
|
|
19762
19934
|
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
@@ -20576,6 +20748,178 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
20576
20748
|
};
|
|
20577
20749
|
};
|
|
20578
20750
|
|
|
20751
|
+
/**
|
|
20752
|
+
* ```js
|
|
20753
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20754
|
+
* const poll = await getPoll('foobar')
|
|
20755
|
+
* ```
|
|
20756
|
+
*
|
|
20757
|
+
* Fetches a {@link Amity.Poll} object
|
|
20758
|
+
*
|
|
20759
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20760
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20761
|
+
*
|
|
20762
|
+
* @category Poll API
|
|
20763
|
+
* @async
|
|
20764
|
+
*/
|
|
20765
|
+
const getPoll = async (pollId) => {
|
|
20766
|
+
const client = getActiveClient();
|
|
20767
|
+
client.log('poll/getPoll', pollId);
|
|
20768
|
+
const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
|
|
20769
|
+
const cachedAt = client.cache && Date.now();
|
|
20770
|
+
if (client.cache)
|
|
20771
|
+
ingestInCache(data, { cachedAt });
|
|
20772
|
+
const { polls } = data;
|
|
20773
|
+
return {
|
|
20774
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20775
|
+
cachedAt,
|
|
20776
|
+
};
|
|
20777
|
+
};
|
|
20778
|
+
/**
|
|
20779
|
+
* ```js
|
|
20780
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20781
|
+
* const poll = getPoll.locally('foobar')
|
|
20782
|
+
* ```
|
|
20783
|
+
*
|
|
20784
|
+
* Fetches a {@link Amity.Poll} object
|
|
20785
|
+
*
|
|
20786
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20787
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20788
|
+
*
|
|
20789
|
+
* @category Poll API
|
|
20790
|
+
*/
|
|
20791
|
+
getPoll.locally = (pollId) => {
|
|
20792
|
+
const client = getActiveClient();
|
|
20793
|
+
client.log('poll/getPoll', pollId);
|
|
20794
|
+
if (!client.cache)
|
|
20795
|
+
return;
|
|
20796
|
+
const cached = pullFromCache(['poll', 'get', pollId]);
|
|
20797
|
+
if (!cached)
|
|
20798
|
+
return;
|
|
20799
|
+
return {
|
|
20800
|
+
data: cached.data,
|
|
20801
|
+
cachedAt: cached.cachedAt,
|
|
20802
|
+
};
|
|
20803
|
+
};
|
|
20804
|
+
|
|
20805
|
+
/**
|
|
20806
|
+
* ```js
|
|
20807
|
+
* import { createPoll } from '@amityco/ts-sdk'
|
|
20808
|
+
* const created = await createPoll({
|
|
20809
|
+
* question: 'question',
|
|
20810
|
+
* answers: [
|
|
20811
|
+
* { dataType: 'text', data: 'answer1' },
|
|
20812
|
+
* { dataType: 'text', data: 'answer2' },
|
|
20813
|
+
* ],
|
|
20814
|
+
* closedIn: 1649136484
|
|
20815
|
+
* }))
|
|
20816
|
+
* ```
|
|
20817
|
+
*
|
|
20818
|
+
* Creates an {@link Amity.Poll}
|
|
20819
|
+
*
|
|
20820
|
+
* @param bundle The data necessary to create a new {@link Amity.Poll}
|
|
20821
|
+
* @returns The newly created {@link Amity.Poll}
|
|
20822
|
+
*
|
|
20823
|
+
* @category Poll API
|
|
20824
|
+
* @async
|
|
20825
|
+
*/
|
|
20826
|
+
const createPoll = async (bundle) => {
|
|
20827
|
+
const client = getActiveClient();
|
|
20828
|
+
client.log('post/createPoll', bundle);
|
|
20829
|
+
const { data } = await client.http.post('/api/v3/polls', bundle);
|
|
20830
|
+
const cachedAt = client.cache && Date.now();
|
|
20831
|
+
if (client.cache)
|
|
20832
|
+
ingestInCache(data, { cachedAt });
|
|
20833
|
+
const { polls } = data;
|
|
20834
|
+
return {
|
|
20835
|
+
data: polls[0],
|
|
20836
|
+
cachedAt,
|
|
20837
|
+
};
|
|
20838
|
+
};
|
|
20839
|
+
|
|
20840
|
+
/**
|
|
20841
|
+
* ```js
|
|
20842
|
+
* import { closePoll } from '@amityco/ts-sdk'
|
|
20843
|
+
* const updated = await closePoll(pollId)
|
|
20844
|
+
* ```
|
|
20845
|
+
*
|
|
20846
|
+
* Updates an {@link Amity.Poll}
|
|
20847
|
+
*
|
|
20848
|
+
* @param pollId The ID of the {@link Amity.Poll} to close
|
|
20849
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20850
|
+
*
|
|
20851
|
+
* @category Poll API
|
|
20852
|
+
* @async
|
|
20853
|
+
*/
|
|
20854
|
+
const closePoll = async (pollId) => {
|
|
20855
|
+
const client = getActiveClient();
|
|
20856
|
+
client.log('user/closePoll', pollId);
|
|
20857
|
+
const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
|
|
20858
|
+
const cachedAt = client.cache && Date.now();
|
|
20859
|
+
if (client.cache)
|
|
20860
|
+
ingestInCache(data, { cachedAt });
|
|
20861
|
+
const { polls } = data;
|
|
20862
|
+
return {
|
|
20863
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20864
|
+
cachedAt,
|
|
20865
|
+
};
|
|
20866
|
+
};
|
|
20867
|
+
|
|
20868
|
+
/**
|
|
20869
|
+
* ```js
|
|
20870
|
+
* import { deletePoll } from '@amityco/ts-sdk'
|
|
20871
|
+
* const success = await deletePoll(pollId)
|
|
20872
|
+
* ```
|
|
20873
|
+
*
|
|
20874
|
+
* Deletes a {@link Amity.Poll}
|
|
20875
|
+
*
|
|
20876
|
+
* @param pollId The {@link Amity.Poll} ID to delete
|
|
20877
|
+
* @return A success boolean if the {@link Amity.Poll} was deleted
|
|
20878
|
+
*
|
|
20879
|
+
* @category Poll API
|
|
20880
|
+
* @async
|
|
20881
|
+
*/
|
|
20882
|
+
const deletePoll = async (pollId) => {
|
|
20883
|
+
const client = getActiveClient();
|
|
20884
|
+
client.log('poll/deletePoll', pollId);
|
|
20885
|
+
const poll = await getPoll(pollId);
|
|
20886
|
+
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
20887
|
+
const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
|
|
20888
|
+
const { success } = data; // unwrapPayload(data)
|
|
20889
|
+
const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
|
|
20890
|
+
upsertInCache(['poll', 'get', pollId], deleted);
|
|
20891
|
+
return success;
|
|
20892
|
+
};
|
|
20893
|
+
|
|
20894
|
+
/**
|
|
20895
|
+
* ```js
|
|
20896
|
+
* import { votePoll } from '@amityco/ts-sdk'
|
|
20897
|
+
* const voted = await votePoll(pollId)
|
|
20898
|
+
* ```
|
|
20899
|
+
*
|
|
20900
|
+
* Votes for an {@link Amity.Poll}
|
|
20901
|
+
*
|
|
20902
|
+
* @param pollId The ID of the {@link Amity.Poll} to vote
|
|
20903
|
+
* @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
|
|
20904
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20905
|
+
*
|
|
20906
|
+
* @category Poll API
|
|
20907
|
+
* @async
|
|
20908
|
+
*/
|
|
20909
|
+
const votePoll = async (pollId, answerIds) => {
|
|
20910
|
+
const client = getActiveClient();
|
|
20911
|
+
client.log('user/votePoll', pollId);
|
|
20912
|
+
const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
|
|
20913
|
+
const cachedAt = client.cache && Date.now();
|
|
20914
|
+
if (client.cache)
|
|
20915
|
+
ingestInCache(data, { cachedAt });
|
|
20916
|
+
const { polls } = data;
|
|
20917
|
+
return {
|
|
20918
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20919
|
+
cachedAt,
|
|
20920
|
+
};
|
|
20921
|
+
};
|
|
20922
|
+
|
|
20579
20923
|
/**
|
|
20580
20924
|
* ```js
|
|
20581
20925
|
* import { getStream } from '@amityco/ts-sdk'
|
|
@@ -20869,6 +21213,28 @@ const onStreamRecorded = (callback) => {
|
|
|
20869
21213
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
20870
21214
|
};
|
|
20871
21215
|
|
|
21216
|
+
/**
|
|
21217
|
+
* Retrieves accessToken info to use in Beta services
|
|
21218
|
+
*
|
|
21219
|
+
* @param apiKey for the Http Client instance
|
|
21220
|
+
* @param apiRegion endpoint to connect to
|
|
21221
|
+
* @param params The token parameters
|
|
21222
|
+
* @param params.userId The userId to use to issue a token
|
|
21223
|
+
* @param params.displayName The user's displayName
|
|
21224
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
21225
|
+
* @return An accessToken info object for the given userId
|
|
21226
|
+
*
|
|
21227
|
+
* @category External API
|
|
21228
|
+
* @hidden
|
|
21229
|
+
*/
|
|
21230
|
+
const createUserToken = async (apiKey, apiRegion, params) => {
|
|
21231
|
+
const deviceId = getDeviceId();
|
|
21232
|
+
const deviceInfo = await getDeviceInfo();
|
|
21233
|
+
const http = createHttpTransport(computeUrl('http', apiRegion));
|
|
21234
|
+
const { data } = await http.post('/api/v3/sessions', Object.assign(Object.assign({}, params), { deviceId, deviceInfo: Object.assign(Object.assign({}, deviceInfo), { model: 'token management API on TS-SDK' }) }), { headers: { 'X-API-Key': apiKey } });
|
|
21235
|
+
return { accessToken: data.accessToken };
|
|
21236
|
+
};
|
|
21237
|
+
|
|
20872
21238
|
exports.API_REGIONS = API_REGIONS;
|
|
20873
21239
|
exports.VERSION = VERSION$1;
|
|
20874
21240
|
exports.acceptFollower = acceptFollower;
|
|
@@ -20878,17 +21244,21 @@ exports.addCommunityMembers = addCommunityMembers;
|
|
|
20878
21244
|
exports.addCommunityMembersRoles = addCommunityMembersRoles;
|
|
20879
21245
|
exports.addReaction = addReaction;
|
|
20880
21246
|
exports.backupCache = backupCache;
|
|
21247
|
+
exports.closePoll = closePoll;
|
|
20881
21248
|
exports.connectClient = connectClient;
|
|
20882
21249
|
exports.createChannel = createChannel;
|
|
20883
21250
|
exports.createClient = createClient;
|
|
20884
21251
|
exports.createComment = createComment;
|
|
20885
21252
|
exports.createCommunity = createCommunity;
|
|
20886
21253
|
exports.createFile = createFile;
|
|
21254
|
+
exports.createImage = createImage;
|
|
20887
21255
|
exports.createMessage = createMessage;
|
|
21256
|
+
exports.createPoll = createPoll;
|
|
20888
21257
|
exports.createPost = createPost;
|
|
20889
21258
|
exports.createQuery = createQuery;
|
|
20890
21259
|
exports.createReport = createReport;
|
|
20891
21260
|
exports.createStream = createStream;
|
|
21261
|
+
exports.createUserToken = createUserToken;
|
|
20892
21262
|
exports.createVideo = createVideo;
|
|
20893
21263
|
exports.declineFollower = declineFollower;
|
|
20894
21264
|
exports.deleteChannel = deleteChannel;
|
|
@@ -20896,6 +21266,7 @@ exports.deleteComment = deleteComment;
|
|
|
20896
21266
|
exports.deleteCommunity = deleteCommunity;
|
|
20897
21267
|
exports.deleteFile = deleteFile;
|
|
20898
21268
|
exports.deleteMessage = deleteMessage;
|
|
21269
|
+
exports.deletePoll = deletePoll;
|
|
20899
21270
|
exports.deletePost = deletePost;
|
|
20900
21271
|
exports.deleteReport = deleteReport;
|
|
20901
21272
|
exports.deleteStream = deleteStream;
|
|
@@ -20908,6 +21279,7 @@ exports.fileUrlWithSize = fileUrlWithSize;
|
|
|
20908
21279
|
exports.filterByPropEquality = filterByPropEquality;
|
|
20909
21280
|
exports.follow = follow;
|
|
20910
21281
|
exports.getActiveClient = getActiveClient;
|
|
21282
|
+
exports.getCategory = getCategory;
|
|
20911
21283
|
exports.getChannel = getChannel;
|
|
20912
21284
|
exports.getChannels = getChannels;
|
|
20913
21285
|
exports.getComment = getComment;
|
|
@@ -20922,6 +21294,7 @@ exports.getMessage = getMessage;
|
|
|
20922
21294
|
exports.getMessages = getMessages;
|
|
20923
21295
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
20924
21296
|
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
21297
|
+
exports.getPoll = getPoll;
|
|
20925
21298
|
exports.getPost = getPost;
|
|
20926
21299
|
exports.getPostTopic = getPostTopic;
|
|
20927
21300
|
exports.getPosts = getPosts;
|
|
@@ -21018,6 +21391,7 @@ exports.onUserUpdated = onUserUpdated;
|
|
|
21018
21391
|
exports.pullFromCache = pullFromCache;
|
|
21019
21392
|
exports.pushToCache = pushToCache;
|
|
21020
21393
|
exports.queryCache = queryCache;
|
|
21394
|
+
exports.queryCategories = queryCategories;
|
|
21021
21395
|
exports.queryChannelMembers = queryChannelMembers;
|
|
21022
21396
|
exports.queryChannels = queryChannels;
|
|
21023
21397
|
exports.queryComments = queryComments;
|
|
@@ -21058,4 +21432,5 @@ exports.updatePost = updatePost;
|
|
|
21058
21432
|
exports.updateStream = updateStream;
|
|
21059
21433
|
exports.updateUser = updateUser;
|
|
21060
21434
|
exports.upsertInCache = upsertInCache;
|
|
21435
|
+
exports.votePoll = votePoll;
|
|
21061
21436
|
exports.wipeCache = wipeCache;
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './message/observers';
|
|
|
24
24
|
export * from './community/api';
|
|
25
25
|
export * from './community/events';
|
|
26
26
|
export * from './community/observers';
|
|
27
|
+
export * from './category/api';
|
|
27
28
|
export * from './feed/api';
|
|
28
29
|
export * from './follow/api';
|
|
29
30
|
export * from './follow/events';
|
|
@@ -34,6 +35,8 @@ export * from './post/observers';
|
|
|
34
35
|
export * from './comment/api';
|
|
35
36
|
export * from './comment/events';
|
|
36
37
|
export * from './comment/observers';
|
|
38
|
+
export * from './poll/api';
|
|
37
39
|
export * from './stream/api';
|
|
38
40
|
export * from './stream/events';
|
|
41
|
+
export * from './external/api';
|
|
39
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAG3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAG7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,YAAY,CAAC;AAG3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAG7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,gBAAgB,CAAC"}
|