@alphauspkgs/blue-sdk-ts 1.0.36 → 1.0.37
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/conn/conn.js +14 -6
- package/conn/conn.ts +21 -10
- package/cover/v1/client.js +2 -2
- package/cover/v1/client.ts +2 -2
- package/package.json +2 -3
package/conn/conn.js
CHANGED
|
@@ -6,15 +6,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BlueCredentials = exports.WithNewBlueCredentials = exports.WithAccessToken = exports.WithDefaultCredentials = exports.BlueAPIService = void 0;
|
|
7
7
|
const connect_1 = require("@connectrpc/connect");
|
|
8
8
|
const connect_web_1 = require("@connectrpc/connect-web");
|
|
9
|
-
const connect_devtools_1 = require("connect-devtools");
|
|
10
9
|
const axios_1 = __importDefault(require("axios"));
|
|
11
10
|
const DEFAULT_BLUE_RPC_HOST = "https://bluerpc.alphaus.cloud:8443";
|
|
12
11
|
const DEFAULT_AUTH_URL = "https://login.alphaus.cloud/ripple/access_token";
|
|
12
|
+
function loggingInterceptor() {
|
|
13
|
+
return (next) => async (req) => {
|
|
14
|
+
const res = await next(req);
|
|
15
|
+
const message = {
|
|
16
|
+
method: req.method.name,
|
|
17
|
+
request: req.message,
|
|
18
|
+
response: res.message,
|
|
19
|
+
};
|
|
20
|
+
console.log(message);
|
|
21
|
+
return res;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
13
24
|
class BlueAPIService {
|
|
14
25
|
get clientInstance() {
|
|
15
26
|
return this.client;
|
|
16
27
|
}
|
|
17
|
-
constructor(service, serviceName, connectOption = new WithDefaultCredentials()) {
|
|
28
|
+
constructor(service, serviceName, connectOption = new WithDefaultCredentials(), logging = false) {
|
|
18
29
|
this.serviceName = serviceName;
|
|
19
30
|
const interceptors = [
|
|
20
31
|
(next) => async (req) => {
|
|
@@ -22,11 +33,8 @@ class BlueAPIService {
|
|
|
22
33
|
await connectOption.apply(req.header);
|
|
23
34
|
return await next(req);
|
|
24
35
|
},
|
|
36
|
+
...(logging ? [loggingInterceptor()] : []),
|
|
25
37
|
];
|
|
26
|
-
if ("window" in globalThis &&
|
|
27
|
-
"__CONNECT_WEB_DEVTOOLS__" in globalThis.window) {
|
|
28
|
-
interceptors.push(connect_devtools_1.devtoolsInterceptor);
|
|
29
|
-
}
|
|
30
38
|
const transport = (0, connect_web_1.createGrpcWebTransport)({
|
|
31
39
|
baseUrl: connectOption.getHost(),
|
|
32
40
|
interceptors: interceptors,
|
package/conn/conn.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { createClient, Interceptor, type Client } from "@connectrpc/connect";
|
|
2
2
|
import { createGrpcWebTransport } from "@connectrpc/connect-web";
|
|
3
3
|
import type { DescService } from "@bufbuild/protobuf";
|
|
4
|
-
import { devtoolsInterceptor } from "connect-devtools";
|
|
5
4
|
import axios from "axios";
|
|
6
5
|
|
|
7
6
|
const DEFAULT_BLUE_RPC_HOST = "https://bluerpc.alphaus.cloud:8443";
|
|
8
7
|
const DEFAULT_AUTH_URL = "https://login.alphaus.cloud/ripple/access_token";
|
|
8
|
+
|
|
9
|
+
function loggingInterceptor(): Interceptor {
|
|
10
|
+
return (next) => async (req) => {
|
|
11
|
+
const res = await next(req);
|
|
12
|
+
|
|
13
|
+
const message = {
|
|
14
|
+
method: req.method.name,
|
|
15
|
+
request: req.message,
|
|
16
|
+
response: res.message,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
console.log(message);
|
|
20
|
+
|
|
21
|
+
return res;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
export class BlueAPIService<Service extends DescService> {
|
|
10
26
|
private client: Client<Service>;
|
|
11
27
|
|
|
@@ -16,7 +32,8 @@ export class BlueAPIService<Service extends DescService> {
|
|
|
16
32
|
constructor(
|
|
17
33
|
service: Service,
|
|
18
34
|
private serviceName: string,
|
|
19
|
-
connectOption: ConnectOption = new WithDefaultCredentials()
|
|
35
|
+
connectOption: ConnectOption = new WithDefaultCredentials(),
|
|
36
|
+
logging = false,
|
|
20
37
|
) {
|
|
21
38
|
const interceptors: Interceptor[] = [
|
|
22
39
|
(next) => async (req) => {
|
|
@@ -24,15 +41,9 @@ export class BlueAPIService<Service extends DescService> {
|
|
|
24
41
|
await connectOption.apply(req.header);
|
|
25
42
|
return await next(req);
|
|
26
43
|
},
|
|
44
|
+
...(logging ? [loggingInterceptor()] : []),
|
|
27
45
|
];
|
|
28
46
|
|
|
29
|
-
if (
|
|
30
|
-
"window" in globalThis &&
|
|
31
|
-
"__CONNECT_WEB_DEVTOOLS__" in globalThis.window
|
|
32
|
-
) {
|
|
33
|
-
interceptors.push(devtoolsInterceptor);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
47
|
const transport = createGrpcWebTransport({
|
|
37
48
|
baseUrl: connectOption.getHost(),
|
|
38
49
|
interceptors: interceptors,
|
|
@@ -85,7 +96,7 @@ export class WithDefaultCredentials implements ConnectOption {
|
|
|
85
96
|
export class WithAccessToken implements ConnectOption {
|
|
86
97
|
constructor(
|
|
87
98
|
private readonly accessToken: string,
|
|
88
|
-
private readonly host?: string
|
|
99
|
+
private readonly host?: string,
|
|
89
100
|
) {}
|
|
90
101
|
|
|
91
102
|
getHost(): string {
|
package/cover/v1/client.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NewCoverClient = NewCoverClient;
|
|
4
4
|
const cover_pb_1 = require("./cover_pb");
|
|
5
5
|
const conn_1 = require("../../conn/conn");
|
|
6
|
-
function NewCoverClient(opt) {
|
|
7
|
-
const blueapi = new conn_1.BlueAPIService(cover_pb_1.Cover, "cover", opt);
|
|
6
|
+
function NewCoverClient(opt, logging = false) {
|
|
7
|
+
const blueapi = new conn_1.BlueAPIService(cover_pb_1.Cover, "cover", opt, logging);
|
|
8
8
|
return blueapi.clientInstance;
|
|
9
9
|
}
|
package/cover/v1/client.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cover } from "./cover_pb";
|
|
2
2
|
import { BlueAPIService, ConnectOption } from "../../conn/conn";
|
|
3
3
|
|
|
4
|
-
export function NewCoverClient(opt?: ConnectOption) {
|
|
5
|
-
const blueapi = new BlueAPIService(Cover, "cover", opt);
|
|
4
|
+
export function NewCoverClient(opt?: ConnectOption, logging = false) {
|
|
5
|
+
const blueapi = new BlueAPIService(Cover, "cover", opt, logging);
|
|
6
6
|
return blueapi.clientInstance;
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphauspkgs/blue-sdk-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsc"
|
|
6
6
|
},
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@connectrpc/connect": "^2.1.0",
|
|
13
13
|
"@connectrpc/connect-web": "^2.1.0",
|
|
14
|
-
"axios": "^1.13.0"
|
|
15
|
-
"connect-devtools": "^1.0.0"
|
|
14
|
+
"axios": "^1.13.0"
|
|
16
15
|
},
|
|
17
16
|
"repository": {
|
|
18
17
|
"type": "git",
|