Skip to content

Commit 05dba30

Browse files
Added js doc comments
1 parent 2b4377c commit 05dba30

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

spec/middleware/TelemetryHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe("TelemetryHandler.ts", () => {
8383
it("Should set sdk version header with feature flag", async () => {
8484
try {
8585
const telemetryOptions = new TelemetryHandlerOptions();
86-
telemetryOptions.setFeatureUsage(FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
86+
telemetryOptions["setFeatureUsage"](FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
8787
const context: Context = {
8888
request: "url",
8989
options: {

spec/middleware/TelemetryHandlerOptions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ describe("TelemetryHandlerOptions.ts", () => {
5454
describe("setFeatureUsage", () => {
5555
it("Should set a given flags", () => {
5656
const telemetryOptions = new TelemetryHandlerOptions();
57-
telemetryOptions.setFeatureUsage(FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
58-
telemetryOptions.setFeatureUsage(FeatureUsageFlag.RETRY_HANDLER_ENABLED);
57+
telemetryOptions["setFeatureUsage"](FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
58+
telemetryOptions["setFeatureUsage"](FeatureUsageFlag.RETRY_HANDLER_ENABLED);
5959
assert.equal(telemetryOptions["featureUsage"] & FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
6060
assert.equal(telemetryOptions["featureUsage"] & FeatureUsageFlag.RETRY_HANDLER_ENABLED, FeatureUsageFlag.RETRY_HANDLER_ENABLED);
6161
assert.equal(telemetryOptions["featureUsage"] & FeatureUsageFlag.REDIRECT_HANDLER_ENABLED, FeatureUsageFlag.NONE);
6262
});
6363
});
64-
/* tslint:enable: no-string-literal no-bitwise*/
6564

6665
describe("getFeatureUsage", () => {
6766
it("Should return the feature usage in hexadecimal string", () => {
6867
const telemetryOptions = new TelemetryHandlerOptions();
69-
telemetryOptions.setFeatureUsage(FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
70-
telemetryOptions.setFeatureUsage(FeatureUsageFlag.RETRY_HANDLER_ENABLED);
68+
telemetryOptions["setFeatureUsage"](FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
69+
telemetryOptions["setFeatureUsage"](FeatureUsageFlag.RETRY_HANDLER_ENABLED);
7170
const usageFlag = telemetryOptions.getFeatureUsage();
7271
assert.equal(usageFlag, "6");
7372
});
7473
});
74+
/* tslint:enable: no-string-literal no-bitwise*/
7575
});

src/middleware/MiddlewareControl.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ export class MiddlewareControl {
4040
/**
4141
* @public
4242
* To get the middleware option using the class name of the option
43-
* @param {string} name - The class name of the strongly types option class
43+
* @param {string} name - The class name of the strongly typed option class
4444
* @returns The middleware option
4545
*/
4646
public getMiddlewareOptions(name: string): MiddlewareOptions {
4747
return this.middlewareOptions.get(name);
4848
}
4949

50+
/**
51+
* @public
52+
* To set the middleware options using the class name of the option
53+
* @param {string} name - The class name of the strongly typed option class
54+
* @param {MiddlewareOptions} option - The strongly typed middleware option
55+
* @returns nothing
56+
*/
5057
public setMiddlewareOptions(name: string, option: MiddlewareOptions): void {
5158
this.middlewareOptions.set(name, option);
5259
}

src/middleware/TelemetryHandler.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,32 @@ import { TelemetryHandlerOptions } from "./options/TelemetryHandlerOptions";
2323
* Class for TelemetryHandler
2424
*/
2525
export class TelemetryHandler implements Middleware {
26+
/**
27+
* @private
28+
* @static
29+
* A member holding the name of the client request id header
30+
*/
2631
private static CLIENT_REQUEST_ID_HEADER = "client-request-id";
2732

33+
/**
34+
* @private
35+
* @static
36+
* A member holding the name of the sdk version header
37+
*/
2838
private static SDK_VERSION_HEADER = "SdkVersion";
2939

40+
/**
41+
* @private
42+
* @static
43+
* A member holding the language prefix for the sdk version header value
44+
*/
3045
private static PRODUCT_NAME = "graph-js";
3146

47+
/**
48+
* @private
49+
* @static
50+
* A member holding the key for the feature usage metrics
51+
*/
3252
private static FEATURE_USAGE_STRING = "featureUsage";
3353

3454
/**

src/middleware/options/TelemetryHandlerOptions.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import { MiddlewareControl } from "../MiddlewareControl";
1414

1515
import { MiddlewareOptions } from "./IMiddlewareOptions";
1616

17+
/**
18+
* @enum
19+
* @property {number} NONE - The hexadecimal flag value for nothing enabled
20+
* @property {number} REDIRECT_HANDLER_ENABLED - The hexadecimal flag value for redirect handler enabled
21+
* @property {number} RETRY_HANDLER_ENABLED - The hexadecimal flag value for retry handler enabled
22+
* @property {number} AUTHENTICATION_HANDLER_ENABLED - The hexadecimal flag value for the authentication handler enabled
23+
*/
1724
export enum FeatureUsageFlag {
1825
NONE = 0x0,
1926
REDIRECT_HANDLER_ENABLED = 0x1,
@@ -28,8 +35,20 @@ export enum FeatureUsageFlag {
2835
*/
2936

3037
export class TelemetryHandlerOptions implements MiddlewareOptions {
38+
/**
39+
* @private
40+
* A member to hold the OR of feature usage flags
41+
*/
3142
private featureUsage: FeatureUsageFlag = FeatureUsageFlag.NONE;
3243

44+
/**
45+
* @public
46+
* @static
47+
* To update the feature usage in the context object
48+
* @param {Context} context - The request context object containing middleware options
49+
* @param {FeatureUsageFlag} flag - The flag value
50+
* @returns nothing
51+
*/
3352
public static updateFeatureUsageFlag(context: Context, flag: FeatureUsageFlag): void {
3453
let options: TelemetryHandlerOptions;
3554
if (context.middlewareControl instanceof MiddlewareControl) {
@@ -44,12 +63,23 @@ export class TelemetryHandlerOptions implements MiddlewareOptions {
4463
options.setFeatureUsage(flag);
4564
}
4665

47-
public setFeatureUsage(flag: FeatureUsageFlag): void {
66+
/**
67+
* @private
68+
* To set the feature usage flag
69+
* @param {FeatureUsageFlag} flag - The flag value
70+
* @returns nothing
71+
*/
72+
private setFeatureUsage(flag: FeatureUsageFlag): void {
4873
/* tslint:disable: no-bitwise */
4974
this.featureUsage = this.featureUsage | flag;
5075
/* tslint:enable: no-bitwise */
5176
}
5277

78+
/**
79+
* @public
80+
* To get the feature usage
81+
* @returns A feature usage flag as hexadecimal string
82+
*/
5383
public getFeatureUsage(): string {
5484
return this.featureUsage.toString(16);
5585
}

0 commit comments

Comments
 (0)