UNPKG

1.85 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3import { isNode, } from "@azure/core-http";
4import * as os from "os";
5import { TelemetryPolicy } from "./policies/TelemetryPolicy";
6import { SDK_VERSION } from "./utils/constants";
7/**
8 * TelemetryPolicyFactory is a factory class helping generating {@link TelemetryPolicy} objects.
9 */
10export class TelemetryPolicyFactory {
11 /**
12 * Creates an instance of TelemetryPolicyFactory.
13 * @param telemetry -
14 */
15 constructor(telemetry) {
16 const userAgentInfo = [];
17 if (isNode) {
18 if (telemetry) {
19 const telemetryString = telemetry.userAgentPrefix || "";
20 if (telemetryString.length > 0 && userAgentInfo.indexOf(telemetryString) === -1) {
21 userAgentInfo.push(telemetryString);
22 }
23 }
24 // e.g. azsdk-js-storageblob/10.0.0
25 const libInfo = `azsdk-js-storageblob/${SDK_VERSION}`;
26 if (userAgentInfo.indexOf(libInfo) === -1) {
27 userAgentInfo.push(libInfo);
28 }
29 // e.g. (NODE-VERSION 4.9.1; Windows_NT 10.0.16299)
30 let runtimeInfo = `(NODE-VERSION ${process.version})`;
31 if (os) {
32 runtimeInfo = `(NODE-VERSION ${process.version}; ${os.type()} ${os.release()})`;
33 }
34 if (userAgentInfo.indexOf(runtimeInfo) === -1) {
35 userAgentInfo.push(runtimeInfo);
36 }
37 }
38 this.telemetryString = userAgentInfo.join(" ");
39 }
40 /**
41 * Creates a TelemetryPolicy object.
42 *
43 * @param nextPolicy -
44 * @param options -
45 */
46 create(nextPolicy, options) {
47 return new TelemetryPolicy(nextPolicy, options, this.telemetryString);
48 }
49}
50//# sourceMappingURL=TelemetryPolicyFactory.js.map
\No newline at end of file