@soluzioni-futura/aws-mqtt-client-utils
Advanced tools
Comparing version
@@ -11,3 +11,3 @@ import { Client } from "paho-mqtt"; | ||
export default function getAwsMqttClient(options: AwsMqttClientOptions): Client; | ||
import pahoMqtt from "paho-mqtt"; | ||
import type pahoMqtt from "paho-mqtt"; | ||
export { pahoMqtt }; |
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pahoMqtt = void 0; | ||
const paho_mqtt_1 = require("paho-mqtt"); | ||
@@ -32,3 +31,3 @@ const hmac_sha256_1 = __importDefault(require("crypto-js/hmac-sha256")); | ||
const signUrl = (data) => { | ||
const { awsSecretAccessKey, hostname, method, now, path, payload, queryParams, region, scheme, serviceName, awsSessionToken, today } = data; | ||
const { secretAccessKey, hostname, method, now, path, payload, queryParams, region, scheme, serviceName, sessionToken, today } = data; | ||
const signedHeaders = "host"; | ||
@@ -41,7 +40,7 @@ const canonicalHeaders = "host:" + hostname.toLowerCase() + "\n"; | ||
const stringToSign = `AWS4-HMAC-SHA256\n${now}\n${today}/${region}/${serviceName}/aws4_request\n${hashedCanonicalRequest}`; | ||
const signingKey = getSignatureKey(awsSecretAccessKey, today, region, serviceName); | ||
const signingKey = getSignatureKey(secretAccessKey, today, region, serviceName); | ||
const signature = hmac_sha256_1.default(stringToSign, signingKey); | ||
let finalParams = `${queryParams}&X-Amz-Signature=${signature}`; | ||
if (awsSessionToken) { | ||
finalParams += `&X-Amz-Security-Token=${encodeURIComponent(awsSessionToken)}`; | ||
if (sessionToken) { | ||
finalParams += `&X-Amz-Security-Token=${encodeURIComponent(sessionToken)}`; | ||
} | ||
@@ -52,3 +51,3 @@ const url = scheme + hostname + path + "?" + finalParams; | ||
const prepareWebSocketUrl = (data) => { | ||
const { awsAccessKeyId, awsSecretAccessKey, options: { host, region, port }, awsSessionToken } = data; | ||
const { accessKeyId, secretAccessKey, options: { host, region, port }, sessionToken } = data; | ||
const now = getDateTimeString(); | ||
@@ -58,3 +57,3 @@ const today = getDateString(now); | ||
const serviceName = "iotdevicegateway"; | ||
const queryParams = `X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=${awsAccessKeyId}%2F${today}%2F${region}%2F${serviceName}%2Faws4_request&X-Amz-Date=${now}&X-Amz-SignedHeaders=host`; | ||
const queryParams = `X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=${accessKeyId}%2F${today}%2F${region}%2F${serviceName}%2Faws4_request&X-Amz-Date=${now}&X-Amz-SignedHeaders=host`; | ||
let hostname = host; | ||
@@ -70,4 +69,4 @@ if (port && port !== 443) { | ||
queryParams, | ||
awsAccessKeyId, | ||
awsSecretAccessKey, | ||
accessKeyId, | ||
secretAccessKey, | ||
region, | ||
@@ -78,3 +77,3 @@ now, | ||
serviceName, | ||
awsSessionToken | ||
sessionToken | ||
}); | ||
@@ -85,4 +84,4 @@ }; | ||
const url = prepareWebSocketUrl({ | ||
awsAccessKeyId: options.awsAccessKeyId, | ||
awsSecretAccessKey: options.awsSecretAccessKey, | ||
accessKeyId: options.awsAccessKeyId, | ||
secretAccessKey: options.awsSecretAccessKey, | ||
options: { | ||
@@ -92,3 +91,3 @@ host: options.iotEndpoint, | ||
}, | ||
awsSessionToken: options.awsSessionToken | ||
sessionToken: options.awsSessionToken | ||
}); | ||
@@ -98,3 +97,1 @@ return new paho_mqtt_1.Client(url, clientId); | ||
exports.default = getAwsMqttClient; | ||
const paho_mqtt_2 = __importDefault(require("paho-mqtt")); | ||
exports.pahoMqtt = paho_mqtt_2.default; |
{ | ||
"name": "@soluzioni-futura/aws-mqtt-client-utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,2 @@ | ||
import { Client } from "paho-mqtt" | ||
import { Client, Message } from "paho-mqtt" | ||
@@ -37,4 +37,4 @@ import hmacSHA256 from "crypto-js/hmac-sha256" | ||
queryParams: string, | ||
awsAccessKeyId: string, | ||
awsSecretAccessKey: string, | ||
accessKeyId: string, | ||
secretAccessKey: string, | ||
region: string, | ||
@@ -45,7 +45,7 @@ serviceName: string, | ||
now: string, | ||
awsSessionToken?: string | ||
sessionToken?: string | ||
}): string => { | ||
const { | ||
awsSecretAccessKey, | ||
secretAccessKey, | ||
hostname, | ||
@@ -60,3 +60,3 @@ method, | ||
serviceName, | ||
awsSessionToken, | ||
sessionToken, | ||
today | ||
@@ -73,3 +73,3 @@ } = data | ||
const stringToSign = `AWS4-HMAC-SHA256\n${now}\n${today}/${region}/${serviceName}/aws4_request\n${hashedCanonicalRequest}` | ||
const signingKey = getSignatureKey(awsSecretAccessKey, today, region, serviceName) | ||
const signingKey = getSignatureKey(secretAccessKey, today, region, serviceName) | ||
const signature = hmacSHA256(stringToSign, signingKey) | ||
@@ -79,4 +79,4 @@ | ||
if (awsSessionToken) { | ||
finalParams += `&X-Amz-Security-Token=${encodeURIComponent(awsSessionToken)}` | ||
if (sessionToken) { | ||
finalParams += `&X-Amz-Security-Token=${encodeURIComponent(sessionToken)}` | ||
} | ||
@@ -95,9 +95,9 @@ | ||
}, | ||
awsAccessKeyId: string, | ||
awsSecretAccessKey: string, | ||
awsSessionToken?: string | ||
accessKeyId: string, | ||
secretAccessKey: string, | ||
sessionToken?: string | ||
}) => { | ||
const { | ||
awsAccessKeyId, | ||
awsSecretAccessKey, | ||
accessKeyId, | ||
secretAccessKey, | ||
options: { | ||
@@ -108,3 +108,3 @@ host, | ||
}, | ||
awsSessionToken | ||
sessionToken | ||
} = data | ||
@@ -116,3 +116,3 @@ | ||
const serviceName = "iotdevicegateway" | ||
const queryParams = `X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=${awsAccessKeyId}%2F${today}%2F${region}%2F${serviceName}%2Faws4_request&X-Amz-Date=${now}&X-Amz-SignedHeaders=host` | ||
const queryParams = `X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=${accessKeyId}%2F${today}%2F${region}%2F${serviceName}%2Faws4_request&X-Amz-Date=${now}&X-Amz-SignedHeaders=host` | ||
let hostname = host | ||
@@ -130,4 +130,4 @@ | ||
queryParams, | ||
awsAccessKeyId, | ||
awsSecretAccessKey, | ||
accessKeyId, | ||
secretAccessKey, | ||
region, | ||
@@ -138,3 +138,3 @@ now, | ||
serviceName, | ||
awsSessionToken | ||
sessionToken | ||
}) | ||
@@ -156,4 +156,4 @@ } | ||
const url = prepareWebSocketUrl({ | ||
awsAccessKeyId: options.awsAccessKeyId, | ||
awsSecretAccessKey: options.awsSecretAccessKey, | ||
accessKeyId: options.awsAccessKeyId, | ||
secretAccessKey: options.awsSecretAccessKey, | ||
options: { | ||
@@ -163,3 +163,3 @@ host: options.iotEndpoint, | ||
}, | ||
awsSessionToken: options.awsSessionToken | ||
sessionToken: options.awsSessionToken | ||
}) | ||
@@ -170,5 +170,5 @@ | ||
import pahoMqtt from "paho-mqtt" | ||
import type pahoMqtt from "paho-mqtt" | ||
export { | ||
pahoMqtt | ||
} |
12952
-1.63%252
-1.18%