@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.
@@ -19,5 +19,7 @@
19
19
  * @category Poll API
20
20
  * @async
21
21
  */
22
- export declare const createPoll: (bundle: Pick<Amity.Poll, 'question' | 'answers' | 'answerType' | 'closedIn'>) => Promise<Amity.Cached<Amity.Poll>>;
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,SAAS,GAAG,YAAY,GAAG,UAAU,CAAC,KAC3E,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAelC,CAAC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-beta.18",
3
+ "version": "0.0.1-beta.19",
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",
@@ -13,6 +13,7 @@ declare global {
13
13
  childrenNumber: number;
14
14
  children: Comment['commentId'][];
15
15
  segmentNumber: number;
16
+ editedAt: Amity.timestamp;
16
17
  } & Amity.Relationship<CommentReferenceType> &
17
18
  Amity.Content<T> &
18
19
  Amity.Metadata &
@@ -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()
@@ -3,3 +3,4 @@ export * from './createFile';
3
3
  export * from './deleteFile';
4
4
  export * from './fileUrlWithSize';
5
5
  export * from './createVideo';
6
+ export * from './createImage';
package/src/index.ts CHANGED
@@ -62,3 +62,6 @@ export * from './poll/api';
62
62
 
63
63
  export * from './stream/api';
64
64
  export * from './stream/events';
65
+
66
+ // // external apis
67
+ export * from './external/api';
@@ -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' | 'answers' | 'answerType' | 'closedIn'>,
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);