diff --git a/packages/abstractions/package.json b/packages/abstractions/package.json index 7600859e62..7894c5f210 100644 --- a/packages/abstractions/package.json +++ b/packages/abstractions/package.json @@ -1,6 +1,6 @@ { "name": "@microsoft/kiota-abstractions", - "version": "1.0.0-preview.2", + "version": "1.0.0-preview.3", "description": "Core abstractions for kiota generated libraries in TypeScript and JavaScript", "main": "dist/cjs/src/index.js", "files": [ diff --git a/packages/abstractions/src/commonRequestConfiguration.ts b/packages/abstractions/src/commonRequestConfiguration.ts new file mode 100644 index 0000000000..d774ddf2b4 --- /dev/null +++ b/packages/abstractions/src/commonRequestConfiguration.ts @@ -0,0 +1,9 @@ +import { RequestOption } from "./requestOption"; + +/** Configuration for the request such as headers, query parameters, and middleware options. */ +export class CommonRequestConfiguration { + /** Request headers */ + public headers?: Record | undefined; + /** Request options */ + public options?: RequestOption[] | undefined; +} diff --git a/packages/abstractions/src/index.ts b/packages/abstractions/src/index.ts index 33e1f86925..d0085405c3 100644 --- a/packages/abstractions/src/index.ts +++ b/packages/abstractions/src/index.ts @@ -2,6 +2,7 @@ export * from "./apiClientBuilder"; export * from "./apiError"; export * from "./authentication"; export * from "./dateOnly"; +export * from "./commonRequestConfiguration"; export * from "./duration"; export * from "./getPathParameters"; export * from "./httpMethod"; diff --git a/packages/abstractions/src/requestInformation.ts b/packages/abstractions/src/requestInformation.ts index 3b7426fed6..f098266894 100644 --- a/packages/abstractions/src/requestInformation.ts +++ b/packages/abstractions/src/requestInformation.ts @@ -69,7 +69,15 @@ export class RequestInformation { public getRequestOptions() { return this._requestOptions; } - public addRequestOptions(...options: RequestOption[]) { + /** Adds the headers for the request. */ + public addRequestHeaders(source: Record | undefined) { + if (!source) return; + for (const key in source) { + this.headers[key] = source[key]; + } + } + /** Adds the request options for the request. */ + public addRequestOptions(options: RequestOption[] | undefined) { if (!options || options.length === 0) return; options.forEach((option) => { this._requestOptions[option.getKey()] = option; @@ -129,7 +137,10 @@ export class RequestInformation { * Sets the query string parameters from a raw object. * @param parameters the parameters. */ - public setQueryStringParametersFromRawObject = (q: object): void => { + public setQueryStringParametersFromRawObject = ( + q: object | undefined + ): void => { + if (!q) return; Object.entries(q).forEach(([k, v]) => { let key = k; if ((q as any).getQueryParameter) { diff --git a/packages/abstractions/test/common/requestInformation.ts b/packages/abstractions/test/common/requestInformation.ts index 2d87a64c95..6dcb09202d 100644 --- a/packages/abstractions/test/common/requestInformation.ts +++ b/packages/abstractions/test/common/requestInformation.ts @@ -12,23 +12,22 @@ const assert = chai.assert; import { RequestInformation } from "../../src"; -class GetQueryParameters -{ - select?: string[]; - count?: boolean; - filter?: string; - orderby?: string[]; - search?: string; - getQueryParameter(originalName:string) : string { - switch(originalName.toLowerCase()) { - case 'select': return '%24select'; - case 'count': return '%24count'; - case 'filter': return '%24filter'; - case 'orderby': return '%24orderby'; - case 'search': return '%24search'; - default: return originalName; - } +class GetQueryParameters { + select?: string[]; + count?: boolean; + filter?: string; + orderby?: string[]; + search?: string; + getQueryParameter(originalName: string): string { + switch (originalName.toLowerCase()) { + case 'select': return '%24select'; + case 'count': return '%24count'; + case 'filter': return '%24filter'; + case 'orderby': return '%24orderby'; + case 'search': return '%24search'; + default: return originalName; } + } } describe("RequestInformation", () => { @@ -54,4 +53,14 @@ describe("RequestInformation", () => { assert.equal(requestInformation.URL, "http://localhost/me?%24select=id,displayName"); }); + + it("Adds headers to requestInformation", () => { + const requestInformation = new RequestInformation(); + requestInformation.pathParameters["baseurl"] = baseUrl; + requestInformation.urlTemplate = "http://localhost/me{?%24select}"; + const headers: Record = { ConsistencyLevel: "eventual" }; + requestInformation.addRequestHeaders(headers); + assert.isNotEmpty(requestInformation.headers); + assert.equal("eventual", requestInformation.headers["ConsistencyLevel"]); + }); }); diff --git a/packages/test/generatedCode/models/microsoft/graph/index.ts b/packages/test/generatedCode/models/microsoft/graph/index.ts index 15f61d988e..e04c0e0b6a 100644 --- a/packages/test/generatedCode/models/microsoft/graph/index.ts +++ b/packages/test/generatedCode/models/microsoft/graph/index.ts @@ -1,20 +1,20 @@ export * from './entity' export * from './outlookItem' -export * from './emailAddress' -export * from './followupFlag' -export * from './itemBody' -export * from './inferenceClassificationOverride' export * from './message' +export * from './singleValueLegacyExtendedProperty' export * from './messageRuleActions' -export * from './inferenceClassification' -export * from './messageRule' +export * from './recipient' +export * from './extension' +export * from './dateTimeTimeZone' +export * from './mailFolder' export * from './attachment' -export * from './singleValueLegacyExtendedProperty' -export * from './internetMessageHeader' +export * from './followupFlag' +export * from './itemBody' +export * from './messageRulePredicates' export * from './sizeRange' +export * from './messageRule' export * from './multiValueLegacyExtendedProperty' -export * from './mailFolder' -export * from './recipient' -export * from './messageRulePredicates' -export * from './dateTimeTimeZone' -export * from './extension' +export * from './inferenceClassificationOverride' +export * from './internetMessageHeader' +export * from './inferenceClassification' +export * from './emailAddress' diff --git a/packages/test/package.json b/packages/test/package.json index bac162cc7e..d2f371b0d0 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "@azure/identity": "2.0.4", - "@microsoft/kiota-abstractions": "1.0.0-preview.2", + "@microsoft/kiota-abstractions": "1.0.0-preview.3", "@microsoft/kiota-authentication-azure": "1.0.0-preview.1", "@microsoft/kiota-http-fetchlibrary": "1.0.0-preview.2", "@microsoft/kiota-serialization-json": "1.0.0-preview.2",