Comparing version 2.1.0 to 2.2.0
# Changelog | ||
## 2.2.0 | ||
- Use Fallback, if configured, for `.get`, `.getPolicyMetadata`, Query Builder, and | ||
local check APIs if Oso Cloud returns an error (Requires Fallback 1.0.0 or later) | ||
- Use Fallback, if configured, for supported endpoints if Oso Cloud returns an | ||
HTTP 400 error | ||
## 2.1.0 | ||
@@ -51,3 +58,3 @@ | ||
- feat: Add new `oso.bulkActions()` API: https://www.osohq.com/docs/reference/client-apis/node#in-bulk-osobulkactionsactor-resources | ||
- feat: Add new `oso.bulkActions()` API: <https://www.osohq.com/docs/reference/client-apis/node#in-bulk-osobulkactionsactor-resources> | ||
@@ -54,0 +61,0 @@ ## 1.0.3 |
{ | ||
"name": "oso-cloud", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Oso Cloud Node.js Client SDK", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -148,3 +148,4 @@ /// <reference types="node" /> | ||
constructor(url: string, apiKey: string, options: ClientOptions); | ||
fallbackEligible(path: string): boolean | "" | undefined; | ||
fallbackEligible(method: string, path: string): boolean | "" | undefined; | ||
fallbackEligibleStatusCode(statusCode: number): boolean; | ||
printDebugInfo(msg: string): Promise<void>; | ||
@@ -151,0 +152,0 @@ private printRequestTimingInfo; |
@@ -25,4 +25,4 @@ "use strict"; | ||
const retryOptions = { | ||
retries: 5, | ||
retryOn: [429, 500, 501, 502, 503, 504], | ||
retries: 2, | ||
retryOn: [400, 429, 500, 501, 502, 503, 504], | ||
retryDelay: function (attempt, _error, _response) { | ||
@@ -80,7 +80,32 @@ return Math.pow(2, attempt) * 10; | ||
} | ||
fallbackEligible(path) { | ||
return (this.fallbackAgent && | ||
this.fallbackUrl && | ||
["/authorize", "/list", "/actions", "/evaluate_query"].includes(path)); | ||
fallbackEligible(method, path) { | ||
let eligiblePath = false; | ||
switch (method.toLowerCase()) { | ||
case "post": { | ||
eligiblePath = [ | ||
"/authorize", | ||
"/list", | ||
"/actions", | ||
// distributed check api's | ||
"/actions_query", | ||
"/authorize_query", | ||
"/list_query", | ||
"/evaluate_query_local", | ||
// query builder api's | ||
"/evaluate_query", | ||
].includes(path); | ||
break; | ||
} | ||
case "get": { | ||
eligiblePath = ["/facts", "/policy_metadata"].includes(path); | ||
break; | ||
} | ||
} | ||
return this.fallbackAgent && this.fallbackUrl && eligiblePath; | ||
} | ||
fallbackEligibleStatusCode(statusCode) { | ||
// HTTP400 and HTTP5xx indicates errors experienced by the server in | ||
// handling the request, so these should be retried against fallback | ||
return statusCode == 400 || statusCode >= 500; | ||
} | ||
printDebugInfo(msg) { | ||
@@ -146,3 +171,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
if (["ECONNREFUSED", "ETIMEDOUT"].includes(e.code) && | ||
this.fallbackEligible(path)) { | ||
this.fallbackEligible(method, path)) { | ||
let url = `${this.fallbackUrl}/api${path}`; | ||
@@ -157,3 +182,4 @@ request.agent = this.fallbackAgent; | ||
this.printRequestTimingInfo(result, startTime, path); | ||
if (result.status >= 500 && this.fallbackEligible(path)) { | ||
if (this.fallbackEligibleStatusCode(result.status) && | ||
this.fallbackEligible(method, path)) { | ||
const fallbackStartTime = Date.now(); | ||
@@ -160,0 +186,0 @@ let url = `${this.fallbackUrl}/api${path}`; |
{ | ||
"name": "oso-cloud", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Oso Cloud Node.js Client SDK", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126182
1815