@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/README.md +3 -3
- package/dist/@types/core/events.d.ts +2 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +3 -3
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +12 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -0
- package/dist/index.cjs.js +15 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +15 -16
- package/dist/index.umd.js +5 -5
- package/package.json +1 -1
- package/src/@types/core/events.ts +1 -1
- package/src/client/api/createClient.ts +7 -7
- package/src/client/utils/endpoints.ts +14 -0
- package/src/index.ts +1 -0
- package/dist/core/network.d.ts +0 -11
- package/dist/core/network.d.ts.map +0 -1
- package/src/core/network.ts +0 -14
package/package.json
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
36
|
+
apiRegion,
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
const http = createHttpTransport(
|
|
40
|
-
const ws = createWebsocketTransport(
|
|
41
|
-
const mqtt = createMqttTransport(
|
|
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
package/dist/core/network.d.ts
DELETED
|
@@ -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"}
|
package/src/core/network.ts
DELETED
|
@@ -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
|
-
}
|