Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/kiota-http-fetchlibrary

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/kiota-http-fetchlibrary - npm Package Compare versions

Comparing version 1.0.0-preview.6 to 1.0.0-preview.7

dist/cjs/test/common/fetchRequestAdapter.d.ts

2

dist/cjs/src/fetchRequestAdapter.d.ts

@@ -32,2 +32,4 @@ import { AuthenticationProvider, BackingStoreFactory, Parsable, ParsableFactory, ParseNodeFactory, RequestAdapter, RequestInformation, ResponseHandler, SerializationWriterFactory } from "@microsoft/kiota-abstractions";

private getHttpResponseMessage;
private retryCAEResponseIfRequired;
private getClaimsFromResponse;
private setBaseUrlForRequestInformation;

@@ -34,0 +36,0 @@ private getRequestFromRequestInformation;

@@ -235,3 +235,3 @@ "use strict";

});
this.getHttpResponseMessage = (requestInfo) => tslib_1.__awaiter(this, void 0, void 0, function* () {
this.getHttpResponseMessage = (requestInfo, claims) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!requestInfo) {

@@ -241,6 +241,36 @@ throw new Error("requestInfo cannot be null");

this.setBaseUrlForRequestInformation(requestInfo);
yield this.authenticationProvider.authenticateRequest(requestInfo);
const additionalContext = {};
if (claims) {
additionalContext["claims"] = claims;
}
yield this.authenticationProvider.authenticateRequest(requestInfo, additionalContext);
const request = this.getRequestFromRequestInformation(requestInfo);
return yield this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
const response = yield this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
return yield this.retryCAEResponseIfRequired(requestInfo, response, claims);
});
this.retryCAEResponseIfRequired = (requestInfo, response, claims) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const responseClaims = this.getClaimsFromResponse(response, claims);
if (responseClaims) {
yield this.purgeResponseBody(response);
return yield this.getHttpResponseMessage(requestInfo, responseClaims);
}
return response;
});
this.getClaimsFromResponse = (response, claims) => {
if (response.status === 401 && !claims) {
// avoid infinite loop, we only retry once
// no need to check for the content since it's an array and it doesn't need to be rewound
const rawAuthenticateHeader = response.headers.get("WWW-Authenticate");
if (rawAuthenticateHeader && /^Bearer /gi.test(rawAuthenticateHeader)) {
const rawParameters = rawAuthenticateHeader.replace(/^Bearer /gi, "").split(",");
for (const rawParameter of rawParameters) {
const trimmedParameter = rawParameter.trim();
if (/claims="[^"]+"/gi.test(trimmedParameter)) {
return trimmedParameter.replace(/claims="([^"]+)"/gi, "$1");
}
}
}
}
return undefined;
};
this.setBaseUrlForRequestInformation = (requestInfo) => {

@@ -247,0 +277,0 @@ requestInfo.pathParameters["baseurl"] = this.baseUrl;

@@ -32,2 +32,4 @@ import { AuthenticationProvider, BackingStoreFactory, Parsable, ParsableFactory, ParseNodeFactory, RequestAdapter, RequestInformation, ResponseHandler, SerializationWriterFactory } from "@microsoft/kiota-abstractions";

private getHttpResponseMessage;
private retryCAEResponseIfRequired;
private getClaimsFromResponse;
private setBaseUrlForRequestInformation;

@@ -34,0 +36,0 @@ private getRequestFromRequestInformation;

@@ -231,3 +231,3 @@ import { ApiError, BackingStoreFactorySingleton, enableBackingStoreForParseNodeFactory, enableBackingStoreForSerializationWriterFactory, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions";

};
this.getHttpResponseMessage = async (requestInfo) => {
this.getHttpResponseMessage = async (requestInfo, claims) => {
if (!requestInfo) {

@@ -237,6 +237,36 @@ throw new Error("requestInfo cannot be null");

this.setBaseUrlForRequestInformation(requestInfo);
await this.authenticationProvider.authenticateRequest(requestInfo);
const additionalContext = {};
if (claims) {
additionalContext["claims"] = claims;
}
await this.authenticationProvider.authenticateRequest(requestInfo, additionalContext);
const request = this.getRequestFromRequestInformation(requestInfo);
return await this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
const response = await this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
return await this.retryCAEResponseIfRequired(requestInfo, response, claims);
};
this.retryCAEResponseIfRequired = async (requestInfo, response, claims) => {
const responseClaims = this.getClaimsFromResponse(response, claims);
if (responseClaims) {
await this.purgeResponseBody(response);
return await this.getHttpResponseMessage(requestInfo, responseClaims);
}
return response;
};
this.getClaimsFromResponse = (response, claims) => {
if (response.status === 401 && !claims) {
// avoid infinite loop, we only retry once
// no need to check for the content since it's an array and it doesn't need to be rewound
const rawAuthenticateHeader = response.headers.get("WWW-Authenticate");
if (rawAuthenticateHeader && /^Bearer /gi.test(rawAuthenticateHeader)) {
const rawParameters = rawAuthenticateHeader.replace(/^Bearer /gi, "").split(",");
for (const rawParameter of rawParameters) {
const trimmedParameter = rawParameter.trim();
if (/claims="[^"]+"/gi.test(trimmedParameter)) {
return trimmedParameter.replace(/claims="([^"]+)"/gi, "$1");
}
}
}
}
return undefined;
};
this.setBaseUrlForRequestInformation = (requestInfo) => {

@@ -243,0 +273,0 @@ requestInfo.pathParameters["baseurl"] = this.baseUrl;

6

package.json
{
"name": "@microsoft/kiota-http-fetchlibrary",
"version": "1.0.0-preview.6",
"version": "1.0.0-preview.7",
"description": "Kiota request adapter implementation with fetch",

@@ -47,7 +47,7 @@ "keywords": [

"dependencies": {
"@microsoft/kiota-abstractions": "1.0.0-preview.5",
"@microsoft/kiota-abstractions": "1.0.0-preview.6",
"node-fetch": "^2.6.5",
"tslib": "^2.3.1"
},
"gitHead": "20c11fcd4aa553aa40c706ebe7969be4d5f98d59"
"gitHead": "de31c882a56870f10216603a245270120a31f9d0"
}

@@ -212,3 +212,3 @@ import { ApiError, AuthenticationProvider, BackingStoreFactory, BackingStoreFactorySingleton, DateOnly, Duration, enableBackingStoreForParseNodeFactory, enableBackingStoreForSerializationWriterFactory, Parsable, ParsableFactory, ParseNode,ParseNodeFactory, ParseNodeFactoryRegistry, RequestAdapter, RequestInformation, ResponseHandler, SerializationWriterFactory, SerializationWriterFactoryRegistry, TimeOnly } from "@microsoft/kiota-abstractions";

};
private getHttpResponseMessage = async (requestInfo: RequestInformation): Promise<Response> => {
private getHttpResponseMessage = async (requestInfo: RequestInformation, claims?: string): Promise<Response> => {
if (!requestInfo) {

@@ -218,7 +218,38 @@ throw new Error("requestInfo cannot be null");

this.setBaseUrlForRequestInformation(requestInfo);
await this.authenticationProvider.authenticateRequest(requestInfo);
const additionalContext = {} as Record<string, unknown>;
if (claims) {
additionalContext["claims"] = claims;
}
await this.authenticationProvider.authenticateRequest(requestInfo, additionalContext);
const request = this.getRequestFromRequestInformation(requestInfo);
return await this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
const response = await this.httpClient.executeFetch(requestInfo.URL, request, requestInfo.getRequestOptions());
return await this.retryCAEResponseIfRequired(requestInfo, response, claims);
};
private retryCAEResponseIfRequired = async (requestInfo: RequestInformation, response: Response, claims?: string) => {
const responseClaims = this.getClaimsFromResponse(response, claims);
if (responseClaims) {
await this.purgeResponseBody(response);
return await this.getHttpResponseMessage(requestInfo, responseClaims);
}
return response;
};
private getClaimsFromResponse = (response: Response, claims?: string) => {
if (response.status === 401 && !claims) {
// avoid infinite loop, we only retry once
// no need to check for the content since it's an array and it doesn't need to be rewound
const rawAuthenticateHeader = response.headers.get("WWW-Authenticate");
if (rawAuthenticateHeader && /^Bearer /gi.test(rawAuthenticateHeader)) {
const rawParameters = rawAuthenticateHeader.replace(/^Bearer /gi, "").split(",");
for (const rawParameter of rawParameters) {
const trimmedParameter = rawParameter.trim();
if (/claims="[^"]+"/gi.test(trimmedParameter)) {
return trimmedParameter.replace(/claims="([^"]+)"/gi, "$1");
}
}
}
}
return undefined;
};
private setBaseUrlForRequestInformation = (requestInfo: RequestInformation): void => {

@@ -225,0 +256,0 @@ requestInfo.pathParameters["baseurl"] = this.baseUrl;

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc