@superfaceai/one-sdk
Advanced tools
Comparing version 3.0.0-beta.12 to 3.0.0-beta.13
@@ -7,6 +7,9 @@ import { Asyncify } from './asyncify.js'; | ||
constructor(stream) { | ||
this.reader = stream.getReader(); | ||
this.reader = stream?.getReader(); | ||
this.chunks = []; | ||
} | ||
async read(out) { | ||
if (this.reader === undefined) { | ||
return 0; | ||
} | ||
if (this.chunks.length === 0) { | ||
@@ -244,3 +247,3 @@ const readResult = await this.reader.read(); | ||
const response = await this.requests.remove(message.handle); | ||
const bodyStream = new ReadableStreamAdapter(response.body); // TODO: handle when they are missing | ||
const bodyStream = new ReadableStreamAdapter(response.body); | ||
return { kind: 'ok', status: response.status, headers: headersToMultimap(response.headers), body_stream: this.streams.insert(bodyStream) }; | ||
@@ -247,0 +250,0 @@ } |
@@ -18,3 +18,9 @@ import { SecurityValuesMap } from './common/index.js'; | ||
*/ | ||
superfaceApiUrl?: string; | ||
superfaceApiUrl?: string | false; | ||
/** | ||
* Whether to register `beforeExit` hook to call `OneClient.destroy()`. | ||
* | ||
* Default: `true` | ||
*/ | ||
onBeforeExitHook?: boolean; | ||
}; | ||
@@ -38,3 +44,3 @@ export type ClientPerformOptions = { | ||
resolveProviderUrl(provider: string): Promise<string>; | ||
private initProcessHooks; | ||
sendMetrics(): Promise<void>; | ||
private get userAgent(); | ||
@@ -49,2 +55,3 @@ } | ||
getProfile(name: string): Promise<Profile>; | ||
sendMetricsToSuperface(): Promise<void>; | ||
} | ||
@@ -51,0 +58,0 @@ export declare class Profile { |
@@ -120,10 +120,16 @@ import fs from 'node:fs/promises'; | ||
this.userAgent = userAgent; | ||
if (superfaceApiUrl !== undefined) { | ||
this.insightsUrl = `${superfaceApiUrl}/insights/sdk_event`; | ||
if (superfaceApiUrl === false) { | ||
this.insightsUrl = false; | ||
} | ||
else { | ||
else if (superfaceApiUrl === undefined) { | ||
this.insightsUrl = 'https://superface.ai/insights/sdk_event'; | ||
} | ||
else { | ||
this.insightsUrl = `${superfaceApiUrl}/insights/sdk_event`; | ||
} | ||
} | ||
async persistMetrics(events) { | ||
if (this.insightsUrl === false) { | ||
return; | ||
} | ||
const headers = { | ||
@@ -142,3 +148,3 @@ 'content-type': 'application/json', | ||
headers | ||
}); | ||
}).catch(err => console.error("Failed to send metrics", err)); | ||
} | ||
@@ -167,2 +173,7 @@ async persistDeveloperDump(events) { | ||
}, { metricsTimeout: 1000, userAgent: this.userAgent }); | ||
if (options.onBeforeExitHook !== false) { | ||
process.once('beforeExit', async () => { | ||
await this.destroy(); | ||
}); | ||
} | ||
} | ||
@@ -181,3 +192,2 @@ async init() { | ||
})); // TODO: node typings do not include version https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/wasi.d.ts#L68-L110 | ||
this.initProcessHooks(); | ||
readyState.ready = true; | ||
@@ -225,6 +235,4 @@ }); | ||
} | ||
initProcessHooks() { | ||
process.on('beforeExit', async () => { | ||
await this.destroy(); | ||
}); | ||
async sendMetrics() { | ||
await this.app.sendMetrics(); | ||
} | ||
@@ -253,2 +261,5 @@ get userAgent() { | ||
} | ||
async sendMetricsToSuperface() { | ||
await this.internal.sendMetrics(); | ||
} | ||
} | ||
@@ -255,0 +266,0 @@ export class Profile { |
{ | ||
"name": "@superfaceai/one-sdk", | ||
"version": "3.0.0-beta.12", | ||
"version": "3.0.0-beta.13", | ||
"exports": { | ||
@@ -5,0 +5,0 @@ ".": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5278303
1442