Repository: Azure/azure-functions-durable-js (ts)

Issue:
Leverage the HttpRequest and HttpResponse classes from `@azure/functions`
Let's get rid of the `IHttpRequest` and `IHttpRespones` classes in this SDK, and instead rely on the `HttpRequest` and `HttpResponse` classes provided by `@azure/functions`. 

This means that `client.createCheckStatusResponse()` and `client.waitForCompletionOrCreateCheckStatusResponse()` should both accept an `HttpRequest` object, and return an `HttpResponse` object. 

While technically a breaking change, this is actually helpful in most cases, because `HttpRequest` is the type of trigger input received by HTTP-triggered functions anyway, and most functions just pass the result of those API back to the Functions library, which also now expects an `HttpResponse` object

Pull request description:
Remove IHttpRequest and IHttpResponse interfaces
Resolves #454. This PR removes the `IHttpResponse` and `IHttpRequest` object, and instead relies on the `HttpResponse` and `HttpRequest` objects from `@azure/functions` (respectively). Since this affects the type signatures of public APIs, this _is_ a breaking change, but we discussed offline, and we decided this is a breaking change worth pursuing. In most cases, this should actually _help_ customers, since the expected `HttpRequest` argument to APIs is usually the request object given to the client functions (which now has `HttpRequest` type), and the `HttpResponse` type is usually passed as the return value of the function, which now is expected to be `HttpResponse`. I'm not sure why the `IHttpResponse` and `IHttpRequest` types were honored/respected before, but I've removed the checks/tests related to that as well. 

Patch:
diff --git a/src/classes.ts b/src/classes.ts
index ab6a60a..0ba8cc3 100644
--- a/src/classes.ts
+++ b/src/classes.ts
@@ -50,9 +50,6 @@ export { OrchestrationClientInputData } from "./orchestrationclientinputdata";
 export { HttpCreationPayload } from "./httpcreationpayload";
 export { HttpManagementPayload } from "./httpmanagementpayload";
 
-export { IHttpRequest } from "./ihttprequest";
-export { IHttpResponse } from "./ihttpresponse";
-
 export { DurableOrchestrationStatus } from "./durableorchestrationstatus";
 export { OrchestrationRuntimeStatus } from "./orchestrationruntimestatus";
 export { PurgeHistoryResult } from "./purgehistoryresult";
diff --git a/src/durableorchestrationclient.ts b/src/durableorchestrationclient.ts
index 7a82071..0eb88d0 100644
--- a/src/durableorchestrationclient.ts
+++ b/src/durableorchestrationclient.ts
@@ -16,8 +16,6 @@ import {
     EntityStateResponse,
     HttpCreationPayload,
     HttpManagementPayload,
-    IHttpRequest,
-    IHttpResponse,
     OrchestrationClientInputData,
     OrchestrationRuntimeStatus,
     PurgeHistoryResult,
@@ -175,7 +173,7 @@ export class DurableOrchestrationClient {
      *  containing instance management URLs.
      */
     public createCheckStatusResponse(
-        request: IHttpRequest | HttpRequest | undefined,
+        request: HttpRequest | undefined,
         instanceId: string
     ): HttpResponse {
         const httpManagementPayload = this.getClientResponseLinks(request, instanceId);
@@ -745,7 +743,7 @@ export class DurableOrchestrationClient {
         instanceId: string,
         timeoutInMilliseconds = 10000,
         retryIntervalInMilliseconds = 1000
-    ): Promise<IHttpResponse> {
+    ): Promise<HttpResponse> {
         if (retryIntervalInMilliseconds > timeoutInMilliseconds) {
             throw new Error(
                 `Total timeout ${timeoutInMilliseconds} (ms) should be bigger than retry timeout ${retryIntervalInMilliseconds} (ms)`
@@ -784,19 +782,19 @@ export class DurableOrchestrationClient {
         }
     }
 
-    private createHttpResponse(statusCode: number, body: unknown): IHttpResponse {
+    private createHttpResponse(statusCode: number, body: unknown): HttpResponse {
         const bodyAsJson = JSON.stringify(body);
-        return {
+        return new HttpResponse({
             status: statusCode,
-            body: bodyAsJson,
+            jsonBody: bodyAsJson,
             headers: {
                 "Content-Type": "application/json",
             },
-        };
+        });
     }
 
     private getClientResponseLinks(
-        request: IHttpRequest | HttpRequest | undefined,
+        request: HttpRequest | undefined,
         instanceId: string
     ): HttpManagementPayload {
         const payload = { ...this.clientData.managementUrls };
@@ -806,9 +804,7 @@ export class DurableOrchestrationClient {
                 this.hasValidRequestUrl(request) &&
                 isURL(payload[key], this.urlValidationOptions)
             ) {
-                const requestUrl = new url.URL(
-                    (request as HttpRequest).url || (request as IHttpRequest).http.url
-                );
+                const requestUrl = new url.URL((request as HttpRequest).url);
                 const dataUrl = new url.URL(payload[key]);
                 payload[key] = payload[key].replace(dataUrl.origin, requestUrl.origin);
             }
@@ -819,13 +815,8 @@ export class DurableOrchestrationClient {
         return payload;
     }
 
-    private hasValidRequestUrl(request: IHttpRequest | HttpRequest | undefined): boolean {
-        const isHttpRequest = request !== undefined && (request as HttpRequest).url !== undefined;
-        const isIHttpRequest =
-            request !== undefined && (request as IHttpRequest).http !== undefined;
-        return (
-            isHttpRequest || (isIHttpRequest && (request as IHttpRequest).http.url !== undefined)
-        );
+    private hasValidRequestUrl(request: HttpRequest | undefined): boolean {
+        return request !== undefined && (request as HttpRequest).url !== undefined;
     }
 
     private extractUniqueWebhookOrigins(clientData: OrchestrationClientInputData): string[] {
diff --git a/src/ihttprequest.ts b/src/ihttprequest.ts
deleted file mode 100644
index 587bfbe..0000000
--- a/src/ihttprequest.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface IHttpRequest {
-    http: {
-        url: string;
-    };
-}
diff --git a/src/ihttpresponse.ts b/src/ihttpresponse.ts
deleted file mode 100644
index 47cc082..0000000
--- a/src/ihttpresponse.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface IHttpResponse {
-    status: number;
-    body: unknown;
-    headers?: object;
-}


Test patch:
diff --git a/test/unit/orchestrationclient-spec.ts b/test/unit/orchestrationclient-spec.ts
index 96066bf..7838a38 100644
--- a/test/unit/orchestrationclient-spec.ts
+++ b/test/unit/orchestrationclient-spec.ts
@@ -90,32 +90,6 @@ describe("Orchestration Client", () => {
             expect(response.headers.get("Retry-After")).to.equal("10");
         });
 
-        it(`returns a proper response object from request.http.url`, async () => {
-            const client = new DurableOrchestrationClient(defaultClientInputData);
-            const requestObj = {
-                http: {
-                    url: defaultRequestUrl,
-                    method: "GET",
-                },
-            };
-
-            const response = client.createCheckStatusResponse(requestObj, defaultInstanceId);
-            const responseBody = await response.json();
-
-            const expectedPayload = TestUtils.createHttpManagementPayload(
-                defaultInstanceId,
-                Constants.DefaultLocalOrigin,
-                defaultTaskHub,
-                defaultConnection
-            );
-
-            expect(response.status).to.equal(202);
-            expect(responseBody).to.deep.equal(expectedPayload);
-            expect(response.headers.get("Content-Type")).to.equal("application/json");
-            expect(response.headers.get("Location")).to.equal(expectedPayload.statusQueryGetUri);
-            expect(response.headers.get("Retry-After")).to.equal("10");
-        });
-
         it("returns a proper response object when request is undefined", async () => {
             const client = new DurableOrchestrationClient(defaultClientInputData);
 
@@ -1160,21 +1134,17 @@ describe("Orchestration Client", () => {
 
             nock(Constants.DefaultLocalOrigin).get(/.*/).reply(202, expectedStatus);
 
-            const expectedResponse = {
-                status: 200,
-                body: JSON.stringify(expectedOutput),
-                headers: {
-                    "Content-Type": "application/json",
-                },
-            };
-
             const res = await client.waitForCompletionOrCreateCheckStatusResponse(
                 defaultRequest,
                 defaultInstanceId,
                 defaultTimeout,
                 defaultInterval
             );
-            expect(res).to.be.deep.equal(expectedResponse);
+
+            const body = await res.json();
+            expect(res.status).to.equal(200);
+            expect(body).to.equal(JSON.stringify(expectedOutput));
+            expect(res.headers.get("Content-Type")).to.equal("application/json");
         });
 
         it("returns expected result for canceled instance", async () => {
@@ -1193,13 +1163,6 @@ describe("Orchestration Client", () => {
             nock(Constants.DefaultLocalOrigin).get(/.*/).reply(202, expectedStatus);
 
             const expectedStatusAsJson = JSON.stringify(expectedStatus);
-            const expectedResponse = {
-                status: 200,
-                body: expectedStatusAsJson,
-                headers: {
-                    "Content-Type": "application/json",
-                },
-            };
 
             const res = await client.waitForCompletionOrCreateCheckStatusResponse(
                 defaultRequest,
@@ -1207,7 +1170,11 @@ describe("Orchestration Client", () => {
                 defaultTimeout,
                 defaultInterval
             );
-            expect(res).to.be.deep.equal(expectedResponse);
+
+            const body = await res.json();
+            expect(res.status).to.equal(200);
+            expect(body).to.equal(expectedStatusAsJson);
+            expect(res.headers.get("Content-Type")).to.equal("application/json");
         });
 
         it("returns expected result for terminated instance", async () => {
@@ -1226,13 +1193,6 @@ describe("Orchestration Client", () => {
             nock(Constants.DefaultLocalOrigin).get(/.*/).reply(202, expectedStatus);
 
             const expectedStatusAsJson = JSON.stringify(expectedStatus);
-            const expectedResponse = {
-                status: 200,
-                body: expectedStatusAsJson,
-                headers: {
-                    "Content-Type": "application/json",
-                },
-            };
 
             const res = await client.waitForCompletionOrCreateCheckStatusResponse(
                 defaultRequest,
@@ -1240,7 +1200,11 @@ describe("Orchestration Client", () => {
                 defaultTimeout,
                 defaultInterval
             );
-            expect(res).to.be.deep.equal(expectedResponse);
+
+            const body = await res.json();
+            expect(res.status).to.equal(200);
+            expect(body).to.equal(expectedStatusAsJson);
+            expect(res.headers.get("Content-Type")).to.equal("application/json");
         });
 
         it("returns expected result for failed instance", async () => {
@@ -1259,13 +1223,6 @@ describe("Orchestration Client", () => {
             nock(Constants.DefaultLocalOrigin).get(/.*/).reply(202, expectedStatus);
 
             const expectedStatusAsJson = JSON.stringify(expectedStatus);
-            const expectedResponse = {
-                status: 500,
-                body: expectedStatusAsJson,
-                headers: {
-                    "Content-Type": "application/json",
-                },
-            };
 
             const res = await client.waitForCompletionOrCreateCheckStatusResponse(
                 defaultRequest,
@@ -1273,7 +1230,11 @@ describe("Orchestration Client", () => {
                 defaultTimeout,
                 defaultInterval
             );
-            expect(res).to.be.deep.equal(expectedResponse);
+
+            const body = await res.json();
+            expect(res.status).to.equal(500);
+            expect(body).to.equal(expectedStatusAsJson);
+            expect(res.headers.get("Content-Type")).to.equal("application/json");
         });
 
         it("continues polling for running instance", async () => {
@@ -1318,21 +1279,17 @@ describe("Orchestration Client", () => {
                     "Content-Type": "application/json",
                 });
 
-            const expectedResponse = {
-                status: 200,
-                body: JSON.stringify(expectedOutput),
-                headers: {
-                    "Content-Type": "application/json",
-                },
-            };
-
             const res = await client.waitForCompletionOrCreateCheckStatusResponse(
                 defaultRequest,
                 defaultInstanceId,
                 defaultTimeout,
                 defaultInterval
             );
-            expect(res).to.be.deep.equal(expectedResponse);
+
+            const body = await res.json();
+            expect(res.status).to.equal(200);
+            expect(body).to.equal(JSON.stringify(expectedOutput));
+            expect(res.headers.get("Content-Type")).to.equal("application/json");
             expect(scope.isDone()).to.be.equal(true);
         });