@amityco/ts-sdk 0.0.1-beta.18 → 0.0.1-beta.19
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/domains/comment.d.ts +1 -0
- package/dist/@types/domains/comment.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/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 +65 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +64 -1
- 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/package.json +1 -1
- package/src/@types/domains/comment.ts +1 -0
- package/src/channel/api/queryChannels.ts +2 -0
- 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
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -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();
|
|
@@ -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);
|