macrocosmos 1.2.0 → 1.2.2
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/dist/lib/BaseClient.d.ts +46 -0
- package/dist/lib/BaseClient.js +66 -0
- package/dist/lib/apex/Client.d.ts +7 -10
- package/dist/lib/apex/Client.js +17 -21
- package/dist/lib/billing/Client.d.ts +3 -12
- package/dist/lib/billing/Client.js +10 -21
- package/dist/lib/gravity/Client.d.ts +12 -14
- package/dist/lib/gravity/Client.js +10 -20
- package/dist/lib/sn13/Client.d.ts +3 -12
- package/dist/lib/sn13/Client.js +10 -21
- package/new_version.txt +1 -0
- package/old_version.txt +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface BaseClientOptions {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
appName?: string;
|
|
5
|
+
secure?: boolean;
|
|
6
|
+
userId?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Base client class that provides common functionality for all clients
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseClient {
|
|
12
|
+
protected apiKey: string;
|
|
13
|
+
protected baseURL: string;
|
|
14
|
+
protected appName: string;
|
|
15
|
+
protected secure: boolean;
|
|
16
|
+
protected userId: string;
|
|
17
|
+
constructor(options: BaseClientOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Get the API key for authentication
|
|
20
|
+
*/
|
|
21
|
+
protected getApiKey(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the base URL for the client
|
|
24
|
+
*/
|
|
25
|
+
protected getBaseURL(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get the app name for the client
|
|
28
|
+
*/
|
|
29
|
+
protected getAppName(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get whether the client is using secure connections
|
|
32
|
+
*/
|
|
33
|
+
protected isSecure(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get the client name
|
|
36
|
+
*/
|
|
37
|
+
protected getClientName(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get the client version
|
|
40
|
+
*/
|
|
41
|
+
protected getClientVersion(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get the user ID for service account authentication
|
|
44
|
+
*/
|
|
45
|
+
protected getUserId(): string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
/**
|
|
6
|
+
* Base client class that provides common functionality for all clients
|
|
7
|
+
*/
|
|
8
|
+
class BaseClient {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.apiKey = options.apiKey || "";
|
|
11
|
+
this.baseURL = options.baseURL || constants_1.BASE_URL;
|
|
12
|
+
this.appName = options.appName || "unknown";
|
|
13
|
+
this.userId = options.userId || "";
|
|
14
|
+
// Check environment variable for HTTPS setting
|
|
15
|
+
const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
|
|
16
|
+
// Use secure if explicitly set in options or if HTTPS is enabled via env var
|
|
17
|
+
this.secure = options.secure !== undefined ? options.secure : useHttps;
|
|
18
|
+
// Check if the API key is valid
|
|
19
|
+
if (!this.apiKey) {
|
|
20
|
+
throw new Error("API key is required");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the API key for authentication
|
|
25
|
+
*/
|
|
26
|
+
getApiKey() {
|
|
27
|
+
return this.apiKey;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the base URL for the client
|
|
31
|
+
*/
|
|
32
|
+
getBaseURL() {
|
|
33
|
+
return this.baseURL;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the app name for the client
|
|
37
|
+
*/
|
|
38
|
+
getAppName() {
|
|
39
|
+
return this.appName;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get whether the client is using secure connections
|
|
43
|
+
*/
|
|
44
|
+
isSecure() {
|
|
45
|
+
return this.secure;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the client name
|
|
49
|
+
*/
|
|
50
|
+
getClientName() {
|
|
51
|
+
return constants_1.CLIENT_NAME;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the client version
|
|
55
|
+
*/
|
|
56
|
+
getClientVersion() {
|
|
57
|
+
return constants_1.VERSION;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the user ID for service account authentication
|
|
61
|
+
*/
|
|
62
|
+
getUserId() {
|
|
63
|
+
return this.userId;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.BaseClient = BaseClient;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { IChatCompletionRequest, IChatMessage, ISamplingParameters, IChatCompletionResponse, IChatCompletionChunkResponse, IWebRetrievalRequest, IWebRetrievalResponse, IApexServiceClient } from "../../generated/apex/v1/apex";
|
|
3
|
+
import { BaseClient, BaseClientOptions } from "../BaseClient";
|
|
3
4
|
import { ApexStream } from "./Stream";
|
|
4
|
-
interface ApexClientOptions {
|
|
5
|
-
apiKey?: string;
|
|
6
|
-
baseURL?: string;
|
|
7
|
-
appName?: string;
|
|
5
|
+
interface ApexClientOptions extends BaseClientOptions {
|
|
8
6
|
timeout?: number;
|
|
9
|
-
secure?: boolean;
|
|
10
7
|
}
|
|
11
8
|
export type ChatMessage = IChatMessage;
|
|
12
9
|
export type SamplingParameters = ISamplingParameters;
|
|
@@ -26,16 +23,16 @@ export interface ApexProtoClient {
|
|
|
26
23
|
* Client for interacting with the Apex API
|
|
27
24
|
* Provides OpenAI-compatible interface over gRPC
|
|
28
25
|
*/
|
|
29
|
-
export declare class ApexClient {
|
|
30
|
-
apiKey: string;
|
|
31
|
-
private baseURL;
|
|
32
|
-
private appName;
|
|
26
|
+
export declare class ApexClient extends BaseClient {
|
|
33
27
|
private protoClient;
|
|
34
28
|
private defaultTimeout;
|
|
35
|
-
private secure;
|
|
36
29
|
constructor(options: ApexClientOptions);
|
|
37
30
|
private initializeGrpcClient;
|
|
38
31
|
private createGrpcClient;
|
|
32
|
+
/**
|
|
33
|
+
* Get the default timeout for chat completions
|
|
34
|
+
*/
|
|
35
|
+
private getDefaultTimeout;
|
|
39
36
|
/**
|
|
40
37
|
* OpenAI-compatible chat completions API
|
|
41
38
|
*/
|
package/dist/lib/apex/Client.js
CHANGED
|
@@ -37,14 +37,15 @@ exports.ApexClient = void 0;
|
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
-
const
|
|
40
|
+
const BaseClient_1 = require("../BaseClient");
|
|
41
41
|
const Stream_1 = require("./Stream");
|
|
42
42
|
/**
|
|
43
43
|
* Client for interacting with the Apex API
|
|
44
44
|
* Provides OpenAI-compatible interface over gRPC
|
|
45
45
|
*/
|
|
46
|
-
class ApexClient {
|
|
46
|
+
class ApexClient extends BaseClient_1.BaseClient {
|
|
47
47
|
constructor(options) {
|
|
48
|
+
super(options);
|
|
48
49
|
/**
|
|
49
50
|
* OpenAI-compatible chat completions API
|
|
50
51
|
*/
|
|
@@ -55,7 +56,7 @@ class ApexClient {
|
|
|
55
56
|
// Apply default timeout if not specified in params
|
|
56
57
|
const requestParams = {
|
|
57
58
|
...params,
|
|
58
|
-
timeout: params.timeout || this.
|
|
59
|
+
timeout: params.timeout || this.getDefaultTimeout(),
|
|
59
60
|
};
|
|
60
61
|
// Handle streaming vs non-streaming
|
|
61
62
|
if (requestParams.stream) {
|
|
@@ -96,20 +97,8 @@ class ApexClient {
|
|
|
96
97
|
});
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
|
-
this.apiKey = options.apiKey || constants_1.APEX_API_KEY || "";
|
|
100
|
-
this.baseURL = options.baseURL || constants_1.BASE_URL;
|
|
101
|
-
this.appName = options.appName || "unknown";
|
|
102
100
|
this.defaultTimeout = options.timeout || 60;
|
|
103
|
-
// Check environment variable for HTTPS setting
|
|
104
|
-
const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
|
|
105
|
-
// Use secure if explicitly set in options or if HTTPS is enabled via env var
|
|
106
|
-
this.secure = options.secure !== undefined ? options.secure : useHttps;
|
|
107
|
-
// Initialize gRPC client
|
|
108
101
|
this.protoClient = this.initializeGrpcClient();
|
|
109
|
-
// Check if the API key is valid
|
|
110
|
-
if (!this.apiKey) {
|
|
111
|
-
throw new Error("API key is required");
|
|
112
|
-
}
|
|
113
102
|
}
|
|
114
103
|
initializeGrpcClient() {
|
|
115
104
|
// Load proto file directly
|
|
@@ -130,15 +119,16 @@ class ApexClient {
|
|
|
130
119
|
// Create gRPC credentials with API key
|
|
131
120
|
const callCreds = grpc.credentials.createFromMetadataGenerator((_params, callback) => {
|
|
132
121
|
const meta = new grpc.Metadata();
|
|
133
|
-
meta.add("authorization", `Bearer ${this.
|
|
134
|
-
meta.add("x-source", this.
|
|
135
|
-
meta.add("x-client-id",
|
|
136
|
-
meta.add("x-client-version",
|
|
122
|
+
meta.add("authorization", `Bearer ${this.getApiKey()}`);
|
|
123
|
+
meta.add("x-source", this.getAppName());
|
|
124
|
+
meta.add("x-client-id", this.getClientName());
|
|
125
|
+
meta.add("x-client-version", this.getClientVersion());
|
|
126
|
+
meta.add("x-forwarded-user", this.getUserId());
|
|
137
127
|
callback(null, meta);
|
|
138
128
|
});
|
|
139
129
|
// Create credentials based on secure option
|
|
140
130
|
let credentials;
|
|
141
|
-
if (this.
|
|
131
|
+
if (this.isSecure()) {
|
|
142
132
|
// Use secure credentials for production
|
|
143
133
|
const channelCreds = grpc.credentials.createSsl();
|
|
144
134
|
credentials = grpc.credentials.combineChannelCredentials(channelCreds, callCreds);
|
|
@@ -148,7 +138,13 @@ class ApexClient {
|
|
|
148
138
|
credentials = grpc.credentials.createInsecure();
|
|
149
139
|
}
|
|
150
140
|
// Create gRPC client
|
|
151
|
-
return new this.protoClient.ApexService(this.
|
|
141
|
+
return new this.protoClient.ApexService(this.getBaseURL(), credentials);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the default timeout for chat completions
|
|
145
|
+
*/
|
|
146
|
+
getDefaultTimeout() {
|
|
147
|
+
return this.defaultTimeout;
|
|
152
148
|
}
|
|
153
149
|
}
|
|
154
150
|
exports.ApexClient = ApexClient;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { IGetUsageRequest, IGetUsageResponse, IBillingServiceClient } from "../../generated/billing/v1/billing";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
baseURL?: string;
|
|
6
|
-
appName?: string;
|
|
7
|
-
timeout?: number;
|
|
8
|
-
secure?: boolean;
|
|
3
|
+
import { BaseClient, BaseClientOptions } from "../BaseClient";
|
|
4
|
+
interface BillingClientOptions extends BaseClientOptions {
|
|
9
5
|
}
|
|
10
6
|
export type GetUsageRequest = IGetUsageRequest;
|
|
11
7
|
export type GetUsageResponse = IGetUsageResponse;
|
|
@@ -20,13 +16,8 @@ export interface BillingProtoClient {
|
|
|
20
16
|
* Client for interacting with the Billing API
|
|
21
17
|
* Provides billing service interface over gRPC
|
|
22
18
|
*/
|
|
23
|
-
export declare class BillingClient {
|
|
24
|
-
apiKey: string;
|
|
25
|
-
private baseURL;
|
|
26
|
-
private appName;
|
|
19
|
+
export declare class BillingClient extends BaseClient {
|
|
27
20
|
private protoClient;
|
|
28
|
-
private defaultTimeout;
|
|
29
|
-
private secure;
|
|
30
21
|
constructor(options: BillingClientOptions);
|
|
31
22
|
private initializeGrpcClient;
|
|
32
23
|
private createGrpcClient;
|
|
@@ -37,13 +37,14 @@ exports.BillingClient = void 0;
|
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
-
const
|
|
40
|
+
const BaseClient_1 = require("../BaseClient");
|
|
41
41
|
/**
|
|
42
42
|
* Client for interacting with the Billing API
|
|
43
43
|
* Provides billing service interface over gRPC
|
|
44
44
|
*/
|
|
45
|
-
class BillingClient {
|
|
45
|
+
class BillingClient extends BaseClient_1.BaseClient {
|
|
46
46
|
constructor(options) {
|
|
47
|
+
super(options);
|
|
47
48
|
/**
|
|
48
49
|
* Get usage information for a product
|
|
49
50
|
*/
|
|
@@ -59,20 +60,7 @@ class BillingClient {
|
|
|
59
60
|
});
|
|
60
61
|
});
|
|
61
62
|
};
|
|
62
|
-
this.apiKey = options.apiKey || constants_1.APEX_API_KEY || "";
|
|
63
|
-
this.baseURL = options.baseURL || constants_1.BASE_URL;
|
|
64
|
-
this.appName = options.appName || "unknown";
|
|
65
|
-
this.defaultTimeout = options.timeout || 60;
|
|
66
|
-
// Check environment variable for HTTPS setting
|
|
67
|
-
const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
|
|
68
|
-
// Use secure if explicitly set in options or if HTTPS is enabled via env var
|
|
69
|
-
this.secure = options.secure !== undefined ? options.secure : useHttps;
|
|
70
|
-
// Initialize gRPC client
|
|
71
63
|
this.protoClient = this.initializeGrpcClient();
|
|
72
|
-
// Check if the API key is valid
|
|
73
|
-
if (!this.apiKey) {
|
|
74
|
-
throw new Error("API key is required");
|
|
75
|
-
}
|
|
76
64
|
}
|
|
77
65
|
initializeGrpcClient() {
|
|
78
66
|
// Load proto file directly
|
|
@@ -93,15 +81,16 @@ class BillingClient {
|
|
|
93
81
|
// Create gRPC credentials with API key
|
|
94
82
|
const callCreds = grpc.credentials.createFromMetadataGenerator((_params, callback) => {
|
|
95
83
|
const meta = new grpc.Metadata();
|
|
96
|
-
meta.add("authorization", `Bearer ${this.
|
|
97
|
-
meta.add("x-source", this.
|
|
98
|
-
meta.add("x-client-id",
|
|
99
|
-
meta.add("x-client-version",
|
|
84
|
+
meta.add("authorization", `Bearer ${this.getApiKey()}`);
|
|
85
|
+
meta.add("x-source", this.getAppName());
|
|
86
|
+
meta.add("x-client-id", this.getClientName());
|
|
87
|
+
meta.add("x-client-version", this.getClientVersion());
|
|
88
|
+
meta.add("x-forwarded-user", this.getUserId());
|
|
100
89
|
callback(null, meta);
|
|
101
90
|
});
|
|
102
91
|
// Create credentials based on secure option
|
|
103
92
|
let credentials;
|
|
104
|
-
if (this.
|
|
93
|
+
if (this.isSecure()) {
|
|
105
94
|
// Use secure credentials for production
|
|
106
95
|
const channelCreds = grpc.credentials.createSsl();
|
|
107
96
|
credentials = grpc.credentials.combineChannelCredentials(channelCreds, callCreds);
|
|
@@ -111,7 +100,7 @@ class BillingClient {
|
|
|
111
100
|
credentials = grpc.credentials.createInsecure();
|
|
112
101
|
}
|
|
113
102
|
// Create gRPC client
|
|
114
|
-
return new this.protoClient.BillingService(this.
|
|
103
|
+
return new this.protoClient.BillingService(this.getBaseURL(), credentials);
|
|
115
104
|
}
|
|
116
105
|
}
|
|
117
106
|
exports.BillingClient = BillingClient;
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
import { IGetGravityTasksRequest, IGetGravityTasksResponse, IGetCrawlerRequest, IGetCrawlerResponse, ICreateGravityTaskRequest, ICreateGravityTaskResponse, IBuildDatasetRequest, IBuildDatasetResponse, IGetDatasetRequest, IGetDatasetResponse, ICancelGravityTaskRequest, ICancelGravityTaskResponse, ICancelDatasetRequest, ICancelDatasetResponse, IGravityServiceClient } from "../../generated/gravity/v1/gravity";
|
|
3
|
+
import { BaseClient, BaseClientOptions } from "../BaseClient";
|
|
4
|
+
interface GravityClientOptions extends BaseClientOptions {
|
|
5
|
+
}
|
|
6
|
+
interface GravityService extends grpc.ServiceClientConstructor, IGravityServiceClient {
|
|
7
|
+
}
|
|
8
|
+
export interface GravityProtoClient {
|
|
9
|
+
GravityService: {
|
|
10
|
+
new (address: string, credentials: grpc.ChannelCredentials): GravityService;
|
|
11
|
+
};
|
|
7
12
|
}
|
|
8
|
-
export type GravityTask = IGravityTask;
|
|
9
|
-
export type Crawler = ICrawler;
|
|
10
|
-
export type Dataset = IDataset;
|
|
11
13
|
/**
|
|
12
14
|
* Client for interacting with the Gravity API
|
|
13
15
|
* Provides gRPC interface for data collection and dataset management
|
|
14
16
|
*/
|
|
15
|
-
export declare class GravityClient {
|
|
16
|
-
apiKey: string;
|
|
17
|
-
private baseURL;
|
|
18
|
-
private appName;
|
|
17
|
+
export declare class GravityClient extends BaseClient {
|
|
19
18
|
private protoClient;
|
|
20
|
-
private secure;
|
|
21
19
|
constructor(options: GravityClientOptions);
|
|
22
20
|
private initializeGrpcClient;
|
|
23
21
|
private createGrpcClient;
|
|
@@ -37,13 +37,14 @@ exports.GravityClient = void 0;
|
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
-
const
|
|
40
|
+
const BaseClient_1 = require("../BaseClient");
|
|
41
41
|
/**
|
|
42
42
|
* Client for interacting with the Gravity API
|
|
43
43
|
* Provides gRPC interface for data collection and dataset management
|
|
44
44
|
*/
|
|
45
|
-
class GravityClient {
|
|
45
|
+
class GravityClient extends BaseClient_1.BaseClient {
|
|
46
46
|
constructor(options) {
|
|
47
|
+
super(options);
|
|
47
48
|
/**
|
|
48
49
|
* Lists all data collection tasks for a user
|
|
49
50
|
*/
|
|
@@ -149,19 +150,7 @@ class GravityClient {
|
|
|
149
150
|
});
|
|
150
151
|
});
|
|
151
152
|
};
|
|
152
|
-
this.apiKey = options.apiKey || constants_1.GRAVITY_API_KEY || "";
|
|
153
|
-
this.baseURL = options.baseURL || constants_1.BASE_URL;
|
|
154
|
-
this.appName = options.appName || "unknown";
|
|
155
|
-
// Check environment variable for HTTPS setting
|
|
156
|
-
const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
|
|
157
|
-
// Use secure if explicitly set in options or if HTTPS is enabled via env var
|
|
158
|
-
this.secure = options.secure !== undefined ? options.secure : useHttps;
|
|
159
|
-
// Initialize gRPC client
|
|
160
153
|
this.protoClient = this.initializeGrpcClient();
|
|
161
|
-
// Check if the API key is valid
|
|
162
|
-
if (!this.apiKey) {
|
|
163
|
-
throw new Error("API key is required");
|
|
164
|
-
}
|
|
165
154
|
}
|
|
166
155
|
initializeGrpcClient() {
|
|
167
156
|
// Load proto file directly
|
|
@@ -182,15 +171,16 @@ class GravityClient {
|
|
|
182
171
|
// Create gRPC credentials with API key
|
|
183
172
|
const callCreds = grpc.credentials.createFromMetadataGenerator((_params, callback) => {
|
|
184
173
|
const meta = new grpc.Metadata();
|
|
185
|
-
meta.add("authorization", `Bearer ${this.
|
|
186
|
-
meta.add("x-source", this.
|
|
187
|
-
meta.add("x-client-id",
|
|
188
|
-
meta.add("x-client-version",
|
|
174
|
+
meta.add("authorization", `Bearer ${this.getApiKey()}`);
|
|
175
|
+
meta.add("x-source", this.getAppName());
|
|
176
|
+
meta.add("x-client-id", this.getClientName());
|
|
177
|
+
meta.add("x-client-version", this.getClientVersion());
|
|
178
|
+
meta.add("x-forwarded-user", this.getUserId());
|
|
189
179
|
callback(null, meta);
|
|
190
180
|
});
|
|
191
181
|
// Create credentials based on secure option
|
|
192
182
|
let credentials;
|
|
193
|
-
if (this.
|
|
183
|
+
if (this.isSecure()) {
|
|
194
184
|
// Use secure credentials for production
|
|
195
185
|
const channelCreds = grpc.credentials.createSsl();
|
|
196
186
|
credentials = grpc.credentials.combineChannelCredentials(channelCreds, callCreds);
|
|
@@ -200,7 +190,7 @@ class GravityClient {
|
|
|
200
190
|
credentials = grpc.credentials.createInsecure();
|
|
201
191
|
}
|
|
202
192
|
// Create gRPC client
|
|
203
|
-
return new this.protoClient.GravityService(this.
|
|
193
|
+
return new this.protoClient.GravityService(this.getBaseURL(), credentials);
|
|
204
194
|
}
|
|
205
195
|
}
|
|
206
196
|
exports.GravityClient = GravityClient;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { IListTopicsRequest, IListTopicsResponse, IListTopicsResponseDetail, IValidateRedditTopicRequest, IValidateRedditTopicResponse, ISn13ServiceClient } from "../../generated/sn13/v1/sn13_validator";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
baseURL?: string;
|
|
6
|
-
appName?: string;
|
|
7
|
-
timeout?: number;
|
|
8
|
-
secure?: boolean;
|
|
3
|
+
import { BaseClient, BaseClientOptions } from "../BaseClient";
|
|
4
|
+
interface Sn13ClientOptions extends BaseClientOptions {
|
|
9
5
|
}
|
|
10
6
|
export type ListTopicsRequest = IListTopicsRequest;
|
|
11
7
|
export type ListTopicsResponse = IListTopicsResponse;
|
|
@@ -23,13 +19,8 @@ export interface Sn13ProtoClient {
|
|
|
23
19
|
* Client for interacting with the SN13 API
|
|
24
20
|
* Provides SN13 service interface over gRPC
|
|
25
21
|
*/
|
|
26
|
-
export declare class Sn13Client {
|
|
27
|
-
apiKey: string;
|
|
28
|
-
private baseURL;
|
|
29
|
-
private appName;
|
|
22
|
+
export declare class Sn13Client extends BaseClient {
|
|
30
23
|
private protoClient;
|
|
31
|
-
private defaultTimeout;
|
|
32
|
-
private secure;
|
|
33
24
|
constructor(options: Sn13ClientOptions);
|
|
34
25
|
private initializeGrpcClient;
|
|
35
26
|
private createGrpcClient;
|
package/dist/lib/sn13/Client.js
CHANGED
|
@@ -37,13 +37,14 @@ exports.Sn13Client = void 0;
|
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
-
const
|
|
40
|
+
const BaseClient_1 = require("../BaseClient");
|
|
41
41
|
/**
|
|
42
42
|
* Client for interacting with the SN13 API
|
|
43
43
|
* Provides SN13 service interface over gRPC
|
|
44
44
|
*/
|
|
45
|
-
class Sn13Client {
|
|
45
|
+
class Sn13Client extends BaseClient_1.BaseClient {
|
|
46
46
|
constructor(options) {
|
|
47
|
+
super(options);
|
|
47
48
|
/**
|
|
48
49
|
* List topics from a source
|
|
49
50
|
*/
|
|
@@ -74,20 +75,7 @@ class Sn13Client {
|
|
|
74
75
|
});
|
|
75
76
|
});
|
|
76
77
|
};
|
|
77
|
-
this.apiKey = options.apiKey || constants_1.APEX_API_KEY || "";
|
|
78
|
-
this.baseURL = options.baseURL || constants_1.BASE_URL;
|
|
79
|
-
this.appName = options.appName || "unknown";
|
|
80
|
-
this.defaultTimeout = options.timeout || 60;
|
|
81
|
-
// Check environment variable for HTTPS setting
|
|
82
|
-
const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
|
|
83
|
-
// Use secure if explicitly set in options or if HTTPS is enabled via env var
|
|
84
|
-
this.secure = options.secure !== undefined ? options.secure : useHttps;
|
|
85
|
-
// Initialize gRPC client
|
|
86
78
|
this.protoClient = this.initializeGrpcClient();
|
|
87
|
-
// Check if the API key is valid
|
|
88
|
-
if (!this.apiKey) {
|
|
89
|
-
throw new Error("API key is required");
|
|
90
|
-
}
|
|
91
79
|
}
|
|
92
80
|
initializeGrpcClient() {
|
|
93
81
|
// Load proto file directly
|
|
@@ -108,15 +96,16 @@ class Sn13Client {
|
|
|
108
96
|
// Create gRPC credentials with API key
|
|
109
97
|
const callCreds = grpc.credentials.createFromMetadataGenerator((_params, callback) => {
|
|
110
98
|
const meta = new grpc.Metadata();
|
|
111
|
-
meta.add("authorization", `Bearer ${this.
|
|
112
|
-
meta.add("x-source", this.
|
|
113
|
-
meta.add("x-client-id",
|
|
114
|
-
meta.add("x-client-version",
|
|
99
|
+
meta.add("authorization", `Bearer ${this.getApiKey()}`);
|
|
100
|
+
meta.add("x-source", this.getAppName());
|
|
101
|
+
meta.add("x-client-id", this.getClientName());
|
|
102
|
+
meta.add("x-client-version", this.getClientVersion());
|
|
103
|
+
meta.add("x-forwarded-user", this.getUserId());
|
|
115
104
|
callback(null, meta);
|
|
116
105
|
});
|
|
117
106
|
// Create credentials based on secure option
|
|
118
107
|
let credentials;
|
|
119
|
-
if (this.
|
|
108
|
+
if (this.isSecure()) {
|
|
120
109
|
// Use secure credentials for production
|
|
121
110
|
const channelCreds = grpc.credentials.createSsl();
|
|
122
111
|
credentials = grpc.credentials.combineChannelCredentials(channelCreds, callCreds);
|
|
@@ -126,7 +115,7 @@ class Sn13Client {
|
|
|
126
115
|
credentials = grpc.credentials.createInsecure();
|
|
127
116
|
}
|
|
128
117
|
// Create gRPC client
|
|
129
|
-
return new this.protoClient.Sn13Service(this.
|
|
118
|
+
return new this.protoClient.Sn13Service(this.getBaseURL(), credentials);
|
|
130
119
|
}
|
|
131
120
|
}
|
|
132
121
|
exports.Sn13Client = Sn13Client;
|
package/new_version.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.2.2
|
package/old_version.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.2.1
|