@amityco/ts-sdk 0.0.1-beta.14 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-beta.14",
3
+ "version": "0.0.1-beta.15",
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",
@@ -6,7 +6,7 @@ declare global {
6
6
  namespace Amity {
7
7
  type Listener<T = any> = (params: T) => void
8
8
 
9
- type ObjectListener<T, K extends string[]> = {
9
+ type ObjectListener<T, K extends string[]> = Listener<T> | {
10
10
  onEvent?: (event: K[number], params: T) => void
11
11
  } & {
12
12
  [P in K[number]]?: Listener<T>
@@ -2,7 +2,7 @@ import { VERSION } from '~/version'
2
2
 
3
3
  import { createLogger } from '~/core/debug'
4
4
 
5
- import { API_ENDPOINT, getUrlFromTemplate, UrlTemplate } from '~/core/network'
5
+ import { API_REGIONS, computeUrl } from '~/client/utils/endpoints'
6
6
  import { createHttpTransport, createMqttTransport, createWebsocketTransport } from '~/core/transports'
7
7
 
8
8
  import { createEventEmitter } from '~/core/events'
@@ -18,7 +18,7 @@ import { getActiveClient, setActiveClient } from './activeClient'
18
18
  * Creates a new {@link Amity.Client} instance
19
19
  *
20
20
  * @param apiKey for the {@link Amity.Client} instance
21
- * @param apiEndpoint endpoint to connect to
21
+ * @param apiRegion endpoint to connect to
22
22
  * @param debugSession session's identifier for the client's logger instance
23
23
  * @returns A {@link Amity.Client} instance
24
24
  *
@@ -26,19 +26,19 @@ import { getActiveClient, setActiveClient } from './activeClient'
26
26
  **/
27
27
  export const createClient = (
28
28
  apiKey: string,
29
- apiEndpoint: typeof API_ENDPOINT[keyof typeof API_ENDPOINT]|string = API_ENDPOINT.SG,
29
+ apiRegion: typeof API_REGIONS[keyof typeof API_REGIONS] = API_REGIONS.SG,
30
30
  debugSession: string = 'amity'
31
31
  ): Amity.Client => {
32
32
  const log = createLogger(debugSession)
33
33
 
34
34
  log('client/api/createClient', {
35
35
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
36
- apiEndpoint,
36
+ apiRegion,
37
37
  })
38
38
 
39
- const http = createHttpTransport(getUrlFromTemplate(UrlTemplate.HTTP, apiEndpoint))
40
- const ws = createWebsocketTransport(getUrlFromTemplate(UrlTemplate.HTTP, apiEndpoint))
41
- const mqtt = createMqttTransport(getUrlFromTemplate(UrlTemplate.MQTT, apiEndpoint));
39
+ const http = createHttpTransport(computeUrl('http', apiRegion))
40
+ const ws = createWebsocketTransport(computeUrl('http', apiRegion))
41
+ const mqtt = createMqttTransport(computeUrl('mqtt', apiRegion));
42
42
 
43
43
  const emitter = createEventEmitter()
44
44
 
@@ -0,0 +1,14 @@
1
+ export const API_REGIONS = {
2
+ EU: 'eu',
3
+ SG: 'sg',
4
+ US: 'us',
5
+ } as const
6
+
7
+ const URLS = {
8
+ http: 'https://api.{region}.amity.co',
9
+ mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
10
+ } as const
11
+
12
+ export function computeUrl(type: keyof typeof URLS, region: string) {
13
+ return URLS[type].replace('{region}', region)
14
+ }
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export * from './cache/api'
10
10
 
11
11
  export * from './client/api'
12
12
  export * from './client/events'
13
+ export { API_REGIONS } from './client/utils/endpoints'
13
14
 
14
15
  // asc core
15
16
  export * from './user/api'
@@ -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"}
@@ -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
- }