@amityco/ts-sdk 7.1.1-1d526d8.0 → 7.1.1-5d7c3fd0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "7.1.1-1d526d8.0",
3
+ "version": "7.1.1-5d7c3fd0.0",
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",
@@ -36,6 +36,7 @@ declare global {
36
36
 
37
37
  log: Logger;
38
38
  http: AxiosInstance;
39
+ upload: AxiosInstance;
39
40
  mqtt?: Amity.MqttClient;
40
41
  ws?: SocketIOClient.Socket;
41
42
  emitter: Emitter<Amity.Events>;
@@ -50,7 +50,7 @@ export const createClient = (
50
50
  rteEnabled = true,
51
51
  }: {
52
52
  debugSession?: string;
53
- apiEndpoint?: { http?: string; mqtt?: string };
53
+ apiEndpoint?: { http?: string; mqtt?: string; upload?: string };
54
54
  prefixDeviceIdKey?: string;
55
55
  rteEnabled?: boolean;
56
56
  } = {},
@@ -63,9 +63,11 @@ export const createClient = (
63
63
  });
64
64
 
65
65
  const httpEndpoint = apiEndpoint?.http ?? computeUrl('http', apiRegion);
66
+ const uploadEndpoint = apiEndpoint?.upload ?? computeUrl('upload', apiRegion);
66
67
  const mqttEndpoint = apiEndpoint?.mqtt ?? computeUrl('mqtt', apiRegion);
67
68
 
68
69
  const http = createHttpTransport(httpEndpoint);
70
+ const upload = createHttpTransport(uploadEndpoint);
69
71
 
70
72
  let ws;
71
73
  let mqtt;
@@ -103,6 +105,7 @@ export const createClient = (
103
105
  http,
104
106
  ws,
105
107
  mqtt,
108
+ upload,
106
109
  emitter,
107
110
 
108
111
  /*
@@ -6,6 +6,7 @@ export const API_REGIONS = {
6
6
 
7
7
  const URLS = {
8
8
  http: 'https://apix.{region}.amity.co',
9
+ upload: 'https://upload.{region}.amity.co',
9
10
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
10
11
  } as const;
11
12
 
@@ -30,6 +30,14 @@ export const setClientToken = async (params: Parameters<typeof getToken>[0]) =>
30
30
  isUserDeleted: false,
31
31
  };
32
32
 
33
+ client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
34
+
35
+ client.upload.defaults.metadata = {
36
+ tokenExpiry: expiresAt,
37
+ isGlobalBanned: false,
38
+ isUserDeleted: false,
39
+ };
40
+
33
41
  // manually setup the token for ws transport
34
42
  if (client.ws) client.ws.io.opts.query = { token: accessToken };
35
43
 
@@ -42,7 +42,7 @@ export const uploadFile = async <T extends Amity.FileType = any>(
42
42
  ? (formData as any).getHeaders()
43
43
  : { 'content-type': 'multipart/form-data' };
44
44
 
45
- const { data } = await client.http.post<Amity.CreateFilePayload<T>>('/api/v4/files', formData, {
45
+ const { data } = await client.upload.post<Amity.CreateFilePayload<T>>('/api/v4/files', formData, {
46
46
  headers,
47
47
  onUploadProgress({ loaded, total = 100 }) {
48
48
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -42,7 +42,7 @@ export const uploadImage = async (
42
42
  ? (formData as any).getHeaders()
43
43
  : { 'content-type': 'multipart/form-data' };
44
44
 
45
- const { data } = await client.http.post<Amity.CreateFilePayload<'image'>>(
45
+ const { data } = await client.upload.post<Amity.CreateFilePayload<'image'>>(
46
46
  '/api/v4/images',
47
47
  formData,
48
48
  {
@@ -48,7 +48,7 @@ export const uploadVideo = async (
48
48
  ? (formData as any).getHeaders()
49
49
  : { 'content-type': 'multipart/form-data' };
50
50
 
51
- const { data } = await client.http.post<Amity.CreateFilePayload<'video'>>(
51
+ const { data } = await client.upload.post<Amity.CreateFilePayload<'video'>>(
52
52
  '/api/v4/videos',
53
53
  formData,
54
54
  {