@apimatic/core
Advanced tools
Comparing version 0.6.2 to 0.7.0
@@ -0,1 +1,2 @@ | ||
import { detect } from 'detect-browser'; | ||
import warning from 'tiny-warning'; | ||
@@ -77,3 +78,44 @@ /** | ||
} | ||
/** | ||
* Replace the templated placeholders in user-agent with the platform | ||
* related information. | ||
* @param userAgent User-agent value to be updated | ||
* @returns Updated user-agent value | ||
*/ | ||
export { deprecated, isBlob, sanitizeUrl }; | ||
function updateUserAgent(userAgent, apiVersion, detail) { | ||
var updatedAgent = userAgent; | ||
var result = detect(); | ||
if (result) { | ||
updatedAgent = updatedAgent.replace('{engine}', result.name); | ||
} | ||
if (result === null || result === void 0 ? void 0 : result.version) { | ||
updatedAgent = updatedAgent.replace('{engine-version}', result.version); | ||
} | ||
if (result === null || result === void 0 ? void 0 : result.os) { | ||
updatedAgent = updatedAgent.replace('{os-info}', result.os); | ||
} | ||
if (typeof apiVersion !== 'undefined') { | ||
updatedAgent = updatedAgent.replace('{api-version}', apiVersion); | ||
} | ||
if (typeof detail !== 'undefined') { | ||
assertUserAgentDetail(detail); | ||
updatedAgent = updatedAgent.replace('{detail}', encodeURIComponent(detail)); | ||
} | ||
return updatedAgent; | ||
} | ||
function assertUserAgentDetail(detail) { | ||
if (detail.length > 128) { | ||
throw new Error('userAgentDetail length exceeds 128 characters limit'); | ||
} | ||
} | ||
export { deprecated, isBlob, sanitizeUrl, updateUserAgent }; |
@@ -1,2 +0,2 @@ | ||
export { deprecated, isBlob, sanitizeUrl } from './apiHelper.js'; | ||
export { deprecated, isBlob, sanitizeUrl, updateUserAgent } from './apiHelper.js'; | ||
export { FileWrapper, cloneFileWrapper, isFileWrapper } from './fileWrapper.js'; | ||
@@ -3,0 +3,0 @@ export { AbortError } from './errors/abortError.js'; |
@@ -33,2 +33,9 @@ /** | ||
export declare function deprecated(methodName: string, notice?: string): void; | ||
/** | ||
* Replace the templated placeholders in user-agent with the platform | ||
* related information. | ||
* @param userAgent User-agent value to be updated | ||
* @returns Updated user-agent value | ||
*/ | ||
export declare function updateUserAgent(userAgent: string, apiVersion?: string, detail?: string): string; | ||
//# sourceMappingURL=apiHelper.d.ts.map |
@@ -8,4 +8,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deprecated = exports.isBlob = exports.sanitizeUrl = void 0; | ||
exports.updateUserAgent = exports.deprecated = exports.isBlob = exports.sanitizeUrl = void 0; | ||
var tslib_1 = require("tslib"); | ||
var detect_browser_1 = require("detect-browser"); | ||
var tiny_warning_1 = tslib_1.__importDefault(require("tiny-warning")); | ||
@@ -73,1 +74,34 @@ /** | ||
exports.deprecated = deprecated; | ||
/** | ||
* Replace the templated placeholders in user-agent with the platform | ||
* related information. | ||
* @param userAgent User-agent value to be updated | ||
* @returns Updated user-agent value | ||
*/ | ||
function updateUserAgent(userAgent, apiVersion, detail) { | ||
var updatedAgent = userAgent; | ||
var result = detect_browser_1.detect(); | ||
if (result) { | ||
updatedAgent = updatedAgent.replace('{engine}', result.name); | ||
} | ||
if (result === null || result === void 0 ? void 0 : result.version) { | ||
updatedAgent = updatedAgent.replace('{engine-version}', result.version); | ||
} | ||
if (result === null || result === void 0 ? void 0 : result.os) { | ||
updatedAgent = updatedAgent.replace('{os-info}', result.os); | ||
} | ||
if (typeof apiVersion !== 'undefined') { | ||
updatedAgent = updatedAgent.replace('{api-version}', apiVersion); | ||
} | ||
if (typeof detail !== 'undefined') { | ||
assertUserAgentDetail(detail); | ||
updatedAgent = updatedAgent.replace('{detail}', encodeURIComponent(detail)); | ||
} | ||
return updatedAgent; | ||
} | ||
exports.updateUserAgent = updateUserAgent; | ||
function assertUserAgentDetail(detail) { | ||
if (detail.length > 128) { | ||
throw new Error('userAgentDetail length exceeds 128 characters limit'); | ||
} | ||
} |
{ | ||
"name": "@apimatic/core", | ||
"author": "Wajahat Iqbal", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
@@ -64,2 +64,3 @@ "sideEffects": false, | ||
"axios": "^0.21.1", | ||
"detect-browser": "^5.3.0", | ||
"detect-node": "^2.0.4", | ||
@@ -66,0 +67,0 @@ "form-data": "^3.0.0", |
@@ -7,2 +7,3 @@ /** | ||
import { detect } from 'detect-browser'; | ||
import warning from 'tiny-warning'; | ||
@@ -75,1 +76,39 @@ | ||
} | ||
/** | ||
* Replace the templated placeholders in user-agent with the platform | ||
* related information. | ||
* @param userAgent User-agent value to be updated | ||
* @returns Updated user-agent value | ||
*/ | ||
export function updateUserAgent( | ||
userAgent: string, | ||
apiVersion?: string, | ||
detail?: string | ||
): string { | ||
let updatedAgent = userAgent; | ||
const result = detect(); | ||
if (result) { | ||
updatedAgent = updatedAgent.replace('{engine}', result.name); | ||
} | ||
if (result?.version) { | ||
updatedAgent = updatedAgent.replace('{engine-version}', result.version); | ||
} | ||
if (result?.os) { | ||
updatedAgent = updatedAgent.replace('{os-info}', result.os); | ||
} | ||
if (typeof apiVersion !== 'undefined') { | ||
updatedAgent = updatedAgent.replace('{api-version}', apiVersion); | ||
} | ||
if (typeof detail !== 'undefined') { | ||
assertUserAgentDetail(detail); | ||
updatedAgent = updatedAgent.replace('{detail}', encodeURIComponent(detail)); | ||
} | ||
return updatedAgent; | ||
} | ||
function assertUserAgentDetail(detail: string) { | ||
if (detail.length > 128) { | ||
throw new Error('userAgentDetail length exceeds 128 characters limit'); | ||
} | ||
} |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ import { SchemaValidationError } from '../schema'; |
@@ -0,0 +0,0 @@ import { HttpRequest } from '../http/httpRequest'; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ // tslint:disable-next-line:no-reference |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
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
186814
4979
9
+ Addeddetect-browser@^5.3.0
+ Addeddetect-browser@5.3.0(transitive)