@amityco/ts-sdk 0.0.1-beta.12 → 0.0.1-beta.15
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/README.md +3 -3
- package/dist/@types/core/cache.d.ts +2 -2
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +2 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/paging.d.ts +19 -38
- package/dist/@types/core/paging.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +12 -4
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +2 -2
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/mention.d.ts +23 -0
- package/dist/@types/domains/mention.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +2 -2
- 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/queryCategories.d.ts +3 -3
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +1 -1
- package/dist/client/api/createClient.d.ts +3 -3
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/disconnectClient.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +12 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -0
- package/dist/comment/api/createComment.d.ts +1 -1
- package/dist/comment/api/createComment.d.ts.map +1 -1
- package/dist/comment/api/updateComment.d.ts +1 -1
- package/dist/comment/api/updateComment.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts +1 -1
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/microtasks.d.ts +13 -0
- package/dist/core/microtasks.d.ts.map +1 -0
- package/dist/core/query/paging.d.ts +2 -13
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +22 -4
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/index.cjs.js +101 -74
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +101 -74
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts +2 -2
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/updateMessage.d.ts +2 -2
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/post/api/createPost.d.ts +7 -3
- package/dist/post/api/createPost.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts +3 -3
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/api/updatePost.d.ts +1 -1
- package/dist/post/api/updatePost.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +1 -1
- package/dist/stream/api/queryStreams.d.ts +1 -1
- package/dist/utils/env.d.ts +5 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/rollup.config.js +3 -0
- package/src/@types/core/cache.ts +2 -2
- package/src/@types/core/events.ts +1 -1
- package/src/@types/core/paging.ts +29 -44
- package/src/@types/core/query.ts +7 -3
- package/src/@types/domains/client.ts +1 -1
- package/src/@types/domains/comment.ts +1 -0
- package/src/@types/domains/file.ts +2 -1
- package/src/@types/domains/mention.ts +26 -0
- package/src/@types/domains/message.ts +1 -0
- package/src/@types/domains/post.ts +2 -1
- package/src/@types/index.ts +2 -0
- package/src/channel/api/queryChannelMembers.ts +2 -1
- package/src/client/api/connectClient.ts +1 -1
- package/src/client/api/createClient.ts +7 -7
- package/src/client/api/disconnectClient.ts +0 -1
- package/src/client/utils/endpoints.ts +14 -0
- package/src/comment/api/createComment.ts +1 -2
- package/src/comment/api/updateComment.ts +1 -1
- package/src/community/api/queryCommunityMembers.ts +1 -1
- package/src/core/debug.ts +3 -1
- package/src/core/device.ts +3 -2
- package/src/core/events.ts +3 -1
- package/src/core/microtasks.ts +27 -0
- package/src/core/query/paging.ts +6 -41
- package/src/core/query/query.ts +5 -5
- package/src/core/subscription.ts +4 -4
- package/src/feed/api/queryGlobalFeed.ts +58 -5
- package/src/index.ts +1 -0
- package/src/message/api/createMessage.ts +2 -2
- package/src/message/api/updateMessage.ts +2 -2
- package/src/post/api/createPost.ts +6 -4
- package/src/post/api/queryPosts.ts +5 -5
- package/src/post/api/updatePost.ts +2 -2
- package/src/utils/env.ts +7 -0
- package/src/version.ts +3 -1
- package/dist/core/network.d.ts +0 -11
- package/dist/core/network.d.ts.map +0 -1
- package/src/core/network.ts +0 -14
package/src/core/query/paging.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
1
|
import { encode, decode } from 'js-base64'
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -22,7 +21,7 @@ export const isSkipLimit = (json: Object): json is Amity.SkipLimitPagination =>
|
|
|
22
21
|
* @hidden
|
|
23
22
|
*/
|
|
24
23
|
export const isAfterBefore = (json: Object): json is Amity.AfterBeforePagination => (
|
|
25
|
-
['after', 'before', 'first', 'last'].some(prop => prop in json)
|
|
24
|
+
['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json)
|
|
26
25
|
)
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -34,7 +33,7 @@ export const isAfterBefore = (json: Object): json is Amity.AfterBeforePagination
|
|
|
34
33
|
* @hidden
|
|
35
34
|
*/
|
|
36
35
|
export const isAfterBeforeRaw = (json: Object): json is Amity.AfterBeforeRawPagination => (
|
|
37
|
-
|
|
36
|
+
'limit' in json
|
|
38
37
|
)
|
|
39
38
|
|
|
40
39
|
/**
|
|
@@ -63,9 +62,8 @@ export const isPaged = <T extends unknown>(payload: any): payload is Amity.Paged
|
|
|
63
62
|
* @hidden
|
|
64
63
|
*/
|
|
65
64
|
export const toToken = (
|
|
66
|
-
paging: Amity.Page | undefined,
|
|
67
|
-
style:
|
|
68
|
-
|
|
65
|
+
paging: Amity.Page | Amity.PageRaw | undefined,
|
|
66
|
+
style: Amity.PaginationStyles,
|
|
69
67
|
): Amity.Token | undefined => {
|
|
70
68
|
if (!paging || !Object.keys(paging).length)
|
|
71
69
|
return
|
|
@@ -79,7 +77,7 @@ export const toToken = (
|
|
|
79
77
|
limit: paging.limit,
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
else if (style === 'afterbefore') {
|
|
80
|
+
else if (style === 'afterbefore' && isAfterBefore(paging)) {
|
|
83
81
|
/*
|
|
84
82
|
Caution: this testing style is only valid because
|
|
85
83
|
our backend expects nothing else than a number as
|
|
@@ -114,6 +112,7 @@ export const toToken = (
|
|
|
114
112
|
return encode(JSON.stringify(payload))
|
|
115
113
|
}
|
|
116
114
|
|
|
115
|
+
|
|
117
116
|
/**
|
|
118
117
|
* Converts a b64 string token into a paging object
|
|
119
118
|
*
|
|
@@ -170,37 +169,3 @@ export const toPageRaw = (token?: Amity.Token): Amity.PageRaw | null => {
|
|
|
170
169
|
|
|
171
170
|
return null
|
|
172
171
|
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Slices a collection according to its paging
|
|
176
|
-
*
|
|
177
|
-
* @param type the type of collection (for unique id identification with after/before)
|
|
178
|
-
* @param collection the collection to slice
|
|
179
|
-
* @param paging the paging object
|
|
180
|
-
* @returns the sliced collection according to the paging definition
|
|
181
|
-
*
|
|
182
|
-
* @hidden
|
|
183
|
-
*/
|
|
184
|
-
export const sliceByPaging = <K extends Amity.Domain, T extends Amity.Model[K]>(
|
|
185
|
-
type: K, collection: T[], page?: Amity.Page
|
|
186
|
-
) => {
|
|
187
|
-
console.log('slice by paging', page)
|
|
188
|
-
if (!page) return collection.slice()
|
|
189
|
-
|
|
190
|
-
let start: number | undefined = 0
|
|
191
|
-
let end: number | undefined = undefined
|
|
192
|
-
|
|
193
|
-
// next page behavior
|
|
194
|
-
if (page.after) {
|
|
195
|
-
start = page.after
|
|
196
|
-
end = start + page.limit
|
|
197
|
-
// prev page behavior
|
|
198
|
-
} else if (page.before) {
|
|
199
|
-
end = page.before + 1
|
|
200
|
-
start = end > page.limit ? end - page.limit : 0
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const paged = collection.slice(start, end)
|
|
204
|
-
|
|
205
|
-
return paged.length === page.limit ? paged : undefined
|
|
206
|
-
}
|
package/src/core/query/query.ts
CHANGED
|
@@ -170,7 +170,7 @@ const isEmpty = (local: any) => {
|
|
|
170
170
|
*/
|
|
171
171
|
export const runQuery = <Args extends any[], Returned extends any>(
|
|
172
172
|
{ func, args }: Amity.Query<Args, Returned>,
|
|
173
|
-
callback?: (args: Amity.Snapshot<Returned
|
|
173
|
+
callback?: (args: Amity.Snapshot<Returned>) => void,
|
|
174
174
|
options: Amity.QueryOptions = queryOptions('cache_then_server')
|
|
175
175
|
) => {
|
|
176
176
|
let local: Returned | undefined
|
|
@@ -193,7 +193,7 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
193
193
|
|
|
194
194
|
const shouldAbort = isCachable(local) && isFresh(local, options.lifeSpan)
|
|
195
195
|
|
|
196
|
-
callback?.(createSnapshot(local , {
|
|
196
|
+
callback?.(createSnapshot<Returned>(local , {
|
|
197
197
|
origin: 'local',
|
|
198
198
|
loading: !(isFetcher(func) && shouldAbort)
|
|
199
199
|
}))
|
|
@@ -201,7 +201,7 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
201
201
|
if (shouldAbort)
|
|
202
202
|
return
|
|
203
203
|
} else {
|
|
204
|
-
callback?.(createSnapshot(undefined, {
|
|
204
|
+
callback?.(createSnapshot<Returned>(undefined, {
|
|
205
205
|
origin: 'local',
|
|
206
206
|
loading: true
|
|
207
207
|
}))
|
|
@@ -213,7 +213,7 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
213
213
|
// isLocal(local) && syncInCache(local, fresh)
|
|
214
214
|
|
|
215
215
|
callback?.(
|
|
216
|
-
createSnapshot(fresh, {
|
|
216
|
+
createSnapshot<Returned>(fresh, {
|
|
217
217
|
origin: 'server',
|
|
218
218
|
loading: false,
|
|
219
219
|
})
|
|
@@ -221,7 +221,7 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
221
221
|
})
|
|
222
222
|
.catch(error => {
|
|
223
223
|
callback?.(
|
|
224
|
-
createSnapshot(undefined, {
|
|
224
|
+
createSnapshot<Returned>(undefined, {
|
|
225
225
|
origin: 'server',
|
|
226
226
|
loading: false,
|
|
227
227
|
error,
|
package/src/core/subscription.ts
CHANGED
|
@@ -61,13 +61,13 @@ export function subscribeTopic(
|
|
|
61
61
|
topic: string,
|
|
62
62
|
callback?: Amity.Listener<ASCError | void>
|
|
63
63
|
): Amity.Unsubscriber {
|
|
64
|
-
const { mqtt, emitter, accessToken,
|
|
64
|
+
const { mqtt, emitter, accessToken, _internalUserId } = getActiveClient()
|
|
65
65
|
|
|
66
|
-
if (mqttAccessToken !== accessToken || mqttUserId !==
|
|
66
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== _internalUserId) {
|
|
67
67
|
mqttAccessToken = accessToken!
|
|
68
|
-
mqttUserId =
|
|
68
|
+
mqttUserId = _internalUserId!
|
|
69
69
|
|
|
70
|
-
mqtt.connect({ accessToken:
|
|
70
|
+
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId })
|
|
71
71
|
proxyMqttEvents(mqtt, emitter)
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api/activeClient'
|
|
|
2
2
|
|
|
3
3
|
import { toPage, toToken } from '~/core/query'
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
|
+
import { pullFromCache, pushToCache } from '~/cache/api'
|
|
6
|
+
import { getResolver } from '~/core/model'
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
@@ -19,15 +21,16 @@ import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
|
19
21
|
**/
|
|
20
22
|
export const queryGlobalFeed = async (query?: {
|
|
21
23
|
dataTypes?: ('video' | 'image' | 'file' | 'liveStream')[]
|
|
24
|
+
useCustomRanking?: boolean
|
|
22
25
|
page?: Amity.Page
|
|
23
|
-
}): Promise<Amity.Paged<Amity.Post
|
|
26
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.Post>>> => {
|
|
24
27
|
const client = getActiveClient()
|
|
25
28
|
client.log('feed/queryGlobalFeed', query)
|
|
26
29
|
|
|
27
|
-
const { page, ...params } = query ?? {}
|
|
30
|
+
const { useCustomRanking, page, ...params } = query ?? {}
|
|
28
31
|
|
|
29
32
|
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
30
|
-
`/api/v4/me/global-feeds`, { params: {
|
|
33
|
+
useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: {
|
|
31
34
|
...params,
|
|
32
35
|
options: {
|
|
33
36
|
token: toToken(page, 'skiplimit')
|
|
@@ -38,10 +41,60 @@ export const queryGlobalFeed = async (query?: {
|
|
|
38
41
|
const { paging, ...payload } = data
|
|
39
42
|
const { posts } = payload
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
const cachedAt = client.cache && Date.now()
|
|
45
|
+
|
|
46
|
+
if (client.cache) {
|
|
47
|
+
ingestInCache(payload as Amity.PostPayload)
|
|
48
|
+
|
|
49
|
+
const cacheKey = ['globalFeed', 'query', { ...params, useCustomRanking, options: { ...page } } as Amity.Serializable]
|
|
50
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging })
|
|
51
|
+
}
|
|
42
52
|
|
|
43
53
|
const nextPage = toPage(paging.next)
|
|
44
54
|
const prevPage = toPage(paging.previous)
|
|
45
55
|
|
|
46
|
-
return { data: posts, prevPage, nextPage }
|
|
56
|
+
return { data: posts, cachedAt, prevPage, nextPage }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ```js
|
|
61
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
62
|
+
* const posts = await queryGlobalFeed.locally()
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
66
|
+
*
|
|
67
|
+
* @param query The query parameters
|
|
68
|
+
* @returns A page of {@link Amity.Post} objects
|
|
69
|
+
*
|
|
70
|
+
* @category Feed API
|
|
71
|
+
* @async
|
|
72
|
+
**/
|
|
73
|
+
queryGlobalFeed.locally = (
|
|
74
|
+
query: Parameters<typeof queryGlobalFeed>[0],
|
|
75
|
+
): Amity.Cached<Amity.Paged<Amity.Post>> | undefined => {
|
|
76
|
+
const client = getActiveClient()
|
|
77
|
+
client.log('post/queryGlobalFeed.locally', query)
|
|
78
|
+
|
|
79
|
+
if (!client.cache) return
|
|
80
|
+
|
|
81
|
+
const { useCustomRanking, page, ...params } = query ?? {}
|
|
82
|
+
|
|
83
|
+
const queryKey = ['globalFeed', 'query', { ...params, useCustomRanking, options: { ...page }} as Amity.Serializable];
|
|
84
|
+
const { data, cachedAt } = pullFromCache<{ posts: string[] } & Amity.Pagination>(queryKey) ?? {}
|
|
85
|
+
|
|
86
|
+
if (!data?.posts.length)
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
const posts: Amity.Post[] = data.posts
|
|
90
|
+
.map(postId => pullFromCache<Amity.Post>(['post', 'get', postId])!)
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.map(({ data }) => data)
|
|
93
|
+
|
|
94
|
+
const prevPage = toPage(data?.paging.previous)
|
|
95
|
+
const nextPage = toPage(data?.paging.next)
|
|
96
|
+
|
|
97
|
+
return posts.length === data?.posts?.length
|
|
98
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
99
|
+
: undefined
|
|
47
100
|
}
|
package/src/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ import { fireEvent } from '~/core/events'
|
|
|
24
24
|
* @async
|
|
25
25
|
*/
|
|
26
26
|
export const createMessage = async <T extends Amity.MessageContentType>(
|
|
27
|
-
bundle: Pick<Amity.Message<T>, 'channelId' | 'type' | 'data' | 'metadata'>
|
|
27
|
+
bundle: Pick<Amity.Message<T>, 'channelId' | 'type' | 'data' | 'metadata' | 'mentionees'>
|
|
28
28
|
): Promise<Amity.Cached<Amity.Message>> => {
|
|
29
29
|
const client = getActiveClient()
|
|
30
30
|
client.log('user/createMessage', bundle)
|
|
@@ -62,7 +62,7 @@ export const createMessage = async <T extends Amity.MessageContentType>(
|
|
|
62
62
|
* @category Message API
|
|
63
63
|
*/
|
|
64
64
|
createMessage.optimistically = (
|
|
65
|
-
bundle: Pick<Amity.Message, 'channelId' | 'type' | 'data' | 'metadata'>
|
|
65
|
+
bundle: Pick<Amity.Message, 'channelId' | 'type' | 'data' | 'metadata' | 'mentionees'>
|
|
66
66
|
): Amity.Cached<Amity.Message> | undefined => {
|
|
67
67
|
const client = getActiveClient()
|
|
68
68
|
client.log('user/createMessage.locally', bundle)
|
|
@@ -23,7 +23,7 @@ import { fireEvent } from '~/core/events'
|
|
|
23
23
|
*/
|
|
24
24
|
export const updateMessage = async (
|
|
25
25
|
messageId: Amity.Message['messageId'],
|
|
26
|
-
patch: Patch<Amity.Message, 'data' | 'metadata'>,
|
|
26
|
+
patch: Patch<Amity.Message, 'data' | 'metadata' | 'mentionees'>,
|
|
27
27
|
): Promise<Amity.Cached<Amity.Message>> => {
|
|
28
28
|
const client = getActiveClient()
|
|
29
29
|
client.log('user/updateMessage', patch)
|
|
@@ -61,7 +61,7 @@ export const updateMessage = async (
|
|
|
61
61
|
*/
|
|
62
62
|
updateMessage.optimistically = (
|
|
63
63
|
messageId: Amity.Message['messageId'],
|
|
64
|
-
patch: Patch<Amity.Message, 'data' | 'metadata'>,
|
|
64
|
+
patch: Patch<Amity.Message, 'data' | 'metadata' | 'mentionees'>,
|
|
65
65
|
): Amity.Cached<Amity.Message> | undefined => {
|
|
66
66
|
const client = getActiveClient()
|
|
67
67
|
client.log('user/updateMessage', patch)
|
|
@@ -22,19 +22,21 @@ import { fireEvent } from '~/core/events'
|
|
|
22
22
|
* @async
|
|
23
23
|
*/
|
|
24
24
|
export const createPost = async <T extends Amity.PostContentType | string>(
|
|
25
|
-
bundle: Pick<Amity.Post, 'targetType' | 'targetId' | 'metadata'> & {
|
|
26
|
-
dataType?: T,
|
|
25
|
+
bundle: Pick<Amity.Post, 'targetType' | 'targetId' | 'metadata' | 'mentionees'> & {
|
|
26
|
+
dataType?: T,
|
|
27
|
+
data?: { [k: string]: any },
|
|
28
|
+
attachments?: { type: T, fileId: Amity.File['fileId'] }[]
|
|
27
29
|
},
|
|
28
30
|
): Promise<Amity.Cached<Amity.Post>> => {
|
|
29
31
|
const client = getActiveClient()
|
|
30
32
|
client.log('post/createPost', bundle)
|
|
31
33
|
|
|
32
34
|
// API-FIX: backend rejects that we pass the dataType manually T_T
|
|
33
|
-
if (!bundle.dataType || ['text', 'image', 'file'].includes(bundle.dataType))
|
|
35
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
|
|
34
36
|
delete bundle.dataType
|
|
35
37
|
|
|
36
38
|
const { data } = await client.http.post<Amity.PostPayload>(
|
|
37
|
-
'/api/
|
|
39
|
+
'/api/v4/posts', bundle
|
|
38
40
|
)
|
|
39
41
|
|
|
40
42
|
const cachedAt = client.cache && Date.now()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { toToken, toPageRaw } from '~/core/query'
|
|
4
4
|
|
|
5
5
|
import { pullFromCache, pushToCache } from '~/cache/api'
|
|
6
6
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
@@ -31,9 +31,9 @@ export const queryPosts = async (
|
|
|
31
31
|
feedType?: 'reviewing' | 'published'
|
|
32
32
|
tags?: Amity.Taggable['tags'],
|
|
33
33
|
matchingOnlyParentPost?: boolean
|
|
34
|
-
page?: Amity.
|
|
34
|
+
page?: Amity.PageRaw
|
|
35
35
|
}
|
|
36
|
-
): Promise<Amity.Cached<Amity.
|
|
36
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.Post>>> => {
|
|
37
37
|
const client = getActiveClient()
|
|
38
38
|
client.log('post/queryPosts', query)
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ export const queryPosts = async (
|
|
|
41
41
|
|
|
42
42
|
// API-FIX: parameters should be querystring. (1)
|
|
43
43
|
// API-FIX: backend should answer Amity.Response (2)
|
|
44
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
44
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
45
45
|
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
46
46
|
`/api/v4/posts`, { params: {
|
|
47
47
|
...params,
|
|
@@ -87,7 +87,7 @@ export const queryPosts = async (
|
|
|
87
87
|
*/
|
|
88
88
|
queryPosts.locally = (
|
|
89
89
|
query: Parameters<typeof queryPosts>[0],
|
|
90
|
-
): Amity.Cached<Amity.
|
|
90
|
+
): Amity.Cached<Amity.Paged<Amity.Post>> | undefined => {
|
|
91
91
|
const client = getActiveClient()
|
|
92
92
|
client.log('post/queryPosts.locally', query)
|
|
93
93
|
|
|
@@ -22,13 +22,13 @@ import { fireEvent } from '~/core/events'
|
|
|
22
22
|
*/
|
|
23
23
|
export const updatePost = async (
|
|
24
24
|
postId: Amity.Post['postId'],
|
|
25
|
-
patch: Patch<Amity.Post, 'data' | 'metadata'>,
|
|
25
|
+
patch: Patch<Amity.Post, 'data' | 'metadata' | 'mentionees'>,
|
|
26
26
|
): Promise<Amity.Cached<Amity.Post>> => {
|
|
27
27
|
const client = getActiveClient()
|
|
28
28
|
client.log('user/updatePost', patch)
|
|
29
29
|
|
|
30
30
|
const { data } = await client.http.put<Amity.PostPayload>(
|
|
31
|
-
`/api/
|
|
31
|
+
`/api/v4/posts/${encodeURIComponent(postId)}`, patch,
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
const cachedAt = client.cache && Date.now()
|
package/src/utils/env.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const theGlobal = globalThis || global || window;
|
|
2
|
+
|
|
3
|
+
export const { process: safeProcess = {} }: { process: Partial<NodeJS.Process> } = theGlobal
|
|
4
|
+
|
|
5
|
+
export function getEnv() { return safeProcess.env ?? {} }
|
|
6
|
+
|
|
7
|
+
export const isProduction = safeProcess.env?.NODE_ENV === 'production'
|
package/src/version.ts
CHANGED
package/dist/core/network.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const API_ENDPOINT: {
|
|
2
|
-
readonly EU: "eu";
|
|
3
|
-
readonly SG: "sg";
|
|
4
|
-
readonly US: "us";
|
|
5
|
-
};
|
|
6
|
-
export declare enum UrlTemplate {
|
|
7
|
-
HTTP = "https://api.{region}.amity.co",
|
|
8
|
-
MQTT = "wss://sse.{region}.amity.co:443/mqtt"
|
|
9
|
-
}
|
|
10
|
-
export declare const getUrlFromTemplate: (template: UrlTemplate, region: string) => string;
|
|
11
|
-
//# sourceMappingURL=network.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/core/network.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIf,CAAA;AAEV,oBAAY,WAAW;IACrB,IAAI,kCAAkC;IACtC,IAAI,yCAAyC;CAC9C;AAED,eAAO,MAAM,kBAAkB,aAAe,WAAW,UAAU,MAAM,WAExE,CAAA"}
|
package/src/core/network.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const API_ENDPOINT = {
|
|
2
|
-
EU: 'eu',
|
|
3
|
-
SG: 'sg',
|
|
4
|
-
US: 'us',
|
|
5
|
-
} as const
|
|
6
|
-
|
|
7
|
-
export enum UrlTemplate {
|
|
8
|
-
HTTP = 'https://api.{region}.amity.co',
|
|
9
|
-
MQTT = 'wss://sse.{region}.amity.co:443/mqtt',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const getUrlFromTemplate = ( template: UrlTemplate, region: string ) => {
|
|
13
|
-
return template.replace( '{region}', region);
|
|
14
|
-
}
|