@amityco/ts-sdk 6.35.3-854efd4.0 → 6.35.3-c7e7d80.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": "6.35.3-854efd4.0",
3
+ "version": "6.35.3-c7e7d80.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",
@@ -0,0 +1,12 @@
1
+ export {};
2
+
3
+ declare global {
4
+ namespace Amity {
5
+ type LinkPreview = {
6
+ title: string | null;
7
+ description: string | null;
8
+ image: string | null;
9
+ video: string | null;
10
+ };
11
+ }
12
+ }
@@ -0,0 +1,30 @@
1
+ import { getActiveClient } from './activeClient';
2
+
3
+ /**
4
+ * ```js
5
+ * import { fetchLinkPreview } from '@amityco/ts-sdk'
6
+ * const { title, description, imageUrl } = fetchLinkPreview('https://www.example.com/')
7
+ * ```
8
+ *
9
+ *
10
+ * @param url the url to fetch link preview
11
+ * @returns A {@link Amity.LinkPreview} instance
12
+ *
13
+ * @category Client API
14
+ * */
15
+
16
+ export const fetchLinkPreview = async (url: string): Promise<Amity.LinkPreview> => {
17
+ const client = getActiveClient();
18
+
19
+ let fetchUrl = url;
20
+
21
+ if (!/^https?:\/\//i.test(url)) {
22
+ fetchUrl = `https://${url}`;
23
+ }
24
+
25
+ const { data } = await client.http.get<Amity.LinkPreview>(
26
+ `/api/v1/link-preview?url=${encodeURIComponent(fetchUrl)}`,
27
+ );
28
+
29
+ return data;
30
+ };
@@ -18,3 +18,5 @@ export * from './markerSync';
18
18
  export * from './enableUnreadCount';
19
19
 
20
20
  export * from './setUploadedFileAccessType';
21
+
22
+ export * from './fetchLinkPreview';