@luvio/utils
Advanced tools
Comparing version 5.21.1-alpha.0 to 5.23.0
@@ -15,1 +15,2 @@ export * from './bfs'; | ||
export { satisfies, stringIsVersion, Version } from './version'; | ||
export * from './error-handling'; |
@@ -524,3 +524,81 @@ /** | ||
export { isArray as ArrayIsArray, indexOf as ArrayPrototypeIndexOf, push as ArrayPrototypePush, slice as ArrayPrototypeSlice, ConsoleLogger, DataIncompleteError, DataNotFoundError, DefaultFileParserLogger, Err, stringify as JSONStringify, LogLevelMap, create as ObjectCreate, freeze as ObjectFreeze, keys as ObjectKeys, hasOwnProperty as ObjectPrototypeHasOwnProperty, Ok, addAllToSet, bfs, capitalize, deepEquals, err, includes, isCacheHitOrError, isCacheMiss, isDataIncompleteError, isDataNotFoundError, isPromiseLike, isSubscribable, loggerService, ok, racesync, rejectedPromiseLike, resolvedPromiseLike, satisfies, setDifference, setOverlaps, stableJSONStringify, stringIsVersion, toCamelCase, toError, toPascalCase, toScreamingSnakeCase, toTypeScriptSafeIdentifier, withResolvers }; | ||
var HttpStatusCode; | ||
(function (HttpStatusCode) { | ||
HttpStatusCode[HttpStatusCode["Ok"] = 200] = "Ok"; | ||
HttpStatusCode[HttpStatusCode["Created"] = 201] = "Created"; | ||
HttpStatusCode[HttpStatusCode["NoContent"] = 204] = "NoContent"; | ||
HttpStatusCode[HttpStatusCode["NotModified"] = 304] = "NotModified"; | ||
HttpStatusCode[HttpStatusCode["BadRequest"] = 400] = "BadRequest"; | ||
HttpStatusCode[HttpStatusCode["Unauthorized"] = 401] = "Unauthorized"; | ||
HttpStatusCode[HttpStatusCode["Forbidden"] = 403] = "Forbidden"; | ||
HttpStatusCode[HttpStatusCode["NotFound"] = 404] = "NotFound"; | ||
HttpStatusCode[HttpStatusCode["ServerError"] = 500] = "ServerError"; | ||
HttpStatusCode[HttpStatusCode["GatewayTimeout"] = 504] = "GatewayTimeout"; | ||
})(HttpStatusCode || (HttpStatusCode = {})); | ||
// Logic from https://github.com/salesforce-experience-platform-emu/lds-lightning-platform/blob/main/packages/lds-network-aura/src/middlewares/utils.ts#L197 | ||
function getFetchResponseFromAuraError(err) { | ||
// Handle ConnectInJava exception shapes | ||
if (err.data !== undefined && err.data.statusCode !== undefined) { | ||
let data = {}; | ||
data = err.data; | ||
if (err.id !== undefined) { | ||
data.id = err.id; | ||
} | ||
return new FetchResponse(data.statusCode, data); | ||
} | ||
// Handle all the other kind of errors | ||
return new FetchResponse(HttpStatusCode.ServerError, { | ||
error: err.message, | ||
}); | ||
} | ||
// Backwards-compatible fetch error coerce | ||
// Adapted from https://github.com/salesforce-experience-platform-emu/luvio/blob/main/packages/@luvio/network-adapter-fetch/src/fetchNetworkAdapter.ts#L67 | ||
async function coerceResponseToFetchResponse(response) { | ||
const { status } = response; | ||
// coerce headers | ||
const responseHeaders = {}; | ||
response.headers.forEach((value, key) => { | ||
responseHeaders[key] = value; | ||
}); | ||
// parse body | ||
let responseBody = null; | ||
if (status !== 204) { | ||
const contentType = responseHeaders['content-type']; | ||
responseBody = | ||
contentType && contentType.startsWith('application/json') | ||
? await response.json() | ||
: await response.text(); | ||
} | ||
return new FetchResponse(status, responseBody, responseHeaders); | ||
} | ||
function getStatusText(status) { | ||
switch (status) { | ||
case HttpStatusCode.Ok: | ||
return 'OK'; | ||
case HttpStatusCode.Created: | ||
return 'Created'; | ||
case HttpStatusCode.NotModified: | ||
return 'Not Modified'; | ||
case HttpStatusCode.BadRequest: | ||
return 'Bad Request'; | ||
case HttpStatusCode.NotFound: | ||
return 'Not Found'; | ||
case HttpStatusCode.ServerError: | ||
return 'Server Error'; | ||
default: | ||
return `Unexpected HTTP Status Code: ${status}`; | ||
} | ||
} | ||
class FetchResponse extends Error { | ||
constructor(status, body, headers) { | ||
super(); | ||
this.status = status; | ||
this.body = body; | ||
this.headers = headers || {}; | ||
this.ok = status >= 200 && this.status <= 299; | ||
this.statusText = getStatusText(status); | ||
} | ||
} | ||
export { isArray as ArrayIsArray, indexOf as ArrayPrototypeIndexOf, push as ArrayPrototypePush, slice as ArrayPrototypeSlice, ConsoleLogger, DataIncompleteError, DataNotFoundError, DefaultFileParserLogger, Err, FetchResponse, HttpStatusCode, stringify as JSONStringify, LogLevelMap, create as ObjectCreate, freeze as ObjectFreeze, keys as ObjectKeys, hasOwnProperty as ObjectPrototypeHasOwnProperty, Ok, addAllToSet, bfs, capitalize, coerceResponseToFetchResponse, deepEquals, err, getFetchResponseFromAuraError, includes, isCacheHitOrError, isCacheMiss, isDataIncompleteError, isDataNotFoundError, isPromiseLike, isSubscribable, loggerService, ok, racesync, rejectedPromiseLike, resolvedPromiseLike, satisfies, setDifference, setOverlaps, stableJSONStringify, stringIsVersion, toCamelCase, toError, toPascalCase, toScreamingSnakeCase, toTypeScriptSafeIdentifier, withResolvers }; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@luvio/utils", | ||
"version": "5.21.1-alpha.0", | ||
"version": "5.23.0", | ||
"description": "Luvio utils", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
93660
32
1013
1