@clevercloud/client
Advanced tools
Comparing version 8.3.0 to 9.0.0
@@ -12,20 +12,4 @@ "use strict"; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
async function getSubtleCrypto() { | ||
// Browser environment | ||
if (globalThis.crypto?.subtle != null) { | ||
return globalThis.crypto?.subtle; | ||
} // Node environment | ||
else { | ||
const cryptoModule = await Promise.resolve().then(() => _interopRequireWildcard(require('node:crypto'))); | ||
return cryptoModule.subtle; | ||
} | ||
} | ||
function addOauthHeader(tokens) { | ||
return async function (requestParams) { | ||
const cryptoSubtle = await getSubtleCrypto(); | ||
const { | ||
@@ -48,7 +32,7 @@ method, | ||
const encodedKey = encoder.encode(key); | ||
const cryptoKey = await cryptoSubtle.importKey('raw', encodedKey, { | ||
const cryptoKey = await globalThis.crypto.subtle.importKey('raw', encodedKey, { | ||
name: 'HMAC', | ||
hash: 'SHA-512' | ||
}, false, ['sign']); | ||
const result = await cryptoSubtle.sign({ | ||
const result = await globalThis.crypto.subtle.sign({ | ||
name: 'HMAC', | ||
@@ -55,0 +39,0 @@ hash: 'SHA-512' |
import OAuth from 'oauth-1.0a'; | ||
async function getSubtleCrypto () { | ||
// Browser environment | ||
if (globalThis.crypto?.subtle != null) { | ||
return globalThis.crypto?.subtle; | ||
} | ||
// Node environment | ||
else { | ||
const cryptoModule = await import('node:crypto'); | ||
return cryptoModule.subtle; | ||
} | ||
} | ||
export function addOauthHeader (tokens) { | ||
@@ -20,4 +7,2 @@ | ||
const cryptoSubtle = await getSubtleCrypto(); | ||
const { method, url, headers, queryParams } = requestParams; | ||
@@ -37,3 +22,3 @@ | ||
const cryptoKey = await cryptoSubtle.importKey( | ||
const cryptoKey = await globalThis.crypto.subtle.importKey( | ||
'raw', | ||
@@ -46,3 +31,3 @@ encodedKey, | ||
const result = await cryptoSubtle.sign( | ||
const result = await globalThis.crypto.subtle.sign( | ||
{ name: 'HMAC', hash: 'SHA-512' }, | ||
@@ -49,0 +34,0 @@ cryptoKey, |
{ | ||
"name": "@clevercloud/client", | ||
"version": "8.3.0", | ||
"version": "9.0.0", | ||
"description": "JavaScript REST client and utils for Clever Cloud's API", | ||
@@ -63,4 +63,4 @@ "homepage": "https://github.com/CleverCloud/clever-client.js", | ||
"volta": { | ||
"node": "18.18.0" | ||
"node": "22.7.0" | ||
} | ||
} |
608854
18749