graphlit-client 1.0.20251222001 → 1.0.20251222003
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/client.d.ts +8 -0
- package/dist/client.js +38 -17
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface GraphlitClientOptions {
|
|
|
26
26
|
ownerId?: string;
|
|
27
27
|
userId?: string;
|
|
28
28
|
apiUri?: string;
|
|
29
|
+
/** Pre-signed JWT token. When provided, jwtSecret is not required. */
|
|
30
|
+
token?: string;
|
|
29
31
|
/** Retry configuration for network errors */
|
|
30
32
|
retryConfig?: RetryConfig;
|
|
31
33
|
}
|
|
@@ -50,7 +52,13 @@ declare class Graphlit {
|
|
|
50
52
|
private deepseekClient?;
|
|
51
53
|
private xaiClient?;
|
|
52
54
|
constructor(organizationIdOrOptions?: string | GraphlitClientOptions, environmentId?: string, jwtSecret?: string, ownerId?: string, userId?: string, apiUri?: string);
|
|
55
|
+
/**
|
|
56
|
+
* Initialize the Apollo client without regenerating the token.
|
|
57
|
+
* Used when a pre-signed token is provided.
|
|
58
|
+
*/
|
|
59
|
+
private initializeClient;
|
|
53
60
|
refreshClient(): void;
|
|
61
|
+
private setupApolloClient;
|
|
54
62
|
/**
|
|
55
63
|
* Set a custom OpenAI client instance for streaming
|
|
56
64
|
* @param client - OpenAI client instance (e.g., new OpenAI({ apiKey: "..." }))
|
package/dist/client.js
CHANGED
|
@@ -209,33 +209,54 @@ class Graphlit {
|
|
|
209
209
|
jitter: true,
|
|
210
210
|
...options.retryConfig,
|
|
211
211
|
};
|
|
212
|
-
if
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
212
|
+
// Skip all validation if pre-signed token is provided
|
|
213
|
+
if (!options.token) {
|
|
214
|
+
if (!this.organizationId) {
|
|
215
|
+
throw new Error("Graphlit organization identifier is required.");
|
|
216
|
+
}
|
|
217
|
+
if (!isValidGuid(this.organizationId)) {
|
|
218
|
+
throw new Error(`Invalid organization ID format. Expected a valid GUID, but received: '${this.organizationId}'. ` +
|
|
219
|
+
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
|
|
220
|
+
}
|
|
221
|
+
if (!this.environmentId) {
|
|
222
|
+
throw new Error("Graphlit environment identifier is required.");
|
|
223
|
+
}
|
|
224
|
+
if (!isValidGuid(this.environmentId)) {
|
|
225
|
+
throw new Error(`Invalid environment ID format. Expected a valid GUID, but received: '${this.environmentId}'. ` +
|
|
226
|
+
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
|
|
227
|
+
}
|
|
228
|
+
if (!this.jwtSecret) {
|
|
229
|
+
throw new Error("Graphlit environment JWT secret is required.");
|
|
230
|
+
}
|
|
228
231
|
}
|
|
229
232
|
// Validate optional userId if provided (ownerId can be any format)
|
|
230
233
|
if (this.userId && !isValidGuid(this.userId)) {
|
|
231
234
|
throw new Error(`Invalid user ID format. Expected a valid GUID, but received: '${this.userId}'. ` +
|
|
232
235
|
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
|
|
233
236
|
}
|
|
234
|
-
|
|
237
|
+
// If a pre-signed token is provided, use it directly instead of generating one
|
|
238
|
+
if (options.token) {
|
|
239
|
+
this.token = options.token;
|
|
240
|
+
this.initializeClient();
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.refreshClient();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Initialize the Apollo client without regenerating the token.
|
|
248
|
+
* Used when a pre-signed token is provided.
|
|
249
|
+
*/
|
|
250
|
+
initializeClient() {
|
|
251
|
+
this.client = undefined;
|
|
252
|
+
this.setupApolloClient();
|
|
235
253
|
}
|
|
236
254
|
refreshClient() {
|
|
237
255
|
this.client = undefined;
|
|
238
256
|
this.generateToken();
|
|
257
|
+
this.setupApolloClient();
|
|
258
|
+
}
|
|
259
|
+
setupApolloClient() {
|
|
239
260
|
const httpLink = createHttpLink({
|
|
240
261
|
uri: this.apiUri,
|
|
241
262
|
});
|